@@ -43,8 +43,9 @@ CborError MessageEncoder::encode(Message * message, uint8_t * data, size_t const
43
43
CborEncoder encoder;
44
44
CborEncoder arrayEncoder;
45
45
46
- cbor_encoder_init (&encoder, data, size, 0 );
47
46
47
+ cbor_encoder_init (&encoder, data, size, 0 );
48
+ DEBUG_INFO (" Encoder init with size %d" , size);
48
49
while (current_state != EncoderState::Complete) {
49
50
50
51
switch (current_state) {
@@ -71,6 +72,7 @@ CborError MessageEncoder::encode(Message * message, uint8_t * data, size_t const
71
72
72
73
MessageEncoder::EncoderState MessageEncoder::handle_EncodeTag (CborEncoder * encoder, Message * message, uint8_t * data)
73
74
{
75
+ DEBUG_INFO (" Encode tag" );
74
76
CborTag commandTag = (uint64_t ) message->id ;
75
77
if (cbor_encode_tag (encoder, commandTag) != CborNoError)
76
78
return EncoderState::Error;
@@ -80,6 +82,7 @@ MessageEncoder::EncoderState MessageEncoder::handle_EncodeTag(CborEncoder * enco
80
82
81
83
MessageEncoder::EncoderState MessageEncoder::handle_EncodeArray (CborEncoder * encoder, CborEncoder * array_encoder)
82
84
{
85
+ DEBUG_INFO (" Start array" );
83
86
if (cbor_encoder_create_array (encoder, array_encoder, CborIndefiniteLength) != CborNoError)
84
87
return EncoderState::Error;
85
88
@@ -88,11 +91,14 @@ MessageEncoder::EncoderState MessageEncoder::handle_EncodeArray(CborEncoder * en
88
91
89
92
MessageEncoder::EncoderState MessageEncoder::handle_EncodeParam (CborEncoder * encoder, CborEncoder * array_encoder, Message * message, uint8_t * data, size_t const size)
90
93
{
94
+ DEBUG_INFO (" Encode param" );
91
95
CborError error = CborNoError;
92
96
// Switch case on the message id
97
+ DEBUG_INFO (" message id is %d" , message->id );
93
98
switch (message->id )
94
99
{
95
100
case CommandID::ThingGetIdCmdUpId:
101
+ DEBUG_INFO (" Encode thing id up" );
96
102
error = MessageEncoder::encodeThingGetIdCmdUp (array_encoder, message);
97
103
break ;
98
104
case CommandID::ThingGetLastValueCmdUpId:
@@ -106,68 +112,51 @@ MessageEncoder::EncoderState MessageEncoder::handle_EncodeParam(CborEncoder * en
106
112
default :
107
113
return EncoderState::MessageNotSupported;
108
114
}
109
-
110
- if (error != CborNoError)
115
+ DEBUG_INFO (" Check error" );
116
+ if (error != CborNoError) {
117
+ DEBUG_INFO (" error is %d" , error);
111
118
return EncoderState::Error;
112
-
119
+ }
120
+
113
121
return EncoderState::CloseArray;
114
122
}
115
123
116
124
MessageEncoder::EncoderState MessageEncoder::handle_CloseArray (CborEncoder * encoder, CborEncoder * array_encoder)
117
125
{
118
- CborError error = cbor_encoder_close_container (encoder, array_encoder);
119
- if (cbor_encoder_close_container (encoder, array_encoder))
126
+ DEBUG_INFO (" Close array" );
127
+ if (cbor_encoder_close_container (encoder, array_encoder) != CborNoError) {
128
+ DEBUG_INFO (" Error closing array" );
120
129
return EncoderState::Error;
121
-
130
+ }
131
+
132
+ DEBUG_INFO (" After close array" );
122
133
return EncoderState::Complete;
123
134
}
124
135
125
136
// Message specific encoders
126
137
CborError MessageEncoder::encodeThingGetIdCmdUp (CborEncoder * array_encoder, Message * message)
127
138
{
128
139
ThingGetIdCmdUp * thingGetIdCmdUp = (ThingGetIdCmdUp *) message;
129
- // Encode the thing id
130
- CborError error = CborNoError;
131
- error = cbor_encode_text_string (array_encoder, thingGetIdCmdUp->fields .params .thing_id , THING_ID_SIZE);
132
-
133
- return error;
140
+ 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));
142
+ return CborNoError;
134
143
}
135
144
136
145
CborError MessageEncoder::encodeDeviceBeginCmdUp (CborEncoder * array_encoder, Message * message)
137
146
{
138
147
DeviceBeginCmdUp * deviceBeginCmdUp = (DeviceBeginCmdUp *) message;
139
- // Encode the sha
140
- CborError error = CborNoError;
141
- error = cbor_encode_byte_string (array_encoder, deviceBeginCmdUp->fields .params .sha , SHA256_SIZE);
142
-
143
- return error;
148
+ CHECK_CBOR (cbor_encode_byte_string (array_encoder, deviceBeginCmdUp->fields .params .sha , SHA256_SIZE));
149
+ return CborNoError;
144
150
}
145
151
146
152
CborError MessageEncoder::encodeOtaProgressCmdUp (CborEncoder * array_encoder, Message * message)
147
153
{
148
154
OtaProgressCmdUp * ota = (OtaProgressCmdUp *)message;
149
- // Encode the url
150
- CborError error = CborNoError;
151
- error = cbor_encode_text_string (array_encoder, ota->fields .params .id , ID_SIZE);
152
- if (error != CborNoError)
153
- return error;
154
-
155
- // Encode the state
156
- error = cbor_encode_text_string (array_encoder, ota->fields .params .state , STATE_SIZE);
157
- if (error != CborNoError)
158
- return error;
159
-
160
- // Encode the time
161
- error = cbor_encode_uint (array_encoder, ota->fields .params .time );
162
- if (error != CborNoError)
163
- return error;
164
-
165
- // Encode the count
166
- error = cbor_encode_uint (array_encoder, ota->fields .params .count );
167
- if (error != CborNoError)
168
- return error;
169
-
170
- return error;
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_uint (array_encoder, ota->fields .params .time ));
158
+ CHECK_CBOR (cbor_encode_uint (array_encoder, ota->fields .params .count ));
159
+ return CborNoError;
171
160
}
172
161
173
162
0 commit comments