1
zhyinch
2021-10-25 c5193cf1c2e36894cbb2d7e9cd171b64f81ae8ea
Src/application/dw_app.c
@@ -562,7 +562,7 @@
                           {flag_getresponse=1;}
                           lastsync_timer=sync_timer;
                           //offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset;
                           SetNextPollTime(tagslotpos);
//                           SetNextPollTime(tagslotpos);
      }
         
         memcpy(&temp_dist, &rx_buffer[DIST_IDX], 4);
@@ -675,7 +675,46 @@
//         tyncpoll_time = (tagslotpos--%max_slotpos)*slottime;
   }
}
extern u32 synctimer;
u8 pd_i;
u32 temptime,delaytime;
u16 delaycount;
int16_t poll_offsettime=-6900;
extern u16 slotpos_intoatl, slotpos;
void NextPollDelay(u32 anchor_time)
{
      tagslotpos = 0 ;
    for(pd_i=0;pd_i<tag_frequency;pd_i++)
    {
        slotpos_intoatl = pd_i*bigslot_num+tagslotpos;
        temptime = (slotpos_intoatl*SLOTTIME_MS+100)*100;
        if(anchor_time<temptime-5000)
        {
            delaytime = temptime-anchor_time+poll_offsettime;
            return ;
        }
    }
    temptime = (tagslotpos*SLOTTIME_MS+100+10000)*100;
    delaytime = temptime-anchor_time+poll_offsettime;
   return ;
}
u16 lpcount,poll_startcount;
u16 waketopolltimeus = 4000;
#define BASENUM_COMTIME 244
u32 last_anchor_time;
void SetLPTimer(u32 anchor_time)
{
    NextPollDelay(anchor_time);
    current_count=HAL_LPTIM_ReadCounter(&hlptim1);
    lpcount = current_count+delaytime/LPTIMER_LSB+(10-nearbase_num)*8;
      poll_startcount = lpcount+(waketopolltimeus)/LPTIMER_LSB;
      if(poll_startcount>=32768)
      {
      poll_startcount -=32768;
      }
    __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount);
      last_anchor_time = anchor_time;
}
void NearPoll(void)
{
   
@@ -817,13 +856,7 @@
                                 {sync_timer=0;}
                           }
                           ancsync_time=((sync_timer)*1000+tmp_time);   
                           last_slotnum=current_slotnum;
                           current_slotnum=((float)(sync_timer*10 - tagslotpos*SLOTTIME_MS)/(SLOTTIME_MS*bigslot_num))+1;
                           if(current_slotnum==last_slotnum-1)
                           {flag_getresponse=1;}
                           lastsync_timer=sync_timer;
                           offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset;
                           SetNextPollTime(tagslotpos);
                           SetLPTimer(ancsync_time);
                           if(result==0)
                                 {while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成
                                 { };}                        
@@ -886,7 +919,8 @@
         {
            tag_state = STARTPOLL;
         }         
   if(mainbase_lost_count!=0)
         {SetLPTimer(last_anchor_time);}
         if(para_update)
         {
         uint8_t pack_length = 0,pack_index = 0,pack_msgtype = 0;
@@ -936,7 +970,7 @@
         if(tagslotpos--<2)
            tagslotpos=TOTAL_SLOTNUM;
      }
      SetNextPollTime(tagslotpos);
//      SetNextPollTime(tagslotpos);
      dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);         //设置发送后开启接收,并设定延迟时间
    dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);