fiatlux/firmware/messages.h

76 lines
1.7 KiB
C
Raw Permalink 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,
count
};
const char* id_to_string(id val){
static const char* lookup[] = {
"NONE",
"RESTART",
"CLEAR_CONFIG",
"FIRMWARE_FRAME",
"FIRMWARE_CHECK",
"VOLTAGE_INFO",
"SYSTEM_INFO",
"out of range"
};
if(val < id::count)
return lookup[val];
else
return lookup[id::count];
}
template <typename T>
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 {
unsigned walltime;
unsigned uptime;
int heap;
uint32_t chipid;
uint32_t flashid;
uint32_t flashsize;
/*
" \"hostname\" : \"%s\""
"}"
*/
} __attribute__((packed));
struct response {
id cmd;
uint8_t ret;
uint16_t val;
} __attribute__((packed));
}
}