Hello,
I was unable to figure out how to transfer a hex value in string to char array.
I have;
String l = "731c8080"; // these value changes frequently in the loop
String m = "58ed12a5" / /these value changes frequently in the loop
char buf[8];
Now I need like this:
buf[0] = 0x73; // buf[ ] should be updated frequently based on the "l" and "m" values
buf[1] = 0x1c;
buf[2] = 0x80;
buf[3] = 0x80;
buf[4] = 0x58;
buf[5] = 0xed;
buf[6] = 0x12;
buf[7] = 0xa5;
Thanks for your reply!
Now how can I call the values of (byte)buf[i], HEX and use for further processing.
like
char hexcon[8];
hexcon[0]= (byte)buf[0], HEX; // So the value of hexcon[0] = 73;
hexcon[1]= (byte)buf[1], HEX; // So the value of hexcon[1] = 1c;
hexcon[2]= (byte)buf[2], HEX; // So the value of hexcon[0] = 80;
hexcon[3]= (byte)buf[3], HEX; // So the value of hexcon[0] = 80;
hexcon[4]= (byte)buf[4], HEX; // So the value of hexcon[0] = 58;
hexcon[5]= (byte)buf[5], HEX; // So the value of hexcon[0] = ed;
hexcon[6]= (byte)buf[6], HEX; // So the value of hexcon[0] = 12;
hexcon[7]= (byte)buf[7], HEX; // So the value of hexcon[0] = a5;
I would ask how the hex digits get into these strings/Strings to begin with? If they are read from some stream (eg. Serial), then the easiest solution could be to read them directly into your buf[8] array from the stream.
then after applying some conversion formula I will get 10 digit long value. "long lati = 1023456789;"
Now the long values needs to be converted into HEX value (in string format) . "HEX value = 3D00B615"
HEX value needs to be included into an char/data array to transfer as CAN messages.
buf[0] = 73; // buf should be updated frequently based on the "l" and "m" values
buf[1] = 1c;
buf[2] = 80;
buf[3] = 80;
buf[4] = 58;
buf[5] = ed;
buf[6] = 12;
buf[7] = a5;
can message will be sent with following line
CAN.sendMessage(0x18FFE61C,1,8,buf);