00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <unistd.h>
00027 #include <string>
00028 #include "feisc.h"
00029 #include "FedmIscCore.h"
00030 #include "ISO_IEC_7816_6_ICManufacturerRegistration.h"
00031
00032
00033 using namespace std;
00034
00035
00036
00037 void cbsFct1(void* pAny, int iError, unsigned char ucCmd);
00038 void Display0x22Response(FEDM_ISCReaderModule* pReader, int iError);
00039 void Display0x6EResponse(FEDM_ISCReaderModule* pReader, int iError);
00040 char* GetISOMfrCode(unsigned char ucMfr);
00041
00042
00043
00044
00045 int main(int argc, char *argv[])
00046 {
00047 int iBack = 0;
00048 char cErrorText[256];
00049
00050 FEDM_ISCReaderModule* pReader = new FEDM_ISCReaderModule;
00051 FEDM_TASK_INIT TaskInit;
00052
00053
00054 iBack = pReader->SetTableSize(FEDM_ISC_BRM_TABLE, 256);
00055 if(iBack < 0)
00056 {
00057 pReader->GetErrorText(cErrorText, iBack);
00058 printf("SetTableSize returns %d: %s. FENotifySample finished\n", iBack, cErrorText);
00059 delete pReader;
00060 return -1;
00061 }
00062
00063
00064
00065 TaskInit.iConnectByHost = 0;
00066 TaskInit.pAny = (void*)pReader;
00067 TaskInit.uiFlag = FEDM_TASKCB1;
00068 TaskInit.uiUse = FEDM_TASKID_NOTIFICATION;
00069 memset(TaskInit.cIPAdr, 0, 16);
00070 TaskInit.iPortNr = 10005;
00071 TaskInit.cbFct1 = cbsFct1;
00072 TaskInit.iNotifyWithAck = 0;
00073 TaskInit.uiTimeout = 30;
00074 TaskInit.bCryptoMode = false;
00075 TaskInit.bKeepAlive = true;
00076 TaskInit.uiKeepAliveIdleTime = 500;
00077 TaskInit.uiKeepAliveProbeCount = 5;
00078 TaskInit.uiKeepAliveIntervalTime = 500;
00079
00080
00081 iBack = pReader->StartAsyncTask(&TaskInit);
00082 if(iBack < 0)
00083 {
00084 pReader->GetErrorText(cErrorText, iBack);
00085 printf("StartAsyncTask returns %d: %s. FENotifySample finished\n", iBack, cErrorText);
00086 delete pReader;
00087 return -1;
00088 }
00089
00090
00091
00092 while(true)
00093 {
00094
00095 usleep(10000);
00096 }
00097
00098
00099 pReader->CancelAsyncTask();
00100
00101 printf("FENotifySample finished\n");
00102
00103 delete pReader;
00104 return EXIT_SUCCESS;
00105 }
00106
00107
00108
00109 void cbsFct1(void* pAny, int iError, unsigned char ucCmd)
00110 {
00111 FEDM_ISCReaderModule* pReader = (FEDM_ISCReaderModule*)pAny;
00112
00113 switch(ucCmd)
00114 {
00115 case 0x22:
00116 Display0x22Response(pReader, iError);
00117 break;
00118
00119 case 0x6E:
00120 Display0x6EResponse(pReader, iError);
00121 break;
00122 }
00123 }
00124
00125
00126
00127 void Display0x22Response(FEDM_ISCReaderModule* pReader, int iError)
00128 {
00129 bool bSNR = false;
00130 bool bDB = false;
00131 bool bTime = false;
00132 bool bDate = false;
00133 bool bAnt = false;
00134 bool bIn = false;
00135 bool bExt = false;
00136 bool bEpc = false;
00137
00138 unsigned char ucTrData[3];
00139 unsigned char ucTrType = 0;
00140 unsigned char ucDBAdr = 0;
00141 unsigned char ucDBSize = 0;
00142 unsigned char ucTmp;
00143 unsigned char ucSnr[32];
00144 unsigned char ucSnrLen = 0;
00145 unsigned char ucC1G2PC[2];
00146 unsigned char ucTimer[4];
00147 unsigned char ucDate[5];
00148 unsigned char ucAntNr = 0;
00149 unsigned char ucInput = 0;
00150 unsigned char ucState = 0;
00151
00152 unsigned int uiDBN = 0;
00153 unsigned int uiTmp = 0;
00154
00155 string sTmp;
00156
00157 static char g_str[1024];
00158 static char g_cErrorText[256];
00159
00160 if(iError < 0)
00161 {
00162 pReader->GetErrorText(g_cErrorText, iError);
00163 printf("%s\n", g_cErrorText);
00164 return;
00165 }
00166
00167 if(! ( iError==0x00 ||
00168 iError==0x83 ||
00169 iError==0x84 ||
00170 iError==0x93 ||
00171 iError==0x94 ) )
00172 {
00173 pReader->GetErrorText(g_cErrorText, iError);
00174 printf("%s\n", g_cErrorText);
00175 return;
00176 }
00177
00178
00179 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_SNR, &bSNR);
00180 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_DB, &bDB);
00181 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_ANT, &bAnt);
00182 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_TIME, &bTime);
00183 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_DATE, &bDate);
00184 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_EXT, &bExt);
00185 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA2_IN, &bIn);
00186
00187 printf("\n[0x22] Read Buffer >> ");
00188 int iState = FEISC_GetLastState(pReader->GetReaderHnd(), g_str);
00189 printf("Statusbyte: 0x%02X (%s)\n", (unsigned char)iState, g_str);
00190
00191
00192 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1, &ucTrData[0]);
00193 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA2, &ucTrData[1]);
00194
00195 if(ucTrData[0] & 0x80)
00196 printf(" TR-DATA....0x%02X 0x%02X\n", ucTrData[0], ucTrData[1]);
00197 else
00198 printf(" TR-DATA....0x%02X\n", ucTrData[0]);
00199
00200 pReader->GetData(FEDM_ISC_TMP_ADV_BRM_RECSETS, &uiTmp);
00201 printf(" DATA-SETS..%d\n", uiTmp);
00202
00203 for(int iIdx=0; iIdx<pReader->GetTableLength(FEDM_ISC_BRM_TABLE); iIdx++)
00204 {
00205 bEpc = false;
00206 printf(" %d. Transponder\n", (int)(iIdx+1));
00207
00208 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_SNR_LEN, &ucSnrLen);
00209
00210 if(bSNR && ucSnrLen>0)
00211 {
00212 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_TRTYPE, &ucTrType);
00213
00214 switch(ucTrType)
00215 {
00216
00217 case FEDM_ISC_TR_TYPE_ICODE1:
00218 sprintf(g_str, " (Philips I-Code1)");
00219 break;
00220
00221
00222 case FEDM_ISC_TR_TYPE_TAGIT:
00223 sprintf(g_str, " (Texas Instruments Tag-it HF)");
00224 break;
00225
00226
00227 case FEDM_ISC_TR_TYPE_ISO15693:
00228 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_SNR, ucSnr, 8);
00229 sprintf(g_str, " (ISO15693 - %s)", GetISOMfrCode(ucSnr[1]));
00230 break;
00231
00232
00233 case FEDM_ISC_TR_TYPE_ISO14443A:
00234 sprintf(g_str, " (ISO14443-A)");
00235 break;
00236
00237
00238 case FEDM_ISC_TR_TYPE_ISO14443B:
00239 sprintf(g_str, " (ISO14443-B)");
00240 break;
00241
00242
00243 case FEDM_ISC_TR_TYPE_EPC:
00244 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_IS_EPC, &bEpc);
00245 if(bEpc)
00246 {
00247 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_TYPE, &ucTmp);
00248 switch(ucTmp)
00249 {
00250 case FEDM_ISC_EPC_TYPE_1:
00251 sprintf(g_str, " (EPC 96 bit)");
00252 break;
00253 case FEDM_ISC_EPC_TYPE_2:
00254 sprintf(g_str, " (EPC 64 bit type I)");
00255 break;
00256 case FEDM_ISC_EPC_TYPE_3:
00257 sprintf(g_str, " (EPC 64 bit type II)");
00258 break;
00259 case FEDM_ISC_EPC_TYPE_4:
00260 sprintf(g_str, " (EPC 64 bit type III)");
00261 break;
00262 default:
00263 sprintf(g_str, " (unknown EPC type)");
00264 }
00265 }
00266 break;
00267
00268
00269 case FEDM_ISC_TR_TYPE_ICODE_UID:
00270 sprintf(g_str, " (I-CODE UID)");
00271 break;
00272
00273
00274 case FEDM_ISC_TR_TYPE_ISO18000_6_A:
00275 sprintf(g_str, " (18000-6-A)");
00276 break;
00277
00278
00279 case FEDM_ISC_TR_TYPE_ISO18000_6_B:
00280 sprintf(g_str, " (18000-6-B)");
00281 break;
00282
00283
00284 case FEDM_ISC_TR_TYPE_EM4222:
00285 sprintf(g_str, " (EM4222)");
00286 break;
00287
00288
00289 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN2:
00290 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_IS_EPC, &bEpc);
00291 if(bEpc)
00292 {
00293 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_TYPE, &ucTmp);
00294 switch(ucTmp)
00295 {
00296 case FEDM_ISC_EPC_TYPE_1:
00297 sprintf(g_str, " (EPC Class 1 Gen 2 - EPC 96 bit)");
00298 break;
00299 case FEDM_ISC_EPC_TYPE_2:
00300 sprintf(g_str, " (EPC Class 1 Gen 2 - EPC 64 bit type I)");
00301 break;
00302 case FEDM_ISC_EPC_TYPE_3:
00303 sprintf(g_str, " (EPC Class 1 Gen 2 - EPC 64 bit type II)");
00304 break;
00305 case FEDM_ISC_EPC_TYPE_4:
00306 sprintf(g_str, " (EPC Class 1 Gen 2 - EPC 64 bit type III)");
00307 break;
00308 default:
00309 sprintf(g_str, " (EPC Class 1 Gen 2 - unknown EPC type)");
00310 }
00311 }
00312 else
00313 {
00314 sprintf(g_str, " (EPC Class 1 Gen 2)");
00315 }
00316 break;
00317
00318
00319 case FEDM_ISC_TR_TYPE_EPC_CLASS0:
00320 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_IS_EPC, &bEpc);
00321 if(bEpc)
00322 {
00323 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_TYPE, &ucTmp);
00324 switch(ucTmp)
00325 {
00326 case FEDM_ISC_EPC_TYPE_1:
00327 sprintf(g_str, " (EPC Class 0 - EPC 96 bit)");
00328 break;
00329 case FEDM_ISC_EPC_TYPE_2:
00330 sprintf(g_str, " (EPC Class 0 - EPC 64 bit type I)");
00331 break;
00332 case FEDM_ISC_EPC_TYPE_3:
00333 sprintf(g_str, " (EPC Class 0 - EPC 64 bit type II)");
00334 break;
00335 case FEDM_ISC_EPC_TYPE_4:
00336 sprintf(g_str, " (EPC Class 0 - EPC 64 bit type III)");
00337 break;
00338 default:
00339 sprintf(g_str, " (EPC Class 0 - unknown EPC type)");
00340 }
00341 }
00342 else
00343 {
00344 sprintf(g_str, " (EPC Class 0)");
00345 }
00346 break;
00347
00348
00349 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN1:
00350 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_IS_EPC, &bEpc);
00351 if(bEpc)
00352 {
00353 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_TYPE, &ucTmp);
00354 switch(ucTmp)
00355 {
00356 case FEDM_ISC_EPC_TYPE_1:
00357 sprintf(g_str, " (EPC Class 1 Gen 1 - EPC 96 bit)");
00358 break;
00359 case FEDM_ISC_EPC_TYPE_2:
00360 sprintf(g_str, " (EPC Class 1 Gen 1 - EPC 64 bit type I)");
00361 break;
00362 case FEDM_ISC_EPC_TYPE_3:
00363 sprintf(g_str, " (EPC Class 1 Gen 1 - EPC 64 bit type II)");
00364 break;
00365 case FEDM_ISC_EPC_TYPE_4:
00366 sprintf(g_str, " (EPC Class 1 Gen 1 - EPC 64 bit type III)");
00367 break;
00368 default:
00369 sprintf(g_str, " (EPC Class 1 Gen 1 - unknown EPC type)");
00370 }
00371 }
00372 else
00373 {
00374 sprintf(g_str, " (EPC Class 1 Gen 1)");
00375 }
00376 break;
00377
00378 default:
00379 sprintf(g_str, " (unknown)");
00380 break;
00381 }
00382
00383 printf(" TR-TYPE....: 0x%02X (%s)\n", ucTrType, g_str);
00384
00385
00386
00387 if(ucTrType == FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN2)
00388 {
00389 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_CL1_GEN2_PC, ucC1G2PC, 2);
00390 printf(" PC.........: %02X%02X\n", ucC1G2PC[0], ucC1G2PC[1]);
00391 }
00392
00393
00394 if(bEpc)
00395 {
00396 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC, sTmp);
00397 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_TYPE, &ucTmp);
00398
00399 switch(ucTmp)
00400 {
00401 case FEDM_ISC_EPC_TYPE_1:
00402 case FEDM_ISC_EPC_TYPE_2:
00403 case FEDM_ISC_EPC_TYPE_3:
00404 case FEDM_ISC_EPC_TYPE_4:
00405 printf(" EPC........: %s\n", sTmp.c_str());
00406 break;
00407 default:
00408 printf(" EPC........: ??\n");
00409 }
00410 }
00411 else
00412 {
00413 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_SNR, sTmp);
00414 printf(" SNR........: %s\n", sTmp.c_str());
00415 }
00416 }
00417
00418 if(bDB)
00419 {
00420 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_DBN, &uiDBN);
00421 if(uiDBN > 0)
00422 {
00423 printf(" DB-N.......: 0x%04X\n", uiDBN);
00424
00425 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_BLOCK_SIZE, &ucDBSize);
00426 printf(" DB-SIZE....: 0x%02X\n", ucDBSize);
00427
00428 printf(" DB.........: ");
00429 for(int iCnt=0; iCnt<(int)uiDBN; iCnt++)
00430 {
00431 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_RxDB, ucDBAdr+iCnt, sTmp);
00432 printf(sTmp.c_str());
00433
00434 if(iCnt<(int)(uiDBN-1))
00435 printf("\n ");
00436 }
00437
00438 printf("\n");
00439 }
00440 }
00441
00442 if(bDate)
00443 {
00444 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_DATE, ucDate, 5);
00445
00446 printf(" DATE.......: %02d/%02d/%02d%02d\n", ucDate[2], ucDate[3], ucDate[0], ucDate[1]);
00447 }
00448
00449 if(bTime)
00450 {
00451 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_TIMER, ucTimer, 4);
00452 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_TIMER, &uiTmp);
00453
00454 unsigned int uiHours = ucTimer[0];
00455 unsigned int uiMinutes = ucTimer[1];
00456 unsigned int uiMilliSecs = (ucTimer[2]<<8) + ucTimer[3];
00457 unsigned int uiSeconds = uiMilliSecs / 1000;
00458 uiMilliSecs = uiMilliSecs % 1000;
00459
00460 printf(" TIME ......: %08X, (%02d:%02d:%02d.%03d)\n", uiTmp, uiHours, uiMinutes, uiSeconds, uiMilliSecs);
00461 }
00462
00463 if(bAnt && ((bSNR && ucSnrLen>0) || (bDB && uiDBN>0)))
00464 {
00465 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_ANT_NR, &ucAntNr);
00466
00467 printf(" Antenna No.: 0x%02X\n", ucAntNr);
00468 }
00469
00470 if(bExt && bIn)
00471 {
00472 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_INPUT, &ucInput);
00473
00474 printf(" INPUT......: 0x%02X\n", ucInput);
00475
00476 pReader->GetTableData(iIdx, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_STATE, &ucState);
00477
00478 printf(" STATE......: 0x%02X\n", ucState);
00479 }
00480
00481 }
00482
00483 }
00484
00485
00486
00487 void Display0x6EResponse(FEDM_ISCReaderModule* pReader, int iError)
00488 {
00489 unsigned char ucData[13];
00490 static char g_str[1024];
00491
00492 pReader->GetData(FEDM_ISC_TMP_DIAG_DATA, &ucData[0], 13);
00493
00494 printf("\n[0x6E] Reader Diagnostic >> ");
00495 int iState = FEISC_GetLastState(pReader->GetReaderHnd(), g_str);
00496 printf("Statusbyte: 0x%02X (%s)\n", (unsigned char)iState, g_str);
00497
00498 if(ucData[0] & 0x01)
00499 printf(" 0: RF-Hardware.......Error\n");
00500 else
00501 printf(" 0: RF-Hardware..........OK\n");
00502
00503 if(ucData[0] & 0x02)
00504 printf(" 1: Noise-Level.......Error\n");
00505 else
00506 printf(" 1: Noise-Level..........OK\n");
00507
00508 if(ucData[0] & 0x10)
00509 printf(" 4: False Power.........Yes\n");
00510 else
00511 printf(" 4: False Power..........No\n");
00512
00513 if(ucData[0] & 0x20)
00514 printf(" 5: Channel Allocation..Yes\n");
00515 else
00516 printf(" 5: Channel Allocation...No\n");
00517
00518 printf("\n");
00519
00520 if(ucData[1] & 0x01)
00521 printf(" 0: Ant1 |Z| <> 50 Ohm.......Yes\n");
00522 else
00523 printf(" 0: Ant1 |Z| <> 50 Ohm........No\n");
00524
00525 if(ucData[1] & 0x02)
00526 printf(" 1: Ant2 |Z| <> 50 Ohm.......Yes\n");
00527 else
00528 printf(" 1: Ant2 |Z| <> 50 Ohm........No\n");
00529
00530 if(ucData[1] & 0x04)
00531 printf(" 2: Ant3 |Z| <> 50 Ohm.......Yes\n");
00532 else
00533 printf(" 2: Ant3 |Z| <> 50 Ohm........No\n");
00534
00535 if(ucData[1] & 0x08)
00536 printf(" 3: Ant4 |Z| <> 50 Ohm.......Yes\n");
00537 else
00538 printf(" 3: Ant4 |Z| <> 50 Ohm........No\n");
00539
00540 }
00541
00542
00543 char* GetISOMfrCode(unsigned char ucMfr)
00544 {
00545 switch(ucMfr)
00546 {
00547 case 0x01:
00548 return FEISC_ISO_MOTOROLA;
00549 case 0x02:
00550 return FEISC_ISO_STM;
00551 case 0x03:
00552 return FEISC_ISO_HITACHI;
00553 case 0x04:
00554 return FEISC_ISO_PHILIPS;
00555 case 0x05:
00556 return FEISC_ISO_INFINEON;
00557 case 0x06:
00558 return FEISC_ISO_CYLINC;
00559 case 0x07:
00560 return FEISC_ISO_TI;
00561 case 0x08:
00562 return FEISC_ISO_FUJITSU;
00563 case 0x09:
00564 return FEISC_ISO_MATSUSHITA;
00565 case 0x0A:
00566 return FEISC_ISO_NEC;
00567 case 0x0B:
00568 return FEISC_ISO_OKI;
00569 case 0x0C:
00570 return FEISC_ISO_TOSHIBA;
00571 case 0x0D:
00572 return FEISC_ISO_MITSUBISHI;
00573 case 0x0E:
00574 return FEISC_ISO_SAMSUNG;
00575 case 0x0F:
00576 return FEISC_ISO_HYUNDAI;
00577 case 0x10:
00578 return FEISC_ISO_LG;
00579 case 0x11:
00580 return FEISC_ISO_EMOSYN;
00581 case 0x12:
00582 return FEISC_ISO_INSIDE;
00583 case 0x13:
00584 return FEISC_ISO_ORGA;
00585 case 0x14:
00586 return FEISC_ISO_SHARP;
00587 case 0x15:
00588 return FEISC_ISO_ATMEL;
00589 case 0x16:
00590 return FEISC_ISO_EM;
00591 case 0x17:
00592 return FEISC_ISO_KSW;
00593 case 0x19:
00594 return FEISC_ISO_XICOR;
00595 }
00596
00597 return "unknown manufacturer";
00598 }