zhyinch
2020-04-07 a185e714b1710025030317a1a32ad0ce660deef5
Src/application/dw_app.c
@@ -104,7 +104,7 @@
static uint8_t tx_poll_msg[20] = {0};
static uint8_t tx_sync_msg[14] = {0};
//static uint8_t rx_resp_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'V', 'E', 'W', 'A', 0x10, 0x02, 0, 0, 0, 0};
static uint8_t tx_final_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static uint8_t tx_final_msg[24] = {0};
   
//static uint8_t rx_poll_msg[] = {0x00, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x21, 0, 0};
static uint8_t tx_resp_msg[20] = {0};
@@ -254,7 +254,7 @@
    Reset_DW1000();//重启DW1000 /* Target specific drive of RSTn line into DW1000 low for a period. */
      Spi_ChangePrescaler(SPIx_PRESCALER_SLOW);   //设置为快速模式
    dwt_initialise(DWT_LOADUCODE);//初始化DW1000
   Spi_ChangePrescaler(SPIx_PRESCALER_FAST);   //设置为快速模式
     Spi_ChangePrescaler(SPIx_PRESCALER_FAST);   //设置为快速模式
    /* Configure DW1000. See NOTE 6 below. */
    dwt_configure(&config);//配置DW1000
@@ -319,8 +319,11 @@
uint16_t checksum;
int8_t tag_delaytime;
extern uint16_t sync_timer;
uint16_t tmp_time,sync_count;
uint32_t time32_incr;uint32_t frame_len;
uint16_t tmp_time,current_slottimes;
uint32_t time32_incr;
int32_t ancsync_time;
uint32_t frame_len;
int32_t count_offset,nextpoll_delaytime;
void Tag_App(void)//发送模式(TAG标签)
{
   
@@ -338,7 +341,7 @@
    dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);         //设置发送后开启接收,并设定延迟时间
    dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);      
   tag_succ_times = 0;
   tx_poll_msg[BATTARY_IDX] = Get_Battary();
   tx_poll_msg[BATTARY_IDX] = bat_percent;
   //tx_poll_msg[BUTTON_IDX] = !READ_KEY0;
   tx_poll_msg[SEQUENCE_IDX] = frame_seq_nb++;
@@ -385,7 +388,7 @@
       * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */
      
      if (rx_buffer[MESSAGE_TYPE_IDX] == RESPONSE&&!memcmp(&rx_buffer[TAG_ID_IDX],&dev_id,4)) //判断接收到的数据是否是response数据
      { uint16_t anc_id_recv;
      { uint16_t anc_id_recv,current_count;
         /* Retrieve poll transmission and response reception timestamp. */
         poll_tx_ts = get_tx_timestamp_u64();                              //获得POLL发送时间T1
         resp_rx_ts = get_rx_timestamp_u64();                              //获得RESPONSE接收时间T4
@@ -402,17 +405,6 @@
            sync_timer++;
            if(sync_timer>=1010)
               {sync_timer=0;}
         }
         sync_count=(sync_timer*1000+tmp_time)/LPTIMER_LSB;
         __HAL_LPTIM_CNT_SET(&hlptim1, sync_count);
         for(i=0;i<100;i++)
         {
            lastpoll_count = slot_startcount+i*interval_count;
            if(lastpoll_count>sync_count)
            {
             __HAL_LPTIM_COMPARE_SET(&hlptim1, lastpoll_count);
               break;
            }
         }
         
@@ -437,10 +429,34 @@
         dwt_writetxdata(sizeof(tx_final_msg), tx_final_msg, 0);//将发送数据写入DW1000
         dwt_writetxfctrl(sizeof(tx_final_msg), 0);//设定发送数据长度
         result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送
         ancsync_time=((sync_timer+0)*1000+tmp_time);
         current_count=HAL_LPTIM_ReadCounter(&hlptim1);
      //   count_offset=sync_count-current_count-143;
      //   current_slottimes=(ancsync_time-10000)/(g_com_map[COM_INTERVAL]*1000);
         nextpoll_delaytime=tyncpoll_time*1000+g_com_map[COM_INTERVAL]*1000-((ancsync_time-10000)%(g_com_map[COM_INTERVAL]*1000))-5150;
         if(abs(ancsync_time-910000)<1000)
         {
         nextpoll_delaytime+=10000;
         }
         if(nextpoll_delaytime<2000)
         {
            nextpoll_delaytime+=g_com_map[COM_INTERVAL]*1000;
         }
         lastpoll_count= current_count+(nextpoll_delaytime)/LPTIMER_LSB;
         if(lastpoll_count>LPTIMER_1S_COUNT)
            lastpoll_count-=LPTIMER_1S_COUNT;
         __HAL_LPTIM_COMPARE_SET(&hlptim1, lastpoll_count);
//         printf("ancsync_time: %u     \r\n ",ancsync_time);
//         printf("current_slottimes: %u   ",current_slottimes);
//         printf("nextpoll_delaytime: %u   ",nextpoll_delaytime);
//         printf("current_count: %u   ",current_count);
//         printf("lastpoll_count: %u",lastpoll_count);
         
         tag_succ_times++;
         
            LED0_BLINK;
            
               memcpy(&anc_id_recv,&rx_buffer[ANCHOR_ID_IDX],2);
//               g_Tagdist[anc_id_recv]=   hex_dist;
@@ -458,7 +474,7 @@
               usart_send[14] = button;
               checksum = Checksum_u16(&usart_send[2],17);
               memcpy(&usart_send[19],&checksum,2);
               UART_PushFrame(usart_send,21);
         //      UART_PushFrame(usart_send,21);
               }
      //         memcpy(&Modbus_HoldReg[anc_id_recv*2],&hex_dist,4);
         /* Poll DW1000 until TX frame sent event set. See NOTE 8 below. */