New payload type for gamestart
This commit is contained in:
parent
fea2d19e94
commit
1743d8d58a
3 changed files with 38 additions and 4 deletions
|
@ -51,7 +51,7 @@ Types for controller:
|
|||
- 2 game start
|
||||
[ X B B B B B B B ]
|
||||
-------- - - -
|
||||
time left ↓ ↓ #puzzle modules
|
||||
time left ↓ ↓ #puzzle modules - 1
|
||||
#strikes #max strikes
|
||||
|
||||
- 3 state (every x ms – e.g. in the middle of each second)
|
||||
|
|
|
@ -42,6 +42,8 @@ uint8_t payload_type(uint8_t module_type, uint8_t module_id, uint8_t msg_type) {
|
|||
return OBUS_PAYLDTYPE_EMPTY;
|
||||
|
||||
case OBUS_MSGTYPE_C_GAMESTART:
|
||||
return OBUS_PAYLDTYPE_GAMESTART;
|
||||
|
||||
case OBUS_MSGTYPE_C_STATE:
|
||||
case OBUS_MSGTYPE_C_SOLVED:
|
||||
case OBUS_MSGTYPE_C_TIMEOUT:
|
||||
|
@ -113,6 +115,17 @@ bool receive(struct message *msg) {
|
|||
case OBUS_PAYLDTYPE_EMPTY:
|
||||
break;
|
||||
|
||||
case OBUS_PAYLDTYPE_GAMESTART:
|
||||
if (receive_frame.can_dlc < 8) {
|
||||
Serial.println(F("W Received illegal gamestatus msg: payload <8"));
|
||||
return false;
|
||||
}
|
||||
msg->gamestart.time_left = unpack_4b_into_u32(&(receive_frame.data[1]));
|
||||
msg->gamestart.strikes = receive_frame.data[5];
|
||||
msg->gamestart.max_strikes = receive_frame.data[6];
|
||||
msg->gamestart.puzzle_modules_connected = 1 + (uint16_t) receive_frame.data[7];
|
||||
break;
|
||||
|
||||
case OBUS_PAYLDTYPE_GAMESTATUS:
|
||||
if (receive_frame.can_dlc < 8) {
|
||||
Serial.println(F("W Received illegal gamestatus msg: payload <8"));
|
||||
|
@ -183,6 +196,13 @@ void send(struct message *msg) {
|
|||
case OBUS_PAYLDTYPE_EMPTY:
|
||||
break;
|
||||
|
||||
case OBUS_PAYLDTYPE_GAMESTART:
|
||||
pack_u32_into_4b(&(send_frame.data[1]), msg->gamestatus.time_left);
|
||||
send_frame.data[5] = msg->gamestatus.strikes;
|
||||
send_frame.data[6] = msg->gamestatus.max_strikes;
|
||||
length = 7;
|
||||
break;
|
||||
|
||||
case OBUS_PAYLDTYPE_GAMESTATUS:
|
||||
pack_u32_into_4b(&(send_frame.data[1]), msg->gamestatus.time_left);
|
||||
send_frame.data[5] = msg->gamestatus.strikes;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#define OBUS_PAYLDTYPE_COUNT 2
|
||||
#define OBUS_PAYLDTYPE_INFO 3
|
||||
#define OBUS_PAYLDTYPE_MODULEADDR 4
|
||||
#define OBUS_PAYLDTYPE_GAMESTART 5
|
||||
|
||||
#define OBUS_PAYLD_INFO_MAXLEN (OBUS_MSG_LENGTH - 1)
|
||||
|
||||
|
@ -47,6 +48,12 @@ struct module {
|
|||
};
|
||||
|
||||
struct payld_empty {};
|
||||
struct payld_gamestart {
|
||||
uint32_t time_left;
|
||||
uint8_t strikes;
|
||||
uint8_t max_strikes;
|
||||
uint16_t puzzle_modules_connected; // uint16 because the range is 1 through 256 inclusive
|
||||
};
|
||||
struct payld_gamestatus {
|
||||
uint32_t time_left;
|
||||
uint8_t strikes;
|
||||
|
@ -65,6 +72,7 @@ struct message {
|
|||
uint8_t msg_type;
|
||||
union {
|
||||
struct payld_empty empty;
|
||||
struct payld_gamestart gamestart;
|
||||
struct payld_gamestatus gamestatus;
|
||||
uint8_t count;
|
||||
struct payld_infomessage infomessage;
|
||||
|
@ -165,11 +173,17 @@ inline void send_c_hello(struct module from) {
|
|||
* Send a controller "game start" OBUS message
|
||||
*/
|
||||
inline void send_c_gamestart(
|
||||
struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) {
|
||||
struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint16_t puzzle_modules_connected) {
|
||||
|
||||
assert(from.type == OBUS_TYPE_CONTROLLER);
|
||||
_send_payld_gamestatus(
|
||||
from, false, OBUS_MSGTYPE_C_GAMESTART, time_left, strikes, max_strikes, puzzle_modules_solved);
|
||||
assert(puzzle_modules_connected - 1 <= UINT8_MAX);
|
||||
|
||||
struct message msg = _msg(from, false, OBUS_MSGTYPE_C_GAMESTART);
|
||||
msg.gamestart.time_left = time_left;
|
||||
msg.gamestart.strikes = strikes;
|
||||
msg.gamestart.max_strikes = max_strikes;
|
||||
msg.gamestart.puzzle_modules_connected = (uint8_t) (puzzle_modules_connected - 1);
|
||||
send(&msg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue