Arduino code and xml frame

I need to send more values data on a frame "vehicle speed and fuel level, i used code from example , since it send only 4 value in the first frame i tried to add one value in the code memcpy(); , how to edit the code to send more value in the frame

byte buf[8];

memcpy(buf, &rpm, 2);
memcpy(buf + 2, &kpa, 2);
memcpy(buf + 4, &clt, 2);
memcpy(buf + 6, &tps, 2);
i

A frame is 8 bytes so you either need to add another frame to accommodate the values, or alternatively if the values you have are only 8 bit then alter the above.

Below is sending two frames

void SendCANFramesToSerial() {
byte buf[8];

// build & send CAN frames to RealDash.
// a CAN frame payload is always 8 bytes containing data in a manner
// described by the RealDash custom channel description XML file
// all multibyte values are handled as little endian by default.
// endianess of the values can be specified in XML file if it is required to use big endian values

// build 1st CAN frame, ESP32 digital pins and analog values
//MyDebug();
memcpy(buf + 0, &digitalPins, 2);
memcpy(buf + 2, &analogPin, 2);
memcpy(buf + 4, &empty, 2);
memcpy(buf + 6, &empty, 2);

// write first CAN frame to serial
SendCANFrameToSerial(1900, buf);

// build 2nd CAN frame, values from BMP280
memcpy(buf + 0, &bar, 2);
memcpy(buf + 2, &brt, 2);
memcpy(buf + 4, &alt, 2);
memcpy(buf + 6, &amb, 2);

// write 2nd CAN frame to serial
SendCANFrameToSerial(1901, buf);
}

thank you at all , one more help
for warning indicator light like air bag warning , what value we must send for on off

If you transfer this in dual byte format you would need to use unit=β€œbit” in the corresponding xml file to extract this digital value.

In my example I am transferring four digital inputs as &digitalPins corresponding to different inputs on the ESP32 I am using, then using xml to separate them again on the android device.

Hope this makes sense

In arduino code , what value we send, 1,or on and show me xml partion please

You need to send digital 1, or 0

below xml corresponds to the first bit of &digitalPins


value targetId=β€œ160” units=β€œbit” startbit=β€œ0” bitcount=β€œ1”>

i tried to activate the ABS light from arduino code , but not working , here is the PART OF code :

unsigned int ABS = 1; // i put 1 to activate

memcpy(buf, &ABS, 2);

SendCANFrameToSerial(1902, buf);

here the xml part:

you need to remove < from xml to attach

this is the xml part

value targetId=β€œ160” units=β€œbit” startbit=β€œ0” bitcount=β€œ1”>

For ABS warning change the 160 to 273, also check endianess=β€œlittle” in the frame header

1 Like