Skip to content

Instantly share code, notes, and snippets.

@peplin peplin/config.json
Created Jun 4, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.