From 2a1115b77100f6bfeca9031d9a9c82b07e130d32 Mon Sep 17 00:00:00 2001 From: zhangbo <zhangbo@qq.com> Date: 星期五, 28 三月 2025 09:11:09 +0800 Subject: [PATCH] 功耗不对,基本逻辑实现 --- keil/uwb_app.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 100 insertions(+), 10 deletions(-) diff --git a/keil/uwb_app.c b/keil/uwb_app.c index 4358095..dc1aa48 100644 --- a/keil/uwb_app.c +++ b/keil/uwb_app.c @@ -11,6 +11,7 @@ #include "board.h" #include "lib_aoa.h" #include "WS2812.h" +#include "PCA9555.h" extern int simple_main(void); extern int temp_main(void); void Calibration_Time(void); @@ -37,7 +38,7 @@ extern uint8_t group_id; static uint16_t anc_id_recv,tag_id_recv; static int16_t rec_antdelay; -extern uint32_t dev_id; +extern uint16_t dev_id; static uint16_t taglist_pos,tmp_time; extern uint16_t tag_frequency; extern uint16_t disoffset; @@ -343,7 +344,7 @@ memcpy(&rx_rpt, rx_report, sizeof(struct MAC_HW_REPORT_T)); rx_length = 0; receive_error_flag=1; - OpenUWB();//再次开启UWB接收 + OpenUWB();//再次开启UWB接收 } // CloseUWB(); // OpenUWB();//再次开启UWB接收 @@ -371,6 +372,7 @@ uint32_t start_receive_count,end_receive_count,poll_timeout,current_count,temp_resp; uint16_t anchordata_id[TAG_NUM_IN_SYS],anchordata_dist[TAG_NUM_IN_SYS]; static uint8_t anchordata_bat[TAG_NUM_IN_SYS]; +static int8_t anchor_rssi[TAG_NUM_IN_SYS]; uint8_t anchordata_num = 0; static int16_t tagdist_list[TAG_NUM_IN_SYS]; uint16_t random_time; @@ -478,6 +480,9 @@ // } // anchordata_num=j; //} +extern uint8_t in_the_room_flag; +extern uint8_t lounei_flag; +uint8_t ceju_onlinetime; void TagListUpdate(void) { uint16_t i,j=0,k=0; @@ -488,8 +493,17 @@ tagid_list[j]=tagid_list[i]; tagdist_list[j] = tagdist_list[i]; anchordata_bat[j]=anchordata_bat[i];//电量随之更新 + anchor_rssi[j]=anchor_rssi[i]; tagofflinetime[j++]=tagofflinetime[i]; + in_the_room_flag=0; + ceju_onlinetime++; } + + } + if(ceju_onlinetime>0||taglist_num==0) + { + ceju_onlinetime=0; + in_the_room_flag=1; } taglist_num=j; } @@ -600,11 +614,11 @@ } void OpenUWB(void) { -// while(!mac_is_busy()) -// { - flag_temp1=uwb_rx(0, 0,range_timeout_us);//提交接收请求 - uwb_rx_flag=1; -// } +// while(!mac_is_busy()) +// { +// flag_temp1=uwb_rx(0, 0,range_timeout_us);//提交接收请求 +// uwb_rx_flag=1; +// } //LOG_INFO(TRACE_MODULE_APP,"打开uwb_rx\r\n"); } void UWBOneSecondTask(void) @@ -614,6 +628,8 @@ if(uwb_losttimer>g_com_map[UWB_RNAGE_TIME]) uwb_losttimer=g_com_map[UWB_RNAGE_TIME]+1;//防止溢出 } +extern uint8_t heart_upload_time; +uint16_t count_hexupload; void UWBSendUDPTask(void) { uint16_t checksum,tempdistarray[20]; @@ -626,15 +642,19 @@ { uint16_t id,dist; uint8_t bat; + int8_t rssi1; id = tagid_list[j]; dist = tagdist_list[j]; bat = anchordata_bat[j]; + rssi1=anchor_rssi[j]; tagid_list[j] = tagid_list[j+1]; tagdist_list[j] = tagdist_list[j+1]; anchordata_bat[j] = anchordata_bat[j+1]; + anchor_rssi[j] = anchor_rssi[j+1]; tagid_list[j+1] = id; tagdist_list[j+1] = dist; anchordata_bat[j+1] = bat; + anchor_rssi[j+1] = rssi1; } } @@ -674,7 +694,11 @@ memcpy(&usart_send[17+taglist_num*4],&anchordata_bat,taglist_num); checksum = Checksum_u16(&usart_send[2],15+5*taglist_num); memcpy(&usart_send[17+5*taglist_num],&checksum,2); - HexToAsciiSendUDP(usart_send,19+5*taglist_num); + if(lounei_flag==0&&heart_upload_time%3==0) + { + HexToAsciiSendUDP(usart_send,19+5*taglist_num); + count_hexupload++; + } taglist_num = 0; // rxnum=0; } @@ -698,10 +722,63 @@ UWBSendUDPTask(); } } +//int uwb_app_poll(void) +//{ +// +// UWBIdleTask(); +//} +//enumwltagstate wltag_state=RANGE; +uint32_t wltag_statetimer,wltag_uwbtimer; int uwb_app_poll(void) { + switch(wltag_state) + { + + case RANGE: +// time_flag=HIDO_TimerGetTick()-wltag_uwbtimer; + if(HIDO_TimerGetTick()-wltag_uwbtimer>2&&uwb_rx_flag==0) + { + wltag_uwbtimer = HIDO_TimerGetTick(); + OpenUWB(); + + } + else if(HIDO_TimerGetTick()-wltag_uwbtimer>1&&uwb_rx_flag==1) + { +// time_flag=HIDO_TimerGetTick()-wltag_uwbtimer; + wltag_uwbtimer = HIDO_TimerGetTick(); + CloseUWB(); + } + if(uwb_losttimer>g_com_map[UWB_RNAGE_TIME]) + { + wltag_statetimer = HIDO_TimerGetTick(); + if(uwb_rx_flag==0)//若要切换到搜索模式时没有开启则开启UWB + { + OpenUWB(); + } + wltag_state = SEARCH; + } + break; + case SEARCH: + if(HIDO_TimerGetTick()-wltag_statetimer>1) + { + wltag_statetimer = HIDO_TimerGetTick(); + wltag_state = CLOSE; + CloseUWB(); + + } + break; + case CLOSE: + if(HIDO_TimerGetTick()-wltag_statetimer>g_com_map[UWB_WAIT_TIME]) + { + wltag_statetimer = HIDO_TimerGetTick(); + wltag_state = SEARCH; + OpenUWB(); + } + break; + } UWBIdleTask(); } +uint8_t in_the_room_flag=0; int Anchor_App(void) { uint8_t i; @@ -755,11 +832,24 @@ Anchor_RecNearPoll(i); tagdist_list[taglist_pos]=rec_ancdistlist[i]; anchordata_bat[taglist_pos] = battary;//保存该基站电量 + anchor_rssi[taglist_pos]=rssi; +// in_the_room_flag=1; +// if(dev_id==g_com_map[DOOR_UWB_1]) +// { +// +// } +// if(dev_id==g_com_map[DOOR_UWB_2]) +// { +// +// } +// if(dev_id==g_com_map[DOOR_UWB_3]) +// { +// IN_THE_ROOM_FLAG=1; +// } if(taglist_pos==taglist_num)// taglist_pos==taglist_num 说明这个基站不在当前列表中 { //tempid==dev_id 说明基站下发测距报文有这个标签的信息 taglist_num++; //满足上述两种情况才会添加基站ID进入列表中,否则会出现标签不在基站列表中,标签也不响应的情况 - tagid_list[taglist_pos] = tag_id_recv; - + tagid_list[taglist_pos] = tag_id_recv; } break; } -- Gitblit v1.9.3