This commit is contained in:
parent
1b566c8281
commit
2b9a2d0c32
|
@ -500,6 +500,12 @@ int main(void)
|
|||
rt_uint8_t mac_addr[6];
|
||||
Flash_Get_Mac_Addr (mac_addr, 1);
|
||||
Bt_Valve_Handler (kValveCmdCtr, 1, mac_addr);
|
||||
}
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Ml307_Send_Event (kMl307PowerDownEvent);
|
||||
#endif
|
||||
if (Flash_Get_Valve_Num())
|
||||
{
|
||||
if (rt_sem_take (&bt_ctr_sem, 5000) == RT_EOK)
|
||||
{
|
||||
LOG_D ("电磁阀动作完成");
|
||||
|
@ -509,11 +515,8 @@ int main(void)
|
|||
LOG_E ("电磁阀动作失败");
|
||||
}
|
||||
}
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Ml307_Send_Event(kMl307PowerDownEvent);
|
||||
#endif
|
||||
rt_uint8_t cnt = 0;
|
||||
while ((ml307_power_down_flag == 0) && (cnt < 60)) // 等待接收到物联网模组关机完成
|
||||
while ((ml307_power_down_flag == 0) && (cnt < 30)) // 等待接收到物联网模组关机完成
|
||||
{
|
||||
rt_thread_mdelay (1000);
|
||||
LOG_D ("cnt = %d", cnt);
|
||||
|
|
|
@ -479,12 +479,20 @@ int Ml307_Send_Time_Calibration (struct at_device *device, void *param)
|
|||
*/
|
||||
int Ml307_Send_Alarm (struct at_device *device, void *param)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
struct Ml307_Ops *ml307_ops = (struct Ml307_Ops *)param;
|
||||
if ((device == RT_NULL) || (ml307_ops == RT_NULL))
|
||||
{
|
||||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_ALARM))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_ALARM);
|
||||
|
@ -507,7 +515,13 @@ int Ml307_Send_Alarm_Recover (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_ALARM_RECOVER))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_ALARM_RECOVER);
|
||||
|
@ -530,7 +544,13 @@ int Ml307_Send_Fault (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_FAULT))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_FAULT);
|
||||
|
@ -553,7 +573,13 @@ int Ml307_Send_Fault_Recover (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_FAULT_RECOVER))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_FAULT_RECOVER);
|
||||
|
@ -576,7 +602,13 @@ int Ml307_Send_Self_Check (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_SELF_CHECK))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_SELF_CHECK);
|
||||
|
@ -599,7 +631,13 @@ int Ml307_Send_Silence (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_SILENCE))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_SILENCE);
|
||||
|
@ -622,7 +660,13 @@ int Ml307_Send_Exception (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_EXCEPTION))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_EXCEPTION);
|
||||
|
@ -714,7 +758,13 @@ int Ml307_Send_Power_On (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_POWER_ON))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_POWER_ON);
|
||||
|
@ -737,6 +787,13 @@ int Ml307_Send_Power_Off (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
rt_memset (&valve[0].valve_connct_status, 0, (sizeof (struct valve_t) - 7)); // 当掉电事件时,直接清空阀门结构体,这样连接状态就为断开
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_POWER_OFF))
|
||||
{
|
||||
|
@ -760,7 +817,13 @@ int Ml307_Send_Valve_Connect (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_VALVE_CONNECT))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_VALVE_CONNECT);
|
||||
|
@ -783,7 +846,13 @@ int Ml307_Send_Valve_Disconnect (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_VALVE_DISCONNECT))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_VALVE_DISCONNECT);
|
||||
|
@ -806,7 +875,13 @@ int Ml307_Send_Device_Failure (struct at_device *device, void *param)
|
|||
LOG_E ("ml307 param error\n");
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t ret = RT_EOK;
|
||||
ret = device->class->device_ops->control (device, AT_DEVICE_CTRL_GET_SIGNAL, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E ("ml307 get signal failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if (ml307_ops->send (ml307_ops, DATA_SERIAL_NUM, CMD_TYPE_DEVICE_EVENT_REPORT, DEVICE_TYPE_ML307, EVENT_TYPE_DEVICE_FAILURE))
|
||||
{
|
||||
LOG_E ("ml307 send cmd[%X] failed\n", EVENT_TYPE_DEVICE_FAILURE);
|
||||
|
@ -944,10 +1019,20 @@ int Ml307_Process_Events (Ml307Event ml307_recv_event, struct at_device *device,
|
|||
{
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
|
||||
ml307_connect_sever_flag = 0;
|
||||
if (!ml307_disconnect_retry_flag)
|
||||
{
|
||||
LOG_D("与服务器断开,重连网络中");
|
||||
rt_sem_release (ml307_disconnect_sem);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D ("与服务区断开连接,等待连接中......\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1353,12 +1438,26 @@ rt_err_t Handle_Valve_Add (struct Ml307_Ops *ops)
|
|||
}
|
||||
LOG_D ("新增阀门设备成功\n");
|
||||
Flash_Set_Valve_Num (cnt + 1);
|
||||
ops->Resp (ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_ADD, temp, RESPONSE_CODE_SUCCESS);
|
||||
if (ops->Resp (ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_ADD, temp, RESPONSE_CODE_SUCCESS) != RT_EOK)
|
||||
{
|
||||
LOG_D ("发送失败,清空本地mac地址");
|
||||
rt_uint8_t mac_addr[6] = {0};
|
||||
// 清空本地阀门信息
|
||||
if (Flash_Set_Mac_Addr (mac_addr, 1) != RESET)
|
||||
{
|
||||
LOG_E ("本地阀门信息清空完成");
|
||||
Flash_Set_Valve_Num (0);
|
||||
}
|
||||
Bt_Valve_Handler (kValveCmdRemAll, RT_NULL, RT_NULL);
|
||||
if (rt_sem_take (&bt_rem_sem, 10000) == RT_EOK) // 如果没刷掉数据,则黄灯会亮一秒,如果刷成功了,则红灯闪一下黄灯不会亮
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
}
|
||||
|
||||
/*更换阀门设备*/
|
||||
rt_err_t Handle_Valve_Replace (struct Ml307_Ops *ops)
|
||||
|
@ -1890,7 +1989,7 @@ static void Ml307_Life_Thread_Entry (void *parameter)
|
|||
goto __exit;
|
||||
}
|
||||
/*设置心跳包*/
|
||||
if (at_obj_exec_cmd (device->client, resp, "AT+MIPTKA=0,1,120,60,1") != RT_EOK)
|
||||
if (at_obj_exec_cmd (device->client, resp, "AT+MIPTKA=0,1,120,60,3") != RT_EOK)
|
||||
{
|
||||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
|
|
Loading…
Reference in New Issue