00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
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
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
00087
00088
00089
00090
00091
00092
00093
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
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
00111
00112
00113
00114
00115
00116
00117
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
00127 if( (BlockSize!=4) && (BlockSize!=16) && (BlockSize!=32) )
00128 return FEDM_ERROR_BLOCK_SIZE;
00129
00130
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
00139
00140
00141
00142
00143
00144
00145
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
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
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
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
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
00216
00217
00218
00219
00220
00221
00222
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
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
00263
00264
00265
00266
00267
00268
00269
00270
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
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
00297
00298
00299
00300
00301
00302
00303
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
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
00331
00332
00333
00334
00335
00336
00337
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
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
00366
00367
00368
00369
00370
00371
00372
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
00386
00387
00388
00389
00390
00391
00392
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
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
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
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
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
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
00542 *iOut += ( (int)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00543
00544 delete[] ucTmpBuf;
00545
00546 return FEDM_OK;
00547 }
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
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
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
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
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
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
00677 *i64Out += ( (__int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00678
00679 delete[] ucTmpBuf;
00680
00681 return FEDM_OK;
00682 }
00683 #endif
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
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
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
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
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
00799 *i64Out += ( (__int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00800
00801 delete[] ucTmpBuf;
00802
00803 return FEDM_OK;
00804 }
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
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
00856 *ui64Out += ( (unsigned __int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
00857
00858 delete[] ucTmpBuf;
00859
00860 return FEDM_OK;
00861 }
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
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
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
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
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
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
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
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
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
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
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
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
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
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
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
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
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
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
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
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
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
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
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
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
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
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
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
01357 *iOut += ( (int)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
01358
01359 delete[] ucTmpBuf;
01360
01361 return FEDM_OK;
01362 }
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
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
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
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
01454 *i64Out += ( (__int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
01455
01456 delete[] ucTmpBuf;
01457
01458 return FEDM_OK;
01459 }
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
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
01513 *ui64Out += ( (unsigned __int64)(*(ucTmpBuf+(iLen-1)-iByteCnt)) << (8*iByteCnt) );
01514
01515 delete[] ucTmpBuf;
01516
01517 return FEDM_OK;
01518 }
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
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
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
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
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
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
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
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
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
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
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
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
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
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
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
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
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
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
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
01846 ucOutBuf[4-1-iCnt] = *( ((unsigned char*)&uiIn) + iCnt );
01847 }
01848
01849 return FEDM_OK;
01850 }
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
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
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
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
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
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
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
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
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
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
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
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
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
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
02142 ucOutBuf[8-1-iCnt] = *( ((unsigned char*)&i64In) + iCnt );
02143 }
02144
02145 return FEDM_OK;
02146 }
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
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
02177 ucOutBuf[8-1-iCnt] = *( ((unsigned char*)&ui64In) + iCnt );
02178 }
02179
02180 return FEDM_OK;
02181 }
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
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
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
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
02289
02290
02291
02292
02293
02294
02295
02296
02297
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
02340
02341
02342
02343
02344
02345
02346
02347
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
02388
02389
02390
02391
02392
02393
02394
02395
02396
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
02426
02427
02428
02429
02430
02431
02432
02433
02434
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
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
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
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
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
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
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
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
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
02611
02612
02613
02614
02615
02616
02617
02618
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__
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
02646
02647
02648
02649
02650
02651
02652
02653
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
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
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( <ime );
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