Created
June 4, 2014 02:33
-
-
Save peplin/b348c9776a690435cc4a to your computer and use it in GitHub Desktop.
OpenXC custom command to send CAN message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "buses": { | |
"hs": { | |
"controller": 1, | |
"speed": 500000, | |
"raw_writable": true | |
} | |
}, | |
"commands": [ | |
{"name": "my_custom_command", | |
"handler": "sendMyCanMessage" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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