Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion common_libraries/comms/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static size_t expected_payload_len(uint16_t type)
case MSG_TYPE__HEARTBEAT: return 4u;
case MSG_TYPE__SET_LED_PWM: return sizeof(uint8_t) + sizeof(float); // 5
case MSG_TYPE__HARDWARE_ERROR: return 2u;
case MSG_TYPE__LED_PANEL_FEEDBACK: return sizeof(uint8_t) + sizeof(float);
default: return SIZE_MAX;
}
}
Expand Down Expand Up @@ -127,6 +128,10 @@ static size_t pack_payload(const msg_t* msg, uint8_t* out, size_t cap)
PACK(out, pos, msg->payload.led_panel_cmd.panel_percent);
break;
}
case MSG_TYPE__LED_PANEL_FEEDBACK:
PACK(out, pos, msg->payload.led_panel_feedback.led_panel_index);
PACK(out, pos, msg->payload.led_panel_feedback.panel_percent);
break;
case MSG_TYPE__HARDWARE_ERROR:
PACK(out, pos, msg->payload.hardware_error.error_type);
PACK(out, pos, msg->payload.hardware_error.info);
Expand All @@ -152,6 +157,10 @@ static bool unpack_payload(msg_t* msg, const uint8_t* in, size_t len)
UNPACK(in, pos, msg->payload.led_panel_cmd.led_panel_index);
UNPACK(in, pos, msg->payload.led_panel_cmd.panel_percent);
break;
case MSG_TYPE__LED_PANEL_FEEDBACK:
UNPACK(in, pos, msg->payload.led_panel_feedback.led_panel_index);
UNPACK(in, pos, msg->payload.led_panel_feedback.panel_percent);
break;
case MSG_TYPE__HARDWARE_ERROR:
UNPACK(in, pos, msg->payload.hardware_error.error_type);
UNPACK(in, pos, msg->payload.hardware_error.info);
Expand Down Expand Up @@ -251,4 +260,4 @@ bool convert_from_raw(const uint8_t* raw_in, encoded_msg_t* out)
memset(out->payload, 0, sizeof out->payload);
memcpy(out->payload, raw_in + pos, plen);
return true;
}
}
9 changes: 8 additions & 1 deletion common_libraries/comms/comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ typedef struct {
bool is_response; // A response is the LED controller responding with the currently set value
} LedPanelCMD_t;

typedef struct {
uint8_t led_panel_index;
float panel_percent;
} LedPanelFeedback_t;

typedef struct {
uint8_t error_type;
uint8_t info;
Expand All @@ -72,6 +77,7 @@ typedef union {
Ping_t ping;
HeartBeat_t heartbeat;
LedPanelCMD_t led_panel_cmd;
LedPanelFeedback_t led_panel_feedback;
HardwareError_t hardware_error;
} Payload_t;

Expand Down Expand Up @@ -105,6 +111,7 @@ typedef enum {
MSG_TYPE__HEARTBEAT,
MSG_TYPE__SET_LED_PWM,
MSG_TYPE__HARDWARE_ERROR, // Not really used rn
MSG_TYPE__LED_PANEL_FEEDBACK,
NUM_MSG_TYPES
} msg_type_t;

Expand All @@ -130,4 +137,4 @@ bool dlc_to_len(const uint32_t dlc, uint8_t* len_out);

#ifdef __cplusplus
}
#endif
#endif
Loading