Cleanup code

This commit is contained in:
redfast00 2020-09-09 20:41:48 +02:00
parent 4bcb6e8395
commit 8d3e243718
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
2 changed files with 8 additions and 9 deletions

View file

@ -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) { 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) { switch (msg_type) {
case OBUS_MSGTYPE_C_ACK: case OBUS_MSGTYPE_C_ACK:
case OBUS_MSGTYPE_C_HELLO: 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; return false;
break; break;
} }
} } else if (module_type == OBUS_TYPE_INFO) {
else if (module_type == OBUS_TYPE_INFO) {
// Info modules can only send 7 bytes of data // Info modules can only send 7 bytes of data
return OBUS_PAYLDTYPE_INFO; return OBUS_PAYLDTYPE_INFO;
// Module messages // Module messages
@ -139,7 +138,7 @@ bool receive(struct message *msg) {
Serial.println(F("W Received illegal count msg: payload <8")); Serial.println(F("W Received illegal count msg: payload <8"));
return false; 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; break;
default: default:
Serial.println(F("W Couldn't determine payload type")); Serial.println(F("W Couldn't determine payload type"));
@ -191,7 +190,7 @@ void send(struct message *msg) {
break; break;
case OBUS_PAYLDTYPE_INFO: 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; length = 8;
break; break;
default: default:

View file

@ -59,7 +59,7 @@ struct message {
struct payld_empty empty; struct payld_empty empty;
struct payld_gamestatus gamestatus; struct payld_gamestatus gamestatus;
uint8_t count; 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); send(&msg);
} }
inline void send_i_infomessage(struct module from, uint8_t infomessage[7]) { inline void send_i_infomessage(struct module from, uint8_t infomessage[OBUS_MSG_LENGTH - 1]) {
assert(from.type == OBUS_TYPE_INFO && from.id != 0); assert(from.type == OBUS_TYPE_INFO && from.id != OBUS_CONTROLLER_ID);
struct message msg = _msg(from, false, OBUS_MSGTYPE_I_INFOMESSAGE); 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); send(&msg);
} }