zhyinch
2021-05-17 a44433dad85a3ce434cca78695a866748dd24d3b
Ô´Âë/ºËÐİå/Src/application/dw_app.c
@@ -14,7 +14,7 @@
   DWT_PAC8,        /* Preamble acquisition chunk size. Used in RX only. */
   9,               /* TX preamble code. Used in TX only. */
   9,               /* RX preamble code. Used in RX only. */
   0,               /* Use non-standard SFD (Boolean) */
   1,               /* Use non-standard SFD (Boolean) */
   DWT_BR_6M8,      /* Data rate. */
   DWT_PHRMODE_STD, /* PHY header mode. */
   (129 + 8 - 8)    /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */
@@ -338,10 +338,17 @@
   tx_nearpoll_msg[SEQUENCE_IDX] = frame_seq_nb++;
   tx_nearpoll_msg[NEARBASENUM_INDEX] = nearbase_num;
   memcpy(&tx_nearpoll_msg[NEARBASEID_INDEX],&nearbaseid_list,nearbase_num*2);
    for(i=0;i<nearbase_num;i++)
    { memcpy(&tx_nearpoll_msg[NEARBASEID_INDEX+nearbase_num*2+i*2],&nearbase_distlist[i],2);}
        for(i=0;i<MAX_NEARBASE_NUM;i++)
    {
        nearbase_distlist[i]=0x1ffff;
    }
   tx_nearpoll_msg[MESSAGE_TYPE_IDX] = NEAR_POLL;   
   memcpy(&tx_nearpoll_msg[ANCHOR_ID_IDX],&mainbase_id,2);   
   dwt_writetxdata(13+2*nearbase_num, tx_nearpoll_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去
   dwt_writetxfctrl(13+2*nearbase_num, 0);//设置超宽带发送数据长度
   dwt_writetxdata(13+4*nearbase_num, tx_nearpoll_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去
   dwt_writetxfctrl(13+4*nearbase_num, 0);//设置超宽带发送数据长度
   dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置
   
   flag_finalsend=0;
@@ -450,7 +457,8 @@
                        if(temp_dist!=0x1ffff)
                           {
                              g_Resttimer=0;
                              #ifndef USART_INTEGRATE_OUTPUT
                                        IWDG_Feed();
                              #ifdef USART_SINGLE_OUTPUT
                              usart_send[2] = 1;//正常模式
                              usart_send[3] = 17;//数据段长度
                              usart_send[4] = frame_seq_nb;//数据段长度
@@ -500,7 +508,7 @@
//                           tagslotpos=GetRandomSlotPos(rec_tagpos_binary);
                           if(temp_dist!=0x1ffff)
                           {
                              #ifndef USART_INTEGRATE_OUTPUT
                              #ifdef USART_SINGLE_OUTPUT
                              usart_send[2] = 1;//正常模式
                              usart_send[3] = 17;//数据段长度
                              usart_send[4] = frame_seq_nb;//数据段长度
@@ -607,10 +615,7 @@
               report_num++;
            }
         }
         for(i=0;i<MAX_NEARBASE_NUM;i++)
         {
            nearbase_distlist[i]=0x1ffff;
         }
         
      //   printf("%d,%d",temp_sync_timer2,temp_sync_timer1);
         #ifdef USART_INTEGRATE_OUTPUT      
@@ -824,6 +829,7 @@
            dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
         }
}
extern u16 dist_threshold;
u8 misdist_num[TAG_NUM_IN_SYS],seize_anchor,getrange_success=0;
u8 Anchor_RecNearPoll(u8 ancrec_nearbasepos) //0 mainbase  1 first near_base
{
@@ -874,9 +880,7 @@
         }
         result = dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED);//延迟发送,等待接收
         battary = rx_buffer[BATTARY_IDX];
         button = rx_buffer[BUTTON_IDX];
         frame_seq_nb2 = rx_buffer[SEQUENCE_IDX];
         if(result==0)
         {
            while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR))&&!g_start_sync_flag)///不断查询芯片状态直到接收成功或者出现错误
