提交 | 用户 | age
|
418cb3
|
1 |
#include "pch.h"
|
Q |
2 |
#include "KLink1.h"
|
|
3 |
#include "KLink.h"
|
|
4 |
#include <afxdialogex.h>
|
|
5 |
#include "CDialogCommSet1.h"
|
|
6 |
|
|
7 |
KLink1::KLink1()
|
|
8 |
{
|
|
9 |
|
|
10 |
}
|
|
11 |
|
|
12 |
KLink1::~KLink1()
|
|
13 |
{
|
|
14 |
|
|
15 |
}
|
|
16 |
|
|
17 |
static const KLink1::stKLTypeName KLCoilTypeNames[] =
|
|
18 |
{
|
|
19 |
{KLink1::KLCoilTypeX,"X",KLink1::KLCoilXCount},
|
|
20 |
{KLink1::KLCoilTypeY,"Y",KLink1::KLCoilYCount},
|
|
21 |
{KLink1::KLCoilTypeR,"R",KLink1::KLCoilRCount},
|
|
22 |
{KLink1::KLCoilTypeLX,"LX",KLink1::KLCoilLXCount},
|
|
23 |
{KLink1::KLCoilTypeLY,"LY",KLink1::KLCoilLYCount},
|
|
24 |
{KLink1::KLCoilTypeT,"T",KLink1::KLCoilTCount},
|
|
25 |
{KLink1::KLCoilTypeC,"C",KLink1::KLCoilCCount}
|
|
26 |
};
|
|
27 |
|
|
28 |
static const KLink1::stKLTypeName KLDataTypeNames[] =
|
|
29 |
{
|
|
30 |
|
|
31 |
KLink1::KLDataTypeWX,"WX", KLink1::KLDataWXCount,
|
|
32 |
KLink1::KLDataTypeWY,"WY", KLink1::KLDataWYCount,
|
|
33 |
KLink1::KLDataTypeWR,"WR",KLink1::KLDataWRCount,
|
|
34 |
KLink1::KLDataTypeWLX,"WLX",KLink1::KLDataWLCount,
|
|
35 |
KLink1::KLDataTypeWLY,"WLY",KLink1::KLDataWLCount,
|
|
36 |
KLink1::KLDataTypeDT,"DT",KLink1::KLDataDTCount,
|
|
37 |
KLink1::KLDataTypeSDT,"SDT",KLink1::KLDataSDTCount,
|
|
38 |
KLink1::KLDataTypeSV,"SV",KLink1::KLDataSVCount ,
|
|
39 |
KLink1::KLDataTypeEV,"EV",KLink1::KLDataEVCount ,
|
|
40 |
KLink1::KLDataTypeLD,"LD",KLink1::KLDataLDCount,
|
|
41 |
KLink1::KLDataSysCfg,"Cfg",128,
|
|
42 |
KLink1::KLDataTypeFlash,"Flash",256,
|
|
43 |
KLink1::KLDataTypeTest,"Test",256
|
|
44 |
};
|
|
45 |
|
|
46 |
const char * KLink1::GetErrDescStr(int nErrNo)
|
|
47 |
{
|
|
48 |
switch (nErrNo)
|
|
49 |
{
|
|
50 |
case KL_ERR:
|
|
51 |
return "ERROR";
|
|
52 |
case KL_OK: //=0
|
|
53 |
return "OK";
|
|
54 |
case KL_NG:// = 1,
|
|
55 |
return "NG";
|
|
56 |
case KL_UNKNOWN: // = 2,
|
|
57 |
return "KL_UNKNOWN";
|
|
58 |
case KL_TIMEOUT: // = 3,
|
|
59 |
return "KL_TIMEOUT";
|
|
60 |
case KL_BCC_ERR: // = 4,
|
|
61 |
return "KL_BCC_ERR";
|
|
62 |
case KL_PKG_ERR: // = 5,
|
|
63 |
return "KL_PKG_ERR";
|
|
64 |
case KL_SEQ_ERR: // = 6,
|
|
65 |
return "KL_SEQ_ERR";
|
|
66 |
case KL_LENTH_EXCEED: //,
|
|
67 |
return "KL_LENTH_EXCEED";
|
|
68 |
case KL_NEED_PASS: //,
|
|
69 |
return "KL_NEED_PASS";
|
|
70 |
case KL_NOT_SUPPORT://,
|
|
71 |
return "KL_NOT_SUPPORT";
|
|
72 |
default:
|
|
73 |
return "KL_OTHER_ERR";
|
|
74 |
break;
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
int KLink1::xtoi(const char * hexstr, int len)
|
|
79 |
{
|
|
80 |
int len1 = len;
|
|
81 |
if (len <= 0) len1 = (int)strlen(hexstr);
|
|
82 |
int j = 0;
|
|
83 |
for (int i = 0; i < len1; i++)
|
|
84 |
{
|
|
85 |
unsigned char ch = hexstr[i];
|
|
86 |
if (ch >= '0'&&ch <= '9') { int k = ch - '0'; j = j * 16 + k; continue; }
|
|
87 |
if (ch >= 'A'&&ch <= 'F') { int k = ch - 'A' + 10; j = j * 16 + k; continue; }
|
|
88 |
if (ch >= 'a'&&ch <= 'f') { int k = ch - 'a' + 10; j = j * 16 + k; continue; }
|
|
89 |
if (ch == ' ' || ch == ' ') { continue; }
|
|
90 |
break;
|
|
91 |
}
|
|
92 |
return j;
|
|
93 |
}
|
|
94 |
|
|
95 |
unsigned char KLink1::KLBCC(void * pData, int nSize)
|
|
96 |
{
|
|
97 |
unsigned char k = 0;
|
|
98 |
for (int i = 0; i < nSize; i++)
|
|
99 |
{
|
|
100 |
k ^= ((unsigned char *)pData)[i];
|
|
101 |
}
|
|
102 |
return k;
|
|
103 |
}
|
|
104 |
int KLink1::CalCRC(void * pBuf, int nSize)
|
|
105 |
{
|
|
106 |
return 0;
|
|
107 |
}
|
|
108 |
|
|
109 |
int KLink1::SetCallBackFuncs(pCallBackFuncs pFuncSt)
|
|
110 |
{
|
|
111 |
if (pFuncSt->OpenFunc) { m_CallBackFuncs.OpenFunc = pFuncSt->OpenFunc; m_bOpenCallBackSet = 1; }
|
|
112 |
if (pFuncSt->CloseFunc) { m_CallBackFuncs.CloseFunc = pFuncSt->CloseFunc; m_bCloseCallBackSet = 1; }
|
|
113 |
if (pFuncSt->SendPkgFunc) { m_CallBackFuncs.SendPkgFunc = pFuncSt->SendPkgFunc; m_bSendCallBackSet = 1; }
|
|
114 |
if (pFuncSt->RecvPkgFunc) { m_CallBackFuncs.RecvPkgFunc = pFuncSt->RecvPkgFunc; m_bRecvCallBackSet = 1; }
|
|
115 |
if (pFuncSt->ClearBufFunc) { m_CallBackFuncs.ClearBufFunc = pFuncSt->ClearBufFunc; m_bClearBufCallBackSet = 1; }
|
|
116 |
if (pFuncSt->OnConnect) { m_CallBackFuncs.OnConnect = pFuncSt->OnConnect; m_bOnConnectCallBackSet = 1; }
|
|
117 |
if (pFuncSt->OnDisConnect) { m_CallBackFuncs.OnDisConnect = pFuncSt->OnDisConnect; m_bOnDisConnectCallBackSet = 1; }
|
|
118 |
if (pFuncSt->OnError) { m_CallBackFuncs.OnError = pFuncSt->OnError; m_bOnErrorCallBackSet = 1; }
|
|
119 |
|
|
120 |
// if (pFuncSt->SendPkgFunc) { m_CallBackFuncs.SendPkgFunc = pFuncSt->SendPkgFunc; m_bSendCallBackSet = 1; }
|
|
121 |
|
|
122 |
return KL_OK;
|
|
123 |
}
|
|
124 |
|
|
125 |
|
|
126 |
int KLink1::SetCommParam()
|
|
127 |
{
|
|
128 |
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
|
129 |
/*
|
|
130 |
//方法2的状态变更
|
|
131 |
HINSTANCE save_hInstance = AfxGetResourceHandle();
|
|
132 |
|
|
133 |
AfxSetResourceHandle(theApp.m_hInstance);
|
|
134 |
|
|
135 |
// CDialog dlg(IDD_DLL_DIALOG);//打开ID为2000的对话框
|
|
136 |
// dlg.DoModal();
|
|
137 |
*/
|
|
138 |
CDialogCommSet1 dialog1;
|
61deef
|
139 |
// if (m_bCommParamSet)
|
df0321
|
140 |
{
|
Q |
141 |
dialog1.m_nComNum = m_nPort;
|
|
142 |
dialog1.m_nBaudRate = m_nBaudRate;
|
|
143 |
dialog1.m_Settings = m_Settings;
|
|
144 |
dialog1.m_bOpened = m_bOpened;
|
|
145 |
}
|
418cb3
|
146 |
INT_PTR r = dialog1.DoModal();
|
Q |
147 |
//方法2的状态还原
|
|
148 |
|
|
149 |
// AfxSetResourceHandle(save_hInstance);
|
|
150 |
if (r == IDOK)
|
|
151 |
{
|
|
152 |
m_nPort = dialog1.m_nComNum;
|
|
153 |
m_nBaudRate = dialog1.m_nBaudRate;
|
|
154 |
m_Settings = dialog1.m_Settings;
|
|
155 |
m_bCommParamSet = true;
|
|
156 |
}
|
|
157 |
else
|
|
158 |
{
|
|
159 |
return -1;
|
|
160 |
}
|
|
161 |
|
|
162 |
return 0;
|
|
163 |
}
|
|
164 |
int KLink1::fnTest1(int n)
|
|
165 |
{
|
|
166 |
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
|
167 |
/*
|
|
168 |
//方法2的状态变更
|
|
169 |
HINSTANCE save_hInstance = AfxGetResourceHandle();
|
|
170 |
|
|
171 |
AfxSetResourceHandle(theApp.m_hInstance);
|
|
172 |
|
|
173 |
// CDialog dlg(IDD_DLL_DIALOG);//打开ID为2000的对话框
|
|
174 |
// dlg.DoModal();
|
|
175 |
*/
|
|
176 |
CDialogCommSet1 dialog1;
|
|
177 |
INT_PTR r = dialog1.DoModal();
|
|
178 |
//方法2的状态还原
|
|
179 |
|
|
180 |
// AfxSetResourceHandle(save_hInstance);
|
|
181 |
|
|
182 |
return 0;
|
|
183 |
}
|
|
184 |
|
|
185 |
int KLink1::Open(int OpenParam)
|
|
186 |
{
|
|
187 |
CString s1;
|
|
188 |
if (!m_bCommParamSet)
|
|
189 |
{
|
|
190 |
if (SetCommParam()) return -1;
|
|
191 |
m_bCommParamSet = 1;
|
|
192 |
}
|
|
193 |
MySerPort1.SetParams(m_nPort, m_nBaudRate, _T("8,N,1"));
|
|
194 |
int r = MySerPort1.Open();
|
|
195 |
s1.Format(_T("Open %s = %d"), MySerPort1.m_strResult, r);
|
|
196 |
m_resultStr = s1; // MySerPort1.m_strResult;
|
|
197 |
if (r == MySerPort1.R_OK)
|
|
198 |
{
|
|
199 |
m_bOpened = true;
|
61deef
|
200 |
// GotoCmdMode();
|
418cb3
|
201 |
// MyKLink1.Open();
|
Q |
202 |
// m_static_connect.SetCtlColor(RGB(0, 255, 0));
|
|
203 |
return KL_OK;
|
|
204 |
}
|
|
205 |
else
|
|
206 |
{
|
|
207 |
m_bOpened = false;
|
|
208 |
return r;
|
|
209 |
}
|
|
210 |
/*
|
|
211 |
if (m_bOpenCallBackSet)
|
|
212 |
{
|
|
213 |
m_CallBackFuncs.OpenFunc();
|
|
214 |
}
|
|
215 |
*/
|
|
216 |
m_bOpened = true;
|
61deef
|
217 |
//
|
418cb3
|
218 |
return KL_OK;
|
Q |
219 |
};
|
|
220 |
int KLink1::Close(int CloseParam)
|
|
221 |
{
|
61deef
|
222 |
ExitCmdMode();
|
418cb3
|
223 |
if (m_bCloseCallBackSet)
|
Q |
224 |
{
|
|
225 |
m_CallBackFuncs.CloseFunc();
|
|
226 |
}
|
|
227 |
m_bOpened = false;
|
|
228 |
return KL_OK;
|
|
229 |
};
|
61deef
|
230 |
|
Q |
231 |
int KLink1::GotoCmdMode(int Param)
|
|
232 |
{
|
|
233 |
int res = KL_OK;
|
|
234 |
int len1 = 3;
|
|
235 |
m_Packetbuf[0] = '+';
|
|
236 |
m_Packetbuf[1] = '+';
|
|
237 |
m_Packetbuf[2] = '+';
|
|
238 |
|
|
239 |
SendPacket(m_Packetbuf, len1);
|
|
240 |
|
|
241 |
return res;
|
|
242 |
}
|
|
243 |
|
|
244 |
int KLink1::ExitCmdMode(int Param)
|
|
245 |
{
|
|
246 |
int res = KL_OK;
|
|
247 |
int len1 = 3;
|
|
248 |
m_Packetbuf[0] = '-';
|
|
249 |
m_Packetbuf[1] = '-';
|
|
250 |
m_Packetbuf[2] = '-';
|
|
251 |
|
|
252 |
SendPacket(m_Packetbuf, len1);
|
|
253 |
|
|
254 |
return res;
|
|
255 |
}
|
|
256 |
|
418cb3
|
257 |
int KLink1::Connect(int ConnectParam)
|
Q |
258 |
{
|
|
259 |
int OpenParam = ConnectParam;
|
|
260 |
int res=Open(OpenParam);
|
|
261 |
unsigned short len1;
|
|
262 |
unsigned short buf1[256];
|
|
263 |
//m_resultStr = MySerPort1.m_strResult;
|
61deef
|
264 |
GotoCmdMode();
|
418cb3
|
265 |
return res;
|
Q |
266 |
if (res == KL_OK)
|
|
267 |
{
|
61deef
|
268 |
GotoCmdMode();
|
418cb3
|
269 |
int res2 = GetInfo(m_Dst, &len1, buf1);
|
Q |
270 |
|
|
271 |
if (m_bOnConnectCallBackSet) { m_CallBackFuncs.OnConnect(); }
|
|
272 |
return res;
|
|
273 |
}
|
|
274 |
return res;
|
|
275 |
}
|
|
276 |
int KLink1::DisConnect(int DisConnectParam)
|
|
277 |
{
|
61deef
|
278 |
ExitCmdMode();
|
418cb3
|
279 |
if (m_bOnDisConnectCallBackSet) { m_CallBackFuncs.OnDisConnect(DisConnectParam); }
|
Q |
280 |
return Close();
|
|
281 |
}
|
|
282 |
|
|
283 |
int KLink1::CalSpeed()
|
|
284 |
{
|
|
285 |
double thistime = MySerPort1.GetTimemS();
|
|
286 |
double diftime = thistime - LastTime;
|
|
287 |
if (diftime >= 500)
|
|
288 |
{
|
|
289 |
m_SendSpeed = (DWORD)(m_nSendCount * 1000 / diftime);
|
|
290 |
m_RecvSpeed = static_cast<DWORD> (m_nRecvCount * 1000 / diftime);
|
|
291 |
m_nLastSendCount = m_nSendCount; m_nSendCount = 0;
|
|
292 |
m_nLastRecvCount = m_nRecvCount; m_nRecvCount = 0;
|
|
293 |
LastTime = thistime;
|
|
294 |
}
|
|
295 |
return 0;
|
|
296 |
}
|
|
297 |
|
|
298 |
int KLink1::DoHeartBeat(int nParam)
|
|
299 |
{
|
|
300 |
unsigned short nByteCount;
|
|
301 |
unsigned short buf1[256];
|
|
302 |
int res = GetInfo(m_Dst, &nByteCount, buf1);
|
|
303 |
return KL_OK;
|
|
304 |
}
|
|
305 |
|
|
306 |
void KLink1::OnTimer()
|
|
307 |
{
|
|
308 |
DoHeartBeat();
|
|
309 |
}
|
|
310 |
|
|
311 |
int KLink1::SendPacket(void * pBuf, int Len)
|
|
312 |
{
|
|
313 |
if (m_bOpened && m_bSendCallBackSet)
|
|
314 |
{
|
61deef
|
315 |
m_nTotalSendCount++;
|
418cb3
|
316 |
if (m_bClearBufCallBackSet) m_CallBackFuncs.ClearBufFunc();
|
Q |
317 |
return m_CallBackFuncs.SendPkgFunc(pBuf, Len);
|
|
318 |
}
|
|
319 |
else return KL_ERR;
|
|
320 |
}
|
|
321 |
|
|
322 |
int KLink1::RecvPacket(void * pBuf, int LenToRead, int ReTryCount)
|
|
323 |
{
|
|
324 |
|
|
325 |
if (m_bOpened && m_bRecvCallBackSet)
|
|
326 |
{
|
|
327 |
int len2 = 0;
|
|
328 |
char * pBufByte = (char *)pBuf;
|
|
329 |
for (int i = 0; i < ReTryCount; i++)
|
|
330 |
{
|
|
331 |
int len1 = m_CallBackFuncs.RecvPkgFunc(pBufByte + len2, LenToRead - len2);
|
|
332 |
if (len1 <= 0 || len1 > 256) {
|
|
333 |
continue;
|
|
334 |
}
|
|
335 |
len2 += len1;
|
|
336 |
if (len2 >= LenToRead) break;
|
|
337 |
}
|
|
338 |
if (len2 >= LenToRead) {
|
|
339 |
m_nContinueErrCount = 0;
|
61deef
|
340 |
m_nTotalRecvCount++;
|
418cb3
|
341 |
return len2;
|
Q |
342 |
}
|
|
343 |
else if (len2 <= 0) {
|
|
344 |
m_nErrCount++;
|
|
345 |
m_nContinueErrCount++;
|
|
346 |
if (m_nContinueErrCount > 10)
|
|
347 |
{
|
|
348 |
// Close(-1);
|
|
349 |
}
|
|
350 |
return KL_ERR;
|
|
351 |
}
|
|
352 |
else {
|
61deef
|
353 |
m_nTotalRecvCount++;
|
418cb3
|
354 |
return len2;
|
Q |
355 |
}
|
|
356 |
}
|
|
357 |
else
|
|
358 |
{
|
|
359 |
return KL_ERR;
|
|
360 |
}
|
|
361 |
}
|
|
362 |
|
|
363 |
int KLink1::MakeExtDataFrame(void * pBuf, UCHAR nDst, UCHAR nType, UCHAR len2, void * pData)
|
|
364 |
{
|
|
365 |
int framelen1 = 0;
|
|
366 |
pKLExtDataFrame pF1 = (pKLExtDataFrame)pBuf;
|
|
367 |
pF1->Dst = nDst;
|
|
368 |
pF1->nType = nType;
|
|
369 |
pF1->Len2 = len2;
|
|
370 |
memcpy(pF1->Data, pData, len2);
|
|
371 |
UCHAR bcc = KLBCC(pBuf, sizeof(tagKLExtDataFrame) + len2 - 1);
|
|
372 |
pF1->Data[len2] = bcc;
|
|
373 |
|
|
374 |
framelen1 = sizeof(tagKLExtDataFrame) + len2;
|
|
375 |
return framelen1;
|
|
376 |
}
|
|
377 |
/*
|
|
378 |
int KLink1::MakeReqPacket(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr, USHORT nCount, void * pData)
|
|
379 |
{
|
|
380 |
int PkgLen1 = 0;
|
|
381 |
pKLReqPacket pPacket = (pKLReqPacket)pBuf;
|
|
382 |
pPacket->StartSign = KLSignStart;
|
|
383 |
pPacket->DstAddr = nDst;
|
|
384 |
pPacket->Stat = Stat;
|
|
385 |
pPacket->Cmd = nCMD;
|
|
386 |
pPacket->Type1 = Type;
|
|
387 |
int Datalen = 0;
|
61deef
|
388 |
int nByteAddr;
|
418cb3
|
389 |
int nWordCount;
|
Q |
390 |
|
|
391 |
switch (nCMD)
|
|
392 |
{
|
|
393 |
case KLCmdNone:
|
|
394 |
break;
|
|
395 |
case KLCmdPing:
|
|
396 |
Datalen = Type;
|
|
397 |
memcpy(pPacket->Params, pData, Datalen);
|
|
398 |
PkgLen1 = sizeof(stKLReqPacket) + Datalen;
|
|
399 |
break;
|
|
400 |
case KLCmdGetInfo:
|
|
401 |
break;
|
|
402 |
case KLCmdRead:
|
|
403 |
Datalen = 0;
|
|
404 |
pPacket->Params[0] = nAddr % 256;
|
|
405 |
pPacket->Params[1] = nAddr / 256;
|
|
406 |
pPacket->Params[2] = nCount % 256;
|
|
407 |
pPacket->Params[3] = nCount / 256;
|
|
408 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
409 |
break;
|
|
410 |
case KLCmdWrite:
|
|
411 |
pPacket->Params[0] = nAddr % 256;
|
|
412 |
pPacket->Params[1] = nAddr / 256;
|
|
413 |
pPacket->Params[2] = nCount % 256;
|
|
414 |
pPacket->Params[3] = nCount / 256;
|
|
415 |
Datalen = nCount;
|
|
416 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
417 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
418 |
|
|
419 |
break;
|
|
420 |
case KLCmdSaveToFlash:
|
|
421 |
break;
|
|
422 |
case KLCmdExChgData:
|
|
423 |
break;
|
|
424 |
case KLCmdGetEventLogCount:
|
|
425 |
pPacket->Params[0] = 0;
|
|
426 |
pPacket->Params[1] = 0;
|
|
427 |
pPacket->Params[2] = 0;
|
|
428 |
pPacket->Params[3] = 0;
|
|
429 |
Datalen = 0;
|
|
430 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
431 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
432 |
default:
|
|
433 |
break;
|
|
434 |
}
|
|
435 |
if (PkgLen1 >= sizeof(stKLReqPacket))
|
|
436 |
{
|
|
437 |
UCHAR BCC = KLBCC(pBuf, PkgLen1 - 1);
|
|
438 |
pPacket->Params[PkgLen1-sizeof(stKLReqPacket)] = BCC;
|
|
439 |
}
|
|
440 |
return PkgLen1;
|
|
441 |
}
|
|
442 |
*/
|
|
443 |
int KLink1::MakeReqPacketEx(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr, USHORT nCount, void * pData, int ExtFrameLen, void * pExtDataFrame)
|
|
444 |
{
|
|
445 |
int PkgLen1 = 0;
|
|
446 |
pKLReqPacket pPacket = (pKLReqPacket)pBuf;
|
|
447 |
pPacket->StartSign = KLSignStart;
|
|
448 |
pPacket->DstAddr = nDst;
|
|
449 |
pPacket->Stat = Stat;
|
|
450 |
pPacket->Cmd = nCMD;
|
|
451 |
pPacket->Type1 = Type;
|
|
452 |
|
|
453 |
pKLStat pStat = (pKLStat)&(pPacket->Stat);
|
|
454 |
int Datalen = 0;
|
|
455 |
int nWordAddr = nAddr;
|
|
456 |
int nWordCount = nCount;
|
|
457 |
pPacket->Params[0] = LOBYTE(nAddr);
|
|
458 |
pPacket->Params[1] = HIBYTE(nAddr);
|
|
459 |
pPacket->Params[2] = nCount % 256;
|
|
460 |
pPacket->Params[3] = nCount / 256;
|
|
461 |
|
|
462 |
switch (nCMD)
|
|
463 |
{
|
|
464 |
case KLCmdNone:
|
|
465 |
break;
|
|
466 |
case KLCmdPing:
|
|
467 |
Datalen = Type;
|
|
468 |
memcpy(pPacket->Params, pData, Datalen);
|
|
469 |
PkgLen1 = sizeof(stKLReqPacket) + Datalen;
|
|
470 |
break;
|
|
471 |
case KLCmdGetInfo:
|
|
472 |
case KLCmdGetSN:
|
|
473 |
Datalen = 0;
|
|
474 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
475 |
break;
|
|
476 |
case KLCmdGetFactoryData:
|
|
477 |
Datalen = 0;
|
|
478 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
479 |
break;
|
|
480 |
case KLCmdWriteFactoryData:
|
|
481 |
Datalen = nCount;
|
|
482 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
483 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
484 |
break;
|
|
485 |
case KLCmdRead:
|
|
486 |
Datalen = 0;
|
|
487 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
488 |
break;
|
|
489 |
case KLCmdWrite:
|
|
490 |
Datalen = nCount;
|
|
491 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
492 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
493 |
break;
|
|
494 |
case KLCmdRead1Bit:
|
|
495 |
Datalen = 0;
|
|
496 |
PkgLen1 = sizeof(stKLReqPacket) + 2 + Datalen;
|
|
497 |
break;
|
|
498 |
case KLCmdWrite1Bit:
|
|
499 |
Datalen = 1;
|
|
500 |
memcpy(pPacket->Params + 2, pData, Datalen);
|
|
501 |
PkgLen1 = sizeof(stKLReqPacket) + 2 + Datalen;
|
|
502 |
break;
|
|
503 |
|
|
504 |
case KLCmdReadBits:
|
|
505 |
Datalen = 0;
|
|
506 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
507 |
break;
|
|
508 |
case KLCmdWriteBits:
|
|
509 |
Datalen = 0;
|
|
510 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
511 |
break;
|
|
512 |
case KLCmdReadDataByte:
|
|
513 |
case KLCmdReadDataWord:
|
|
514 |
case KLCmdReadData:
|
|
515 |
Datalen = 0;
|
|
516 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
517 |
break;
|
|
518 |
case KLCmdWriteDataByte:
|
|
519 |
case KLCmdWriteDataWord:
|
|
520 |
case KLCmdWriteData:
|
|
521 |
Datalen = nCount;
|
|
522 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
523 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
524 |
break;
|
|
525 |
case KLCmdSaveToFlash:
|
|
526 |
break;
|
|
527 |
case KLCmdExChgData:
|
|
528 |
break;
|
|
529 |
case KLCmdReadProgram:
|
|
530 |
Datalen = 0;
|
|
531 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
532 |
break;
|
|
533 |
case KLCmdStartProgram:
|
|
534 |
Datalen = 0;
|
|
535 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
536 |
break;
|
|
537 |
case KLCmdWriteProgram:
|
|
538 |
Datalen = nCount;
|
|
539 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
540 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
541 |
break;
|
|
542 |
case KLCmdFinishProgram:
|
|
543 |
Datalen = 0;
|
|
544 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
545 |
break;
|
61deef
|
546 |
case KLCmdReadPLCAnno:
|
Q |
547 |
Datalen = 0;
|
|
548 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
549 |
break;
|
|
550 |
case KLCmdStartPLCAnno:
|
|
551 |
Datalen = 0;
|
|
552 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
553 |
break;
|
|
554 |
case KLCmdWritePLCAnno:
|
|
555 |
Datalen = nCount;
|
|
556 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
557 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
558 |
break;
|
|
559 |
case KLCmdFinishPLCAnno:
|
|
560 |
Datalen = 0;
|
|
561 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
562 |
break;
|
418cb3
|
563 |
|
Q |
564 |
case KLCmdReadRunStat:
|
|
565 |
Datalen = 0;
|
|
566 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
567 |
break;
|
|
568 |
|
|
569 |
case KLCmdWriteSysCfg:
|
|
570 |
Datalen = nCount;
|
|
571 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
572 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
573 |
break;
|
|
574 |
case KLCmdSaveSysCfg:
|
|
575 |
pPacket->Params[0] = 0;
|
|
576 |
pPacket->Params[1] = 0;
|
|
577 |
pPacket->Params[2] = 0;
|
|
578 |
pPacket->Params[3] = 0;
|
|
579 |
Datalen = 0;
|
|
580 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
581 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
582 |
break;
|
|
583 |
case KLCmdSaveRunStat:
|
|
584 |
pPacket->Params[0] = 0;
|
|
585 |
pPacket->Params[1] = 0;
|
|
586 |
pPacket->Params[2] = 0;
|
|
587 |
pPacket->Params[3] = 0;
|
|
588 |
Datalen = 0;
|
|
589 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
590 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
591 |
break;
|
|
592 |
case KLCmdClearEventLog:
|
|
593 |
pPacket->Params[0] = 0;
|
|
594 |
pPacket->Params[1] = 0;
|
|
595 |
pPacket->Params[2] = 0;
|
|
596 |
pPacket->Params[3] = 0;
|
|
597 |
Datalen = 0;
|
|
598 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
599 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
600 |
|
|
601 |
case KLCmdGetEventLogCount:
|
|
602 |
pPacket->Params[0] = 0;
|
|
603 |
pPacket->Params[1] = 0;
|
|
604 |
pPacket->Params[2] = 0;
|
|
605 |
pPacket->Params[3] = 0;
|
|
606 |
Datalen = 0;
|
|
607 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
608 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
609 |
break;
|
|
610 |
case KLCmdGetEventLog:
|
|
611 |
pPacket->Params[0] = nAddr % 256;
|
|
612 |
pPacket->Params[1] = nAddr / 256;
|
|
613 |
pPacket->Params[2] = nCount % 256;
|
|
614 |
pPacket->Params[3] = nCount / 256;
|
|
615 |
Datalen = 0;
|
|
616 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
|
617 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
618 |
break;
|
|
619 |
|
|
620 |
default:
|
61deef
|
621 |
Datalen = nCount;
|
418cb3
|
622 |
memcpy(pPacket->Params + 4, pData, Datalen);
|
Q |
623 |
PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
|
624 |
break;
|
|
625 |
}
|
|
626 |
|
|
627 |
if (PkgLen1 >= sizeof(stKLReqPacket))
|
|
628 |
{
|
|
629 |
UCHAR BCC = KLBCC(pBuf, PkgLen1 - 1);
|
|
630 |
pPacket->Params[PkgLen1 - sizeof(stKLReqPacket)] = BCC;
|
|
631 |
}
|
|
632 |
|
|
633 |
if (pStat->HasExt && ExtFrameLen > 0 && pExtDataFrame != NULL)
|
|
634 |
{
|
|
635 |
|
|
636 |
memcpy(pPacket->Params + PkgLen1 - sizeof(stKLReqPacket) + 1, pExtDataFrame, ExtFrameLen);
|
|
637 |
PkgLen1 += ExtFrameLen;
|
|
638 |
};
|
|
639 |
return PkgLen1;
|
|
640 |
}
|
|
641 |
|
61deef
|
642 |
int KLink1::MakeRemoteReqPacketEx(void* pBuf, UCHAR nDst, UCHAR Stat, UCHAR nPort, UCHAR nChildId, UCHAR nReqId, UCHAR Param1, USHORT nAddr , USHORT nCount , void* pData , int ExtFrameLen , void* pExtDataFrame)
|
Q |
643 |
{
|
|
644 |
int PkgLen1 = 0;
|
|
645 |
pKLReqPacket pPacket = (pKLReqPacket)pBuf;
|
|
646 |
pPacket->StartSign = KLSignStart;
|
|
647 |
pPacket->DstAddr = nDst;
|
|
648 |
pPacket->Stat = Stat;
|
|
649 |
pPacket->Cmd = KLCmdPortRemoteReq;
|
|
650 |
pPacket->Type1 = nReqId;
|
|
651 |
|
|
652 |
pKLStat pStat = (pKLStat) & (pPacket->Stat);
|
|
653 |
int Datalen = nCount;
|
|
654 |
int nWordAddr = nAddr;
|
|
655 |
int nWordCount = nCount;
|
|
656 |
pPacket->Params[0] = nPort;
|
|
657 |
pPacket->Params[1] = nChildId;
|
|
658 |
pPacket->Params[2] = Param1;
|
|
659 |
pPacket->Params[3] = nAddr % 256;
|
|
660 |
pPacket->Params[4] = nAddr / 256;
|
|
661 |
pPacket->Params[5] = nCount % 256;
|
|
662 |
// pPacket->Params[6] = nCount / 256;
|
|
663 |
memcpy(&pPacket->Params[6], pData, Datalen);
|
|
664 |
PkgLen1 = sizeof(stKLReqPacket) + 6 + Datalen;
|
|
665 |
|
|
666 |
if (PkgLen1 >= sizeof(stKLReqPacket))
|
|
667 |
{
|
|
668 |
UCHAR BCC = KLBCC(pBuf, PkgLen1 - 1);
|
|
669 |
pPacket->Params[PkgLen1 - sizeof(stKLReqPacket)] = BCC;
|
|
670 |
}
|
|
671 |
/*
|
|
672 |
if (pStat->HasExt && ExtFrameLen > 0 && pExtDataFrame != NULL)
|
|
673 |
{
|
|
674 |
|
|
675 |
memcpy(pPacket->Params + PkgLen1 - sizeof(stKLReqPacket) + 1, pExtDataFrame, ExtFrameLen);
|
|
676 |
PkgLen1 += ExtFrameLen;
|
|
677 |
};
|
|
678 |
*/
|
|
679 |
return PkgLen1;
|
|
680 |
}
|
418cb3
|
681 |
|
Q |
682 |
int KLink1::CheckPackage(void * pBuf, int nSize)
|
|
683 |
{
|
|
684 |
pKLRplyPktHdr p1 = (pKLRplyPktHdr)pBuf;
|
|
685 |
if (p1->RplyStSgn != KLSignReply)
|
|
686 |
{
|
|
687 |
return KL_UNKNOWN;
|
|
688 |
}
|
|
689 |
|
|
690 |
int DataLen = 0; //p1->LoadLen;
|
|
691 |
if (DataLen > KLMaxPacketLength)
|
|
692 |
{
|
|
693 |
return KL_PKG_ERR;
|
|
694 |
}
|
|
695 |
if (nSize < DataLen + sizeof(stKLRplyPktHdr))
|
|
696 |
{
|
|
697 |
//len4=sprintf(str3,"%d < %d + %d \r\n",len2,DataLen,sizeof(stPacket));
|
|
698 |
//PutStr(str3,len4);
|
|
699 |
return KL_PKG_ERR; //not long enough
|
|
700 |
}
|
|
701 |
// if (p1->data[DataLen+1] != EndSign)
|
|
702 |
// {
|
|
703 |
// ClientStat[nCurPollId].NoEndErr++;
|
|
704 |
// Uart2Stat.LengthErr++;
|
|
705 |
// return -2;
|
|
706 |
// }
|
|
707 |
unsigned char thisBCC = KLBCC(p1, nSize - 1);
|
|
708 |
if (thisBCC != ((UCHAR *)pBuf)[nSize - 1])
|
|
709 |
{//BCC Error;
|
|
710 |
return KL_BCC_ERR;
|
|
711 |
}
|
|
712 |
return KL_OK;
|
|
713 |
|
|
714 |
return true;
|
|
715 |
return false;
|
|
716 |
}
|
|
717 |
|
|
718 |
int KLink1::ProcessPacket(void *pBuf, int nLen)
|
|
719 |
{
|
|
720 |
return false;
|
|
721 |
}
|
|
722 |
|
|
723 |
int KLink1::ParseRplyPacket(void *pBuf, int nPkgLen, UCHAR * nCmd, UCHAR * Status, USHORT* nCount, void * pData)
|
|
724 |
{
|
|
725 |
if (nPkgLen < 0) { return KL_ERR; }
|
|
726 |
int res = CheckPackage(pBuf, nPkgLen);
|
|
727 |
if (res != KL_OK) return res;
|
|
728 |
int len1 = 0;
|
|
729 |
pKLRplyPktHdr pPacket = (pKLRplyPktHdr)pBuf;
|
|
730 |
UCHAR Sign = pPacket->RplyStSgn;
|
|
731 |
UCHAR nDst = pPacket->DstAddr;
|
|
732 |
*nCmd = pPacket->nRplyCMD;
|
|
733 |
UCHAR nStatus = pPacket->nStatus;
|
|
734 |
*Status = nStatus;
|
|
735 |
m_nRSeq = ((pKLStat)&nStatus)->nSEQ;
|
|
736 |
int Datalen = pPacket->nSize1;
|
|
737 |
*nCount = Datalen;
|
61deef
|
738 |
USHORT ErrCode;
|
418cb3
|
739 |
switch (*nCmd)
|
Q |
740 |
{
|
|
741 |
case KLCmdNone:
|
|
742 |
break;
|
|
743 |
case KLCmdPing:
|
|
744 |
case KLCmdPingReply:
|
|
745 |
*nCount = Datalen;
|
|
746 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
747 |
break;
|
|
748 |
case KLCmdGetInfo:
|
|
749 |
case KLCmdVerInfo:
|
|
750 |
*nCount = Datalen;
|
|
751 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
752 |
break;
|
|
753 |
case KLCmdGetUid:
|
|
754 |
case KLCmdGetSN:
|
|
755 |
case KLCmdGetFactoryData:
|
|
756 |
*nCount = Datalen;
|
|
757 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
758 |
break;
|
|
759 |
case KLCmdWriteFactoryData:
|
|
760 |
*nCount = Datalen;
|
|
761 |
break;
|
|
762 |
case KLCmdRead:
|
|
763 |
case KLCmdReadReply:
|
|
764 |
*nCount = Datalen;
|
|
765 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
766 |
break;
|
|
767 |
case KLCmdWrite:
|
|
768 |
case KLCmdWriteReply:
|
|
769 |
*nCount = Datalen;
|
|
770 |
break;
|
|
771 |
case KLCmdRead1Bit:
|
|
772 |
case KLCmdReadBits:
|
|
773 |
*nCount = Datalen;
|
|
774 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
775 |
break;
|
|
776 |
case KLCmdReadDataByte:
|
|
777 |
*nCount = Datalen;
|
|
778 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
779 |
break;
|
|
780 |
case KLCmdReadDataWord:
|
|
781 |
case KLCmdReadData:
|
|
782 |
*nCount = Datalen;
|
|
783 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
784 |
break;
|
|
785 |
case KLCmdWriteDataByte:
|
|
786 |
case KLCmdWriteDataWord:
|
|
787 |
case KLCmdWriteData:
|
|
788 |
*nCount = Datalen;
|
|
789 |
break;
|
|
790 |
|
|
791 |
case KLCmdSaveToFlash:
|
|
792 |
break;
|
61deef
|
793 |
case KLCmdGetMode:
|
Q |
794 |
*nCount = Datalen;
|
|
795 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
796 |
break;
|
418cb3
|
797 |
case KLCmdReadProgram:
|
Q |
798 |
*nCount = Datalen;
|
|
799 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
800 |
break;
|
|
801 |
case KLCmdStartProgram:
|
|
802 |
*nCount = Datalen;
|
|
803 |
break;
|
|
804 |
case KLCmdWriteProgram:
|
|
805 |
*nCount = Datalen;
|
|
806 |
break;
|
|
807 |
case KLCmdFinishProgram:
|
61deef
|
808 |
*nCount = Datalen;
|
Q |
809 |
break;
|
|
810 |
case KLCmdReadPLCAnno:
|
|
811 |
*nCount = Datalen;
|
|
812 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
813 |
break;
|
|
814 |
case KLCmdStartPLCAnno:
|
|
815 |
*nCount = Datalen;
|
|
816 |
break;
|
|
817 |
case KLCmdWritePLCAnno:
|
|
818 |
*nCount = Datalen;
|
|
819 |
break;
|
|
820 |
case KLCmdFinishPLCAnno:
|
418cb3
|
821 |
*nCount = Datalen;
|
Q |
822 |
break;
|
|
823 |
|
|
824 |
case KLCmdReadRunStat:
|
|
825 |
*nCount = Datalen;
|
|
826 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
827 |
break;
|
|
828 |
case KLCmdReadSysCfg:
|
|
829 |
*nCount = Datalen;
|
|
830 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
831 |
break;
|
|
832 |
case KLCmdExChgData:
|
|
833 |
case KLCmdExChgDataReply:
|
|
834 |
break;
|
|
835 |
case KLCmdGetEventLogCount:
|
|
836 |
*nCount = Datalen;
|
|
837 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
838 |
break;
|
|
839 |
case KLCmdGetEventLog:
|
|
840 |
*nCount = Datalen;
|
|
841 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
842 |
break;
|
61deef
|
843 |
case KLCmdGetPortInfo:
|
418cb3
|
844 |
*nCount = Datalen;
|
Q |
845 |
memcpy(pData, pPacket->Datas, Datalen);
|
61deef
|
846 |
break;
|
Q |
847 |
case KLCmdGetPortChildInfo:
|
|
848 |
*nCount = Datalen;
|
|
849 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
850 |
break;
|
|
851 |
case KLCmdGetPortChnInfo:
|
|
852 |
*nCount = Datalen;
|
|
853 |
memcpy(pData, pPacket->Datas, Datalen);
|
|
854 |
break;
|
|
855 |
case KLCmdErrRply:
|
|
856 |
ErrCode = Datalen + 1000;
|
|
857 |
*nCount = 0;
|
|
858 |
return ErrCode;
|
|
859 |
//memcpy(pData, pPacket->Datas, Datalen);
|
418cb3
|
860 |
break;
|
Q |
861 |
default:
|
|
862 |
*nCount = Datalen;
|
|
863 |
//memcpy(pData, pPacket->Datas, Datalen);
|
|
864 |
break;
|
|
865 |
}
|
|
866 |
return KL_OK;
|
|
867 |
|
|
868 |
return false;
|
|
869 |
}
|
|
870 |
|
|
871 |
int KLink1::ReadBit(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR * Value)
|
|
872 |
{
|
|
873 |
m_Dst = nDst;
|
|
874 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdRead1Bit, nType, nBitAddr);
|
|
875 |
SendPacket(m_Packetbuf, len1);
|
|
876 |
int numToRead = sizeof(stKLRplyPktHdr) + 1;
|
|
877 |
|
|
878 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
879 |
unsigned char nCmd;
|
|
880 |
unsigned short nCount = 0;
|
|
881 |
ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nCount, m_DataBuf);
|
|
882 |
Value[0] = m_DataBuf[0];
|
|
883 |
return KL_OK;
|
|
884 |
}
|
|
885 |
int KLink1::WriteBit(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR Value)
|
|
886 |
{
|
|
887 |
m_Dst = nDst;
|
|
888 |
m_DataBuf[0] = Value;
|
|
889 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWrite1Bit, nType, nBitAddr, 1, m_DataBuf);
|
|
890 |
SendPacket(m_Packetbuf, len1);
|
|
891 |
int len2 = RecvPacket(m_RecvBuf, 6);
|
|
892 |
unsigned char nCmd;
|
|
893 |
unsigned short nCount = 0;
|
|
894 |
ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nCount, m_DataBuf);
|
|
895 |
return KL_OK;
|
|
896 |
}
|
|
897 |
int KLink1::ReadBits(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR nBitCount, UCHAR * Values)
|
|
898 |
{
|
|
899 |
return KL_OK;
|
|
900 |
}
|
|
901 |
int KLink1::WriteBits(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR nBitCount, UCHAR * Values)
|
|
902 |
{
|
|
903 |
return KL_OK;
|
|
904 |
}
|
|
905 |
int KLink1::ReadBitsByWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT *Values)
|
|
906 |
{
|
|
907 |
return KL_OK;
|
|
908 |
}
|
|
909 |
int KLink1::WriteBitsByWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT *Values)
|
|
910 |
{
|
|
911 |
return KL_OK;
|
|
912 |
}
|
|
913 |
int KLink1::GetNextSeq()
|
|
914 |
{
|
|
915 |
m_nSeq++;
|
|
916 |
if (m_nSeq >= 8) m_nSeq = 0;
|
|
917 |
m_Stat1.nSEQ = m_nSeq;
|
|
918 |
return m_nSeq;
|
|
919 |
}
|
|
920 |
|
|
921 |
int KLink1::ReadDataByte(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, USHORT * nByteRead, UCHAR * Values)
|
|
922 |
{
|
|
923 |
m_Dst = nDst;
|
|
924 |
m_resultStr.Empty();
|
|
925 |
UCHAR nExpSeq = GetNextSeq();
|
|
926 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadDataByte, nType, nByteAddr / 2, nByteCount);
|
|
927 |
SendPacket(m_Packetbuf, len1);
|
|
928 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
929 |
int len2 = 0;
|
|
930 |
len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
931 |
if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
|
|
932 |
if (len2 < numToRead)
|
|
933 |
{
|
|
934 |
CString s1;
|
|
935 |
for (int i = 0; i < len2; i++)
|
|
936 |
{
|
|
937 |
s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
|
|
938 |
}
|
|
939 |
s1.Append(_T("\r\n"));
|
|
940 |
m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
|
|
941 |
m_resultStr += s1;
|
|
942 |
}
|
|
943 |
unsigned char nCmd;
|
|
944 |
unsigned short nnCount = 0;
|
|
945 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
946 |
if (res == KL_OK)
|
|
947 |
{
|
|
948 |
for (int i = 0; i < nnCount; i++)
|
|
949 |
{
|
|
950 |
Values[i] = m_DataBuf[i];
|
|
951 |
}
|
|
952 |
}
|
|
953 |
else
|
|
954 |
{
|
|
955 |
m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
|
956 |
CString s1;
|
|
957 |
s1 = GetErrDescStr(res);
|
|
958 |
m_resultStr += s1;
|
|
959 |
return res;
|
|
960 |
}
|
|
961 |
*nByteRead = nnCount;
|
|
962 |
return KL_OK;
|
|
963 |
}
|
|
964 |
|
|
965 |
int KLink1::WriteDataByte(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR * Values)
|
|
966 |
{
|
|
967 |
m_Dst = nDst;
|
|
968 |
m_resultStr.Empty();
|
|
969 |
UCHAR nExpSeq = GetNextSeq();
|
|
970 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteDataByte, nType, nByteAddr / 2, nByteCount, Values);
|
|
971 |
SendPacket(m_Packetbuf, len1);
|
|
972 |
nByteCount = 0;
|
|
973 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
974 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
975 |
// if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
976 |
if (len2 <= 0) return KL_ERR;
|
|
977 |
unsigned char nCmd;
|
|
978 |
unsigned short nnCount = 0;
|
|
979 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
980 |
return res;
|
|
981 |
}
|
|
982 |
|
|
983 |
int KLink1::ReadDataWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * nByteRead, USHORT * Values)
|
|
984 |
{
|
|
985 |
m_Dst = nDst;
|
|
986 |
m_resultStr.Empty();
|
|
987 |
UCHAR nExpSeq = GetNextSeq();
|
|
988 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadDataWord, nType, nWordAddr, nWordCount * 2);
|
|
989 |
SendPacket(m_Packetbuf, len1);
|
|
990 |
int numToRead = sizeof(stKLRplyPktHdr) + nWordCount * 2;
|
|
991 |
|
|
992 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
993 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
994 |
if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
|
|
995 |
if (len2 < numToRead)
|
|
996 |
{
|
|
997 |
CString s1;
|
|
998 |
for (int i = 0; i < len2; i++)
|
|
999 |
{
|
|
1000 |
s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
|
|
1001 |
}
|
|
1002 |
s1.Append(_T("\r\n"));
|
|
1003 |
m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
|
|
1004 |
m_resultStr += s1;
|
|
1005 |
}
|
|
1006 |
unsigned char nCmd;
|
|
1007 |
unsigned short nnCount = 0;
|
|
1008 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1009 |
if (res == KL_OK)
|
|
1010 |
{
|
|
1011 |
for (int i = 0; i < nnCount / 2; i++)
|
|
1012 |
{
|
|
1013 |
// Values[0] = m_DataBuf[0];
|
|
1014 |
Values[i] = m_DataBuf[i * 2] + (m_DataBuf[i * 2 + 1] << 8);
|
|
1015 |
}
|
|
1016 |
}
|
|
1017 |
else
|
|
1018 |
{
|
|
1019 |
m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
|
1020 |
CString s1;
|
|
1021 |
s1 = GetErrDescStr(res);
|
|
1022 |
m_resultStr += s1;
|
|
1023 |
return res;
|
|
1024 |
}
|
|
1025 |
*nByteRead = nnCount;
|
|
1026 |
return KL_OK;
|
|
1027 |
}
|
|
1028 |
|
|
1029 |
int KLink1::WriteDataWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
|
1030 |
{
|
|
1031 |
m_Dst = nDst;
|
|
1032 |
m_resultStr.Empty();
|
|
1033 |
UCHAR nExpSeq = GetNextSeq();
|
|
1034 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteDataWord, nType, nWordAddr, nWordCount, Values);
|
|
1035 |
SendPacket(m_Packetbuf, len1);
|
|
1036 |
nWordCount = 0;
|
|
1037 |
int numToRead = sizeof(stKLRplyPktHdr) + nWordCount;
|
|
1038 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1039 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1040 |
if (len2 == 0) return KL_ERR;
|
|
1041 |
unsigned char nCmd;
|
|
1042 |
unsigned short nnCount = 0;
|
|
1043 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1044 |
Values[0] = m_DataBuf[0];
|
|
1045 |
return res;
|
|
1046 |
}
|
|
1047 |
|
|
1048 |
int KLink1::ReadData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * nByteRead, USHORT * Values)
|
|
1049 |
{
|
|
1050 |
m_Dst = nDst;
|
|
1051 |
m_resultStr.Empty();
|
|
1052 |
UCHAR nExpSeq = GetNextSeq();
|
|
1053 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadData, nType, nWordAddr, nWordCount);
|
|
1054 |
SendPacket(m_Packetbuf, len1);
|
|
1055 |
int len2 = RecvPacket(m_RecvBuf, 64);
|
|
1056 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
|
|
1057 |
if (len2 == 0) return KL_ERR;
|
|
1058 |
unsigned char nCmd;
|
|
1059 |
unsigned short nnCount = 0;
|
|
1060 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1061 |
for (int i = 0; i < nnCount; i++) Values[i] = m_DataBuf[i];
|
|
1062 |
*nByteRead = nnCount;
|
|
1063 |
return res;
|
|
1064 |
|
|
1065 |
return KL_OK;
|
|
1066 |
}
|
|
1067 |
int KLink1::WriteData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
|
1068 |
{
|
|
1069 |
m_Dst = nDst;
|
|
1070 |
m_resultStr.Empty();
|
|
1071 |
UCHAR nExpSeq = GetNextSeq();
|
|
1072 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteData, nType, nWordAddr, nWordCount, Values);
|
|
1073 |
SendPacket(m_Packetbuf, len1);
|
|
1074 |
int len2 = RecvPacket(m_RecvBuf, 64);
|
|
1075 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
|
|
1076 |
if (len2 == 0) return KL_ERR;
|
|
1077 |
unsigned char nCmd;
|
|
1078 |
unsigned short nnCount = 0;
|
|
1079 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1080 |
// Values[0] = m_DataBuf[0];
|
|
1081 |
return res;
|
|
1082 |
|
|
1083 |
return KL_OK;
|
|
1084 |
}
|
|
1085 |
|
|
1086 |
int KLink1::GetInfo(UCHAR nDst, USHORT * nReadBytes, USHORT * Values)
|
|
1087 |
{
|
|
1088 |
m_Dst = nDst;
|
|
1089 |
m_resultStr.Empty();
|
|
1090 |
UCHAR nExpSeq = GetNextSeq();
|
|
1091 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetInfo, 0, 0, 0, Values);
|
|
1092 |
CString s1;
|
|
1093 |
for (int i = 0; i < len1; i++) {
|
|
1094 |
s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
|
|
1095 |
}
|
|
1096 |
//m_resultStr = s1;
|
|
1097 |
SendPacket(m_Packetbuf, len1);
|
|
1098 |
int numToRead = sizeof(stKLRplyPktHdr) + 32;
|
|
1099 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1100 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1101 |
if (len2 == 0) return KL_ERR;
|
|
1102 |
unsigned char nCmd;
|
|
1103 |
unsigned short nnCount = 0;
|
|
1104 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, Values);
|
|
1105 |
// Values[0] = m_DataBuf[0];
|
|
1106 |
*nReadBytes = nnCount;
|
|
1107 |
return res;
|
|
1108 |
|
|
1109 |
return KL_OK;
|
|
1110 |
}
|
|
1111 |
|
|
1112 |
int KLink1::GetSN(UCHAR nDst, USHORT * nReadBytes, USHORT * Values)
|
|
1113 |
{
|
|
1114 |
m_Dst = nDst;
|
|
1115 |
m_resultStr.Empty();
|
|
1116 |
UCHAR nExpSeq = GetNextSeq();
|
|
1117 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetSN, 0, 0, 4, Values);
|
|
1118 |
CString s1;
|
|
1119 |
for (int i = 0; i < len1; i++) {
|
|
1120 |
s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
|
|
1121 |
}
|
|
1122 |
m_resultStr = s1;
|
|
1123 |
SendPacket(m_Packetbuf, len1);
|
|
1124 |
int ByteCount = 4;
|
|
1125 |
int numToRead = sizeof(stKLRplyPktHdr) + ByteCount;
|
|
1126 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1127 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1128 |
if (len2 == 0) return KL_ERR;
|
|
1129 |
unsigned char nCmd;
|
|
1130 |
unsigned short nnCount = 0;
|
|
1131 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, Values);
|
|
1132 |
// Values[0] = m_DataBuf[0];
|
|
1133 |
*nReadBytes = nnCount;
|
|
1134 |
return res;
|
|
1135 |
|
|
1136 |
return KL_OK;
|
|
1137 |
return 0;
|
|
1138 |
}
|
|
1139 |
int KLink1::GetUID(UCHAR nDst, USHORT * nReadBytes, USHORT * Values)
|
|
1140 |
{
|
|
1141 |
m_Dst = nDst;
|
|
1142 |
m_resultStr.Empty();
|
|
1143 |
UCHAR nExpSeq = GetNextSeq();
|
|
1144 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetUid, 0, 0, 12, Values);
|
|
1145 |
CString s1;
|
|
1146 |
for (int i = 0; i < len1; i++) {
|
|
1147 |
s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
|
|
1148 |
}
|
|
1149 |
m_resultStr = s1;
|
|
1150 |
SendPacket(m_Packetbuf, len1);
|
|
1151 |
|
|
1152 |
int numToRead = sizeof(stKLRplyPktHdr) + 12;
|
|
1153 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1154 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1155 |
if (len2 == 0) return KL_ERR;
|
|
1156 |
unsigned char nCmd;
|
|
1157 |
unsigned short nnCount = 0;
|
|
1158 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, Values);
|
|
1159 |
// Values[0] = m_DataBuf[0];
|
|
1160 |
*nReadBytes = nnCount;
|
|
1161 |
return res;
|
|
1162 |
|
|
1163 |
return KL_OK;
|
|
1164 |
return 0;
|
|
1165 |
}
|
|
1166 |
|
|
1167 |
int KLink1::ReadFactoryData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values)
|
|
1168 |
{
|
|
1169 |
m_Dst = nDst;
|
|
1170 |
m_resultStr.Empty();
|
|
1171 |
UCHAR nExpSeq = GetNextSeq();
|
|
1172 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetFactoryData, 0, nStartAddr, nByteCount, Values);
|
|
1173 |
CString s1;
|
|
1174 |
for (int i = 0; i < len1; i++) {
|
|
1175 |
s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
|
|
1176 |
}
|
|
1177 |
m_resultStr = s1;
|
|
1178 |
SendPacket(m_Packetbuf, len1);
|
|
1179 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1180 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1181 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1182 |
if (len2 == 0) return KL_ERR;
|
|
1183 |
unsigned char nCmd;
|
|
1184 |
unsigned short nnCount = 0;
|
|
1185 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, Values);
|
|
1186 |
// Values[0] = m_DataBuf[0];
|
|
1187 |
*nReadBytes = nnCount;
|
|
1188 |
return res;
|
|
1189 |
return KL_OK;
|
|
1190 |
}
|
|
1191 |
int KLink1::WriteFactoryData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values)
|
|
1192 |
{
|
|
1193 |
|
|
1194 |
m_Dst = nDst;
|
|
1195 |
m_resultStr.Empty();
|
|
1196 |
UCHAR nExpSeq = GetNextSeq();
|
|
1197 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteFactoryData, 0, nStartAddr, nByteCount, Values);
|
|
1198 |
SendPacket(m_Packetbuf, len1);
|
|
1199 |
int nReadBytes = 0;
|
|
1200 |
int numToRead = sizeof(stKLRplyPktHdr) + nReadBytes;
|
|
1201 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1202 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1203 |
if (len2 == 0) return KL_ERR;
|
|
1204 |
unsigned char nCmd;
|
|
1205 |
unsigned short nnCount = 0;
|
|
1206 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1207 |
// Values[0] = m_DataBuf[0];
|
|
1208 |
return res;
|
|
1209 |
|
|
1210 |
return KL_OK;
|
|
1211 |
}
|
|
1212 |
|
|
1213 |
|
61deef
|
1214 |
int KLink1::ReadSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values)
|
418cb3
|
1215 |
{
|
Q |
1216 |
m_Dst = nDst;
|
|
1217 |
m_resultStr.Empty();
|
|
1218 |
UCHAR nExpSeq = GetNextSeq();
|
61deef
|
1219 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadSysCfg, nType, nStartAddr, nByteCount, Values);
|
418cb3
|
1220 |
CString s1;
|
Q |
1221 |
for (int i = 0; i < len1; i++) {
|
|
1222 |
s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
|
|
1223 |
}
|
|
1224 |
m_resultStr = s1;
|
|
1225 |
SendPacket(m_Packetbuf, len1);
|
|
1226 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1227 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1228 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1229 |
if (len2 == 0) return KL_ERR;
|
|
1230 |
unsigned char nCmd;
|
|
1231 |
unsigned short nnCount = 0;
|
|
1232 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, Values);
|
|
1233 |
// Values[0] = m_DataBuf[0];
|
|
1234 |
*nReadBytes = nnCount;
|
|
1235 |
return res;
|
|
1236 |
return KL_OK;
|
|
1237 |
}
|
61deef
|
1238 |
int KLink1::WriteSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values)
|
418cb3
|
1239 |
{
|
Q |
1240 |
m_Dst = nDst;
|
|
1241 |
m_resultStr.Empty();
|
|
1242 |
UCHAR nExpSeq = GetNextSeq();
|
61deef
|
1243 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteSysCfg, nType, nStartAddr, nByteCount, Values);
|
418cb3
|
1244 |
SendPacket(m_Packetbuf, len1);
|
Q |
1245 |
int nReadBytes = 0;
|
|
1246 |
int numToRead = sizeof(stKLRplyPktHdr) + nReadBytes;
|
|
1247 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1248 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1249 |
if (len2 == 0) return KL_ERR;
|
|
1250 |
unsigned char nCmd;
|
|
1251 |
unsigned short nnCount = 0;
|
|
1252 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1253 |
// Values[0] = m_DataBuf[0];
|
|
1254 |
return res;
|
|
1255 |
|
|
1256 |
return KL_OK;
|
|
1257 |
}
|
|
1258 |
int KLink1::GetEventLogCount(UCHAR nDst, int * nCount)
|
|
1259 |
{
|
|
1260 |
m_Dst = nDst;
|
|
1261 |
m_resultStr.Empty();
|
|
1262 |
UCHAR nExpSeq = GetNextSeq();
|
|
1263 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetEventLogCount, 0);
|
|
1264 |
SendPacket(m_Packetbuf, len1);
|
|
1265 |
int len2 = RecvPacket(m_RecvBuf, 64);
|
|
1266 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
|
|
1267 |
if (len2 == 0) return KL_ERR;
|
|
1268 |
unsigned char nCmd;
|
|
1269 |
unsigned short nnCount = 0;
|
|
1270 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1271 |
nCount[0] = *(int *)m_DataBuf;
|
|
1272 |
return res;
|
|
1273 |
|
|
1274 |
return KL_OK;
|
|
1275 |
}
|
|
1276 |
|
|
1277 |
int KLink1::GetEventLog(UCHAR nDst, int nStartIndex, int nCount, stEventLog * theEventLogs)
|
|
1278 |
{
|
|
1279 |
m_Dst = nDst;
|
|
1280 |
m_resultStr.Empty();
|
|
1281 |
UCHAR nExpSeq = GetNextSeq();
|
|
1282 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetEventLog, 0, nStartIndex, nCount, 0);
|
|
1283 |
SendPacket(m_Packetbuf, len1);
|
|
1284 |
int len2 = RecvPacket(m_RecvBuf, 64);
|
|
1285 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
|
|
1286 |
if (len2 == 0) return KL_ERR;
|
|
1287 |
unsigned char nCmd;
|
|
1288 |
unsigned short nnCount = 0;
|
|
1289 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1290 |
|
|
1291 |
memcpy(theEventLogs, m_DataBuf, nCount * sizeof(stEventLog));
|
|
1292 |
|
|
1293 |
return res;
|
|
1294 |
|
|
1295 |
return KL_OK;
|
|
1296 |
}
|
|
1297 |
|
|
1298 |
int KLink1::GetDateTime32(UCHAR nDst, UINT * pValue)
|
|
1299 |
{
|
|
1300 |
int res = KL_OK;
|
|
1301 |
unsigned short nCount;
|
|
1302 |
res = ReadDataByte(nDst, KLDataTypeSDT, 36, 4, &nCount, (UCHAR *)pValue);
|
|
1303 |
return res;
|
|
1304 |
|
|
1305 |
}
|
|
1306 |
|
|
1307 |
int KLink1::SetDateTime32(UCHAR nDst, UINT Value)
|
|
1308 |
{
|
|
1309 |
int res = KL_OK;
|
|
1310 |
res = WriteDataByte(nDst, KLDataTypeSDT, 36, 4, (UCHAR *)&Value);
|
|
1311 |
return res;
|
|
1312 |
}
|
|
1313 |
|
df0321
|
1314 |
int KLink1::GetMode(UCHAR nDst, UCHAR nType, UCHAR * value)
|
418cb3
|
1315 |
{
|
Q |
1316 |
int res = KL_OK;
|
|
1317 |
// res = ReadDataByte(nDst, 4, KLDataTypeSDT, 36, (UCHAR *)pValue);
|
|
1318 |
m_Dst = nDst;
|
|
1319 |
UCHAR nExpSeq = GetNextSeq();
|
|
1320 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetMode, nType);
|
|
1321 |
SendPacket(m_Packetbuf, len1);
|
|
1322 |
int len2 = RecvPacket(m_RecvBuf, 64);
|
|
1323 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
|
|
1324 |
if (len2 == 0) return KL_ERR;
|
|
1325 |
unsigned char nCmd;
|
|
1326 |
unsigned short nnCount = 0;
|
|
1327 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
df0321
|
1328 |
if (nnCount > 0) { *value = m_DataBuf[0]; }
|
418cb3
|
1329 |
return res;
|
Q |
1330 |
|
|
1331 |
}
|
|
1332 |
|
|
1333 |
|
|
1334 |
int KLink1::ChangeMode(UCHAR nDst, UCHAR nType)
|
|
1335 |
{
|
|
1336 |
int res = KL_OK;
|
|
1337 |
// res = WriteDataByte(nDst, 4, KLDataTypeSDT, 36, (UCHAR *)&Value);
|
|
1338 |
m_Dst = nDst;
|
|
1339 |
UCHAR nExpSeq = GetNextSeq();
|
|
1340 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdChgMode, nType);
|
|
1341 |
SendPacket(m_Packetbuf, len1);
|
|
1342 |
int len2 = RecvPacket(m_RecvBuf, 64);
|
|
1343 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
|
|
1344 |
if (len2 == 0) return KL_ERR;
|
|
1345 |
unsigned char nCmd;
|
|
1346 |
unsigned short nnCount = 0;
|
|
1347 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1348 |
return res;
|
|
1349 |
|
|
1350 |
}
|
|
1351 |
|
|
1352 |
int KLink1::BlinkLED(UCHAR nDst, UCHAR nSecond)
|
|
1353 |
{
|
|
1354 |
int res = KL_OK;
|
|
1355 |
// res = WriteDataByte(nDst, 4, KLDataTypeSDT, 36, (UCHAR *)&Value);
|
|
1356 |
m_Dst = nDst;
|
|
1357 |
UCHAR nExpSeq = GetNextSeq();
|
|
1358 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdBlinkLED, nSecond);
|
|
1359 |
SendPacket(m_Packetbuf, len1);
|
|
1360 |
int nByteCount = 0;
|
|
1361 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1362 |
|
|
1363 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1364 |
if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1365 |
if (len2 == 0) return KL_ERR;
|
|
1366 |
unsigned char nCmd;
|
|
1367 |
unsigned short nnCount = 0;
|
|
1368 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1369 |
return res;
|
|
1370 |
|
|
1371 |
}
|
|
1372 |
|
61deef
|
1373 |
int KLink1::ReadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
418cb3
|
1374 |
{
|
Q |
1375 |
int res = KL_OK;
|
|
1376 |
m_Dst = nDst;
|
|
1377 |
UCHAR nExpSeq = GetNextSeq();
|
|
1378 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadProgram, nType, nWordAddr, nWordCount);
|
|
1379 |
SendPacket(m_Packetbuf, len1);
|
|
1380 |
int nByteCount = nWordCount;
|
|
1381 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1382 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1383 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1384 |
if (len2 <= 0) return KL_ERR;
|
|
1385 |
unsigned char nCmd;
|
|
1386 |
unsigned short nnCount = 0;
|
|
1387 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
61deef
|
1388 |
if (res == KL_OK) {
|
Q |
1389 |
unsigned char* values2 = (unsigned char*)Values;
|
|
1390 |
for (int i = 0; i < nnCount; i++) values2[i] = m_DataBuf[i];
|
|
1391 |
}
|
418cb3
|
1392 |
return res;
|
Q |
1393 |
|
|
1394 |
}
|
|
1395 |
|
61deef
|
1396 |
int KLink1::StartDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgBytes, USHORT nCRC)
|
418cb3
|
1397 |
{
|
Q |
1398 |
int res = KL_OK;
|
|
1399 |
m_Dst = nDst;
|
|
1400 |
UCHAR nExpSeq = GetNextSeq();
|
61deef
|
1401 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdStartProgram, nType, nProgBytes,nCRC);
|
418cb3
|
1402 |
SendPacket(m_Packetbuf, len1);
|
Q |
1403 |
int len2 = RecvPacket(m_RecvBuf, 6);
|
|
1404 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6); }
|
|
1405 |
if (len2 <= 0) return KL_ERR;
|
|
1406 |
unsigned char nCmd;
|
|
1407 |
unsigned short nnCount = 0;
|
|
1408 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1409 |
return res;
|
|
1410 |
|
|
1411 |
}
|
|
1412 |
|
61deef
|
1413 |
int KLink1::DownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, USHORT * Values)
|
418cb3
|
1414 |
{
|
Q |
1415 |
int res = KL_OK;
|
|
1416 |
m_Dst = nDst;
|
|
1417 |
UCHAR nExpSeq = GetNextSeq();
|
61deef
|
1418 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteProgram, nType, nByteAddr, nByteCount, Values);
|
Q |
1419 |
|
|
1420 |
SendPacket(m_Packetbuf, len1);
|
|
1421 |
int len2 = RecvPacket(m_RecvBuf, 6, 10);
|
|
1422 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
|
|
1423 |
if (len2 <= 0) return KL_ERR;
|
|
1424 |
unsigned char nCmd;
|
|
1425 |
unsigned short nnCount = 0;
|
|
1426 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1427 |
// Values[0] = m_DataBuf[0];
|
|
1428 |
return res;
|
|
1429 |
|
|
1430 |
}
|
|
1431 |
|
|
1432 |
int KLink1::FinishDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgSteps, USHORT nCRC)
|
|
1433 |
{
|
|
1434 |
int res = KL_OK;
|
|
1435 |
|
|
1436 |
m_Dst = nDst;
|
|
1437 |
UCHAR nExpSeq = GetNextSeq();
|
|
1438 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdFinishProgram, nType, nProgSteps,nCRC);
|
|
1439 |
SendPacket(m_Packetbuf, len1);
|
|
1440 |
int len2 = RecvPacket(m_RecvBuf, 6,10);
|
|
1441 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
|
|
1442 |
if (len2 <= 0) return KL_ERR;
|
|
1443 |
unsigned char nCmd;
|
|
1444 |
unsigned short nnCount = 0;
|
|
1445 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1446 |
return res;
|
|
1447 |
}
|
|
1448 |
|
|
1449 |
int KLink1::ReadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
|
|
1450 |
{
|
|
1451 |
int res = KL_OK;
|
|
1452 |
m_Dst = nDst;
|
|
1453 |
UCHAR nExpSeq = GetNextSeq();
|
|
1454 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadPLCAnno, nType, nByteAddr, nByteCount);
|
|
1455 |
SendPacket(m_Packetbuf, len1);
|
|
1456 |
// int nByteCount = nByteCount;
|
|
1457 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1458 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1459 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1460 |
if (len2 <= 0) return KL_ERR;
|
|
1461 |
unsigned char nCmd;
|
|
1462 |
unsigned short nnCount = 0;
|
|
1463 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1464 |
if (res == KL_OK) {
|
|
1465 |
unsigned char* values2 = (unsigned char*)Values;
|
|
1466 |
for (int i = 0; i < nnCount; i++) values2[i] = m_DataBuf[i];
|
|
1467 |
}
|
|
1468 |
return res;
|
|
1469 |
|
|
1470 |
}
|
|
1471 |
|
|
1472 |
int KLink1::StartDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nBytes, USHORT nCRC)
|
|
1473 |
{
|
|
1474 |
int res = KL_OK;
|
|
1475 |
m_Dst = nDst;
|
|
1476 |
UCHAR nExpSeq = GetNextSeq();
|
|
1477 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdStartPLCAnno, nType, nBytes, nCRC);
|
|
1478 |
SendPacket(m_Packetbuf, len1);
|
|
1479 |
int len2 = RecvPacket(m_RecvBuf, 6);
|
|
1480 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6); }
|
|
1481 |
if (len2 <= 0) return KL_ERR;
|
|
1482 |
unsigned char nCmd;
|
|
1483 |
unsigned short nnCount = 0;
|
|
1484 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1485 |
return res;
|
|
1486 |
|
|
1487 |
}
|
|
1488 |
|
|
1489 |
int KLink1::DownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
|
|
1490 |
{
|
|
1491 |
int res = KL_OK;
|
|
1492 |
m_Dst = nDst;
|
|
1493 |
UCHAR nExpSeq = GetNextSeq();
|
|
1494 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWritePLCAnno, nType, nByteAddr, nByteCount, Values);
|
418cb3
|
1495 |
|
Q |
1496 |
SendPacket(m_Packetbuf, len1);
|
|
1497 |
int len2 = RecvPacket(m_RecvBuf, 6);
|
|
1498 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
|
|
1499 |
if (len2 <= 0) return KL_ERR;
|
|
1500 |
unsigned char nCmd;
|
|
1501 |
unsigned short nnCount = 0;
|
|
1502 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1503 |
// Values[0] = m_DataBuf[0];
|
|
1504 |
return res;
|
|
1505 |
|
|
1506 |
}
|
|
1507 |
|
61deef
|
1508 |
int KLink1::FinishDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteSize, USHORT nCRC)
|
418cb3
|
1509 |
{
|
Q |
1510 |
int res = KL_OK;
|
|
1511 |
|
|
1512 |
m_Dst = nDst;
|
|
1513 |
UCHAR nExpSeq = GetNextSeq();
|
61deef
|
1514 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdFinishPLCAnno, nType, nByteSize, nCRC);
|
418cb3
|
1515 |
SendPacket(m_Packetbuf, len1);
|
Q |
1516 |
int len2 = RecvPacket(m_RecvBuf, 6);
|
|
1517 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
|
|
1518 |
if (len2 <= 0) return KL_ERR;
|
|
1519 |
unsigned char nCmd;
|
|
1520 |
unsigned short nnCount = 0;
|
|
1521 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1522 |
return res;
|
|
1523 |
}
|
|
1524 |
|
|
1525 |
int KLink1::ReadRunStat(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
|
1526 |
{
|
|
1527 |
int res = KL_OK;
|
|
1528 |
m_Dst = nDst;
|
|
1529 |
UCHAR nExpSeq = GetNextSeq();
|
|
1530 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadRunStat, nType, nWordAddr, nWordCount);
|
|
1531 |
SendPacket(m_Packetbuf, len1);
|
|
1532 |
int nByteCount = nWordCount;
|
|
1533 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1534 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1535 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1536 |
if (len2 <= 0) return KL_ERR;
|
|
1537 |
unsigned char nCmd;
|
|
1538 |
unsigned short nnCount = 0;
|
|
1539 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1540 |
unsigned char * values2 = (unsigned char *)Values;
|
|
1541 |
for (int i = 0; i < nnCount; i++) values2[i] = m_DataBuf[i];
|
|
1542 |
return res;
|
|
1543 |
|
|
1544 |
}
|
|
1545 |
|
|
1546 |
int KLink1::ClearStatistics(UCHAR nDst, UCHAR nType)
|
|
1547 |
{
|
|
1548 |
int res = KL_OK;
|
|
1549 |
m_Dst = nDst;
|
|
1550 |
UCHAR nExpSeq = GetNextSeq();
|
|
1551 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdClearRunStat, nType);
|
|
1552 |
SendPacket(m_Packetbuf, len1);
|
|
1553 |
int nByteCount = 0;
|
|
1554 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1555 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1556 |
if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1557 |
if (len2 <= 0) return KL_ERR;
|
|
1558 |
unsigned char nCmd;
|
|
1559 |
unsigned short nnCount = 0;
|
|
1560 |
res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1561 |
return res;
|
|
1562 |
|
|
1563 |
}
|
61deef
|
1564 |
|
Q |
1565 |
int KLink1::ResetDevice(UCHAR nDst, UCHAR nType)
|
|
1566 |
{
|
|
1567 |
m_Dst = nDst;
|
|
1568 |
m_resultStr.Empty();
|
|
1569 |
UCHAR nExpSeq = GetNextSeq();
|
|
1570 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdResetMachine, nType, 0, 0, 0);
|
|
1571 |
SendPacket(m_Packetbuf, len1);
|
|
1572 |
int nByteCount = 0;
|
|
1573 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1574 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1575 |
// if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1576 |
if (len2 <= 0) return KL_TIMEOUT;
|
|
1577 |
unsigned char nCmd;
|
|
1578 |
unsigned short nnCount = 0;
|
|
1579 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1580 |
return res;
|
|
1581 |
}
|
|
1582 |
|
|
1583 |
int KLink1::WriteFirmware(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
|
|
1584 |
{
|
|
1585 |
m_Dst = nDst;
|
|
1586 |
m_resultStr.Empty();
|
|
1587 |
UCHAR nExpSeq = GetNextSeq();
|
|
1588 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteFirmware, nType, nByteAddr , nByteCount, Values);
|
|
1589 |
SendPacket(m_Packetbuf, len1);
|
|
1590 |
nByteCount = 0;
|
|
1591 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1592 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1593 |
// if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1594 |
m_resultStr.Format(_T("S %d, R %d "), len1, len2);
|
|
1595 |
if (len2 <= 0) return KL_TIMEOUT;
|
|
1596 |
m_resultStr.Append(_T("\r\n"));
|
|
1597 |
for (int j = 0; j < len2; j++) {
|
|
1598 |
m_resultStr.AppendFormat(_T("%02X "), m_RecvBuf[j]);
|
|
1599 |
}
|
|
1600 |
unsigned char nCmd;
|
|
1601 |
unsigned short nnCount = 0;
|
|
1602 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1603 |
return res;
|
|
1604 |
}
|
|
1605 |
|
|
1606 |
int KLink1::WriteFirmInfo(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
|
|
1607 |
{
|
|
1608 |
m_Dst = nDst;
|
|
1609 |
m_resultStr.Empty();
|
|
1610 |
UCHAR nExpSeq = GetNextSeq();
|
|
1611 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteFirmInfo, nType, nByteAddr , nByteCount, Values);
|
|
1612 |
SendPacket(m_Packetbuf, len1);
|
|
1613 |
nByteCount = 0;
|
|
1614 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1615 |
int len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1616 |
// if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
|
1617 |
if (len2 <= 0) return KL_TIMEOUT;
|
|
1618 |
unsigned char nCmd;
|
|
1619 |
unsigned short nnCount = 0;
|
|
1620 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1621 |
return res;
|
|
1622 |
}
|
|
1623 |
|
|
1624 |
int KLink1::GetPortInfo(UCHAR nDst, UCHAR nType, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values)
|
|
1625 |
{
|
|
1626 |
m_Dst = nDst;
|
|
1627 |
m_resultStr.Empty();
|
|
1628 |
UCHAR nExpSeq = GetNextSeq();
|
|
1629 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetPortInfo, nType, 0, 0);
|
|
1630 |
SendPacket(m_Packetbuf, len1);
|
|
1631 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1632 |
int len2 = 0;
|
|
1633 |
len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1634 |
if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
|
|
1635 |
if (len2 < numToRead)
|
|
1636 |
{
|
|
1637 |
CString s1;
|
|
1638 |
for (int i = 0; i < len2; i++)
|
|
1639 |
{
|
|
1640 |
s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
|
|
1641 |
}
|
|
1642 |
s1.Append(_T("\r\n"));
|
|
1643 |
m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
|
|
1644 |
m_resultStr += s1;
|
|
1645 |
}
|
|
1646 |
unsigned char nCmd;
|
|
1647 |
unsigned short nnCount = 0;
|
|
1648 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1649 |
if (res == KL_OK)
|
|
1650 |
{
|
|
1651 |
memcpy(Values, m_DataBuf, nnCount);
|
|
1652 |
}
|
|
1653 |
else
|
|
1654 |
{
|
|
1655 |
m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
|
1656 |
CString s1;
|
|
1657 |
s1 = GetErrDescStr(res);
|
|
1658 |
m_resultStr += s1;
|
|
1659 |
return res;
|
|
1660 |
}
|
|
1661 |
*nByteRead = nnCount;
|
|
1662 |
return KL_OK;
|
|
1663 |
}
|
|
1664 |
|
|
1665 |
int KLink1::GetPortChildInfo(UCHAR nDst, UCHAR nType, UCHAR nChildId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values)
|
|
1666 |
{
|
|
1667 |
m_Dst = nDst;
|
|
1668 |
m_resultStr.Empty();
|
|
1669 |
UCHAR nExpSeq = GetNextSeq();
|
|
1670 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetPortChildInfo, nType, nChildId, 0);
|
|
1671 |
SendPacket(m_Packetbuf, len1);
|
|
1672 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1673 |
int len2 = 0;
|
|
1674 |
len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1675 |
if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
|
|
1676 |
if (len2 < numToRead)
|
|
1677 |
{
|
|
1678 |
CString s1;
|
|
1679 |
for (int i = 0; i < len2; i++)
|
|
1680 |
{
|
|
1681 |
s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
|
|
1682 |
}
|
|
1683 |
s1.Append(_T("\r\n"));
|
|
1684 |
m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
|
|
1685 |
m_resultStr += s1;
|
|
1686 |
}
|
|
1687 |
unsigned char nCmd;
|
|
1688 |
unsigned short nnCount = 0;
|
|
1689 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1690 |
if (res == KL_OK)
|
|
1691 |
{
|
|
1692 |
memcpy(Values, m_DataBuf, nnCount);
|
|
1693 |
}
|
|
1694 |
else
|
|
1695 |
{
|
|
1696 |
m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
|
1697 |
CString s1;
|
|
1698 |
s1 = GetErrDescStr(res);
|
|
1699 |
m_resultStr += s1;
|
|
1700 |
return res;
|
|
1701 |
}
|
|
1702 |
*nByteRead = nnCount;
|
|
1703 |
return KL_OK;
|
|
1704 |
}
|
|
1705 |
|
|
1706 |
int KLink1::GetPortChnInfo(UCHAR nDst, UCHAR nType, UCHAR nChnId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values)
|
|
1707 |
{
|
|
1708 |
m_Dst = nDst;
|
|
1709 |
m_resultStr.Empty();
|
|
1710 |
UCHAR nExpSeq = GetNextSeq();
|
|
1711 |
int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetPortChnInfo, nType, nChnId, 0);
|
|
1712 |
SendPacket(m_Packetbuf, len1);
|
|
1713 |
int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
|
1714 |
int len2 = 0;
|
|
1715 |
len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1716 |
if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
|
|
1717 |
if (len2 < numToRead)
|
|
1718 |
{
|
|
1719 |
CString s1;
|
|
1720 |
for (int i = 0; i < len2; i++)
|
|
1721 |
{
|
|
1722 |
s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
|
|
1723 |
}
|
|
1724 |
s1.Append(_T("\r\n"));
|
|
1725 |
m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
|
|
1726 |
m_resultStr += s1;
|
|
1727 |
}
|
|
1728 |
unsigned char nCmd;
|
|
1729 |
unsigned short nnCount = 0;
|
|
1730 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1731 |
if (res == KL_OK)
|
|
1732 |
{
|
|
1733 |
memcpy(Values, m_DataBuf, nnCount);
|
|
1734 |
}
|
|
1735 |
else
|
|
1736 |
{
|
|
1737 |
m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
|
1738 |
CString s1;
|
|
1739 |
s1 = GetErrDescStr(res);
|
|
1740 |
m_resultStr += s1;
|
|
1741 |
return res;
|
|
1742 |
}
|
|
1743 |
*nByteRead = nnCount;
|
|
1744 |
return KL_OK;
|
|
1745 |
}
|
|
1746 |
|
|
1747 |
int KLink1::RunRemoteReq(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nReqId, UCHAR nParam,USHORT nByteAddr, UCHAR nByteCount, void * pData)
|
|
1748 |
{
|
|
1749 |
m_Dst = nDst;
|
|
1750 |
m_resultStr.Empty();
|
|
1751 |
UCHAR nExpSeq = GetNextSeq();
|
|
1752 |
int len1 = MakeRemoteReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, nPort, nChnId, nReqId,nParam,nByteAddr,nByteCount,pData);
|
|
1753 |
SendPacket(m_Packetbuf, len1);
|
|
1754 |
int numToRead = sizeof(stKLRplyPktHdr) + 0;
|
|
1755 |
int len2 = 0;
|
|
1756 |
len2 = RecvPacket(m_RecvBuf, numToRead);
|
|
1757 |
if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
|
|
1758 |
if (len2 < numToRead)
|
|
1759 |
{
|
|
1760 |
CString s1;
|
|
1761 |
for (int i = 0; i < len2; i++)
|
|
1762 |
{
|
|
1763 |
s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
|
|
1764 |
}
|
|
1765 |
s1.Append(_T("\r\n"));
|
|
1766 |
m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
|
|
1767 |
m_resultStr += s1;
|
|
1768 |
}
|
|
1769 |
unsigned char nCmd;
|
|
1770 |
unsigned short nnCount = 0;
|
|
1771 |
int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
|
1772 |
if (res == KL_OK)
|
|
1773 |
{
|
|
1774 |
}
|
|
1775 |
else
|
|
1776 |
{
|
|
1777 |
m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
|
1778 |
CString s1;
|
|
1779 |
s1 = GetErrDescStr(res);
|
|
1780 |
m_resultStr += s1;
|
|
1781 |
return res;
|
|
1782 |
}
|
|
1783 |
return KL_OK;
|
|
1784 |
|
|
1785 |
}
|
|
1786 |
|
|
1787 |
int KLink1::RmoteBlinkLED(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nSecond)
|
|
1788 |
{
|
|
1789 |
return RunRemoteReq(nDst, nPort, nChnId, ReqBlinkLED, nSecond,0,0,0);
|
|
1790 |
}
|
|
1791 |
|
|
1792 |
|
|
1793 |
|
|
1794 |
|