Skip to content

Commit e62b501

Browse files
committed
Proper handling of incoming message for I2C
1 parent 9cc7891 commit e62b501

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

test/tst_i2c_message_receiving.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "tst_defs.h"
1212

1313
static bool async_receive_flag = false;
14-
static incoming_queue_item_t *incoming_item = NULL;
14+
static robusto_message_t *incoming_message = NULL;
1515

1616
static robusto_peer_t *incoming_peer = NULL;
1717
static uint8_t *reply_msg = NULL;
@@ -141,7 +141,8 @@ void tst_i2c_message_receive_presentation(void)
141141

142142
void i2c_tst_do_on_work(incoming_queue_item_t *_incoming_item) {
143143
ROB_LOGI("TEST", "In i2c_tst_do_on_work");
144-
incoming_item = _incoming_item;
144+
incoming_message= _incoming_item->message;
145+
_incoming_item->recipient_frees_message = true;
145146
async_receive_flag = true;
146147

147148
}
@@ -151,19 +152,20 @@ void tst_i2c_message_receive_string_message(void) {
151152
// Register the on work callback
152153
robusto_register_handler(i2c_tst_do_on_work);
153154
async_receive_flag = false;
154-
incoming_item = NULL;
155+
incoming_message = NULL;
155156

156157
if (robusto_waitfor_bool(&async_receive_flag, 30000)) {
157158
ROB_LOGI("Test", "Async receive flag was set to true.");
158159
} else {
159160
TEST_FAIL_MESSAGE("Test failed, timed out.");
160161
}
161-
if (incoming_item == NULL) {
162+
if (incoming_message == NULL) {
162163
TEST_FAIL_MESSAGE("Test failed, incoming_item NULL.");
163164
}
164-
TEST_ASSERT_EQUAL_INT_MESSAGE(2, incoming_item->message->string_count, "The string count is wrong.");
165-
TEST_ASSERT_EQUAL_STRING_MESSAGE(&tst_strings, incoming_item->message->strings[0], "First string did not match");
166-
TEST_ASSERT_EQUAL_STRING_MESSAGE((char *)&(tst_strings[4]), incoming_item->message->strings[1], "Second string did not match");
165+
TEST_ASSERT_EQUAL_INT_MESSAGE(2, incoming_message->string_count, "The string count is wrong.");
166+
TEST_ASSERT_EQUAL_STRING_MESSAGE(&tst_strings, incoming_message->strings[0], "First string did not match");
167+
TEST_ASSERT_EQUAL_STRING_MESSAGE((char *)&(tst_strings[4]), incoming_message->strings[1], "Second string did not match");
168+
robusto_message_free(incoming_message);
167169

168170

169171
}

test/tst_i2c_message_receiving.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ void tst_i2c_message_receive_string_message(void);
55
void tst_message_receive_binary_message_mock(void);
66
void tst_message_receive_multi_message_mock(void);
77
void tst_message_receive_binary_message_restricted_mock(void);
8-
void tst_i2c_message_receive_presentation(void);
9-
void tst_i2c_message_receive_string_message(void);
8+
void tst_i2c_message_receive_presentation(void);

0 commit comments

Comments
 (0)