summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/handshake.c19
-rw-r--r--src/master_posix.c8
2 files changed, 13 insertions, 14 deletions
diff --git a/src/handshake.c b/src/handshake.c
index f525f3c..dcad919 100644
--- a/src/handshake.c
+++ b/src/handshake.c
@@ -21,17 +21,15 @@ hs_status_t HS_func_0(p_stream_t stream, void **args)
hs_status_t HS_func_1(p_stream_t stream, void **args)
{
int hs_status = HS_STATE_1;
- uint8_t MDR_ACK_buf[2] = {0x0, 0x0};
- if (stream.read(MDR_ACK_buf, 2, NULL, &stream) != 0);
+ args[0] = malloc(sizeof(uint8_t)*2);
+ if (stream.read(args[0], 2, NULL, &stream) != 0);
else {
- uint8_t ACK_flag = MDR_ACK_buf[1];
+ uint8_t ACK_flag = ((uint8_t*)args[0])[1];
if (ACK_flag == 0xFF) {
- /* Assign MDR_len for forward propogation in FSM */
- args[0] = malloc(sizeof(uint16_t));
- args[0] = &MDR_ACK_buf[0];
hs_status = HS_STATE_2;
}
else {
+ free(args[0]);
hs_status = HS_STATE_FAIL;
}
}
@@ -54,15 +52,14 @@ hs_status_t HS_func_2(p_stream_t stream, void **args)
hs_status_t HS_func_3(p_stream_t stream, void **args)
{
int hs_status = HS_STATE_3;
- uint8_t *MDR_buf, *MDR_len = (uint8_t*)args[0];
- MDR_buf = (uint8_t*)malloc(*MDR_len);
+ uint8_t MDR_len = ((uint8_t*)args[0])[0];
+ args[1] = malloc(sizeof(uint8_t)*(MDR_len));
- if (stream.read(MDR_buf, *MDR_len, NULL, &stream) != 0) {
+ if (stream.read(args[1], MDR_len, NULL, &stream) != 0) {
+ free(args[1]);
hs_status = HS_STATE_FAIL;
}
else {
- args[1] = malloc(sizeof(uint8_t)*(*MDR_len));
- memcpy(args[1], MDR_buf, *MDR_len);
hs_status = HS_STATE_SUCCESS;
}
return hs_status;
diff --git a/src/master_posix.c b/src/master_posix.c
index a79df53..54a94bd 100644
--- a/src/master_posix.c
+++ b/src/master_posix.c
@@ -141,7 +141,7 @@ void vStartPOSIXMaster(void *pvParams)
static void *handshake_func(void * pvArgs)
{
printf("Handshake thread started %s", LINE_BREAK);
- for (;;) {
+ /* for (;;) { */
for (int dev_idx = 0; dev_idx < BUS_DEVICE_LIMIT-1; dev_idx++) {
/*
* With the new state machine structure, what is the correct condition
@@ -180,11 +180,13 @@ static void *handshake_func(void * pvArgs)
MDR_res_message.subscriptions.funcs.decode = decode_subscriptions_callback;
MDR_res_message.subscriptions.arg = (void*)dev_idx;
pb_istream_t MDR_res_stream = pb_istream_from_buffer(args[1],
- *(uint16_t*)args[0]);
+ *(uint8_t*)args[0]);
if (!pb_decode(&MDR_res_stream, s2m_MDR_response_fields, &MDR_res_message)) {
+ printf("decode fail\n");
hs_state = HS_STATE_FAIL;
}
else {
+ printf("decode done\n");
device_info[dev_idx] = malloc(sizeof(device_info_t));
device_info[dev_idx]->i2c_addr = 0x0;
device_info[dev_idx]->device_id = dev_idx;
@@ -196,7 +198,7 @@ static void *handshake_func(void * pvArgs)
/* TODO This is slightly redundant now, so fix this */
/* dev_sts[dev_idx] = get_state_from_hs_status(GET_ADDR_FROM_IDX(dev_idx), hs_state); */
}
- }
+ /* } */
}
return NULL;
}