This commit is contained in:
TAO Cheng
2013-07-22 14:34:50 +08:00
parent 9b5c637ad4
commit 5a8e27e70d
37 changed files with 3405 additions and 1426 deletions
@@ -146,6 +146,14 @@ SSI_STATUS CProto_Util::Initialize()
return SSI_STATUS_NORMAL;
}
void CProto_Util::SetOutFile(FILE* pOutFile)
{
SSI_STATUS Status=SSI_STATUS_NORMAL;
UNREFERENCED_PARAMETER(Status);
m_pOutFile = pOutFile;
};
//******************************************************************************
SSI_STATUS CProto_Util::Terminate()
{
@@ -224,3 +232,204 @@ void CProto_Util::_clear_blanks(char *cBuff)
strcpy(cBuff, pBuff);
return;
};
//=====================================================================================
void CProto_Util::Dump_Array_Ascii(char *cBuff, char iEP, char *cResult)
{
int iLen = strlen(cBuff);
char cBytes[MAX_BUFF_SIZE];
memset(cBytes, 0, MAX_BUFF_SIZE);
if (iEP == '2') iLen = (iLen-6)/2;
for (int i=0;i<iLen;i++)
{
sscanf_s((const char *)(cBuff+i*2), "%2x", (cBytes+i));
};
fprintf(m_pOutFile, cBytes);
strcpy(cResult, cBytes);
// Build_Mitutoyo_Data_Matrix(cBytes, iEP);
return;
}
//=====================================================================================
//
//=====================================================================================
void CProto_Util::Dump_Array_LONG_MM(char *cBuff, int iLen)
{
char cLong_array[64][9];
long lLong_array[64];
double mm;
for (int i=0;i<iLen;i++)
{
memcpy(&(cLong_array[i][0]), cBuff+8*i, 8);
sscanf_s(&(cLong_array[i][0]), "%8x", &(lLong_array[i]));
mm = lLong_array[i]/(25.4*1000);
fprintf(m_pOutFile, "%6.3f ", mm );
};
return;
}
//=====================================================================================
//
//=====================================================================================
void CProto_Util::Dump_BYTES(char *cBuff, int iLen)
{
char x[MAX_BUFF_SIZE];
memset(x, 0, MAX_BUFF_SIZE);
memcpy(x, cBuff, iLen);
fprintf(m_pOutFile, "%s ", x );
return;
}
//=====================================================================================
// Dump an array of short INT
//=====================================================================================
void CProto_Util::Dump_SHORT_INT(char *cBuff)
{
char x[5];
int iShort;
memset(x, 0, 5);
x[0] = *(cBuff+2);
x[1] = *(cBuff+3);
x[2] = *(cBuff+0);
x[3] = *(cBuff+1);
iShort = HexToInt(x, 4);
fprintf(m_pOutFile, "%8i ", iShort );
return;
}
//=====================================================================================
//
//=====================================================================================
void CProto_Util::Dump_Array_BYTE(char *cBuff)
{
char x[3];
memset(x, 0, sizeof(x));
memcpy(x, cBuff, 2);
fprintf(m_pOutFile, "%s ", x );
return;
}
//=====================================================================================
void CProto_Util::Dump_Array_UINT_TO_INCH(char *cBuff, int iLen)
{
char cLong_array[64][7];
long lLong_array[64];
for (int i=0;i<iLen;i++)
{
memcpy(&(cLong_array[i][0]), cBuff+4*i, 4);
sscanf_s(&(cLong_array[i][0]), "%4x", &(lLong_array[i]));
fprintf(m_pOutFile, "%06.6f ", lLong_array[i]/(25.4 * 1000.0) );
};
return;
};
//=====================================================================================
//
//=====================================================================================
void CProto_Util::Dump_Array_UINT(char *cBuff, int iLen)
{
char cLong_array[64][7];
long lLong_array[64];
for (int i=0;i<iLen;i++)
{
memcpy(&(cLong_array[i][0]), cBuff+4*i, 4);
sscanf_s(&(cLong_array[i][0]), "%4x", &(lLong_array[i]));
fprintf(m_pOutFile, "%06d ", lLong_array[i] );
};
return;
}
long CProto_Util::_ascii2long_rev(char *cBuff)
{
char cLong[9];
long lLong;
cLong[7] = *cBuff;
cLong[6] = *(cBuff+1);
cLong[5] = *(cBuff+2);
cLong[4] = *(cBuff+3);
cLong[3] = *(cBuff+4);
cLong[2] = *(cBuff+5);
cLong[1] = *(cBuff+6);
cLong[0] = *(cBuff+7);
sscanf_s(cLong, "%8x", &lLong);
return lLong;
};
//=====================================================================================
//
void CProto_Util::Dump_Array_LONG_REV(char *cBuff, int iLen)
{
char cLong[9];
long lLong;
int _iLen = (iLen>64) ? 64 : iLen; // only process 64 max
for (int i=0;i<_iLen;i++)
{
cLong[6] = *(cBuff+8*i+0);
cLong[7] = *(cBuff+8*i+1);
cLong[4] = *(cBuff+8*i+2);
cLong[5] = *(cBuff+8*i+3);
cLong[2] = *(cBuff+8*i+4);
cLong[3] = *(cBuff+8*i+5);
cLong[0] = *(cBuff+8*i+6);
cLong[1] = *(cBuff+8*i+7);
sscanf_s(cLong, "%8x", &lLong);
fprintf(m_pOutFile, "%08d ", lLong);
};
return;
};
//=====================================================================================
//
//=====================================================================================
void CProto_Util::Dump_Array_LONG(char *cBuff, int iLen, int iSize)
{
char cLong_array[64][9];
long lLong_array[64];
for (int i=0;i<iLen;i++)
{
/*
if(bSo7)
memcpy(&(cLong_array[i][0]), cBuff+6*i, 6);
else
memcpy(&(cLong_array[i][0]), cBuff+8*i, 8);
*/
memcpy(&(cLong_array[i][0]), cBuff+iSize*i, iSize);
sscanf_s(&(cLong_array[i][0]), "%8x", &(lLong_array[i]));
fprintf(m_pOutFile, "%08d ", lLong_array[i] );
};
return;
}
//===================================================================
int CProto_Util::HexToInt(char *Data, int Bytes)
{
int Byte;
int HexChar, Value;
Value = 0;
for( Byte = 0; Byte < Bytes; Byte++ )
{
Value <<= 4;
HexChar = *Data++ -= '0';
if( HexChar > 32 )
HexChar -= 39;
else if( HexChar > 9 )
HexChar -= 7;
Value += HexChar;
}
return( Value );
}
//===================================================================
const char *CProto_Util::byte_to_binary ( int x )
{
static char b[9];
b[0] = '\0';
int z;
for (z = 256; z > 0; z >>= 1)
{
strcat(b, ((x & z) == z) ? "1" : "0");
}
return b;
}