From c4c5e394af036710c94586de9e2be9aa868daf0d Mon Sep 17 00:00:00 2001 From: PgSocks Date: Mon, 13 Feb 2023 16:34:10 -0600 Subject: [PATCH] Add function to get size of message by command ID --- include/message.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/message.h b/include/message.h index 615dfae..621cd02 100644 --- a/include/message.h +++ b/include/message.h @@ -259,3 +259,27 @@ enum MESSAGEERR { enum MESSAGEERR message_validate(const union Message* message); + +static +inline +size_t +message_length(uint16_t cmd) { + switch(cmd) { + case SET_SDK_CONNECTION_CMD: + return sizeof(struct SetSdkConnectionReq); + case SDK_HEARTBEAT_CMD: + return sizeof(struct SdkHeartbeatReq); + case SET_SDK_MODE_CMD: + return sizeof(struct SetSdkModeReq); + case SET_SYSTEM_LED_CMD: + return sizeof(struct SetSystemLedReq); + case SET_ROBOT_MODE_CMD: + return sizeof(struct SetRobotModeReq); + case SUBNODE_RESET_CMD: + return sizeof(struct SubNodeResetReq); + case SUBSCRIBE_ADD_NODE_CMD: + return sizeof(struct SubscribeAddNodeReq); + default: + return 0; + } +}