Skip to content

Commit e802b62

Browse files
committed
Fix models
1 parent 1a928a0 commit e802b62

File tree

4 files changed

+56
-43
lines changed

4 files changed

+56
-43
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ void ArduinoIoTCloudTCP::encode(){
328328
if (MessageEncoder::encode(message, data, sizeof(data), bytes_encoded) == CborNoError)
329329
if (bytes_encoded > 0)
330330
{
331-
DEBUG_INFO("Data are %s", data);
331+
DEBUG_INFO("Data size is %d", sizeof(data));
332+
for (int i = 0; i < 50; i++) {
333+
DEBUG_INFO("%02X", data[i]);
334+
}
332335
} else {
333336
DEBUG_INFO("No data sent");
334337
}

src/cbor/MessageDecoder.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ MessageDecoder::ArrayParserState MessageDecoder::handle_EnterArray(CborValue * m
121121
}
122122

123123
MessageDecoder::ArrayParserState MessageDecoder::decodeGetThingIdCommand(CborValue * param, Message * message) {
124-
GetThingIdCommand * thingCommand = (GetThingIdCommand *) message;
124+
ThingGetIdCmdDown * thingCommand = (ThingGetIdCmdDown *) message;
125125

126126
// Message is composed of a single parameter, a string (thing_id)
127127
if (copyCBORStringToArray(param, thingCommand->fields.params.thing_id, sizeof(thingCommand->fields.params.thing_id))) {
@@ -160,7 +160,7 @@ MessageDecoder::ArrayParserState MessageDecoder::decodeSetTimezoneCommand(CborVa
160160
}
161161

162162
MessageDecoder::ArrayParserState MessageDecoder::decodeSetLastValueCommand(CborValue * param, Message * message) {
163-
SetLastValueCommand * setLv = (SetLastValueCommand *) message;
163+
ThingGetLastValueCmdDown * setLv = (ThingGetLastValueCmdDown *) message;
164164

165165
// Message is composed TODO
166166

@@ -169,7 +169,7 @@ MessageDecoder::ArrayParserState MessageDecoder::decodeSetLastValueCommand(CborV
169169
}
170170

171171
MessageDecoder::ArrayParserState MessageDecoder::decodeOTAAvailableCommand(CborValue * param, Message * message) {
172-
OTAavailable * ota = (OTAavailable *) message;
172+
OtaUpdateCmdDown * ota = (OtaUpdateCmdDown *) message;
173173

174174
// Message is composed 4 parameters: id, url, initialSha, finalSha
175175
if (copyCBORStringToArray(param, ota->fields.params.id, sizeof(ota->fields.params.id))) {
@@ -216,16 +216,16 @@ MessageDecoder::ArrayParserState MessageDecoder::handle_Param(CborValue * param,
216216

217217
switch (message->id)
218218
{
219-
case CommandID::GetThingIdCommandId:
219+
case CommandID::ThingGetIdCmdDownId:
220220
return MessageDecoder::decodeGetThingIdCommand(param, message);
221221

222-
case CommandID::SetTimezoneCommandId:
222+
case CommandID::TimezoneCommandDownId:
223223
return MessageDecoder::decodeSetTimezoneCommand(param, message);
224224

225-
case CommandID::SetLastValueCommandId:
225+
case CommandID::ThingGetLastValueCmdDownId:
226226
return MessageDecoder::decodeSetLastValueCommand(param, message);
227227

228-
case CommandID::OTAavailableId:
228+
case CommandID::OtaUpdateCmdDownId:
229229
return MessageDecoder::decodeOTAAvailableCommand(param, message);
230230

231231
default:

src/cbor/MessageEncoder.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ CborError MessageEncoder::encode(Message * message, uint8_t * data, size_t const
4545

4646

4747
cbor_encoder_init(&encoder, data, size, 0);
48+
49+
4850
DEBUG_INFO("Encoder init with size %d", size);
4951
while (current_state != EncoderState::Complete) {
5052

@@ -77,7 +79,7 @@ MessageEncoder::EncoderState MessageEncoder::handle_EncodeTag(CborEncoder * enco
7779
if (cbor_encode_tag(encoder, commandTag) != CborNoError)
7880
return EncoderState::Error;
7981

80-
return EncoderState::EncodeParam;
82+
return EncoderState::EncodeArray;
8183
}
8284

8385
MessageEncoder::EncoderState MessageEncoder::handle_EncodeArray(CborEncoder * encoder, CborEncoder * array_encoder)
@@ -138,7 +140,7 @@ CborError MessageEncoder::encodeThingGetIdCmdUp(CborEncoder * array_encoder, Mes
138140
{
139141
ThingGetIdCmdUp * thingGetIdCmdUp = (ThingGetIdCmdUp *) message;
140142
DEBUG_INFO("Encoding thing id: %s", thingGetIdCmdUp->fields.params.thing_id);
141-
CHECK_CBOR(cbor_encode_text_string(array_encoder, thingGetIdCmdUp->fields.params.thing_id, THING_ID_SIZE));
143+
CHECK_CBOR(cbor_encode_text_stringz(array_encoder, thingGetIdCmdUp->fields.params.thing_id));
142144
return CborNoError;
143145
}
144146

@@ -152,8 +154,8 @@ CborError MessageEncoder::encodeDeviceBeginCmdUp(CborEncoder * array_encoder, Me
152154
CborError MessageEncoder::encodeOtaProgressCmdUp(CborEncoder * array_encoder, Message * message)
153155
{
154156
OtaProgressCmdUp * ota = (OtaProgressCmdUp *)message;
155-
CHECK_CBOR(cbor_encode_text_string(array_encoder, ota->fields.params.id, ID_SIZE));
156-
CHECK_CBOR(cbor_encode_text_string(array_encoder, ota->fields.params.state, STATE_SIZE));
157+
CHECK_CBOR(cbor_encode_text_stringz(array_encoder, ota->fields.params.id));
158+
CHECK_CBOR(cbor_encode_text_stringz(array_encoder, ota->fields.params.state));
157159
CHECK_CBOR(cbor_encode_uint(array_encoder, ota->fields.params.time));
158160
CHECK_CBOR(cbor_encode_uint(array_encoder, ota->fields.params.count));
159161
return CborNoError;

src/models/models.h

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
#define ID_SIZE 32
1010

1111
enum CommandID: uint32_t {
12-
GetLastValueCommandId = 66305,
13-
SetLastValueCommandId = 66306,
14-
GetTimezoneCommandId = 66307,
15-
SetTimezoneCommandId = 66308,
16-
OTAavailableId = 66309,
17-
GetThingIdCommandId = 66304,
1812
ThingGetIdCmdUpId = 66304,
1913
ThingGetLastValueCmdUpId = 66816,
2014
DeviceBeginCmdUpId = 67328,
21-
OtaProgressCmdUpId = 66048
15+
OtaProgressCmdUpId = 66048,
16+
OtaUpdateCmdDownId = 65792,
17+
ThingGetIdCmdDownId = 66560,
18+
ThingGetLastValueCmdDownId = 67072,
19+
TimezoneCommandUpId = 67398,
20+
TimezoneCommandDownId = 67428
2221
};
2322

2423
struct Command {
@@ -97,60 +96,69 @@ union OtaProgressCmdUp {
9796
} fields;
9897
};
9998

100-
struct LastValueCommand {
99+
struct OtaUpdateCmdDownCommand {
101100
Command command;
102101
};
103102

104-
union GetLastValueCommand {
103+
union OtaUpdateCmdDown {
105104
struct {
106-
LastValueCommand lastValueCommand;
105+
OtaUpdateCmdDownCommand otaUpdateCmdDownCommand;
107106
struct {
108-
// TODO fill in params
107+
char id[ID_SIZE];
108+
char url[URL_SIZE];
109+
uint8_t initialSha256[SHA256_SIZE];
110+
uint8_t finalSha256[SHA256_SIZE];
109111
} params;
110112
} fields;
111113
};
112114

113-
union SetLastValueCommand {
115+
struct ThingGetIdCmdDownCommand {
116+
Command command;
117+
};
118+
119+
union ThingGetIdCmdDown {
114120
struct {
115-
LastValueCommand lastValueCommand;
121+
ThingGetIdCmdDownCommand thingGetIdCmdDownCommand;
116122
struct {
117-
// TODO fill in params
123+
char thing_id[THING_ID_SIZE];
118124
} params;
119125
} fields;
120126
};
121127

122-
struct TimezoneCommand {
123-
Command command;
128+
struct ThingGetLastValueCmdDownCommand {
129+
Command command;
124130
};
125131

126-
union GetTimezoneCommand {
132+
union ThingGetLastValueCmdDown {
127133
struct {
128-
TimezoneCommand timezoneCommand;
134+
ThingGetLastValueCmdDownCommand thingGetLastValueCmdDownCommand;
135+
struct {
136+
uint8_t * last_values;
137+
size_t length;
138+
} params;
129139
} fields;
130140
};
131141

132-
union SetTimezoneCommand {
142+
struct TimezoneCommandUpCommand {
143+
Command command;
144+
};
145+
146+
union GetTimezoneCommand {
133147
struct {
134-
TimezoneCommand timezoneCommand;
135-
struct {
136-
uint32_t offset;
137-
uint32_t until;
138-
} params;
148+
TimezoneCommandUpCommand timezoneCommandUp;
139149
} fields;
140150
};
141151

142-
struct OTACommand {
152+
struct TimezoneCommandDownCommand {
143153
Command command;
144154
};
145155

146-
union OTAavailable {
156+
union SetTimezoneCommand {
147157
struct {
148-
OTACommand otaCommand;
158+
TimezoneCommandDownCommand timezoneCommandDown;
149159
struct {
150-
char id[ID_SIZE];
151-
char url[URL_SIZE];
152-
uint8_t initialSha256[SHA256_SIZE];
153-
uint8_t finalSha256[SHA256_SIZE];
160+
uint32_t offset;
161+
uint32_t until;
154162
} params;
155163
} fields;
156164
};

0 commit comments

Comments
 (0)