Skip to content

Commit f26d791

Browse files
committed
fixed pointer
1 parent 0502e0b commit f26d791

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,12 @@ void ArduinoIoTCloudTCP::decode(){
308308
uint8_t const payload[] = {0xDA, 0x00, 0x01, 0x03, 0x00, 0x83, 0x68, 0x74, 0x68, 0x69, 0x6E, 0x67, 0x5F, 0x69, 0x64, 0x0A, 0xFB, 0x40, 0x09, 0x1E, 0xB8, 0x51, 0xEB, 0x85, 0x1F};
309309

310310
int const payload_length = sizeof(payload) / sizeof(uint8_t);
311-
MessageDecoder::decode(message, payload, payload_length);
311+
MessageDecoder::decode(&message, payload, payload_length);
312312

313313

314314
DEBUG_INFO("Message id is %d", message.id);
315+
ThingBeginCommand * thingCommand = (ThingBeginCommand*) &message;
316+
DEBUG_INFO("Thing id is %d", thingCommand->thing_id);
315317
}
316318

317319
/******************************************************************************

src/cbor/MessageDecoder.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@
3333
PUBLIC MEMBER FUNCTIONS
3434
******************************************************************************/
3535

36-
void MessageDecoder::decode(Message & message, uint8_t const * const payload, size_t const length)
36+
void MessageDecoder::decode(Message * message, uint8_t const * const payload, size_t const length)
3737
{
3838
DEBUG_INFO(">>>>>>>>>> Decode invoked");
3939
CborValue main_iter, array_iter, param;
4040
CborTag tag;
4141
CborParser parser;
4242
int index;
4343

44-
//std::list<CborMapData> map_data_list; /* List of map data that will hold all the attributes of a property */
45-
4644
if (cbor_parser_init(payload, length, 0, &parser, &main_iter) != CborNoError)
4745
return;
4846

@@ -54,8 +52,8 @@ void MessageDecoder::decode(Message & message, uint8_t const * const payload, si
5452
ThingBeginCommand * beginCommand = new ThingBeginCommand;
5553
String uuid_string = "e0bd5569-5c19-4535-9dd8-988564f7bc95";
5654
strncpy(beginCommand->thing_id, uuid_string.c_str(), sizeof(beginCommand->thing_id));
57-
message = *beginCommand;
58-
message.id = CommandID(tag);
55+
message = (Message*) beginCommand;
56+
message->id = CommandID(tag);
5957

6058
}
6159

@@ -97,7 +95,7 @@ DEBUG_INFO(">>>>>>>>>> handle_EnterArray");
9795
}
9896

9997

100-
MessageDecoder::ArrayParserState MessageDecoder::handle_Param(CborValue * param, Message & message) {
98+
MessageDecoder::ArrayParserState MessageDecoder::handle_Param(CborValue * param, Message message) {
10199
ArrayParserState next_state = ArrayParserState::Error;
102100

103101
// switch (message->id)

src/cbor/MessageDecoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MessageDecoder
4141
public:
4242

4343
/* decode a CBOR payload received from the cloud */
44-
static void decode(Message & msg, uint8_t const * const payload, size_t const length);
44+
static void decode(Message * msg, uint8_t const * const payload, size_t const length);
4545

4646

4747
private:
@@ -59,7 +59,7 @@ class MessageDecoder
5959
};
6060

6161
static ArrayParserState handle_EnterArray(CborValue * array_iter, CborValue * param);
62-
static ArrayParserState handle_Param(CborValue * param, Message & message);
62+
static ArrayParserState handle_Param(CborValue * param, Message * message);
6363
static ArrayParserState handle_LeaveArray(CborValue * array_iter);
6464

6565
static bool ifNumericConvertToDouble(CborValue * value_iter, double * numeric_val);

0 commit comments

Comments
 (0)