|
|
|
@ -116,8 +116,9 @@ typedef struct
|
|
|
|
|
uint8_t FPGA_version[DEV_VERSION_STR_LEN];
|
|
|
|
|
uint8_t factory_time[DEV_COMPILE_TIME_LEN];
|
|
|
|
|
/* 设备其他信息. 160byte */
|
|
|
|
|
uint8_t name[DEV_NAME_LEN];
|
|
|
|
|
char name[DEV_NAME_LEN];
|
|
|
|
|
char QCCID[WL_QCCID_LEN];
|
|
|
|
|
char APN[DEV_APN_LEN];
|
|
|
|
|
} wl_proto_wakeup_t;
|
|
|
|
|
|
|
|
|
|
/* 实时数据传输结构体 */
|
|
|
|
@ -151,6 +152,8 @@ typedef struct
|
|
|
|
|
uint16_t threshold_power;
|
|
|
|
|
uint16_t threshold_defect;
|
|
|
|
|
uint16_t threshold_fault;
|
|
|
|
|
uint16_t keepalive;
|
|
|
|
|
uint8_t reserve[2];
|
|
|
|
|
} wl_proto_config_t;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
@ -449,6 +452,12 @@ static void _wl_4G_recv_contect(uint8_t *cmd, uint32_t len)
|
|
|
|
|
dev_config.fault_threshold = cfg->threshold_fault;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cfg->keepalive != dev_config.keepalive)
|
|
|
|
|
{
|
|
|
|
|
is_cfg_save = TRUE;
|
|
|
|
|
dev_config.keepalive = cfg->keepalive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_cfg_save)
|
|
|
|
|
{
|
|
|
|
|
common_sys_set(COM_SYS_SAVE_CONFIG, 0);
|
|
|
|
@ -579,6 +588,12 @@ static void _wl_4G_recv_cfg_set(uint8_t *cmd, uint32_t len)
|
|
|
|
|
dev_config.fault_threshold = cfg->threshold_fault;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cfg->keepalive != dev_config.keepalive)
|
|
|
|
|
{
|
|
|
|
|
is_cfg_save = TRUE;
|
|
|
|
|
dev_config.keepalive = cfg->keepalive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_cfg_save)
|
|
|
|
|
{
|
|
|
|
|
common_sys_set(COM_SYS_SAVE_CONFIG, 0);
|
|
|
|
@ -800,7 +815,7 @@ static void _wl_4G_recv_update_fpga(uint8_t *cmd, uint32_t len)
|
|
|
|
|
uint32_t addr = TFTP_APP_ADDRESS;
|
|
|
|
|
uint32_t app_len = 0;
|
|
|
|
|
|
|
|
|
|
/* index 为 0 表示是首保, 需要擦除 FLASH. */
|
|
|
|
|
/* index 为 0 表示是首包, 需要擦除 FLASH */
|
|
|
|
|
if (0 == m_head->index)
|
|
|
|
|
{
|
|
|
|
|
while(addr != TFTP_APP_ADDRESS_END)
|
|
|
|
@ -1122,9 +1137,10 @@ static void _wl_4G_send_contact(void)
|
|
|
|
|
_wl_4G_head_init(sizeof(proto_head_t) + sizeof(wl_proto_wakeup_t), DEBUG_CT_REPLY, DEBUG_C_CONTACT, wl_ctrl.pkt_id);
|
|
|
|
|
|
|
|
|
|
/* 封装数据. */
|
|
|
|
|
memcpy(data, &dev_info.type_m, sizeof(wl_proto_wakeup_t) - DEV_NAME_LEN);
|
|
|
|
|
memcpy(data, &dev_info.type_m, sizeof(wl_proto_wakeup_t) - DEV_NAME_LEN - WL_QCCID_LEN - DEV_APN_LEN);
|
|
|
|
|
memcpy(data->name, dev_config.host, DEV_NAME_LEN);
|
|
|
|
|
memcpy(data->QCCID, wl_ctrl.QCCID, WL_QCCID_LEN);
|
|
|
|
|
memcpy(data->APN, dev_config.APN, DEV_APN_LEN);
|
|
|
|
|
|
|
|
|
|
/* 计算校验和. */
|
|
|
|
|
crc = (uint32_t*)(wl_ctrl.dma_tx_buf + head->len);
|
|
|
|
@ -1718,21 +1734,18 @@ void _wl_4G_send(void)
|
|
|
|
|
}
|
|
|
|
|
else if (WL_STATE_UPDATE_RT == wl_ctrl.state)
|
|
|
|
|
{
|
|
|
|
|
/* 设备保活报文发送. */
|
|
|
|
|
_wl_4G_send_update_rt();
|
|
|
|
|
wl_ctrl.send_cnt++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (WL_STATE_UPDATE_FPGA_RT == wl_ctrl.state)
|
|
|
|
|
{
|
|
|
|
|
/* 设备保活报文发送. */
|
|
|
|
|
_wl_4G_send_update_fpga_rt();
|
|
|
|
|
wl_ctrl.send_cnt++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (WL_STATE_KEEPALIVE == wl_ctrl.state)
|
|
|
|
|
{
|
|
|
|
|
/* 设备保活报文发送. */
|
|
|
|
|
_wl_4G_send_keepalive();
|
|
|
|
|
wl_ctrl.send_cnt++;
|
|
|
|
|
break;
|
|
|
|
@ -1744,25 +1757,29 @@ void _wl_4G_send(void)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 发送数据状态机改变 */
|
|
|
|
|
/* 发包状态机改变 */
|
|
|
|
|
void _wl_4G_state_chg(void)
|
|
|
|
|
{
|
|
|
|
|
if (dau_ctrl.update_rt != DAU_UPD_NONE)
|
|
|
|
|
{
|
|
|
|
|
/* FPGA 升级结果回复 */
|
|
|
|
|
wl_ctrl.state = WL_STATE_UPDATE_FPGA_RT;
|
|
|
|
|
}
|
|
|
|
|
else if(!IS_MONITOR_BIT_SET(dau_ctrl.col_flag, DAU_COL_FLAG_FAULT_CMP))
|
|
|
|
|
{
|
|
|
|
|
/* 故障定位数据上送 */
|
|
|
|
|
wl_ctrl.state = WL_STATE_REALDATA_FAULT;
|
|
|
|
|
}
|
|
|
|
|
else if(!IS_MONITOR_BIT_SET(dau_ctrl.col_flag, DAU_COL_FLAG_REG_CMP))
|
|
|
|
|
{
|
|
|
|
|
/* 定时数据上送 */
|
|
|
|
|
wl_ctrl.state = WL_STATE_REALDATA;
|
|
|
|
|
}
|
|
|
|
|
else if(wl_ctrl.keepalive < HAL_GetTick())
|
|
|
|
|
{
|
|
|
|
|
/* 保活报文上送 */
|
|
|
|
|
wl_ctrl.state = WL_STATE_KEEPALIVE;
|
|
|
|
|
wl_ctrl.keepalive = dev_config.keepalive + HAL_GetTick();
|
|
|
|
|
wl_ctrl.keepalive = HAL_GetTick() + dev_config.keepalive * 60000;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1792,6 +1809,7 @@ void _wl_4G_init_soft(void)
|
|
|
|
|
|
|
|
|
|
if ((WL_STATE_SOFT == wl_ctrl.state) && is_timeout)
|
|
|
|
|
{
|
|
|
|
|
/* 等待 RDY 字符串 */
|
|
|
|
|
wl_ctrl.time_send = 0;
|
|
|
|
|
wl_ctrl.send_cnt = 0;
|
|
|
|
|
wl_ctrl.state++;
|
|
|
|
@ -1806,20 +1824,18 @@ void _wl_4G_init_soft(void)
|
|
|
|
|
{
|
|
|
|
|
/* 修改波特率. */
|
|
|
|
|
_wl_4G_init_cmd_send("AT+IPR=230400\r\n", 1100);
|
|
|
|
|
//_wl_4G_init_cmd_send("AT+IPR=115200\r\n", 1100);
|
|
|
|
|
//_wl_4G_init_cmd_send("AT+IPR=19200\r\n", 1100);
|
|
|
|
|
wl_ctrl.send_cnt++;
|
|
|
|
|
}
|
|
|
|
|
else if ((WL_STATE_AT_QICSGP == wl_ctrl.state) && is_timeout)
|
|
|
|
|
{
|
|
|
|
|
/* 创建场景. */
|
|
|
|
|
/* 创建场景 */
|
|
|
|
|
snprintf((char*)wl_ctrl.dma_tx_buf, WL_DMA_TX_BUF_LEN, "AT+QICSGP=1,1,\"%s\",\"\",\"\",1\r\n", dev_config.APN);
|
|
|
|
|
_wl_4G_init_cmd_send(wl_ctrl.dma_tx_buf, 1100);
|
|
|
|
|
wl_ctrl.send_cnt++;
|
|
|
|
|
}
|
|
|
|
|
else if ((WL_STATE_AT_QIACT == wl_ctrl.state) && is_timeout)
|
|
|
|
|
{
|
|
|
|
|
/* 使能场景. */
|
|
|
|
|
/* 使能场景 */
|
|
|
|
|
_wl_4G_init_cmd_send("AT+QIACT=1\r\n", 33000);
|
|
|
|
|
wl_ctrl.send_cnt++;
|
|
|
|
|
}
|
|
|
|
@ -1869,7 +1885,8 @@ void _wl_4G_init_soft(void)
|
|
|
|
|
}
|
|
|
|
|
else if (wl_ctrl.state > WL_STATE_AT_COMP)
|
|
|
|
|
{
|
|
|
|
|
vty_print("#W4 %d\r\n", wl_ctrl.state);
|
|
|
|
|
/* 理论上进不来 */
|
|
|
|
|
vty_print("#WE0 %d\r\n", wl_ctrl.state);
|
|
|
|
|
wl_ctrl.state = WL_STATE_AT_ATE;
|
|
|
|
|
wl_ctrl.time_send = 0;
|
|
|
|
|
wl_ctrl.send_cnt = 0;
|
|
|
|
@ -1889,28 +1906,31 @@ static void _wl_4G_hw_init(void)
|
|
|
|
|
HAL_GPIO_WritePin(G4G_RST_GPIO_Port, G4G_RST_Pin, GPIO_PIN_RESET);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 重启 4G 模块硬件. */
|
|
|
|
|
/* 重启 4G 模块硬件 */
|
|
|
|
|
static void _wl_4G_hw_restart(void)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_4G, "4G restart(%d)\r\n", wl_ctrl.err_cnt);
|
|
|
|
|
|
|
|
|
|
/* 初始化 4G 模块硬件. */
|
|
|
|
|
/* 关闭 4G 模块硬件 */
|
|
|
|
|
HAL_GPIO_WritePin(POWER_4G_GPIO_Port, POWER_4G_Pin, GPIO_PIN_RESET);
|
|
|
|
|
HAL_UART_Abort(wl_ctrl.uart);
|
|
|
|
|
HAL_UART_DeInit(wl_ctrl.uart);
|
|
|
|
|
memset(&wl_buf_list_rx, 0, sizeof(wl_buf_list_t));
|
|
|
|
|
MX_USART3_UART_Init();
|
|
|
|
|
HAL_UARTEx_ReceiveToIdle_DMA(wl_ctrl.uart, wl_ctrl.dma_rx_buf, WL_DMA_RX_BUF_LEN);
|
|
|
|
|
osDelay(10000);
|
|
|
|
|
/* 20s 内要收到 4G 模块发出的 RDY. */
|
|
|
|
|
wl_ctrl.state = 0;
|
|
|
|
|
wl_ctrl.send_cnt = 0;
|
|
|
|
|
wl_ctrl.mul_idx = 0;
|
|
|
|
|
wl_ctrl.cmd_buf_index = 0;
|
|
|
|
|
wl_ctrl.time_send = HAL_GetTick() + 20000;
|
|
|
|
|
wl_ctrl.err_cnt++;
|
|
|
|
|
memset(&wl_buf_list_rx, 0, sizeof(wl_buf_list_t));
|
|
|
|
|
|
|
|
|
|
/* 初始化硬件 */
|
|
|
|
|
osDelay(10000);
|
|
|
|
|
MX_USART3_UART_Init();
|
|
|
|
|
_wl_4G_hw_init();
|
|
|
|
|
|
|
|
|
|
/* 开启串口空闲中断收包 */
|
|
|
|
|
HAL_UARTEx_ReceiveToIdle_DMA(wl_ctrl.uart, wl_ctrl.dma_rx_buf, WL_DMA_RX_BUF_LEN);
|
|
|
|
|
|
|
|
|
|
/* 4G 掉线后不能阻止波形采集, 掉线后默认上传完成 */
|
|
|
|
|
if (!MONITOR_BITMAP_SET(dau_ctrl.col_flag, DAU_COL_FLAG_REG_CMP))
|
|
|
|
|
{
|
|
|
|
@ -1938,12 +1958,12 @@ static void _wl_4G_hw_restart(void)
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 无线模块主任务循环. */
|
|
|
|
|
/* 无线模块主任务循环 */
|
|
|
|
|
static void _wl_4G_start(void *argument)
|
|
|
|
|
{
|
|
|
|
|
uint32_t notify_value = 0;
|
|
|
|
|
|
|
|
|
|
/* 等待完成 1 次 ADC 采样. */
|
|
|
|
|
/* 等待完成首次 ADC 采样 */
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
if (IS_MONITOR_BIT_SET(system_init_flag, SYS_INIT_ADC))
|
|
|
|
@ -1953,7 +1973,7 @@ static void _wl_4G_start(void *argument)
|
|
|
|
|
osDelay(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 初始化 4G 模块硬件. */
|
|
|
|
|
/* 初始化 4G 模块硬件 */
|
|
|
|
|
MX_USART3_UART_Init();
|
|
|
|
|
_wl_4G_hw_init();
|
|
|
|
|
|
|
|
|
@ -1974,7 +1994,7 @@ static void _wl_4G_start(void *argument)
|
|
|
|
|
|
|
|
|
|
if (wl_ctrl.state < WL_STATE_CONTACT)
|
|
|
|
|
{
|
|
|
|
|
/* 进入软件初始化. */
|
|
|
|
|
/* 进入软件初始化 */
|
|
|
|
|
_wl_4G_init_soft();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -1989,41 +2009,43 @@ static void _wl_4G_start(void *argument)
|
|
|
|
|
}
|
|
|
|
|
else if (WL_STATE_END == wl_ctrl.state)
|
|
|
|
|
{
|
|
|
|
|
/* 计算状态机 */
|
|
|
|
|
/* 发包状态机改变 */
|
|
|
|
|
_wl_4G_state_chg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 进入数据交互模式. */
|
|
|
|
|
/* 根据状态机状态发送报文 */
|
|
|
|
|
_wl_4G_send();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 喂狗. */
|
|
|
|
|
common_watchdog_set(COM_WDG_WIR);
|
|
|
|
|
|
|
|
|
|
/* 等待 DMA 收包中断. */
|
|
|
|
|
/* 等待 DMA 收包中断 */
|
|
|
|
|
notify_value = ulTaskNotifyTake(pdTRUE, WL_RX_TIMEOUT);
|
|
|
|
|
/* 收包超时, 返回循环头部. */
|
|
|
|
|
if (0 == notify_value)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 收包处理. */
|
|
|
|
|
/* 收包处理 */
|
|
|
|
|
_wl_4G_receive();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Interface functions -------------------------------------------------------*/
|
|
|
|
|
/* 无线通讯任务初始化. */
|
|
|
|
|
/* description: 无线通讯任务初始化
|
|
|
|
|
param:
|
|
|
|
|
return: */
|
|
|
|
|
void wl_init(void)
|
|
|
|
|
{
|
|
|
|
|
wl_ctrl.uart = &huart3;
|
|
|
|
|
wl_ctrl.handle = osThreadNew(_wl_4G_start, NULL, &WL_attributes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* description: 无线通讯调试显示接口
|
|
|
|
|
param:
|
|
|
|
|
return: */
|
|
|
|
|
void wl_show(void)
|
|
|
|
|
{
|
|
|
|
|
vty_print("ST\r\n");
|
|
|
|
|
vty_print("%-03d %d\r\n\n", wl_ctrl.state, wl_ctrl.send_cnt);
|
|
|
|
|
vty_print("ST: %-03d %d\r\n\n", wl_ctrl.state, wl_ctrl.send_cnt);
|
|
|
|
|
}
|
|
|
|
|
/******************* (C) COPYRIGHT LandPower ***** END OF FILE ****************/
|
|
|
|
|