From 5ee4fd97245fed0d45fb60d1aa38cca83e788ed5 Mon Sep 17 00:00:00 2001 From: zhangbo <zhangbo@qq.com> Date: 星期二, 20 五月 2025 16:13:14 +0800 Subject: [PATCH] 修改了计步逻辑还有蓝牙上传逻辑 --- keil/include/src/Radio/lora_1268.c | 229 +++++++++++++++++++++++++++------------------------------ 1 files changed, 109 insertions(+), 120 deletions(-) diff --git a/keil/include/src/Radio/lora_1268.c b/keil/include/src/Radio/lora_1268.c index 6e0f48b..3141d79 100644 --- a/keil/include/src/Radio/lora_1268.c +++ b/keil/include/src/Radio/lora_1268.c @@ -15,6 +15,7 @@ #include "HIDO_TypeDef.h" #include "PCA9555.h" #include "mk_misc.h" +//#include "lis3dh_driver.c" /********************************************结构体**************************************************************/ typedef enum { @@ -157,7 +158,7 @@ lora_sendbuffer[HB_LORAPOWER_IDX] = g_com_map[LORA_POWER]; checksum = Checksum_u16(lora_sendbuffer,14); memcpy(&lora_sendbuffer[14],&checksum,2); - Radio.Send(lora_sendbuffer,16); +// Radio.Send(lora_sendbuffer,16); /*****************************心跳包上传内容*************************************/ @@ -172,7 +173,7 @@ extern uint8_t DMA_RXBuf_BT[200]; extern uint8_t report_ancnum; extern uint8_t report_ancnum_bt; -uint32_t BT_SEND_flag=0; +uint32_t BT_SEND_lenth=0; uint8_t BT_NUM=0; extern uint16_t report_ancdist[ANC_MAX_NUM],report_ancid[ANC_MAX_NUM]; extern uint8_t bat_percent; @@ -180,6 +181,14 @@ extern uint16_t REV_POLL_NUM; extern uint16_t REPLY_POLL_NUM; uint16_t num[3]={0,0,0}; +extern uint8_t stationary_flag; +extern uint8_t SOS_KEY_STATE; +uint32_t LORA_POLL_COUNT=0; +extern uint32_t step_count; +uint8_t step_count_rep; +//extern u16_m f_step; +extern uint8_t uwbled,gpsled,loraled,powerled; +extern uint8_t exercise_state; void LoraReportPoll(void) { // delay_ms(100); @@ -196,17 +205,9 @@ LoraReportFreqPoll(); flag_getwgresp = 0; - // wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; - //Lora_init(); - uint32_t para; - para=freq_list[2] * 100000; - -// rf_set_sf(REPORT_CHANNEL_SF); - SwitchLoraSettings(para,REPORT_CHANNEL_SF,0); - //rf_set_default_para(wg_report_freq,REPORT_CHANNEL_SF); - // SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,g_com_map[LORA_POWER]); -// dangqian_frqe=rf_read_freq(); + SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,22); + mir3da_get_step(); if(heatbeat_count++>HEATBEAT_UPDATE_TIME && WG_Connected == wg_state) //如果心跳包到达上传时间,并且网关处于链接状态,就上传心跳包 { heatbeat_count = 0; @@ -240,18 +241,26 @@ lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_GPS; lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+30; #else - lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG; - lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+ANCID_IDX; + BT_NUM=DMA_RXBuf_BT[0]; + if(SOS_KEY_STATE) + { + BT_NUM=0; + } +// lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG; + lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_BT; + lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+4*BT_NUM+ANCID_IDX+3; #endif 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[BAT_IDX] = bat_percent;//(uint8_t)(step_count % 256); +// lora_sendbuffer[BAT_IDX] = (uint8_t)(step_count % 256); + lora_sendbuffer[STATE_IDX] = !GET_USERKEY|stationary_flag<<1; //GET_USERKEY这个是那个lora——busy那个引脚 // lora_sendbuffer[STATE_IDX]=0x01; // lora_sendbuffer[GATEWAY_CHANL]=0x02; // lora_sendbuffer[CHANL_NUM]=0x03; - // 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); @@ -261,53 +270,52 @@ lora_sendbuffer[GPS_SPOWER_IDX] = gps_signalpower; lora_sendbuffer[GPS_CHAFENLINGQI] = gps_chafenlingqi; #endif - // memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&bar_height,2); -// memcpy(&report_ancid,test_temp,10); -// memcpy(&report_ancdist,test_temp2,10); - - 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); + memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&intheight,2); + lora_sendbuffer[BT_ANCID_IDX] = report_ancnum; + memcpy(&lora_sendbuffer[BT_ANCID_IDX+1],report_ancid,report_ancnum*2); + memcpy(&lora_sendbuffer[BT_ANCID_IDX+report_ancnum*2+1],report_ancdist,report_ancnum*2); uint8_t LORA_RETRANSNUSSION_BT=0; - BT_NUM=DMA_RXBuf_BT[0]; - num[0]=REV_RX_NUM; - num[1]=REV_POLL_NUM; - num[2]=REPLY_POLL_NUM; -// REV_RX_NUM=0; -// REV_POLL_NUM=0; -// REPLY_POLL_NUM=0; - if(0<BT_NUM&&BT_NUM<11) - { - lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_BT; - LORA_RETRANSNUSSION_BT=ANCID_IDX+report_ancnum*4; - //LORA_RETRANSNUSSION_BT report_ancnum_bt - +// +// num[0]=REV_RX_NUM; +// num[1]=REV_POLL_NUM; +// num[2]=REPLY_POLL_NUM; + LORA_RETRANSNUSSION_BT=BT_ANCID_IDX+report_ancnum*4+1; lora_sendbuffer[LORA_RETRANSNUSSION_BT] = 0x2D; //蓝牙上传标识符 + memcpy(&lora_sendbuffer[LORA_RETRANSNUSSION_BT+1],&DMA_RXBuf_BT[0],BT_NUM*2+1); //基站ID memcpy(&lora_sendbuffer[LORA_RETRANSNUSSION_BT+BT_NUM*2+2],&DMA_RXBuf_BT[1+BT_NUM*2],BT_NUM*2);//基站距离 - lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+4*BT_NUM+ANCID_IDX+2; - } - if(lora_sendbuffer[LORA_RETRANSNUSSION_BT]==0x2D) - { - checksum = Checksum_u16(lora_sendbuffer,4*BT_NUM+4*report_ancnum+ANCID_IDX+2); - memcpy(&lora_sendbuffer[ANCID_IDX+BT_NUM*4+report_ancnum*4+2],&checksum,2); - BT_SEND_flag++; - Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+4); + lora_sendbuffer[MSG_LENGTH] = LORA_RETRANSNUSSION_BT+4*BT_NUM+2; + + //保留位3 + if(step_count < 0) + step_count=0; + lora_sendbuffer[STEP_COUNT] = (uint8_t)(step_count % 256); + lora_sendbuffer[EXERCISE_STATE]=exercise_state; + lora_sendbuffer[RESERVED_POSITION]=0; +// } +// if(lora_sendbuffer[LORA_RETRANSNUSSION_BT]==0x2D) +// { + checksum = Checksum_u16(lora_sendbuffer,4*BT_NUM+4*report_ancnum+BT_ANCID_IDX+3); + memcpy(&lora_sendbuffer[LORA_RETRANSNUSSION_BT+BT_NUM*4+2],&checksum,2); + BT_SEND_lenth=BT_ANCID_IDX+report_ancnum*4+BT_NUM*4+5; + + Radio.Send(lora_sendbuffer,BT_SEND_lenth); + LORA_POLL_COUNT++; // LORA_3029_SINGLE_SEND(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+4,0); - } - else - { - checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX); - memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2); - Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+2); - } +// } +// else +// { +// checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX); +// memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2); +// Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+2); +// } // LORA_3029_SINGLE_SEND(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+4,0); memset(DMA_RXBuf_BT, 0,200); memset(&lora_sendbuffer[ANCID_IDX],0,200); //LED_TB_ON; - LORA_LED_ON; + loraled=1; for(uint8_t i=0;i<3;i++) recnum[i] = 0; @@ -321,7 +329,7 @@ //uint16_t rec_value,rec_delaytime,rx_count,datalen_offset; uint8_t shengji_flag,time=5; -extern uint32_t uwbled,gpsled,loraled,powerled; +//extern uint32_t uwbled,gpsled,loraled,powerled; extern struct RxDoneMsg RxDoneParams; //extern uint8_t Lora_tx_ancnum; @@ -350,7 +358,7 @@ checksum = Checksum_u16(lora_sendbuffer,11+data_length); memcpy(&lora_sendbuffer[11+data_length],&checksum,2); // LORA_3029_SINGLE_SEND(lora_sendbuffer,data_length+13,0); - Radio.Send(lora_sendbuffer,data_length+13); +// Radio.Send(lora_sendbuffer,data_length+13); //++; // Delay_Ms(100); } @@ -368,7 +376,7 @@ memcpy(&lora_sendbuffer[7], &g_com_map[index/2], data_length); checksum = Checksum_u16(lora_sendbuffer,9+data_length); memcpy(&lora_sendbuffer[9+data_length],&checksum,2); - Radio.Send(lora_sendbuffer,data_length+11); +// Radio.Send(lora_sendbuffer,data_length+11); // LORA_3029_SINGLE_SEND(lora_sendbuffer,data_length+11,0); // Delay_Ms(100); @@ -381,7 +389,7 @@ uint16_t lora_send_count; uint8_t mode_flag=0; uint32_t frqe,dangqian_frqe; -uint32_t freq_list[4] = {470000000/100000,4730,4780,4910}; + void Lora_Tx_Poll() { @@ -396,6 +404,7 @@ { // gpio_pin_set(IO_PIN_5); + if(lora_send_count++%10==0||lora_jianting_flag) { lora_tx_flag=0; @@ -403,67 +412,11 @@ if(rec_secdelay>0) { rec_secdelay--; -// if(lora_jianting_flag) -// { -// if(++group_id>GROUP_NUM) -// { -// group_id = 1; -// } -// t22[ti++] = group_id; -// if(ti>=20) -// ti=0; -// group_min_dist[group_id] = 0xffff; -// Radio.Standby(); -// SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0); -// Radio.Rx(0); -// } return; } -// //找3个小组中最近距离最大的小组,上传报文后切换到这个小组,因为上传报文会时间占用。 -// if(group_min_dist[1]>group_min_dist[2]) //如果1大于2 -// { -// group_maxdist_index = group_min_dist[1]>group_min_dist[3]?1:3; //取 1和3 最大值 -// group_mindist_index = group_min_dist[2]<group_min_dist[3]?2:3;//取 2和3 最小值 -// -// }else{ -// group_maxdist_index = group_min_dist[2]>group_min_dist[3]?2:3; //取 2和3 最大值 -// group_mindist_index = group_min_dist[1]<group_min_dist[3]?1:3;//取 1和3 最小值 -// } -//// group_id = 1; -// group_id = group_maxdist_index; #endif - t22[ti++] = group_id; - if(ti>=20) - ti=0; - // group_min_dist[group_id] = 0xffff; - // Radio.Standby(); - //rf_antenna_close(); -// rf_set_mode(RF_MODE_STB3); -// uint32_t para; -// frqe=((UWB_CHANNEL_FRQ+group_id)*100000); -// para=freq_list[1] * 100000; -//// rf_set_default_para(frqe,UWB_CHANNEL_SF); -// rf_set_carrier_wave_off(); -//// rf_set_carrier_wave_on(); -// rf_set_freq(para); -// rf_set_sf(5); -//// rf_set_tx_power(para); -//// rf_set_carrier_wave_freq(freq_list[1] * 100000); -// //SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0); -// dangqian_frqe=rf_read_freq(); - // LoraSendComMap(WGRSP_RWTAG_READ); - - //delay_us(5000); -// rf_enter_continous_rx(); - //LedTask(); - //LoraHeartBeartPoll(); -// if(rf_continous_tx_send_data(tx_test_buf, TX_LEN) != OK) -// { -// while(1); -// } - // rf_get_mode(); - LoraReportPoll(); - // LedOff_task(); + + LoraReportPoll(); } } @@ -486,9 +439,10 @@ //uint32_t lora_zhuangtai; //uint16_t current_count; //extern wg_state_enum wg_state; - +uint8_t txdone=0; void OnTxDone( void ) -{ +{ + txdone++; if(flag_writepara_needreset) //配置写入完成设备需要重启 { printf("网关下发配置写入完成,重启"); @@ -503,7 +457,7 @@ else { Radio.Rx( 50 ); - LORA_LED_OFF; + } } #define BUFFER_SIZE 255 // Define the payload size here @@ -531,8 +485,11 @@ uint16_t rec_value,rx_count,datalen_offset; int32_t target_count; uint32_t sleep_time_count=0; +uint32_t sleep_time_count_LAST=0; +uint16_t time_count; uint8_t LoraUp_flag; - +uint16_t REV_WG_pack=0; +uint8_t rxdone=0; void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { uint16_t checksum1; @@ -541,6 +498,7 @@ RssiValue = rssi; SnrValue = snr; Radio.Standby(); + rxdone++; no_rx_flag = 0; lora_up_rec_flag=1; if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_WGRESPTAG) @@ -564,8 +522,10 @@ switch(RX_Buffer[PWTAG_RW_FLAG_IDX]) { case WGRSP_RWTAG_NONE: + REV_WG_pack++; wg_report_freq = RX_Buffer[POLL_FREQ_IDX]+400; memcpy(&rec_delaytime,&RX_Buffer[NEXTPOLL_TIME_IDX],2); + if(report_ancnum<2) { datalen_offset = report_ancnum*85; @@ -577,12 +537,30 @@ { rec_secdelay = 0; } - sleep_time_count =(__MS_TO_32K_CNT(rec_delaytime)/10)- delaytime-datalen_offset; + if(rec_delaytime<500) + { + int t; + t++; + } +// sleep_time_count =(__MS_TO_32K_CNT(rec_delaytime)/10)- delaytime-datalen_offset; + sleep_time_count =(__MS_TO_32K_CNT(rec_delaytime)/10); while(sleep_time_count>=32768) { sleep_time_count-=32768; } -// sleep_timer_start(sleep_time_count); + while(sleep_time_count<2000) + { + sleep_time_count+=10000; + } +// if(REV_WG_pack==1) +// { +// sleep_time_count_LAST=sleep_time_count; +// } +// if(abs(sleep_time_count_LAST-sleep_time_count)>2000||REV_WG_pack==1) +// { +// sleep_timer_start(sleep_time_count); + time_count++; +// } break; case WGRSP_RWTAG_READ: no_rx_flag = 1; @@ -629,6 +607,17 @@ break; } } + if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_RANGEPOLL) + { + +// uwb_open(); + +//// UwbRange(); + +// uwb_ceju_count++; + } + + } } -- Gitblit v1.9.3