Skip to content

Commit

Permalink
Changed processMSreq to handle msgType other than 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ads103 authored Dec 26, 2021
1 parent a3d6e2e commit 1650656
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions MegaCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

MegaCAN::MegaCAN() {}

void MegaCAN::processMSreq(uint32_t msgCore, const uint8_t msgData[3], MegaCAN_message_t &msg) {
void MegaCAN::processMSreq(uint32_t msgCore, const uint8_t msgData[8], MegaCAN_message_t &msg) {
// Process message core
msg.core.toTable = (msgCore & ~(0b11111111111111111111111111111011)) << 2; //set bit 4 of toTable to bit 2 of msgCore
msg.core.toTable |= (msgCore & ~(0b11111111111111111111111110000111)) >> 3; //set bits 3-0 of toTable to bits 6-3 of msgCore
msg.core.toID = (msgCore & ~(0b11111111111111111111100001111111)) >> 7; //set ToID to bits 10-7 of msgCore
msg.core.fromID = (msgCore & ~(0b11111111111111111000011111111111)) >> 11; //set FromID to bits 14-11 of msgCore
msg.core.msgType = (msgCore & ~(0b11111111111111000111111111111111)) >> 15; //set msgType to bits 17-15 of msgCore
msg.core.toOffset = (msgCore & ~(0b11100000000000111111111111111111)) >> 18; //set toOffset to bits 28-18 of msgCore

msg.rawData = msgData; // Don't clobber data for msgType != 1

// Process message data
// Process message data - Only valid if msgType is 1.
msg.data.request.varBlk = msgData[0];
msg.data.request.varOffset = msgData[1];
msg.data.request.varOffset = (msg.data.request.varOffset << 3) | (msgData[2] >> 5);
Expand Down

0 comments on commit 1650656

Please sign in to comment.