Skip to content

Instantly share code, notes, and snippets.

@peplin
Created June 4, 2014 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peplin/b348c9776a690435cc4a to your computer and use it in GitHub Desktop.
Save peplin/b348c9776a690435cc4a to your computer and use it in GitHub Desktop.
OpenXC custom command to send CAN message
{ "buses": {
"hs": {
"controller": 1,
"speed": 500000,
"raw_writable": true
}
},
"commands": [
{"name": "my_custom_command",
"handler": "sendMyCanMessage"
}
]
}
// When our command is received over USB or Bluetooth on the VI, this function is called.
// We don't need any parameters from our command so we ignore the 'value' and 'event'
// parameters
void sendMyCanMessage(const char* name, openxc_DynamicField* value,
openxc_DynamicField* event, CanSignal* signals, int signalCount) {
// First, build a CanMessage object representing the message you want to send.
CanMessage message = {
id: 42,
format: CanMessageFormat::STANDARD, // STANDARD as opposed to an extended ID frame
data: {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xef}
};
// Next, grab a reference to the CAN bus you want the message to be sent on. We want bus 1, which we can expect to be at index 0.
CanBus bus = getCanBuses()[0];
// Finally, enqueue the message to send on the bus - it will be sent out ASAP.
can::write::enqueueMessage(&bus, &message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment