//DBC文件,创建一个Message-TestA,创建一个signal-TestSignal,将TestSignal添加到TestA下;
variables
{
message TestA myTest; //实例化message TestA;
}
on key '1'
{
myTest.TestSignal = 1414742342;//"FAST"转成16进制,转成10进制;
output(myTest);
}
on key '2'
{
myTest.TestSignal = 0x54534146;//"FAST"转成16进制;
output(myTest);
}
on key '3'
{
//不知道ASCII字符对应的16进制或者10进制数值时,输入字符串调用函数直接转成16进制;
char inChargerNumber[5]="FAST";//此为需要输入的字符串
byte ouChargerNumber[5];
long ChargerNum;
int i;
Fun_ConvertStrToASCIIArr(inChargerNumber,strlen(inChargerNumber),ouChargerNumber);
for(i = 0;i < 4;i++)
{
ChargerNum = (ouChargerNumber[0]<<0) + (ouChargerNumber[1]<<8) + (ouChargerNumber[2]<<16) + (ouChargerNumber[3]<<24);
}
myTest.TestSignal = ChargerNum;//TestSignal赋值
output(myTest);//发送改消息
}
byte Fun_ConvertStrToASCIIArr(char inStr[],int numChars, byte outArray[])
{
//Variables
int i; //General counter
byte retVal; //return value
char tmpErrStr[256]; //temp string
retVal = 1;//gcOk;
if(elcount(outArray) < numChars)
{
retVal = 0;//gcNok;
snprintf(tmpErrStr, elcount (tmpErrStr), "GBF_ConvertStrToASCIIArr: ERROR: Output Array not large enough for conversion!");
write(tmpErrStr);
}
else
{
for (i=0;i<numChars;i++)
{
outArray[i] = (byte) inStr[i];
}
}
return retVal;
}
字符串转为ASCII16进制
最新推荐文章于 2023-08-28 20:08:24 发布