| | |
| | | static u16 checksum; |
| | | u8 gps_state,gps_chafenlingqi,gps_satel_num,gps_signalpower; |
| | | double gps_jingdu,gps_weidu; |
| | | float gps_height; |
| | | extern u8 bat_percent,stationary_flag; |
| | | int16_t sendcount = 0,tp1; |
| | | int16_t sendcount = 0,tp1,bar_height; |
| | | u8 flag_getwgresp; |
| | | void LoraHeartBeartPoll(void) |
| | | { |
| | | LoraReportFreqPoll(); |
| | | flag_getwgresp = 0; |
| | | SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,g_com_map[LORA_POWER]); |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGHEARTBEAT; |
| | | lora_sendbuffer[MSG_LENGTH] = 14; |
| | | memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2); |
| | | memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2); |
| | | memcpy(&lora_sendbuffer[HB_VERSION_IDX],&g_com_map[VERSION],2); |
| | | memcpy(&lora_sendbuffer[HB_UWBPOWER_IDX],&g_com_map[POWER],2); |
| | | memcpy(&lora_sendbuffer[HB_LORAPOWER_IDX],&g_com_map[POWER],2); |
| | | checksum = Checksum_u16(lora_sendbuffer,14); |
| | | memcpy(&lora_sendbuffer[14],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,16); |
| | | } |
| | | uint16_t heatbeat_count = 3598; |
| | | #define HEATBEAT_UPDATE_TIME 3600 |
| | | void LoraReportPoll(void) |
| | | { |
| | | |
| | |
| | | LoraReportFreqPoll(); |
| | | flag_getwgresp = 0; |
| | | SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,g_com_map[LORA_POWER]); |
| | | if(heatbeat_count++>HEATBEAT_UPDATE_TIME && WG_Connected == wg_state) //如果心跳包到达上传时间,并且网关处于链接状态,就上传心跳包 |
| | | { |
| | | heatbeat_count = 0; |
| | | LoraHeartBeartPoll(); |
| | | return; |
| | | } |
| | | #ifdef USE_GPS |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_GPS; |
| | | #else |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG; |
| | | #endif |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+30; |
| | | memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2); |
| | | memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2); |
| | | lora_sendbuffer[SEQNUM_IDX] = seq_num++; |
| | | lora_sendbuffer[BAT_IDX] = bat_percent; |
| | | lora_sendbuffer[STATE_IDX] = !GET_USERKEY|stationary_flag<<1;; |
| | | lora_sendbuffer[STATE_IDX] = !GET_USERKEY|stationary_flag<<1; |
| | | #ifdef USE_GPS |
| | | memcpy(&lora_sendbuffer[GPS_JINGDU_IDX],&gps_jingdu,8); |
| | | memcpy(&lora_sendbuffer[GPS_WEIDU_IDX],&gps_jingdu,8); |
| | | memcpy(&lora_sendbuffer[GPS_HEIGHT_IDX],&gps_height,8); |
| | | lora_sendbuffer[GPS_STATE_IDX] = gps_state; |
| | | lora_sendbuffer[GPS_SATEL_NUM_IDX] = gps_satel_num; |
| | | lora_sendbuffer[GPS_SPOWER_IDX] = gps_signalpower; |
| | | lora_sendbuffer[GPS_CHAFENLINGQI] = gps_chafenlingqi; |
| | | #endif |
| | | memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&bar_height,2); |
| | | lora_sendbuffer[ANCNUM_IDX] = report_ancnum; |
| | | memcpy(&lora_sendbuffer[ANCID_IDX],report_ancid,report_ancnum*2); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*2],report_ancdist,report_ancnum*2); |
| | |
| | | LED_TB_ON; |
| | | // bat_percent=Get_Battary(); |
| | | |
| | | } |
| | | } |