|
|
|
@ -45,6 +45,7 @@ CLte_dev_t lte_dev = { |
|
|
|
.client1 = (Cclient_t *)&client1, |
|
|
|
.config_sta = false, |
|
|
|
.reset_flag = DTU_CF_NEED_RESET, |
|
|
|
.dev_init_flag = true, |
|
|
|
}; |
|
|
|
|
|
|
|
void BSP_LTE_SendData(uint8_t *pdata, uint32_t length) { |
|
|
|
@ -97,7 +98,7 @@ int16_t BSP_LTE_SendCmd(const char *cmd, const char *expect, const char *error, |
|
|
|
while (rt_device_read(lte_dev.com_dev, 0, &c, 1) == 1) { |
|
|
|
} |
|
|
|
|
|
|
|
if (NULL != rt_strstr((char *)lte_dev.at_buf, expect) && expect != NULL) { |
|
|
|
if (expect != NULL && NULL != rt_strstr((char *)lte_dev.at_buf, expect)) { |
|
|
|
return 0; |
|
|
|
} else if (NULL != rt_strstr((char *)lte_dev.at_buf, error) && |
|
|
|
error != NULL) { |
|
|
|
@ -135,44 +136,80 @@ int16_t BSP_LTE_SendATE(int16_t retry) { |
|
|
|
|
|
|
|
// char tmp_imei[16] = "001068000000006";
|
|
|
|
// char tmp_imei_2[16] = "869455062043381";
|
|
|
|
void extract_number(const char *src, char *dest) { |
|
|
|
char *start = strchr(src, '\n') + 1; |
|
|
|
char *end = strchr(start, '\r'); |
|
|
|
|
|
|
|
int extract_number(const char *src, char *dest) { |
|
|
|
if(src == RT_NULL || dest == RT_NULL){ |
|
|
|
return -1; |
|
|
|
} |
|
|
|
char *start = NULL; |
|
|
|
char *end = NULL; |
|
|
|
if (strchr(src, '\n') != NULL) { |
|
|
|
start = strchr(src, '\n') + 1; |
|
|
|
if (start != NULL) { |
|
|
|
end = strchr(start, '\r'); |
|
|
|
} |
|
|
|
} |
|
|
|
if (start != NULL && end != NULL) { |
|
|
|
int length = end - start; |
|
|
|
|
|
|
|
if(length >= 30){ |
|
|
|
return -1; |
|
|
|
} |
|
|
|
strncpy(dest, start, length); |
|
|
|
dest[length] = '\0'; |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
void BSP_LTE_GetIMEI(char *pIMEI) { |
|
|
|
while (0 != BSP_LTE_SendCmd(AT_IMEI, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
|
LTE_CMD_WAIT_NORMAL)); |
|
|
|
|
|
|
|
extract_number((const char *)lte_dev.at_buf, pIMEI); |
|
|
|
int BSP_LTE_GetIMEI(char *pIMEI) { |
|
|
|
int ret = 0; |
|
|
|
// while (0 != BSP_LTE_SendCmd(AT_IMEI, DEFAULT_EXPECT, DEFAULT_ERROR,
|
|
|
|
// LTE_CMD_WAIT_NORMAL));
|
|
|
|
ret = BSP_LTE_SendCmd(AT_IMEI, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
|
LTE_CMD_WAIT_NORMAL); |
|
|
|
if (ret != 0) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
if (extract_number((const char *)lte_dev.at_buf, pIMEI) == -1) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
if (strlen(pIMEI) < 10) { |
|
|
|
BSP_LTE_GetIMEI(pIMEI); |
|
|
|
ret = -1; |
|
|
|
} |
|
|
|
if (pIMEI[15] == '\"') pIMEI[15] = 0; |
|
|
|
if (pIMEI[15] == '\"') |
|
|
|
pIMEI[15] = 0; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
void BSP_LTE_GetICCID(char *pICCID) { |
|
|
|
char *start, *end = NULL; |
|
|
|
while (0 != BSP_LTE_SendCmd(AT_ICCID, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
|
LTE_CMD_WAIT_LONG)); |
|
|
|
//sscanf((const char *)lte_dev.at_buf, "+ICCID:%s\n", pICCID);
|
|
|
|
int BSP_LTE_GetICCID(char *pICCID) { |
|
|
|
char *start = NULL; |
|
|
|
char *end = NULL; |
|
|
|
int ret = 0; |
|
|
|
// while (0 != BSP_LTE_SendCmd(AT_ICCID, DEFAULT_EXPECT, DEFAULT_ERROR,
|
|
|
|
// LTE_CMD_WAIT_LONG));
|
|
|
|
ret = BSP_LTE_SendCmd(AT_ICCID, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
|
LTE_CMD_WAIT_LONG); |
|
|
|
if(ret != 0){ |
|
|
|
return -1; |
|
|
|
} |
|
|
|
if(rt_strstr((const char *)lte_dev.at_buf, "+ICCID:") != NULL){ |
|
|
|
start = |
|
|
|
rt_strstr((const char *)lte_dev.at_buf, "+ICCID:") + rt_strlen("+ICCID:") + 1; |
|
|
|
} |
|
|
|
if(start == RT_NULL){ |
|
|
|
return -1; |
|
|
|
} |
|
|
|
end = start; |
|
|
|
while (*end != '\0' && *end != '\r' && *end != '\n') end++; |
|
|
|
rt_size_t len = end - start; |
|
|
|
if(len >= 30){ |
|
|
|
return -1; |
|
|
|
} |
|
|
|
rt_memcpy(pICCID, start, len); |
|
|
|
pICCID[len] = '\0'; |
|
|
|
|
|
|
|
if (strlen(pICCID) < 10) { |
|
|
|
BSP_LTE_GetICCID(pICCID); |
|
|
|
ret = -1; |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
int16_t BSP_LTE_GetCGATT(int16_t retry) { |
|
|
|
@ -301,9 +338,9 @@ void BSP_LTE_Config(void) { |
|
|
|
} |
|
|
|
|
|
|
|
/*查询模块信息*/ |
|
|
|
if (lte_dev.dev_init_flag == true) { |
|
|
|
BSP_LTE_SendCmd(AT_ATI, DEFAULT_EXPECT, DEFAULT_ERROR, LTE_CMD_WAIT_NORMAL); |
|
|
|
rt_kprintf("%s", lte_dev.at_buf); |
|
|
|
hw_printf("%s", lte_dev.at_buf); |
|
|
|
} |
|
|
|
/*查询SIM卡是否存在*/ |
|
|
|
res = BSP_LTE_SendATCPIN(3); |
|
|
|
if (res == 0) |
|
|
|
@ -314,18 +351,25 @@ void BSP_LTE_Config(void) { |
|
|
|
} |
|
|
|
|
|
|
|
/*请求移动设备的识别码*/ |
|
|
|
BSP_LTE_GetIMEI(lte_dev.imei); |
|
|
|
if (lte_dev.dev_init_flag == true) { |
|
|
|
if (BSP_LTE_GetIMEI(lte_dev.imei) == -1) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
/*请求sim卡号码*/ |
|
|
|
BSP_LTE_GetICCID(lte_dev.iccid); |
|
|
|
|
|
|
|
if (BSP_LTE_GetICCID(lte_dev.iccid) == -1) { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
/*查询信号强度*/ |
|
|
|
res = BSP_LTE_GetCSQ(); |
|
|
|
if (res != -1) lte_dev.csq = res; |
|
|
|
|
|
|
|
/*查询网络注册状态*/ |
|
|
|
BSP_LTE_GetCEREG(3); |
|
|
|
|
|
|
|
res = BSP_LTE_GetCEREG(3); |
|
|
|
if(res == -1){ |
|
|
|
return; |
|
|
|
} |
|
|
|
/*配置应用场景*/ |
|
|
|
BSP_LTE_SendCmd(AT_QICSGP, DEFAULT_EXPECT, DEFAULT_ERROR, LTE_CMD_WAIT_LONG); |
|
|
|
|
|
|
|
@ -335,19 +379,6 @@ void BSP_LTE_Config(void) { |
|
|
|
//+CGDCONT: 1,"IP","cmiot","0.0.0.0",0,0,0,0,0,0....OK
|
|
|
|
|
|
|
|
lte_dev.config_sta = true; |
|
|
|
} |
|
|
|
|
|
|
|
void hw_printf(const char *fmt, ...) { |
|
|
|
char buff[128]; |
|
|
|
va_list args; |
|
|
|
va_start(args, fmt); |
|
|
|
|
|
|
|
rt_vsnprintf(buff, sizeof(buff), fmt, args); |
|
|
|
va_end(args); |
|
|
|
|
|
|
|
rt_device_t com_dev = fmu_com_get(); |
|
|
|
if (com_dev != RT_NULL) { |
|
|
|
rt_device_write(com_dev, 0, buff, rt_strlen(buff)); |
|
|
|
} |
|
|
|
lte_dev.dev_init_flag = false; |
|
|
|
} |
|
|
|
//------------------End of File----------------------------
|
|
|
|
|