Skip to content

Commit

Permalink
[src/mdm9206] fix for SIM7000C runtime issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Jian.Cui authored and Yang, Xiao committed Nov 29, 2017
1 parent 4e68220 commit cbb798d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
27 changes: 23 additions & 4 deletions src/import/mdm9206/example/iotkit_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ static const QCLI_Command_t iot_cmd_list[] =
" p <topic> <message> #publish\n"
" s <topic> #subscribe\n"
" u <topic> #unsubscribe\n"
" y #yield\n"
" d ", "test mqtt function",NULL},
" y <timeout> or y#yield\n"
" d #destroy", "test mqtt function",NULL},

{http, false, "http", "#i <key><secret><name><id> or i#init\n"
" a #auth\n"
Expand Down Expand Up @@ -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';
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand All @@ -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 ) {
Expand Down
23 changes: 15 additions & 8 deletions src/import/mdm9206/example/iotkit_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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, ...)
Expand All @@ -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";
}
Expand All @@ -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;
Expand Down

0 comments on commit cbb798d

Please sign in to comment.