Skip to content

Commit

Permalink
Extend Commands.h to include new Command protocol model
Browse files Browse the repository at this point in the history
  • Loading branch information
andreagilardoni committed Apr 18, 2024
1 parent 8a14fcb commit 3e281fa
Showing 1 changed file with 101 additions and 2 deletions.
103 changes: 101 additions & 2 deletions src/message/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@
#include <stddef.h>

/******************************************************************************
* TYPEDEF
* DEFINE
******************************************************************************/

enum CommandId : uint16_t {
#define THING_ID_SIZE 37
#define SHA256_SIZE 32
#define URL_SIZE 256
#define ID_SIZE 16
#define MAX_LIB_VERSION_SIZE 10

/******************************************************************************
TYPEDEF
******************************************************************************/

enum CommandId: uint32_t {

/* Device commands */
DeviceBeginCmdId,
Expand All @@ -39,6 +49,15 @@ enum CommandId : uint16_t {
/* Generic commands */
ResetCmdId,

/* OTA commands */
OtaBeginUpId,
OtaProgressCmdUpId,
OtaUpdateCmdDownId,

/* Timezone commands */
TimezoneCommandUpId,
TimezoneCommandDownId,

/* Unknown command id */
UnknownCmdId
};
Expand All @@ -48,3 +67,83 @@ struct Command {
};

typedef Command Message;

struct ThingGetIdCmdUp {
Command c;
struct {
char thing_id[THING_ID_SIZE];
} params;
};

struct LastValuesBeginCmd {
Command c;
};

struct OtaBeginUp {
Command c;
struct {
uint8_t sha [SHA256_SIZE];
} params;
};

struct DeviceBeginCmd {
Command c;
struct {
char lib_version[MAX_LIB_VERSION_SIZE];
} params;
};

struct OtaProgressCmdUp {
Command c;
struct {
uint8_t id[ID_SIZE];
uint8_t state;
int32_t state_data;
uint64_t time;
} params;
};

struct TimezoneCommandUp {
Command c;
};

struct OtaUpdateCmdDown {
Command c;
struct {
uint8_t id[ID_SIZE];
char url[URL_SIZE];
uint8_t initialSha256[SHA256_SIZE];
uint8_t finalSha256[SHA256_SIZE];
} params;
};

struct ThingBeginCmd {
Command c;
struct {
char thing_id[THING_ID_SIZE];
} params;
};

struct LastValuesUpdateCmd {
Command c;
struct {
uint8_t * last_values;
size_t length;
} params;
};

struct TimezoneCommandDown {
Command c;
struct {
int32_t offset;
uint32_t until;
} params;
};

union CommandDown {
struct Command c;
struct OtaUpdateCmdDown otaUpdateCmdDown;
struct ThingBeginCmd thingBeginCmd;
struct LastValuesUpdateCmd lastValuesUpdateCmd;
struct TimezoneCommandDown timezoneCommandDown;
};

0 comments on commit 3e281fa

Please sign in to comment.