How do I do this?
Here is a function. I need to modify this to put the data into 4 char bytes, an upper set an a lower set. For example, I want the value of data if it is integer 31 to go into buf2 as four vaules on the end of prefix before the \3. See below.
Say the prefix is "123" and data is between -31 and +31.
setvalue (char *prefix, int data)
{
int Result;
strcpy (buf2, prefix);
sprintf(buf2 + strlen(buf2), "%2x\3", data);
Result = sendData (buf2, strlen(buf2));
return Result;
}
I want buf2 to contain 123FFE1\3 or 123001F\3
The -31 becomes FF E1 and + 31 becomes 00 1F. Basically I need an interger to ASCII Character Hex routine. It takes the integer an converts it to Character Hex values. For example, 31 becomes 001F and -31 becomes FFE1.The values 0-9 get converted to 30 to 39 Hex and A-F get converted to 41-46 Hex.
I think I want something like:
dataupper
if "-" then FF
else
00
datalower
itoa (31)
would convert it to 1F
sprintf (buf2 + strlen(buf2), "%2x%3x", dataupper, datalower);
Result = sendData (buf2, strlen(buf2));
I would like it if someone can give me a complete function that would result in sendData sending a buf2 containing the prefix, the 4 bytes of the converted integer and the \3 (ETX) on the end. Any questions let me know. Otherwise thanks.
Thanks for the Help.
Doug Cabell
Alternate Eye, LLC
Here is a function. I need to modify this to put the data into 4 char bytes, an upper set an a lower set. For example, I want the value of data if it is integer 31 to go into buf2 as four vaules on the end of prefix before the \3. See below.
Say the prefix is "123" and data is between -31 and +31.
setvalue (char *prefix, int data)
{
int Result;
strcpy (buf2, prefix);
sprintf(buf2 + strlen(buf2), "%2x\3", data);
Result = sendData (buf2, strlen(buf2));
return Result;
}
I want buf2 to contain 123FFE1\3 or 123001F\3
The -31 becomes FF E1 and + 31 becomes 00 1F. Basically I need an interger to ASCII Character Hex routine. It takes the integer an converts it to Character Hex values. For example, 31 becomes 001F and -31 becomes FFE1.The values 0-9 get converted to 30 to 39 Hex and A-F get converted to 41-46 Hex.
I think I want something like:
dataupper
if "-" then FF
else
00
datalower
itoa (31)
would convert it to 1F
sprintf (buf2 + strlen(buf2), "%2x%3x", dataupper, datalower);
Result = sendData (buf2, strlen(buf2));
I would like it if someone can give me a complete function that would result in sendData sending a buf2 containing the prefix, the 4 bytes of the converted integer and the \3 (ETX) on the end. Any questions let me know. Otherwise thanks.
Thanks for the Help.
Doug Cabell
Alternate Eye, LLC