diff --git a/examples/multithread/multithread.c b/examples/multithread/multithread.c index d0b247160..b76781774 100755 --- a/examples/multithread/multithread.c +++ b/examples/multithread/multithread.c @@ -317,7 +317,7 @@ static void *subscribe_task(void *param) { int rc = MQTT_CODE_SUCCESS; uint16_t i; - MQTTCtx *mqttCtx = param; + MQTTCtx *mqttCtx = (MQTTCtx*)param; /* Build list of topics */ XMEMSET(&mqttCtx->subscribe, 0, sizeof(MqttSubscribe)); @@ -375,7 +375,7 @@ static void *waitMessage_task(void *param) #endif { int rc; - MQTTCtx *mqttCtx = param; + MQTTCtx *mqttCtx = (MQTTCtx*)param; /* Read Loop */ PRINTF("MQTT Waiting for message..."); @@ -453,7 +453,7 @@ static void *publish_task(void *param) { int rc; char buf[7]; - MQTTCtx *mqttCtx = param; + MQTTCtx *mqttCtx = (MQTTCtx*)param; MqttPublish publish; /* Publish Topic */ @@ -485,7 +485,7 @@ static void *ping_task(void *param) #endif { int rc; - MQTTCtx *mqttCtx = param; + MQTTCtx *mqttCtx = (MQTTCtx*)param; MqttPing ping; XMEMSET(&ping, 0, sizeof(ping)); diff --git a/src/mqtt_client.c b/src/mqtt_client.c index bf1163d88..e16d13320 100644 --- a/src/mqtt_client.c +++ b/src/mqtt_client.c @@ -748,7 +748,7 @@ static int MqttClient_WaitType(MqttClient *client, void *packet_obj, MqttPacket_TypeDesc(wait_type), wait_type, wait_packet_id); #endif - switch (*mms_stat) + switch ((int)*mms_stat) { case MQTT_MSG_BEGIN: { @@ -776,8 +776,8 @@ static int MqttClient_WaitType(MqttClient *client, void *packet_obj, pendResp = NULL; rc = wm_SemLock(&client->lockClient); if (rc == 0) { - if (MqttClient_RespList_Find(client, wait_type, wait_packet_id, - &pendResp)) { + if (MqttClient_RespList_Find(client, (MqttPacketType)wait_type, + wait_packet_id, &pendResp)) { if (pendResp->packetDone) { /* pending response is already done, so return */ rc = pendResp->packet_ret; @@ -2336,19 +2336,23 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, { int rc; SN_MsgType packet_type; - word16 packet_id = 0; - MqttMsgStat* stat; + word16 packet_id; + MqttMsgStat* mms_stat; if (client == NULL || packet_obj == NULL) { return MQTT_CODE_ERROR_BAD_ARG; } /* all packet type structures must have MqttMsgStat at top */ - stat = (MqttMsgStat*)packet_obj; + mms_stat = (MqttMsgStat*)packet_obj; wait_again: - switch ((int)*stat) + /* initialize variables */ + packet_id = 0; + packet_type = SN_MSG_TYPE_RESERVED; + + switch ((int)*mms_stat) { case MQTT_MSG_BEGIN: { @@ -2366,7 +2370,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, return rc; } - *stat = MQTT_MSG_WAIT; + *mms_stat = MQTT_MSG_WAIT; client->packet.buf_len = rc; /* Decode header */ @@ -2380,7 +2384,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, client->packet.buf_len, packet_type); #endif - *stat = MQTT_MSG_READ; + *mms_stat = MQTT_MSG_READ; FALL_THROUGH; } @@ -2388,7 +2392,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, case MQTT_MSG_READ: case MQTT_MSG_READ_PAYLOAD: { - if (*stat == MQTT_MSG_READ_PAYLOAD) { + if (*mms_stat == MQTT_MSG_READ_PAYLOAD) { packet_type = SN_MSG_TYPE_PUBLISH; } rc = SN_Client_HandlePacket(client, packet_type, packet_obj, @@ -2405,7 +2409,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, break; } - *stat = MQTT_MSG_BEGIN; + *mms_stat = MQTT_MSG_BEGIN; goto wait_again; } @@ -2416,7 +2420,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, default: { #ifdef WOLFMQTT_DEBUG_CLIENT - PRINTF("SN_Client_WaitType: Invalid state %d!", *stat); + PRINTF("SN_Client_WaitType: Invalid state %d!", *mms_stat); #endif rc = MQTT_CODE_ERROR_STAT; break; @@ -2424,7 +2428,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, } /* switch (msg->stat) */ /* reset state */ - *stat = MQTT_MSG_BEGIN; + *mms_stat = MQTT_MSG_BEGIN; return rc; } diff --git a/src/mqtt_packet.c b/src/mqtt_packet.c index 2a37ae4a0..82a7174f7 100755 --- a/src/mqtt_packet.c +++ b/src/mqtt_packet.c @@ -837,8 +837,8 @@ int MqttEncode_Publish(byte *tx_buf, int tx_buf_len, MqttPublish *publish, tx_payload += MqttEncode_Vbi(tx_payload, props_len); /* Encode properties */ - tx_payload += MqttEncode_Props(publish->type, publish->props, - tx_payload); + tx_payload += MqttEncode_Props((MqttPacketType)publish->type, + publish->props, tx_payload); } #endif @@ -912,8 +912,8 @@ int MqttDecode_Publish(byte *rx_buf, int rx_buf_len, MqttPublish *publish) variable_len += tmp + props_len; if (props_len > 0) { /* Decode the Properties */ - rx_payload += MqttDecode_Props(publish->type, &publish->props, - rx_payload, props_len); + rx_payload += MqttDecode_Props((MqttPacketType)publish->type, + &publish->props, rx_payload, props_len); if (publish->props != NULL) { /* Parse properties. */ } @@ -1854,7 +1854,7 @@ int SN_Decode_Header(byte *rx_buf, int rx_buf_len, } /* Message Type */ - packet_type = *rx_buf++; + packet_type = (SN_MsgType)*rx_buf++; if (p_packet_type) *p_packet_type = packet_type; diff --git a/wolfmqtt/mqtt_packet.h b/wolfmqtt/mqtt_packet.h index 54e395e60..14808f1f0 100644 --- a/wolfmqtt/mqtt_packet.h +++ b/wolfmqtt/mqtt_packet.h @@ -759,8 +759,9 @@ typedef enum _SN_MsgType { SN_MSG_TYPE_WILLMSGUPD = 0x1C, SN_MSG_TYPE_WILLMSGRESP = 0x1D, /* 0x1E - 0xFD reserved */ - SN_MSG_TYPE_ENCAPMSG = 0xFE /* Encapsulated message */ + SN_MSG_TYPE_ENCAPMSG = 0xFE, /* Encapsulated message */ /* 0xFF reserved */ + SN_MSG_TYPE_RESERVED = 0xFF } SN_MsgType; /* Topic ID types */