优化了一下网络连接,
This commit is contained in:
parent
a26e8a73b5
commit
b274562f53
|
@ -2,7 +2,7 @@
|
|||
* @Author: mbw
|
||||
* @Date: 2024-10-23 17:14:16
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2025-06-06 08:48:12
|
||||
* @LastEditTime: 2025-06-06 14:00:40
|
||||
* @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c
|
||||
* @Descrt_thread_
|
||||
*
|
||||
|
@ -302,7 +302,7 @@ int main(void)
|
|||
LOG_D("工作时长:%d", work_duration);
|
||||
// 读取历史记录总数
|
||||
g_Calibration_status = Flash_Get_Calibration_State();
|
||||
rt_thread_mdelay(100);
|
||||
rt_thread_mdelay(10);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@
|
|||
* @Author: mbw
|
||||
* @Date: 2024-11-30 15:46:21
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2025-06-06 08:37:07
|
||||
* @LastEditTime: 2025-06-06 14:02:27
|
||||
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_ml307.c
|
||||
* @Description:
|
||||
*
|
||||
|
@ -26,7 +26,7 @@
|
|||
#if IOT_MODULE_SWITCH == 1
|
||||
#define ML307_THREAD_STACK_SIZE (4096 + 2048)
|
||||
#define ML307_RECV_THREAD_STACK_SIZE (4096 + 2048)
|
||||
#define ML307_LIFE_THREAD_STACK_SIZE (4096+1024)
|
||||
#define ML307_LIFE_THREAD_STACK_SIZE (4096 + 1024)
|
||||
#define ML307_THREAD_PRIORITY 25
|
||||
#define ML307_THREAD_TICKS 50
|
||||
#define ML307_RECV_THREAD_PRIORITY 24
|
||||
|
@ -305,25 +305,24 @@ int BSP_Ml307_Init (struct Ml307_Ops *ops, rt_uint8_t version)
|
|||
#include <stdint.h>
|
||||
|
||||
// 将十进制转换为BCD格式(例如:33 -> 0x33)
|
||||
uint8_t dec_to_bcd(uint8_t dec)
|
||||
uint8_t dec_to_bcd (uint8_t dec)
|
||||
{
|
||||
return ((dec / 10) << 4) | (dec % 10);
|
||||
}
|
||||
|
||||
|
||||
int test(int argc, char **argv)
|
||||
int test (int argc, char **argv)
|
||||
{
|
||||
uint8_t a = atoi(argv[1]);
|
||||
uint8_t a = atoi (argv[1]);
|
||||
rt_uint8_t b = a;
|
||||
|
||||
LOG_D("in = 0x%02X, %d", a, a);
|
||||
LOG_D ("in = 0x%02X, %d", a, a);
|
||||
b = a;
|
||||
b = dec_to_bcd(b);
|
||||
LOG_D("in = 0x%02X, %d", b, b);
|
||||
b = dec_to_bcd (b);
|
||||
LOG_D ("in = 0x%02X, %d", b, b);
|
||||
return b;
|
||||
}
|
||||
MSH_CMD_EXPORT(test, "test");
|
||||
|
||||
MSH_CMD_EXPORT (test, "test");
|
||||
|
||||
int _Update_Valve_Data (struct Ml307_Ops *ops)
|
||||
{
|
||||
|
@ -338,7 +337,7 @@ int _Update_Valve_Data (struct Ml307_Ops *ops)
|
|||
LOG_D ("valve_num: %d", ops->body->valve_num);
|
||||
rt_memcpy (&ops->body->valve_data[0], &valve[0], sizeof (struct valve_t));
|
||||
// rt_memset(&valve[0].valve_connct_status, 0, (sizeof(struct valve_t) - 7)); // 清空阀门包数据,等待下次更新,如果没更新说明断开了
|
||||
ops->body->valve_data[0].valve_voltage = dec_to_bcd(ops->body->valve_data[0].valve_voltage);
|
||||
ops->body->valve_data[0].valve_voltage = dec_to_bcd (ops->body->valve_data[0].valve_voltage);
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
@ -975,7 +974,7 @@ int Ml307_Process_Events (Ml307Event ml307_recv_event, struct at_device *device,
|
|||
if (event) // 处理该事件
|
||||
{
|
||||
// 打印事件的名称
|
||||
ml307_disconnect_retry_flag = 0;//有事件,则断连重试标志清空
|
||||
ml307_disconnect_retry_flag = 0; // 有事件,则断连重试标志清空
|
||||
ml307_current_evnet = event->event_flag;
|
||||
for (size_t i = 0; i < max_retry_count; i++)
|
||||
{
|
||||
|
@ -986,6 +985,7 @@ int Ml307_Process_Events (Ml307Event ml307_recv_event, struct at_device *device,
|
|||
#ifdef TEST_ENABLE
|
||||
RTC_ShowTime(); // 每次发送打印下时间,容易定位问题
|
||||
#endif
|
||||
cnt++;
|
||||
LOG_D ("%s上报, cnt :%d", event->event_name, cnt);
|
||||
|
||||
int result = event->send_func (device, ml307_ops);
|
||||
|
@ -1008,7 +1008,6 @@ int Ml307_Process_Events (Ml307Event ml307_recv_event, struct at_device *device,
|
|||
{
|
||||
// 收不到说明在平台未注册或者信号不行,此时ml307_connect_sever_flag 为0,但ml307_conncet_tcp_flag = 1;此时不发起重连,等待事件触发就行
|
||||
ret = RT_ERROR;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1049,12 +1048,12 @@ int Ml307_Process_Events (Ml307Event ml307_recv_event, struct at_device *device,
|
|||
|
||||
if (!ml307_disconnect_retry_flag)
|
||||
{
|
||||
LOG_D("与服务器断开,重连网络中");
|
||||
LOG_D ("与服务器断开,重连网络中");
|
||||
rt_sem_release (ml307_disconnect_sem);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D ("与服务区断开连接,等待连接中......\n");
|
||||
LOG_D ("与服务区断开连接,等待连接中......\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1814,7 +1813,7 @@ static void Ml307_Send_Thread_Entry (void *param)
|
|||
{
|
||||
LOG_E ("ml307 send data failed result = [%d]\n", result);
|
||||
}
|
||||
rt_thread_mdelay(5000);
|
||||
rt_thread_mdelay (5000);
|
||||
Ml307_Send_Event (kMl307HeartbeatEvent);
|
||||
}
|
||||
else if (ml307_recv_event & Ml307_Get_Event_Flag (KMl307ValveDisconnectEvent))
|
||||
|
@ -2020,12 +2019,38 @@ static void Ml307_Life_Thread_Entry (void *parameter)
|
|||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
}
|
||||
if (at_obj_exec_cmd(device->client, resp, "AT+CEREG=1") != RT_EOK)
|
||||
if (at_obj_exec_cmd (device->client, resp, "AT+CEREG=1") != RT_EOK)
|
||||
{
|
||||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
}
|
||||
rt_uint8_t i = 0;
|
||||
/* check the GPRS network is registered */
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
if (at_obj_exec_cmd (device->client, resp, "AT+CEREG?") == RT_EOK)
|
||||
{
|
||||
int link_stat = 0;
|
||||
|
||||
if (at_resp_parse_line_args_by_kw (resp, "+CEREG:", "+CEREG: %*d,%d", &link_stat) > 0)
|
||||
{
|
||||
if ((link_stat == 1) || (link_stat == 5))
|
||||
{
|
||||
LOG_D ("%s device GPRS is registered", device->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
rt_thread_mdelay (1000);
|
||||
}
|
||||
if (i == 10)
|
||||
{
|
||||
LOG_E ("%s device GPRS is register failed", device->name);
|
||||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
|
||||
/* check SIM card */
|
||||
for (i = 0; i < 60; i++)
|
||||
{
|
||||
|
@ -2072,7 +2097,28 @@ static void Ml307_Life_Thread_Entry (void *parameter)
|
|||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
for (i = 0; i < 60; i++)
|
||||
{
|
||||
if (at_obj_exec_cmd (device->client, resp, "AT+CGACT=1") == RT_EOK)
|
||||
{
|
||||
LOG_D ("pdp激活成功");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// AT+CGACT=0,1 //去激活 PDP
|
||||
if (at_obj_exec_cmd (device->client, resp, "AT+CGACT=0") == RT_EOK)
|
||||
{
|
||||
LOG_D ("pdp去激活成功");
|
||||
}
|
||||
}
|
||||
rt_thread_mdelay (5000);
|
||||
}
|
||||
if (i == 60)
|
||||
{
|
||||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
}
|
||||
/* check the GPRS network is registered */
|
||||
for (i = 0; i < 60; i++)
|
||||
{
|
||||
|
|
|
@ -134,7 +134,7 @@
|
|||
#define RT_USING_AT
|
||||
// #define NETDEV_USING_PING//用来监测和平台之间的延时
|
||||
#ifdef ENABLE_LOG_ALL
|
||||
// #define AT_DEBUG
|
||||
#define AT_DEBUG
|
||||
#endif
|
||||
|
||||
#define AT_USING_CLIENT
|
||||
|
|
Loading…
Reference in New Issue