/** * Send a message on the CAN bus through the CAN driver in FRC_NetworkCommunication * * Trusted messages require a 2-byte token at the beginning of the data payload. * If the message being sent is trusted, make space for the token. * * @param messageID The messageID to be used on the CAN bus * @param data The up to 8 bytes of data to be sent with the message * @param dataSize Specify how much of the data in "data" to send * @return Status of send call */ int32_t CANJaguar::sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize) { static constexpr uint32_t kTrustedMessages[] = { LM_API_VOLT_T_EN, LM_API_VOLT_T_SET, LM_API_SPD_T_EN, LM_API_SPD_T_SET, LM_API_VCOMP_T_EN, LM_API_VCOMP_T_SET, LM_API_POS_T_EN, LM_API_POS_T_SET, LM_API_ICTRL_T_EN, LM_API_ICTRL_T_SET}; int32_t status=0; for (uint8_t i=0; i<(sizeof(kTrustedMessages)/sizeof(kTrustedMessages[0])); i++) { if ((kFullMessageIDMask & messageID) == kTrustedMessages[i]) { uint8_t dataBuffer[8]; dataBuffer[0] = 0; dataBuffer[1] = 0; // Make sure the data will still fit after adjusting for the token. if (dataSize > 6) { // TODO: I would rather this not have to set the global error wpi_setGlobalWPIErrorWithContext(ParameterOutOfRange, "dataSize > 6"); return 0; } for (uint8_t j=0; j < dataSize; j++) { dataBuffer[j + 2] = data[j]; } FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, dataBuffer, dataSize + 2, &status); return status; } } FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, data, dataSize, &status); return status; }
/** * Send a message on the CAN bus through the CAN driver in FRC_NetworkCommunication * * Trusted messages require a 2-byte token at the beginning of the data payload. * If the message being sent is trusted, make space for the token. * * @param messageID The messageID to be used on the CAN bus * @param data The up to 8 bytes of data to be sent with the message * @param dataSize Specify how much of the data in "data" to send */ INT32 CANJaguar::sendMessage(UINT32 messageID, const UINT8 *data, UINT8 dataSize) { static const UINT32 kTrustedMessages[] = { LM_API_VOLT_T_EN, LM_API_VOLT_T_SET, LM_API_SPD_T_EN, LM_API_SPD_T_SET, LM_API_POS_T_EN, LM_API_POS_T_SET, LM_API_ICTRL_T_EN, LM_API_ICTRL_T_SET}; INT32 status=0; for (UINT8 i=0; i<(sizeof(kTrustedMessages)/sizeof(kTrustedMessages[0])); i++) { if ((kFullMessageIDMask & messageID) == kTrustedMessages[i]) { UINT8 dataBuffer[8]; dataBuffer[0] = 0; dataBuffer[1] = 0; // Make sure the data will still fit after adjusting for the token. if (dataSize > 6) { // TODO: Error return 0; } for (UINT8 j=0; j < dataSize; j++) { dataBuffer[j + 2] = data[j]; } FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, dataBuffer, dataSize + 2, &status); return status; } } FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, data, dataSize, &status); return status; }