From 8d3e24371833bde60f08ed988f0a91c5ba2095b1 Mon Sep 17 00:00:00 2001 From: redfast00 Date: Wed, 9 Sep 2020 20:41:48 +0200 Subject: [PATCH] Cleanup code --- lib/obus_can.cpp | 9 ++++----- lib/obus_can.h | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/obus_can.cpp b/lib/obus_can.cpp index 066aff5..a5828e0 100644 --- a/lib/obus_can.cpp +++ b/lib/obus_can.cpp @@ -33,7 +33,7 @@ void _decode_can_id(uint16_t can_id, struct module *mod, bool *priority) { } uint8_t payload_type(uint8_t module_type, uint8_t module_id, uint8_t msg_type) { - if (module_type == OBUS_TYPE_CONTROLLER && module_type == 0) { + if (module_type == OBUS_TYPE_CONTROLLER && module_id == OBUS_CONTROLLER_ID) { switch (msg_type) { case OBUS_MSGTYPE_C_ACK: case OBUS_MSGTYPE_C_HELLO: @@ -50,8 +50,7 @@ uint8_t payload_type(uint8_t module_type, uint8_t module_id, uint8_t msg_type) { return false; break; } - } - else if (module_type == OBUS_TYPE_INFO) { + } else if (module_type == OBUS_TYPE_INFO) { // Info modules can only send 7 bytes of data return OBUS_PAYLDTYPE_INFO; // Module messages @@ -139,7 +138,7 @@ bool receive(struct message *msg) { Serial.println(F("W Received illegal count msg: payload <8")); return false; } - memcpy(msg->infomessage, &receive_frame.data[1], OBUS_MSG_LENGTH - 1); + memcpy(msg->infomessage, &(receive_frame.data[1]), OBUS_MSG_LENGTH - 1); break; default: Serial.println(F("W Couldn't determine payload type")); @@ -191,7 +190,7 @@ void send(struct message *msg) { break; case OBUS_PAYLDTYPE_INFO: - memcpy(&send_frame.data[1], msg->infomessage, OBUS_MSG_LENGTH - 1); + memcpy(&(send_frame.data[1]), msg->infomessage, OBUS_MSG_LENGTH - 1); length = 8; break; default: diff --git a/lib/obus_can.h b/lib/obus_can.h index 4c05639..ecdb0d3 100644 --- a/lib/obus_can.h +++ b/lib/obus_can.h @@ -59,7 +59,7 @@ struct message { struct payld_empty empty; struct payld_gamestatus gamestatus; uint8_t count; - uint8_t infomessage; + uint8_t infomessage[OBUS_MSG_LENGTH - 1]; }; }; @@ -234,10 +234,10 @@ inline void send_m_solved(struct module from) { send(&msg); } -inline void send_i_infomessage(struct module from, uint8_t infomessage[7]) { - assert(from.type == OBUS_TYPE_INFO && from.id != 0); +inline void send_i_infomessage(struct module from, uint8_t infomessage[OBUS_MSG_LENGTH - 1]) { + assert(from.type == OBUS_TYPE_INFO && from.id != OBUS_CONTROLLER_ID); struct message msg = _msg(from, false, OBUS_MSGTYPE_I_INFOMESSAGE); - memcpy(infomessage, msg.infomessage, 7); + memcpy(infomessage, msg.infomessage, OBUS_MSG_LENGTH - 1); send(&msg); }