ISOHostSampleDlg.cpp
Go to the documentation of this file.
00001 /*-------------------------------------------------------
00002 |                                                       |
00003 |                  ISOHostSampleDlg.cpp                 |
00004 |                                                       |
00005 ---------------------------------------------------------
00006 
00007 Copyright  2007         FEIG ELECTRONIC GmbH, All Rights Reserved.
00008                                                 Lange Strasse 4
00009                                                 D-35781 Weilburg
00010                                                 Federal Republic of Germany
00011                                                 phone    : +49 6471 31090
00012                                                 fax      : +49 6471 310999
00013                                                 e-mail   : info@feig.de
00014                                                 Internet : http://www.feig.de
00015                                         
00016 Author                  :       Benjamin Stadin
00017 Begin                   :       11.12.2006
00018 
00019 Version                 :       01.00.00 / 24.01.2007 / Benjamin Stadin
00020 
00021 Operation Systems       :       Linux
00022 */
00023 
00024 #include <QMainWindow>
00025 #include "ISOHostSampleDlg.h"
00026 
00027 // FE-includes
00028 #include "ISO_IEC_7816_6_ICManufacturerRegistration.h"
00029 #include "../../../../feisc-lib/include/feisc.h" 
00030 #include "../../../../feusb-lib/include/feusb.h" 
00031 
00032 
00033 static const char * const aboutMessage = "<p><b>ISOHost Linux Sample - copyright FEIG ELECTRONIC GmbH</b></p>";
00034 
00035 //------------------------------------------------------------------------------
00036 // Name: displayNewTag() 
00037 // Desc: displays new tags in the tag table. Triggered by the inventory thread
00038 //------------------------------------------------------------------------------
00039 void ISOHostSampleDlg::displayNewTag()
00040 {
00041         unsigned char ucTagType = 0;
00042         unsigned char ucEpcType = 0;
00043         unsigned char ucSnr[32] = {0};
00044         int iCnt=0;
00045         int iBack;
00046         unsigned int  uiHeader = 0;
00047         char sSnr[64];
00048         char sTagType[256] = {0};
00049         char sTags[256] = {0};
00050         char sMfr[256] = {0};
00051         unsigned int uiEPClen;
00052 
00053         //Get TableLength (how many Tags)
00054         int iLen = m_iscReader->GetTableLength(FEDM_ISC_ISO_TABLE);
00055         /*if (iLen > tagTable->rowCount())
00056                 tagTable->setRowCount(iLen);*/
00057 
00058         if(iLen == 0)
00059         {
00060                 char cErrorText[256];
00061                 FEISC_GetLastState(m_iscReader->GetReaderHnd(), cErrorText);
00062                 ui.statusLineEdit->setText(cErrorText);
00063                 clearTagList();
00064                 return;
00065         }
00066         else
00067         {
00068                 tagTable->clear();
00069                 tagTable->setRowCount(iLen);
00070                 for (iCnt= 0; iCnt<iLen; iCnt++)
00071                 {
00072                         //insert serial number into taglist
00073                         iBack = m_iscReader->GetTableData(iCnt,FEDM_ISC_ISO_TABLE,FEDM_ISC_DATA_SNR, ucSnr, sizeof(ucSnr));
00074                         if (iBack == 0)
00075                                 iBack = m_iscReader->GetTableData(iCnt,FEDM_ISC_ISO_TABLE,FEDM_ISC_DATA_TRTYPE, &ucTagType);
00076 
00077                         if((ucTagType & 0x80) == 0 && iBack == 0)       // HF-Transponder
00078                         {
00079                                 switch(ucTagType)
00080                                 {
00081                                 case FEDM_ISC_TR_TYPE_ICODE1:
00082                                         strcpy(sTagType, "Philips I-Code1");
00083                                         break;
00084                                 
00085                                 case FEDM_ISC_TR_TYPE_TAGIT:
00086                                         strcpy(sTagType, "Texas Instruments Tag-it HF");
00087                                         break;
00088 
00089                                 case FEDM_ISC_TR_TYPE_ISO15693:
00090                                         memset(ucSnr, 0, 8);
00091                                         m_iscReader->GetTableData(iCnt, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_SNR, ucSnr, 8);
00092                                         GetISOMfrCode(ucSnr[1], sMfr);
00093                                         sprintf(sTagType, "ISO15693 - %s", sMfr);
00094                                         break;
00095                         
00096                                 case FEDM_ISC_TR_TYPE_ISO14443A:
00097                                         strcpy(sTagType, "ISO14443-A");
00098                                         break;
00099                                 
00100                                 case FEDM_ISC_TR_TYPE_ISO14443B:
00101                                         strcpy(sTagType, "ISO14443-B");
00102                                         break;
00103 
00104                                 case FEDM_ISC_TR_TYPE_EPC:
00105                                         m_iscReader->GetTableData(iCnt, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_EPC_HEADER, &uiHeader);
00106                                         m_iscReader->GetTableData(iCnt, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_EPC_TYPE, &ucEpcType);
00107 
00108                                         switch(ucEpcType)
00109                                         {
00110                                         case FEDM_ISC_EPC_TYPE_1:
00111                                                 strcpy(sTagType, "EPC 96 bit");
00112                                                 m_iscReader->GetTableData(iCnt, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00113                                                 break;
00114                                         case FEDM_ISC_EPC_TYPE_2:
00115                                                 strcpy(sTagType, "EPC 64 bit type I");
00116                                                 m_iscReader->GetTableData(iCnt, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00117                                                 break;
00118                                         case FEDM_ISC_EPC_TYPE_3:
00119                                                 strcpy(sTagType, "EPC 64 bit type II");
00120                                                 m_iscReader->GetTableData(iCnt, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00121                                                 break;
00122                                         case FEDM_ISC_EPC_TYPE_4:
00123                                                 strcpy(sTagType, "EPC 64 bit type III");
00124                                                 m_iscReader->GetTableData(iCnt, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00125                                                 break;
00126                                         }
00127                                         break;
00128 
00129                                 case FEDM_ISC_TR_TYPE_ICODE_UID:
00130                                         strcpy(sTagType, "I-CODE UID");
00131                                         break;
00132                                 }
00133                         }
00134                         else if((ucTagType & 0x80) == 0x80)     // UHF-Transponder
00135                         {
00136                                 switch(ucTagType)
00137                                 {
00138                                 case FEDM_ISC_TR_TYPE_ISO18000_6_A:
00139                                         strcpy(sTagType, "ISO18000-6-A");
00140                                         break;
00141                                 case FEDM_ISC_TR_TYPE_ISO18000_6_B:
00142                                         strcpy(sTagType, "ISO18000-6-B");
00143                                         break;
00144                                 case FEDM_ISC_TR_TYPE_EM4222:
00145                                         strcpy(sTagType, "EM4222");
00146                                         break;
00147                                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN2:
00148                                         strcpy(sTagType, "EPC Generation 2");
00149                                         break;
00150                                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN1:
00151                                         strcpy(sTagType, "EPC Class 1");
00152                                         break;
00153 
00154                                 default:  strcpy(sTagType, "unknown");
00155                                 }
00156                         }
00157                         m_iscReader->GetTableData(iCnt,FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_SNR_LEN, &uiEPClen);
00158                         //Show in table
00159                         tagTable->edit(iCnt, "TagType", sTagType);
00160                         FEDM_ConvHexUCharToHexChar(ucSnr, uiEPClen, sSnr, sizeof(sSnr));
00161                         tagTable->edit(iCnt, "SerialNumber", sSnr);
00162                 }
00163                 
00164                 if (iLen == 1)
00165                 {
00166                         strcpy(sTags, " 1 Tag in Field ");
00167                 }
00168                 else 
00169                 {
00170                         sprintf(sTags, " %i Tags in Field ", iLen);
00171                 }
00172                 ui.statusLineEdit->setText(sTags);
00173         }
00174         
00175         // Thread is in conditional wait state. Send wake signal to continue
00176         m_readTagsThread->readTags();
00177         
00178 }
00179 
00180 //------------------------------------------------------------------------------
00181 // Name: displayError(int error)
00182 // Desc: displays an error in the line edit. Triggered by the inventory thread
00183 //------------------------------------------------------------------------------
00184 void ISOHostSampleDlg::displayError(int error)
00185 {
00186         char sErrorText[256] = {0};
00187         
00188         m_iscReader->GetErrorText(sErrorText, error);
00189         ui.statusLineEdit->setText(sErrorText);
00190         m_readTagsThread->readTags();
00191 }
00192 
00193 //------------------------------------------------------------------------------
00194 // Name: displayNoTag()
00195 // Desc: disyplays messahe if no tag is in field. Triggered by inventory thread
00196 //------------------------------------------------------------------------------
00197 void ISOHostSampleDlg::displayNoTag()
00198 {
00199         ui.statusLineEdit->setText("No tag in field");
00200         clearTagList();
00201         m_readTagsThread->readTags();
00202 }
00203 
00204 //------------------------------------------------------------------------------
00205 // Name: GetISOMfrCode(unsigned char ucMfr, char* sMfr)
00206 // Desc: returns a string description of the ISO code
00207 //------------------------------------------------------------------------------
00208 void ISOHostSampleDlg::GetISOMfrCode(unsigned char ucMfr, char* sMfr)
00209 {
00210         switch(ucMfr)
00211         {
00212         case 0x01:
00213                 strcpy(sMfr, FEISC_ISO_MOTOROLA);
00214                 break;
00215         case 0x02:
00216                 strcpy(sMfr, FEISC_ISO_STM);
00217                 break;
00218         case 0x03:
00219                 strcpy(sMfr, FEISC_ISO_HITACHI);
00220                 break;
00221         case 0x04:
00222                 strcpy(sMfr, FEISC_ISO_PHILIPS);
00223                 break;
00224         case 0x05:
00225                 strcpy(sMfr, FEISC_ISO_INFINEON);
00226                 break;
00227         case 0x06:
00228                 strcpy(sMfr, FEISC_ISO_CYLINC);
00229                 break;
00230         case 0x07:
00231                 strcpy(sMfr, FEISC_ISO_TI);
00232                 break;
00233         case 0x08:
00234                 strcpy(sMfr, FEISC_ISO_FUJITSU);
00235                 break;
00236         case 0x09:
00237                 strcpy(sMfr, FEISC_ISO_MATSUSHITA);
00238                 break;
00239         case 0x0A:
00240                 strcpy(sMfr, FEISC_ISO_NEC);
00241                 break;
00242         case 0x0B:
00243                 strcpy(sMfr, FEISC_ISO_OKI);
00244                 break;
00245         case 0x0C:
00246                 strcpy(sMfr, FEISC_ISO_TOSHIBA);
00247                 break;
00248         case 0x0D:
00249                 strcpy(sMfr, FEISC_ISO_MITSUBISHI);
00250                 break;
00251         case 0x0E:
00252                 strcpy(sMfr, FEISC_ISO_SAMSUNG);
00253                 break;
00254         case 0x0F:
00255                 strcpy(sMfr, FEISC_ISO_HYUNDAI);
00256                 break;
00257         case 0x10:
00258                 strcpy(sMfr, FEISC_ISO_LG);
00259                 break;
00260         case 0x11:
00261                 strcpy(sMfr, FEISC_ISO_EMOSYN);
00262                 break;
00263         case 0x12:
00264                 strcpy(sMfr, FEISC_ISO_INSIDE);
00265                 break;
00266         case 0x13:
00267                 strcpy(sMfr, FEISC_ISO_ORGA);
00268                 break;
00269         case 0x14:
00270                 strcpy(sMfr, FEISC_ISO_SHARP);
00271                 break;
00272         case 0x15:
00273                 strcpy(sMfr, FEISC_ISO_ATMEL);
00274                 break;
00275         case 0x16:
00276                 strcpy(sMfr, FEISC_ISO_EM);
00277                 break;
00278         case 0x17:
00279                 strcpy(sMfr, FEISC_ISO_KSW);
00280                 break;
00281         case 0x19:
00282                 strcpy(sMfr, FEISC_ISO_XICOR);
00283                 break;
00284         default:
00285                 strcpy(sMfr, "unknown manufacturer");
00286         }
00287 }
00288 
00289 //------------------------------------------------------------------------------
00290 // Name: clearTagList()
00291 // Desc: clears the tag table
00292 //------------------------------------------------------------------------------
00293 void ISOHostSampleDlg::clearTagList()
00294 {
00295         tagTable->clear();
00296         tagTable->setRowCount(256);
00297 }
00298 
00299 //------------------------------------------------------------------------------
00300 // Name: ISOHostSampleDlg()
00301 // Desc: constructor
00302 //------------------------------------------------------------------------------
00303 ISOHostSampleDlg::ISOHostSampleDlg()
00304 {
00305         ui.setupUi(this);
00306         
00307         QStringList list;
00308         list += "TagType";
00309         list += "SerialNumber";
00310         tagTable = new FEUITable(list, ui.tagListGroupBox);
00311         hexTable = new FEUISimpleHexTable(ui.hexDataGroupBox);
00312         
00313         // Just fill the hex and tag table with something
00314         hexTable->setRowCount(256);
00315         tagTable->setRowCount(256);
00316         
00317         setupMenuBar();
00318         
00319         m_iscReader = new FEDM_ISCReaderModule;
00320         
00321         connect(ui.startPushButton, SIGNAL(clicked()), this, SLOT(startButtonClicked()));
00322         
00323         initReader();
00324         
00325         m_readTagsThread = new FEReadTagsThread(m_iscReader);
00326         
00327         connect(m_readTagsThread, SIGNAL(onNewTag(int)), this, SLOT(displayNewTag()));
00328         connect(m_readTagsThread, SIGNAL(onError(int)), this, SLOT(displayError(int)));
00329         connect(m_readTagsThread, SIGNAL(onNoTag(int)), this, SLOT(displayNoTag()));
00330         connect(ui.clearListPushButton, SIGNAL(clicked()), this, SLOT(clearTagList()));
00331         connect(ui.clearProtPushButton, SIGNAL(clicked()), ui.protocolTextEdit, SLOT(clear()));
00332         connect(ui.readTagPushButton, SIGNAL(clicked()), this, SLOT(readTagButtonClicked()));
00333         connect(ui.writeTagPushButton, SIGNAL(clicked()), this, SLOT(writeTagButtonClicked()));
00334         
00335         //AddEventHandler for protocol output to FERichEditCtrl
00336         int iReaderHnd = m_iscReader->GetReaderHnd();
00337         FEISC_EVENT_INIT taskInit;
00338         taskInit.cbFct =        &protCallBackHelper;
00339         taskInit.uiUse =        FEISC_PRT_EVENT;
00340         taskInit.uiFlag =       FEISC_CALLBACK;
00341         int iBack =             FEISC_AddEventHandler (iReaderHnd,&taskInit);
00342         if (iBack <0)
00343         {
00344                 char cErrorText[256];
00345                 m_iscReader->GetErrorText(cErrorText, iBack);
00346                 QMessageBox::critical(this, tr("FEISC_AddEventHandler() error"), cErrorText,
00347                                                 QMessageBox::Abort);
00348                 return;
00349         }
00350         // Saves current pointer to class instance which is needed by the static 
00351         // callback. See ISOHostSampleDlg.h 
00352         setGetClassInstance(this);
00353         connect(this, SIGNAL(onProtocolEvent(int,int)), this, SLOT(displayProtocol(int,int)));
00354         
00355         // callbach fct for usb device removal. The handle may become invalid when the device is removed
00356         connect(this, SIGNAL(onUSBDisconnect(int, unsigned int)), this, SLOT(disconnectUSBEvent(int, unsigned int)));
00357         FEUSB_EVENT_INIT usbInit;
00358         usbInit.uiFlag = FEUSB_CALLBACK;
00359         usbInit.uiUse = FEUSB_DEV_DISCONNECT_EVENT;
00360         usbInit.cbFct = &disconnectUSBEventHelper;
00361         FEUSB_AddEventHandler(0,&usbInit);
00362 }
00363 
00364 //------------------------------------------------------------------------------
00365 // Name: dsconnectUSBEventHelper(int i, unsigned int k)
00366 // Desc: static helper function to emit a signal for USB disconnect event callback
00367 //------------------------------------------------------------------------------
00368 void ISOHostSampleDlg::disconnectUSBEventHelper(int i, unsigned int k)
00369 {
00370         ISOHostSampleDlg* classInstance = setGetClassInstance(NULL);
00371         
00372         emit(classInstance->onUSBDisconnect(i, k));
00373 }
00374 
00375 //------------------------------------------------------------------------------
00376 // Name: dsconnectUSBEvent(int i, unsigned int k)
00377 // Desc: called by static helper fct above
00378 //------------------------------------------------------------------------------
00379 void ISOHostSampleDlg::disconnectUSBEvent(int i, unsigned int k)
00380 {
00381         // Finish the thread
00382         if (m_readTagsThread->running())
00383                 startButtonClicked();
00384 }
00385 
00386 //------------------------------------------------------------------------------
00387 // Name: ~ISOHostSampleDlg()
00388 // Desc: destructor
00389 //------------------------------------------------------------------------------
00390 ISOHostSampleDlg::~ISOHostSampleDlg()
00391 {
00392         // Delete protocol output handler
00393         if (m_iscReader)
00394         {
00395                 int iReaderHnd = m_iscReader->GetReaderHnd();
00396                 if (iReaderHnd > 0)
00397                 {
00398                         FEISC_EVENT_INIT taskInit;
00399                         taskInit.cbFct =        &protCallBackHelper;
00400                         taskInit.uiUse =        FEISC_PRT_EVENT;
00401                         taskInit.uiFlag =       FEISC_CALLBACK;
00402                         FEISC_DelEventHandler (iReaderHnd,&taskInit);
00403                         
00404                         // delete usb disconnect event handler
00405                         FEUSB_EVENT_INIT usbInit;
00406                         usbInit.uiFlag = FEUSB_CALLBACK;
00407                         usbInit.uiUse = FEUSB_DEV_DISCONNECT_EVENT; 
00408                         usbInit.cbFct = &disconnectUSBEventHelper;
00409                         FEUSB_DelEventHandler(0,&usbInit);
00410                 }
00411         }
00412         
00413         if (m_readTagsThread)
00414         {
00415                 m_readTagsThread->quit();
00416                 sleep(0);
00417                 delete m_readTagsThread;
00418         }
00419         
00420         if (m_iscReader)
00421                 delete m_iscReader;
00422 
00423         if (tagTable)
00424                 delete tagTable;
00425                 
00426         if (hexTable)
00427                 delete hexTable;
00428 }
00429 
00430 //------------------------------------------------------------------------------
00431 // Name: readTagButtonClicked()
00432 // Desc: reads a tag and displays it in the hex table
00433 //------------------------------------------------------------------------------
00434 void ISOHostSampleDlg::readTagButtonClicked()
00435 {
00436         unsigned char ucReadBlock[1024];                // Byte-Block for Receive-Function
00437         unsigned char ucBlockSize;              // BlockSize
00438         unsigned int uiEPClen;
00439         int row;                        // Index of internal table and tagTable (same)
00440         int i;                          // best variable of the world   
00441         char cErrorText[256] = {0};     // for Messagetext
00442         unsigned char ucSecStatus = 0;          // SecurityStatus
00443         int iBack;
00444         char cSnr[64] = {0};
00445         int iHexSets = 0;
00446         unsigned char ucTrType;
00447         
00448         hexTable->clear();
00449 
00450         // which tag is selected?
00451         row = tagTable->currentRow();
00452         QTableWidgetItem *item = tagTable->item(row, 1);
00453         if (!item || item->text().length() <= 0)
00454         {
00455                 ui.statusLineEdit->setText("No tag selected");
00456                 return;
00457         }
00458 
00459         char* sSnr = qstrdup(item->text().toLatin1());
00460         strcpy(cSnr, sSnr);
00461         delete sSnr;
00462                 
00463         int iDbn;
00464         char* sDbn = qstrdup(ui.dbnLineEdit->text().toLatin1());
00465         iDbn = atoi(sDbn);
00466         delete sDbn;
00467         
00468         int iDbAdr;
00469         char* sDbAdr = qstrdup(ui.dbAdrLineEdit->text().toLatin1());
00470         iDbAdr = atoi(sDbAdr);
00471         delete sDbAdr;
00472         
00473         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_UID, cSnr, strlen(cSnr));
00474         m_iscReader->GetTableData(row,FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_SNR_LEN, &uiEPClen);
00475         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_UID_LEN,uiEPClen);
00476         m_iscReader->SetData(FEDM_ISC_TMP_B0_CMD, (unsigned char)0x23); 
00477         m_iscReader->SetData(FEDM_ISC_TMP_B0_MODE,(unsigned char)0x00); // reset mode byte
00478         m_iscReader->SetData(FEDM_ISC_TMP_B0_MODE_SEC, (unsigned char)0x01);
00479         m_iscReader->SetData(FEDM_ISC_TMP_B0_MODE, (unsigned char)FEDM_ISC_ISO_MODE_ADR);
00480         
00481         // get tag type
00482         m_iscReader->GetTableData(row, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_TRTYPE, &ucTrType);
00483         switch (ucTrType)
00484         {
00485                 case FEDM_ISC_TR_TYPE_ISO18000_6_B: // ISO18000-6-B
00486                 case FEDM_ISC_TR_TYPE_EPC:
00487                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN2:
00488                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN1:
00489                 case 0x86:
00490                         m_iscReader->SetData(FEDM_ISC_TMP_B0_MODE_UID_LF,true);
00491                         m_iscReader->SetData(FEDM_ISC_TMP_B0_MODE_EXT_ADR,(unsigned char)0x01);
00492                         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_BANK_BANK_NR,(unsigned char)0x03);
00493                         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_BANK_ACCESS_FLAG,(unsigned char)0x00); 
00494                         iHexSets = 256;
00495                         break;
00496                         
00497                 case FEDM_ISC_TR_TYPE_ICODE1: // Philips I-CODE
00498                         iHexSets = 11;
00499                         break;
00500 
00501                 case FEDM_ISC_TR_TYPE_TAGIT: // Texas Intruments Tag-it HF
00502                         iHexSets = 8;
00503                         break;
00504                 
00505                 case FEDM_ISC_TR_TYPE_ISO15693: // ISO15693
00506                 case FEDM_ISC_TR_TYPE_ISO14443A: // ISO14443A
00507                 case FEDM_ISC_TR_TYPE_ISO14443B: // ISO14443B
00508                         iHexSets = 256; 
00509                         break;
00510 
00511                 default:
00512                         iHexSets = 0;
00513                         break;
00514         }
00515 
00516         // request data
00517         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_DBN, (unsigned char)iDbn);
00518         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_DB_ADR, (unsigned char)iDbAdr);
00519         
00520         // protocol transfer
00521         iBack = m_iscReader->SendProtocol(0xB0);
00522 
00523         if(iBack < 0)
00524         {
00525                 m_iscReader->GetErrorText(cErrorText,iBack);
00526                 QMessageBox::critical(this, tr("SendProtocol(0xB0) error"), cErrorText,
00527                                         QMessageBox::Abort);
00528                 return;
00529         }
00530 
00531         if(! (iBack == 0x00 || iBack == 0x83 || iBack == 0x84 || iBack ==0x90 || 
00532                 iBack == 0x93 || iBack == 0x94 || iBack == 0x95 ) )
00533         {
00534                 m_iscReader->GetStatusText(cErrorText,iBack);
00535                 QMessageBox::critical(this, tr("SendProtocol(0xB0) error"), cErrorText,
00536                                         QMessageBox::Abort);
00537                 return;
00538         }
00539 
00540         // get blocksize
00541         m_iscReader->GetTableData(row,FEDM_ISC_ISO_TABLE,FEDM_ISC_DATA_BLOCK_SIZE,&ucBlockSize);
00542         
00543         char sDbSize[16] = {0};
00544         sprintf(sDbSize, "%d", int(ucBlockSize));
00545         ui.dbSizeLineEdit->setText(sDbSize);
00546         
00547         hexTable->initTable(iHexSets, (int)ucBlockSize);
00548         for(i=iDbAdr; i<iDbn+iDbAdr; i++ )
00549         {
00550                 memset(ucReadBlock, 0, sizeof(ucReadBlock));
00551                 m_iscReader->GetTableData(row, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_RxDB, 
00552                                 (unsigned char)i, ucReadBlock, 
00553                                 (int) ucBlockSize);     
00554                 m_iscReader->GetTableData(row, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_SEC_STATUS, 
00555                                 i, &ucSecStatus, 1);                            
00556                 
00557                 if(ucSecStatus == 1)
00558                 {
00559                         hexTable->edit(i, ucReadBlock, true);
00560                 }
00561                 else
00562                 {
00563                         hexTable->edit(i, ucReadBlock, false);
00564                 }
00565         }               
00566 }
00567 
00568 //------------------------------------------------------------------------------
00569 // Name: writeTagButtonClicked()
00570 // Desc: writes data to the tag
00571 //------------------------------------------------------------------------------
00572 void ISOHostSampleDlg::writeTagButtonClicked()
00573 {
00574         unsigned char ucWriteBlock[1024];       // Bytes to write
00575         unsigned char ucBlockSize;              // BlockSize
00576         unsigned char ucTrType;
00577         unsigned int uiEPClen;
00578         int i;                                          
00579         char cErrorText[256] = {0};     // for Messagetext
00580         int idx;
00581         int row = 0;
00582         char cSnr[64] = {0};
00583         int iDbn;
00584         int iDbAdr;
00585         
00586         row = tagTable->currentRow();
00587         QTableWidgetItem *item = tagTable->item(row, 1);
00588         if (!item || item->text().length() <= 0)
00589         {
00590                 ui.statusLineEdit->setText("No tag selected");
00591                 return;
00592         }
00593                  
00594         // serial no of selected tag
00595         char* sSnr = qstrdup(item->text().toLatin1());
00596         strcpy(cSnr, sSnr);
00597         delete sSnr;
00598         
00599         char* sDbn = qstrdup(ui.dbnLineEdit->text().toLatin1());
00600         iDbn = atoi(sDbn);
00601         delete sDbn;
00602         
00603         char* sDbAdr = qstrdup(ui.dbAdrLineEdit->text().toLatin1());
00604         iDbAdr = atoi(sDbAdr);
00605         delete sDbAdr;
00606         
00607         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_UID, cSnr, strlen(cSnr));
00608         m_iscReader->GetTableData(row,FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_SNR_LEN, &uiEPClen);
00609         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_UID_LEN,uiEPClen);
00610         // get blocksize
00611         m_iscReader->GetTableData(row,FEDM_ISC_ISO_TABLE,FEDM_ISC_DATA_BLOCK_SIZE,&ucBlockSize);
00612         //Prepare Protocol-Parameter
00613         m_iscReader->SetData(FEDM_ISC_TMP_B0_CMD, (unsigned char)0x24);
00614         m_iscReader->SetData(FEDM_ISC_TMP_B0_MODE,(unsigned char)0x00); // reset mode byte
00615         m_iscReader->SetData(FEDM_ISC_TMP_B0_MODE, (unsigned char)FEDM_ISC_ISO_MODE_ADR);
00616 
00617         // get tag type
00618         m_iscReader->GetTableData(row, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_TRTYPE, &ucTrType);
00619         switch (ucTrType)
00620         {
00621                 case FEDM_ISC_TR_TYPE_ISO18000_6_B: // ISO18000-6-B
00622                 case FEDM_ISC_TR_TYPE_EPC:
00623                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN2:
00624                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN1:
00625                 case 0x86:
00626                         m_iscReader->SetData(FEDM_ISC_TMP_B0_MODE_UID_LF,true);
00627                         m_iscReader->SetData(FEDM_ISC_TMP_B0_MODE_EXT_ADR,(unsigned char)0x01);
00628                         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_BANK_BANK_NR,(unsigned char)0x03);
00629                         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_BANK_ACCESS_FLAG,(unsigned char)0x00); 
00630                         break;
00631                         
00632                 default:
00633                         break;
00634         }
00635         
00636         // request data
00637         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_DBN, (unsigned char)iDbn);
00638         m_iscReader->SetData(FEDM_ISC_TMP_B0_REQ_DB_ADR, (unsigned char)iDbAdr);
00639         idx = m_iscReader->FindTableIndex(0, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_SNR, sSnr);
00640         
00641         // get data from Hex Edit 
00642         for(i=0; i<iDbn; i++ )
00643         {
00644                 char hexStr [1024] = {0};
00645                 hexTable->getHexString(hexStr, iDbAdr+i);
00646                 FEDM_ConvHexCharToHexUChar(hexStr, strlen(hexStr), ucWriteBlock, int(ucBlockSize));
00647                 m_iscReader->SetTableData(row, FEDM_ISC_ISO_TABLE, FEDM_ISC_DATA_TxDB, i+iDbAdr, ucWriteBlock, (int)ucBlockSize);
00648         }
00649         
00650         // write data to Tag
00651         int iBack = m_iscReader->SendProtocol(0xB0);
00652         if(iBack < 0)
00653         {
00654                 m_iscReader->GetErrorText(cErrorText, iBack);
00655                                 QMessageBox::critical(this, tr("SendProtocol(0xB0) error"), cErrorText,
00656                                         QMessageBox::Abort);
00657                 return;
00658         }
00659 
00660         if(! (iBack == 0x00 || iBack == 0x83 || iBack == 0x84 || iBack ==0x90 || 
00661                 iBack == 0x93 || iBack == 0x94 || iBack == 0x95 ) )
00662         {
00663                 m_iscReader->GetStatusText(cErrorText, iBack);
00664                 QMessageBox::critical(this, tr("SendProtocol() error"), cErrorText,
00665                                         QMessageBox::Abort);
00666                 return;
00667         }
00668         
00669         // copy data from Transmit-Buffer to Receive-Buffer (only for HexEdit)
00670         for(i=0; i<iDbn; i++ )
00671         {
00672                 m_iscReader->GetTableData(row,FEDM_ISC_ISO_TABLE,FEDM_ISC_DATA_TxDB, i+iDbAdr, ucWriteBlock, (int) ucBlockSize);
00673                 m_iscReader->SetTableData(row,FEDM_ISC_ISO_TABLE,FEDM_ISC_DATA_RxDB, i+iDbAdr, ucWriteBlock, (int) ucBlockSize);        
00674         }
00675 }
00676 
00677 //------------------------------------------------------------------------------
00678 // Name: resizeEvent(QResizeEvent *event)
00679 // Desc: handles resizing of the custom table
00680 //------------------------------------------------------------------------------
00681 void ISOHostSampleDlg::resizeEvent(QResizeEvent *event)
00682 {
00683         //event->accept();
00684         QRect tagRect = ui.tagListGroupBox->geometry();
00685         int tagTableWidth = tagRect.width() - 18;
00686         int tagTableHeight = tagRect.height() - 24;
00687         tagTable->setGeometry(10, 20, tagTableWidth, tagTableHeight);
00688         
00689         QRect hexRect = ui.hexDataGroupBox->geometry();
00690         int hexTableWidth = hexRect.width() - 18;
00691         int hexTableHeight = hexRect.height() - 24;
00692         hexTable->setGeometry(10, 20, hexTableWidth, hexTableHeight);
00693 }
00694 
00695 //------------------------------------------------------------------------------
00696 // Name: showAbout()
00697 // Desc: shows an "About" message
00698 //------------------------------------------------------------------------------
00699 void ISOHostSampleDlg::showAbout()
00700 {
00701         QMessageBox::information(this, tr("About"), aboutMessage, QMessageBox::Abort);
00702 }
00703 
00704 //------------------------------------------------------------------------------
00705 // Name: setupMenuBar()
00706 // Desc: sets up the menu bar
00707 //------------------------------------------------------------------------------
00708 void ISOHostSampleDlg::setupMenuBar()
00709 {
00710         QMenu *fileMenu = menuBar()->addMenu(tr("&File"));   
00711         fileMenu->addAction(tr("&Exit"), this, SLOT(close()));
00712 
00713         QMenu *optionsMenu = menuBar()->addMenu(tr("&Options"));
00714         optionsMenu->addAction(tr("&Find reader"), this, SLOT(initReader()));    
00715         
00716         QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
00717         helpMenu->addAction(tr("&About"), this, SLOT(showAbout()));    
00718 }
00719 
00720 //------------------------------------------------------------------------------
00721 // Name: initReader()
00722 // Desc: shows the detect reader dialog, initializes the reader and sets callback functions
00723 //------------------------------------------------------------------------------
00724 void ISOHostSampleDlg::initReader()
00725 {
00726         int iReaderHnd;
00727         
00728         detectReaderDlg.setReader(m_iscReader);
00729         
00730         if (detectReaderDlg.exec() != QDialog::Accepted)
00731                 return;
00732 
00733         
00734         iReaderHnd = m_iscReader->GetReaderHnd();
00735         // can't happen with reader module, left for general purpose anyways
00736         if(iReaderHnd < 0)
00737         {
00738                 char cErrorText[256];
00739                 m_iscReader->GetErrorText(cErrorText, iReaderHnd);
00740                 QMessageBox::critical(this, tr("GetReaderHnd() error "),
00741                                     cErrorText,
00742                                     QMessageBox::Abort);
00743         }
00744         else
00745         {
00746                 //Set the TableSize
00747                 m_iscReader->SetTableSize(FEDM_ISC_ISO_TABLE, 512);             
00748         }       
00749         
00750         // log protocol to output file
00751         //FEISC_SetReaderPara(m_iscReader->GetReaderHnd(), "LogProt", "1");
00752         
00753 }
00754 
00755 
00756 //------------------------------------------------------------------------------
00757 // Name: static setGetClassInstance(ISOHostSampleDlg* classInstance)
00758 // Desc: set / get function to share a pointer of the class instance of the UI with the static callback.
00759 // Return: Null if new pointer is set, or a pointer to the instance if instance == NULL 
00760 //------------------------------------------------------------------------------
00761 ISOHostSampleDlg* ISOHostSampleDlg::setGetClassInstance(ISOHostSampleDlg* classInstance)
00762 {
00763         static ISOHostSampleDlg* statInstance = NULL;
00764         
00765         if (classInstance != NULL)
00766         {
00767                 statInstance = classInstance;
00768                 return NULL;
00769         }
00770         else
00771         {
00772                 return statInstance;
00773         }
00774 }
00775 
00776 //------------------------------------------------------------------------------
00777 // Name: static protCallBackHelper(int iMsg,int iLen)
00778 // Desc: delegates between static callback function and UI and triggers the callback
00779 //       event to show the protocol messages in the protocol window
00780 //------------------------------------------------------------------------------
00781 void ISOHostSampleDlg::protCallBackHelper(int iMsg,int iLen)
00782 {
00783         ISOHostSampleDlg* classInstance = setGetClassInstance(NULL);
00784         
00785         emit(classInstance->onProtocolEvent(iMsg, iLen));
00786 }
00787 
00788 //------------------------------------------------------------------------------
00789 // Name: displayProtocol(int iMsg,int iLen)
00790 // Desc: displays protocol messages in the protocol window. Triggered by 
00791 //       onProtocolEvent() which is triggered in the static helper function protCallBackHelper()
00792 //------------------------------------------------------------------------------
00793 void ISOHostSampleDlg::displayProtocol(int iMsg,int iLen)
00794 {
00795         if ((char*)iMsg == NULL)
00796                 return;
00797                 
00798         int len = strlen((char*)iMsg);
00799         if (len > 0)
00800         {
00801                 QString outStr;
00802                 outStr = (char*)iMsg;
00803                 outStr += "\n";
00804                 ui.protocolTextEdit->append(outStr);
00805         }
00806 }
00807 
00808 //------------------------------------------------------------------------------
00809 // Name: startButtonClicked()
00810 // Desc: starts / stops the inventory thread
00811 //------------------------------------------------------------------------------
00812 void ISOHostSampleDlg::startButtonClicked()
00813 {
00814 
00815         if (m_readTagsThread->running())
00816         {       
00817                 //pause thread
00818                 m_readTagsThread->pauseThread();
00819                 ui.startPushButton->setText("&Start");
00820                 
00821                 //Set Buttons enabled
00822                 ui.readTagPushButton->setEnabled(true);
00823                 ui.writeTagPushButton->setEnabled(true);
00824         }
00825         else
00826         {
00827                 //Set Buttons unenabled
00828                 ui.readTagPushButton->setEnabled(false);
00829         
00830                 //Delete all tags from the ListView
00831                 tagTable->clear();
00832                 ui.startPushButton->setText("&Stop");
00833                 
00834                 ui.readTagPushButton->setEnabled(false);
00835                 ui.writeTagPushButton->setEnabled(false);
00836                 
00837                 // start thread (or resume if already created)
00838                 m_readTagsThread->readTags();
00839                 
00840         }
00841 }


rfid_drivers
Author(s): Raul Perula-Martinez
autogenerated on Thu Apr 2 2015 03:06:14