|
@@ -104,7 +104,7 @@ uint16_t randomFun() {
|
|
|
|
|
|
|
|
void Device_Info_Init_Fun() {
|
|
void Device_Info_Init_Fun() {
|
|
|
deviceInfo.isOnline = FALSE;
|
|
deviceInfo.isOnline = FALSE;
|
|
|
- deviceInfo.SOS_Flag = FALSE;
|
|
|
|
|
|
|
+ deviceInfo.isSOS = FALSE;
|
|
|
deviceInfo.broadcast_type = BROADCAST_ALL;
|
|
deviceInfo.broadcast_type = BROADCAST_ALL;
|
|
|
deviceInfo.loraDeviceAddress_H = 0xFE; //默认地址高位
|
|
deviceInfo.loraDeviceAddress_H = 0xFE; //默认地址高位
|
|
|
deviceInfo.loraDeviceAddress_L = 0xEF; //默认地址低位
|
|
deviceInfo.loraDeviceAddress_L = 0xEF; //默认地址低位
|
|
@@ -259,26 +259,6 @@ int main(void)
|
|
|
powerOn();
|
|
powerOn();
|
|
|
E52_CtlPowerOn_Fun();
|
|
E52_CtlPowerOn_Fun();
|
|
|
|
|
|
|
|
- // deviceInfo.loraDeviceAddress_H = 0xFE;
|
|
|
|
|
- // deviceInfo.loraDeviceAddress_L = 0xE1;
|
|
|
|
|
- // Flash_Write_LoraAddr(deviceInfo.loraDeviceAddress_H, deviceInfo.loraDeviceAddress_L);
|
|
|
|
|
- // uint8_t addrH, addrL;
|
|
|
|
|
- // while (TRUE) {
|
|
|
|
|
- // Flash_Read_LoraAddr(&addrH, &addrL);
|
|
|
|
|
- // printf("LoraAddr: %02X%02X\r\n", addrH, addrL);
|
|
|
|
|
- // HAL_Delay(1000);
|
|
|
|
|
- // }
|
|
|
|
|
- // 在需要设置RTC时间的地方直接调用
|
|
|
|
|
- // 参数依次为:小时、分钟、秒、星期、月份、日期、年份(均为BCD格式)
|
|
|
|
|
- // RTC_SetDateTime(&hrtc,
|
|
|
|
|
- // 0x12, // 12时
|
|
|
|
|
- // 0x30, // 30分
|
|
|
|
|
- // 0x00, // 00秒
|
|
|
|
|
- // RTC_WEEKDAY_WEDNESDAY, // 星期三
|
|
|
|
|
- // RTC_MONTH_OCTOBER, // 10月
|
|
|
|
|
- // 0x17, // 17日
|
|
|
|
|
- // 0x25); // 25年(2025年)
|
|
|
|
|
-
|
|
|
|
|
// 启动 USART2 DMA 接收
|
|
// 启动 USART2 DMA 接收
|
|
|
HAL_UART_Receive_DMA(&huart3, rx_buf, sizeof(rx_buf));
|
|
HAL_UART_Receive_DMA(&huart3, rx_buf, sizeof(rx_buf));
|
|
|
__HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);
|
|
__HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);
|
|
@@ -364,6 +344,7 @@ int main(void)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (deviceInfo.isSOS) {
|
|
if (deviceInfo.isSOS) {
|
|
|
|
|
+ deviceInfo.isOnline = TRUE;
|
|
|
RTC_TimeTypeDef now = {0};
|
|
RTC_TimeTypeDef now = {0};
|
|
|
HAL_RTC_GetTime(&hrtc, &now, RTC_FORMAT_BIN);
|
|
HAL_RTC_GetTime(&hrtc, &now, RTC_FORMAT_BIN);
|
|
|
|
|
|
|
@@ -377,6 +358,28 @@ int main(void)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (GET_CMD( deviceInfo.commandFromCloud) == IDLE || GET_STEP(deviceInfo.commandFromCloud) == STEP_INIT) {
|
|
|
|
|
+ // printf("为idle状态的时间为\r\n");
|
|
|
|
|
+ RTC_TimeTypeDef now = {0};
|
|
|
|
|
+ HAL_RTC_GetTime(&hrtc, &now, RTC_FORMAT_BIN);
|
|
|
|
|
+ IDLE_struct = now; // 记录上报时间
|
|
|
|
|
+ }else {
|
|
|
|
|
+ RTC_TimeTypeDef now = {0};
|
|
|
|
|
+ HAL_RTC_GetTime(&hrtc, &now, RTC_FORMAT_BIN);
|
|
|
|
|
+
|
|
|
|
|
+ int pressedSeconds = (now.Hours * 3600 + now.Minutes * 60 + now.Seconds)
|
|
|
|
|
+ - (IDLE_struct.Hours * 3600 + IDLE_struct.Minutes * 60 + IDLE_struct.Seconds);
|
|
|
|
|
+ if (pressedSeconds < 0) pressedSeconds += 24 * 3600;
|
|
|
|
|
+ // printf("不为idle状态的时间为:%d\r\n",pressedSeconds);
|
|
|
|
|
+
|
|
|
|
|
+ if (pressedSeconds >= 20) {
|
|
|
|
|
+ deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_INIT);
|
|
|
|
|
+ // printf("111111\r\n");
|
|
|
|
|
+ IDLE_struct = now; // 记录上报时间
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
// 解析后台命令
|
|
// 解析后台命令
|
|
|
if (GET_CMD( deviceInfo.commandFromCloud) == IDLE && GET_STEP(deviceInfo.commandFromCloud) == STEP_VERIFY) {
|
|
if (GET_CMD( deviceInfo.commandFromCloud) == IDLE && GET_STEP(deviceInfo.commandFromCloud) == STEP_VERIFY) {
|
|
@@ -384,8 +387,7 @@ int main(void)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 03:请求蓝牙数据
|
|
// 03:请求蓝牙数据
|
|
|
- if ((GET_CMD( deviceInfo.commandFromCloud) == REQUEST_BLUETOOTH_DATA && deviceInfo.isOnline) || deviceInfo.isSOS) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (((GET_CMD(deviceInfo.commandFromCloud) == REQUEST_BLUETOOTH_DATA && deviceInfo.isOnline ) || deviceInfo.isSOS)) {
|
|
|
switch (GET_STEP(deviceInfo.commandFromCloud)) {
|
|
switch (GET_STEP(deviceInfo.commandFromCloud)) {
|
|
|
case REQUEST_BLUETOOTH_DATA_SCAN:
|
|
case REQUEST_BLUETOOTH_DATA_SCAN:
|
|
|
Timer_Managment_Fun(&htim4, TIMER_OP_START);
|
|
Timer_Managment_Fun(&htim4, TIMER_OP_START);
|
|
@@ -419,23 +421,30 @@ int main(void)
|
|
|
deviceInfo.forwardBLAndLoraDataDuration = 0;
|
|
deviceInfo.forwardBLAndLoraDataDuration = 0;
|
|
|
i = 0;
|
|
i = 0;
|
|
|
deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_INIT);
|
|
deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_INIT);
|
|
|
- // printf("发送结束\r\n");
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
|
// 处理未知步骤
|
|
// 处理未知步骤
|
|
|
- printf("收到未知步骤,忽略处理\r\n");
|
|
|
|
|
- deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_VERIFY);
|
|
|
|
|
- rx_buf_uart2[0] = 0x55;
|
|
|
|
|
- rx_buf_uart2[1] = 0xBB;
|
|
|
|
|
- rx_buf_uart2[2] = 0x03;
|
|
|
|
|
- rx_buf_uart2[3] = deviceInfo.loraDeviceAddress_H;
|
|
|
|
|
- rx_buf_uart2[4] = deviceInfo.loraDeviceAddress_L;
|
|
|
|
|
- rx_buf_uart2[5] = 0x03;
|
|
|
|
|
- rx_buf_uart2[6] = 0xE8;
|
|
|
|
|
- rx_buf_uart2[7] = 0x00;
|
|
|
|
|
- rx_buf_uart2[8] = 0xFF;
|
|
|
|
|
- rx_buf_uart2[9] = 0xEE;
|
|
|
|
|
|
|
+ if (deviceInfo.isSOS) {
|
|
|
|
|
+ // HAL_Delay(1000);
|
|
|
|
|
+ deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_VERIFY);
|
|
|
|
|
+ rx_buf_uart2[0] = 0x55;
|
|
|
|
|
+ rx_buf_uart2[1] = 0xBB;
|
|
|
|
|
+ rx_buf_uart2[2] = 0x03;
|
|
|
|
|
+ rx_buf_uart2[3] = deviceInfo.loraDeviceAddress_H;
|
|
|
|
|
+ rx_buf_uart2[4] = deviceInfo.loraDeviceAddress_L;
|
|
|
|
|
+ rx_buf_uart2[5] = 0x03;
|
|
|
|
|
+ rx_buf_uart2[6] = 0xE8;
|
|
|
|
|
+ rx_buf_uart2[7] = 0x00;
|
|
|
|
|
+ rx_buf_uart2[8] = 0xFF;
|
|
|
|
|
+ rx_buf_uart2[9] = 0xEE;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ receiveBlDataCount = 0;
|
|
|
|
|
+ deviceInfo.timeCount = 0;
|
|
|
|
|
+ deviceInfo.forwardBLAndLoraDataDuration = 0;
|
|
|
|
|
+ i = 0;
|
|
|
|
|
+ deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_INIT);
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|