diff --git a/lib/obus_can.cpp b/lib/obus_can.cpp index b1ff16b..5eae8c1 100644 --- a/lib/obus_can.cpp +++ b/lib/obus_can.cpp @@ -51,7 +51,7 @@ uint8_t obuscan_payload_type(uint8_t module_type, uint8_t msg_type) { } else { switch (msg_type) { case OBUS_MSGTYPE_M_STRIKE: - return OBUS_PAYLDTYPE_IDEMPOTENCY_ID; + return OBUS_PAYLDTYPE_COUNT; case OBUS_MSGTYPE_M_HELLO: case OBUS_MSGTYPE_M_SOLVED: @@ -119,8 +119,8 @@ bool obuscan_receive(struct obus_message *msg) { msg->gamestatus.max_strikes = receive_frame.data[6]; break; - case OBUS_PAYLDTYPE_IDEMPOTENCY_ID: - msg->idempotency.id = receive_frame.data[1]; + case OBUS_PAYLDTYPE_COUNT: + msg->count = receive_frame.data[1]; break; default: @@ -163,6 +163,11 @@ void obuscan_send(struct obus_message *msg) { length = 7; break; + case OBUS_PAYLDTYPE_COUNT: + send_frame.data[1] = msg->count; + length = 2; + break; + default: Serial.println(F("Unknown payload type")); return; diff --git a/lib/obus_can.h b/lib/obus_can.h index 22c4672..9ed98d5 100644 --- a/lib/obus_can.h +++ b/lib/obus_can.h @@ -26,9 +26,9 @@ #define OBUS_MSGTYPE_M_STRIKE 1 #define OBUS_MSGTYPE_M_SOLVED 2 -#define OBUS_PAYLDTYPE_EMPTY 0 -#define OBUS_PAYLDTYPE_GAMESTATUS 1 -#define OBUS_PAYLDTYPE_IDEMPOTENCY_ID 2 +#define OBUS_PAYLDTYPE_EMPTY 0 +#define OBUS_PAYLDTYPE_GAMESTATUS 1 +#define OBUS_PAYLDTYPE_COUNT 2 struct module { uint8_t type; @@ -41,9 +41,6 @@ struct payld_gamestatus { uint8_t strikes; uint8_t max_strikes; }; -struct payld_idempotency { - uint8_t id; -}; struct obus_message { @@ -53,7 +50,7 @@ struct obus_message { union { struct payld_empty empty; struct payld_gamestatus gamestatus; - struct payld_idempotency idempotency; + uint8_t count; }; }; @@ -210,9 +207,10 @@ inline void obuscan_send_m_hello(struct module from) { /** * Send a module "strike" OBUS message */ -inline void obuscan_send_m_strike(struct module from) { +inline void obuscan_send_m_strike(struct module from, uint8_t count) { assert(from.type != OBUS_TYPE_CONTROLLER); struct obus_message msg = _obuscan_msg(from, false, OBUS_MSGTYPE_M_STRIKE); + msg.count = count; obuscan_send(&msg); }