FEDM_XmlReaderCfgProfileModul.cpp
Go to the documentation of this file.
00001 /*-------------------------------------------------------
00002 |                                                       |
00003 |              FEDM_XmlReaderCfgProfileModul.cpp        |
00004 |                                                       |
00005 ---------------------------------------------------------
00006 
00007 Copyright  2007-2009    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                   :       13.08.2007
00018 Version                 :       03.00.05 / 24.02.2009 / M. Hultsch
00019 
00020 Operation Systems       :       independent
00021 
00022 Function                        :       main class for XML document handler
00023                                                 
00024 Note                            :       this XML document handler is designed only for use
00025                                                 inside the class library FEDM !!
00026 
00027 
00028 Trademarks:
00029 -----------
00030 OBID®, OBID i-scan® and OBID myAXXESS® are registered Trademarks of FEIG ELECTRONIC GmbH
00031 Other Trademarks: see FEDM.h
00032 */
00033 
00034 
00035 #ifdef _FEDM_XML_SUPPORT
00036 
00037 
00038 #include "FEDM_XmlReaderCfgProfileModul.h"
00039 #include "FEDM_DataBase.h"
00040 #include "FEDM_Xml.h"
00041 #include <time.h>
00042 
00043 #if _MSC_VER >= 1400
00044         #pragma warning(disable : 4996)
00045 #endif
00046 
00047 #ifdef _FEDM_LINUX
00048         #include <string.h>
00049 #endif
00050 
00051 
00052 //#####################################################################################
00053 // Construction/Destruction
00054 //#####################################################################################
00055 
00056 /***************************************************************************
00057   Begin         :       13.08.2007 / M. Hultsch
00058   Version       :       03.00.00 / 19.09.2007 / M. Hultsch
00059 
00060   Function              :       constructor
00061 
00062   Parameters    :       -
00063 
00064   Return value  :       -
00065 ***************************************************************************/
00066 FEDM_XMLReaderCfgProfileModul::FEDM_XMLReaderCfgProfileModul()
00067 {
00068         m_wsDocType                     = L"";
00069         m_wsDocVer                      = L"";
00070         m_wsComment                     = L"";
00071         m_wsFedmVer                     = L"";
00072         m_wsDate                        = L"";
00073         m_wsTime                        = L"";
00074 
00075         m_ReaderRequirement.Init();
00076 }
00077 
00078 /***************************************************************************
00079   Begin         :       13.08.2007 / M. Hultsch
00080   Version       :       03.00.00 / 13.08.2007 / M. Hultsch
00081 
00082   Function              :       destructor
00083 
00084   Parameters    :       -
00085 
00086   Return value  :       -
00087 ***************************************************************************/
00088 FEDM_XMLReaderCfgProfileModul::~FEDM_XMLReaderCfgProfileModul()
00089 {
00090 }
00091 
00092 
00093 //#####################################################################################
00094 // serialization functions
00095 //#####################################################################################
00096 
00097 /***************************************************************************
00098   Begin         :       13.08.2007 / M. Hultsch
00099   Version       :       03.00.05 / 24.02.2009 / M. Hultsch
00100 
00101   Function              :       read xml document and save content in reader class
00102 
00103   Parameters    :       FEDM_DataBase* pReader
00104                                         char* sFileName -       file name
00105 
00106   Return value  :       FEDM_OK or error code (<0)
00107 ***************************************************************************/
00108 int FEDM_XMLReaderCfgProfileModul::SerializeIn(FEDM_DataBase* pReader, char* sFileName)
00109 {
00110         FEDM_CHK5(pReader);
00111         FEDM_CHK5(sFileName);
00112 
00113         char    cValue[64];
00114         int iTmp[3];
00115         unsigned int i = 0;
00116         unsigned int uiTmp;
00117         int             iBack = 0;
00118         FEDM_XML_TREEITEM* root = NULL;
00119         FEDM_XML_TREEITEM* parent = NULL;
00120         FEDM_XML_TREEITEM* child = NULL;
00121 
00122         memset(iTmp, 0, 3);
00123 
00124         
00125         iBack = OpenDoc(sFileName, "r");
00126         if(iBack)
00127                 return iBack;
00128         
00129         // is it a xml document?
00130         if(IsXmlDoc())
00131         {
00132                 CloseDoc();
00133                 return m_iLastError;
00134         }
00135 
00136         // has the xml document an OBID tag?
00137         if(HasOBIDTag())
00138         {
00139                 CloseDoc();
00140                 return m_iLastError;
00141         }
00142         
00143         // read complete xml document into string
00144         if(ReadDoc())
00145         {
00146                 CloseDoc();
00147                 return m_iLastError;
00148         }
00149 
00150         CloseDoc();
00151 
00152 
00153         // root tag
00154         root = FindTag(FEDM_XML_TAG_OBID_UC);
00155         if(root == NULL)
00156                 return m_iLastError;
00157         AddTagItem(NULL, root);
00158 
00159         // header tag
00160         child = FindTag(FEDM_XML_TAG_FILE_HDR_UC);
00161         if(child == NULL)
00162         {
00163                 DeleteXmlTree(); // clean up
00164                 return m_iLastError;
00165         }
00166         AddTagItem(root, child);
00167         parent = child;
00168 
00169         // header tag document type
00170         child = FindTag(FEDM_XML_TAG_DOC_TYPE_UC);
00171         if(child == NULL)
00172         {
00173                 DeleteXmlTree(); // clean up
00174                 return m_iLastError;
00175         }
00176         if(child->sValue != FEDM_XML_STRING_DOC_TYPE_4_UC)
00177         {
00178                 delete child;
00179                 DeleteXmlTree(); // clean up
00180                 FEDM_RETURN(FEDM_XML_ERROR_DOC_FILE_TYPE);
00181         }
00182         m_wsDocType = child->sValue;
00183         AddTagItem(parent, child);
00184 
00185         // header tag document version
00186         child = FindTag(FEDM_XML_TAG_DOC_VERSION_UC);
00187         if(child == NULL)
00188         {
00189                 DeleteXmlTree(); // clean up
00190                 return m_iLastError;
00191         }
00192         if(child->sValue != FEDM_XML_STRING_PROFILE_DOC_VERSION_UC)
00193         {
00194                 delete child;
00195                 DeleteXmlTree(); // clean up
00196                 FEDM_RETURN(FEDM_XML_ERROR_DOC_FILE_VERSION);
00197         }
00198         m_wsDocVer = child->sValue;
00199         AddTagItem(parent, child);
00200 
00201         // header tag comment
00202         child = FindTag(FEDM_XML_TAG_COMMENT_UC);
00203         if(child != NULL)
00204         {
00205                 AddTagItem(parent, child);
00206                 m_wsComment = child->sValue;
00207         }
00208 
00209         // reader tag
00210         child = FindTag(FEDM_XML_TAG_READER_UC);
00211         if(child == NULL)
00212         {
00213                 DeleteXmlTree(); // clean up
00214                 return m_iLastError;
00215         }
00216         AddTagItem(root, child);
00217         parent = child;
00218 
00219         // reader tag reader type
00220         child = FindTag(FEDM_XML_TAG_READER_TYPE_UC);
00221         if(child != NULL)
00222         {
00223                 AddTagItem(parent, child);
00224                 if(child->sValue.length()>0 && child->sValue.length()<FEDM_MAX_NAME_SIZE)
00225                 {
00226                         memset(cValue, 0, FEDM_MAX_NAME_SIZE);
00227                         for(i = 0; i < child->sValue.length(); i++)
00228                                 cValue[i] = (char)(child->sValue.c_str())[i];
00229 
00230                         sscanf(cValue, "%u", &uiTmp);
00231                         if(uiTmp != pReader->GetReaderType())
00232                         {
00233                                 DeleteXmlTree(); // clean up
00234                                 FEDM_RETURN(FEDM_ERROR_WRONG_READER_TYPE);
00235                         }
00236                 }
00237                 else
00238                 {
00239                         DeleteXmlTree(); // clean up
00240                         FEDM_RETURN(FEDM_XML_ERROR_NO_TAG_VALUE);
00241                 }
00242         }
00243 
00244         m_ReaderRequirement.Init();
00245 
00246         // optional reader tag: CFG-Reset
00247         child = FindTag(FEDM_XML_TAG_CFG_RESET_UC);
00248         if(child != NULL)
00249         {
00250                 AddTagItem(parent, child);
00251                 if(child->sValue.length()>0 && child->sValue.length()<2)
00252                 {
00253                         memset(cValue, 0, 2);
00254                         for(i = 0; i < 1; i++)
00255                                 cValue[i] = (char)(child->sValue.c_str())[i];
00256                         sscanf(cValue, "%X", &uiTmp);
00257                         if(uiTmp == 1)
00258                                 m_ReaderRequirement.bCfgReset = true;
00259                 }
00260         }
00261 
00262         // optional reader tag: RFC firmware
00263         child = FindTag(FEDM_XML_TAG_FIRMWARE_VERSION_UC,
00264                                         FEDM_XML_TAG_CONTROLLER_TYPE_UC,
00265                                         L"RFC",
00266                                         false,
00267                                         true);
00268         if(child != NULL)
00269         {
00270                 AddTagItem(parent, child);
00271                 if(child->sValue.length()>0 && child->sValue.length()<FEDM_MAX_NAME_SIZE)
00272                 {
00273                         memset(cValue, 0, FEDM_MAX_NAME_SIZE);
00274                         for(i = 0; i < child->sValue.length(); i++)
00275                                 cValue[i] = (char)(child->sValue.c_str())[i];
00276                         sscanf(cValue, "%d.%d.%d", &iTmp[0], &iTmp[1], &iTmp[2]);
00277                         uiTmp = (iTmp[0]<<16) + (iTmp[1]<<8) + iTmp[2];
00278                         m_ReaderRequirement.mapControllerFW.insert(make_pair(FEDM_CNTRL_TYPE_RFC, uiTmp));
00279                         m_ReaderRequirement.bHasRfcFw = true;
00280                 }
00281         }
00282 
00283         // optional reader tag: ACC firmware
00284         child = FindTag(FEDM_XML_TAG_FIRMWARE_VERSION_UC,
00285                                         FEDM_XML_TAG_CONTROLLER_TYPE_UC,
00286                                         L"ACC",
00287                                         false,
00288                                         true);
00289         if(child != NULL)
00290         {
00291                 AddTagItem(parent, child);
00292                 if(child->sValue.length()>0 && child->sValue.length()<FEDM_MAX_NAME_SIZE)
00293                 {
00294                         memset(cValue, 0, FEDM_MAX_NAME_SIZE);
00295                         for(i = 0; i < child->sValue.length(); i++)
00296                                 cValue[i] = (char)(child->sValue.c_str())[i];
00297                         sscanf(cValue, "%d.%d.%d", &iTmp[0], &iTmp[1], &iTmp[2]);
00298                         uiTmp = (iTmp[0]<<16) + (iTmp[1]<<8) + iTmp[2];
00299                         m_ReaderRequirement.mapControllerFW.insert(make_pair(FEDM_CNTRL_TYPE_ACC, uiTmp));
00300                         m_ReaderRequirement.bHasAccFw = true;
00301                 }
00302         }
00303 
00304         // optional reader tag: cutomer id
00305         child = FindTag(FEDM_XML_TAG_CUSTOMER_ID_UC);
00306         if(child != NULL)
00307         {
00308                 AddTagItem(parent, child);
00309                 if(child->sValue.length()>0 && child->sValue.length()<FEDM_MAX_NAME_SIZE)
00310                 {
00311                         memset(cValue, 0, FEDM_MAX_NAME_SIZE);
00312                         for(i = 0; i < child->sValue.length(); i++)
00313                                 cValue[i] = (char)(child->sValue.c_str())[i];
00314                         sscanf(cValue, "%X", &m_ReaderRequirement.uiCumstomerID);
00315                         m_ReaderRequirement.bHasCustID = true;
00316                 }
00317         }
00318 
00319         // optional reader tag: reader functions
00320         child = FindTag(FEDM_XML_TAG_READER_FUNCTIONS_UC);
00321         if(child != NULL)
00322         {
00323                 AddTagItem(parent, child);
00324                 if(child->sValue.length()>0 && child->sValue.length()<FEDM_MAX_NAME_SIZE)
00325                 {
00326                         memset(cValue, 0, FEDM_MAX_NAME_SIZE);
00327                         for(i = 0; i < child->sValue.length(); i++)
00328                                 cValue[i] = (char)(child->sValue.c_str())[i];
00329                         sscanf(cValue, "%X", &m_ReaderRequirement.uiReaderFunction);
00330                         m_ReaderRequirement.bHasRdrFunc = true;
00331                 }
00332         }
00333 
00334         // optional reader tag: transponder driver
00335         child = FindTag(FEDM_XML_TAG_TRANSPONDER_DRIVER_UC);
00336         if(child != NULL)
00337         {
00338                 AddTagItem(parent, child);
00339                 if(child->sValue.length()>0 && child->sValue.length()<FEDM_MAX_NAME_SIZE)
00340                 {
00341                         memset(cValue, 0, FEDM_MAX_NAME_SIZE);
00342                         for(i = 0; i < child->sValue.length(); i++)
00343                                 cValue[i] = (char)(child->sValue.c_str())[i];
00344                         sscanf(cValue, "%X", &m_ReaderRequirement.uiTransponderDriver);
00345                         m_ReaderRequirement.bHasTrpDrv = true;
00346                 }
00347         }
00348 
00349         // optional reader tag: frequency
00350         child = FindTag(FEDM_XML_TAG_FREQUENCY_UC);
00351         if(child != NULL)
00352         {
00353                 AddTagItem(parent, child);
00354                 if(child->sValue.length()>0 && child->sValue.length()<FEDM_MAX_NAME_SIZE)
00355                 {
00356                         memset(cValue, 0, FEDM_MAX_NAME_SIZE);
00357                         for(i = 0; i < child->sValue.length(); i++)
00358                                 cValue[i] = (char)(child->sValue.c_str())[i];
00359                         sscanf(cValue, "%d", &m_ReaderRequirement.uiFrequency);
00360                         m_ReaderRequirement.bHasFrequency = true;
00361                 }
00362         }
00363 
00364 
00365         // ... transfer content of tag items to byte arrays
00366         iBack = pReader->SerializeProfileIn(this, root);
00367         if(iBack)
00368         {
00369                 DeleteXmlTree(); // clean up
00370                 return iBack;
00371         }
00372 
00373         // clean up
00374         DeleteXmlTree();
00375 
00376         FEDM_RETURN(FEDM_OK);
00377 }
00378 
00379 
00380 /***************************************************************************
00381   Begin         :       13.08.2007 / M. Hultsch
00382   Version       :       03.00.05 / 22.02.2009 / M. Hultsch
00383 
00384   Function              :       write content of reader class into xml document
00385 
00386   Parameters    :       FEDM_DataBase* pReader
00387                                         char* sFileName -       file name
00388 
00389   Return value  :       FEDM_OK or error code (<0)
00390 ***************************************************************************/
00391 int FEDM_XMLReaderCfgProfileModul::SerializeOut(FEDM_DataBase* pReader, char* sFileName)
00392 {
00393         FEDM_CHK5(pReader);
00394         FEDM_CHK5(sFileName);
00395 
00396         int             iBack = 0;
00397 //      char    cValue[32];
00398         wchar_t wcTmp[128];
00399 #if !defined(_FEDM_SUPPORT_UCLINUX) && !defined(_WIN32_WCE)
00400         time_t  ltime;
00401         struct  tm *tmtime;
00402 #endif
00403         FEDM_XML_TREEITEM* root = NULL;
00404         FEDM_XML_TREEITEM* parent = NULL;
00405         FEDM_XML_TREEITEM* child = NULL;
00406         map<unsigned int, unsigned int>::iterator itor;
00407 
00408 
00409         // root tag
00410         root = BuildTag(FEDM_XML_TAG_OBID_UC);
00411         if(root == NULL)
00412         {
00413                 return m_iLastError;
00414         }
00415         AddTagItem(NULL, root);
00416 
00417         // header tag
00418         child = BuildTag(FEDM_XML_TAG_FILE_HDR_UC);
00419         if(child == NULL)
00420         {
00421                 DeleteXmlTree(); // clean up
00422                 return m_iLastError;
00423         }
00424         AddTagItem(root, child);
00425         parent = child;
00426 
00427         // header tag document type
00428         child = BuildTag(FEDM_XML_TAG_DOC_TYPE_UC, false);
00429         if(child == NULL)
00430         {
00431                 DeleteXmlTree(); // clean up
00432                 return m_iLastError;
00433         }
00434         AddTagValue(child, FEDM_XML_STRING_DOC_TYPE_4_UC);
00435         AddTagItem(parent, child);
00436 
00437         // header tag document version
00438         child = BuildTag(FEDM_XML_TAG_DOC_VERSION_UC, false);
00439         if(child == NULL)
00440         {
00441                 DeleteXmlTree(); // clean up
00442                 return m_iLastError;
00443         }
00444         AddTagValue(child, FEDM_XML_STRING_PROFILE_DOC_VERSION_UC);
00445         AddTagItem(parent, child);
00446 
00447         // header tag fedm library version number
00448         child = BuildTag(FEDM_XML_TAG_FEDM_VERSION_UC, false);
00449         if(child == NULL)
00450         {
00451                 DeleteXmlTree(); // clean up
00452                 return m_iLastError;
00453         }
00454         AddTagValue(child, FEDM_VERSION_UC);
00455         AddTagItem(parent, child);
00456 
00457         // header tag date
00458 #if !defined(_FEDM_SUPPORT_UCLINUX) && !defined(_WIN32_WCE)
00459         child = BuildTag(FEDM_XML_TAG_DATE_UC, false);
00460         if(child == NULL)
00461         {
00462                 DeleteXmlTree(); // clean up
00463                 return m_iLastError;
00464         }
00465         time(&ltime);
00466         tmtime = localtime(&ltime);
00467         wcsftime(wcTmp, 128, L"%x", tmtime);
00468         AddTagValue(child, wcTmp);
00469         AddTagItem(parent, child);
00470 #endif
00471 
00472         // header tag time
00473 #if !defined(_FEDM_SUPPORT_UCLINUX) && !defined(_WIN32_WCE)
00474         child = BuildTag(FEDM_XML_TAG_TIME_UC, false);
00475         if(child == NULL)
00476         {
00477                 DeleteXmlTree(); // clean up
00478                 return m_iLastError;
00479         }
00480         wcsftime(wcTmp, 128, L"%X", tmtime);
00481         AddTagValue(child, wcTmp);
00482         AddTagItem(parent, child);
00483 #endif
00484 
00485         // header tag comment
00486         if(m_wsComment.size() > 0)
00487         {
00488                 child = BuildTag(FEDM_XML_TAG_COMMENT_UC, false);
00489                 if(child == NULL)
00490                 {
00491                         DeleteXmlTree(); // clean up
00492                         return m_iLastError;
00493                 }
00494                 AddTagValue(child, m_wsComment);
00495                 AddTagItem(parent, child);
00496         }
00497 
00498 
00499         // reader tag
00500         child = BuildTag(FEDM_XML_TAG_READER_UC);
00501         if(child == NULL)
00502         {
00503                 DeleteXmlTree(); // clean up
00504                 return m_iLastError;
00505         }
00506         AddTagItem(root, child);
00507         parent = child;
00508 
00509         // tag reader name
00510         child = BuildTag(FEDM_XML_TAG_READER_NAME_UC, false);
00511         if(child == NULL)
00512         {
00513                 DeleteXmlTree(); // clean up
00514                 return m_iLastError;
00515         }
00516 #if defined(__BORLANDC__) || defined(_MSC_VER)
00517         swprintf(wcTmp, L"%S", pReader->GetReaderName());
00518 #else
00519         swprintf(wcTmp, 128, L"%s", pReader->GetReaderName());
00520 #endif
00521         AddTagValue(child, wcTmp);
00522         AddTagItem(parent, child);
00523 
00524         // tag reader type
00525         child = BuildTag(FEDM_XML_TAG_READER_TYPE_UC, false);
00526         if(child == NULL)
00527         {
00528                 DeleteXmlTree(); // clean up
00529                 return m_iLastError;
00530         }
00531 #if defined(__BORLANDC__) || defined(_MSC_VER)
00532         swprintf(wcTmp, L"%u", pReader->GetReaderType());
00533 #else
00534         swprintf(wcTmp, 128, L"%u", pReader->GetReaderType());
00535 #endif
00536         AddTagValue(child, wcTmp);
00537         AddTagItem(parent, child);
00538 
00539         // optional tags from m_ReaderRequirement: CFG-Reset
00540         if(m_ReaderRequirement.bCfgReset)
00541         {
00542                 child = BuildTag(FEDM_XML_TAG_CFG_RESET_UC, false);
00543                 if(child == NULL)
00544                 {
00545                         DeleteXmlTree(); // clean up
00546                         return m_iLastError;
00547                 }
00548 #if defined(__BORLANDC__) || defined(_MSC_VER)
00549                 swprintf(wcTmp, L"%d", (int)1);
00550 #else
00551                 swprintf(wcTmp, 128, L"%d", (int)1);
00552 #endif
00553                 AddTagValue(child, wcTmp);
00554                 AddTagItem(parent, child);
00555         }
00556 
00557         // optional tags from m_ReaderRequirement: RFC firmware
00558         if(m_ReaderRequirement.bHasRfcFw)
00559         {
00560                 itor = m_ReaderRequirement.mapControllerFW.find(FEDM_CNTRL_TYPE_RFC);
00561                 if(itor != m_ReaderRequirement.mapControllerFW.end())
00562                 {
00563                         child = BuildTag(FEDM_XML_TAG_FIRMWARE_VERSION_UC, false);
00564                         if(child == NULL)
00565                         {
00566                                 DeleteXmlTree(); // clean up
00567                                 return m_iLastError;
00568                         }
00569                         AddTagAttrib(child, FEDM_XML_TAG_CONTROLLER_TYPE_UC, L"RFC");
00570 #if defined(__BORLANDC__) || defined(_MSC_VER)
00571                         swprintf(wcTmp, L"%d.%d.%d", ((itor->second&0x00FF0000)>>16), ((itor->second&0x0000FF00)>>8), (itor->second&0x000000FF));
00572 #else
00573                         swprintf(wcTmp, 128, L"%d.%d.%d", ((itor->second&0x00FF0000)>>16), ((itor->second&0x0000FF00)>>8), (itor->second&0x000000FF));
00574 #endif
00575                         AddTagValue(child, wcTmp);
00576                         AddTagItem(parent, child);
00577                 }
00578         }
00579 
00580         // optional tags from m_ReaderRequirement: ACC firmware
00581         if(m_ReaderRequirement.bHasAccFw)
00582         {
00583                 itor = m_ReaderRequirement.mapControllerFW.find(FEDM_CNTRL_TYPE_ACC);
00584                 if(itor != m_ReaderRequirement.mapControllerFW.end())
00585                 {
00586                         child = BuildTag(FEDM_XML_TAG_FIRMWARE_VERSION_UC, false);
00587                         if(child == NULL)
00588                         {
00589                                 DeleteXmlTree(); // clean up
00590                                 return m_iLastError;
00591                         }
00592                         AddTagAttrib(child, FEDM_XML_TAG_CONTROLLER_TYPE_UC, L"ACC");
00593 #if defined(__BORLANDC__) || defined(_MSC_VER)
00594                         swprintf(wcTmp, L"%d.%d.%d", ((itor->second&0x00FF0000)>>16), ((itor->second&0x0000FF00)>>8), (itor->second&0x000000FF));
00595 #else
00596                         swprintf(wcTmp, 128, L"%d.%d.%d", ((itor->second&0x00FF0000)>>16), ((itor->second&0x0000FF00)>>8), (itor->second&0x000000FF));
00597 #endif
00598                         AddTagValue(child, wcTmp);
00599                         AddTagItem(parent, child);
00600                 }
00601         }
00602 
00603         // optional tags from m_ReaderRequirement: customer id
00604         if(m_ReaderRequirement.bHasCustID)
00605         {
00606                 child = BuildTag(FEDM_XML_TAG_CUSTOMER_ID_UC, false);
00607                 if(child == NULL)
00608                 {
00609                         DeleteXmlTree(); // clean up
00610                         return m_iLastError;
00611                 }
00612 #if defined(__BORLANDC__) || defined(_MSC_VER)
00613                 swprintf(wcTmp, L"0x%08X", m_ReaderRequirement.uiCumstomerID);
00614 #else
00615                 swprintf(wcTmp, 128, L"0x%08X", m_ReaderRequirement.uiCumstomerID);
00616 #endif
00617                 AddTagValue(child, wcTmp);
00618                 AddTagItem(parent, child);
00619         }
00620 
00621         // optional tags from m_ReaderRequirement: reader function
00622         if(m_ReaderRequirement.bHasRdrFunc)
00623         {
00624                 child = BuildTag(FEDM_XML_TAG_READER_FUNCTIONS_UC, false);
00625                 if(child == NULL)
00626                 {
00627                         DeleteXmlTree(); // clean up
00628                         return m_iLastError;
00629                 }
00630 #if defined(__BORLANDC__) || defined(_MSC_VER)
00631                 swprintf(wcTmp, L"0x%08X", m_ReaderRequirement.uiReaderFunction);
00632 #else
00633                 swprintf(wcTmp, 128, L"0x%08X", m_ReaderRequirement.uiReaderFunction);
00634 #endif
00635                 AddTagValue(child, wcTmp);
00636                 AddTagItem(parent, child);
00637         }
00638 
00639         // optional tags from m_ReaderRequirement: transponder driver
00640         if(m_ReaderRequirement.bHasTrpDrv)
00641         {
00642                 child = BuildTag(FEDM_XML_TAG_TRANSPONDER_DRIVER_UC, false);
00643                 if(child == NULL)
00644                 {
00645                         DeleteXmlTree(); // clean up
00646                         return m_iLastError;
00647                 }
00648 #if defined(__BORLANDC__) || defined(_MSC_VER)
00649                 swprintf(wcTmp, L"0x%08X", m_ReaderRequirement.uiTransponderDriver);
00650 #else
00651                 swprintf(wcTmp, 128, L"0x%08X", m_ReaderRequirement.uiTransponderDriver);
00652 #endif
00653                 AddTagValue(child, wcTmp);
00654                 AddTagItem(parent, child);
00655         }
00656 
00657         // optional tags from m_ReaderRequirement: region
00658         if(m_ReaderRequirement.bHasFrequency)
00659         {
00660                 child = BuildTag(FEDM_XML_TAG_FREQUENCY_UC, false);
00661                 if(child == NULL)
00662                 {
00663                         DeleteXmlTree(); // clean up
00664                         return m_iLastError;
00665                 }
00666 #if defined(__BORLANDC__) || defined(_MSC_VER)
00667                 swprintf(wcTmp, L"%d", m_ReaderRequirement.uiFrequency);
00668 #else
00669                 swprintf(wcTmp, 128, L"%d", m_ReaderRequirement.uiFrequency);
00670 #endif
00671                 AddTagValue(child, wcTmp);
00672                 AddTagItem(parent, child);
00673         }
00674         
00675 
00676         // add data array tags
00677         iBack = pReader->SerializeProfileOut(this, root);
00678         if(iBack)
00679         {
00680                 DeleteXmlTree(); // clean up
00681                 return iBack;
00682         }
00683 
00684         iBack = OpenDoc(sFileName, "w");
00685         if(iBack)
00686         {
00687                 DeleteXmlTree(); // clean up
00688                 return iBack;
00689         }
00690         else
00691         {
00692                 WriteDoc();
00693         }
00694 
00695 
00696         CloseDoc();
00697 
00698         FEDM_RETURN(FEDM_OK);
00699 }
00700 
00701 
00702 
00703 
00704 //#####################################################################################
00705 // query functions
00706 //#####################################################################################
00707 
00708 /***************************************************************************
00709   Begin         :       13.08.2007 / M. Hultsch
00710   Version       :       03.00.00 / 13.08.2007 / M. Hultsch
00711 
00712   Function              :       open a xml document and get the document type
00713 
00714   Parameters    :       char* sFileName - pointer to string with file name
00715                                         char* sDocType  - pointer to string for document type
00716 
00717   Return value  :       FEDM_OK or error code (<0)
00718 ***************************************************************************/
00719 int FEDM_XMLReaderCfgProfileModul::QueryDocType(char* sFileName, char* sDocType)
00720 {
00721         int iBack = 0;
00722         FEDM_XML_TREEITEM* root = NULL;
00723         FEDM_XML_TREEITEM* parent = NULL;
00724         FEDM_XML_TREEITEM* child = NULL;
00725 
00726         
00727         iBack = OpenDoc(sFileName, "r");
00728         if(iBack)
00729                 return iBack;
00730         
00731         // is it a xml document?
00732         if(IsXmlDoc())
00733         {
00734                 CloseDoc();
00735                 return m_iLastError;
00736         }
00737 
00738         // has the xml document an OBID tag?
00739         if(HasOBIDTag())
00740         {
00741                 CloseDoc();
00742                 return m_iLastError;
00743         }
00744         
00745         // read complete xml document into string
00746         if(ReadDoc())
00747         {
00748                 CloseDoc();
00749                 return m_iLastError;
00750         }
00751 
00752         CloseDoc();
00753 
00754         // root tag
00755         root = FindTag(FEDM_XML_TAG_OBID_UC);
00756         if(root == NULL)
00757                 return m_iLastError;
00758         AddTagItem(NULL, root);
00759 
00760         // header tag
00761         child = FindTag(FEDM_XML_TAG_FILE_HDR_UC);
00762         if(child == NULL)
00763         {
00764                 DeleteXmlTree(); // clean up
00765                 return m_iLastError;
00766         }
00767         AddTagItem(root, child);
00768         parent = child;
00769 
00770         // header tag document type
00771         child = FindTag(FEDM_XML_TAG_DOC_TYPE_UC);
00772         if(child == NULL)
00773         {
00774                 DeleteXmlTree(); // clean up
00775                 return m_iLastError;
00776         }
00777 
00778 #if defined(__BORLANDC__) || defined(_MSC_VER)
00779         swscanf(child->sValue.c_str(), L"%S", sDocType);
00780 #elif defined(_FEDM_SUPPORT_UCLINUX)
00781         FEDM_SWSCANF(child->sValue.c_str(), sDocType);
00782 #else
00783         swscanf(child->sValue.c_str(), L"%s", sDocType);
00784 #endif
00785         
00786         delete child;
00787         DeleteXmlTree(); // clean up
00788 
00789         FEDM_RETURN(FEDM_OK);
00790 }
00791 
00792 /***************************************************************************
00793   Begin         :       13.08.2007 / M. Hultsch
00794   Version       :       03.00.00 / 13.08.2007 / M. Hultsch
00795 
00796   Function              :       open a xml document and get the doc version
00797 
00798   Parameters    :       char* sFileName         - pointer to string with file name
00799                                         char* sDocVersion       - pointer to string for document version
00800 
00801   Return value  :       FEDM_OK or error code (<0)
00802 ***************************************************************************/
00803 int FEDM_XMLReaderCfgProfileModul::QueryDocVersion(char* sFileName, char* sDocVersion)
00804 {
00805         int iBack = 0;
00806         FEDM_XML_TREEITEM* root = NULL;
00807         FEDM_XML_TREEITEM* parent = NULL;
00808         FEDM_XML_TREEITEM* child = NULL;
00809 
00810         
00811         iBack = OpenDoc(sFileName, "r");
00812         if(iBack)
00813                 return iBack;
00814         
00815         // is it a xml document?
00816         if(IsXmlDoc())
00817         {
00818                 CloseDoc();
00819                 return m_iLastError;
00820         }
00821 
00822         // has the xml document an OBID tag?
00823         if(HasOBIDTag())
00824         {
00825                 CloseDoc();
00826                 return m_iLastError;
00827         }
00828         
00829         // read complete xml document into string
00830         if(ReadDoc())
00831         {
00832                 CloseDoc();
00833                 return m_iLastError;
00834         }
00835 
00836         CloseDoc();
00837 
00838         // root tag
00839         root = FindTag(FEDM_XML_TAG_OBID_UC);
00840         if(root == NULL)
00841                 return m_iLastError;
00842         AddTagItem(NULL, root);
00843 
00844         // header tag
00845         child = FindTag(FEDM_XML_TAG_FILE_HDR_UC);
00846         if(child == NULL)
00847         {
00848                 DeleteXmlTree(); // clean up
00849                 return m_iLastError;
00850         }
00851         AddTagItem(root, child);
00852         parent = child;
00853 
00854         // header tag document type
00855         child = FindTag(FEDM_XML_TAG_DOC_TYPE_UC);
00856         if(child == NULL)
00857         {
00858                 DeleteXmlTree(); // clean up
00859                 return m_iLastError;
00860         }
00861         m_wsDocType = child->sValue;
00862         AddTagItem(parent, child);
00863 
00864         // header tag document version
00865         child = FindTag(FEDM_XML_TAG_DOC_VERSION_UC);
00866         if(child == NULL)
00867         {
00868                 DeleteXmlTree(); // clean up
00869                 return m_iLastError;
00870         }
00871 
00872 #if defined(__BORLANDC__) || defined(_MSC_VER)
00873         swscanf(child->sValue.c_str(), L"%S", sDocVersion);
00874 #elif defined(_FEDM_SUPPORT_UCLINUX)
00875         FEDM_SWSCANF(child->sValue.c_str(), sDocVersion);
00876 #else
00877         swscanf(child->sValue.c_str(), L"%s", sDocVersion);
00878 #endif
00879 
00880         delete child;
00881         DeleteXmlTree(); // clean up
00882 
00883         FEDM_RETURN(FEDM_OK);
00884 }
00885 
00886 /***************************************************************************
00887   Begin         :       13.08.2007 / M. Hultsch
00888   Version       :       03.00.02 / 14.01.2009 / M. Hultsch
00889 
00890   Function              :       open a xml document and get the reader type
00891 
00892   Parameters    :       -
00893 
00894   Return value  :       reader type (>0) or error code (<0)
00895 ***************************************************************************/
00896 int FEDM_XMLReaderCfgProfileModul::QueryReaderType(char* sFileName)
00897 {
00898         char cValue[5];
00899         int iType = 0;
00900         int iBack = 0;
00901         FEDM_XML_TREEITEM* root = NULL;
00902         FEDM_XML_TREEITEM* parent = NULL;
00903         FEDM_XML_TREEITEM* child = NULL;
00904 
00905         
00906         iBack = OpenDoc(sFileName, "r");
00907         if(iBack)
00908                 return iBack;
00909         
00910         // is it a xml document?
00911         if(IsXmlDoc())
00912         {
00913                 CloseDoc();
00914                 return m_iLastError;
00915         }
00916 
00917         // has the xml document an OBID tag?
00918         if(HasOBIDTag())
00919         {
00920                 CloseDoc();
00921                 return m_iLastError;
00922         }
00923         
00924         // read complete xml document into string
00925         if(ReadDoc())
00926         {
00927                 CloseDoc();
00928                 return m_iLastError;
00929         }
00930 
00931         CloseDoc();
00932 
00933         // root tag
00934         root = FindTag(FEDM_XML_TAG_OBID_UC);
00935         if(root == NULL)
00936                 return m_iLastError;
00937         AddTagItem(NULL, root);
00938 
00939         // header tag
00940         child = FindTag(FEDM_XML_TAG_FILE_HDR_UC);
00941         if(child == NULL)
00942         {
00943                 DeleteXmlTree(); // clean up
00944                 return m_iLastError;
00945         }
00946         AddTagItem(root, child);
00947         parent = child;
00948 
00949         // header tag document type
00950         child = FindTag(FEDM_XML_TAG_DOC_TYPE_UC);
00951         if(child == NULL)
00952         {
00953                 DeleteXmlTree(); // clean up
00954                 return m_iLastError;
00955         }
00956         if(child->sValue != FEDM_XML_STRING_DOC_TYPE_4_UC)
00957         {
00958                 delete child;
00959                 DeleteXmlTree(); // clean up
00960                 FEDM_RETURN(FEDM_XML_ERROR_DOC_FILE_TYPE);
00961         }
00962         m_wsDocType = child->sValue;
00963         AddTagItem(parent, child);
00964 
00965         // header tag document version
00966         child = FindTag(FEDM_XML_TAG_DOC_VERSION_UC);
00967         if(child == NULL)
00968         {
00969                 DeleteXmlTree(); // clean up
00970                 return m_iLastError;
00971         }
00972         if(child->sValue != FEDM_XML_STRING_PROFILE_DOC_VERSION_UC)
00973         {
00974                 delete child;
00975                 DeleteXmlTree(); // clean up
00976                 return FEDM_XML_ERROR_DOC_FILE_VERSION;
00977         }
00978         m_wsDocVer = child->sValue;
00979         AddTagItem(parent, child);
00980 
00981         // reader tag
00982         child = FindTag(FEDM_XML_TAG_READER_UC);
00983         if(child == NULL)
00984         {
00985                 DeleteXmlTree(); // clean up
00986                 return m_iLastError;
00987         }
00988         AddTagItem(root, child);
00989         parent = child;
00990 
00991         // reader tag reader type
00992         child = FindTag(FEDM_XML_TAG_READER_TYPE_UC);
00993         if(child == NULL)
00994         {
00995                 DeleteXmlTree(); // clean up
00996                 return m_iLastError;
00997         }
00998 
00999 #if defined(__BORLANDC__) || defined(_MSC_VER)
01000         swscanf(child->sValue.c_str(), L"%S", cValue);
01001 #elif defined(_FEDM_SUPPORT_UCLINUX)
01002         FEDM_SWSCANF(child->sValue.c_str(), cValue);
01003 #else
01004         swscanf(child->sValue.c_str(), L"%s", cValue);
01005 #endif
01006         sscanf(cValue, "%d", &iType);
01007 
01008         delete child;
01009         DeleteXmlTree(); // clean up
01010 
01011         return iType;
01012 }
01013 
01014 
01015 
01016 //#####################################################################################
01017 // get/set functions
01018 //#####################################################################################
01019 
01020 /***************************************************************************
01021   Begin         :       13.08.2007 / M. Hultsch
01022   Version       :       03.00.00 / 13.08.2007 / M. Hultsch
01023 
01024   Function              :       gets the comment
01025 
01026   Parameters    :       string& sComment        - reference to string with comment
01027 
01028   Return value  :       -
01029 ***************************************************************************/
01030 void FEDM_XMLReaderCfgProfileModul::GetComment(string& sComment)
01031 {
01032         char cTmp[256];
01033 
01034         if(m_wsComment.size() > 256)
01035                 return;
01036 
01037 #if defined(__BORLANDC__) || defined(_MSC_VER)
01038         sprintf(cTmp, "%S", m_wsComment.c_str());
01039 #else
01040         sprintf(cTmp, "%s", (const char*)m_wsComment.c_str());
01041 #endif
01042 
01043         sComment = cTmp;
01044 }
01045 
01046 /***************************************************************************
01047   Begin         :       13.08.2007 / M. Hultsch
01048   Version       :       03.00.00 / 13.08.2007 / M. Hultsch
01049 
01050   Function              :       sets the comment
01051 
01052   Parameters    :       string sComment - string with comment
01053 
01054   Return value  :       -
01055 ***************************************************************************/
01056 void FEDM_XMLReaderCfgProfileModul::SetComment(string sComment)
01057 {
01058         wchar_t wcTmp[256];
01059 
01060         if(sComment.size() > 256)
01061                 return;
01062 
01063 #if defined(__BORLANDC__) || defined(_MSC_VER)
01064         swprintf(wcTmp, L"%S", sComment.c_str());
01065 #else
01066         swprintf(wcTmp, 256, L"%s", sComment.c_str());
01067 #endif
01068 
01069         m_wsComment = wcTmp;
01070 }
01071 
01072 #endif // #ifdef _FEDM_XML_SUPPORT
01073 
01074 
01075 
01076 
01077 


maggie_rfid_drivers
Author(s): Raul Perula-Martinez
autogenerated on Mon Sep 14 2015 03:05:30