Skip to content

Commit a7903d5

Browse files
Extend Commands.h to include new Command protocol model
1 parent f5336c3 commit a7903d5

File tree

1 file changed

+94
-2
lines changed

1 file changed

+94
-2
lines changed

src/message/Commands.h

+94-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@
1818
#include <stddef.h>
1919

2020
/******************************************************************************
21-
* TYPEDEF
21+
* DEFINE
2222
******************************************************************************/
2323

24-
enum CommandId : uint16_t {
24+
#define THING_ID_SIZE 37
25+
#define SHA256_SIZE 32
26+
#define URL_SIZE 256
27+
#define ID_SIZE 16
28+
#define MAX_LIB_VERSION_SIZE 10
29+
30+
/******************************************************************************
31+
TYPEDEF
32+
******************************************************************************/
33+
34+
enum CommandId: uint32_t {
2535

2636
/* Device commands */
2737
DeviceBeginCmdId,
@@ -39,6 +49,15 @@ enum CommandId : uint16_t {
3949
/* Generic commands */
4050
ResetCmdId,
4151

52+
/* OTA commands */
53+
OtaBeginUpId,
54+
OtaProgressCmdUpId,
55+
OtaUpdateCmdDownId,
56+
57+
/* Timezone commands */
58+
TimezoneCommandUpId,
59+
TimezoneCommandDownId,
60+
4261
/* Unknown command id */
4362
UnknownCmdId
4463
};
@@ -48,3 +67,76 @@ struct Command {
4867
};
4968

5069
typedef Command Message;
70+
71+
struct LastValuesBeginCmd {
72+
Command c;
73+
};
74+
75+
struct OtaBeginUp {
76+
Command c;
77+
struct {
78+
uint8_t sha [SHA256_SIZE];
79+
} params;
80+
};
81+
82+
struct DeviceBeginCmd {
83+
Command c;
84+
struct {
85+
char lib_version[MAX_LIB_VERSION_SIZE];
86+
} params;
87+
};
88+
89+
struct OtaProgressCmdUp {
90+
Command c;
91+
struct {
92+
uint8_t id[ID_SIZE];
93+
uint8_t state;
94+
int32_t state_data;
95+
uint64_t time;
96+
} params;
97+
};
98+
99+
struct TimezoneCommandUp {
100+
Command c;
101+
};
102+
103+
struct OtaUpdateCmdDown {
104+
Command c;
105+
struct {
106+
uint8_t id[ID_SIZE];
107+
char url[URL_SIZE];
108+
uint8_t initialSha256[SHA256_SIZE];
109+
uint8_t finalSha256[SHA256_SIZE];
110+
} params;
111+
};
112+
113+
struct ThingBeginCmd {
114+
Command c;
115+
struct {
116+
char thing_id[THING_ID_SIZE];
117+
} params;
118+
};
119+
120+
struct LastValuesUpdateCmd {
121+
Command c;
122+
struct {
123+
uint8_t * last_values;
124+
size_t length;
125+
} params;
126+
};
127+
128+
struct TimezoneCommandDown {
129+
Command c;
130+
struct {
131+
int32_t offset;
132+
uint32_t until;
133+
} params;
134+
};
135+
136+
union CommandDown {
137+
struct Command c;
138+
struct OtaUpdateCmdDown otaUpdateCmdDown;
139+
struct ThingBeginCmd thingBeginCmd;
140+
struct LastValuesUpdateCmd lastValuesUpdateCmd;
141+
struct TimezoneCommandDown timezoneCommandDown;
142+
};

0 commit comments

Comments
 (0)