@@ -922,16 +926,18 @@
               /*--------------------------以下为非测距逻辑------------------------*/
               //dist_cm=33000;
               getrange_success = 1;
               g_Resttimer=0;
               LED0_BLINK; //每成功一次通讯则闪烁一次
               dis_after_filter=dist_cm;
               hex_dist = dist_cm+(int16_t)g_com_map[DIST_OFFSET]*10;
               g_flag_Taggetdist[taglist_pos]=0;
               if(hex_dist>0&&hex_dist<2000000)
               if(hex_dist>-1000&&hex_dist<2000000)
               {
               if(abs(hex_dist-his_dist[taglist_pos])<10000||misdist_num[taglist_pos]>3)
               if(abs(hex_dist-his_dist[taglist_pos])<dist_threshold||misdist_num[taglist_pos]>3)
               {
                  int32_t filter_dist;
                        g_Resttimer=0;
                        IWDG_Feed();
                  #ifdef TDFILTER
                  NewTrackingDiffUpdate(taglist_pos, (float)hex_dist);
                  filter_dist=pos_predict[taglist_pos]/10;
@@ -942,12 +948,14 @@
               tagdist_list[taglist_pos] = filter_dist;   
               his_dist[taglist_pos]=hex_dist;   
                  g_Tagdist[taglist_pos]=filter_dist;   
            #ifndef USART_INTEGRATE_OUTPUT
            #ifdef USART_SINGLE_OUTPUT
               usart_send[2] = 1;//正常模式 
               usart_send[3] = 17;//数据段长度
               usart_send[4] = frame_seq_nb2;//数据段长度
               memcpy(&usart_send[5],&tag_id_recv,2);
               memcpy(&usart_send[7],&dev_id,2);
               memcpy(&usart_send[7],&dev_id,2);
                            if(tagdist_list[taglist_pos]<=0)
                                tagdist_list[taglist_pos]=10;
               memcpy(&usart_send[9],&tagdist_list[taglist_pos],4);
               usart_send[13] = battary;
               usart_send[14] = button;
@@ -973,7 +981,7 @@
uint32_t current_syncid=0xffffffff,synclost_timer;
extern u8 flag_syncbase;
u8 tagpos_rec[50],tagpos_send[50],ancidlist_num;
u16 ancidlist_rec[20],ancidlist_send[20];
u16 ancidlist_rec[20],ancidlist_send[20],rec_ancidlist[20],rec_ancdistlist[20];
void Anchor_App(void)
{
   
@@ -1051,8 +1059,28 @@
            }
            break;
      
         case NEAR_POLL:
         case NEAR_POLL:
                frame_seq_nb2 = rx_buffer[SEQUENCE_IDX];
                battary = rx_buffer[BATTARY_IDX];
                button = rx_buffer[BUTTON_IDX];
                rec_nearbase_num=rx_buffer[NEARBASENUM_INDEX];
            memcpy(&tag_id_recv,&rx_buffer[TAG_ID_IDX],2);
                memcpy(&rec_ancidlist,&rx_buffer[NEARBASEID_INDEX],2*rec_nearbase_num);
                memcpy(&rec_ancdistlist,&rx_buffer[NEARBASEID_INDEX+2*rec_nearbase_num],2*rec_nearbase_num);
            #ifdef USART_ALL_OUTPUT
                    usart_send[2] = 0x0c;//正常模式
               usart_send[3] = 8+rec_nearbase_num*4;//数据段长度
               usart_send[4] = frame_seq_nb2;//数据段长度
                  usart_send[5] = battary;
               usart_send[6] = button;
                    usart_send[7] = rec_nearbase_num;
               memcpy(&usart_send[8],&tag_id_recv,2);
               memcpy(&usart_send[10],&rec_ancidlist,2*rec_nearbase_num);
               memcpy(&usart_send[10+rec_nearbase_num*2],&rec_ancdistlist,2*rec_nearbase_num);
               checksum = Checksum_u16(&usart_send[2],8+4*rec_nearbase_num);
               memcpy(&usart_send[10+4*rec_nearbase_num],&checksum,2);
               UART_PushFrame(usart_send,12+rec_nearbase_num*4);
            #endif
         if(tag_id_recv>=g_com_map[WHITELIST1_START]&&tag_id_recv<=g_com_map[WHITELIST1_END])
         {break;}
            taglist_pos=CmpTagInList(tag_id_recv);
@@ -1066,9 +1094,9 @@
               new_tagid=0;
            }
            tagofflinetime[taglist_pos]=0;
          temp_tagpos=round((float)(sync_timer%g_com_map[COM_INTERVAL])/slottime);
                temp_tagpos=round((float)(sync_timer%g_com_map[COM_INTERVAL])/slottime);
            tagpos_rec[(u8)temp_tagpos]=1;
            rec_nearbase_num=rx_buffer[NEARBASENUM_INDEX];
         
            if(rec_nearbase_num>ancidlist_num)
               {