FEDM_Functions.cpp
Go to the documentation of this file.
00001 /*-------------------------------------------------------
00002 |                                                       |
00003 |                    FEDM_Functions.cpp                 |
00004 |                                                       |
00005 ---------------------------------------------------------
00006 
00007 Copyright  2000-2013    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                   :       18.05.2000
00018 Version                 :       04.05.00 / 26.04.2013 / M. Hultsch
00019                                                 - new functions: FEDM_ConvBcdCharToHexUChar, FEDM_ConvHexUCharToBcdChar
00020 
00021                                                 03.02.04 / 10.08.2010 / M. Hultsch
00022 
00023 Operation Systems       :       independent
00024 
00025 Function                        :       collects all global functions for FEDM class library
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 #include <math.h>
00036 #include <stdio.h>
00037 #if !defined(_WIN32_WCE)
00038 #include <sys/timeb.h>
00039 #endif
00040 #include <time.h>
00041 #include "FEDM.h"
00042 #include "FEDM_Functions.h"
00043 
00044 #if defined(_FEDM_LINUX)
00045         #include <sys/time.h>
00046         #include <string.h>
00047 #endif
00048 
00049 #if _MSC_VER >= 1400
00050         #pragma warning(disable : 4996)
00051 #endif
00052 
00053 
00054 
00055 //#####################################################################################
00056 // calculation functions
00057 //#####################################################################################
00058 
00059 
00060 /***************************************************************************
00061   Begin         :       18.05.2000 / M. Hultsch
00062   Version       :       03.00.00 / 27.11.2007 / M. Hultsch
00063 
00064   Function              :       extractes the memory-ID from ID
00065 
00066   Parameters    :       const char* ID          -       data identifier
00067 
00068   Return Value  :       int                                     -       memory-ID
00069 
00070 ***************************************************************************/
00071 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_GetMemIDOfID(const char* ID)
00072 {
00073         FEDM_CHK3(ID);
00074 
00075         int FamID=0, MemID=0, Block=0, BytePos=0, ByteCnt=0, BitPos=0, BitCnt=0;
00076         
00077         // extract access parameters
00078         sscanf( ID, "%d %d %d %d %d %d %d",
00079                         &FamID, &MemID, &Block, &BytePos, &ByteCnt, &BitPos, &BitCnt );
00080         
00081         return MemID;
00082 }
00083 
00084 
00085 /***************************************************************************
00086   Begin         :       10.08.2010 / M. Hultsch
00087   Version       :       03.02.04 / 10.08.2010 / M. Hultsch
00088 
00089   Function              :       extractes the start block number from ID
00090 
00091   Parameters    :       const char* ID          -       data identifier
00092 
00093   Return Value  :       int                                     -       block number
00094 
00095 ***************************************************************************/
00096 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_GetBlockNoOfID(const char* ID)
00097 {
00098         FEDM_CHK3(ID);
00099 
00100         int FamID=0, MemID=0, Block=0, BytePos=0, ByteCnt=0, BitPos=0, BitCnt=0;
00101         
00102         // extract access parameters
00103         sscanf( ID, "%d %d %d %d %d %d %d",
00104                         &FamID, &MemID, &Block, &BytePos, &ByteCnt, &BitPos, &BitCnt );
00105         
00106         return Block;
00107 }
00108 
00109 /***************************************************************************
00110   Begin         :       18.05.2000 / M. Hultsch
00111   Version       :       03.00.00 / 27.11.2007 / M. Hultsch
00112 
00113   Function              :       calculates the start address from ID
00114 
00115   Parameters    :       const char* ID          -       data identifier
00116 
00117   Return Value  :       int                                     -       address or error code
00118 
00119 ***************************************************************************/
00120 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_GetAdrOfID(const char* ID, int BlockSize)
00121 {
00122         FEDM_CHK3(ID);
00123 
00124         int FamID=0, MemID=0, Block=0, BytePos=0, ByteCnt=0, BitPos=0, BitCnt=0;
00125         
00126         // security check
00127         if( (BlockSize!=4) && (BlockSize!=16) && (BlockSize!=32) )
00128                 return FEDM_ERROR_BLOCK_SIZE;
00129 
00130         // extract access parameters
00131         sscanf( ID, "%d %d %d %d %d %d %d",
00132                         &FamID, &MemID, &Block, &BytePos, &ByteCnt, &BitPos, &BitCnt );
00133         
00134         return Block * BlockSize + BytePos;
00135 }
00136 
00137 /***************************************************************************
00138   Begin         :       18.05.2000 / M. Hultsch
00139   Version       :       03.00.00 / 27.11.2007 / M. Hultsch
00140 
00141   Function              :       extracts the count of bytes from ID
00142 
00143   Parameters    :       const char* ID          -       data identifier
00144 
00145   Return Value  :       int                                     -       count of bytes or error code
00146 
00147 ***************************************************************************/
00148 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_GetByteCntOfID(const char* ID)
00149 {
00150         FEDM_CHK3(ID);
00151 
00152         int FamID=0, MemID=0, Block=0, BytePos=0, ByteCnt=0, BitPos=0, BitCnt=0;
00153 
00154         // extract access parameters
00155         sscanf( ID, "%d %d %d %d %d %d %d",
00156                         &FamID, &MemID, &Block, &BytePos, &ByteCnt, &BitPos, &BitCnt );
00157 
00158         return ByteCnt;
00159 }
00160 
00161 
00162 
00163 //#####################################################################################
00164 // MemID modification functions
00165 //#####################################################################################
00166 
00167 
00168 /***************************************************************************
00169   Begin         :       30.03.2001 / M. Hultsch
00170   Version       :       03.00.00 / 20.08.2008 / M. Hultsch
00171 
00172   Function              :       changes MemID in ID from FEDM_xxx_EEDATA_MEM to FEDM_xxx_RAMDATA_MEM
00173 
00174   Parameters    :       const char* ID          -       data identifier
00175 
00176   Return Value  :       char* ID                        -       Pointer to new ID or "00 00 00 00 00 00 00"
00177 
00178 ***************************************************************************/
00179 _FEDM_ISC_CORE_EXT_FUNCT char* FEDM_ToRAM(const char* ID)
00180 {
00181         static char cID[32];
00182 
00183         if(ID==NULL)
00184         {
00185                 strcpy(cID, "00 00 00 00 00 00 00");
00186                 return cID;
00187         }
00188 
00189         int FamID=0, MemID=0, Block=0, BytePos=0, ByteCnt=0, BitPos=0, BitCnt=0;
00190 
00191         // extract access parameters
00192         sscanf( ID, "%d %d %d %d %d %d %d",
00193                         &FamID, &MemID, &Block, &BytePos, &ByteCnt, &BitPos, &BitCnt );
00194 
00195         switch(MemID)
00196         {
00197         case FEDM_RFC_EEDATA_MEM:
00198                 sprintf(cID,
00199                                 "%02d %02d %02d %02d %02d %02d %02d",
00200                                 FamID, FEDM_RFC_RAMDATA_MEM, Block, BytePos, ByteCnt, BitPos, BitCnt);
00201                 break;
00202 
00203         case FEDM_ACC_EEDATA_MEM:
00204                 sprintf(cID,
00205                                 "%02d %02d %02d %02d %02d %02d %02d",
00206                                 FamID, FEDM_ACC_RAMDATA_MEM, Block, BytePos, ByteCnt, BitPos, BitCnt);
00207                 break;
00208         }
00209 
00210         return cID;
00211 }
00212 
00213 
00214 /***************************************************************************
00215   Begin         :       16.08.2007 / M. Hultsch
00216   Version       :       03.00.00 / 20.08.2008 / M. Hultsch
00217 
00218   Function              :       changes MemID in ID from FEDM_xxx_EEDATA_MEM to FEDM_xxx_DATA_MASK_MEM
00219 
00220   Parameters    :       const char* ID          -       data identifier
00221 
00222   Return Value  :       char* ID                        -       Pointer to new ID or "00 00 00 00 00 00 00"
00223 
00224 ***************************************************************************/
00225 _FEDM_ISC_CORE_EXT_FUNCT char* FEDM_ToMask(const char* ID)
00226 {
00227         static char cID[32];
00228 
00229         if(ID==NULL)
00230         {
00231                 strcpy(cID, "00 00 00 00 00 00 00");
00232                 return cID;
00233         }
00234 
00235         int FamID=0, MemID=0, Block=0, BytePos=0, ByteCnt=0, BitPos=0, BitCnt=0;
00236 
00237         // extract access parameters
00238         sscanf( ID, "%d %d %d %d %d %d %d",
00239                         &FamID, &MemID, &Block, &BytePos, &ByteCnt, &BitPos, &BitCnt );
00240 
00241 
00242         switch(MemID)
00243         {
00244         case FEDM_RFC_EEDATA_MEM:
00245                 sprintf(cID,
00246                                 "%02d %02d %02d %02d %02d %02d %02d",
00247                                 FamID, FEDM_RFC_DATA_MASK_MEM, Block, BytePos, ByteCnt, BitPos, BitCnt);
00248                 break;
00249 
00250         case FEDM_ACC_EEDATA_MEM:
00251                 sprintf(cID,
00252                                 "%02d %02d %02d %02d %02d %02d %02d",
00253                                 FamID, FEDM_ACC_DATA_MASK_MEM, Block, BytePos, ByteCnt, BitPos, BitCnt);
00254                 break;
00255         }
00256 
00257         return cID;
00258 }
00259 
00260 
00261 /***************************************************************************
00262   Begin         :       12.07.2001 / M. Hultsch
00263   Version       :       03.00.00 / 27.11.2007 / M. Hultsch
00264 
00265   Function              :       changes MemID in ID
00266 
00267   Parameters    :       const char* ID          -       data identifier
00268                                         int iNewMemID           -       new memory identifier
00269                                         
00270   Return Value  :       char* ID                        -       Pointer to new ID or "00 00 00 00 00 00 00"
00271 
00272 ***************************************************************************/
00273 _FEDM_ISC_CORE_EXT_FUNCT char* FEDM_MdfyMemID(const char* ID, int iNewMemID)
00274 {
00275         static char cID[32];
00276 
00277         if(ID==NULL)
00278         {
00279                 strcpy(cID, "00 00 00 00 00 00 00");
00280                 return cID;
00281         }
00282 
00283         int FamID=0, MemID=0, Block=0, BytePos=0, ByteCnt=0, BitPos=0, BitCnt=0;
00284 
00285         // extract access parameters
00286         sscanf( ID, "%d %d %d %d %d %d %d",
00287                         &FamID, &MemID, &Block, &BytePos, &ByteCnt, &BitPos, &BitCnt );
00288 
00289         sprintf(cID, "%02d %02d %02d %02d %02d %02d %02d",
00290                         FamID, iNewMemID, Block, BytePos, ByteCnt, BitPos, BitCnt);
00291 
00292         return cID;
00293 }
00294 
00295 /***************************************************************************
00296   Begin         :       20.04.2001 / M. Hultsch
00297   Version       :       03.00.00 / 27.11.2007 / M. Hultsch
00298 
00299   Function              :       changes block number in ID
00300 
00301   Parameters    :       const char* ID          -       data identifier
00302 
00303   Return Value  :       char* ID                        -       Pointer to new ID or "00 00 00 00 00 00 00"
00304 
00305 ***************************************************************************/
00306 _FEDM_ISC_CORE_EXT_FUNCT char* FEDM_MdfyBlockNr(const char* ID, int iBlockNr)
00307 {
00308         static char cID[32];
00309 
00310         if(ID==NULL)
00311         {
00312                 strcpy(cID, "00 00 00 00 00 00 00");
00313                 return cID;
00314         }
00315 
00316         int FamID=0, MemID=0, Block=0, BytePos=0, ByteCnt=0, BitPos=0, BitCnt=0;
00317 
00318         // extract access parameters
00319         sscanf( ID, "%d %d %d %d %d %d %d",
00320                         &FamID, &MemID, &Block, &BytePos, &ByteCnt, &BitPos, &BitCnt );
00321 
00322         sprintf(cID,
00323                         "%02d %02d %02d %02d %02d %02d %02d",
00324                         FamID, MemID, iBlockNr, BytePos, ByteCnt, BitPos, BitCnt);
00325 
00326         return cID;
00327 }
00328 
00329 /***************************************************************************
00330   Begin         :       19.04.2002 / M. Hultsch
00331   Version       :       03.00.00 / 27.11.2007 / M. Hultsch
00332 
00333   Function              :       adds offset to block number in ID
00334 
00335   Parameters    :       const char* ID          -       data identifier
00336 
00337   Return Value  :       char* ID                        -       Pointer to new ID or "00 00 00 00 00 00 00"
00338 
00339 ***************************************************************************/
00340 _FEDM_ISC_CORE_EXT_FUNCT char* FEDM_AddOff2BlockNr(const char* ID, int iOffset)
00341 {
00342         static char cID[32];
00343 
00344         if(ID==NULL)
00345         {
00346                 strcpy(cID, "00 00 00 00 00 00 00");
00347                 return cID;
00348         }
00349 
00350         int FamID=0, MemID=0, Block=0, BytePos=0, ByteCnt=0, BitPos=0, BitCnt=0;
00351 
00352         // extract access parameters
00353         sscanf( ID, "%d %d %d %d %d %d %d",
00354                         &FamID, &MemID, &Block, &BytePos, &ByteCnt, &BitPos, &BitCnt );
00355 
00356         sprintf(cID,
00357                         "%02d %02d %02d %02d %02d %02d %02d",
00358                         FamID, MemID, Block+iOffset, BytePos, ByteCnt, BitPos, BitCnt);
00359 
00360         return cID;
00361 }
00362 
00363 
00364 /***************************************************************************
00365   Begin         :       31.05.2012 / M. Hultsch
00366   Version       :       04.02.01 / 31.05.2012 / M. Hultsch
00367 
00368   Function              :       swaps byte order
00369 
00370   Parameters    :       unsigned int value
00371 
00372   Return Value  :       unsigned int - value with swapped byte order
00373 ***************************************************************************/
00374 _FEDM_ISC_CORE_EXT_FUNCT unsigned int FEDM_SwapByteOrder(unsigned int uiValue)
00375 {
00376         unsigned int uiTmp = ((uiValue & 0xFF000000) >> 24);
00377         uiTmp |= ((uiValue & 0x00FF0000) >>  8);
00378         uiTmp |= ((uiValue & 0x0000FF00) <<  8);
00379         uiTmp |= ((uiValue & 0x000000FF) << 24);
00380 
00381         return uiTmp;
00382 }
00383 
00384 /***************************************************************************
00385   Begin         :       31.05.2012 / M. Hultsch
00386   Version       :       04.02.01 / 31.05.2012 / M. Hultsch
00387 
00388   Function              :       swaps byte order
00389 
00390   Parameters    :       __int64 value
00391 
00392   Return Value  :       __int64 - value with swapped byte order
00393 ***************************************************************************/
00394 _FEDM_ISC_CORE_EXT_FUNCT __int64 FEDM_SwapByteOrder(__int64 i64Value)
00395 {
00396         __int64 i64Tmp = 0;
00397 #if _MSC_VER <= 1200 && !defined(__GNUC__)
00398         i64Tmp  = ((i64Value & 0xFF00000000000000) >> 56);
00399         i64Tmp |= ((i64Value & 0x00FF000000000000) >> 40);
00400         i64Tmp |= ((i64Value & 0x0000FF0000000000) >> 24);
00401         i64Tmp |= ((i64Value & 0x000000FF00000000) >>  8);
00402         i64Tmp |= ((i64Value & 0x00000000FF000000) <<  8);
00403         i64Tmp |= ((i64Value & 0x0000000000FF0000) << 24);
00404         i64Tmp |= ((i64Value & 0x000000000000FF00) << 40);
00405         i64Tmp |= ((i64Value & 0x00000000000000FF) << 56);
00406 #else
00407         i64Tmp  = ((i64Value & 0xFF00000000000000ULL) >> 56);
00408         i64Tmp |= ((i64Value & 0x00FF000000000000ULL) >> 40);
00409         i64Tmp |= ((i64Value & 0x0000FF0000000000ULL) >> 24);
00410         i64Tmp |= ((i64Value & 0x000000FF00000000ULL) >>  8);
00411         i64Tmp |= ((i64Value & 0x00000000FF000000ULL) <<  8);
00412         i64Tmp |= ((i64Value & 0x0000000000FF0000ULL) << 24);
00413         i64Tmp |= ((i64Value & 0x000000000000FF00ULL) << 40);
00414         i64Tmp |= ((i64Value & 0x00000000000000FFULL) << 56);
00415 #endif
00416         return i64Tmp;
00417 }
00418 
00419 
00420 //#####################################################################################
00421 // data type conversion functions
00422 // 
00423 // HexStr -> different types
00424 //#####################################################################################
00425 
00426 
00427 /***************************************************************************
00428   Begin         :       20.11.2000 / M. Hultsch
00429   Version       :       01.03.00 / 19.06.2001 / M. Hultsch
00430 
00431   Function              :       converts hex-string (CString) in int
00432                                         all chars except "0..9, a..f, A..F" will be removed
00433 
00434                                         attention: max. 8 chars in sIn
00435 
00436                                         example:
00437                                         sIn  = "1122F05E"
00438                                         iOut = 287502430
00439 
00440   Parameters    :       CString sIn             -       input string
00441                                         int* iOut               -       pointer to data member
00442 
00443   Return Value  :       int                             -       OK (0) or error (<0)
00444 
00445 ***************************************************************************/
00446 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
00447 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToInt(CString sIn, int* iOut)
00448 {
00449         FEDM_CHK3(iOut);
00450 
00451         int             iByteCnt;
00452 #ifdef _FEDM_MFC_SUPPORT                // Microsoft Compiler
00453         int             iTmpBufLen      = sIn.GetLength();
00454 #endif
00455 #ifdef __BORLANDC__     // Borland C++ Builder
00456         int             iTmpBufLen      = sIn.Length();
00457 #endif
00458         unsigned char   *ucTmpBuf;
00459 
00460         if (iTmpBufLen == 0)
00461                 return FEDM_ERROR_STRING_LENGTH;
00462 
00463         if ((iTmpBufLen%2) != 0)
00464                 return FEDM_ERROR_ODD_STRING_LENGTH;
00465 
00466         ucTmpBuf = new unsigned char[iTmpBufLen/2];
00467 
00468         if(ucTmpBuf == NULL)
00469                 return FEDM_ERROR_NO_MORE_MEM;
00470 
00471         int     iLen = FEDM_ConvHexStrToHexUChar(sIn, ucTmpBuf, iTmpBufLen/2);
00472 
00473         if(iLen <= 0 || iLen > 4)
00474         {
00475                 delete[] ucTmpBuf;
00476                 return FEDM_ERROR_BUFFER_LENGTH;
00477         }
00478 
00479         *iOut = 0;
00480 
00481         for(iByteCnt=0; iByteCnt<iLen; iByteCnt++)
00482                 // hier wird Motorola zu Intel geschoben
00483                 *iOut += ( (int)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00484 
00485         delete[] ucTmpBuf;
00486 
00487         return FEDM_OK;
00488 }
00489 #endif
00490 
00491 
00492 /***************************************************************************
00493   Begin         :       30.04.2002 / M. Hultsch
00494   Version       :       01.05.00 / 30.04.2002 / M. Hultsch
00495 
00496   Function              :       converts hex-string (STL-string) in int
00497                                         all chars except "0..9, a..f, A..F" will be removed
00498 
00499                                         attention: max. 8 chars in sIn
00500 
00501                                         example:
00502                                         sIn  = "1122F05E"
00503                                         iOut = 287502430
00504 
00505   Parameters    :       string sIn              -       input string
00506                                         int* iOut               -       pointer to data member
00507 
00508   Return Value  :       int                             -       OK (0) or error (<0)
00509 
00510 ***************************************************************************/
00511 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToInt(string sIn, int* iOut)
00512 {
00513         FEDM_CHK3(iOut);
00514 
00515         int             iByteCnt;
00516         size_t  iTmpBufLen      = sIn.length();
00517         unsigned char   *ucTmpBuf;
00518 
00519         if (iTmpBufLen == 0)
00520                 return FEDM_ERROR_STRING_LENGTH;
00521 
00522         if ((iTmpBufLen%2) != 0)
00523                 return FEDM_ERROR_ODD_STRING_LENGTH;
00524 
00525         ucTmpBuf = new unsigned char[iTmpBufLen/2];
00526 
00527         if(ucTmpBuf == NULL)
00528                 return FEDM_ERROR_NO_MORE_MEM;
00529 
00530         int     iLen = FEDM_ConvHexStrToHexUChar(sIn, ucTmpBuf, (int)iTmpBufLen/2);
00531 
00532         if(iLen <= 0 || iLen > 4)
00533         {
00534                 delete[] ucTmpBuf;
00535                 return FEDM_ERROR_BUFFER_LENGTH;
00536         }
00537 
00538         *iOut = 0;
00539 
00540         for(iByteCnt=0; iByteCnt<iLen; iByteCnt++)
00541                 // hier wird Motorola zu Intel geschoben
00542                 *iOut += ( (int)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00543 
00544         delete[] ucTmpBuf;
00545 
00546         return FEDM_OK;
00547 }
00548 
00549 /***************************************************************************
00550   Begin         :       20.11.2000 / M. Hultsch
00551   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
00552 
00553   Function              :       converts hex-string (CString) in unsigned int
00554                                         all chars except "0..9, a..f, A..F" will be removed
00555 
00556                                         attention: max. 8 chars in sIn
00557 
00558                                         example:
00559                                         sIn   = "1122F05E"
00560                                         uiOut = 287502430
00561 
00562   Parameters    :       CString sIn             -       input string
00563                                         unsigned int* uiOut             -       pointer to data member
00564 
00565   Return Value  :       int                             -       OK (0) or error (<0)
00566 
00567 ***************************************************************************/
00568 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
00569 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToUInt(CString sIn, unsigned int* uiOut)
00570 {
00571         FEDM_CHK3(uiOut);
00572 
00573         int iOut = 0;
00574 
00575         int     iBack = FEDM_ConvHexStrToInt(sIn, &iOut);
00576         
00577         if(iBack < 0)
00578                 return iBack;
00579 
00580         *uiOut = (unsigned int)iOut;
00581 
00582         return FEDM_OK;
00583 }
00584 #endif
00585 
00586 /***************************************************************************
00587   Begin         :       30.04.2002 / M. Hultsch
00588   Version       :       01.05.00 / 30.04.2004 / M. Hultsch
00589 
00590   Function              :       converts hex-string (STL-string) in unsigned int
00591                                         all chars except "0..9, a..f, A..F" will be removed
00592 
00593                                         attention: max. 8 chars in sIn
00594 
00595                                         example:
00596                                         sIn   = "1122F05E"
00597                                         uiOut = 287502430
00598 
00599   Parameters    :       string sIn              -       input string
00600                                         unsigned int* uiOut             -       pointer to data member
00601 
00602   Return Value  :       int                             -       OK (0) or error (<0)
00603 
00604 ***************************************************************************/
00605 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToUInt(string sIn, unsigned int* uiOut)
00606 {
00607         FEDM_CHK3(uiOut);
00608 
00609         int iOut = 0;
00610 
00611         int     iBack = FEDM_ConvHexStrToInt(sIn, &iOut);
00612         
00613         if(iBack < 0)
00614                 return iBack;
00615 
00616         *uiOut = (unsigned int)iOut;
00617 
00618         return FEDM_OK;
00619 }
00620 
00621 /***************************************************************************
00622   Begin         :       20.11.2000 / M. Hultsch
00623   Version       :       01.03.00 / 19.06.2001 / M. Hultsch
00624 
00625   Function              :       converts hex-string (CString) in __int64
00626                                         all chars except "0..9, a..f, A..F" will be removed
00627 
00628                                         attention: max. 16 chars in sIn
00629 
00630                                         example:
00631                                         sIn             = "1122F05E1122F05E"
00632                                         i64Out  = 1234813534658031710
00633 
00634   Parameters    :       CString sIn             -       input string
00635                                         __int64* i64Out -       pointer to data member
00636 
00637   Return Value  :       int                             -       OK (0) or error (<0)
00638 
00639 ***************************************************************************/
00640 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
00641 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToInt64(CString sIn, __int64* i64Out)
00642 {
00643         FEDM_CHK3(i64Out);
00644 
00645         int             iByteCnt;
00646 #ifdef _FEDM_MFC_SUPPORT                // Microsoft Compiler
00647         int             iTmpBufLen      = sIn.GetLength();
00648 #endif
00649 #ifdef __BORLANDC__     // Borland C++ Builder
00650         int             iTmpBufLen      = sIn.Length();
00651 #endif
00652         unsigned char   *ucTmpBuf;
00653 
00654         if (iTmpBufLen == 0)
00655                 return FEDM_ERROR_STRING_LENGTH;
00656 
00657         if ((iTmpBufLen%2) != 0)
00658                 return FEDM_ERROR_ODD_STRING_LENGTH;
00659 
00660         ucTmpBuf = new unsigned char[iTmpBufLen/2];
00661 
00662         if(ucTmpBuf == NULL)
00663                 return FEDM_ERROR_NO_MORE_MEM;
00664 
00665         int     iLen = FEDM_ConvHexStrToHexUChar(sIn, ucTmpBuf, iTmpBufLen/2);
00666 
00667         if(iLen <= 0 || iLen > 8)
00668         {
00669                 delete[] ucTmpBuf;
00670                 return FEDM_ERROR_BUFFER_LENGTH;
00671         }
00672 
00673         *i64Out = 0;
00674 
00675         for(iByteCnt=0; iByteCnt<iLen; iByteCnt++)
00676                 // hier wird Motorola zu Intel geschoben
00677                 *i64Out += ( (__int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00678 
00679         delete[] ucTmpBuf;
00680 
00681         return FEDM_OK;
00682 }
00683 #endif
00684 
00685 /***************************************************************************
00686   Begin         :       17.03.2010 / M. Hultsch
00687   Version       :       03.01.01 / 17.03.2010 / M. Hultsch
00688 
00689   Function              :       converts hex-string (CString) in unsigned __int64
00690                                         all chars except "0..9, a..f, A..F" will be removed
00691 
00692                                         attention: max. 16 chars in sIn
00693 
00694                                         example:
00695                                         sIn             = "1122F05E1122F05E"
00696                                         ui64Out = 1234813534658031710
00697 
00698   Parameters    :       CString sIn                                     -       input string
00699                                         unsigned __int64* ui64Out       -       pointer to data member
00700 
00701   Return Value  :       int                             -       OK (0) or error (<0)
00702 
00703 ***************************************************************************/
00704 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
00705 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToUInt64(CString sIn, unsigned __int64* ui64Out)
00706 {
00707         FEDM_CHK3(ui64Out);
00708 
00709         int             iByteCnt;
00710 #ifdef _FEDM_MFC_SUPPORT                // Microsoft Compiler
00711         int             iTmpBufLen      = sIn.GetLength();
00712 #endif
00713 #ifdef __BORLANDC__     // Borland C++ Builder
00714         int             iTmpBufLen      = sIn.Length();
00715 #endif
00716         unsigned char   *ucTmpBuf;
00717 
00718         if (iTmpBufLen == 0)
00719                 return FEDM_ERROR_STRING_LENGTH;
00720 
00721         if ((iTmpBufLen%2) != 0)
00722                 return FEDM_ERROR_ODD_STRING_LENGTH;
00723 
00724         ucTmpBuf = new unsigned char[iTmpBufLen/2];
00725 
00726         if(ucTmpBuf == NULL)
00727                 return FEDM_ERROR_NO_MORE_MEM;
00728 
00729         int     iLen = FEDM_ConvHexStrToHexUChar(sIn, ucTmpBuf, iTmpBufLen/2);
00730 
00731         if(iLen <= 0 || iLen > 8)
00732         {
00733                 delete[] ucTmpBuf;
00734                 return FEDM_ERROR_BUFFER_LENGTH;
00735         }
00736 
00737         *ui64Out = 0;
00738 
00739         for(iByteCnt=0; iByteCnt<iLen; iByteCnt++)
00740                 // hier wird Motorola zu Intel geschoben
00741                 *ui64Out += ( (unsigned __int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00742 
00743         delete[] ucTmpBuf;
00744 
00745         return FEDM_OK;
00746 }
00747 #endif
00748 
00749 /***************************************************************************
00750   Begin         :       30.04.2002 / M. Hultsch
00751   Version       :       01.05.00 / 30.04.2002 / M. Hultsch
00752 
00753   Function              :       converts hex-string (STL-string) in __int64
00754                                         all chars except "0..9, a..f, A..F" will be removed
00755 
00756                                         attention: max. 16 chars in sIn
00757 
00758                                         example:
00759                                         sIn             = "1122F05E1122F05E"
00760                                         i64Out  = 1234813534658031710
00761 
00762   Parameters    :       string sIn              -       input string
00763                                         __int64* i64Out -       pointer to data member
00764 
00765   Return Value  :       int                             -       OK (0) or error (<0)
00766 
00767 ***************************************************************************/
00768 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToInt64(string sIn, __int64* i64Out)
00769 {
00770         FEDM_CHK3(i64Out);
00771 
00772         int             iByteCnt;
00773         size_t  iTmpBufLen      = sIn.length();
00774         unsigned char   *ucTmpBuf;
00775 
00776         if (iTmpBufLen == 0)
00777                 return FEDM_ERROR_STRING_LENGTH;
00778 
00779         if ((iTmpBufLen%2) != 0)
00780                 return FEDM_ERROR_ODD_STRING_LENGTH;
00781 
00782         ucTmpBuf = new unsigned char[iTmpBufLen/2];
00783 
00784         if(ucTmpBuf == NULL)
00785                 return FEDM_ERROR_NO_MORE_MEM;
00786 
00787         int     iLen = FEDM_ConvHexStrToHexUChar(sIn, ucTmpBuf, (int)iTmpBufLen/2);
00788 
00789         if(iLen <= 0 || iLen > 8)
00790         {
00791                 delete[] ucTmpBuf;
00792                 return FEDM_ERROR_BUFFER_LENGTH;
00793         }
00794 
00795         *i64Out = 0;
00796 
00797         for(iByteCnt=0; iByteCnt<iLen; iByteCnt++)
00798                 // hier wird Motorola zu Intel geschoben
00799                 *i64Out += ( (__int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00800 
00801         delete[] ucTmpBuf;
00802 
00803         return FEDM_OK;
00804 }
00805 
00806 /***************************************************************************
00807   Begin         :       17.03.2010 / M. Hultsch
00808   Version       :       03.01.01 / 17.03.2010 / M. Hultsch
00809 
00810   Function              :       converts hex-string (STL-string) in unsigned __int64
00811                                         all chars except "0..9, a..f, A..F" will be removed
00812 
00813                                         attention: max. 16 chars in sIn
00814 
00815                                         example:
00816                                         sIn             = "1122F05E1122F05E"
00817                                         ui64Out = 1234813534658031710
00818 
00819   Parameters    :       string sIn                                      -       input string
00820                                         unsigned __int64* ui64Out       -       pointer to data member
00821 
00822   Return Value  :       int                             -       OK (0) or error (<0)
00823 
00824 ***************************************************************************/
00825 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToUInt64(string sIn, unsigned __int64* ui64Out)
00826 {
00827         FEDM_CHK3(ui64Out);
00828 
00829         int             iByteCnt;
00830         size_t  iTmpBufLen      = sIn.length();
00831         unsigned char   *ucTmpBuf;
00832 
00833         if (iTmpBufLen == 0)
00834                 return FEDM_ERROR_STRING_LENGTH;
00835 
00836         if ((iTmpBufLen%2) != 0)
00837                 return FEDM_ERROR_ODD_STRING_LENGTH;
00838 
00839         ucTmpBuf = new unsigned char[iTmpBufLen/2];
00840 
00841         if(ucTmpBuf == NULL)
00842                 return FEDM_ERROR_NO_MORE_MEM;
00843 
00844         int     iLen = FEDM_ConvHexStrToHexUChar(sIn, ucTmpBuf, (int)iTmpBufLen/2);
00845 
00846         if(iLen <= 0 || iLen > 8)
00847         {
00848                 delete[] ucTmpBuf;
00849                 return FEDM_ERROR_BUFFER_LENGTH;
00850         }
00851 
00852         *ui64Out = 0;
00853 
00854         for(iByteCnt=0; iByteCnt<iLen; iByteCnt++)
00855                 // hier wird Motorola zu Intel geschoben
00856                 *ui64Out += ( (unsigned __int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00857 
00858         delete[] ucTmpBuf;
00859 
00860         return FEDM_OK;
00861 }
00862 
00863 /***************************************************************************
00864   Begin         :       18.05.2000 / M. Hultsch
00865   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
00866 
00867   Function              :       converts hex-string (CString) in hex-string (unsigned char)
00868                                         example: sIn = "1122F05E" --> ucOutBuf = {0x11, 0x22, 0xF0, 0x5E}
00869                                         all chars except "0..9, a..f, A..F" will be removed
00870                                         
00871                                         attention: no null-termination
00872 
00873   Parameters    :       CString sIn                     -       input string
00874                                         unsigned char* ucOutBuf         -       pointer to output buffer
00875                                         int iOutBufLen          -       size of output buffer
00876 
00877   Return Value  :       int                                     -       count of bytes in output buffer or error code
00878 
00879 ***************************************************************************/
00880 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
00881 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToHexUChar(CString sIn, unsigned char* ucOutBuf, int iOutBufLen)
00882 {
00883         FEDM_CHK3(ucOutBuf);
00884 
00885         int             i;
00886         int             iCnt    = 0;
00887 #ifdef _FEDM_MFC_SUPPORT                // Microsoft Compiler
00888         int             iInLen  = sIn.GetLength();
00889 #endif
00890 #ifdef __BORLANDC__     // Borland C++ Builder
00891         int             iInLen  = sIn.Length();
00892 #endif
00893         int             iOutLen = 0;
00894         unsigned char   *ucTmpBuf;
00895 
00896 
00897         if (iInLen == 0)
00898                 return FEDM_ERROR_STRING_LENGTH;
00899 
00900         ucTmpBuf = new unsigned char[iInLen];
00901 
00902         if(ucTmpBuf == NULL)
00903                 return FEDM_ERROR_NO_MORE_MEM;
00904 
00905         // remove all non-hex chars, copy string (CString) in temp. string (unsigned char)
00906         iCnt = FEDM_RemNoHexChar(sIn, ucTmpBuf, iInLen);
00907         
00908         if ((iCnt%2) != 0)
00909         {
00910                 delete[] ucTmpBuf;
00911                 return FEDM_ERROR_ODD_STRING_LENGTH;
00912         }
00913         
00914         if ((iCnt / 2) > iOutBufLen)
00915         {
00916                 delete[] ucTmpBuf;
00917                 return FEDM_ERROR_BUFFER_LENGTH;
00918         }
00919 
00920         // convert every two chars to one hex-char
00921         for (i = 0; i < iCnt; i += 2)
00922         {
00923                 ucOutBuf[i / 2] = FEDM_ConvTwoAsciiToUChar(ucTmpBuf[i], ucTmpBuf[i+1]);
00924                 iOutLen++;
00925         }
00926 
00927         delete[] ucTmpBuf;
00928 
00929         return iOutLen;
00930 }
00931 #endif
00932 
00933 /***************************************************************************
00934   Begin         :       30.04.2002 / M. Hultsch
00935   Version       :       01.05.00 / 30.04.2002 / M. Hultsch
00936 
00937   Function              :       converts hex-string (STL-string) in hex-string (unsigned char)
00938                                         example: sIn = "1122F05E" --> ucOutBuf = {0x11, 0x22, 0xF0, 0x5E}
00939                                         all chars except "0..9, a..f, A..F" will be removed
00940                                         
00941                                         attention: no null-termination
00942 
00943   Parameters    :       string sIn                      -       input string
00944                                         unsigned char* ucOutBuf         -       pointer to output buffer
00945                                         int iOutBufLen          -       size of output buffer
00946 
00947   Return Value  :       int                                     -       count of bytes in output buffer or error code
00948 
00949 ***************************************************************************/
00950 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexStrToHexUChar(string sIn, unsigned char* ucOutBuf, int iOutBufLen)
00951 {
00952         FEDM_CHK3(ucOutBuf);
00953 
00954         int             i;
00955         int             iCnt    = 0;
00956         int             iInLen  = (int)sIn.length();
00957         int             iOutLen = 0;
00958         unsigned char   *ucTmpBuf;
00959 
00960 
00961         if (iInLen == 0)
00962                 return FEDM_ERROR_STRING_LENGTH;
00963 
00964         ucTmpBuf = new unsigned char[iInLen];
00965 
00966         if(ucTmpBuf == NULL)
00967                 return FEDM_ERROR_NO_MORE_MEM;
00968 
00969         // remove all non-hex chars, copy string (STL-string) in temp. string (unsigned char)
00970         iCnt = FEDM_RemNoHexChar(sIn, ucTmpBuf, iInLen);
00971         
00972         if ((iCnt%2) != 0)
00973         {
00974                 delete[] ucTmpBuf;
00975                 return FEDM_ERROR_ODD_STRING_LENGTH;
00976         }
00977         
00978         if ((iCnt / 2) > iOutBufLen)
00979         {
00980                 delete[] ucTmpBuf;
00981                 return FEDM_ERROR_BUFFER_LENGTH;
00982         }
00983 
00984         // convert every two chars to one hex-char
00985         for (i = 0; i < iCnt; i += 2)
00986         {
00987                 ucOutBuf[i / 2] = FEDM_ConvTwoAsciiToUChar(ucTmpBuf[i], ucTmpBuf[i+1]);
00988                 iOutLen++;
00989         }
00990 
00991         delete[] ucTmpBuf;
00992 
00993         return iOutLen;
00994 }
00995 
00996 
00997 //#####################################################################################
00998 // data type conversion functions
00999 // 
01000 // HexUChar -> different types
01001 //#####################################################################################
01002 
01003 /***************************************************************************
01004   Begin         :       20.11.2000 / M. Hultsch
01005   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
01006 
01007   Function              :       converts hex-string (unsigned char) in int
01008 
01009                                         attention: max. 4 bytes
01010 
01011                                         example:
01012                                         ucInBuf         = {0x11, 0x22, 0xF0, 0x5E}
01013                                         iInBufLen       = 4
01014                                         iOut            = 287502430
01015 
01016   Parameters    :       unsigned char* ucInBuf          -       pointer to input buffer
01017                                         int iInBufLen           -       size of input buffer
01018                                         int* iOut                       -       pointer to data member
01019 
01020   Return Value  :       int                                     -       OK (0) or error (<0)
01021 
01022 ***************************************************************************/
01023 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_ConvHexUCharToInt(unsigned char* ucInBuf, int iInBufLen, int* iOut)
01024 {
01025         FEDM_CHK3(ucInBuf);
01026         FEDM_CHK3(iOut);
01027 
01028         if(iInBufLen<0 || iInBufLen>4)
01029                 return FEDM_ERROR_BUFFER_LENGTH;
01030 
01031         int     iByteCnt;
01032         *iOut = 0;
01033 
01034         // change Motorola format into Intel format
01035         for ( iByteCnt=0; iByteCnt<iInBufLen; iByteCnt++ )
01036                 *iOut += ( (int)ucInBuf[iInBufLen-1-iByteCnt] << (8*iByteCnt) );
01037 
01038         return FEDM_OK;
01039 }
01040 
01041 /***************************************************************************
01042   Begin         :       20.11.2000 / M. Hultsch
01043   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
01044 
01045   Function              :       converts hex-string (unsigned char) in unsigned int
01046 
01047                                         attention: max. 4 bytes
01048 
01049                                         example:
01050                                         ucInBuf         = {0x11, 0x22, 0xF0, 0x5E}
01051                                         iInBufLen       = 4
01052                                         iOut            = 287502430
01053 
01054   Parameters    :       unsigned char* ucInBuf          -       pointer to input buffer
01055                                         int iInBufLen           -       size of input buffer
01056                                         unsigned int* uiOut                     -       pointer to data member
01057 
01058   Return Value  :       int                                     -       OK (0) or error (<0)
01059 
01060 ***************************************************************************/
01061 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_ConvHexUCharToUInt(unsigned char* ucInBuf, int iInBufLen, unsigned int* uiOut)
01062 {
01063         FEDM_CHK3(ucInBuf);
01064         FEDM_CHK3(uiOut);
01065 
01066         int iOut = 0;
01067 
01068         int iBack = FEDM_ConvHexUCharToInt(ucInBuf, iInBufLen, &iOut);
01069 
01070         if(iBack)
01071                 return iBack;
01072 
01073         *uiOut = (unsigned int)iOut;
01074 
01075         return FEDM_OK;
01076 }
01077 
01078 /***************************************************************************
01079   Begin         :       20.11.2000 / M. Hultsch
01080   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
01081 
01082 
01083   Function              :       converts hex-string (unsigned char) in __int64
01084                                         attention: max. 8 bytes
01085 
01086                                         example:
01087                                         ucInBuf         = {0x11, 0x22, 0xF0, 0x5E, 0x11, 0x22, 0xF0, 0x5E}
01088                                         iInBufLen       = 8
01089                                         i64Out          = 1234813534658031710
01090 
01091   Parameters    :       unsigned char* ucInBuf          -       pointer to input buffer
01092                                         int iBufLen                     -       size of input buffer
01093                                         __int64* i64Out         -       pointer to data member
01094 
01095   Return Value  :       int                                     -       OK (0) or error (<0)
01096 
01097 ***************************************************************************/
01098 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_ConvHexUCharToInt64(unsigned char* ucInBuf, int iInBufLen, __int64* i64Out)
01099 {
01100         FEDM_CHK3(ucInBuf);
01101         FEDM_CHK3(i64Out);
01102 
01103         if(iInBufLen<0 || iInBufLen>8)
01104                 return FEDM_ERROR_BUFFER_LENGTH;
01105 
01106         int     iByteCnt;
01107         *i64Out = 0;
01108 
01109         // change Motorola format into Intel format
01110         for ( iByteCnt=0; iByteCnt<iInBufLen; iByteCnt++ )
01111                 *i64Out += ( (__int64)ucInBuf[iInBufLen-1-iByteCnt] << (8*iByteCnt) );
01112 
01113         return FEDM_OK;
01114 }
01115 
01116 /***************************************************************************
01117   Begin         :       17.03.2010 / M. Hultsch
01118   Version       :       03.01.01 / 17.03.2010 / M. Hultsch
01119 
01120 
01121   Function              :       converts hex-string (unsigned char) in unsigned __int64
01122                                         attention: max. 8 bytes
01123 
01124                                         example:
01125                                         ucInBuf         = {0x11, 0x22, 0xF0, 0x5E, 0x11, 0x22, 0xF0, 0x5E}
01126                                         iInBufLen       = 8
01127                                         ui64Out         = 1234813534658031710
01128 
01129   Parameters    :       unsigned char* ucInBuf                          -       pointer to input buffer
01130                                         int iBufLen                                     -       size of input buffer
01131                                         unsigned __int64* i64Out        -       pointer to data member
01132 
01133   Return Value  :       int                                     -       OK (0) or error (<0)
01134 
01135 ***************************************************************************/
01136 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_ConvHexUCharToUInt64(unsigned char* ucInBuf, int iInBufLen, unsigned __int64* ui64Out)
01137 {
01138         FEDM_CHK3(ucInBuf);
01139         FEDM_CHK3(ui64Out);
01140 
01141         if(iInBufLen<0 || iInBufLen>8)
01142                 return FEDM_ERROR_BUFFER_LENGTH;
01143 
01144         int     iByteCnt;
01145         *ui64Out = 0;
01146 
01147         // change Motorola format into Intel format
01148         for ( iByteCnt=0; iByteCnt<iInBufLen; iByteCnt++ )
01149                 *ui64Out += ( (unsigned __int64)ucInBuf[iInBufLen-1-iByteCnt] << (8*iByteCnt) );
01150 
01151         return FEDM_OK;
01152 }
01153 
01154 
01155 /***************************************************************************
01156   Begin         :       20.02.2006 / M. Hultsch
01157   Version       :       02.04.01 / 20.02.2006 / M. Hultsch
01158 
01159   Function              :       converts hex-string (unsigned char) in char string
01160                                         this function is used for transponders serial numbers
01161                                         and other ultra long values
01162 
01163                                         example:
01164                                         ucInBuf         = {0x11, 0x22, 0xF0, 0x5E}
01165                                         iInBufLen       = 4
01166                                         cOut            = "1122F05E"
01167 
01168   Parameters    :       unsigned char* ucInBuf          -       pointer to input buffer
01169                                         int iInBufLen           -       size of input buffer
01170                                         char* cOut                      -       pointer to data member
01171                                         int iOutBufLen          -       size of output buffer (includes additional '\0')
01172 
01173   Return Value  :       int                                     -       OK (0) or error (<0)
01174 
01175 ***************************************************************************/
01176 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexUCharToHexChar(unsigned char* ucInBuf, int iInBufLen, char* cOut, int iOutBufLen)
01177 {
01178         FEDM_CHK3(ucInBuf);
01179         FEDM_CHK3(cOut);
01180 
01181         if(iInBufLen<0 || iOutBufLen<0)
01182                 return FEDM_ERROR_BUFFER_LENGTH;
01183 
01184         if(iOutBufLen < (2*iInBufLen))
01185                 return FEDM_ERROR_BUFFER_LENGTH;
01186 
01187         int      iByteCnt;
01188         char cBuffer[3];
01189         unsigned char ucTmp;
01190 
01191         for(int i=0; i<iOutBufLen; ++i)
01192                 cOut[i] = 0;
01193 
01194         for ( iByteCnt=0; iByteCnt<iInBufLen; iByteCnt++ )
01195         {
01196                 ucTmp = ucInBuf[iByteCnt];
01197                 cBuffer[0] = '\0';
01198                 sprintf( cBuffer, "%02X", ucTmp );
01199                 strcat(cOut, cBuffer);
01200         }
01201 
01202         return FEDM_OK;
01203 }
01204 
01205 
01206 /***************************************************************************
01207   Begin         :       19.08.2003 / M. Hultsch
01208   Version       :       01.08.00 / 19.08.2003 / M. Hultsch
01209 
01210   Function              :       converts hex-string (unsigned char) in STL-string
01211                                         this function is used for transponders serial numbers
01212                                         and other ultra long values
01213 
01214                                         example:
01215                                         ucInBuf         = {0x11, 0x22, 0xF0, 0x5E}
01216                                         iInBufLen       = 4
01217                                         sOut            = "1122F05E"
01218 
01219   Parameters    :       unsigned char* ucInBuf          -       pointer to input buffer
01220                                         int iBufLen                     -       size of input buffer
01221                                         string& sOut            -       pointer to data member
01222 
01223   Return Value  :       int                                     -       OK (0) or error (<0)
01224 
01225 ***************************************************************************/
01226 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_ConvHexUCharToHexStr(unsigned char* ucInBuf, int iInBufLen, string& sOut)
01227 {
01228         FEDM_CHK3(ucInBuf);
01229         FEDM_CHK3(&sOut);
01230 
01231         if(iInBufLen<0)
01232                 return FEDM_ERROR_BUFFER_LENGTH;
01233 
01234         int      iByteCnt;
01235         char cBuffer[3];
01236         unsigned char ucTmp;
01237 
01238         sOut = "";
01239 
01240         for ( iByteCnt=0; iByteCnt<iInBufLen; iByteCnt++ )
01241         {
01242                 ucTmp = ucInBuf[iByteCnt];
01243                 cBuffer[0] = '\0';
01244                 sprintf( cBuffer, "%02X", ucTmp );
01245                 sOut += cBuffer;
01246         }
01247 
01248         return FEDM_OK;
01249 }
01250 
01251 /***************************************************************************
01252   Begin         :       18.05.2000 / M. Hultsch
01253   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
01254 
01255   Function              :       converts hex-string (unsigned char) in CString
01256                                         this function is used for transponders serial numbers
01257                                         and other ultra long values
01258 
01259                                         example:
01260                                         ucInBuf         = {0x11, 0x22, 0xF0, 0x5E}
01261                                         iInBufLen       = 4
01262                                         sOut            = "1122F05E"
01263 
01264   Parameters    :       unsigned char* ucInBuf          -       pointer to input buffer
01265                                         int iBufLen                     -       size of input buffer
01266                                         CString& sOut           -       pointer to data member
01267 
01268   Return Value  :       int                                     -       OK (0) or error (<0)
01269 
01270 ***************************************************************************/
01271 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
01272 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_ConvHexUCharToHexStr(unsigned char* ucInBuf, int iInBufLen, CString& sOut)
01273 {
01274         FEDM_CHK3(ucInBuf);
01275         FEDM_CHK3(&sOut);
01276 
01277         if(iInBufLen<0)
01278                 return FEDM_ERROR_BUFFER_LENGTH;
01279 
01280         int      iByteCnt;
01281         char cBuffer[3];
01282         unsigned char ucTmp;
01283 
01284         sOut = "";
01285 
01286         for ( iByteCnt=0; iByteCnt<iInBufLen; iByteCnt++ )
01287         {
01288                 ucTmp = ucInBuf[iByteCnt];
01289                 cBuffer[0] = '\0';
01290                 sprintf( cBuffer, "%02X", ucTmp );
01291                 sOut += cBuffer;
01292         }
01293 
01294         return FEDM_OK;
01295 }
01296 #endif
01297 
01298 
01299 
01300 //#####################################################################################
01301 // data type conversion functions
01302 // 
01303 // HexChar -> different types
01304 //#####################################################################################
01305 
01306 /***************************************************************************
01307   Begin         :       21.02.2006 / M. Hultsch
01308   Version       :       02.04.01 / 21.02.2006 / M. Hultsch
01309 
01310   Function              :       converts hex char in int
01311 
01312                                         attention: max. 8 bytes and even number of bytes
01313 
01314                                         example:
01315                                         cInBuf          = "1122F05E"
01316                                         iInBufLen       = 8
01317                                         iOut            = 287502430
01318 
01319   Parameters    :       char* cInBuf            -       pointer to input buffer
01320                                         int iInBufLen           -       size of input buffer
01321                                         int* iOut                       -       pointer to data member
01322 
01323   Return Value  :       int                                     -       OK (0) or error (<0)
01324 
01325 ***************************************************************************/
01326 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexCharToInt(char* cInBuf, int iBufLen, int* iOut)
01327 {
01328         FEDM_CHK3(cInBuf);
01329         FEDM_CHK3(iOut);
01330 
01331         int             iByteCnt;
01332         unsigned char   *ucTmpBuf;
01333 
01334         if (iBufLen == 0)
01335                 return FEDM_ERROR_STRING_LENGTH;
01336 
01337         if ((iBufLen%2) != 0)
01338                 return FEDM_ERROR_ODD_STRING_LENGTH;
01339 
01340         ucTmpBuf = new unsigned char[iBufLen/2];
01341 
01342         if(ucTmpBuf == NULL)
01343                 return FEDM_ERROR_NO_MORE_MEM;
01344 
01345         int     iLen = FEDM_ConvHexCharToHexUChar(cInBuf, iBufLen, ucTmpBuf, (int)iBufLen/2);
01346 
01347         if(iLen <= 0 || iLen > 4)
01348         {
01349                 delete[] ucTmpBuf;
01350                 return FEDM_ERROR_BUFFER_LENGTH;
01351         }
01352 
01353         *iOut = 0;
01354 
01355         for(iByteCnt=0; iByteCnt<iLen; iByteCnt++)
01356                 // hier wird Motorola zu Intel geschoben
01357                 *iOut += ( (int)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
01358 
01359         delete[] ucTmpBuf;
01360 
01361         return FEDM_OK;
01362 }
01363 
01364 
01365 /***************************************************************************
01366   Begin         :       21.02.2006 / M. Hultsch
01367   Version       :       02.04.01 / 21.02.2006 / M. Hultsch
01368 
01369   Function              :       converts hex char in unsigned int
01370 
01371                                         attention: max. 8 bytes and even number of bytes
01372 
01373                                         example:
01374                                         cInBuf          = "1122F05E"
01375                                         iInBufLen       = 8
01376                                         iOut            = 287502430
01377 
01378   Parameters    :       char* cInBuf            -       pointer to input buffer
01379                                         int iInBufLen           -       size of input buffer
01380                                         unsigned int* uiOut                     -       pointer to data member
01381 
01382   Return Value  :       int                                     -       OK (0) or error (<0)
01383 
01384 ***************************************************************************/
01385 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexCharToUInt(char* cInBuf, int iBufLen, unsigned int* uiOut)
01386 {
01387         FEDM_CHK3(cInBuf);
01388         FEDM_CHK3(uiOut);
01389 
01390         int iOut = 0;
01391 
01392         int     iBack = FEDM_ConvHexCharToInt(cInBuf, iBufLen, &iOut);
01393         
01394         if(iBack < 0)
01395                 return iBack;
01396 
01397         *uiOut = (unsigned int)iOut;
01398 
01399         return FEDM_OK;
01400 }
01401 
01402 
01403 /***************************************************************************
01404   Begin         :       21.02.2006 / M. Hultsch
01405   Version       :       02.04.01 / 21.02.2006 / M. Hultsch
01406 
01407   Function              :       converts hex char in __int64
01408 
01409                                         attention: max. 16 chars and even number of bytes in cIn
01410 
01411                                         example:
01412                                         cInBuf          = "1122F05E1122F05E"
01413                                         iInBufLen       = 16
01414                                         i64Out          = 1234813534658031710
01415 
01416   Parameters    :       char* cInBuf            -       pointer to input buffer
01417                                         int iInBufLen           -       size of input buffer
01418                                         __int64* i64Out         -       pointer to data member
01419 
01420   Return Value  :       int                                     -       OK (0) or error (<0)
01421 
01422 ***************************************************************************/
01423 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexCharToInt64(char* cInBuf, int iBufLen, __int64* i64Out)
01424 {
01425         FEDM_CHK3(cInBuf);
01426         FEDM_CHK3(i64Out);
01427 
01428         int             iByteCnt;
01429         unsigned char   *ucTmpBuf;
01430 
01431         if (iBufLen == 0)
01432                 return FEDM_ERROR_STRING_LENGTH;
01433 
01434         if ((iBufLen%2) != 0)
01435                 return FEDM_ERROR_ODD_STRING_LENGTH;
01436 
01437         ucTmpBuf = new unsigned char[iBufLen/2];
01438 
01439         if(ucTmpBuf == NULL)
01440                 return FEDM_ERROR_NO_MORE_MEM;
01441 
01442         int     iLen = FEDM_ConvHexCharToHexUChar(cInBuf, iBufLen, ucTmpBuf, (int)iBufLen/2);
01443 
01444         if(iLen <= 0 || iLen > 8)
01445         {
01446                 delete[] ucTmpBuf;
01447                 return FEDM_ERROR_BUFFER_LENGTH;
01448         }
01449 
01450         *i64Out = 0;
01451 
01452         for(iByteCnt=0; iByteCnt<iLen; iByteCnt++)
01453                 // hier wird Motorola zu Intel geschoben
01454                 *i64Out += ( (__int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
01455 
01456         delete[] ucTmpBuf;
01457 
01458         return FEDM_OK;
01459 }
01460 
01461 
01462 /***************************************************************************
01463   Begin         :       17.03.2010 / M. Hultsch
01464   Version       :       03.01.01 / 17.03.2010 / M. Hultsch
01465 
01466   Function              :       converts hex char in unsigned __int64
01467 
01468                                         attention: max. 16 chars and even number of bytes in cIn
01469 
01470                                         example:
01471                                         cInBuf          = "1122F05E1122F05E"
01472                                         iInBufLen       = 16
01473                                         ui64Out         = 1234813534658031710
01474 
01475   Parameters    :       char* cInBuf                            -       pointer to input buffer
01476                                         int iInBufLen                           -       size of input buffer
01477                                         unsigned __int64* ui64Out       -       pointer to data member
01478 
01479   Return Value  :       int                                     -       OK (0) or error (<0)
01480 
01481 ***************************************************************************/
01482 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexCharToUInt64(char* cInBuf, int iBufLen, unsigned __int64* ui64Out)
01483 {
01484         FEDM_CHK3(cInBuf);
01485         FEDM_CHK3(ui64Out);
01486 
01487         int             iByteCnt;
01488         unsigned char   *ucTmpBuf;
01489 
01490         if (iBufLen == 0)
01491                 return FEDM_ERROR_STRING_LENGTH;
01492 
01493         if ((iBufLen%2) != 0)
01494                 return FEDM_ERROR_ODD_STRING_LENGTH;
01495 
01496         ucTmpBuf = new unsigned char[iBufLen/2];
01497 
01498         if(ucTmpBuf == NULL)
01499                 return FEDM_ERROR_NO_MORE_MEM;
01500 
01501         int     iLen = FEDM_ConvHexCharToHexUChar(cInBuf, iBufLen, ucTmpBuf, (int)iBufLen/2);
01502 
01503         if(iLen <= 0 || iLen > 8)
01504         {
01505                 delete[] ucTmpBuf;
01506                 return FEDM_ERROR_BUFFER_LENGTH;
01507         }
01508 
01509         *ui64Out = 0;
01510 
01511         for(iByteCnt=0; iByteCnt<iLen; iByteCnt++)
01512                 // hier wird Motorola zu Intel geschoben
01513                 *ui64Out += ( (unsigned __int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
01514 
01515         delete[] ucTmpBuf;
01516 
01517         return FEDM_OK;
01518 }
01519 
01520 
01521 /***************************************************************************
01522   Begin         :       21.02.2006 / M. Hultsch
01523   Version       :       02.04.01 / 21.02.2006 / M. Hultsch
01524 
01525   Function              :       converts hex char in hex-string (unsigned char)
01526                                         example: cInBuf = "1122F05E" --> ucOutBuf = {0x11, 0x22, 0xF0, 0x5E}
01527                                         
01528                                         attention: no null-termination
01529 
01530   Parameters    :       char* cInBuf            -       pointer to input buffer
01531                                         int iInBufLen           -       size of input buffer
01532                                         unsigned char* ucOutBuf         -       pointer to output buffer
01533                                         int iOutBufLen          -       size of output buffer
01534 
01535   Return Value  :       int                                     -       count of bytes in output buffer or error code
01536 
01537 ***************************************************************************/
01538 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvHexCharToHexUChar(char* cInBuf, int iBufLen, unsigned char* ucOutBuf, int iOutBufLen)
01539 {
01540         FEDM_CHK3(cInBuf);
01541         FEDM_CHK3(ucOutBuf);
01542 
01543         int             i;
01544         int             iOutLen = 0;
01545 
01546 
01547         if (iBufLen == 0)
01548                 return FEDM_ERROR_STRING_LENGTH;
01549 
01550         if ((iBufLen%2) != 0)
01551                 return FEDM_ERROR_ODD_STRING_LENGTH;
01552         
01553         if ((iBufLen / 2) > iOutBufLen)
01554                 return FEDM_ERROR_BUFFER_LENGTH;
01555 
01556 
01557         // convert every two chars to one hex-char
01558         for (i = 0; i < iBufLen; i += 2)
01559         {
01560                 ucOutBuf[i / 2] = FEDM_ConvTwoAsciiToUChar((unsigned char)cInBuf[i], (unsigned char)cInBuf[i+1]);
01561                 iOutLen++;
01562         }
01563 
01564         return iOutLen;
01565 }
01566 
01567 
01568 
01569 
01570 //#####################################################################################
01571 // data type conversion functions
01572 // 
01573 // int -> HexUChar and HexStr
01574 //#####################################################################################
01575 
01576 /***************************************************************************
01577   Begin         :       20.11.2000 / M. Hultsch
01578   Version       :       01.00.00 / 21.11.2000 / M. Hultsch
01579 
01580   Function              :       converts int in hex-string (CString)
01581 
01582                                         example:
01583                                         iIn  = 287502430
01584                                         sOut = "1122F05E"
01585 
01586   Parameters    :       int iIn                 -       input data
01587                                         CString& sOut   -       reference to output string
01588 
01589   Return Value  :       int                             -       OK (0) or error (<0)
01590 
01591 ***************************************************************************/
01592 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
01593 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvIntToHexStr(int iIn, CString& sOut)
01594 {
01595         int iErr;
01596 
01597         FEDM_CHK1(iErr, FEDM_ConvUIntToHexStr((unsigned int)iIn, sOut));
01598 
01599         return FEDM_OK;
01600 }
01601 #endif
01602 
01603 /***************************************************************************
01604   Begin         :       30.04.2002 / M. Hultsch
01605   Version       :       01.05.00 / 30.11.2002 / M. Hultsch
01606 
01607   Function              :       converts int in hex-string (STL-string)
01608 
01609                                         example:
01610                                         iIn  = 287502430
01611                                         sOut = "1122F05E"
01612 
01613   Parameters    :       int iIn                 -       input data
01614                                         string& sOut    -       reference to output string
01615 
01616   Return Value  :       int                             -       OK (0) or error (<0)
01617 
01618 ***************************************************************************/
01619 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvIntToHexStr(int iIn, string& sOut)
01620 {
01621         int iErr;
01622 
01623         FEDM_CHK1(iErr, FEDM_ConvUIntToHexStr((unsigned int)iIn, sOut));
01624 
01625         return FEDM_OK;
01626 }
01627 
01628 /***************************************************************************
01629   Begin         :       20.02.2006 / M. Hultsch
01630   Version       :       02.04.01 / 20.02.2006 / M. Hultsch
01631 
01632   Function              :       converts int in char string
01633 
01634                                         example:
01635                                         iIn  = 287502430
01636                                         cOut = "1122F05E"
01637 
01638   Parameters    :       int iIn                 -       input data
01639                                         char* cOut              -       pointer to output string
01640                                         int iOutBufLen  -       size of output buffer (includes additional '\0')
01641 
01642   Return Value  :       int                             -       OK (0) or error (<0)
01643 
01644 ***************************************************************************/
01645 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvIntToHexChar(int iIn, char* cOut, int iOutBufLen)
01646 {
01647         int iErr;
01648 
01649         FEDM_CHK1(iErr, FEDM_ConvUIntToHexChar((unsigned int)iIn, cOut, iOutBufLen));
01650 
01651         return FEDM_OK;
01652 }
01653 
01654 /***************************************************************************
01655   Begin         :       20.11.2000 / M. Hultsch
01656   Version       :       01.00.00 / 22.11.2000 / M. Hultsch
01657 
01658   Function              :       converts int in hex-string (unsigned char)
01659                                         
01660                                         attention: no null-termination
01661 
01662                                         example:
01663                                         iIn                     = 287502430
01664                                         ucOutBuf        = {0x11, 0x22, 0xF0, 0x5E}
01665                                         iOutBufLen      = 4
01666 
01667   Parameters    :       int iIn                 -       input data
01668                                         unsigned char* ucOutBuf -       pointer to output buffer
01669                                         int iOutBufLen  -       size of output buffer
01670 
01671   Return Value  :       int                             -       OK (0) or error (<0)
01672 
01673 ***************************************************************************/
01674 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvIntToHexUChar(int iIn, unsigned char* ucOutBuf, int iOutBufLen)
01675 {
01676         int iErr;
01677 
01678         FEDM_CHK1(iErr, FEDM_ConvUIntToHexUChar((unsigned int)iIn, ucOutBuf, iOutBufLen));
01679 
01680         return FEDM_OK;
01681 }
01682 
01683 
01684 
01685 //#####################################################################################
01686 // data type conversion functions
01687 // 
01688 // unsigned int -> HexUChar and HexStr
01689 //#####################################################################################
01690 
01691 /***************************************************************************
01692   Begin         :       20.11.2000 / M. Hultsch
01693   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
01694 
01695   Function              :       converts unsigned int in hex-string (CString)
01696 
01697                                         example:
01698                                         uiIn = 287502430
01699                                         sOut = "1122F05E"
01700 
01701   Parameters    :       unsigned int uiIn               -       input data
01702                                         CString& sOut   -       reference to output string
01703 
01704   Return Value  :       int                             -       OK (0) or error (<0)
01705 
01706 ***************************************************************************/
01707 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
01708 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvUIntToHexStr(unsigned int uiIn, CString& sOut)
01709 {
01710         FEDM_CHK3(&sOut);
01711 
01712         unsigned char ucTmpBuf[4];
01713         unsigned char ucTmp;
01714         char  cBuffer[3];
01715         int   iErr;
01716 
01717         FEDM_CHK1(iErr, FEDM_ConvUIntToHexUChar(uiIn, ucTmpBuf, 4));
01718 
01719         sOut = "";
01720         for(int iCnt=0; iCnt<4; iCnt++)
01721         {
01722                 ucTmp = ucTmpBuf[iCnt];
01723                 cBuffer[0] = '\0';
01724                 sprintf( cBuffer, "%02X", ucTmp );
01725                 sOut += cBuffer;
01726         }
01727 
01728         return FEDM_OK;
01729 }
01730 #endif
01731 
01732 /***************************************************************************
01733   Begin         :       30.04.2002 / M. Hultsch
01734   Version       :       01.05.00 / 30.04.2002 / M. Hultsch
01735 
01736   Function              :       converts unsigned int in hex-string (STL-string)
01737 
01738                                         example:
01739                                         uiIn = 287502430
01740                                         sOut = "1122F05E"
01741 
01742   Parameters    :       unsigned int uiIn               -       input data
01743                                         string& sOut    -       reference to output string
01744 
01745   Return Value  :       int                             -       OK (0) or error (<0)
01746 
01747 ***************************************************************************/
01748 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvUIntToHexStr(unsigned int uiIn, string& sOut)
01749 {
01750         FEDM_CHK3(&sOut);
01751 
01752         unsigned char ucTmpBuf[4];
01753         unsigned char ucTmp;
01754         char  cBuffer[3];
01755         int   iErr;
01756 
01757         FEDM_CHK1(iErr, FEDM_ConvUIntToHexUChar(uiIn, ucTmpBuf, 4));
01758 
01759         sOut = "";
01760         for(int iCnt=0; iCnt<4; iCnt++)
01761         {
01762                 ucTmp = ucTmpBuf[iCnt];
01763                 cBuffer[0] = '\0';
01764                 sprintf( cBuffer, "%02X", ucTmp );
01765                 sOut += cBuffer;
01766         }
01767 
01768         return FEDM_OK;
01769 }
01770 
01771 /***************************************************************************
01772   Begin         :       30.04.2002 / M. Hultsch
01773   Version       :       01.05.00 / 30.04.2002 / M. Hultsch
01774 
01775   Function              :       converts unsigned int in hex-string (STL-string)
01776 
01777                                         example:
01778                                         uiIn = 287502430
01779                                         cOut = "1122F05E"
01780 
01781   Parameters    :       unsigned int uiIn               -       input data
01782                                         char* cOut              -       pointer to output string
01783                                         int iOutBufLen  -       size of output buffer (includes additional '\0')
01784 
01785   Return Value  :       int                             -       OK (0) or error (<0)
01786 
01787 ***************************************************************************/
01788 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvUIntToHexChar(unsigned int uiIn, char* cOut, int iOutBufLen)
01789 {
01790         FEDM_CHK3(cOut);
01791 
01792         if(iOutBufLen < 9)
01793                 return FEDM_ERROR_BUFFER_LENGTH;
01794 
01795         unsigned char ucTmpBuf[4];
01796         unsigned char ucTmp;
01797         char  cBuffer[3];
01798         int   iErr;
01799 
01800         FEDM_CHK1(iErr, FEDM_ConvUIntToHexUChar(uiIn, ucTmpBuf, 4));
01801 
01802         for(int i=0; i<iOutBufLen; ++i)
01803                 cOut[i] = 0;
01804 
01805         for(int iCnt=0; iCnt<4; iCnt++)
01806         {
01807                 ucTmp = ucTmpBuf[iCnt];
01808                 cBuffer[0] = '\0';
01809                 sprintf( cBuffer, "%02X", ucTmp );
01810                 strcat(cOut, cBuffer);
01811         }
01812 
01813         return FEDM_OK;
01814 }
01815 
01816 /***************************************************************************
01817   Begin         :       20.11.2000 / M. Hultsch
01818   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
01819 
01820   Function              :       converts unsigned int in hex-string (unsigned char)
01821                                         
01822                                         attention: no null-termination
01823 
01824                                         example:
01825                                         uiIn            = 287502430
01826                                         ucOutBuf        = {0x11, 0x22, 0xF0, 0x5E}
01827                                         iOutBufLen      = 4
01828 
01829   Parameters    :       unsigned int uiIn               -       input data
01830                                         unsigned char* ucOutBuf -       pointer to output buffer
01831                                         int iOutBufLen  -       size of output buffer
01832 
01833   Return Value  :       int                             -       OK (0) or error (<0)
01834 
01835 ***************************************************************************/
01836 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvUIntToHexUChar(unsigned int uiIn, unsigned char* ucOutBuf, int iOutBufLen)
01837 {
01838         FEDM_CHK3(ucOutBuf);
01839 
01840         if(iOutBufLen < 4)
01841                 return FEDM_ERROR_BUFFER_LENGTH;
01842         
01843         for(int iCnt=0; iCnt<4; iCnt++ )
01844         {
01845                 // set data in Motorola format
01846                 ucOutBuf[4-1-iCnt] = *( ((unsigned char*)&uiIn) + iCnt );
01847         }
01848 
01849         return FEDM_OK;
01850 }
01851 
01852 
01853 
01854 //#####################################################################################
01855 // data type conversion functions
01856 // 
01857 // __int64 -> HexUChar and HexStr
01858 //#####################################################################################
01859 
01860 /***************************************************************************
01861   Begin         :       20.11.2000 / M. Hultsch
01862   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
01863 
01864   Function              :       converts __int64 in hex-string (CString)
01865 
01866                                         example:
01867                                         i64In   = 1234813534658031710
01868                                         sOut    = "1122F05E1122F05E"
01869 
01870   Parameters    :       __int64 i64In   -       input data
01871                                         CString& sOut   -       reference to output string
01872 
01873   Return Value  :       int                             -       OK (0) or error (<0)
01874 
01875 ***************************************************************************/
01876 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
01877 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvInt64ToHexStr(__int64 i64In, CString& sOut)
01878 {
01879         FEDM_CHK3(&sOut);
01880 
01881         unsigned char ucTmpBuf[8];
01882         unsigned char ucTmp;
01883         char  cBuffer[3];
01884         int   iErr;
01885 
01886         FEDM_CHK1(iErr, FEDM_ConvInt64ToHexUChar(i64In, ucTmpBuf, 8));
01887 
01888         sOut = "";
01889         for(int iCnt=0; iCnt<8; iCnt++)
01890         {
01891                 ucTmp = ucTmpBuf[iCnt];
01892                 cBuffer[0] = '\0';
01893                 sprintf( cBuffer, "%02X", ucTmp );
01894                 sOut += cBuffer;
01895         }
01896         
01897         return FEDM_OK;
01898 }
01899 #endif
01900 
01901 /***************************************************************************
01902   Begin         :       17.03.2010 / M. Hultsch
01903   Version       :       03.01.01 / 17.03.2010 / M. Hultsch
01904 
01905   Function              :       converts unsigned __int64 in hex-string (CString)
01906 
01907                                         example:
01908                                         ui64In  = 1234813534658031710
01909                                         sOut    = "1122F05E1122F05E"
01910 
01911   Parameters    :       unsigned __int64 ui64In -       input data
01912                                         CString& sOut                   -       reference to output string
01913 
01914   Return Value  :       int                             -       OK (0) or error (<0)
01915 
01916 ***************************************************************************/
01917 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
01918 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvUInt64ToHexStr(unsigned __int64 ui64In, CString& sOut)
01919 {
01920         FEDM_CHK3(&sOut);
01921 
01922         unsigned char ucTmpBuf[8];
01923         unsigned char ucTmp;
01924         char  cBuffer[3];
01925         int   iErr;
01926 
01927         FEDM_CHK1(iErr, FEDM_ConvUInt64ToHexUChar(ui64In, ucTmpBuf, 8));
01928 
01929         sOut = "";
01930         for(int iCnt=0; iCnt<8; iCnt++)
01931         {
01932                 ucTmp = ucTmpBuf[iCnt];
01933                 cBuffer[0] = '\0';
01934                 sprintf( cBuffer, "%02X", ucTmp );
01935                 sOut += cBuffer;
01936         }
01937         
01938         return FEDM_OK;
01939 }
01940 #endif
01941 
01942 /***************************************************************************
01943   Begin         :       30.04.2002 / M. Hultsch
01944   Version       :       01.05.00 / 30.04.2002 / M. Hultsch
01945 
01946   Function              :       converts __int64 in hex-string (STL-string)
01947 
01948                                         example:
01949                                         i64In   = 1234813534658031710
01950                                         sOut    = "1122F05E1122F05E"
01951 
01952   Parameters    :       __int64 i64In   -       input data
01953                                         string& sOut    -       reference to output string
01954 
01955   Return Value  :       int                             -       OK (0) or error (<0)
01956 
01957 ***************************************************************************/
01958 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvInt64ToHexStr(__int64 i64In, string& sOut)
01959 {
01960         FEDM_CHK3(&sOut);
01961 
01962         unsigned char ucTmpBuf[8];
01963         unsigned char ucTmp;
01964         char  cBuffer[3];
01965         int   iErr;
01966 
01967         FEDM_CHK1(iErr, FEDM_ConvInt64ToHexUChar(i64In, ucTmpBuf, 8));
01968 
01969         sOut = "";
01970         for(int iCnt=0; iCnt<8; iCnt++)
01971         {
01972                 ucTmp = ucTmpBuf[iCnt];
01973                 cBuffer[0] = '\0';
01974                 sprintf( cBuffer, "%02X", ucTmp );
01975                 sOut += cBuffer;
01976         }
01977         
01978         return FEDM_OK;
01979 }
01980 
01981 /***************************************************************************
01982   Begin         :       17.03.2010 / M. Hultsch
01983   Version       :       03.01.01 / 17.03.2010 / M. Hultsch
01984 
01985   Function              :       converts unsigned __int64 in hex-string (STL-string)
01986 
01987                                         example:
01988                                         ui64In  = 1234813534658031710
01989                                         sOut    = "1122F05E1122F05E"
01990 
01991   Parameters    :       unsigned __int64 ui64In -       input data
01992                                         string& sOut                    -       reference to output string
01993 
01994   Return Value  :       int                             -       OK (0) or error (<0)
01995 
01996 ***************************************************************************/
01997 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvUInt64ToHexStr(unsigned __int64 ui64In, string& sOut)
01998 {
01999         FEDM_CHK3(&sOut);
02000 
02001         unsigned char ucTmpBuf[8];
02002         unsigned char ucTmp;
02003         char  cBuffer[3];
02004         int   iErr;
02005 
02006         FEDM_CHK1(iErr, FEDM_ConvUInt64ToHexUChar(ui64In, ucTmpBuf, 8));
02007 
02008         sOut = "";
02009         for(int iCnt=0; iCnt<8; iCnt++)
02010         {
02011                 ucTmp = ucTmpBuf[iCnt];
02012                 cBuffer[0] = '\0';
02013                 sprintf( cBuffer, "%02X", ucTmp );
02014                 sOut += cBuffer;
02015         }
02016         
02017         return FEDM_OK;
02018 }
02019 
02020 /***************************************************************************
02021   Begin         :       20.02.2006 / M. Hultsch
02022   Version       :       02.04.01 / 20.02.2006 / M. Hultsch
02023 
02024   Function              :       converts __int64 in char string
02025 
02026                                         example:
02027                                         i64In   = 1234813534658031710
02028                                         cOut    = "1122F05E1122F05E"
02029                                         int iOutBufLen  -       size of output buffer (includes additional '\0')
02030 
02031   Parameters    :       __int64 i64In   -       input data
02032                                         char* cOut              -       pointer to output string
02033                                         int iOutBufLen  -       size of output buffer (includes additional '\0')
02034 
02035   Return Value  :       int                             -       OK (0) or error (<0)
02036 
02037 ***************************************************************************/
02038 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvInt64ToHexChar(__int64 i64In, char* cOut, int iOutBufLen)
02039 {
02040         FEDM_CHK3(cOut);
02041 
02042         if(iOutBufLen < 8)
02043                 return FEDM_ERROR_BUFFER_LENGTH;
02044 
02045         unsigned char ucTmpBuf[8];
02046         unsigned char ucTmp;
02047         char  cBuffer[3];
02048         int   iErr;
02049 
02050         FEDM_CHK1(iErr, FEDM_ConvInt64ToHexUChar(i64In, ucTmpBuf, 8));
02051 
02052         for(int i=0; i<iOutBufLen; ++i)
02053                 cOut[i] = 0;
02054 
02055         for(int iCnt=0; iCnt<8; iCnt++)
02056         {
02057                 ucTmp = ucTmpBuf[iCnt];
02058                 cBuffer[0] = '\0';
02059                 sprintf( cBuffer, "%02X", ucTmp );
02060                 strcat(cOut, cBuffer);
02061         }
02062         
02063         return FEDM_OK;
02064 }
02065 
02066 /***************************************************************************
02067   Begin         :       17.03.2010 / M. Hultsch
02068   Version       :       03.01.01 / 17.03.2010 / M. Hultsch
02069 
02070   Function              :       converts unsigned __int64 in char string
02071 
02072                                         example:
02073                                         ui64In  = 1234813534658031710
02074                                         cOut    = "1122F05E1122F05E"
02075                                         int iOutBufLen  -       size of output buffer (includes additional '\0')
02076 
02077   Parameters    :       unsigned __int64 ui64In -       input data
02078                                         char* cOut                              -       pointer to output string
02079                                         int iOutBufLen                  -       size of output buffer (includes additional '\0')
02080 
02081   Return Value  :       int                             -       OK (0) or error (<0)
02082 
02083 ***************************************************************************/
02084 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvUInt64ToHexChar(unsigned __int64 ui64In, char* cOut, int iOutBufLen)
02085 {
02086         FEDM_CHK3(cOut);
02087 
02088         if(iOutBufLen < 8)
02089                 return FEDM_ERROR_BUFFER_LENGTH;
02090 
02091         unsigned char ucTmpBuf[8];
02092         unsigned char ucTmp;
02093         char  cBuffer[3];
02094         int   iErr;
02095 
02096         FEDM_CHK1(iErr, FEDM_ConvUInt64ToHexUChar(ui64In, ucTmpBuf, 8));
02097 
02098         for(int i=0; i<iOutBufLen; ++i)
02099                 cOut[i] = 0;
02100 
02101         for(int iCnt=0; iCnt<8; iCnt++)
02102         {
02103                 ucTmp = ucTmpBuf[iCnt];
02104                 cBuffer[0] = '\0';
02105                 sprintf( cBuffer, "%02X", ucTmp );
02106                 strcat(cOut, cBuffer);
02107         }
02108         
02109         return FEDM_OK;
02110 }
02111 
02112 /***************************************************************************
02113   Begin         :       20.11.2000 / M. Hultsch
02114   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
02115 
02116   Function              :       converts __int64 in hex-string (unsigned char)
02117                                         
02118                                         attention: no null-termination
02119 
02120                                         example:
02121                                         i64In           = 1234813534658031710
02122                                         ucOutBuf        = {0x11, 0x22, 0xF0, 0x5E, 0x11, 0x22, 0xF0, 0x5E}
02123                                         iOutBufLen      = 8
02124 
02125   Parameters    :       __int64 i64In   -       input data
02126                                         unsigned char* ucOutBuf -       pointer to output buffer
02127                                         int iOutBufLen  -       size of output buffer
02128 
02129   Return Value  :       int                             -       OK (0) or error (<0)
02130 
02131 ***************************************************************************/
02132 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvInt64ToHexUChar(__int64 i64In, unsigned char* ucOutBuf, int iOutBufLen)
02133 {
02134         FEDM_CHK3(ucOutBuf);
02135 
02136         if(iOutBufLen < 8)
02137                 return FEDM_ERROR_BUFFER_LENGTH;
02138         
02139         for(int iCnt=0; iCnt<8; iCnt++ )
02140         {
02141                 // set data in Motorola format
02142                 ucOutBuf[8-1-iCnt] = *( ((unsigned char*)&i64In) + iCnt );
02143         }
02144 
02145         return FEDM_OK;
02146 }
02147 
02148 /***************************************************************************
02149   Begin         :       17.03.2010 / M. Hultsch
02150   Version       :       03.01.01 / 17.03.2010 / M. Hultsch
02151 
02152   Function              :       converts unsigned __int64 in hex-string (unsigned char)
02153                                         
02154                                         attention: no null-termination
02155 
02156                                         example:
02157                                         ui64In          = 1234813534658031710
02158                                         ucOutBuf        = {0x11, 0x22, 0xF0, 0x5E, 0x11, 0x22, 0xF0, 0x5E}
02159                                         iOutBufLen      = 8
02160 
02161   Parameters    :       unsigned __int64 ui64In -       input data
02162                                         unsigned char* ucOutBuf                 -       pointer to output buffer
02163                                         int iOutBufLen                  -       size of output buffer
02164 
02165   Return Value  :       int                             -       OK (0) or error (<0)
02166 ***************************************************************************/
02167 _FEDM_ISC_CORE_EXT_FUNCT int    FEDM_ConvUInt64ToHexUChar(unsigned __int64 ui64In, unsigned char* ucOutBuf, int iOutBufLen)
02168 {
02169         FEDM_CHK3(ucOutBuf);
02170 
02171         if(iOutBufLen < 8)
02172                 return FEDM_ERROR_BUFFER_LENGTH;
02173         
02174         for(int iCnt=0; iCnt<8; iCnt++ )
02175         {
02176                 // set data in Motorola format
02177                 ucOutBuf[8-1-iCnt] = *( ((unsigned char*)&ui64In) + iCnt );
02178         }
02179 
02180         return FEDM_OK;
02181 }
02182 
02183 
02184 
02185 
02186 //#####################################################################################
02187 // very helpful functions
02188 //#####################################################################################
02189 
02190 /***************************************************************************
02191   Begin         :       18.05.2000 / M. Hultsch
02192   Version       :       01.00.01 / 10.12.2000 / M. Hultsch
02193 
02194   Function              :       all chars except "0..9, a..f, A..F" will be removed
02195                                         copy CString in unsigned char-String
02196 
02197   Parameters    :       CString sIn                     -       input string
02198                                         unsigned char* ucOutBuf         -       pointer to output buffer
02199                                         int iBufLen                     -       size of output buffer
02200 
02201   Return Value  :       int                                     -       count of bytes in output buffer
02202 
02203 ***************************************************************************/
02204 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
02205 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_RemNoHexChar(CString sIn, unsigned char* ucOutBuf, int iOutBufLen)
02206 {
02207         FEDM_CHK3(ucOutBuf);
02208 
02209 #ifdef _FEDM_MFC_SUPPORT                // Microsoft Compiler
02210         int     iInLen  = sIn.GetLength();
02211 #endif
02212 #ifdef __BORLANDC__     // Borland C++ Builder
02213         int     iInLen  = sIn.Length();
02214 #endif
02215 
02216         if(iOutBufLen == 0 || iOutBufLen < iInLen)
02217                 return FEDM_ERROR_BUFFER_LENGTH;
02218 
02219         int iOutLen = 0;
02220         
02221 #ifdef __BORLANDC__     // Borland C++ Builder: AnsiStrings index starts with 1 !!
02222         for (int i = 1; i<=iInLen; i++)
02223 #else
02224         for (int i = 0; i<iInLen; i++)
02225 #endif
02226         {
02227                 switch (sIn[i])
02228                 {
02229                 case '0' :;     case '1' :;     case '2' :;     case '3' :;     case '4' :;     case '5' :;
02230                 case '6' :;     case '7' :;     case '8' :;     case '9' :;
02231                 case 'a' :;     case 'b' :;     case 'c' :;     case 'd' :;     case 'e' :;     case 'f' :;
02232                 case 'A' :;     case 'B' :;     case 'C' :;     case 'D' :;     case 'E' :;     case 'F' :;
02233                         ucOutBuf[iOutLen++] = (unsigned char) sIn[i];
02234                         break;
02235                 default:
02236                         break;
02237                 }
02238         }
02239 
02240         return iOutLen;
02241 }
02242 #endif
02243 
02244 /***************************************************************************
02245   Begin         :       30.04.2002 / M. Hultsch
02246   Version       :       01.05.00 / 30.04.2002 / M. Hultsch
02247 
02248   Function              :       all chars except "0..9, a..f, A..F" will be removed
02249                                         copy STL-string in unsigned char-String
02250 
02251   Parameters    :       string sIn                      -       input string
02252                                         unsigned char* ucOutBuf         -       pointer to output buffer
02253                                         int iBufLen                     -       size of output buffer
02254 
02255   Return Value  :       int                                     -       count of bytes in output buffer
02256 
02257 ***************************************************************************/
02258 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_RemNoHexChar(string sIn, unsigned char* ucOutBuf, int iOutBufLen)
02259 {
02260         FEDM_CHK3(ucOutBuf);
02261 
02262         int     iInLen  = (int)sIn.length();
02263 
02264         if(iOutBufLen == 0 || iOutBufLen < iInLen)
02265                 return FEDM_ERROR_BUFFER_LENGTH;
02266 
02267         int iOutLen = 0;
02268         
02269         for (int i = 0; i<iInLen; i++)
02270         {
02271                 switch (sIn[i])
02272                 {
02273                 case '0' :;     case '1' :;     case '2' :;     case '3' :;     case '4' :;     case '5' :;
02274                 case '6' :;     case '7' :;     case '8' :;     case '9' :;
02275                 case 'a' :;     case 'b' :;     case 'c' :;     case 'd' :;     case 'e' :;     case 'f' :;
02276                 case 'A' :;     case 'B' :;     case 'C' :;     case 'D' :;     case 'E' :;     case 'F' :;
02277                         ucOutBuf[iOutLen++] = (unsigned char) sIn[i];
02278                         break;
02279                 default:
02280                         break;
02281                 }
02282         }
02283 
02284         return iOutLen;
02285 }
02286 
02287 /***************************************************************************
02288   Begin         :       07.02.2005 / M. Hultsch
02289   Version       :       02.01.00 / 07.02.2005 / M. Hultsch
02290 
02291   Function              :       all chars except "0..9, a..f, A..F" will be removed
02292                                         copy CString in CString
02293 
02294   Parameters    :       CString sIn                     -       input string
02295                                         CString& sOut           -       output string
02296 
02297   Return Value  :       int                                     -       number of bytes in output string
02298 
02299 ***************************************************************************/
02300 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
02301 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_RemNoHexChar(CString sIn, CString& sOut)
02302 {
02303 #ifdef _FEDM_MFC_SUPPORT                // Microsoft Compiler
02304         int     iInLen  = sIn.GetLength();
02305         sOut.Empty();
02306 #endif
02307 #ifdef __BORLANDC__     // Borland C++ Builder
02308         int     iInLen  = sIn.Length();
02309 #endif
02310 
02311         int iOutLen = 0;
02312 
02313         
02314 #ifdef __BORLANDC__     // Borland C++ Builder: AnsiStrings index starts with 1 !!
02315         for (int i = 1; i<=iInLen; i++)
02316 #else
02317         for (int i = 0; i<iInLen; i++)
02318 #endif
02319         {
02320                 switch (sIn[i])
02321                 {
02322                 case '0' :;     case '1' :;     case '2' :;     case '3' :;     case '4' :;     case '5' :;
02323                 case '6' :;     case '7' :;     case '8' :;     case '9' :;
02324                 case 'a' :;     case 'b' :;     case 'c' :;     case 'd' :;     case 'e' :;     case 'f' :;
02325                 case 'A' :;     case 'B' :;     case 'C' :;     case 'D' :;     case 'E' :;     case 'F' :;
02326                         sOut += sIn[i];
02327                         iOutLen++;
02328                         break;
02329                 default:
02330                         break;
02331                 }
02332         }
02333 
02334         return iOutLen;
02335 }
02336 #endif
02337 
02338 /***************************************************************************
02339   Begin         :       16.04.2007 / M. Hultsch
02340   Version       :       03.00.00 / 16.04.2007 / M. Hultsch
02341 
02342   Function              :       all chars except "0..9, a..f, A..F" will be removed
02343                                         copy CString in CString
02344 
02345   Parameters    :       CString sIn                     -       input string
02346 
02347   Return Value  :       CString sOut            -       output string
02348 
02349 ***************************************************************************/
02350 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
02351 _FEDM_ISC_CORE_EXT_FUNCT CString FEDM_RemNoHexChar(CString sIn)
02352 {
02353 #ifdef _FEDM_MFC_SUPPORT                // Microsoft Compiler
02354         int     iInLen  = sIn.GetLength();
02355         CString sOut;
02356 #endif
02357 #ifdef __BORLANDC__     // Borland C++ Builder
02358         int     iInLen  = sIn.Length();
02359         CString sOut;
02360 #endif
02361 
02362         
02363 #ifdef __BORLANDC__     // Borland C++ Builder: AnsiStrings index starts with 1 !!
02364         for (int i = 1; i<=iInLen; i++)
02365 #else
02366         for (int i = 0; i<iInLen; i++)
02367 #endif
02368         {
02369                 switch (sIn[i])
02370                 {
02371                 case '0' :;     case '1' :;     case '2' :;     case '3' :;     case '4' :;     case '5' :;
02372                 case '6' :;     case '7' :;     case '8' :;     case '9' :;
02373                 case 'a' :;     case 'b' :;     case 'c' :;     case 'd' :;     case 'e' :;     case 'f' :;
02374                 case 'A' :;     case 'B' :;     case 'C' :;     case 'D' :;     case 'E' :;     case 'F' :;
02375                         sOut += sIn[i];
02376                         break;
02377                 default:
02378                         break;
02379                 }
02380         }
02381 
02382         return sOut;
02383 }
02384 #endif
02385 
02386 /***************************************************************************
02387   Begin         :       07.02.2005 / M. Hultsch
02388   Version       :       02.01.00 / 07.02.2005 / M. Hultsch
02389 
02390   Function              :       all chars except "0..9, a..f, A..F" will be removed
02391                                         copy STL-string in STL-string
02392 
02393   Parameters    :       string sIn                      -       input string
02394                                         string sOut                     -       output string
02395 
02396   Return Value  :       int                                     -       number of bytes in output string
02397 
02398 ***************************************************************************/
02399 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_RemNoHexChar(string sIn, string& sOut)
02400 {
02401         int     iInLen  = (int)sIn.length();
02402 
02403         int iOutLen = 0;
02404         
02405         for (int i = 0; i<iInLen; i++)
02406         {
02407                 switch (sIn[i])
02408                 {
02409                 case '0' :;     case '1' :;     case '2' :;     case '3' :;     case '4' :;     case '5' :;
02410                 case '6' :;     case '7' :;     case '8' :;     case '9' :;
02411                 case 'a' :;     case 'b' :;     case 'c' :;     case 'd' :;     case 'e' :;     case 'f' :;
02412                 case 'A' :;     case 'B' :;     case 'C' :;     case 'D' :;     case 'E' :;     case 'F' :;
02413                         sOut += sIn[i];
02414                         iOutLen++;
02415                         break;
02416                 default:
02417                         break;
02418                 }
02419         }
02420 
02421         return iOutLen;
02422 }
02423 
02424 /***************************************************************************
02425   Begin         :       18.05.2000 / M. Hultsch
02426   Version       :       01.00.00 / 18.05.2000 / M. Hultsch
02427 
02428   Function              :       converts two ascii-chars into one byte
02429                                         example: c0='1'; c1='2' --> return value = 0x12
02430 
02431   Parameters    :       unsigned char ucIn1                     -       first ascii char
02432                                         unsigned char ucIn2                     -       second ascii char
02433 
02434   Return Value  :       unsigned char                           -       byte
02435 
02436 ***************************************************************************/
02437 _FEDM_ISC_CORE_EXT_FUNCT unsigned char FEDM_ConvTwoAsciiToUChar(unsigned char ucIn1, unsigned char ucIn2)
02438 {
02439         unsigned char   uc1, uc2;
02440         int             iValue  = 0;
02441 
02442         uc1 = (unsigned char) toupper((int) ucIn1);
02443         uc2 = (unsigned char) toupper((int) ucIn2);
02444 
02445 
02446         if ((uc1 >= '0') && (uc1 <= '9'))       { iValue  = (uc1 - 48) << 4; }
02447         if ((uc1 >= 'A') && (uc1 <= 'F'))       { iValue  = (uc1 - 55) << 4; }
02448         if ((uc2 >= '0') && (uc2 <= '9'))       { iValue += (uc2 - 48); }
02449         if ((uc2 >= 'A') && (uc2 <= 'F'))       { iValue += (uc2 - 55); }
02450 
02451         return (unsigned char)iValue;
02452 }
02453 
02454 /***************************************************************************
02455   Begin         :       27.10.2005 / M. Hultsch
02456   Version       :       02.03.06 / 27.10.2005 / M. Hultsch
02457 
02458   Function              :       converts one hex character into two ascii-chars
02459                                         example: unIn = 0x12 --> return values:  ucOut1='1' (0x31); ucOut2='2' (0x32)
02460 
02461   Parameters    :       unsigned char  ucIn                     -       input hex char
02462                                         unsigned char& ucOut            -       reference to first ascii char
02463                                         unsigned char& ucOut2           -       reference to second ascii char
02464 
02465   Return Value  :       -
02466 ***************************************************************************/
02467 _FEDM_ISC_CORE_EXT_FUNCT void FEDM_ConvHexUCharToTwoAscii(unsigned char ucIn, unsigned char& ucOut1, unsigned char& ucOut2)
02468 {
02469         if( ((ucIn&0xF0) >> 4 ) >= 0 && ((ucIn&0xF0) >> 4 ) <= 9)
02470                 ucOut1 = ((ucIn&0xF0) >> 4 ) + 48;
02471         else if( ((ucIn&0xF0) >> 4 ) >= 10 && ((ucIn&0xF0) >> 4 ) <= 15)
02472                 ucOut1 = ((ucIn&0xF0) >> 4 ) + 55;
02473 
02474         if( (ucIn&0x0F) >= 0 && (ucIn&0x0F) <= 9)
02475                 ucOut2 = (ucIn&0x0F) + 48;
02476         else if( (ucIn&0x0F) >= 10 && (ucIn&0x0F) <= 15)
02477                 ucOut2 = (ucIn&0x0F) + 55;
02478 }
02479 
02480 /***************************************************************************
02481   Begin         :       24.04.2013 / M. Hultsch
02482   Version       :       04.04.04 / 24.04.2013 / M. Hultsch
02483 
02484   Function              :       Converts each ASCII character into hex character.
02485                                         
02486                                         attention: no null-termination
02487 
02488                                         example:
02489                                         ucInBuf         = {'9', '3', '0'}
02490                                         iInBufLen       = 3
02491                                         ucOutBuf        = {0x39, 0x33, 0x30}
02492                                         iOutBufLen      = 3
02493 
02494   Parameters    :       unsigned char* ucInBuf  -       pointer to input buffer
02495                                         int iInBufLen                   -       size of input buffer
02496                                         unsigned char* ucOutBuf -       pointer to output buffer
02497                                         int iOutBufLen                  -       size of output buffer
02498 
02499   Return Value  :       int     -       OK (0) or error (<0)
02500 ***************************************************************************/
02501 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_ConvAsciiCharToHexUChar(unsigned char* ucInBuf, int iInBufLen, unsigned char* ucOutBuf, int iOutBufLen)
02502 {
02503         int     iByteCnt = 0;
02504 
02505         for( iByteCnt=0; iByteCnt<iInBufLen; iByteCnt++ )
02506         {
02507                 sscanf((const char*)&ucInBuf[iByteCnt], "%c", &ucOutBuf[iByteCnt]);
02508         }
02509 
02510         return FEDM_OK;
02511 }
02512 
02513 /***************************************************************************
02514   Begin         :       24.04.2013 / M. Hultsch
02515   Version       :       04.04.04 / 24.04.2013 / M. Hultsch
02516 
02517   Function              :       Converts BCD characters into hex array.
02518                                         Each input byte is expanded into two output bytes.
02519                                         
02520                                         attention: no null-termination
02521 
02522                                         example:
02523                                         ucInBuf         = {0x21, 0x00, 0x14}
02524                                         iInBufLen       = 3
02525                                         ucOutBuf        = {0x02, 0x01, 0x00, 0x00, 0x01, 0x04}
02526                                         iOutBufLen      = 6
02527 
02528   Parameters    :       unsigned char* ucInBuf  -       pointer to input buffer
02529                                         int iInBufLen                   -       size of input buffer
02530                                         unsigned char* ucOutBuf -       pointer to output buffer
02531                                         int iOutBufLen                  -       size of output buffer
02532 
02533   Return Value  :       int     -       Number of bytes in ucOutBuf (>0) or error (<0)
02534 ***************************************************************************/
02535 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_ConvBcdCharToHexUChar(unsigned char* ucInBuf, int iInBufLen, unsigned char* ucOutBuf, int iOutBufLen)
02536 {
02537         int             iBcdCnt;
02538         int             iByteCnt = 0;
02539 
02540         FEDM_CHK3(ucInBuf);
02541         FEDM_CHK3(ucOutBuf);
02542 
02543         if(iOutBufLen < (iInBufLen<<1) )
02544         {
02545                 return FEDM_ERROR_BUFFER_LENGTH;
02546         }
02547 
02548 
02549         for( iBcdCnt=0; iBcdCnt<iInBufLen*2; iBcdCnt++ )
02550         {
02551                 if(iBcdCnt%2 == 0)
02552                         ucOutBuf[iBcdCnt] = (unsigned char) ( ((ucInBuf[iByteCnt] & 0xF0) >> 4) + 0x30 );
02553                 else
02554                         ucOutBuf[iBcdCnt] = (unsigned char)( (ucInBuf[iByteCnt++] & 0x0F) + 0x30 );
02555         }
02556 
02557         return iByteCnt;
02558 }
02559 
02560 /***************************************************************************
02561   Begin         :       24.04.2013 / M. Hultsch
02562   Version       :       04.04.04 / 24.04.2013 / M. Hultsch
02563 
02564   Function              :       Converts hex array into BCD characters .
02565                                         Two input bytes are packed into one output byte.
02566                                         
02567                                         attention: no null-termination
02568 
02569                                         example:
02570                                         ucInBuf         = {0x02, 0x01, 0x00, 0x00, 0x01, 0x04}
02571                                         iInBufLen       = 6
02572                                         ucOutBuf        = {0x21, 0x00, 0x14}
02573                                         iOutBufLen      = 3
02574 
02575   Parameters    :       unsigned char* ucInBuf  -       pointer to input buffer
02576                                         int iInBufLen                   -       size of input buffer
02577                                         unsigned char* ucOutBuf -       pointer to output buffer
02578                                         int iOutBufLen                  -       size of output buffer
02579 
02580   Return Value  :       int     -       Number of bytes in ucOutBuf (>0) or error (<0)
02581 ***************************************************************************/
02582 _FEDM_ISC_CORE_EXT_FUNCT int FEDM_ConvHexUCharToBcdChar(unsigned char* ucInBuf, int iInBufLen, unsigned char* ucOutBuf, int iOutBufLen)
02583 {
02584         int             iBcdCnt;
02585         int             iByteCnt = 0;
02586         
02587         FEDM_CHK3(ucInBuf);
02588         FEDM_CHK3(ucOutBuf);
02589 
02590         if(iInBufLen % 2)
02591         {
02592                 return FEDM_ERROR_PARAMETER;
02593         }
02594 
02595         if(iOutBufLen < (iInBufLen>>1) )
02596         {
02597                 return FEDM_ERROR_BUFFER_LENGTH;
02598         }
02599 
02600         for( iBcdCnt=0; iBcdCnt<iInBufLen; iBcdCnt+=2 )
02601         {
02602                 ucOutBuf[iByteCnt  ]  = (unsigned char)( ( (ucInBuf[iBcdCnt  ]-0x30) & 0x0F ) << 4 );
02603                 ucOutBuf[iByteCnt++] += (unsigned char)(   (ucInBuf[iBcdCnt+1]-0x30) & 0x0F );
02604         }
02605 
02606         return iByteCnt;
02607 }
02608 
02609 /***************************************************************************
02610   Begin         :       20.11.2000 / M. Hultsch
02611   Version       :       01.00.01 / 06.12.2000 / M. Hultsch
02612 
02613   Function              :       test of hex char inside sIn
02614 
02615   Parameters    :       CString sIn     - input string
02616 
02617   Return Value  :       true            - if all char inside sIn are hex chars
02618                                         false           - if one char inside sIn is not a hex char
02619 
02620 ***************************************************************************/
02621 #if defined(_FEDM_MFC_SUPPORT) //|| defined(__BORLANDC__)
02622 _FEDM_ISC_CORE_EXT_FUNCT bool FEDM_IsHex(CString sIn)
02623 {
02624 #ifdef _FEDM_MFC_SUPPORT                // Microsoft Compiler
02625         for( int iCnt=0; iCnt<sIn.GetLength(); iCnt++)
02626 #endif
02627 #ifdef __BORLANDC__     // Borland C++ Builder: AnsiStrings index starts with 1 !!
02628         for( int iCnt=1; iCnt<=sIn.Length(); iCnt++)
02629 #endif
02630         {
02631                 if(! ((sIn[iCnt] >= '0' && sIn[iCnt] <= '9') ||
02632                           (sIn[iCnt] >= 'a' && sIn[iCnt] <= 'f') ||
02633                           (sIn[iCnt] >= 'A' && sIn[iCnt] <= 'F') )
02634                   )
02635                 {
02636                         return false;
02637                 }
02638         }
02639 
02640         return true;
02641 }
02642 #endif
02643 
02644 /***************************************************************************
02645   Begin         :       30.04.2002 / M. Hultsch
02646   Version       :       01.05.00 / 30.04.2002 / M. Hultsch
02647 
02648   Function              :       test of hex char inside sIn
02649 
02650   Parameters    :       string sIn      - input string
02651 
02652   Return Value  :       true            - if all char inside sIn are hex chars
02653                                         false           - if one char inside sIn is not a hex char
02654 
02655 ***************************************************************************/
02656 _FEDM_ISC_CORE_EXT_FUNCT bool FEDM_IsHex(string sIn)
02657 {
02658         for( unsigned int iCnt=0; iCnt<sIn.length(); iCnt++)
02659         {
02660                 if(! ((sIn[iCnt] >= '0' && sIn[iCnt] <= '9') ||
02661                           (sIn[iCnt] >= 'a' && sIn[iCnt] <= 'f') ||
02662                           (sIn[iCnt] >= 'A' && sIn[iCnt] <= 'F') )
02663                   )
02664                 {
02665                         return false;
02666                 }
02667         }
02668 
02669         return true;
02670 }
02671 
02672 
02673 /*******************************************************************************
02674   Function              :       GetUTCTime
02675 
02676   Begin                 :       15.02.2008 / M. Hultsch
02677 
02678   Version               :       03.00.05 / 11.03.2009 / M. Hultsch
02679 
02680   Description   :       get the utc timestamp in microseconds
02681                                         Windows CE: timestamp in seconds
02682 
02683   Parameters    :       -
02684 
02685   Return value  :       (__int64)utc timestamp in microseconds
02686 *******************************************************************************/
02687 #if defined(_FEDM_WINDOWS) && !defined(_WIN32_WCE) && !defined(__BORLANDC__)
02688 _FEDM_ISC_CORE_EXT_FUNCT __int64 FEDM_GetUTCTimestamp()
02689 {
02690         _timeb ts;
02691 #if _MSC_VER == 1200
02692         _ftime(&ts);
02693 #else
02694         _ftime_s(&ts);
02695 #endif
02696         return ((__int64)ts.time * 1000000) + ((__int64)ts.millitm * 1000);
02697 }
02698 #endif
02699 
02700 #if defined(_FEDM_WINDOWS) && !defined(_WIN32_WCE) && defined(__BORLANDC__)
02701 _FEDM_ISC_CORE_EXT_FUNCT __int64 FEDM_GetUTCTimestamp()
02702 {
02703         return 0;
02704 }
02705 #endif
02706 
02707 #if defined(_FEDM_WINDOWS) && defined(_WIN32_WCE)
02708 _FEDM_ISC_CORE_EXT_FUNCT __int64 FEDM_GetUTCTimestamp()
02709 {
02710 #ifdef _FEDM_EVC4
02711         SYSTEMTIME systime;
02712         FILETIME filetime;
02713         ULARGE_INTEGER ulTime;
02714         ::GetSystemTime(&systime);
02715         SystemTimeToFileTime(&systime, &filetime);
02716         ulTime = *((ULARGE_INTEGER*)&filetime);
02717         return (__int64)ulTime.QuadPart;
02718 #else
02719         __int64 ltime;
02720         _time64( &ltime );
02721         return ltime;
02722 #endif
02723 }
02724 #endif
02725 
02726 #ifdef _FEDM_LINUX
02727 _FEDM_ISC_CORE_EXT_FUNCT __int64 FEDM_GetUTCTimestamp()
02728 {
02729         struct timeval    ts;
02730         gettimeofday(&ts, NULL);
02731         return ((__int64)ts.tv_sec)*1000000LL + (__int64)ts.tv_usec;
02732 }
02733 #endif
02734 


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