代码暂存 获取sim状态及时间等信息 功耗75uA左右
This commit is contained in:
parent
3f1963cb5f
commit
f354c35353
|
@ -203,7 +203,7 @@
|
|||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.picolibc.62047318" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.picolibc" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.picolibc.disabled" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.cref.824432654" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.cref" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printmap.751686263" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printmap" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys.351964161" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat.695795083" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usescanffloat.1839373535" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usescanffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
|
@ -244,7 +244,7 @@
|
|||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.picolibc.4345436542" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.picolibc" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.picolibc.disabled" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.cref.1007621036" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.cref" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printmap.2073713641" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printmap" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano.1540675679" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano.1540675679" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnosys.561457319" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.useprintffloat.1497004994" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.useprintffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usescanffloat.881728961" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usescanffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
|
|
|
@ -108,23 +108,23 @@ int main(void)
|
|||
|
||||
BSP_VBAT_Init();
|
||||
logDebug("VBAT init ok\n");
|
||||
|
||||
logDebug("BSP_Get_Tick1 %d\n",BSP_Get_Tick());
|
||||
DelayMs(2000);
|
||||
logDebug("BSP_Get_Tick2 %d\n",BSP_Get_Tick());
|
||||
|
||||
BSP_Ml307r_Init();
|
||||
logDebug("BSP_M1307r ok\n");
|
||||
|
||||
// ShowRestartReason();
|
||||
// IWDG_Init(5000);
|
||||
// logDebug("IWDG init ok\n");
|
||||
ShowRestartReason();
|
||||
IWDG_Init(5000);
|
||||
logDebug("IWDG init ok\n");
|
||||
|
||||
BSP_PRESS_Init();
|
||||
logDebug("BSP init ok\n");
|
||||
|
||||
Function_Check();
|
||||
|
||||
logDebug("BSP_Get_Tick1 %d\n",BSP_Get_Tick());
|
||||
DelayMs(1000);
|
||||
logDebug("BSP_Get_Tick2 %d\n",BSP_Get_Tick());
|
||||
|
||||
Main_Circulation();
|
||||
logDebug("Main_Circulation\n");
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@
|
|||
"generate_map": "\"${BuildArtifactFileBaseName}.map\"",
|
||||
"cross_reference": false,
|
||||
"print_link_map": false,
|
||||
"use_newlib_nano": true,
|
||||
"use_newlib_nano": false,
|
||||
"use_float_with_nano_printf": false,
|
||||
"use_float_with_nano_scanf": false,
|
||||
"do_not_use_syscalls": true,
|
||||
|
@ -305,7 +305,7 @@
|
|||
"generate_map": "\"${BuildArtifactFileBaseName}.map\"",
|
||||
"cross_reference": false,
|
||||
"print_link_map": false,
|
||||
"use_newlib_nano": true,
|
||||
"use_newlib_nano": false,
|
||||
"use_float_with_nano_printf": false,
|
||||
"use_float_with_nano_scanf": false,
|
||||
"do_not_use_syscalls": true,
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
1.使用状态机重构了4G模组连接过程
|
||||
2.调用这个TMOS_GetSystemClock()时需要使用轻量级 C 库 newlib-nano,(默认禁用浮点支持)
|
||||
3.因禁用浮点运算,优化代码ADC部分浮点运算代码
|
||||
4.打开了外部低速时钟
|
||||
|
||||
|
||||
获取sim信息(用于上报)
|
||||
获取实时时间
|
||||
|
||||
数据上报(低电压、阀门状态)
|
||||
下行数据处理
|
||||
滴答定时器精度
|
|
@ -32,6 +32,11 @@ typedef struct __attribute__((packed))
|
|||
uint8_t restart_error_flag : 1; //重启模块失败
|
||||
uint8_t sim_success_flag : 1; //sim成功
|
||||
uint8_t sim_error_flag : 1; //sim失败
|
||||
|
||||
uint8_t Get_ModInfo_flag : 1; //获取模组信息
|
||||
uint8_t ModInfo_update_flag : 1; //信息更新
|
||||
uint8_t ModInfo_success_flag : 1; //获取模组信息成功
|
||||
uint8_t ModInfo_error_flag : 1; //获取模组信息失败
|
||||
|
||||
uint8_t Connect_success_flag : 1; //连接平台成功
|
||||
uint8_t Connect_error_flag : 1; //连接平台失败
|
||||
|
@ -48,8 +53,57 @@ typedef struct __attribute__((packed))
|
|||
|
||||
}IotFlagStruct;
|
||||
|
||||
extern IotFlagStruct IotFlag_t;
|
||||
|
||||
// Module parameters
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
char cmdtype[3];
|
||||
char servic_id[5];
|
||||
char payload_len[5];
|
||||
char imei_len[5];
|
||||
char imei[60];
|
||||
char imsi_len[5];
|
||||
char imsi[60];
|
||||
char iccid_len[5];
|
||||
char iccid[60];
|
||||
char heartbeat_time_len[5];
|
||||
char heartbeat_time[9];//心跳周期 0~100
|
||||
char manufacturer_name_len[5];
|
||||
char manufacturer_name[40];//厂家 名称
|
||||
char terminal_type_len[5];
|
||||
char terminal_type[25];//终端类型
|
||||
char hardware_version_len[5];
|
||||
char hardware_version[11];//硬件版本
|
||||
char software_version_len[5];
|
||||
char software_version[11];//软件版本
|
||||
char battery_value[9];//电池电压,浮点型0~5
|
||||
char battery_voltage[9];//电池电量 整形 1-100
|
||||
|
||||
} TsModule_Info_t;
|
||||
|
||||
// Network service information
|
||||
typedef struct
|
||||
{
|
||||
char cmdtype[3];
|
||||
char servic_id[5];
|
||||
char payload_length[5];
|
||||
char rat[16];//整型。无线接入模式
|
||||
char rsrp[16];//整型,参考信号接收功率,-1400~-440,无效值位-32768
|
||||
char rssi[16];//整形,接收的信号强度指示 -1330~-250,无效值-32768
|
||||
char tx_power[32];//整形,最近一次的发送功率,-400~230,无效值-32768
|
||||
char tx_time[16];//整型,上行累计的发送时长,单位ms,无效值为0
|
||||
char rx_time[16];//整型,下行累计的接收时长,单位ms,无效值0
|
||||
char last_cellid[16];//十六进制字符串,上一次SIB1小区信息,十六进制28BIT的cellid,有效值为0~0xFFFFFFE,无效值为0xFFFFFFFF
|
||||
char last_ecl[16];//整型。上一次的ECL值,普通覆盖还是增强覆盖,有效值取0,1,2,
|
||||
char last_sinr[16];//整形。上一次的SINR值,有效值为-180~-300,无效值为-32768
|
||||
char last_earfcn[16];//整形,上一次的EARFCN值,对应当前服务小区的下行频点号,有效值为0~68535,无效值为-1
|
||||
char last_pci[16];//整形,上一次的PIC值,对应当前小区的物理ID,有效值为0-503,无效值为65535
|
||||
char rsrq[16];//整型,参考信号接收质量,-195~-30,无效值-32768
|
||||
|
||||
}Ts_Network_Service_Info_t;
|
||||
|
||||
extern IotFlagStruct IotFlag_t;
|
||||
extern struct tm Network_Time_t;
|
||||
|
||||
|
||||
static void BSP_Ml307_Power_Off(void);
|
||||
|
@ -63,6 +117,7 @@ void BSP_ML307_SetActive(void);
|
|||
void BSP_ML307_SendMessage(void);
|
||||
static void BSP_Read_Module(void);
|
||||
static void BSP_simcom_init(void);
|
||||
static void BSP_Get_Module_Info(void);
|
||||
static void BSP_Module_Connect_CtWing(void);
|
||||
#endif //!@__BSP_ML307R_H__
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
#include "bsp_iwdg.h"
|
||||
#include "bsp_bmp390.h"
|
||||
#include "bsp_tim.h"
|
||||
|
||||
#include "time.h"
|
||||
#include <stdlib.h>
|
||||
#undef LOG_ENABLE
|
||||
#define LOG_ENABLE 1
|
||||
|
||||
|
@ -20,12 +21,12 @@ IotFlagStruct IotFlag_t;
|
|||
|
||||
MultiTimer Multi_Power_ON_t; //开机
|
||||
MultiTimer Multi_Power_OFF_t; //关机
|
||||
MultiTimer Multi_Restart_t; //重启
|
||||
MultiTimer Multi_Cpin_t; //cpin
|
||||
MultiTimer Multi_Connect_t; //Connect
|
||||
MultiTimer Multi_Send_t; //Send
|
||||
MultiTimer Multi_Restart_t; //重启
|
||||
MultiTimer Multi_Cpin_t; //cpin
|
||||
MultiTimer Multi_Connect_t; //Connect
|
||||
MultiTimer Multi_Send_t; //Send
|
||||
MultiTimer Multi_StopTask_t; //StopTask
|
||||
MultiTimer Multi_Loop_t; //Loop
|
||||
MultiTimer Multi_Loop_t; //Loop
|
||||
|
||||
// 电源状态
|
||||
typedef enum {
|
||||
|
@ -65,7 +66,6 @@ void At_Debug(const char *fmt, ...)
|
|||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
}
|
||||
|
||||
void Ml307_Delay_Ms(uint16_t ms)
|
||||
|
@ -96,7 +96,7 @@ static uint8_t state = 0;
|
|||
#define CPIN_RETRY_INTERVAL_TIME (20*1000UL)
|
||||
#define CONNECT_RETRY_INTERVAL_TIME (20*1000UL)
|
||||
#define SEND_RETRY_INTERVAL_TIME (30*1000UL)
|
||||
#define STOP_TASK_INTERVAL_TIME (20*1000UL)
|
||||
#define STOP_TASK_INTERVAL_TIME (25*1000UL)
|
||||
#define LOOP_INTERVAL_TIME (30*1000UL)
|
||||
|
||||
//开机回调
|
||||
|
@ -172,6 +172,335 @@ static const urc_item_t urc_table[] =
|
|||
{.prefix = "+CPIN: READY", .endmark = '\n', .handler = URC_Module_Ready_Cb},//模块准备就绪
|
||||
};
|
||||
|
||||
|
||||
uint64_t imei_dec = 0;//十进制的IMEI,用作随机时延的入参
|
||||
TsModule_Info_t Module_Info_t = {0};
|
||||
//Convert strings to hexadecimal strings and store them in hex_arry
|
||||
void Module_String2Hex(char *hex_arry, char *str)
|
||||
{
|
||||
for (int i = 0; i < strlen(str); i++)
|
||||
{
|
||||
sprintf(hex_arry + (i * 2), "%02X", str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void Module_Get_Imei_Cb(at_response_t *r)
|
||||
{
|
||||
char imei[16] = {0};
|
||||
if (r->code == AT_RESP_OK)
|
||||
{
|
||||
if (sscanf(r->prefix, "+GSN:%s\r\n", imei) == 1)
|
||||
{
|
||||
logDebug("imei: %s\r\n", imei);
|
||||
imei_dec = strtoll(imei, NULL, 10);
|
||||
Module_String2Hex(Module_Info_t.imei, imei);
|
||||
sprintf(Module_Info_t.imei_len, "%04X", strlen(Module_Info_t.imei)/2);
|
||||
logDebug("Module_Info_t.imei: %s\r\n", Module_Info_t.imei);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logDebug("'CGSN' command response failed!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 获取IMEI数据
|
||||
* @return
|
||||
*/
|
||||
static void Module_Get_Imei(void)
|
||||
{
|
||||
at_attr_t attr;
|
||||
at_attr_deinit(&attr);
|
||||
attr.prefix = "+GSN:";
|
||||
attr.cb = Module_Get_Imei_Cb;
|
||||
at_send_singlline(ml307r_obj, &attr, "AT+GSN=1");
|
||||
}
|
||||
|
||||
static void Module_Get_Imsi_Cb(at_response_t *r)
|
||||
{
|
||||
char imsi[60] = {0};
|
||||
if (r->code == AT_RESP_OK)
|
||||
{
|
||||
if (sscanf(r->prefix, "%s\r\n", imsi) == 1)
|
||||
{
|
||||
logDebug("imsi:%s\r\n",imsi);
|
||||
Module_String2Hex(Module_Info_t.imsi, imsi);
|
||||
sprintf( Module_Info_t.imsi_len, "%04X", strlen(Module_Info_t.imsi)/2);
|
||||
logDebug("Module_Info_t.imsi: %s\r\n", Module_Info_t.imsi);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logDebug("'AT+CIMI' command response failed!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 获取IMSI数据
|
||||
* @return
|
||||
*/
|
||||
static void Module_Get_Imsi(void)
|
||||
{
|
||||
at_attr_t attr;
|
||||
at_attr_deinit(&attr);
|
||||
attr.prefix = "46";
|
||||
attr.suffix = "\r\n";
|
||||
attr.cb = Module_Get_Imsi_Cb;
|
||||
at_send_singlline(ml307r_obj, &attr, "AT+CIMI");
|
||||
}
|
||||
|
||||
|
||||
static void Module_Get_Iccid_Cb(at_response_t *r)
|
||||
{
|
||||
char iccid[30] = {0};
|
||||
|
||||
if (r->code == AT_RESP_OK)
|
||||
{
|
||||
//+QCCID: 898604D3102280304162
|
||||
if (sscanf(r->prefix, "+MCCID: %s", iccid) == 1)
|
||||
{
|
||||
logDebug("iccid: %s\r\n", iccid);
|
||||
Module_String2Hex(Module_Info_t.iccid, iccid);
|
||||
sprintf( Module_Info_t.iccid_len, "%04X", strlen(Module_Info_t.iccid)/2);
|
||||
logDebug("Module_Info_t.iccid: %s\r\n", Module_Info_t.iccid);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logDebug("'AT+QCCID' command response failed!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 获取ICCID数据
|
||||
* @return
|
||||
*/
|
||||
static void Module_Get_Iccid(void)
|
||||
{
|
||||
at_attr_t attr;
|
||||
at_attr_deinit(&attr);
|
||||
attr.prefix = "+MCCID:";
|
||||
attr.cb = Module_Get_Iccid_Cb;
|
||||
at_send_singlline(ml307r_obj, &attr, "AT+MCCID");
|
||||
}
|
||||
|
||||
|
||||
//从字符串中提取特定格式的时间信息。
|
||||
void find_and_extract(char* string_buf, char* result)
|
||||
{
|
||||
const char *start = "+CCLK: \"";
|
||||
const char *end = "+32\"";
|
||||
|
||||
char *s = strstr(string_buf, start);
|
||||
if(s)
|
||||
{
|
||||
s += strlen(start);
|
||||
char *e = strstr(s, end);
|
||||
if(e)
|
||||
{
|
||||
*e = '\0';
|
||||
strncpy(result, s, e-s+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 时区设置:默认东八区
|
||||
*/
|
||||
#define TIMER_ZONE (8U)
|
||||
|
||||
// 将本地时间转换为对应时区时间
|
||||
static void Time_Zone_Conversion(struct tm* timeInfo)
|
||||
{
|
||||
// 根据时区差异进行转换,这里时区差为8小时,没有分钟差异。
|
||||
timeInfo -> tm_hour += TIMER_ZONE; //小时部分加8小时
|
||||
if (timeInfo -> tm_hour >= 24)
|
||||
{ //如果超过24小时,则天数加1,小时数减24。
|
||||
timeInfo -> tm_mday++;
|
||||
timeInfo -> tm_hour -= 24;
|
||||
if (timeInfo -> tm_mday >365)
|
||||
{
|
||||
timeInfo -> tm_year += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct tm Network_Time_t;//网络时间
|
||||
|
||||
static void Module_Timer_Cb(at_response_t *r)
|
||||
{
|
||||
int year, mounth, days, hous, min, sec;
|
||||
|
||||
char urc_buf[32] = {0};
|
||||
|
||||
if (r->code == AT_RESP_OK)
|
||||
{
|
||||
// +CCLK: "24/02/01,05:11:35+32"
|
||||
find_and_extract(r->recvbuf, urc_buf);
|
||||
if(sscanf(urc_buf, "%d/%d/%d,%d:%d:%d", &year, &mounth, &days, &hous, &min, &sec) == 6)
|
||||
{
|
||||
logDebug("urc_buf:%s\r\n", urc_buf);
|
||||
Network_Time_t.tm_year = (2000 + year);
|
||||
Network_Time_t.tm_mon = mounth;
|
||||
Network_Time_t.tm_mday = days;
|
||||
Network_Time_t.tm_hour = hous;//此时为零区时间,需要转化为东八区
|
||||
Network_Time_t.tm_min = min;
|
||||
Network_Time_t.tm_sec = sec;
|
||||
Time_Zone_Conversion(&Network_Time_t);//时区设置
|
||||
|
||||
// RTC_InitTime(Network_Time_t.tm_year, Network_Time_t.tm_mon, Network_Time_t.tm_mday,
|
||||
// Network_Time_t.tm_hour, Network_Time_t.tm_min, Network_Time_t.tm_sec); //更新当前时间
|
||||
// IotFlag_t.update_time_flag = 1;
|
||||
logDebug("NET Timer :%04d-%02d-%02d, %02d:%02d:%02d\r\n", Network_Time_t.tm_year, Network_Time_t.tm_mon, Network_Time_t.tm_mday,
|
||||
Network_Time_t.tm_hour, Network_Time_t.tm_min, Network_Time_t.tm_sec);
|
||||
}
|
||||
else
|
||||
{
|
||||
logDebug("Network time resolution failed\r\n");//网络时间解析失败
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logDebug("Network time acquisition failed\r\n");//网络时间获取失败
|
||||
}
|
||||
}
|
||||
|
||||
static void Module_Timer(void)
|
||||
{
|
||||
at_attr_t attr;
|
||||
|
||||
at_attr_deinit(&attr);
|
||||
attr.cb = Module_Timer_Cb;
|
||||
at_send_singlline(ml307r_obj, &attr, "AT+CCLK?");
|
||||
}
|
||||
|
||||
|
||||
Ts_Network_Service_Info_t Service_Info_t = {0};
|
||||
|
||||
static void Module_NetWork_Info_Cb(at_response_t *r)
|
||||
{
|
||||
if (r->code == AT_RESP_OK)
|
||||
{
|
||||
//"radio",<rat>,<rsrp>,<rssi>,<tx_power>,<tx_time>,<rx_time>,<last_cellid>,<last_ecl>,<last_sinr>,<last_earfcn>,<last_pci>,<rsrq>
|
||||
//+MUESTATS: "radio",4,-660,-400,-32768,0,0,0FB5E606,255,280,38950,22,-60)
|
||||
char *token = strtok(r->prefix, ",");
|
||||
int i = 0;
|
||||
while (token != NULL)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
i++;
|
||||
token = strtok(NULL, ",");
|
||||
continue;
|
||||
}
|
||||
char hex_str[20] = {0};
|
||||
if ((i == 2)||(i == 3)||(i == 4)||(i == 12))
|
||||
{
|
||||
long int num = strtol((token+1), NULL, 10);
|
||||
sprintf(hex_str, "%08X", num);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i != 7)
|
||||
{
|
||||
long int num = strtol(token, NULL, 10);
|
||||
if ((i == 2)||(i == 9))
|
||||
{
|
||||
// num = num*10;
|
||||
sprintf(hex_str, "%08X", num);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(hex_str, "%08X", num);
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (i)
|
||||
{
|
||||
case 1:
|
||||
strcpy(Service_Info_t.rat, hex_str);
|
||||
break;
|
||||
case 2:
|
||||
strcpy(Service_Info_t.rsrp, hex_str);
|
||||
break;
|
||||
case 3:
|
||||
strcpy(Service_Info_t.rssi, hex_str);
|
||||
break;
|
||||
case 4:
|
||||
sprintf(Service_Info_t.tx_power,"%08s", hex_str);
|
||||
|
||||
break;
|
||||
case 5:
|
||||
strcpy(Service_Info_t.tx_time, hex_str);
|
||||
break;
|
||||
case 6:
|
||||
strcpy(Service_Info_t.rx_time, hex_str);//rsrp实际值x10上
|
||||
break;
|
||||
case 7:
|
||||
strncpy(hex_str, token+1, 8);
|
||||
sprintf(Service_Info_t.last_cellid,"%08s", hex_str);
|
||||
break;
|
||||
case 8:
|
||||
strcpy(Service_Info_t.last_ecl, hex_str);//sinr实际值x10上报
|
||||
break;
|
||||
case 9:
|
||||
strcpy(Service_Info_t.last_sinr, hex_str);
|
||||
break;
|
||||
case 10:
|
||||
strcpy(Service_Info_t.last_earfcn, hex_str);
|
||||
break;
|
||||
case 11:
|
||||
strcpy(Service_Info_t.last_pci, hex_str);
|
||||
break;
|
||||
case 12:
|
||||
strcpy(Service_Info_t.rsrq, hex_str);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
token = strtok(NULL, ",");
|
||||
}
|
||||
// logDebug("Service_Info_t = %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\r\n", Service_Info_t.rat,
|
||||
// Service_Info_t.rsrp,Service_Info_t.rssi,Service_Info_t.tx_power,Service_Info_t.tx_time,
|
||||
// Service_Info_t.rx_time,Service_Info_t.last_cellid,Service_Info_t.last_ecl,Service_Info_t.last_sinr,
|
||||
// Service_Info_t.last_earfcn,Service_Info_t.last_pci,Service_Info_t.rsrq);
|
||||
}
|
||||
else
|
||||
{
|
||||
logDebug("AT+MUESTATS=radio command response failed!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 获取连接网络的参数信息
|
||||
* @return
|
||||
*/
|
||||
static void Module_NetWork_Info(void)
|
||||
{
|
||||
at_attr_t attr;
|
||||
|
||||
at_attr_deinit(&attr);
|
||||
attr.prefix = "+MUESTATS: ";
|
||||
attr.cb = Module_NetWork_Info_Cb;
|
||||
at_send_singlline(ml307r_obj, &attr, "AT+MUESTATS=\"radio\"");
|
||||
}
|
||||
|
||||
|
||||
static void BSP_Get_Module_Info(void)
|
||||
{
|
||||
at_send_data(ml307r_obj, NULL, "+++", 3); // 退出透传模式
|
||||
Module_Get_Imei();
|
||||
Module_Get_Imsi();
|
||||
Module_Get_Iccid();
|
||||
Module_Timer();
|
||||
Module_NetWork_Info(); // 获取网络连接信息
|
||||
at_send_singlline(ml307r_obj, NULL, "AT+MIPMODE=0,1"); // 进入透传模式
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @brief 创建设备
|
||||
* @return
|
||||
|
@ -182,7 +511,7 @@ static int BSP_Module_Connect_CtWing_Handle(at_env_t *e)
|
|||
{
|
||||
case 0:
|
||||
logDebug("create device...\r\n");
|
||||
e->println(e, "AT+MIPOPEN=0,\"TCP\",\"112.125.89.8\",47602,,1"); // 8.135.10.183,32994
|
||||
e->println(e, "AT+MIPOPEN=0,\"TCP\",\"112.125.89.8\",45600,,1"); // 8.135.10.183,32994
|
||||
e->reset_timer(e);
|
||||
e->state++;
|
||||
break;
|
||||
|
@ -225,6 +554,7 @@ void BSP_Module_Send_Data(uint8_t* data, uint8_t len)
|
|||
|
||||
void BSP_ML307_SendMessage(void)
|
||||
{
|
||||
BSP_Get_Module_Info(); //获取sim信息
|
||||
if(fault_state){
|
||||
char json_buffer[300];
|
||||
snprintf(json_buffer, sizeof(json_buffer),
|
||||
|
@ -251,7 +581,7 @@ void BSP_ML307_SendMessage(void)
|
|||
"}"
|
||||
"}");
|
||||
|
||||
BSP_Module_Send_Data((uint8_t*)json_buffer, strlen(json_buffer));
|
||||
// BSP_Module_Send_Data((uint8_t*)json_buffer, strlen(json_buffer));
|
||||
// logDebug("fault_state: %d\n", fault_state);
|
||||
IotFlag_t.send_complete_flag = 1;
|
||||
logDebug("BSP_ML307_SendMessage: %s\n", json_buffer);
|
||||
|
@ -481,8 +811,7 @@ static void BSP_Iot_Loop(void)
|
|||
}
|
||||
if (IotFlag_t.sim_success_flag) //sim成功
|
||||
{
|
||||
logDebug("BSP_Get_Module_Info!\r\n");
|
||||
// BSP_Get_Module_Info(); //获取sim信息
|
||||
logDebug("BSP_Get_Module_Info!!!\r\n");
|
||||
MultiTimerStop(&Multi_Cpin_t);
|
||||
state++;
|
||||
}
|
||||
|
@ -539,10 +868,10 @@ static void BSP_Iot_Loop(void)
|
|||
case 5: //处理
|
||||
if(IotFlag_t.send_complete_flag == 1)
|
||||
{
|
||||
logDebug("send_complete_into_stop\r\n");
|
||||
IotFlag_t.send_complete_flag = 0;
|
||||
state = 0;
|
||||
MultiTimerStart(&Multi_StopTask_t, STOP_TASK_INTERVAL_TIME, StopTask_CallBack, NULL); //关闭
|
||||
logDebug("send_complete_into_stop\r\n");
|
||||
IotFlag_t.send_complete_flag = 0;
|
||||
state = 0;
|
||||
MultiTimerStart(&Multi_StopTask_t, STOP_TASK_INTERVAL_TIME, StopTask_CallBack, NULL); //关闭
|
||||
}else
|
||||
{
|
||||
if (IotFlag_t.Loop_count_flag > 2)
|
||||
|
@ -566,44 +895,6 @@ static void BSP_Iot_Loop(void)
|
|||
}
|
||||
}
|
||||
|
||||
static int Module_Read_State(at_env_t *e)
|
||||
{
|
||||
switch (e->state)
|
||||
{
|
||||
case 0:
|
||||
e->obj->adap->debug("Check if the Module is ready\r\n");
|
||||
e->println(e, "AT");
|
||||
e->reset_timer(e);
|
||||
e->state++;
|
||||
break;
|
||||
case 1:
|
||||
if (e->contains(e, "OK"))
|
||||
{
|
||||
e->recvclr(e);
|
||||
e->finish(e, AT_RESP_OK);
|
||||
e->obj->adap->debug("Module is ready\r\n");
|
||||
// BSP_Stop_ML307_Task();
|
||||
}
|
||||
if (e->is_timeout(e, 5000))
|
||||
{
|
||||
e->state--;
|
||||
if (++e->i > 3)
|
||||
{
|
||||
e->obj->adap->debug("Module error\r\n");
|
||||
e->finish(e, AT_RESP_ERROR);
|
||||
// BSP_Stop_ML307_Task();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static void BSP_Read_Module(void)
|
||||
{
|
||||
at_do_work(ml307r_obj, NULL, Module_Read_State); // 重启后生效
|
||||
}
|
||||
|
||||
|
||||
void Ml307r_Loop(void)
|
||||
{
|
||||
FEED_IWDG();
|
||||
|
@ -626,18 +917,15 @@ uint16_t Ml307r_Handle(uint8_t task_id, uint16_t events)
|
|||
|
||||
void BSP_Ml307r_Init(void)
|
||||
{
|
||||
// if(ml307_power_state == POWER_STATE_INIT)
|
||||
// {
|
||||
Ml307r_Gpio_Init();
|
||||
BSP_UART1_Init();
|
||||
ml307r_obj = at_obj_create(&at_adapter);//Create AT communication object
|
||||
if(ml307r_obj != NULL)
|
||||
{
|
||||
at_obj_set_urc(ml307r_obj, urc_table, sizeof(urc_table) / sizeof(urc_table[0]));
|
||||
IotFlag_t.module_init_flag = 1;
|
||||
BSP_BlockSleep();
|
||||
}
|
||||
ml307_task_id = TMOS_ProcessEventRegister(Ml307r_Handle);
|
||||
tmos_set_event(ml307_task_id, ML307_PERIODIC_EVT);
|
||||
// }
|
||||
Ml307r_Gpio_Init();
|
||||
BSP_UART1_Init();
|
||||
ml307r_obj = at_obj_create(&at_adapter);//Create AT communication object
|
||||
if(ml307r_obj != NULL)
|
||||
{
|
||||
at_obj_set_urc(ml307r_obj, urc_table, sizeof(urc_table) / sizeof(urc_table[0]));
|
||||
IotFlag_t.module_init_flag = 1;
|
||||
BSP_BlockSleep();
|
||||
}
|
||||
ml307_task_id = TMOS_ProcessEventRegister(Ml307r_Handle);
|
||||
tmos_set_event(ml307_task_id, ML307_PERIODIC_EVT);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ uint32_t BSP_Get_Tick(void)
|
|||
/* Platform implementation */
|
||||
// return tick_1ms_cnt;
|
||||
// return (uint32_t)((double)TMOS_GetSystemClock() / 1.6);
|
||||
return (uint32_t)((double)TMOS_GetSystemClock() / 2.3); // 定时不准,临时修改
|
||||
uint32_t tmos_time = TMOS_GetSystemClock();
|
||||
// 精确地使用整数计算而非浮点数进行转换
|
||||
return (tmos_time * 417) / 1000; // 0.625ms到ms的转换 //417=625/1.5
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue