fiatlux/firmware/messages.h

87 lines
2.1 KiB
C
Raw Normal View History

2022-09-13 03:29:26 +00:00
//
// Created by jedi on 13.09.22.
//
namespace fiatlux {
namespace messages {
enum id : uint8_t {
NONE = 0,
RESTART,
CLEAR_CONFIG,
FIRMWARE_FRAME,
FIRMWARE_CHECK,
VOLTAGE_INFO,
SYSTEM_INFO,
2023-01-19 17:11:13 +00:00
LIGHTS,
2022-09-13 03:29:26 +00:00
count
};
2023-01-19 17:11:13 +00:00
const char *id_to_string(id val) {
static const char *lookup[] = {
"NONE",
"RESTART",
"CLEAR_CONFIG",
"FIRMWARE_FRAME",
"FIRMWARE_CHECK",
"VOLTAGE_INFO",
"SYSTEM_INFO",
"LIGHTS",
"out of range"
2022-09-13 03:29:26 +00:00
};
if(val < id::count)
return lookup[val];
else
return lookup[id::count];
}
2023-01-19 17:11:13 +00:00
template<typename T>
2022-09-13 03:29:26 +00:00
struct frame {
id cmd;
T msg;
} __attribute__((packed));
struct fw_frame {
char t;
uint8_t reserved[3];
uint16_t seq;
uint16_t len;
uint32_t hash;
uint8_t data[];
} __attribute__((packed));
struct fw_check {
char t;
uint8_t reserved[3];
uint32_t len;
uint32_t hash;
} __attribute__((packed));
struct system_info {
2023-01-19 06:07:24 +00:00
uint32_t walltime;
uint32_t uptime;
int32_t heap;
2022-09-13 03:29:26 +00:00
uint32_t chipid;
uint32_t flashid;
uint32_t flashsize;
2023-01-19 17:11:13 +00:00
uint16_t version;
uint16_t peripheral_version;
2022-09-13 03:29:26 +00:00
/*
" \"hostname\" : \"%s\""
"}"
*/
} __attribute__((packed));
struct response {
id cmd;
uint8_t ret;
uint16_t val;
} __attribute__((packed));
2023-01-19 17:11:13 +00:00
struct lights {
uint32_t top_color;
uint32_t bottom_color;
uint16_t white_brightness;
} __attribute__((packed));
2022-09-13 03:29:26 +00:00
}
}