diff options
| author | lonkaars <loek@pipeframe.xyz> | 2022-05-26 12:14:04 +0200 | 
|---|---|---|
| committer | lonkaars <loek@pipeframe.xyz> | 2022-05-26 12:14:04 +0200 | 
| commit | 54b69efe150e1a102faafb4e214159c92abbb841 (patch) | |
| tree | 6c1cd23f61cbc3012078453f2f7c507704c39a01 /shared/protocol.h | |
| parent | e63abbdff3408c17b45c9032e7f7ba0199b43bd0 (diff) | |
clean up ugly switch case in favor of array lookup
Diffstat (limited to 'shared/protocol.h')
| -rw-r--r-- | shared/protocol.h | 6 | 
1 files changed, 6 insertions, 0 deletions
| diff --git a/shared/protocol.h b/shared/protocol.h index adec614..5bdfcbe 100644 --- a/shared/protocol.h +++ b/shared/protocol.h @@ -15,6 +15,7 @@  #define W2_CMD_CODE_MASK (~1)  #define W2_CMD_DIRECTION_MASK (1) +#define W2_CMD_COUNT 28  enum w2_e_scmds {  	/** ping command */  	W2_CMD_PING = 0x00, @@ -162,6 +163,11 @@ typedef struct {  #pragma pack(pop) +/** stores message handlers in array with opcode as index */ +extern void (*g_w2_cmd_handlers[W2_CMD_COUNT])(w2_s_bin *); +/** fills g_w2_cmd_handlers with functions */ +void w2_cmd_setup_handlers(); +  /** global handler for complete messages */  void w2_cmd_handler(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t length);  /** calculate message length */ |