FedmIscMyAxxess_CsvParser.cpp
Go to the documentation of this file.
00001 /*-------------------------------------------------------
00002 |                                                       |
00003 |       FedmIscMyAxxess_CsvParser.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   : obid-support@feig.de
00014                                                 Internet : http://www.feig.de
00015                                         
00016 Author                  :       Markus Hultsch
00017 Begin                   :       25.06.2009
00018 Version                 :       03.01.00 / 09.02.2010 / B. Tschunko, M. Hultsch
00019 Operation Systems       :       independent
00020 Function                        :       parser for myAxxess Data Files
00021 
00022 OBID® and OBID i-scan® are registered Trademarks of FEIG ELECTRONIC GmbH.
00023 Linux® is a registered trademark of Linus Torvalds.
00024 Microsoft® and Windows® are registered trademarks of Microsoft Corporation.
00025 */
00026 
00027 
00028 //#############################
00029 //      I N C L U D E S
00030 //#############################
00031 #include "FedmIscCore.h"
00032 #include "FedmIscMyAxxess_CsvParser.h"
00033 
00034 
00035 //#######################################################################################
00036 //      class FedmIscMyAxxess_CsvParser
00037 //#######################################################################################
00038 FedmIscMyAxxess_CsvParser::FedmIscMyAxxess_CsvParser(FedmIscMyAxxessReader* pAxxessReader)
00039 {
00040         m_pAxxessReader = pAxxessReader;
00041 }
00042 
00043 
00044 FedmIscMyAxxess_CsvParser::~FedmIscMyAxxess_CsvParser(void)
00045 {
00046 }
00047 
00048 //#####################################################################################
00049 // serialization functions
00050 //#####################################################################################
00051 
00052 /***************************************************************************
00053   Begin         :       25.06.2009 / M. Hultsch
00054   Version       :       03.00.08 / 01.07.2009 / B. Tschunko
00055 
00056   Function              :       read CSV document and save content in data map
00057 
00058   Parameters    :       char* szCsvFileName     - pointer to buffer with filename
00059 
00060   Return value  :       FEDM_OK or error code (<0)
00061 ***************************************************************************/
00062 int FedmIscMyAxxess_CsvParser::SerializeIn(     char* szCsvFileName)
00063 {
00064         int iBack = 0;
00065         char* sPrt = NULL;
00066         string sValue;
00067 
00068         if(strlen(szCsvFileName) == 0 || strlen(szCsvFileName) > FEDM_CSV_MAX_FILENAME_SIZE)
00069         {
00070                 m_pAxxessReader->SetLastError(FEDM_ERROR_STRING_LENGTH);
00071                 return m_pAxxessReader->GetLastError();
00072         }
00073 
00074         FILE* hCvsFile = fopen (szCsvFileName, "r");
00075 
00076     if (hCvsFile == NULL)
00077     {
00078                 m_pAxxessReader->SetLastError(FEDM_ERROR_OPEN_FILE);
00079                 return m_pAxxessReader->GetLastError();
00080     }
00081 
00082         // allocate memory for line
00083         char* pLine = new char[128+1];
00084 
00085         if (pLine == NULL)
00086         {
00087                 fclose(hCvsFile);
00088                 m_pAxxessReader->SetLastError(FEDM_ERROR_NO_MORE_MEM);
00089                 return m_pAxxessReader->GetLastError();
00090         }
00091 
00092         memset(pLine, 0, 128+1);
00093 
00094         // read first line
00095     if(fscanf(hCvsFile, "%128[^\n]\n", pLine) == EOF)
00096         {
00097                 delete [] pLine;           
00098                 fclose(hCvsFile);
00099                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00100                 return m_pAxxessReader->GetLastError();
00101         }
00102 
00103         sPrt = strtok(pLine, ";");
00104 
00105         sValue = sPrt;
00106         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00107         if (sValue == "TIMEZONETABLE")
00108         {
00109                 iBack = SerializeIn_TimezoneTable(hCvsFile, pLine);
00110                 if (iBack)
00111                 {
00112                         m_pAxxessReader->ClearTable(FEDM_MYAXXESS_TIMEZONE_TABLE);
00113                 }
00114 
00115         }
00116         else if (sValue == "HOLIDAYTABLE")
00117         {
00118                 iBack = SerializeIn_HolidayTable(hCvsFile, pLine);
00119                 if (iBack)
00120                 {
00121                         m_pAxxessReader->ClearTable(FEDM_MYAXXESS_HOLIDAY_TABLE);
00122                 }
00123         }
00124         else if (sValue == "ACCESSTABLE")
00125         {
00126                 iBack = SerializeIn_AccessTable(hCvsFile, pLine);
00127                 if (iBack)
00128                 {
00129                         m_pAxxessReader->ClearTable(FEDM_MYAXXESS_ACCESS_TABLE);
00130                 }
00131         }
00132         else if (sValue == "EVENTTABLE")
00133         {
00134                 iBack = SerializeIn_EventTable(hCvsFile, pLine);
00135                 if (iBack)
00136                 {
00137                         m_pAxxessReader->ClearTable(FEDM_MYAXXESS_EVENT_TABLE);
00138                 }
00139         }
00140         else
00141         {
00142                 delete [] pLine;           
00143                 fclose(hCvsFile);
00144                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNKNOWN_TABLE_ID);
00145                 return m_pAxxessReader->GetLastError();
00146         }
00147 
00148         delete [] pLine;           
00149         fclose(hCvsFile);
00150 
00151         return iBack;
00152 }
00153 
00154 /***************************************************************************
00155   Begin         :       25.06.2009 / M. Hultsch
00156   Version       :       03.00.08 / 01.07.2009 / B. Tschunko
00157 
00158   Function              :       write content of data map into CSV document
00159 
00160   Parameters    :       unsigned int uiTableID  - table identifier from FedmIscMyAxxessReader.h
00161                                         char* szCsvFileName     - pointer to buffer with filename
00162 
00163   Return value  :       FEDM_OK or error code (<0)
00164 ***************************************************************************/
00165 int FedmIscMyAxxess_CsvParser::SerializeOut(unsigned int uiTableID, 
00166                                                                                         char* szCsvFileName)
00167 {
00168         int iBack = 0;
00169         char* sPrt = NULL;
00170 
00171         if(strlen(szCsvFileName) == 0 || strlen(szCsvFileName) > FEDM_CSV_MAX_FILENAME_SIZE)
00172         {
00173                 m_pAxxessReader->SetLastError(FEDM_ERROR_STRING_LENGTH);
00174                 return m_pAxxessReader->GetLastError();
00175         }
00176 
00177         //check filetype cvs
00178         char szTmpCsvFileName[FEDM_CSV_MAX_FILENAME_SIZE+1];
00179         strcpy(szTmpCsvFileName, szCsvFileName);
00180         FEDM_STRUPR(szTmpCsvFileName, strlen(szTmpCsvFileName)+1);
00181 
00182         sPrt = strtok(szTmpCsvFileName, ".");
00183         if (sPrt == NULL)
00184         {
00185                 m_pAxxessReader->SetLastError(FEDM_ERROR_OPEN_FILE);
00186                 return m_pAxxessReader->GetLastError();
00187         }
00188         sPrt = strtok(NULL, ".");
00189         if (sPrt == NULL)
00190         {
00191                 m_pAxxessReader->SetLastError(FEDM_ERROR_OPEN_FILE);
00192                 return m_pAxxessReader->GetLastError();
00193         }
00194         if (strcmp(sPrt, "CSV"))
00195         {
00196                 m_pAxxessReader->SetLastError(FEDM_ERROR_OPEN_FILE);
00197                 return m_pAxxessReader->GetLastError();
00198         }
00199 
00200         FILE* hCvsFile = fopen (szCsvFileName, "w");
00201 
00202     if (hCvsFile == NULL)
00203     {
00204                 m_pAxxessReader->SetLastError(FEDM_ERROR_OPEN_FILE);
00205                 return m_pAxxessReader->GetLastError();
00206     }
00207 
00208         switch (uiTableID)
00209         {
00210         case FEDM_MYAXXESS_TIMEZONE_TABLE:
00211 
00212                 iBack = SerializeOut_TimezoneTable(hCvsFile);
00213                 if (iBack)
00214                 {
00215                         //TODO: delete file;
00216                 }
00217                 break;
00218 
00219         case FEDM_MYAXXESS_HOLIDAY_TABLE:
00220 
00221                 iBack = SerializeOut_HolidayTable(hCvsFile);
00222                 if (iBack)
00223                 {
00224                         //TODO: delete file;
00225                 }
00226                 break;
00227 
00228         case FEDM_MYAXXESS_ACCESS_TABLE:
00229 
00230                 iBack = SerializeOut_AccessTable(hCvsFile);
00231                 if (iBack)
00232                 {
00233                         //TODO: delete file;
00234                 }
00235                 break;
00236 
00237         case FEDM_MYAXXESS_EVENT_TABLE:
00238 
00239                 iBack = SerializeOut_EventTable(hCvsFile);
00240                 if (iBack)
00241                 {
00242                         //TODO: delete file;
00243                 }
00244                 break;
00245 
00246         default:
00247                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNKNOWN_TABLE_ID);
00248                 return m_pAxxessReader->GetLastError();
00249         }
00250 
00251         fclose(hCvsFile);
00252 
00253         return iBack;
00254 }
00255 
00256 /***************************************************************************
00257   Begin         :       29.06.2009 / B. Tschunko
00258   Version       :       03.00.08 / 01.07.2009 / B. Tschunko
00259 
00260   Function              :       read CSV  for doc type timezone table
00261 
00262   Parameters    :       FILE* hCvsFile  - opened CVS file
00263                                         char* pLine - pointer to read each line
00264 
00265   Return value  :       FEDM_OK or error code (<0)
00266 ***************************************************************************/
00267 int FedmIscMyAxxess_CsvParser::SerializeIn_TimezoneTable(       FILE* hCvsFile,
00268                                                                                                                         char* pLine)
00269 {
00270         int iBack = 0;
00271         char* sPrt = NULL;
00272         string sValue;
00273         unsigned int uiCnt = 0;
00274         unsigned int uiNumber = 0;
00275 
00276         FEDM_ISC_MYAXXESS_TIMEZONE_TABLE_ITEM pItemTimezone;
00277         pItemTimezone.Init();
00278 
00279         vector<string> aName;
00280         vector<string> aValue;
00281 
00282     if (hCvsFile == NULL)
00283     {
00284                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00285                 return m_pAxxessReader->GetLastError();
00286     }
00287 
00288         m_pAxxessReader->ClearTable(FEDM_MYAXXESS_TIMEZONE_TABLE);
00289 
00290         // read second line
00291     if(fscanf(hCvsFile, "%128[^\n]\n", pLine) == EOF)
00292         {
00293                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00294                 return m_pAxxessReader->GetLastError();
00295         }
00296 
00297         // #### Check Table Header ####
00298         sPrt = strtok(pLine, ";");
00299         sValue = sPrt;
00300         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00301         if (sValue != "NUMBER")
00302         {
00303                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00304                 return m_pAxxessReader->GetLastError();
00305         }
00306 
00307         sPrt = strtok(NULL, ";");
00308         sValue = sPrt;
00309         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00310         if (sValue != "MO")
00311         {
00312                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00313                 return m_pAxxessReader->GetLastError();
00314         }
00315 
00316         sPrt = strtok(NULL, ";");
00317         sValue = sPrt;
00318         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00319         if (sValue != "TU")
00320         {
00321                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00322                 return m_pAxxessReader->GetLastError();
00323         }
00324 
00325         sPrt = strtok(NULL, ";");
00326         sValue = sPrt;
00327         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00328         if (sValue != "WE")
00329         {
00330                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00331                 return m_pAxxessReader->GetLastError();
00332         }
00333 
00334         sPrt = strtok(NULL, ";");
00335         sValue = sPrt;
00336         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00337         if (sValue != "TH")
00338         {
00339                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00340                 return m_pAxxessReader->GetLastError();
00341         }
00342 
00343         sPrt = strtok(NULL, ";");
00344         sValue = sPrt;
00345         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00346         if (sValue != "FR")
00347         {
00348                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00349                 return m_pAxxessReader->GetLastError();
00350         }
00351 
00352         sPrt = strtok(NULL, ";");
00353         sValue = sPrt;
00354         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00355         if (sValue != "SA")
00356         {
00357                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00358                 return m_pAxxessReader->GetLastError();
00359         }
00360 
00361         sPrt = strtok(NULL, ";");
00362         sValue = sPrt;
00363         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00364         if (sValue != "SU")
00365         {
00366                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00367                 return m_pAxxessReader->GetLastError();
00368         }
00369 
00370         sPrt = strtok(NULL, ";");
00371         sValue = sPrt;
00372         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00373         if (sValue != "DATEFROM")
00374         {
00375                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00376                 return m_pAxxessReader->GetLastError();
00377         }
00378 
00379         sPrt = strtok(NULL, ";");
00380         sValue = sPrt;
00381         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00382         if (sValue != "TIMEFROM")
00383         {
00384                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00385                 return m_pAxxessReader->GetLastError();
00386         }
00387 
00388         sPrt = strtok(NULL, ";");
00389         sValue = sPrt;
00390         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00391         if (sValue != "DATETO")
00392         {
00393                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00394                 return m_pAxxessReader->GetLastError();
00395         }
00396 
00397         sPrt = strtok(NULL, ";");
00398         sValue = sPrt;
00399         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00400         if (sValue != "TIMETO")
00401         {
00402                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00403                 return m_pAxxessReader->GetLastError();
00404         }
00405 
00406         // #### read Table Data ####
00407         aName.push_back("");
00408         aName.push_back("");
00409         aName.push_back("");
00410         aName.push_back("");
00411         aName.push_back("");
00412         aValue.push_back("");
00413         aValue.push_back("");
00414         aValue.push_back("");
00415         aValue.push_back("");
00416         aValue.push_back("");
00417 
00418         bool bAddPlus = false;
00419 
00420         // max. 15 Timezone Table Entries
00421         for (uiCnt = 0; uiCnt < 15; uiCnt++)
00422         {
00423                 aValue[0] = "";
00424                 aValue[1] = "";
00425                 aValue[2] = "";
00426                 aValue[3] = "";
00427                 aValue[4] = "";
00428 
00429                 // read next line
00430                 if(fscanf(hCvsFile, "%128[^\n]\n", pLine) == EOF)
00431                 {
00432                         break;
00433                 }
00434 
00435                 // check Number
00436                 sPrt = strtok(pLine, ";");
00437 
00438                 sscanf(sPrt, "%d", &uiNumber);
00439                 if (uiNumber != (uiCnt+1))
00440                 {
00441                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00442                         return m_pAxxessReader->GetLastError();
00443                 }
00444 
00445                 // get Days
00446                 bAddPlus = false;
00447                 aName[0] = "Days";
00448                 for (unsigned char ucDay = 0; ucDay < 7; ucDay++)
00449                 {
00450                         sPrt = strtok(NULL, ";");
00451                         if (sPrt == NULL)
00452                         {
00453                                 m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00454                                 return m_pAxxessReader->GetLastError();
00455                         }
00456 
00457                         if (!strcmp(sPrt, "0"))
00458                         {
00459                                 continue;
00460                         }
00461                         else if(!strcmp(sPrt, "1"))
00462                         {
00463                                 if (bAddPlus)
00464                                         aValue[0] += "+";
00465 
00466                                 switch (ucDay)
00467                                 {
00468                                 case 0:
00469                                         aValue[0] += "Mo";
00470                                         break;
00471 
00472                                 case 1:
00473                                         aValue[0] += "Tu";
00474                                         break;
00475 
00476                                 case 2:
00477                                         aValue[0] += "We";
00478                                         break;
00479 
00480                                 case 3:
00481                                         aValue[0] += "Th";
00482                                         break;
00483 
00484                                 case 4:
00485                                         aValue[0] += "Fr";
00486                                         break;
00487 
00488                                 case 5:
00489                                         aValue[0] += "Sa";
00490                                         break;
00491 
00492                                 case 6:
00493                                         aValue[0] += "Su";
00494                                         break;
00495                                 }
00496                                 bAddPlus = true;
00497                         }
00498                         else
00499                         {
00500                                 m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00501                                 return m_pAxxessReader->GetLastError();
00502                         }
00503                 }
00504 
00505                 // get DateFrom
00506                 sPrt = strtok(NULL, ";");
00507                 if (sPrt == NULL)
00508                 {
00509                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00510                         return m_pAxxessReader->GetLastError();
00511                 }
00512                 aName[1] = "DateFrom";
00513                 aValue[1] = sPrt;
00514 
00515                 // get TimeFrom
00516                 sPrt = strtok(NULL, ";");
00517                 if (sPrt == NULL)
00518                 {
00519                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00520                         return m_pAxxessReader->GetLastError();
00521                 }
00522                 aName[2] = "TimeFrom";
00523                 aValue[2] = sPrt;
00524 
00525                 // get DateTo value
00526                 sPrt = strtok(NULL, ";");
00527                 if (sPrt == NULL)
00528                 {
00529                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00530                         return m_pAxxessReader->GetLastError();
00531                 }
00532                 aName[3] = "DateTo";
00533                 aValue[3] = sPrt;
00534 
00535                 // get TimeTo value
00536                 sPrt = strtok(NULL, ";");
00537                 if (sPrt == NULL)
00538                 {
00539                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00540                         return m_pAxxessReader->GetLastError();
00541                 }
00542                 aName[4] = "TimeTo";
00543                 aValue[4] = sPrt;
00544 
00545                 // build and add Timezone
00546                 iBack = m_pAxxessReader->BuildTableItem(aName, aValue, &pItemTimezone);
00547                 if(iBack != 0)
00548                 {
00549                         return iBack;
00550                 }               
00551                 iBack = m_pAxxessReader->AddTableItem(&pItemTimezone);
00552                 if (iBack != 0)
00553                 {
00554                         return iBack;
00555                 }
00556         }
00557 
00558         // all lines read
00559         if (uiCnt == 15)
00560         {
00561                 if(fscanf(hCvsFile, "%128[^\n]\n", pLine) != EOF)
00562                 {
00563                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00564                         return m_pAxxessReader->GetLastError();
00565                 }
00566         }
00567 
00568         m_pAxxessReader->SetLastError(FEDM_OK);
00569         return m_pAxxessReader->GetLastError();
00570 }
00571 
00572 /***************************************************************************
00573   Begin         :       29.06.2009 / B. Tschunko
00574   Version       :       03.00.08 / 01.07.2009 / B. Tschunko
00575 
00576   Function              :       read CSV  for doc type holiday table
00577 
00578   Parameters    :       FILE* hCvsFile  - opened CVS file
00579                                         char* pLine - pointer to read each line
00580 
00581   Return value  :       FEDM_OK or error code (<0)
00582 ***************************************************************************/
00583 int FedmIscMyAxxess_CsvParser::SerializeIn_HolidayTable(        FILE* hCvsFile,
00584                                                                                                                         char* pLine)
00585 {
00586         int iBack = 0;
00587         char* sPrt = NULL;
00588         string sValue;
00589         unsigned int uiCnt = 0;
00590 
00591         FEDM_ISC_MYAXXESS_HOLIDAY_TABLE_ITEM pItemHoliday;
00592         pItemHoliday.Init();
00593 
00594         vector<string> aName;
00595         vector<string> aValue;
00596 
00597     if (hCvsFile == NULL)
00598     {
00599                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00600                 return m_pAxxessReader->GetLastError();
00601     }
00602 
00603         m_pAxxessReader->ClearTable(FEDM_MYAXXESS_HOLIDAY_TABLE);
00604 
00605         // read second line
00606     if(fscanf(hCvsFile, "%128[^\n]\n", pLine) == EOF)
00607         {
00608                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00609                 return m_pAxxessReader->GetLastError();
00610         }
00611 
00612         // #### Check Table Header ####
00613         sPrt = strtok(pLine, ";");
00614         sValue = sPrt;
00615         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00616         if (sValue != "NUMBER")
00617         {
00618                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00619                 return m_pAxxessReader->GetLastError();
00620         }
00621 
00622         sPrt = strtok(NULL, ";");
00623         sValue = sPrt;
00624         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00625         if (sValue != "HOLIDAY")
00626         {
00627                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00628                 return m_pAxxessReader->GetLastError();
00629         }
00630 
00631         // #### read Table Data ####
00632         aName.push_back("");
00633         aValue.push_back("");
00634 
00635         
00636         // max. 256 Holiday Table Entries
00637         for (uiCnt = 0; uiCnt < 256; uiCnt++)
00638         {
00639                 aValue[0] = "";
00640 
00641                 // read next line
00642                 if(fscanf(hCvsFile, "%128[^\n]\n", pLine) == EOF)
00643                 {
00644                         break;
00645                 }
00646 
00647                 // remove Number
00648                 sPrt = strtok(pLine, ";");
00649 
00650                 // get Holiday
00651                 sPrt = strtok(NULL, ";");
00652                 if (sPrt == NULL)
00653                 {
00654                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00655                         return m_pAxxessReader->GetLastError();
00656                 }
00657                 aName[0] = "Holiday";
00658                 aValue[0] = sPrt;
00659 
00660                 // build and add Holiday
00661                 iBack = m_pAxxessReader->BuildTableItem(aName, aValue, &pItemHoliday);
00662                 if(iBack != 0)
00663                 {
00664                         return iBack;
00665                 }               
00666                 iBack = m_pAxxessReader->AddTableItem(&pItemHoliday);
00667                 if (iBack != 0)
00668                 {
00669                         return iBack;
00670                 }
00671         }
00672 
00673         // all lines read
00674         if (uiCnt == 256)
00675         {
00676                 if(fscanf(hCvsFile, "%128[^\n]\n", pLine) != EOF)
00677                 {
00678                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00679                         return m_pAxxessReader->GetLastError();
00680                 }
00681         }
00682 
00683         m_pAxxessReader->SetLastError(FEDM_OK);
00684         return m_pAxxessReader->GetLastError();
00685 }
00686 
00687 /***************************************************************************
00688   Begin         :       29.06.2009 / B. Tschunko
00689   Version       :       03.00.08 / 01.07.2009 / B. Tschunko
00690 
00691   Function              :       read CSV  for doc type access table
00692 
00693   Parameters    :       FILE* hCvsFile  - opened CVS file
00694                                         char* pLine - pointer to read each line
00695 
00696   Return value  :       FEDM_OK or error code (<0)
00697 ***************************************************************************/
00698 int FedmIscMyAxxess_CsvParser::SerializeIn_AccessTable( FILE* hCvsFile,
00699                                                                                                                 char* pLine)
00700 {
00701         int iBack = 0;
00702         char* sPrt = NULL;
00703         string sValue;
00704         unsigned int uiCnt = 0;
00705         unsigned int uiLength = 0;
00706 
00707         FEDM_ISC_MYAXXESS_ACCESS_TABLE_ITEM pItemAccess;
00708         pItemAccess.Init();
00709 
00710         vector<string> aName;
00711         vector<string> aValue;
00712 
00713     if (hCvsFile == NULL)
00714     {
00715                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00716                 return m_pAxxessReader->GetLastError();
00717     }
00718 
00719         m_pAxxessReader->ClearTable(FEDM_MYAXXESS_ACCESS_TABLE);
00720 
00721         // read second line
00722     if(fscanf(hCvsFile, "%128[^\n]\n", pLine) == EOF)
00723         {
00724                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00725                 return m_pAxxessReader->GetLastError();
00726         }
00727 
00728         // #### Check IDD-Format Info ####
00729         sPrt = strtok(pLine, ";");
00730         sValue = sPrt;
00731         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00732         if (sValue != "IDD-FORMAT")
00733         {
00734                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00735                 return m_pAxxessReader->GetLastError();
00736         }
00737 
00738         sPrt = strtok(NULL, ";");
00739         sValue = sPrt;
00740         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00741         if (sValue == "ASCII")
00742         {
00743                 iBack = m_pAxxessReader->SetIDDFormat(FEDM_MYAXXESS_IDD_FORMAT_ASCII);
00744                 if (iBack)
00745                 {
00746                         return iBack;
00747                 }
00748         }
00749         else if(sValue == "NUM")
00750         {
00751                 iBack = m_pAxxessReader->SetIDDFormat(FEDM_MYAXXESS_IDD_FORMAT_NUM);
00752                 if (iBack)
00753                 {
00754                         return iBack;
00755                 }
00756         }
00757         else if(sValue == "HEX")
00758         {
00759                 iBack = m_pAxxessReader->SetIDDFormat(FEDM_MYAXXESS_IDD_FORMAT_HEX);
00760                 if (iBack)
00761                 {
00762                         return iBack;
00763                 }
00764         }
00765         else
00766         {
00767                 m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00768                 return m_pAxxessReader->GetLastError();
00769         }
00770 
00771         // read third line
00772     if(fscanf(hCvsFile, "%128[^\n]\n", pLine) == EOF)
00773         {
00774                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00775                 return m_pAxxessReader->GetLastError();
00776         }
00777 
00778         // #### Check IDD-Length Info ####
00779         sPrt = strtok(pLine, ";");
00780         sValue = sPrt;
00781         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00782         if (sValue != "IDD-LENGTH")
00783         {
00784                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00785                 return m_pAxxessReader->GetLastError();
00786         }
00787 
00788         sPrt = strtok(NULL, ";");
00789         sscanf(sPrt, "%d", &uiLength);
00790         iBack = m_pAxxessReader->SetIDDLength(uiLength);
00791         if (iBack)
00792         {
00793                 return iBack;
00794         }
00795 
00796         // read forth line
00797     if(fscanf(hCvsFile, "%128[^\n]\n", pLine) == EOF)
00798         {
00799                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00800                 return m_pAxxessReader->GetLastError();
00801         }
00802 
00803         // #### Check Table Header ####
00804         sPrt = strtok(pLine, ";");
00805         sValue = sPrt;
00806         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00807         if (sValue != "NUMBER")
00808         {
00809                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00810                 return m_pAxxessReader->GetLastError();
00811         }
00812 
00813         sPrt = strtok(NULL, ";");
00814         sValue = sPrt;
00815         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00816         if (sValue != "IDD")
00817         {
00818                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00819                 return m_pAxxessReader->GetLastError();
00820         }
00821 
00822         sPrt = strtok(NULL, ";");
00823         sValue = sPrt;
00824         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00825         if (sValue != "TIMEZONES")
00826         {
00827                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00828                 return m_pAxxessReader->GetLastError();
00829         }
00830 /*
00831         sPrt = strtok(NULL, ";");
00832         sValue = sPrt;
00833         FEDM_STRUPR((char *)(sValue.c_str()), sValue.length()+1);
00834         if (sValue != "RESERVED")
00835         {
00836                 m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED_NAMESPACE);
00837                 return m_pAxxessReader->GetLastError();
00838         }
00839 */
00840 
00841         // #### read Table Data ####
00842         aName.push_back("");
00843         aName.push_back("");
00844 //      aName.push_back("");
00845         aValue.push_back("");
00846         aValue.push_back("");
00847 //      aValue.push_back("");
00848 
00849         // max. 65535 Access Table Entries
00850         for (uiCnt = 0; uiCnt < 65535; uiCnt++)
00851         {
00852                 aValue[0] = "";
00853                 aValue[1] = "";
00854 //              aValue[2] = "";
00855 
00856                 // read next line
00857                 if(fscanf(hCvsFile, "%128[^\n]\n", pLine) == EOF)
00858                 {
00859                         break;
00860                 }
00861 
00862                 // remove Number
00863                 sPrt = strtok(pLine, ";");
00864 
00865                 // get IDD
00866                 sPrt = strtok(NULL, ";");
00867                 if (sPrt == NULL)
00868                 {
00869                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00870                         return m_pAxxessReader->GetLastError();
00871                 }
00872                 aName[0] = "IDD";
00873                 aValue[0] = sPrt;
00874 
00875 
00876                 // get Timezones
00877                 sPrt = strtok(NULL, ";");
00878                 if (sPrt == NULL)
00879                 {
00880                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00881                         return m_pAxxessReader->GetLastError();
00882                 }
00883                 aName[1] = "Timezones";
00884                 aValue[1] = sPrt;
00885 /*
00886                 // get Reserved
00887                 sPrt = strtok(NULL, ";");
00888                 if (sPrt == NULL)
00889                 {
00890                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00891                         return m_pAxxessReader->GetLastError();
00892                 }
00893                 aName[2] = "Reserved";
00894                 aValue[2] = sPrt;
00895 */              
00896                 // build and add Access Entry
00897                 iBack = m_pAxxessReader->BuildTableItem(aName, aValue, &pItemAccess);
00898                 if(iBack != 0)
00899                 {
00900                         return iBack;
00901                 }               
00902                 iBack = m_pAxxessReader->AddTableItem(&pItemAccess);
00903                 if (iBack != 0)
00904                 {
00905                         return iBack;
00906                 }
00907         }
00908 
00909         // all lines read
00910         if (uiCnt == 65535)
00911         {
00912             if(fscanf(hCvsFile, "%128[^\n]\n", pLine) != EOF)
00913                 {
00914                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
00915                         return m_pAxxessReader->GetLastError();
00916                 }
00917         }
00918 
00919         m_pAxxessReader->SetLastError(FEDM_OK);
00920         return m_pAxxessReader->GetLastError();
00921 }
00922 
00923 
00924 /***************************************************************************
00925   Begin         :       06.07.2009 / B. Tschunko
00926   Version       :       03.00.08 / 06.07.2009 / B. Tschunko
00927 
00928   Function              :       read CSV  for doc type event table
00929 
00930   Parameters    :       FILE* hCvsFile  - opened CVS file
00931                                         char* pLine - pointer to read each line
00932 
00933   Return value  :       FEDM_OK or error code (<0)
00934 ***************************************************************************/
00935 int FedmIscMyAxxess_CsvParser::SerializeIn_EventTable(  FILE* hCvsFile,
00936                                                                                                                 char* pLine)
00937 {
00938         m_pAxxessReader->SetLastError(FEDM_ERROR_UNSUPPORTED);
00939         return m_pAxxessReader->GetLastError();
00940 }
00941 
00942 
00943 
00944 
00945 /***************************************************************************
00946   Begin         :       01.07.2009 / B. Tschunko
00947   Version       :       03.00.08 / 01.07.2009 / B. Tschunko
00948 
00949   Function              :       write CSV  for doc type timezone table
00950 
00951   Parameters    :       FILE* hCvsFile  - opened CVS file
00952 
00953   Return value  :       FEDM_OK or error code (<0)
00954 ***************************************************************************/
00955 int FedmIscMyAxxess_CsvParser::SerializeOut_TimezoneTable(      FILE* hCvsFile)
00956 {
00957         unsigned int uiNumber = 0;
00958         char    buf[512];
00959 
00960     if (hCvsFile == NULL)
00961     {
00962                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
00963                 return m_pAxxessReader->GetLastError();
00964     }
00965 
00966         // #### Write Table Identifier ####
00967         sprintf(buf, "TimezoneTable\n");
00968         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
00969 
00970         // #### Write Table Header ####
00971         sprintf(buf, "Number;Mo;Tu;We;Th;Fr;Sa;Su;DateFrom;TimeFrom;DateTo;TimeTo\n");
00972         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
00973 
00974         // #### Write Table Data ####
00975         FEDM_ISC_MYAXXESS_TIMEZONE_TABLE_ITEM*  pTimezoneItem   = NULL;
00976         vector<FEDM_ISC_MYAXXESS_TIMEZONE_TABLE_ITEM*>::iterator        itorTimezone;
00977 
00978         uiNumber = 0;
00979         // load Holiday Table
00980         for(itorTimezone  = m_pAxxessReader->m_TimezoneTable.begin();
00981                 itorTimezone != m_pAxxessReader->m_TimezoneTable.end();
00982                 itorTimezone++)
00983         {
00984                 if ((*itorTimezone) == NULL)
00985                         continue;
00986 
00987                 pTimezoneItem = *itorTimezone;
00988 
00989                 switch (m_pAxxessReader->m_ucDateFormat)
00990                 {
00991                 case FEDM_MYAXXESS_DATE_FORMAT_ISO8601:
00992                         sprintf(buf, 
00993                                         "%i;%d;%d;%d;%d;%d;%d;%d;20%02d-%02d-%02d;%02d:%02d;20%02d-%02d-%02d;%02d:%02d\n",      
00994                                         ++uiNumber,
00995                                         ((pTimezoneItem->ucDays>>1) & 0x01),
00996                                         ((pTimezoneItem->ucDays>>2) & 0x01),
00997                                         ((pTimezoneItem->ucDays>>3) & 0x01),
00998                                         ((pTimezoneItem->ucDays>>4) & 0x01),
00999                                         ((pTimezoneItem->ucDays>>5) & 0x01),
01000                                         ((pTimezoneItem->ucDays>>6) & 0x01),
01001                                         (pTimezoneItem->ucDays & 0x01),
01002                                         pTimezoneItem->ucStartDate_Year, 
01003                                         pTimezoneItem->ucStartDate_Month,
01004                                         pTimezoneItem->ucStartDate_Day,
01005                                         pTimezoneItem->ucStartTime_Hour,
01006                                         pTimezoneItem->ucStartTime_Minute, 
01007                                         pTimezoneItem->ucEndDate_Year, 
01008                                         pTimezoneItem->ucEndDate_Month,
01009                                         pTimezoneItem->ucEndDate_Day,
01010                                         pTimezoneItem->ucEndTime_Hour,
01011                                         pTimezoneItem->ucEndTime_Minute);
01012                         break;
01013 
01014                 case FEDM_MYAXXESS_DATE_FORMAT_GER:
01015                         sprintf(buf, 
01016                                         "%i;%d;%d;%d;%d;%d;%d;%d;%02d.%02d.20%02d;%02d:%02d;%02d.%02d.20%02d;%02d:%02d\n",      
01017                                         ++uiNumber,
01018                                         ((pTimezoneItem->ucDays>>1) & 0x01),
01019                                         ((pTimezoneItem->ucDays>>2) & 0x01),
01020                                         ((pTimezoneItem->ucDays>>3) & 0x01),
01021                                         ((pTimezoneItem->ucDays>>4) & 0x01),
01022                                         ((pTimezoneItem->ucDays>>5) & 0x01),
01023                                         ((pTimezoneItem->ucDays>>6) & 0x01),
01024                                         (pTimezoneItem->ucDays & 0x01),
01025                                         pTimezoneItem->ucStartDate_Day, 
01026                                         pTimezoneItem->ucStartDate_Month,
01027                                         pTimezoneItem->ucStartDate_Year,
01028                                         pTimezoneItem->ucStartTime_Hour,
01029                                         pTimezoneItem->ucStartTime_Minute, 
01030                                         pTimezoneItem->ucEndDate_Day, 
01031                                         pTimezoneItem->ucEndDate_Month,
01032                                         pTimezoneItem->ucEndDate_Year,
01033                                         pTimezoneItem->ucEndTime_Hour,
01034                                         pTimezoneItem->ucEndTime_Minute);
01035                         break;
01036 
01037                 case FEDM_MYAXXESS_DATE_FORMAT_US:
01038                         sprintf(buf, 
01039                                         "%i;%d;%d;%d;%d;%d;%d;%d;%02d/%02d/20%02d;%02d:%02d;%02d/%02d/20%02d;%02d:%02d\n",      
01040                                         ++uiNumber,
01041                                         ((pTimezoneItem->ucDays>>1) & 0x01),
01042                                         ((pTimezoneItem->ucDays>>2) & 0x01),
01043                                         ((pTimezoneItem->ucDays>>3) & 0x01),
01044                                         ((pTimezoneItem->ucDays>>4) & 0x01),
01045                                         ((pTimezoneItem->ucDays>>5) & 0x01),
01046                                         ((pTimezoneItem->ucDays>>6) & 0x01),
01047                                         (pTimezoneItem->ucDays & 0x01),
01048                                         pTimezoneItem->ucStartDate_Month, 
01049                                         pTimezoneItem->ucStartDate_Day,
01050                                         pTimezoneItem->ucStartDate_Year,
01051                                         pTimezoneItem->ucStartTime_Hour,
01052                                         pTimezoneItem->ucStartTime_Minute, 
01053                                         pTimezoneItem->ucEndDate_Month, 
01054                                         pTimezoneItem->ucEndDate_Day,
01055                                         pTimezoneItem->ucEndDate_Year,
01056                                         pTimezoneItem->ucEndTime_Hour,
01057                                         pTimezoneItem->ucEndTime_Minute);
01058                         break;
01059 
01060                 default:
01061                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
01062                         return m_pAxxessReader->GetLastError();
01063                 }
01064 
01065                 fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01066         }
01067 
01068         m_pAxxessReader->SetLastError(FEDM_OK);
01069         return m_pAxxessReader->GetLastError();
01070 }
01071 
01072 /***************************************************************************
01073   Begin         :       01.07.2009 / B. Tschunko
01074   Version       :       03.00.08 / 01.07.2009 / B. Tschunko
01075 
01076   Function              :       write CSV  for doc type holiday table
01077 
01078   Parameters    :       FILE* hCvsFile  - opened CVS file
01079 
01080   Return value  :       FEDM_OK or error code (<0)
01081 ***************************************************************************/
01082 int FedmIscMyAxxess_CsvParser::SerializeOut_HolidayTable(       FILE* hCvsFile)
01083 {
01084         unsigned int uiNumber = 0;
01085         char    buf[512];
01086 
01087     if (hCvsFile == NULL)
01088     {
01089                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
01090                 return m_pAxxessReader->GetLastError();
01091     }
01092 
01093         // #### Write Table Identifier ####
01094         sprintf(buf, "HolidayTable\n");
01095         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01096 
01097         // #### Write Table Header ####
01098         sprintf(buf, "Number;Holiday\n");
01099         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01100 
01101         // #### Write Table Data ####
01102         FEDM_ISC_MYAXXESS_HOLIDAY_TABLE_ITEM*   pHolidayItem    = NULL;
01103         vector<FEDM_ISC_MYAXXESS_HOLIDAY_TABLE_ITEM*>::iterator itorHoliday;
01104 
01105         uiNumber = 0;
01106         // load Holiday Table
01107         for(itorHoliday  = m_pAxxessReader->m_HolidayTable.begin();
01108                 itorHoliday != m_pAxxessReader->m_HolidayTable.end();
01109                 itorHoliday++)
01110         {
01111                 if ((*itorHoliday) == NULL)
01112                         continue;
01113 
01114                 pHolidayItem = *itorHoliday;
01115 
01116                 switch (m_pAxxessReader->m_ucDateFormat)
01117                 {
01118                 case FEDM_MYAXXESS_DATE_FORMAT_ISO8601:
01119                         sprintf(buf, 
01120                                         "%i;20%02d-%02d-%02d\n",        
01121                                         ++uiNumber,                             
01122                                         pHolidayItem->ucHoliday_Year,           
01123                                         pHolidayItem->ucHoliday_Month,          
01124                                         pHolidayItem->ucHoliday_Day);
01125                         break;
01126 
01127                 case FEDM_MYAXXESS_DATE_FORMAT_GER:
01128                         sprintf(buf,
01129                                         "%i;%02d.%02d.20%02d\n",
01130                                         ++uiNumber,
01131                                         pHolidayItem->ucHoliday_Day,
01132                                         pHolidayItem->ucHoliday_Month,
01133                                         pHolidayItem->ucHoliday_Year);
01134                         break;
01135 
01136                 case FEDM_MYAXXESS_DATE_FORMAT_US:
01137                         sprintf(buf, 
01138                                         "%i;%02d/%02d/20%02d\n",
01139                                         ++uiNumber,
01140                                         pHolidayItem->ucHoliday_Month,
01141                                         pHolidayItem->ucHoliday_Day,
01142                                         pHolidayItem->ucHoliday_Year);
01143                         break;
01144 
01145                 default:
01146                         m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
01147                         return m_pAxxessReader->GetLastError();
01148                 }
01149 
01150                 fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01151         }
01152 
01153         m_pAxxessReader->SetLastError(FEDM_OK);
01154         return m_pAxxessReader->GetLastError();
01155 }
01156 
01157 /***************************************************************************
01158   Begin         :       01.07.2009 / B. Tschunko
01159   Version       :       03.00.08 / 01.07.2009 / B. Tschunko
01160 
01161   Function              :       write CSV  for doc type access table
01162 
01163   Parameters    :       FILE* hCvsFile  - opened CVS file
01164 
01165   Return value  :       FEDM_OK or error code (<0)
01166 ***************************************************************************/
01167 int FedmIscMyAxxess_CsvParser::SerializeOut_AccessTable(        FILE* hCvsFile)
01168 {
01169         unsigned int uiNumber = 0;
01170         char    buf[512];
01171         char    szIDD[256];
01172         unsigned __int64 ui64IDD = 0;
01173         bool bAddPlus = false;
01174         char szTimezones[64];
01175 
01176         memset(szIDD, 0, 64);
01177 
01178     if (hCvsFile == NULL)
01179     {
01180                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
01181                 return m_pAxxessReader->GetLastError();
01182     }
01183 
01184         // #### Write Table Identifier ####
01185         sprintf(buf, "AccessTable\n");
01186         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01187 
01188         // #### IDD-Format Info ####
01189         switch (m_pAxxessReader->m_Metadata.ucIDDFormat)
01190         {
01191         case FEDM_MYAXXESS_IDD_FORMAT_ASCII:
01192                 sprintf(buf, "IDD-Format;ASCII\n");
01193                 break;
01194 
01195         case FEDM_MYAXXESS_IDD_FORMAT_NUM:
01196                 sprintf(buf, "IDD-Format;Num\n");
01197                 break;
01198 
01199         case FEDM_MYAXXESS_IDD_FORMAT_HEX:
01200                 sprintf(buf, "IDD-Format;Hex\n");
01201                 break;
01202 
01203         default:
01204                 m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
01205                 return m_pAxxessReader->GetLastError();
01206         }
01207         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01208 
01209         // #### IDD-Length Info ####
01210         if ((m_pAxxessReader->m_Metadata.ucIDDLength < 1) || (m_pAxxessReader->m_Metadata.ucIDDLength > 64))
01211         {
01212                 m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
01213                 return m_pAxxessReader->GetLastError();
01214         }
01215         sprintf(buf, "IDD-Length;%d\n", m_pAxxessReader->m_Metadata.ucIDDLength);
01216         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01217 
01218         // #### Write Table Header ####
01219         sprintf(buf, "Number;IDD;Timezones;Reserved\n");
01220         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01221 
01222         // #### Write Table Data ####
01223         FEDM_ISC_MYAXXESS_ACCESS_TABLE_ITEM*    pAccessItem     = NULL;
01224         vector<FEDM_ISC_MYAXXESS_ACCESS_TABLE_ITEM*>::iterator  itorAccess;
01225 
01226         uiNumber = 0;
01227 
01228         // load Access Table
01229         for(itorAccess  = m_pAxxessReader->m_AccessTable.begin();
01230                 itorAccess != m_pAxxessReader->m_AccessTable.end();
01231                 itorAccess++)
01232         {
01233                 if ((*itorAccess) == NULL)
01234                         continue;
01235 
01236                 pAccessItem = *itorAccess;
01237 
01238                 switch(m_pAxxessReader->m_Metadata.ucIDDFormat)
01239                 {
01240                 case FEDM_MYAXXESS_IDD_FORMAT_ASCII:
01241                         memcpy(szIDD, pAccessItem->ucIDD, m_pAxxessReader->m_Metadata.ucIDDLength);
01242                         szIDD[m_pAxxessReader->m_Metadata.ucIDDLength] = '\0';
01243                         break;
01244 
01245                 case FEDM_MYAXXESS_IDD_FORMAT_NUM:
01246                         if(strlen((char*)pAccessItem->ucIDD) > 20)
01247                         {
01248                                 m_pAxxessReader->SetLastError(FEDM_ERROR_STRING_LENGTH);
01249                                 return m_pAxxessReader->GetLastError();
01250                         }
01251                         ui64IDD = 0;
01252                         for (unsigned char ucByte = 0; ucByte < m_pAxxessReader->m_Metadata.ucIDDLength; ucByte++)
01253                         {
01254                                 // change Motorola format to Intel format
01255                                 ui64IDD += ( (unsigned __int64)pAccessItem->ucIDD[m_pAxxessReader->m_Metadata.ucIDDLength-ucByte-1] << (8*ucByte) );
01256                         }
01257                         sprintf(szIDD,"%lld",ui64IDD);
01258                         break;
01259 
01260                 case FEDM_MYAXXESS_IDD_FORMAT_HEX:
01261                         FEDM_ConvHexUCharToHexChar(pAccessItem->ucIDD, m_pAxxessReader->m_Metadata.ucIDDLength, szIDD, 256);
01262                         break;
01263                 }
01264 
01265                 bAddPlus = false;
01266                 for (unsigned char ucCnt = 0; ucCnt < 16; ucCnt++)
01267                 {
01268                         if (pAccessItem->uiTimezones & (0x01 << ucCnt))
01269                         {
01270                                 if (bAddPlus)
01271                                         sprintf(szTimezones, "%s+%d", szTimezones, ucCnt+1);
01272                                 else
01273                                         sprintf(szTimezones, "%d", ucCnt+1);
01274                                 bAddPlus = true;
01275                         }
01276                 }
01277 
01278                 sprintf(buf, 
01279                                 "%i;%s;%s;%d\n",        
01280                                 ++uiNumber,
01281                                 szIDD,
01282                                 szTimezones,
01283                                 pAccessItem->ucReserved);
01284 
01285                 fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01286         }
01287 
01288         m_pAxxessReader->SetLastError(FEDM_OK);
01289         return m_pAxxessReader->GetLastError();
01290 }
01291 
01292 
01293 /***************************************************************************
01294   Begin         :       01.07.2009 / B. Tschunko
01295   Version       :       03.00.13 / 30.09.2009 / B. Tschunko, M. Hultsch
01296 
01297   Function              :       write CSV  for doc type event table
01298 
01299   Parameters    :       FILE* hCvsFile  - opened CVS file
01300 
01301   Return value  :       FEDM_OK or error code (<0)
01302 ***************************************************************************/
01303 int FedmIscMyAxxess_CsvParser::SerializeOut_EventTable( FILE* hCvsFile)
01304 {
01305         unsigned int uiNumber = 0;
01306         char    buf[512];
01307         char    szIDD[256];
01308         char    szTimestamp[64];
01309         char    szStatus[32];
01310         char    szInput[32];
01311         char    szAnt[32];
01312         unsigned __int64 ui64IDD = 0;
01313 
01314     if (hCvsFile == NULL)
01315     {
01316                 m_pAxxessReader->SetLastError(FEDM_ERROR_READ_FILE);
01317                 return m_pAxxessReader->GetLastError();
01318     }
01319 
01320         memset(szIDD, 0, 64);
01321         memset(szTimestamp, 0, 64);
01322         memset(szStatus, 0, 32);
01323         memset(szInput, 0, 32);
01324         memset(szAnt, 0, 32);
01325 
01326         // #### Write Table Identifier ####
01327         sprintf(buf, "EventTable\n");
01328         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01329 
01330         // #### Write IDD Format ####
01331         switch (m_pAxxessReader->m_Metadata.ucIDDFormat)
01332         {
01333         case FEDM_MYAXXESS_IDD_FORMAT_ASCII:
01334                 sprintf(buf, "IDD-Format;ASCII\n");
01335                 break;
01336 
01337         case FEDM_MYAXXESS_IDD_FORMAT_NUM:
01338                 sprintf(buf, "IDD-Format;Num\n");
01339                 break;
01340 
01341         case FEDM_MYAXXESS_IDD_FORMAT_HEX:
01342                 sprintf(buf, "IDD-Format;Hex\n");
01343                 break;
01344 
01345         default:
01346                 m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
01347                 return m_pAxxessReader->GetLastError();
01348         }
01349         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01350 
01351         // #### Write Table Header ####
01352         sprintf(buf, "Number;EventID;IDD;Date;Time;Input;Ant;Action;Error;Source\n");
01353         fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01354 
01355         // #### Write Table Data ####
01356         FEDM_ISC_MYAXXESS_EVENT_TABLE_ITEM*     pEventItem      = NULL;
01357 
01358         uiNumber = 0;
01359         // load Event Table
01360         while(! m_pAxxessReader->m_EventTable.empty())
01361         {
01362                 pEventItem = m_pAxxessReader->m_EventTable.front();
01363                 if(pEventItem == NULL)
01364                         continue;
01365 
01366                 if(pEventItem->ucDataLayout & 0x01)
01367                 {
01368                         switch(m_pAxxessReader->m_Metadata.ucIDDFormat)
01369                         {
01370                         case FEDM_MYAXXESS_IDD_FORMAT_ASCII:
01371                                 memcpy(szIDD, pEventItem->ucIDD, pEventItem->ucIDDLength);
01372                                 szIDD[pEventItem->ucIDDLength] = '\0';
01373                                 break;
01374 
01375                         case FEDM_MYAXXESS_IDD_FORMAT_NUM:
01376                                 if(strlen((char*)pEventItem->ucIDD) > 20)
01377                                 {
01378                                         m_pAxxessReader->m_EventTable.pop();
01379                                         m_pAxxessReader->SetLastError(FEDM_ERROR_STRING_LENGTH);
01380                                         return m_pAxxessReader->GetLastError();
01381                                 }       
01382                                 ui64IDD = 0;
01383                                 for(unsigned char ucByte=0; ucByte<pEventItem->ucIDDLength; ucByte++ )
01384                                 {
01385                                         // change Motorola format to Intel format
01386                                         ui64IDD += ( (unsigned __int64)pEventItem->ucIDD[pEventItem->ucIDDLength-ucByte-1] << (8*ucByte) );
01387                                 }
01388                                 sprintf(szIDD,"%lld",ui64IDD);
01389                                 break;
01390 
01391                         case FEDM_MYAXXESS_IDD_FORMAT_HEX:
01392                                 FEDM_ConvHexUCharToHexChar(pEventItem->ucIDD, pEventItem->ucIDDLength, szIDD, 256);
01393                                 break;
01394                         }
01395                 }
01396 
01397                 if(pEventItem->ucDataLayout & 0x02)
01398                 {
01399                         switch (m_pAxxessReader->m_ucDateFormat)
01400                         {
01401                         case FEDM_MYAXXESS_DATE_FORMAT_ISO8601:
01402                                 sprintf(szTimestamp,
01403                                                 "20%02d-%02d-%02d;%02d:%02d",   
01404                                                 pEventItem->ucYear, 
01405                                                 pEventItem->ucMonth, 
01406                                                 pEventItem->ucDay, 
01407                                                 pEventItem->ucHour, 
01408                                                 pEventItem->ucMinute);
01409                                 break;
01410 
01411                         case FEDM_MYAXXESS_DATE_FORMAT_GER:
01412                                 sprintf(szTimestamp,
01413                                                 "%02d.%02d.20%02d;%02d:%02d",   
01414                                                 pEventItem->ucDay, 
01415                                                 pEventItem->ucMonth, 
01416                                                 pEventItem->ucYear,
01417                                                 pEventItem->ucHour, 
01418                                                 pEventItem->ucMinute);
01419                                 break;
01420 
01421                         case FEDM_MYAXXESS_DATE_FORMAT_US:
01422                                 sprintf(szTimestamp, 
01423                                                 "%02d/%02d/20%02d;%02d:%02d",   
01424                                                 pEventItem->ucMonth,
01425                                                 pEventItem->ucDay, 
01426                                                 pEventItem->ucYear,
01427                                                 pEventItem->ucHour, 
01428                                                 pEventItem->ucMinute);
01429                                 break;
01430 
01431                         default:
01432                                 m_pAxxessReader->SetLastError(FEDM_ERROR_PARAMETER);
01433                                 return m_pAxxessReader->GetLastError();
01434                         }
01435                 }
01436 
01437                 if(pEventItem->ucDataLayout & 0x04)
01438                 {
01439                         sprintf(szStatus,
01440                                         "%d;%i",        
01441                                         pEventItem->ucAction,
01442                                         pEventItem->uiError);
01443                 }
01444 
01445                 if(pEventItem->ucDataLayout & 0x08)
01446                 {
01447                         sprintf(szInput,
01448                                         "%d",
01449                                         pEventItem->ucInput);
01450                 }
01451 
01452                 if(pEventItem->ucDataLayout & 0x10)
01453                 {
01454                         sprintf(szAnt,
01455                                         "%d",
01456                                         pEventItem->ucAnt);
01457                 }
01458 
01459                 sprintf(buf,
01460                                 "%i;%d;%s;%s;%s;%s;%s;%s\n",    
01461                                 ++uiNumber,
01462                                 pEventItem->ucEventID,
01463                                 szIDD,
01464                                 szTimestamp,
01465                                 szInput,
01466                                 szAnt,
01467                                 szStatus,
01468                                 pEventItem->sSourceIP.c_str());
01469 
01470 
01471                 fwrite(buf, sizeof(char), strlen(buf), hCvsFile);
01472 
01473                 // item must be deleted, because item is no longer controlled by the queue
01474                 m_pAxxessReader->m_EventTable.pop();
01475 
01476         } // while(! m_pAxxessReader->m_EventTable.empty())
01477 
01478         m_pAxxessReader->SetLastError(FEDM_OK);
01479         return m_pAxxessReader->GetLastError();
01480 }


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