Rename idempotency to count, add to strike msg

This commit is contained in:
Midgard 2020-08-25 21:47:58 +02:00
parent 181dd87752
commit 87824c6356
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 14 additions and 11 deletions

View file

@ -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;

View file

@ -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);
}