myAXXESS_NotifySample.cpp
Go to the documentation of this file.
00001 /*-------------------------------------------------------
00002 |                                                       |
00003 |                  myAXXESS_NotifySample.cpp            |
00004 |                                                       |
00005 ---------------------------------------------------------
00006 
00007 Copyright  2009-2010    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          :       Manuel Sahm
00017 Begin           :       05.10.2009
00018 
00019 Version         :       01.01.00 / 12.02.2010 / M. Hultsch
00020 
00021 Operation Systems       :       Linux
00022 */
00023 
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <unistd.h>
00027 #include <string>
00028 #include "../../../fedm-classlib/src/myaxxess/FedmIscMyAxxessReader.h"
00029 
00030 // STL - Standard Template Library
00031 using namespace std;
00032 
00033 int cbsEvent( void* pAny, int iError, FEDM_ISC_MYAXXESS_EVENT_TABLE_ITEM* pEventItem, unsigned char& ucAction, char* cIPAdr, int iPortNr );
00034 void cbsKeepAlive( void* pAny, int iError, unsigned int uiErrorFlags, unsigned int uiTableSize, unsigned int uiTableLength, char* cIPAdr, int iPortNr);
00035 
00036 int main(int argc, char *argv[])
00037 {
00038         int iBack = 0;
00039         int iReaderHnd = 0;
00040         FedmIscMyAxxessReader* m_pReader = NULL;
00041         unsigned int m_uiPortNr = 10005;
00042 
00043         m_pReader = new FedmIscMyAxxessReader(7, FEDM_MYAXXESS_IDD_FORMAT_HEX);
00044 
00045         iBack = m_pReader->StartEventHandler(m_uiPortNr, m_pReader, cbsEvent, cbsKeepAlive, -1, NULL);
00046         if(iBack < 0)
00047         {
00048                 printf("StartEventHandler returns %d: %s.  myAXXESS_NotifySample finished\n", iBack, m_pReader->GetErrorText(iBack));
00049                 delete m_pReader;
00050                 return -1;
00051         }
00052         else
00053         {
00054                 printf("myAXXESS_NotifySample is running on Port %d\n", m_uiPortNr);
00055         }
00056 
00057 
00058         // main loop
00059         while(true)
00060         {
00061                 // do nothing
00062                 usleep(10000);  // 10.000 s
00063         }
00064 
00065 
00066         iReaderHnd = m_pReader->GetReaderObject()->GetReaderHnd();
00067         if (iReaderHnd != 0)
00068         {
00069                 m_pReader->StopEventHandler();
00070         }
00071 
00072         printf("myAXXESS_NotifySample finished\n");
00073         
00074         delete m_pReader;
00075         return EXIT_SUCCESS;
00076 }
00077 
00078 int cbsEvent(   void* pAny,                                     // pAny
00079                 int iError,                                     // error value
00080                 FEDM_ISC_MYAXXESS_EVENT_TABLE_ITEM* pEventItem, // event record
00081                 unsigned char& ucAction,                        // reference to action
00082                 char* cIPAdr,                                   // IP-Address
00083                 int iPortNr )                                   // IP-Port
00084 {
00085         if((FedmIscMyAxxessReader*)pAny == NULL)
00086                 return 0;
00087 
00088         if(pEventItem == NULL)
00089                 return 0;
00090 
00091         FedmIscMyAxxessReader* pMyAxxessReader = (FedmIscMyAxxessReader*)pAny;
00092 
00093         char    szTimestamp[64];
00094         char    szTmp[32];
00095         string sReport;
00096         string sTmp;
00097 
00098         sReport = "\n";
00099         sReport += "[Event]\n";
00100         sReport += "EventID.......";
00101         switch(pEventItem->ucEventID)
00102         {
00103         case FEDM_MYAXXESS_EVENT_ACCESS:
00104                 sReport += "ACCESS";
00105                 break;
00106 
00107         case FEDM_MYAXXESS_EVENT_IO:
00108                 sReport += "INPUT";
00109                 break;
00110 
00111 /*      case FEDM_MYAXXESS_EVENT_ALARM:
00112                 sReport += "ALARM";
00113                 break;
00114 
00115         case FEDM_MYAXXESS_EVENT_REQUEST:
00116                 sReport += "ACCESS REQUEST";
00117                 break;*/
00118         
00119         default:
00120                 sReport += "Unknown";
00121                 break;
00122         }
00123         sReport += "\n";
00124 
00125         if(iError != 0x00 && iError != 0x93)
00126         {
00127                 sReport += pMyAxxessReader->GetErrorText(iError);
00128                 printf("%s\n", sReport.c_str());
00129                 return 0;
00130         }
00131 
00132         if(pEventItem->ucDataLayout & 0x01)
00133         {
00134                 sReport += "IDD...........";
00135                 FEDM_ConvHexUCharToHexStr(pEventItem->ucIDD, pEventItem->ucIDDLength, sTmp);
00136                 sReport += sTmp;
00137                 sReport += "\n";
00138         }
00139 
00140         if(pEventItem->ucDataLayout & 0x02)
00141         {
00142                 sReport += "Timestamp.....";
00143                 sprintf(szTimestamp,
00144                                 "Date=20%02d-%02d-%02d Time=%02d:%02d", 
00145                                 pEventItem->ucYear, 
00146                                 pEventItem->ucMonth, 
00147                                 pEventItem->ucDay, 
00148                                 pEventItem->ucHour, 
00149                                 pEventItem->ucMinute);
00150                 sReport += szTimestamp;
00151                 sReport += "\n";
00152         }
00153 
00154         if(pEventItem->ucDataLayout & 0x04)
00155         {
00156                 sReport += "Action........";
00157                 sprintf(szTmp, "0x%02X    (", pEventItem->ucAction);
00158                 sReport += szTmp;
00159                 if(pEventItem->ucAction & 0x01)
00160                         sReport += "Access permitted";
00161                 else if(! (pEventItem->ucAction & 0x01))
00162                         sReport += "Access denied";
00163                 
00164                 sReport += ")\n";
00165 
00166                 sReport += "Error.........";
00167                 sprintf(szTmp, "0x%04X  (", pEventItem->uiError);
00168                 sReport += szTmp;
00169                 if(pEventItem->uiError & 0x0001)
00170                         sReport += "RTC-Error";
00171                 if( (pEventItem->uiError & 0x0001) && (pEventItem->uiError & (~0x0001)))
00172                         sReport += ", ";
00173                 if(pEventItem->uiError & 0x0002)
00174                         sReport += "Metadata corrupt";
00175                 if( (pEventItem->uiError & 0x0002) && (pEventItem->uiError & (~0x0003)))
00176                         sReport += ", ";
00177                 if(pEventItem->uiError & 0x0004)
00178                         sReport += "Timezone Table CRC-Error";
00179                 if( (pEventItem->uiError & 0x0004) && (pEventItem->uiError & (~0x0007)))
00180                         sReport += ", ";
00181                 if(pEventItem->uiError & 0x0008)
00182                         sReport += "Holiday Table CRC-Error";
00183                 if( (pEventItem->uiError & 0x0008) && (pEventItem->uiError & (~0x000F)))
00184                         sReport += ", ";
00185                 if(pEventItem->uiError & 0x0010)
00186                         sReport += "Access Table CRC-Error";
00187                 if( (pEventItem->uiError & 0x0010) && (pEventItem->uiError & (~0x001F)))
00188                         sReport += ", ";
00189                 if(pEventItem->uiError & 0x0040)
00190                         sReport += "Reader Config mismatch";
00191                 if( (pEventItem->uiError & 0x0040) && (pEventItem->uiError & (~0x007F)))
00192                         sReport += ", ";
00193                 if(pEventItem->uiError & 0x0080)
00194                         sReport += "Table Update";
00195                 if( (pEventItem->uiError & 0x0080) && (pEventItem->uiError & (~0x00FF)))
00196                         sReport += ", ";
00197                 if(pEventItem->uiError & 0x8000)
00198                         sReport += "Overflow";
00199 
00200                 sReport += ")\n";
00201         }
00202 
00203         if(pEventItem->ucDataLayout & 0x08)
00204         {
00205                 sReport += "Input.........";
00206                 sprintf(szTmp, "0x%02X", pEventItem->ucInput);
00207                 sReport += szTmp;
00208                 sReport += "\n";
00209         }
00210         
00211         sReport += "Source........";
00212         sReport += cIPAdr;
00213         sReport += ":";
00214         sprintf(szTmp, "%d", iPortNr);
00215         sReport += szTmp;
00216         sReport += "\n";
00217 
00218         printf("%s\n", sReport.c_str());
00219         
00220         return 0;
00221 }
00222 
00223 
00224 void cbsKeepAlive(      void* pAny,                     // pAny
00225                         int iError,                     // error value
00226                         unsigned int uiErrorFlags,      // error flags from my axxess Reader
00227                         unsigned int uiTableSize,       // event table size
00228                         unsigned int uiTableLength,     // event table length
00229                         char* cIPAdr,                   // IP-Address
00230                         int iPortNr)                    // IP-Port
00231 {
00232         if((FedmIscMyAxxessReader*)pAny == NULL)
00233                 return;
00234 
00235         char    szTmp[32];
00236         string sReport;
00237 
00238         sReport = "\n";
00239         sReport += "[KeepAlive]\n";
00240 
00241         sReport += "Error.........";
00242         sprintf(szTmp, "0x%04X  (", uiErrorFlags);
00243         sReport += szTmp;
00244         if(uiErrorFlags & 0x0001)
00245                 sReport += "RTC-Error";
00246         if( (uiErrorFlags & 0x0001) && (uiErrorFlags & (~0x0001)))
00247                 sReport += ", ";
00248         if(uiErrorFlags & 0x0002)
00249                 sReport += "Metadata corrupt";
00250         if( (uiErrorFlags & 0x0002) && (uiErrorFlags & (~0x0003)))
00251                 sReport += ", ";
00252         if(uiErrorFlags & 0x0004)
00253                 sReport += "Timezone Table CRC-Error";
00254         if( (uiErrorFlags & 0x0004) && (uiErrorFlags & (~0x0007)))
00255                 sReport += ", ";
00256         if(uiErrorFlags & 0x0008)
00257                 sReport += "Holiday Table CRC-Error";
00258         if( (uiErrorFlags & 0x0008) && (uiErrorFlags & (~0x000F)))
00259                 sReport += ", ";
00260         if(uiErrorFlags & 0x0010)
00261                 sReport += "Access Table CRC-Error";
00262         if( (uiErrorFlags & 0x0010) && (uiErrorFlags & (~0x001F)))
00263                 sReport += ", ";
00264         if(uiErrorFlags & 0x0040)
00265                 sReport += "Reader Config mismatch";
00266         if( (uiErrorFlags & 0x0040) && (uiErrorFlags & (~0x007F)))
00267                 sReport += ", ";
00268         if(uiErrorFlags & 0x0080)
00269                 sReport += "Table Update";
00270         if( (uiErrorFlags & 0x0080) && (uiErrorFlags & (~0x00FF)))
00271                 sReport += ", ";
00272         if(uiErrorFlags & 0x8000)
00273                 sReport += "Overflow";
00274 
00275         sReport += ")\n";
00276 
00277         sReport += "Table-Size....";
00278         sprintf(szTmp, "%d\n", uiTableSize);
00279         sReport += szTmp;
00280         sReport += "Table-Length..";
00281         sprintf(szTmp, "%d\n", uiTableLength);
00282         sReport += szTmp;
00283         
00284         sReport += "Source........";
00285         sReport += cIPAdr;
00286         sReport += ":";
00287         sprintf(szTmp, "%d", iPortNr);
00288         sReport += szTmp;
00289         sReport += "\n";
00290 
00291         printf("%s\n", sReport.c_str());
00292 }


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