BRMDemoDlg.cpp
Go to the documentation of this file.
00001 /*-------------------------------------------------------
00002 |                                                       |
00003 |                  BRMDemoDlg.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                   :       10.01.2007
00018 
00019 Version                 :       01.00.00 / 24.01.2007 / Benjamin Stadin
00020 
00021 Operation Systems       :       Linux
00022 */
00023 
00024 #include <QMainWindow>
00025 #include "BRMDemoDlg.h"
00026 
00027 // FE-includes
00028 #include "ISO_IEC_7816_6_ICManufacturerRegistration.h"
00029 #include "../../../../feisc-lib/include/feisc.h" 
00030 #include "../../../../fedm-classlib/src/FedmIscCore.h"
00031 
00032 static const char * const aboutMessage = "<p><b>BRM Demo Linux Sample - copyright 2007 FEIG ELECTRONIC GmbH</b></p>";
00033 
00034 //------------------------------------------------------------------------------
00035 // Name: displayData() 
00036 // Desc: displays new tags in the tag table. Triggered by inventory thread
00037 //------------------------------------------------------------------------------
00038 void BRMDemoDlg::displayData()
00039 {
00040         switch(m_iscReader->GetReaderType())
00041         {
00042         case FEDM_ISC_TYPE_ISCLR200:
00043                 OnDataProt21();
00044                 break;
00045         default:
00046                 OnDataProt22();
00047                 break;
00048         }
00049         
00050         // Thread is waiting for ui to update. Calling readTags() again sends signal to wake up
00051         m_readTagsThread->readTags();
00052 }
00053 
00054 void BRMDemoDlg::OnDataProt21()
00055 {
00056         unsigned char ucTmp;
00057         unsigned char ucDB[4] = {0};
00058         unsigned char ucAnt;
00059         char data[512] = {0};
00060         //QString str;
00061         bool bSNR = false;
00062         bool bDB = false;
00063         bool bTime = false;
00064         bool bAnt = false;
00065         int row = 0;
00066         int iBack = 0;
00067 
00068 
00069         for (int i = 0; i < m_iscReader->GetTableLength(FEDM_ISC_BRM_TABLE); i++) 
00070         {
00071                 tagTable->newRow();
00072                 row = tagTable->rowCount()-1;
00073                 // Show in ListView
00074                 memset(data, 0, sizeof(data));
00075                 sprintf(data, "%d", row);
00076                 tagTable->edit(row, "No", data);
00077 
00078                 m_iscReader->GetData(FEDM_ISCLR_TMP_BRM_TRDATA_SNR,  &bSNR);
00079                 m_iscReader->GetData(FEDM_ISCLR_TMP_BRM_TRDATA_DB,        &bDB);
00080                 m_iscReader->GetData(FEDM_ISCLR_TMP_BRM_TRDATA_ANT,  &bAnt);
00081                 m_iscReader->GetData(FEDM_ISCLR_TMP_BRM_TRDATA_TIME, &bTime);
00082 
00083                 if(bTime)
00084                 {
00085                         unsigned char ucTime[4];
00086 
00087                         memset(data, 0, sizeof(data));
00088                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_TIMER, ucTime, sizeof(ucTime));
00089                         unsigned int uiHours     = ucTime[0];
00090                         unsigned int uiMinutes   = ucTime[1];
00091                         unsigned int uiMilliSecs = (ucTime[2]<<8) + ucTime[3];
00092                         unsigned int uiSeconds   = uiMilliSecs / 1000;
00093                         uiMilliSecs = uiMilliSecs % 1000;
00094                         
00095                         sprintf(data, "%02d:%02d:%02d.%03d", uiHours, uiMinutes, uiSeconds, uiMilliSecs);
00096                         tagTable->edit(row, "Time", data); 
00097                 }
00098 
00099                 // get serial number
00100                 if (bSNR)
00101                 {
00102                         // get tag name
00103                         char cTagType[128] = {0};
00104                         unsigned char ucSnr[32];
00105                         char cSnr[64];
00106                         char cMfr[256] = {0};
00107                         unsigned int uiHeader;
00108                         unsigned int uiEPClen;
00109                         unsigned char ucEpcType;
00110                         
00111                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_TRTYPE, &ucTmp);
00112                         
00113                         if((ucTmp & 0x80) == 0 && iBack == 0)   // HF-Transponder
00114                         {
00115                                 switch(ucTmp)
00116                                 {
00117                                 case FEDM_ISC_TR_TYPE_ICODE1:
00118                                         strcpy(cTagType, "Philips I-Code1");
00119                                         break;
00120                                 
00121                                 case FEDM_ISC_TR_TYPE_TAGIT:
00122                                         strcpy(cTagType, "Texas Instruments Tag-it HF");
00123                                         break;
00124 
00125                                 case FEDM_ISC_TR_TYPE_ISO15693:
00126                                         memset(ucSnr, 0, 8);
00127                                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_SNR, ucSnr, 8);
00128                                         GetISOMfrCode(ucSnr[1], cMfr);
00129                                         sprintf(cTagType, "ISO15693 - %s", cMfr);
00130                                         break;
00131                         
00132                                 case FEDM_ISC_TR_TYPE_ISO14443A:
00133                                         strcpy(cTagType, "ISO14443-A");
00134                                         break;
00135                                 
00136                                 case FEDM_ISC_TR_TYPE_ISO14443B:
00137                                         strcpy(cTagType, "ISO14443-B");
00138                                         break;
00139 
00140                                 case FEDM_ISC_TR_TYPE_EPC:
00141                                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_HEADER, &uiHeader);
00142                                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_TYPE, &ucEpcType);
00143 
00144                                         switch(ucEpcType)
00145                                         {
00146                                         case FEDM_ISC_EPC_TYPE_1:
00147                                                 strcpy(cTagType, "EPC 96 bit");
00148                                                 m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00149                                                 break;
00150                                         case FEDM_ISC_EPC_TYPE_2:
00151                                                 strcpy(cTagType, "EPC 64 bit type I");
00152                                                 m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00153                                                 break;
00154                                         case FEDM_ISC_EPC_TYPE_3:
00155                                                 strcpy(cTagType, "EPC 64 bit type II");
00156                                                 m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00157                                                 break;
00158                                         case FEDM_ISC_EPC_TYPE_4:
00159                                                 strcpy(cTagType, "EPC 64 bit type III");
00160                                                 m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00161                                                 break;
00162                                         }
00163                                         break;
00164 
00165                                 case FEDM_ISC_TR_TYPE_ICODE_UID:
00166                                         strcpy(cTagType, "I-CODE UID");
00167                                         break;
00168                                 }
00169                         }
00170                         else if((ucTmp & 0x80) == 0x80) // UHF-Transponder
00171                         {
00172                                 switch(ucTmp)
00173                                 {
00174                                 case FEDM_ISC_TR_TYPE_ISO18000_6_A:
00175                                         strcpy(cTagType, "ISO18000-6-A");
00176                                         break;
00177                                 case FEDM_ISC_TR_TYPE_ISO18000_6_B:
00178                                         strcpy(cTagType, "ISO18000-6-B");
00179                                         break;
00180                                 case FEDM_ISC_TR_TYPE_EM4222:
00181                                         strcpy(cTagType, "EM4222");
00182                                         break;
00183                                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN2:
00184                                         strcpy(cTagType, "EPC Generation 2");
00185                                         break;
00186                                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN1:
00187                                         strcpy(cTagType, "EPC Class 1");
00188                                         break;
00189 
00190                                 default:  strcpy(cTagType, "unknown");
00191                                 }
00192                         }
00193                         //Show in table
00194                         tagTable->edit(row, "Type", cTagType);
00195                         m_iscReader->GetTableData(i,FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_SNR_LEN, &uiEPClen);
00196                         FEDM_ConvHexUCharToHexChar(ucSnr, uiEPClen, cSnr, sizeof(cSnr));
00197                         tagTable->edit(row, "Serial No", cSnr); 
00198                 
00199                 }
00200          
00201                 if (bDB)
00202                 {
00203                         memset(data, 0, sizeof(data));
00204                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_RxDB, 1, ucDB, 4);
00205                         sprintf(data, "%02X", (unsigned int)(ucDB));
00206                         tagTable->edit(row, "Data Block", data); 
00207                 }
00208 
00209                 if (bAnt)
00210                 {
00211                         memset(data, 0, sizeof(data));
00212                         // get antenna byte. each bit represents one antenna
00213                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_ANT_NR, &ucAnt);
00214                         char buf[4] = {0};
00215                         int antNo=1;
00216                         for (int p=1; p<=256; p*=2)
00217                         {
00218                                 if (ucAnt & p)
00219                                 {
00220                                         if (strlen(data) > 0)
00221                                                 strcat(data, ", ");
00222                                         sprintf(buf, "%d", antNo);
00223                                         strcat(data, buf);
00224                                 }
00225                                 antNo++;
00226                         }
00227                         tagTable->edit(row, "Ant No", data);
00228                 }
00229         }
00230 }
00231 
00232 void BRMDemoDlg::OnDataProt22()
00233 {
00234         unsigned char ucTmp;
00235         unsigned char ucAnt;
00236         char data[512] = {0};
00237         bool bSNR = false;
00238         bool bDB = false;
00239         bool bTime = false;
00240         bool bAnt = false;
00241         bool bDate = false;
00242         int row = 0;
00243         int iBack = 0;
00244 
00245         for (int i = 0; i < m_iscReader->GetTableLength(FEDM_ISC_BRM_TABLE); i++) 
00246         {
00247                 tagTable->newRow();
00248                 row = tagTable->rowCount()-1;
00249                 // Show in ListView
00250                 memset(data, 0, sizeof(data));
00251                 sprintf(data, "%d", row);
00252                 tagTable->edit(row, "No", data);
00253 
00254                 m_iscReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_SNR,   &bSNR);
00255                 m_iscReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_DB,    &bDB);
00256                 m_iscReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_ANT,   &bAnt);
00257                 m_iscReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_TIME, &bTime);
00258                 m_iscReader->GetData(FEDM_ISC_TMP_ADV_BRM_TRDATA1_DATE, &bDate);
00259 
00260                 if(bDate)
00261                 {
00262                         unsigned char ucDate[5];
00263                         memset(data, 0, sizeof(data));
00264                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_DATE, ucDate, 5);
00265                         sprintf(data, "%02d/%02d/%02d%02d", ucDate[2], ucDate[3], ucDate[0], ucDate[1]);
00266                         tagTable->edit(row, "Date", data); 
00267                 }
00268 
00269                 if(bTime)
00270                 {
00271                         unsigned char ucTime[4];
00272                         memset(data, 0, sizeof(data));
00273                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_TIMER, ucTime, 4);
00274                         unsigned int uiHours     = ucTime[0];
00275                         unsigned int uiMinutes   = ucTime[1];
00276                         unsigned int uiMilliSecs = (ucTime[2]<<8) + ucTime[3];
00277                         unsigned int uiSeconds   = uiMilliSecs / 1000;
00278                         uiMilliSecs = uiMilliSecs % 1000;
00279                         
00280                         sprintf(data, "%02d:%02d:%02d.%03d", uiHours, uiMinutes, uiSeconds, uiMilliSecs);
00281                         tagTable->edit(row, "Time", data); 
00282                 }
00283 
00284                 // get serial number
00285                 if (bSNR)
00286                 {
00287                         // get tag name
00288                         char cTagType[128] = {0};
00289                         unsigned char ucSnr[32];
00290                         char cSnr[64];
00291                         char cMfr[256] = {0};
00292                         unsigned int uiHeader;
00293                         unsigned int uiEPClen;
00294                         unsigned char ucEpcType;
00295                         
00296                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_TRTYPE, &ucTmp);
00297                         
00298                         if((ucTmp & 0x80) == 0 && iBack == 0)   // HF-Transponder
00299                         {
00300                                 switch(ucTmp)
00301                                 {
00302                                 case FEDM_ISC_TR_TYPE_ICODE1:
00303                                         strcpy(cTagType, "Philips I-Code1");
00304                                         break;
00305                                 
00306                                 case FEDM_ISC_TR_TYPE_TAGIT:
00307                                         strcpy(cTagType, "Texas Instruments Tag-it HF");
00308                                         break;
00309 
00310                                 case FEDM_ISC_TR_TYPE_ISO15693:
00311                                         memset(ucSnr, 0, 8);
00312                                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_SNR, ucSnr, 8);
00313                                         GetISOMfrCode(ucSnr[1], cMfr);
00314                                         sprintf(cTagType, "ISO15693 - %s", cMfr);
00315                                         break;
00316                         
00317                                 case FEDM_ISC_TR_TYPE_ISO14443A:
00318                                         strcpy(cTagType, "ISO14443-A");
00319                                         break;
00320                                 
00321                                 case FEDM_ISC_TR_TYPE_ISO14443B:
00322                                         strcpy(cTagType, "ISO14443-B");
00323                                         break;
00324 
00325                                 case FEDM_ISC_TR_TYPE_EPC:
00326                                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_HEADER, &uiHeader);
00327                                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC_TYPE, &ucEpcType);
00328 
00329                                         switch(ucEpcType)
00330                                         {
00331                                         case FEDM_ISC_EPC_TYPE_1:
00332                                                 strcpy(cTagType, "EPC 96 bit");
00333                                                 m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00334                                                 break;
00335                                         case FEDM_ISC_EPC_TYPE_2:
00336                                                 strcpy(cTagType, "EPC 64 bit type I");
00337                                                 m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00338                                                 break;
00339                                         case FEDM_ISC_EPC_TYPE_3:
00340                                                 strcpy(cTagType, "EPC 64 bit type II");
00341                                                 m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00342                                                 break;
00343                                         case FEDM_ISC_EPC_TYPE_4:
00344                                                 strcpy(cTagType, "EPC 64 bit type III");
00345                                                 m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_EPC, ucSnr);
00346                                                 break;
00347                                         }
00348                                         break;
00349 
00350                                 case FEDM_ISC_TR_TYPE_ICODE_UID:
00351                                         strcpy(cTagType, "I-CODE UID");
00352                                         break;
00353                                 }
00354                         }
00355                         else if((ucTmp & 0x80) == 0x80) // UHF-Transponder
00356                         {
00357                                 switch(ucTmp)
00358                                 {
00359                                 case FEDM_ISC_TR_TYPE_ISO18000_6_A:
00360                                         strcpy(cTagType, "ISO18000-6-A");
00361                                         break;
00362                                 case FEDM_ISC_TR_TYPE_ISO18000_6_B:
00363                                         strcpy(cTagType, "ISO18000-6-B");
00364                                         break;
00365                                 case FEDM_ISC_TR_TYPE_EM4222:
00366                                         strcpy(cTagType, "EM4222");
00367                                         break;
00368                                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN2:
00369                                         strcpy(cTagType, "EPC Generation 2");
00370                                         break;
00371                                 case FEDM_ISC_TR_TYPE_EPC_CLASS1_GEN1:
00372                                         strcpy(cTagType, "EPC Class 1");
00373                                         break;
00374 
00375                                 default:  strcpy(cTagType, "unknown");
00376                                 }
00377                         }
00378                         //Show in table
00379                         tagTable->edit(row, "Type", cTagType);
00380                         m_iscReader->GetTableData(i,FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_SNR_LEN, &uiEPClen);
00381                         FEDM_ConvHexUCharToHexChar(ucSnr, uiEPClen, cSnr, sizeof(cSnr));
00382                         tagTable->edit(row, "Serial No", cSnr); 
00383                 
00384                 }
00385 
00386                 if (bDB)
00387                 {
00388                         // get number of entries in db
00389                         unsigned int numEntries;
00390                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_DBN, &numEntries);
00391                         // get database address offset
00392                         unsigned char dbAddress = 0;
00393                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_DB_ADR, &dbAddress);
00394                         // get data block size
00395                         unsigned char   ucBlockSize;
00396                         unsigned char   ucReadBlock[256] = {0};
00397                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_BLOCK_SIZE, &ucBlockSize);
00398                         // get data blocks
00399                         memset(data, 0, sizeof(data));
00400                         char tmp[516] = {0}; // 512 + 1 at least
00401                         for (unsigned int dbEntry=0; dbEntry<numEntries; dbEntry++)
00402                         {
00403                                 memset(tmp, 0, sizeof(tmp));
00404                                 memset(ucReadBlock, 0, sizeof(ucReadBlock));
00405                                 iBack = m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_RxDB, dbAddress+dbEntry, ucReadBlock, int(ucBlockSize));
00406                                 if (iBack < 0)
00407                                         displayError(iBack);
00408                                 for (int pos=0; pos<(int)ucBlockSize; pos++)
00409                                 {
00410                                         sprintf(tmp, "%02X", ucReadBlock[pos]);
00411                                         strcat(data, tmp);
00412                                         strcat(data, " ");                              
00413                                 }
00414                         }
00415                         tagTable->edit(row, "Data Block", data); 
00416                 }
00417 
00418                 if (bAnt)
00419                 {
00420                         memset(data, 0, sizeof(data));
00421                         // get antenna byte. each bit represents one antenna
00422                         m_iscReader->GetTableData(i, FEDM_ISC_BRM_TABLE, FEDM_ISC_DATA_ANT_NR, &ucAnt);
00423                         char buf[4] = {0};
00424                         int antNo=1;
00425                         for (int p=1; p<=256; p*=2)
00426                         {
00427                                 if (ucAnt & p)
00428                                 {
00429                                         if (strlen(data) > 0)
00430                                                 strcat(data, ", ");
00431                                         sprintf(buf, "%d", antNo);
00432                                         strcat(data, buf);
00433                                 }
00434                                 antNo++;
00435                         }
00436                         tagTable->edit(row, "Ant No", data);
00437                 }
00438         }
00439 }
00440 
00441 //------------------------------------------------------------------------------
00442 // Name: GetISOMfrCode(unsigned char ucMfr, char* sMfr)
00443 // Desc: returns a string description of the ISO code
00444 //------------------------------------------------------------------------------
00445 void BRMDemoDlg::GetISOMfrCode(unsigned char ucMfr, char* sMfr)
00446 {
00447         switch(ucMfr)
00448         {
00449         case 0x01:
00450                 strcpy(sMfr, FEISC_ISO_MOTOROLA);
00451                 break;
00452         case 0x02:
00453                 strcpy(sMfr, FEISC_ISO_STM);
00454                 break;
00455         case 0x03:
00456                 strcpy(sMfr, FEISC_ISO_HITACHI);
00457                 break;
00458         case 0x04:
00459                 strcpy(sMfr, FEISC_ISO_PHILIPS);
00460                 break;
00461         case 0x05:
00462                 strcpy(sMfr, FEISC_ISO_INFINEON);
00463                 break;
00464         case 0x06:
00465                 strcpy(sMfr, FEISC_ISO_CYLINC);
00466                 break;
00467         case 0x07:
00468                 strcpy(sMfr, FEISC_ISO_TI);
00469                 break;
00470         case 0x08:
00471                 strcpy(sMfr, FEISC_ISO_FUJITSU);
00472                 break;
00473         case 0x09:
00474                 strcpy(sMfr, FEISC_ISO_MATSUSHITA);
00475                 break;
00476         case 0x0A:
00477                 strcpy(sMfr, FEISC_ISO_NEC);
00478                 break;
00479         case 0x0B:
00480                 strcpy(sMfr, FEISC_ISO_OKI);
00481                 break;
00482         case 0x0C:
00483                 strcpy(sMfr, FEISC_ISO_TOSHIBA);
00484                 break;
00485         case 0x0D:
00486                 strcpy(sMfr, FEISC_ISO_MITSUBISHI);
00487                 break;
00488         case 0x0E:
00489                 strcpy(sMfr, FEISC_ISO_SAMSUNG);
00490                 break;
00491         case 0x0F:
00492                 strcpy(sMfr, FEISC_ISO_HYUNDAI);
00493                 break;
00494         case 0x10:
00495                 strcpy(sMfr, FEISC_ISO_LG);
00496                 break;
00497         case 0x11:
00498                 strcpy(sMfr, FEISC_ISO_EMOSYN);
00499                 break;
00500         case 0x12:
00501                 strcpy(sMfr, FEISC_ISO_INSIDE);
00502                 break;
00503         case 0x13:
00504                 strcpy(sMfr, FEISC_ISO_ORGA);
00505                 break;
00506         case 0x14:
00507                 strcpy(sMfr, FEISC_ISO_SHARP);
00508                 break;
00509         case 0x15:
00510                 strcpy(sMfr, FEISC_ISO_ATMEL);
00511                 break;
00512         case 0x16:
00513                 strcpy(sMfr, FEISC_ISO_EM);
00514                 break;
00515         case 0x17:
00516                 strcpy(sMfr, FEISC_ISO_KSW);
00517                 break;
00518         case 0x19:
00519                 strcpy(sMfr, FEISC_ISO_XICOR);
00520                 break;
00521         default:
00522                 strcpy(sMfr, "unknown manufacturer");
00523         }
00524 }
00525 
00526 //------------------------------------------------------------------------------
00527 // Name: displayError(int error)
00528 // Desc: displays an error in the line edit. Triggered by the inventory thread
00529 //------------------------------------------------------------------------------
00530 void BRMDemoDlg::displayError(int error)
00531 {
00532         char sErrorText[256] = {0};
00533         
00534         m_iscReader->GetErrorText(sErrorText, error);
00535         ui.statusLineEdit->setText(sErrorText);
00536         m_readTagsThread->readTags();
00537 }
00538 
00539 //------------------------------------------------------------------------------
00540 // Name: clearTagList()
00541 // Desc: clears the tag table
00542 //------------------------------------------------------------------------------
00543 void BRMDemoDlg::clearTagList()
00544 {
00545         ui.statusLineEdit->setText("");
00546         m_iListItem = 0;
00547         tagTable->clear();
00548 }
00549 
00550 //------------------------------------------------------------------------------
00551 // Name: BRMDemoDlg()
00552 // Desc: constructor
00553 //------------------------------------------------------------------------------
00554 BRMDemoDlg::BRMDemoDlg()
00555 {
00556         ui.setupUi(this);
00557         
00558         QSplitter page;
00559         
00560         m_iListItem = 0;
00561         
00562         QStringList list;
00563         list += "No";
00564         list += "Date";
00565         list += "Time";
00566         list += "Type";
00567         list += "Serial No";
00568         list += "Data Block";
00569         list += "Ant No";
00570         tagTable = new FEUITable(list, ui.tagListGroupBox);
00571 
00572         setupMenuBar();
00573         
00574         m_iscReader = new FEDM_ISCReaderModule;
00575         
00576         initReader();
00577         
00578         m_readTagsThread = new FEReadTagsThread(m_iscReader);
00579         
00580         connect(m_readTagsThread, SIGNAL(onNewData(int)), this, SLOT(displayData()));
00581         connect(m_readTagsThread, SIGNAL(onError(int)), this, SLOT(displayError(int)));
00582         connect(ui.clearListPushButton, SIGNAL(clicked()), this, SLOT(clearTagList()));
00583         connect(ui.clearProtPushButton, SIGNAL(clicked()), ui.protocolTextEdit, SLOT(clear()));
00584         connect(ui.startPushButton, SIGNAL(clicked()), this, SLOT(startButtonClicked()));
00585         
00586         //AddEventHandler for protocol output to FERichEditCtrl
00587         int iReaderHnd = m_iscReader->GetReaderHnd();
00588         FEISC_EVENT_INIT taskInit;
00589         taskInit.cbFct =        &protCallBackHelper;
00590         taskInit.uiUse =        FEISC_PRT_EVENT;
00591         taskInit.uiFlag =       FEISC_CALLBACK;
00592         int iBack =             FEISC_AddEventHandler (iReaderHnd,&taskInit);
00593         if (iBack <0)
00594         {
00595                 char cErrorText[256];
00596                 m_iscReader->GetErrorText(cErrorText, iBack);
00597                 QMessageBox::critical(this, tr("FEISC_AddEventHandler() error"), cErrorText,
00598                                                 QMessageBox::Abort);
00599                 return;
00600         }
00601         // Saves current pointer to class instance which is needed by the static 
00602         // callback. See BRMDemoDlg.h 
00603         setGetClassInstance(this);
00604         connect(this, SIGNAL(onProtocolEvent(int,int)), this, SLOT(displayProtocol(int,int)));
00605 }
00606 
00607 //------------------------------------------------------------------------------
00608 // Name: ~BRMDemoDlg()
00609 // Desc: destructor
00610 //------------------------------------------------------------------------------
00611 BRMDemoDlg::~BRMDemoDlg()
00612 {
00613         // Delete protocol output handler
00614         if (m_iscReader)
00615         {
00616                 int iReaderHnd = m_iscReader->GetReaderHnd();
00617                 if (iReaderHnd > 0)
00618                 {
00619                         FEISC_EVENT_INIT taskInit;
00620                         taskInit.cbFct =        &protCallBackHelper;
00621                         taskInit.uiUse =        FEISC_PRT_EVENT;
00622                         taskInit.uiFlag =       FEISC_CALLBACK;
00623                         FEISC_DelEventHandler (iReaderHnd,&taskInit);
00624                 }
00625         }
00626         
00627         if (m_readTagsThread != NULL)
00628         {
00629                 m_readTagsThread->quit();
00630                 sleep(0);
00631                 delete m_readTagsThread;
00632                 m_readTagsThread = NULL;
00633         }
00634         
00635         if (m_iscReader != NULL)
00636         {
00637                 m_iscReader->DisConnect();
00638                 delete m_iscReader;
00639                 m_iscReader = NULL;
00640         }
00641 
00642         if (tagTable != NULL)
00643         {
00644                 delete tagTable;
00645                 tagTable = NULL;
00646         }
00647 
00648 }
00649 
00650 //------------------------------------------------------------------------------
00651 // Name: resizeEvent(QResizeEvent *event)
00652 // Desc: handles resizing of the custom table
00653 //------------------------------------------------------------------------------
00654 void BRMDemoDlg::resizeEvent(QResizeEvent *event)
00655 {
00656         //event->accept();
00657         QRect tagRect = ui.tagListGroupBox->geometry();
00658         int tagTableWidth = tagRect.width() - 18;
00659         int tagTableHeight = tagRect.height() - 24;
00660         tagTable->setGeometry(10, 20, tagTableWidth, tagTableHeight);
00661 }
00662 
00663 //------------------------------------------------------------------------------
00664 // Name: showAbout()
00665 // Desc: shows an "About" message
00666 //------------------------------------------------------------------------------
00667 void BRMDemoDlg::showAbout()
00668 {
00669         QMessageBox::information(this, tr("About"), aboutMessage, QMessageBox::Abort);
00670 }
00671 
00672 //------------------------------------------------------------------------------
00673 // Name: setupMenuBar()
00674 // Desc: sets up the menu bar
00675 //------------------------------------------------------------------------------
00676 void BRMDemoDlg::setupMenuBar()
00677 {
00678         QMenu *fileMenu = menuBar()->addMenu(tr("&File"));   
00679         fileMenu->addAction(tr("&Exit"), this, SLOT(close()));
00680 
00681         QMenu *optionsMenu = menuBar()->addMenu(tr("&Options"));
00682         optionsMenu->addAction(tr("&Find reader"), this, SLOT(initReader()));    
00683         
00684         QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
00685         helpMenu->addAction(tr("&About"), this, SLOT(showAbout()));    
00686 }
00687 
00688 //------------------------------------------------------------------------------
00689 // Name: initReader()
00690 // Desc: shows the detect reader dialog, initializes the reader and sets callback functions
00691 //------------------------------------------------------------------------------
00692 void BRMDemoDlg::initReader()
00693 {
00694         int iReaderHnd;
00695         
00696         detectReaderDlg.setReader(m_iscReader);
00697         
00698         if (detectReaderDlg.exec() != QDialog::Accepted)
00699                 return;
00700 
00701         
00702         iReaderHnd = m_iscReader->GetReaderHnd();
00703                 
00704         if(iReaderHnd < 0)
00705         {
00706                 char cErrorText[256];
00707                 m_iscReader->GetErrorText(cErrorText, iReaderHnd);
00708                 QMessageBox::critical(this, tr("GetReaderHnd() error "),
00709                                     cErrorText,
00710                                     QMessageBox::Abort);
00711                 return;
00712         }
00713         else
00714         {
00715                 //Set the TableSize
00716                 //m_reader->SetTableSize(, 500);
00717                 m_iscReader->SetTableSize(FEDM_ISC_BRM_TABLE, 500);
00718                                 
00719                 ui.startPushButton->setEnabled(true);
00720                 
00721         }       
00722         
00723         // log protocol to output file
00724         //FEISC_SetReaderPara(m_iscReader->GetReaderHnd(), "LogProt", "1");
00725         
00726 }
00727 
00728 
00729 //------------------------------------------------------------------------------
00730 // Name: static setGetClassInstance(BRMDemoDlg* classInstance)
00731 // Desc: set / get function to share a pointer of the class instance of the UI with the static callback.
00732 // Return: Null if new pointer is set, or a pointer to the instance if instance == NULL 
00733 //------------------------------------------------------------------------------
00734 BRMDemoDlg* BRMDemoDlg::setGetClassInstance(BRMDemoDlg* classInstance)
00735 {
00736         static BRMDemoDlg* statInstance = NULL;
00737         
00738         if (classInstance != NULL)
00739         {
00740                 statInstance = classInstance;
00741                 return NULL;
00742         }
00743         else
00744         {
00745                 return statInstance;
00746         }
00747 }
00748 
00749 //------------------------------------------------------------------------------
00750 // Name: static protCallBackHelper(int iMsg,int iLen)
00751 // Desc: delegates between static callback function and UI and triggers the callback
00752 //       event to show the protocol messages in the protocol window
00753 //------------------------------------------------------------------------------
00754 void BRMDemoDlg::protCallBackHelper(int iMsg,int iLen)
00755 {
00756         BRMDemoDlg* classInstance = setGetClassInstance(NULL);
00757         
00758         emit(classInstance->onProtocolEvent(iMsg, iLen));
00759 }
00760 
00761 //------------------------------------------------------------------------------
00762 // Name: displayProtocol(int iMsg,int iLen)
00763 // Desc: displays protocol messages in the protocol window. Triggered by 
00764 //       onProtocolEvent() which is triggered in the static helper function protCallBackHelper()
00765 //------------------------------------------------------------------------------
00766 void BRMDemoDlg::displayProtocol(int iMsg,int iLen)
00767 {
00768         if ((char*)iMsg == NULL)
00769                 return;
00770                 
00771         int len = strlen((char*)iMsg);
00772         if (len > 0)
00773         {
00774                 QString outStr;
00775                 outStr = (char*)iMsg;
00776                 outStr += "\n";
00777                 ui.protocolTextEdit->append(outStr);
00778         }
00779 }
00780 
00781 //------------------------------------------------------------------------------
00782 // Name: startButtonClicked()
00783 // Desc: starts / stops the inventory thread
00784 //------------------------------------------------------------------------------
00785 void BRMDemoDlg::startButtonClicked()
00786 {
00787         ui.statusLineEdit->setText("");
00788         
00789         if (m_readTagsThread->running())
00790         {       
00791                 //pause thread
00792                 m_readTagsThread->pauseThread();
00793                 ui.startPushButton->setText("&Start BRM");
00794         }
00795         else
00796         {
00797                 //Delete all tags from the ListView
00798                 tagTable->clear();
00799                 ui.startPushButton->setText("&Stop BRM");
00800                 
00801                 // start thread (or resume if already created)
00802                 m_readTagsThread->readTags();
00803                 
00804         }
00805 }


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