diff --git a/src/import/mdm9206/example/iotkit_demo.c b/src/import/mdm9206/example/iotkit_demo.c index 0de0d72da..62c83f1fc 100644 --- a/src/import/mdm9206/example/iotkit_demo.c +++ b/src/import/mdm9206/example/iotkit_demo.c @@ -109,8 +109,8 @@ static const QCLI_Command_t iot_cmd_list[] = " p #publish\n" " s #subscribe\n" " u #unsubscribe\n" - " y #yield\n" - " d ", "test mqtt function",NULL}, + " y or y#yield\n" + " d #destroy", "test mqtt function",NULL}, {http, false, "http", "#i or i#init\n" " a #auth\n" @@ -147,10 +147,11 @@ static QCLI_Command_Status_t mqtt(uint32_t Parameter_Count, QCLI_Parameter_t *Pa #define MQTT_DEVICE_NAME_LEN (32) #define MQTT_DEVICE_SECRET_LEN (64) + static char isInit = 0; static char msg_buf[MSG_LEN_MAX]; static char msg_readbuf[MSG_LEN_MAX] ; - static iotx_conn_info_pt pconn_info; + static iotx_conn_info_pt pconn_info = NULL; static iotx_mqtt_param_t mqtt_params; static void *pclient=NULL; char command = '0'; @@ -162,6 +163,17 @@ static QCLI_Command_Status_t mqtt(uint32_t Parameter_Count, QCLI_Parameter_t *Pa if(Parameter_Count < 1){ return QCLI_STATUS_USAGE_E; } + + if(isInit == 0){ + memset(msg_buf, 0, sizeof(msg_buf)); + memset(msg_readbuf, 0, sizeof(msg_readbuf)); + memset(&mqtt_params, 0, sizeof(mqtt_params)); + memset(product_key, 0, sizeof(product_key)); + memset(device_name, 0, sizeof(device_name)); + memset(device_secret, 0, sizeof(device_secret)); + isInit = 1; + } + command = (char)Parameter_List[0].String_Value[0]; switch ( command ) { @@ -231,7 +243,7 @@ static QCLI_Command_Status_t mqtt(uint32_t Parameter_Count, QCLI_Parameter_t *Pa QCLI_Printf(qcli_iotkit_handle, "had constructed\n"); break; } - if (pconn_info->client_id == 0){ + if ((NULL == pconn_info) || (0 == pconn_info->client_id)){ QCLI_Printf(qcli_iotkit_handle, "please auth first\n"); break; } @@ -363,6 +375,7 @@ static QCLI_Command_Status_t http(uint32_t Parameter_Count, QCLI_Parameter_t *Pa { static void *http_handle = NULL; + static char isInit = 0; static iotx_device_info_t device_info; static iotx_http_param_t http_param; @@ -372,6 +385,12 @@ static QCLI_Command_Status_t http(uint32_t Parameter_Count, QCLI_Parameter_t *Pa return QCLI_STATUS_USAGE_E; } + if(0 == isInit){ + memset(&device_info, 0, sizeof(device_info)); + memset(&http_param, 0 ,sizeof(http_param)); + isInit = 1; + } + command = (char)Parameter_List[0].String_Value[0]; switch ( command ) { diff --git a/src/import/mdm9206/example/iotkit_hal.c b/src/import/mdm9206/example/iotkit_hal.c index 033a6d70c..280f593ed 100644 --- a/src/import/mdm9206/example/iotkit_hal.c +++ b/src/import/mdm9206/example/iotkit_hal.c @@ -8,6 +8,8 @@ #define _IN_ #define _OU_ +#define LOG_BUFFER_SIZE 256 + extern QCLI_Group_Handle_t qcli_iotkit_handle; /* Handle for IOT Command Group. */ int HAL_Vsnprintf(_IN_ char *str, _IN_ const int len, _IN_ const char *format, va_list ap) @@ -17,12 +19,15 @@ int HAL_Vsnprintf(_IN_ char *str, _IN_ const int len, _IN_ const char *format, v void HAL_Printf(_IN_ const char *fmt, ...) { - static char str_tmp[256] = {0}; + static char str_tmp[LOG_BUFFER_SIZE]; va_list list; - va_start (list, fmt); - HAL_Vsnprintf(str_tmp, 256, fmt, list); + + memset(str_tmp, 0, LOG_BUFFER_SIZE); + + va_start(list, fmt); + HAL_Vsnprintf(str_tmp, LOG_BUFFER_SIZE - 1, fmt, list); va_end(list); - QCLI_Printf(qcli_iotkit_handle, "%s",str_tmp); + QCLI_Printf(qcli_iotkit_handle, "%s", str_tmp); } int HAL_Snprintf(_IN_ char *str, const int len, const char *fmt, ...) @@ -37,7 +42,8 @@ int HAL_Snprintf(_IN_ char *str, const int len, const char *fmt, ...) return rc; } -char *HAL_GetModuleID(char mid_str[]){ +char *HAL_GetModuleID(char mid_str[]) +{ strcpy(mid_str, "xyz"); return "xyz"; } @@ -53,9 +59,10 @@ uint32_t HAL_Random(uint32_t region) return (region > 0) ? (rand() % region) : 0; } -int HAL_Atoi(const char *str){ - int res = 0,i; - for(i = 0 ; str[i] <='9' && str[i] >= '0';++i){ +int HAL_Atoi(const char *str) +{ + int res = 0, i; + for (i = 0 ; str[i] <= '9' && str[i] >= '0'; ++i) { res = res * 10 + str[i] - '0'; } return res;