将标定值改为1600,预热时间改为3min,加了断电关阀功能

This commit is contained in:
小马_666 2025-01-04 16:08:24 +08:00
parent d446e2a999
commit 9a7c78302f
8 changed files with 234 additions and 276 deletions

View File

@ -2,7 +2,7 @@
* @Author: mbw
* @Date: 2024-10-23 17:14:16
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-02 17:29:27
* @LastEditTime: 2025-01-04 16:01:41
* @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c
* @Descrt_thread_
*
@ -149,8 +149,8 @@ void Preheat_Timer_Callback(void *parameter)
int main(void)
{
// 定义超时时间,单位为毫秒
// #define TIMEOUT_MS 3 * 60 * 1000
#define TIMEOUT_MS 8 * 1000
#define TIMEOUT_MS 3 * 60 * 1000
// #define TIMEOUT_MS 8 * 1000
#define WORK_TIMER_CNT (1000 * 60 * 60 * 24)
rt_err_t result = RT_EINVAL;
rt_uint32_t received_event;
@ -381,7 +381,7 @@ int main(void)
Flash_Write_Record(kRecordFault);
LED_Y_FAULT;
BEEP_FAULT;
// BEEP_FAULT;
#if (IOT_MODULE_SWITCH == 1)
Ml307_Send_Event(kMl307FaultEvent);
@ -421,7 +421,7 @@ int main(void)
SysControl.last_status = SysControl.status;
SysControl.status = kPowerDownEvent;
GAS_POWER_CLOSE;
// 写入掉电记录
Flash_Write_Record(kRecordPowerDown);
@ -431,7 +431,9 @@ int main(void)
#endif
if (Flash_Get_Valve_Num())
{
Bt_Valve_Handler(kValveCmdCtr, 0, RT_NULL);
rt_uint8_t mac_addr[6];
Flash_Get_Mac_Addr(mac_addr, 1);
Bt_Valve_Handler(kValveCmdCtr, 1, mac_addr);
if (rt_sem_take(&bt_ctr_sem, 10000) == RT_EOK)
{
LOG_D("电磁阀动作完成");
@ -441,7 +443,7 @@ int main(void)
LOG_E("电磁阀动作失败");
}
}
GAS_POWER_CLOSE;
LOG_D("Enter AnalogWatchdog Interrupt");
// 等待30s,要是还没断电就重启
for (uint8_t i = 0; i < 30; i++)

View File

@ -17,7 +17,7 @@
#define SYS_PREHEAT_TIME_S (10U)
#define SYS_MUTE_TIME_S (uint8_t)(10 * 3)
#define MAX_EXPIRATION_DAYS (uint16_t)(365 * 10 + 30 * 3)
#define MAX_EXPIRATION_DAYS (uint16_t)(365 * 5 + 30 * 3)
typedef enum
{

View File

@ -67,14 +67,14 @@ extern agile_led_t *led_y;
LED_ON(g); \
} while (0U)
//网络连接指示灯
//网络连接断开指示灯
#define LED_G_INTERNET \
do \
{ \
LED_STOP(r); \
LED_STOP(g); \
LED_STOP(y); \
LED_CTRL(g, "500,500", -1);\
LED_CTRL(g, "500,1000", -1);\
LED_START(g);\
} while (0U)

View File

@ -2,7 +2,7 @@
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-09-04 13:33:49
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-03 16:44:30
* @LastEditTime: 2025-01-04 15:48:16
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\at_device_ml307.c
* @Description :
*
@ -46,7 +46,6 @@
#define ML307_THREAD_STACK_SIZE (4096)
#define ML307_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 2)
ml307_sys_info ml307 = {0};
struct rt_completion ml307_init_complate;
volatile rt_uint8_t socket_id = 0;
@ -96,7 +95,7 @@ static rt_err_t ml307_power_off(struct at_device *device)
rt_thread_mdelay(ML307_POWER_OFF_TIME * RT_TICK_PER_SECOND);
rt_pin_write(ml307->power_pin, PIN_LOW);
rt_thread_mdelay(100);
return RT_EOK;
}
@ -105,7 +104,7 @@ rt_err_t Ml307_Reset(struct at_device *device)
rt_pin_write(ML307_RST_PIN, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(ML307_RST_PIN, PIN_LOW);
rt_sem_release(ml307_disconnect_sem);
rt_sem_release(ml307_disconnect_sem);
// at_client_send("AT+MREBOOT\r\n", rt_strlen("AT+MREBOOT\r\n"));
return RT_EOK;
@ -123,10 +122,10 @@ MSH_CMD_EXPORT(TEST_Ml307_Reset, "test_ml307_reset");
static void urc_tcp_recv(struct at_client *client, const char *data, rt_size_t size)
{
int id;
int len = 0;
rt_uint16_t crc16 = 0;
rt_uint16_t rec_crc16 = 0;
char crc16_buf[6] = {0};
int len = 0;
rt_uint16_t crc16 = 0;
rt_uint16_t rec_crc16 = 0;
char crc16_buf[6] = {0};
char data_buf[AT_CLIENT_RECV_BUFF_LEN] = {0};
rt_uint8_t recv_byte_buf[AT_CLIENT_RECV_BUFF_LEN] = {0};
@ -155,10 +154,10 @@ static void urc_tcp_recv(struct at_client *client, const char *data, rt_size_t s
{
rt_memset(ml307_ops.recv, 0, sizeof(struct Ml307RecvData)); // 清空结构体
rt_memcpy(ml307_ops.recv, recv_byte_buf, sizeof(struct Ml307RecvData));
if (ml307_ops.recv->recv_data.event_type != INSTRUCTION_HEART_BEAT)//加这个的原因就是如果有指令下发,会出现两个信号量,指令会执行两次,所以排除心跳包才释放信号量
if (ml307_ops.recv->recv_data.event_type != INSTRUCTION_HEART_BEAT) // 加这个的原因就是如果有指令下发,会出现两个信号量,指令会执行两次,所以排除心跳包才释放信号量
{
rt_sem_release(ml307_recv_sem);
}
}
}
else
{
@ -185,26 +184,25 @@ static void urc_tcp_connect_state(struct at_client *client, const char *data, rt
{
switch (err_code)
{
case 0:
LOG_D("TCP connect success");
ml307_conncet_tcp_flag = 1;
break;
case 571:
LOG_D("PDP激活失败");
ml307_conncet_tcp_flag = 0;
break;
default:
LOG_D("连接失败");
ml307_conncet_tcp_flag = 0;
break;
case 0:
ml307_conncet_tcp_flag = 1;
break;
case 571:
LOG_D("PDP激活失败");
ml307_conncet_tcp_flag = 0;
rt_sem_release(ml307_disconnect_sem);
break;
default:
LOG_D("连接失败");
ml307_conncet_tcp_flag = 0;
rt_sem_release(ml307_disconnect_sem);
break;
}
rt_sem_release(ml307_connect_flag_sem);//用于返回连接的标志量在连接函数中
rt_sem_release(ml307_disconnect_sem);
rt_sem_release(ml307_connect_flag_sem); // 用于返回连接的标志量在连接函数中
}
}
}
static void urc_tcp_disconnect(struct at_client *client, const char *data, rt_size_t size)
{
size_t state = 0, id;
@ -236,7 +234,7 @@ static void urc_tcp_disconnect(struct at_client *client, const char *data, rt_si
}
}
static void urc_sim_remove(struct at_client *client, const char *data, rt_size_t size)
void urc_sim_remove(struct at_client *client, const char *data, rt_size_t size)
{
LOG_D("SIM removed");
Send_Laser_Alarm_Event(kFaultEvent);
@ -247,7 +245,7 @@ static const struct at_urc urc_table[] = {
{"+MIPURC: \"disconn\"", "\r\n", urc_tcp_disconnect},
{"+MIPURC: \"rtcp\"", "\r\n", urc_tcp_recv},
{"+MATREADY", "\r\n", urc_device_reset},
{"+CPIN: SIM REMOVED", "\r\n", urc_sim_remove},
// {"+CPIN: SIM REMOVED", "\r\n", urc_sim_remove},
};
void show_resp_info(at_response_t resp)
@ -292,8 +290,8 @@ int at_device_ml307_disconnect_tcp(struct at_device *device)
static int at_device_ml307_connect_tcp(struct at_device *device)
{
flash_sever_info sever_info = {0};
rt_err_t ret = RT_ERROR;
flash_sever_info sever_info = {0};
rt_err_t ret = RT_ERROR;
ASSERT(device);
rt_uint8_t retry = (rt_uint8_t)Flash_Get_SysCfg(kIotRetryId);
at_response_t resp = at_create_resp(64, 2, 5000);
@ -319,23 +317,23 @@ static int at_device_ml307_connect_tcp(struct at_device *device)
if (rt_sem_take(ml307_connect_flag_sem, 10000) == RT_EOK)
{
if (ml307_conncet_tcp_flag)
{
{
LOG_D("ml307 connect to tcp server success");
ret = RT_EOK;
break;
}
else
{
{
LOG_E("ml307 connect to tcp server fail");
}
}
}
else if (at_resp_get_line_by_kw(resp, "+CME ERROR: 552") == RT_EOK)//已经连接了
else if (at_resp_get_line_by_kw(resp, "+CME ERROR: 552") == RT_EOK) // 已经连接了
{
ret = RT_EOK;
break;
}
else if (at_resp_get_line_by_kw(resp, "+CME ERROR: 559") == RT_EOK)//SOCKET错误
else if (at_resp_get_line_by_kw(resp, "+CME ERROR: 559") == RT_EOK) // SOCKET错误
{
ml307_conncet_tcp_flag = 0;
rt_sem_release(ml307_disconnect_sem);
@ -363,14 +361,14 @@ int at_send_data(struct at_device *device, const char *data, rt_size_t send_len)
if (at_obj_exec_cmd(device->client, resp, "AT+MIPCFG=\"encoding\",0,1,1") != RT_EOK)
{
return RT_ERROR;
}
}
if (at_obj_exec_cmd(device->client, resp, TCP_SEND_DATA, socket_id, send_len, data) == RT_EOK)
{
size_t len = 0;
if (at_resp_parse_line_args_by_kw(resp, "+MIPSEND:", "+MIPSEND:%*d,%d", &len) > 0)
{
if(len == send_len)
if (len == send_len)
{
LOG_D("send data success, len:%d", len);
at_delete_resp(resp);
@ -399,6 +397,21 @@ static int ml307_check_link_status(struct at_device *device)
LOG_E("no memory for resp create.");
return -RT_ERROR;
}
if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL?") < 0)
{
result = -RT_ERROR;
goto __exit;
}
//// 查询拨号状态
if (at_resp_parse_line_args_by_kw(resp, "+MIPCALL:", "+MIPCALL: %d,%*d,%*s", &link_stat) > 0)
{
if (link_stat == 1)
{
result = RT_EOK;
}
}
if (at_obj_exec_cmd(device->client, resp, "AT+CGACT?") < 0)
{
result = -RT_ERROR;
@ -455,6 +468,7 @@ static int ml307_netdev_set_info(struct netdev *netdev)
result = -RT_ENOMEM;
goto __exit;
}
device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_CONN, RT_NULL); // 打开连接
/* set network interface device IP address */
{
#define IP_ADDR_SIZE_MAX 16
@ -512,20 +526,26 @@ static void ml307_check_link_status_entry(void *parameter)
LOG_E("get device(%s) failed.", netdev->name);
return;
}
at_response_t resp = at_create_resp(ML307_IMEI_RESP_SIZE, 0, ML307_INFO_RESP_TIMO);
if (resp == RT_NULL)
{
LOG_E("no memory for resp create.");
return;
}
while (1)
{
link_status = ml307_check_link_status(device);
if (link_status < 0)
{
rt_thread_mdelay(ML307_LINK_DELAY_TIME);
at_exec_cmd(resp, "AT+MIPCALL=1,1");
continue;
}
/* check the network interface device link status */
if ((ML307_LINK_STATUS_OK == link_status) != netdev_is_link_up(netdev))
{
netdev_low_level_set_link_status(netdev, (ML307_LINK_STATUS_OK == link_status));
}
// /* check the network interface device link status */
// if ((ML307_LINK_STATUS_OK == link_status) != netdev_is_link_up(netdev))
// {
// netdev_low_level_set_link_status(netdev, (ML307_LINK_STATUS_OK == link_status));
// }
rt_thread_delay(ML307_LINK_DELAY_TIME);
}
}
@ -533,7 +553,7 @@ static void ml307_check_link_status_entry(void *parameter)
int ml307_netdev_check_link_status(struct netdev *netdev)
{
#define ML307_LINK_THREAD_TICK 20
#define ML307_LINK_THREAD_STACK_SIZE (1024)
#define ML307_LINK_THREAD_STACK_SIZE (2048)
#define ML307_LINK_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX - 2)
rt_thread_t tid;
@ -792,15 +812,15 @@ static struct netdev *ml307_netdev_add(const char *netdev_name)
/* ============================= ml307 device operations ============================= */
// #define AT_SEND_CMD(client, resp, resp_line, timeout, cmd) \
// do { \
// (resp) = at_resp_set_info((resp), 128, (resp_line), rt_tick_from_millisecond(timeout)); \
// if (at_obj_exec_cmd((client), (resp), (cmd)) < 0) \
// { \
// result = -RT_ERROR; \
// goto __exit; \
// } \
// } while(0)
#define AT_SEND_CMD(client, resp, resp_line, timeout, cmd) \
do { \
(resp) = at_resp_set_info((resp), 128, (resp_line), rt_tick_from_millisecond(timeout)); \
if (at_obj_exec_cmd((client), (resp), (cmd)) < 0) \
{ \
result = -RT_ERROR; \
goto __exit; \
} \
} while (0)
/* initialize for ml307 */
static void ml307_init_thread_entry(void *parameter)
{
@ -809,8 +829,9 @@ static void ml307_init_thread_entry(void *parameter)
#define CSQ_RETRY 20
#define CEREG_RETRY 50
#define IPADDR_RETRY 10
#define COMMON_RETRY 10
#define ML307_AT_DEFAULT_TIMEOUT 1000
#define COMMON_RETRY 10
#define CGATT_RETRY 10
#define ML307_AT_DEFAULT_TIMEOUT 5000
int i;
rt_uint8_t retry_num = INIT_RETRY;
rt_err_t result = RT_EOK;
@ -831,9 +852,9 @@ static void ml307_init_thread_entry(void *parameter)
while (retry_num--)
{
/* power on the ml307 device */
rt_thread_mdelay(500);
ml307_power_on(device);
rt_thread_mdelay(1000);
ml307_power_on(device);
rt_thread_mdelay(2000);
LOG_D("power on %s device.", device->name);
/* wait ml307 startup finish, send AT every 500ms, if receive OK, SYNC success*/
if (at_client_obj_wait_connect(client, ML307_WAIT_CONNECT_TIME))
@ -843,11 +864,7 @@ static void ml307_init_thread_entry(void *parameter)
}
/* disable echo */
if (at_obj_exec_cmd(device->client, resp, "ATE0") != RT_EOK)
{
result = -RT_ERROR;
goto __exit;
}
AT_SEND_CMD(client, resp, 0, ML307_AT_DEFAULT_TIMEOUT, "ATE0");
/* get module version */
if (at_obj_exec_cmd(device->client, resp, "ATI") != RT_EOK)
{
@ -869,8 +886,8 @@ static void ml307_init_thread_entry(void *parameter)
{
result = -RT_ERROR;
goto __exit;
}
/*设置包模式*/
}
/*设置包模式*/
if (at_obj_exec_cmd(device->client, resp, "AT+MIPCFG=\"autofree\",0,0") != RT_EOK)
{
result = -RT_ERROR;
@ -882,7 +899,7 @@ static void ml307_init_thread_entry(void *parameter)
result = -RT_ERROR;
goto __exit;
}
/* Define PDP Context */
/* Define PDP Context */
for (i = 0; i < COMMON_RETRY; i++)
{
if (at_obj_exec_cmd(client, resp, "AT+CGDCONT=1,\"IPV4V6\",\"cmnet\"") == RT_EOK)
@ -898,6 +915,7 @@ static void ml307_init_thread_entry(void *parameter)
result = -RT_ERROR;
goto __exit;
}
{
#define ML307_NETDEV_HWADDR_LEN 8
#define ML307_IMEI_LEN 15
@ -941,7 +959,7 @@ static void ml307_init_thread_entry(void *parameter)
}
}
}
rt_thread_mdelay(1000);
rt_thread_mdelay(3000);
}
if (i == CPIN_RETRY)
{
@ -949,41 +967,23 @@ static void ml307_init_thread_entry(void *parameter)
result = -RT_ERROR;
goto __exit;
}
// /*网络注册 */
// for (i = 0; i < CSQ_RETRY; i++)
// {
// if (at_obj_exec_cmd(device->client, resp, "AT+CREG=1") == RT_EOK)
// {
// rt_uint8_t state;
// if (at_resp_parse_line_args_by_kw(resp, "+CREG:", "+CREG:%d", &state) > 0)
// {
// if (state == 1)
// {
// LOG_D("%s device network registration success.", device->name);
// /* code */
// }
// else
// {
// LOG_E("%s device network registration failed.", device->name);
// result = -RT_ERROR;
// goto __exit;
// }
// }
// else
// {
// LOG_D("%s device prase \"AT+CREG=1\" cmd error.", device->name);
// result = -RT_ERROR;
// goto __exit;
// }
// }
// rt_thread_mdelay(1000);
// }
// if (i == CSQ_RETRY)
// {
// LOG_D("%s device network registration failed.", device->name);
// result = -RT_ERROR;
// goto __exit;
// }
if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL=1,1") != RT_EOK)
{
result = -RT_ERROR;
goto __exit;
}
char parsed_data[10] = {0};
for (i = 0; i < CGATT_RETRY; i++)
{
AT_SEND_CMD(client, resp, 0, ML307_AT_DEFAULT_TIMEOUT, "AT+CGATT?");
at_resp_parse_line_args_by_kw(resp, "+CGATT:", "+CGATT: %s", &parsed_data);
if (!rt_strncmp(parsed_data, "1", 1))
{
LOG_D("%s device Packet domain attach.", device->name);
break;
}
rt_thread_mdelay(1000);
}
/* set network interface device hardware iccid */
{
@ -1036,34 +1036,6 @@ static void ml307_init_thread_entry(void *parameter)
Flash_Sys_Cfg(kIotImsiId, ml307.imsi, ML307_IMSI_LEN);
}
/* check signal strength */
for (i = 0; i < CSQ_RETRY; i++)
{
if (at_obj_exec_cmd(device->client, resp, "AT+CSQ") == RT_EOK)
{
int signal_strength = 0, err_rate = 0;
if (at_resp_parse_line_args_by_kw(resp, "+CSQ:", "+CSQ: %d,%d", &signal_strength, &err_rate) > 0)
{
if ((signal_strength != 99) && (signal_strength != 0))
{
LOG_D("%s device signal strength: %d, channel bit err_rate: %d",
device->name, signal_strength, err_rate);
ml307.rssi = signal_strength;
break;
}
}
}
rt_thread_mdelay(1000);
}
if (i == CSQ_RETRY)
{
LOG_E("%s device signal strength check failed", device->name);
result = -RT_ERROR;
goto __exit;
}
/* check the GPRS network is registered */
for (i = 0; i < CEREG_RETRY; i++)
{
@ -1147,7 +1119,7 @@ static void ml307_init_thread_entry(void *parameter)
/* set network interface device status and address information */
ml307_netdev_set_info(device->netdev);
/* check and create link staus sync thread */
// ml307_netdev_check_link_status(device->netdev);
ml307_netdev_check_link_status(device->netdev);
LOG_I("%s device network initialize success.", device->name);
rt_completion_done(&ml307_init_complate); // 通知初始化完成
}
@ -1246,7 +1218,7 @@ rt_err_t Ml307_Get_Signal_Info(struct at_device *device)
//+CESQ:99,99,255,255,28,44
for (i = 0; i < RETRY; i++)
{
{
if (at_obj_exec_cmd(device->client, resp, "AT+CESQ") == RT_EOK)
{
rt_uint8_t rsrp = 0;
@ -1332,7 +1304,7 @@ static int ml307_init(struct at_device *device)
{
rt_pin_mode(ml307->power_status_pin, PIN_MODE_INPUT);
}
if (ml307->rst_pin != -1)
if (ml307->rst_pin != -1)
{
rt_pin_mode(ml307->rst_pin, PIN_MODE_OUTPUT);
}
@ -1427,7 +1399,7 @@ int Time_Calibration(struct at_device *device)
int year, mounth, days, hous, min, sec;
/*+CCLK:24/11/12,06:08:19+32*/
if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0)
{
{
rtc_dt.year = (2000 + year);
rtc_dt.month = mounth;
rtc_dt.day = days;

View File

@ -2,7 +2,7 @@
* @Author: mbw
* @Date: 2024-12-03 10:31:45
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-03 14:57:36
* @LastEditTime: 2025-01-04 15:42:19
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_bt.c
* @Description:
*
@ -411,7 +411,7 @@ void BSP_Bt_Valve_Updata(void)
if (Flash_Get_Mac_Addr(mac, i) == 0) // 说明有MAC数据
{
rt_memcpy(valve[cnt].valve_mac, mac, 6); // 这样做的目的就是读取方便只需要根据flash中读取到的数量进行读取前N个值
valve[cnt].valve_id = i + 1;
valve[cnt].valve_id = i;
LOG_D("updata valve_id: %d, valve_mac: %02X %02X %02X %02X %02X %02X",
valve[cnt].valve_id,
valve[cnt].valve_mac[0],

View File

@ -5,6 +5,7 @@
#include "at_device_ml307.h"
#include <rtthread.h>
#include <rthw.h>
#include "rtdef.h"
#define LOG_TAG "bsp_flash"
#define LOG_LVL LOG_LVL_DBG
@ -24,8 +25,8 @@ rt_uint8_t sys_hw_ver = 0x10;
rt_uint8_t sys_sw_ver = 0x11;
rt_uint8_t sys_nb_retry = 0x03; // 重试次数3次
rt_uint16_t sys_nb_upload_cycle = 0x0001; // 120分钟一次
rt_uint16_t sys_alarm_h_value = 0x0032; // 50
rt_uint16_t sys_alarm_l_value = 0x09C4; // 2500
rt_uint16_t sys_alarm_h_value = 0x09C4; // 2500
rt_uint16_t sys_alarm_l_value = 0x0640; // 1600
rt_uint8_t sys_temp_alarm_threshold = 0x32;
rt_uint8_t sys_emagnetic_switch = 0x04; // 具备阀门功能
rt_uint8_t sys_relay_switch = 0x04; // 具备继电器功能
@ -895,8 +896,8 @@ int BSP_Flash_Init(void)
Flash_Write(FLASH_INIT_FLAG_ADDR, flash_init_flag,
sizeof(flash_init_flag));
Flash_SetProductTimeLimit(2024, 9, 8, 13, 58, 20, kFactoryTimeId);
Flash_SetProductTimeLimit(2024 + 8, 9, 8, 13, 58, 20, kExpirationTimeId);
Flash_SetProductTimeLimit(2025, 1, 6, 11, 20, 50, kFactoryTimeId);
Set_ExpirationTime(MAX_EXPIRATION_DAYS);
sci.hw_ver = sys_hw_ver;
sci.sw_ver = sys_sw_ver;

View File

@ -54,14 +54,14 @@ static void BSP_Led_thread_entry(void *param)
#endif
if (SysControl.status == kNormalDetectionEvents)
{
if ((power_on_send_flag))
{
LED_G_INTERNET;
}
else if ((!power_on_send_flag))
if ((ml307_conncet_tcp_flag))
{
LED_G_NORMAL;
}
else
{
LED_G_INTERNET;
}
}
rt_thread_mdelay(1000);
}

View File

@ -806,7 +806,7 @@ int Ml307_Process_Events(Ml307Event ml307_recv_event, struct at_device *device,
LOG_E("ml307 send cmd failed\n");
}
else
return RT_EOK;// 函数执行完毕返回0
return RT_EOK; // 函数执行完毕返回0
}
}
else
@ -817,7 +817,7 @@ int Ml307_Process_Events(Ml307Event ml307_recv_event, struct at_device *device,
rt_thread_mdelay(5000);
}
}
return RT_ERROR;
}
@ -1507,154 +1507,137 @@ static void Ml307_Send_Thread_Entry(void *param)
if (result == RT_EOK)
{
LOG_D("ml307 recv event OK\n");
if (ml307_conncet_tcp_flag != 1)
if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307PowerOnEvent))
{
if (device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_CONN, RT_NULL) == RT_EOK) // 打开连接
result = Ml307_Process_Events(kMl307PowerOnEvent, device, ops); // 当上电心跳包发送不成功时,其他事件不启动
if (result)
{
LOG_I("ml307 connect tcp success\n");
power_on_send_flag = 0;
rt_timer_start(ml307_power_error_timer); // 启动重连定时器, 3min一次直到发送成功
LOG_E("ml307 send data failed result = [%d]\n", result);
}
else
{
LOG_E("ml307 connect tcp failed\n");
rt_timer_start(ml307_timer); // 当上电心跳包发送成功时, 开始心跳包周期发送
power_on_send_flag = 1;
Ml307_Send_Event(kMl307TimeCalibrationEvent); // 上电网络连接成功时,更新下时间
rt_timer_start(ml307_upload_timer);
}
}
if (ml307_conncet_tcp_flag)
if(power_on_send_flag)
{
if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307PowerOnEvent))
if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307HeartbeatEvent))
{
result = Ml307_Process_Events(kMl307PowerOnEvent, device, ops); // 当上电心跳包发送不成功时,其他事件不启动
result = Ml307_Process_Events(kMl307HeartbeatEvent, device, ops);
if (result)
{
power_on_send_flag = 0;
rt_timer_start(ml307_power_error_timer); // 启动重连定时器, 3min一次直到发送成功
LOG_E("ml307 send data failed result = [%d]\n", result);
}
else
{
rt_timer_start(ml307_timer); // 当上电心跳包发送成功时, 开始心跳包周期发送
power_on_send_flag = 1;
Ml307_Send_Event(kMl307TimeCalibrationEvent); // 上电网络连接成功时,更新下时间
rt_timer_start(ml307_upload_timer);
}
}
if (power_on_send_flag)
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307TimeCalibrationEvent))
{
if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307HeartbeatEvent))
Time_Calibration(device);
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307AlarmEvent))
{
result = Ml307_Process_Events(kMl307AlarmEvent, device, ops);
if (result)
{
result = Ml307_Process_Events(kMl307HeartbeatEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
LOG_E("ml307 send data failed result = [%d]\n", result);
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307TimeCalibrationEvent))
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307AlarmRcyEvent))
{
result = Ml307_Process_Events(kMl307AlarmRcyEvent, device, ops);
if (result)
{
Time_Calibration(device);
LOG_E("ml307 send data failed result = [%d]\n", result);
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307AlarmEvent))
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307FaultEvent))
{
if (device_state_flag != 1) // 当设备失效时,只上报失效信息
{
result = Ml307_Process_Events(kMl307AlarmEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307AlarmRcyEvent))
{
result = Ml307_Process_Events(kMl307AlarmRcyEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307FaultEvent))
{
if (device_state_flag != 1) // 当设备失效时,只上报失效信息
{
result = Ml307_Process_Events(kMl307FaultEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307FaultRcyEvent))
{
result = Ml307_Process_Events(kMl307FaultRcyEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307SelfCheckEvent))
{
result = Ml307_Process_Events(kMl307SelfCheckEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307SilenceEvent))
{
result = Ml307_Process_Events(kMl307SilenceEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307ExceptionEvent))
{
result = Ml307_Process_Events(kMl307ExceptionEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307ValveStatusEvent))
{
result = Ml307_Process_Events(kMl307ValveStatusEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307FanStatusEvent))
{
result = Ml307_Process_Events(kMl307FanStatusEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307TempAnomalyEvent))
{
result = Ml307_Process_Events(kMl307TempAnomalyEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307PowerDownEvent))
{
result = Ml307_Process_Events(kMl307PowerDownEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
ml307_event_initialized = RT_FALSE; // 当接收到掉电事件时,不再接收其他事件
// rt_event_detach(&at_device_event);
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307DeviceFailureEvent))
{
result = Ml307_Process_Events(kMl307DeviceFailureEvent, device, ops);
result = Ml307_Process_Events(kMl307FaultEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
}
rt_thread_mdelay(1); // 释放下线程
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307FaultRcyEvent))
{
result = Ml307_Process_Events(kMl307FaultRcyEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307SelfCheckEvent))
{
result = Ml307_Process_Events(kMl307SelfCheckEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307SilenceEvent))
{
result = Ml307_Process_Events(kMl307SilenceEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307ExceptionEvent))
{
result = Ml307_Process_Events(kMl307ExceptionEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307ValveStatusEvent))
{
result = Ml307_Process_Events(kMl307ValveStatusEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307FanStatusEvent))
{
result = Ml307_Process_Events(kMl307FanStatusEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307TempAnomalyEvent))
{
result = Ml307_Process_Events(kMl307TempAnomalyEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307PowerDownEvent))
{
result = Ml307_Process_Events(kMl307PowerDownEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
ml307_event_initialized = RT_FALSE; // 当接收到掉电事件时,不再接收其他事件
}
else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307DeviceFailureEvent))
{
result = Ml307_Process_Events(kMl307DeviceFailureEvent, device, ops);
if (result)
{
LOG_E("ml307 send data failed result = [%d]\n", result);
}
}
}
}
}