00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #if !defined(_FEDM_NO_PD_SUPPORT)
00033
00034 #include "FedmIscPeripheralDevice.h"
00035 #include "../FEDM_ISCReader.h"
00036 #include "feisc.h"
00037
00038
00039
00040
00041
00042
00044
00046
00047 FedmIscPeripheralDevice::FedmIscPeripheralDevice(FEDM_ISCReader* pReader,
00048 unsigned char ucBusAdr,
00049 unsigned char ucPort,
00050 int iPDType)
00051 {
00052 m_DeviceInfo.Init();
00053
00054
00055 m_ucBusAdr = ucBusAdr;
00056 m_ucPort = ucPort;
00057
00058
00059 m_pReader = pReader;
00060
00061 m_iLastError = 0;
00062 m_ucLastStatus = 0;
00063
00064 m_iPDType = iPDType;
00065
00066
00067
00068 m_iReaderHnd = 0;
00069
00070
00071
00072 memset(&m_ucSendData[0], 0x00, sizeof(m_ucSendData));
00073 m_iSendDataLen = 0;
00074 memset(&m_ucSendProt[0], 0x00, sizeof(m_ucSendProt));
00075 m_iSendProtLen = 0 ;
00076 memset(&m_ucRspProt[0], 0x00, sizeof(m_ucRspProt));
00077 m_iRspProtLen = 0;
00078 memset(&m_ucRspData[0], 0x00, sizeof(m_ucRspData));
00079 m_iRspDataLen = 0;
00080
00081 m_iReaderHnd = FEISC_NewReader(0);
00082 FEISC_SetReaderPara(m_iReaderHnd, "FrameSupport","Advanced");
00083 }
00084
00086
00088
00089 FedmIscPeripheralDevice::~FedmIscPeripheralDevice()
00090 {
00091 FEISC_DeleteReader(m_iReaderHnd);
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 int FedmIscPeripheralDevice::Reset()
00108 {
00109 int iBack = 0;
00110 unsigned char ucRecBusAddr = 0x00;
00111 unsigned char ucCmd = 0x00;
00112
00113
00114
00115 m_iSendProtLen = FEISC_BuildSendProtocol(m_iReaderHnd, m_ucBusAdr, FEISC_CPU_RESET, m_ucSendData , 0, m_ucSendProt, 0);
00116 if(m_iSendProtLen <= 0)
00117 {
00118 FEDM_RETURN(m_iSendProtLen);
00119 }
00120
00121
00122 iBack = FEISC_0x9F_Piggyback_Command(m_pReader->GetReaderHnd(),m_pReader->GetBusAddress(), 0x00, FEDM_ISC_TYPE_ANT_GPC, FEDM_ISC_PD_PORT_TYPE_RS4XX, m_ucSendProt, m_iSendProtLen, m_ucRspProt, &m_iRspProtLen);
00123 if(iBack < 0)
00124 {
00125 FEDM_RETURN(iBack);
00126 }
00127 else if(iBack == 0x20)
00128 {
00129 FEDM_RETURN(iBack);
00130 }
00131
00132
00133 iBack = FEISC_SplitRecProtocol(m_iReaderHnd, m_ucRspProt, m_iRspProtLen, &ucRecBusAddr, &ucCmd, m_ucRspData, &m_iRspDataLen, 0);
00134 if(iBack != 0)
00135 {
00136 FEDM_RETURN(iBack);
00137 }
00138
00139 FEDM_RETURN(FEDM_OK);
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 FEDM_ISC_PERIPHERAL_DEVICE_INFO* FedmIscPeripheralDevice::ReadInfo()
00161 {
00162 int iBack = 0;
00163 unsigned char ucRecBusAddr = 0x00;
00164 unsigned char ucCmd = 0x00;
00165 unsigned char ucDevice = 0x00;
00166
00167 m_DeviceInfo.Init();
00168
00169 switch(m_iPDType)
00170 {
00171 case FEDM_ISC_PD_TYPE_PEOPLE_COUNTER:
00172 case FEDM_ISC_PD_TYPE_EXTERNAL_IO:
00173 ucDevice = FEDM_ISC_TYPE_ANT_GPC;
00174 break;
00175 SetLastError(FEDM_ERROR_UNKNOWN_READER_TYPE);
00176 return NULL;
00177 default:
00178
00179 break;
00180 }
00181
00182
00183
00184
00185
00186
00187 m_ucSendData[0] = 0x00;
00188
00189 FEDM_CHK7(m_iSendProtLen,FEISC_BuildSendProtocol(m_pReader->GetReaderHnd(), m_ucBusAdr, FEISC_READER_INFO, m_ucSendData , 1, m_ucSendProt, 0));
00190 FEDM_CHK7(iBack,FEISC_0x9F_Piggyback_Command(m_pReader->GetReaderHnd(),m_pReader->GetBusAddress(), 0x00, ucDevice, m_ucPort, m_ucSendProt, m_iSendProtLen, m_ucRspProt, &m_iRspProtLen));
00191 if(iBack==0x00 || iBack==0x84 || iBack==0xF1)
00192 {
00193
00194 FEDM_CHK7(iBack, FEISC_SplitRecProtocol(m_pReader->GetReaderHnd(), m_ucRspProt, m_iRspProtLen, &ucRecBusAddr, &ucCmd, m_ucRspData, &m_iRspDataLen, 0));
00195 if(m_iRspDataLen > 0)
00196 {
00197 memcpy(m_DeviceInfo.ucSwVer, m_ucRspData, 13);
00198 m_DeviceInfo.bIsMode0x00Read = true;
00199 }
00200 }
00201 else if(iBack==0x19)
00202 {
00203 this->SetLastError(iBack);
00204 return NULL;
00205 }
00206 else if(iBack == 0x20)
00207 {
00208 this->SetLastError(iBack);
00209 return NULL;
00210 }
00211
00212
00213
00214
00215
00216 m_ucSendData[0] = 0x10;
00217
00218 FEDM_CHK7(m_iSendProtLen,FEISC_BuildSendProtocol(m_pReader->GetReaderHnd(), m_ucBusAdr, FEISC_READER_INFO, m_ucSendData , 1, m_ucSendProt, 0));
00219 FEDM_CHK7(iBack,FEISC_0x9F_Piggyback_Command(m_pReader->GetReaderHnd(),m_pReader->GetBusAddress(), 0x00, ucDevice, m_ucPort, m_ucSendProt, m_iSendProtLen, m_ucRspProt, &m_iRspProtLen));
00220 if(iBack==0x00 || iBack==0x84 || iBack==0xF1)
00221 {
00222
00223 FEDM_CHK7(iBack, FEISC_SplitRecProtocol(m_pReader->GetReaderHnd(), m_ucRspProt, m_iRspProtLen, &ucRecBusAddr, &ucCmd, m_ucRspData, &m_iRspDataLen, 0));
00224 if(m_iRspDataLen > 0)
00225 {
00226 memcpy(m_DeviceInfo.ucHwInfo, m_ucRspData, 11);
00227 m_DeviceInfo.bIsMode0x10Read = true;
00228 }
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 m_ucSendData[0] = 0x60;
00285
00286 FEDM_CHK7(m_iSendProtLen,FEISC_BuildSendProtocol(m_pReader->GetReaderHnd(), m_ucBusAdr, FEISC_READER_INFO, m_ucSendData , 1, m_ucSendProt, 0));
00287 FEDM_CHK7(iBack,FEISC_0x9F_Piggyback_Command(m_pReader->GetReaderHnd(),m_pReader->GetBusAddress(), 0x00, ucDevice, m_ucPort, m_ucSendProt, m_iSendProtLen, m_ucRspProt, &m_iRspProtLen));
00288 if(iBack==0x00 || iBack==0xF1)
00289 {
00290
00291 FEDM_CHK7(iBack, FEISC_SplitRecProtocol(m_pReader->GetReaderHnd(), m_ucRspProt, m_iRspProtLen, &ucRecBusAddr, &ucCmd, m_ucRspData, &m_iRspDataLen, 0));
00292 if(m_iRspDataLen > 0)
00293 {
00294 memcpy(&m_DeviceInfo.ucNoOfInputs, m_ucRspData, 3);
00295 m_DeviceInfo.bIsMode0x60Read = true;
00296 }
00297 }
00298
00299 SetLastError(FEDM_OK);
00300 return &m_DeviceInfo;
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 int FedmIscPeripheralDevice::GetPDType()
00315 {
00316 return m_iPDType;
00317 }
00318
00319 unsigned char FedmIscPeripheralDevice::GetBusAddress()
00320 {
00321 return m_ucBusAdr;
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 FEDM_ISCReader* FedmIscPeripheralDevice::GetReaderObject()
00336 {
00337 return m_pReader;
00338 }
00339
00340
00342
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 int FedmIscPeripheralDevice::GetLastError()
00357 {
00358 return m_iLastError;
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 unsigned char FedmIscPeripheralDevice::GetLastStatus()
00374 {
00375 return m_ucLastStatus;
00376 }
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 const char* FedmIscPeripheralDevice::GetErrorText(int iErrorCode)
00391 {
00392 if(iErrorCode == 0)
00393 {
00394 return "OK";
00395 }
00396 else
00397 {
00398
00399 if(m_pReader != NULL)
00400 {
00401 return m_pReader->GetErrorText(iErrorCode);
00402 }
00403 }
00404
00405 return "";
00406 }
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 const char* FedmIscPeripheralDevice::GetStatusText(unsigned char ucStatus)
00421 {
00422 int iBack = 0 ;
00423 static char cStatusText[256];
00424
00425
00426 iBack = FEISC_GetStatusText(ucStatus, cStatusText);
00427 if(iBack == 0)
00428 {
00429 return cStatusText;
00430 }
00431 else
00432 {
00433 return "";
00434 }
00435 }
00436
00437
00439
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452 void FedmIscPeripheralDevice::SetLastError(int iError)
00453 {
00454 if(iError < 0)
00455 m_iLastError = iError;
00456 else
00457 m_ucLastStatus = (unsigned char)iError;
00458 }
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471 void FedmIscPeripheralDevice::BuildInfoReport(string& sReport)
00472 {
00473 if(m_DeviceInfo.bIsMode0x00Read)
00474 Add0x00InfoText(sReport);
00475
00476 if(m_DeviceInfo.bIsMode0x10Read)
00477 Add0x10InfoText(sReport);
00478
00479 if(m_DeviceInfo.bIsMode0x60Read)
00480 Add0x60InfoText(sReport);
00481 }
00482
00483
00484
00485 void FedmIscPeripheralDevice::Add0x00InfoText(string& sReport)
00486 {
00487 char cBuffer[64];
00488 unsigned int uiRxBufLen = 0;
00489 unsigned int uiTxBufLen = 0;
00490
00491 uiRxBufLen = (m_DeviceInfo.ucRxBufferSize[0]<<8) + m_DeviceInfo.ucRxBufferSize[1];
00492 uiTxBufLen = (m_DeviceInfo.ucTxBufferSize[0]<<8) + m_DeviceInfo.ucTxBufferSize[1];
00493
00494
00495 sReport += "Firmware Version of Peripheral Device:";
00496 sReport += "\r\n";
00497 sprintf(cBuffer, "%02d.%02d.%02d", m_DeviceInfo.ucSwVer[0], m_DeviceInfo.ucSwVer[1], m_DeviceInfo.ucDevVer);
00498
00499 sReport += "\tSoftware Revision:.....";
00500 sReport += cBuffer;
00501 sReport += "\r\n";
00502 sprintf(cBuffer, "0x%02X", m_DeviceInfo.ucHwType);
00503 sReport += "\tHardware Type:.........";
00504 sReport += cBuffer;
00505 sReport += "\r\n";
00506
00507 sprintf(cBuffer, "%02d", m_DeviceInfo.ucDeviceType);
00508 sReport += "\tDevice Type:...........";
00509 sReport += cBuffer;
00510 sReport += " (";
00511 switch(m_DeviceInfo.ucDeviceType)
00512 {
00513 case FEDM_ISC_TYPE_ANT_GPC:
00514 sReport += "People Counter";
00515 break;
00516
00517
00518
00519 }
00520 sReport += ")";
00521 sReport += "\r\n";
00522
00523 sprintf(cBuffer, "%05d", uiRxBufLen);
00524 sReport += "\tMax. Rx buffer size:...";
00525 sReport += cBuffer;
00526 sReport += "\r\n";
00527 sprintf(cBuffer, "%05d", uiTxBufLen);
00528 sReport += "\tMax. Tx buffer size:...";
00529 sReport += cBuffer;
00530 sReport += "\r\n";
00531 }
00532
00533 void FedmIscPeripheralDevice::Add0x10InfoText(string& sReport)
00534 {
00535 char cBuffer[64];
00536
00537 sReport += "\r\n";
00538 sReport += "Hardware Information:";
00539 sReport += "\r\n";
00540 sprintf(cBuffer, "\t0x%02X%02X - 0x%02X%02X - 0x%02X%02X",
00541 m_DeviceInfo.ucHwInfo[0],
00542 m_DeviceInfo.ucHwInfo[1],
00543 m_DeviceInfo.ucDHw[0],
00544 m_DeviceInfo.ucDHw[1],
00545 m_DeviceInfo.ucAHw[0],
00546 m_DeviceInfo.ucAHw[1]);
00547
00548 sReport += cBuffer;
00549
00550 sReport += "\r\n";
00551 sReport += "\tSupported Port Types:..";
00552 if(m_DeviceInfo.ucPortTypes & 0x01)
00553 {
00554 sReport += "Serial";
00555 if(m_DeviceInfo.ucPortTypes & 0xFE)
00556 sReport += ", ";
00557 }
00558 if(m_DeviceInfo.ucPortTypes & 0x02)
00559 {
00560 sReport += "RS4xx";
00561 if(m_DeviceInfo.ucPortTypes & 0xFC)
00562 sReport += ", ";
00563 }
00564 if(m_DeviceInfo.ucPortTypes & 0x04)
00565 {
00566 sReport += "LAN";
00567 if(m_DeviceInfo.ucPortTypes & 0xF8)
00568 sReport += ", ";
00569 }
00570 if(m_DeviceInfo.ucPortTypes & 0x08)
00571 {
00572 sReport += "WLAN";
00573 if(m_DeviceInfo.ucPortTypes & 0xF0)
00574 sReport += ", ";
00575 }
00576 if(m_DeviceInfo.ucPortTypes & 0x10)
00577 {
00578 sReport += "USB";
00579 if(m_DeviceInfo.ucPortTypes & 0xE0)
00580 sReport += ", ";
00581 }
00582 if(m_DeviceInfo.ucPortTypes & 0x20)
00583 {
00584 sReport += "Bluetooth";
00585 if(m_DeviceInfo.ucPortTypes & 0xC0)
00586 sReport += ", ";
00587 }
00588 if(m_DeviceInfo.ucPortTypes & 0x80)
00589 {
00590 sReport += "Discovery";
00591 }
00592
00593 sReport += "\r\n";
00594 }
00595
00596 void FedmIscPeripheralDevice::Add0x60InfoText(string& sReport)
00597 {
00598 char cBuffer[64];
00599
00600 sReport += "\r\n";
00601 sReport += "Input/Output capabilities";
00602 sReport += "\r\n";
00603
00604 sReport += "\tNumber of Inputs:......";
00605 sprintf(cBuffer, "%d", m_DeviceInfo.ucNoOfInputs);
00606 sReport += cBuffer;
00607 sReport += "\r\n";
00608
00609 sReport += "\tNumber of Outputs:.....";
00610 sprintf(cBuffer, "%d", m_DeviceInfo.ucNoOfOutputs);
00611 sReport += cBuffer;
00612 sReport += "\r\n";
00613
00614 sReport += "\tNumber of Relays:......";
00615 sprintf(cBuffer, "%d", m_DeviceInfo.ucNoOfRelays);
00616 sReport += cBuffer;
00617 sReport += "\r\n";
00618 }
00619
00620 #endif // #if !defined(_FEDM_NO_PD_SUPPORT)