Skip to content

Commit 24de8e6

Browse files
andreagilardonipennam
authored andcommitted
Extend Commands.h to include new Command protocol model
1 parent f13300a commit 24de8e6

File tree

1 file changed

+101
-2
lines changed

1 file changed

+101
-2
lines changed

Diff for: src/message/Commands.h

+101-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,83 @@ struct Command {
4867
};
4968

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

0 commit comments

Comments
 (0)