From 068c7c0707f67e118e27cccd08b892faa9b2c6bd Mon Sep 17 00:00:00 2001
From: zhangbo <zhangbo@qq.com>
Date: 星期四, 31 十月 2024 18:03:15 +0800
Subject: [PATCH] 完成测距,但是收包时间还可以优化

---
 keil/include/main/main.c |   89 +++++++++++++++++++++++++++++---------------
 1 files changed, 59 insertions(+), 30 deletions(-)

diff --git a/keil/include/main/main.c b/keil/include/main/main.c
index d176e66..2214a33 100644
--- a/keil/include/main/main.c
+++ b/keil/include/main/main.c
@@ -93,6 +93,7 @@
 uint16_t warning_distance,prewarning_distance;
 int16_t fVoltage_mv,first_search_flag;
 uint8_t bat_percent,g_start_send_flag=1;
+uint8_t LORA_REV_uwb_up =0;
 uint8_t link_success_flag,motor_count;
 uint16_t gps_wait_count;
 uint8_t state5v = 1;
@@ -281,6 +282,7 @@
 uint8_t flag_sleeptimer,flag_secondtask,secondtask_count;
 static void sleep_timer_callback(void *dev, uint32_t time)
 {
+    g_start_send_flag=1;
 //    IO_control_init();
 //    UWBPoll();
 //    
@@ -494,36 +496,47 @@
 uint32_t successful_cnt=0;
 uint8_t flag_4guart_needinit=0;
 #define TX_LEN  10
+#define RX_LEN  10
 uint8_t tx_test_buf[TX_LEN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+uint8_t RF_RX_temp[RX_LEN]={0};
 extern struct RxDoneMsg RxDoneParams;
 static void Lora_irq_handler(enum IO_PIN_T pin)
 {   
    ceshi++;
         rf_irq_process();
-        if(rf_get_transmit_flag() == RADIO_FLAG_TXDONE)
-        {
-            rf_set_transmit_flag(RADIO_FLAG_IDLE);
-            rf_enter_continous_rx();
-//            rf_delay_ms(1000);
-//            if(rf_continous_tx_send_data(tx_test_buf, TX_LEN) != OK)
-//            {
-////                rf_enter_continous_rx();
-//            }
-//            else
-//            {
-//                error_cnt ++;
-//            }
-        }
+	      //g_start_send_flag=1;
+//        if(rf_get_transmit_flag() == RADIO_FLAG_TXDONE)
+//        {
+//            rf_set_transmit_flag(RADIO_FLAG_IDLE);
+//            rf_enter_continous_rx();
+////            rf_delay_ms(1000);
+////            if(rf_continous_tx_send_data(tx_test_buf, TX_LEN) != OK)
+////            {
+//////                rf_enter_continous_rx();
+////            }
+////            else
+////            {
+////                error_cnt ++;
+////            }
+//        }
         if(rf_get_recv_flag() == RADIO_FLAG_RXDONE)
         {
             rf_set_recv_flag(RADIO_FLAG_IDLE);
+					  memcpy(RF_RX_temp,RxDoneParams.Payload,RxDoneParams.Size);
+					  if(RF_RX_temp[0]==0x48&&RF_RX_temp[1]==0x58)
+						{
+							LORA_REV_uwb_up=1;
+							
+						}
+						// rf_enter_continous_rx(); //重新进入接收模式
+					  //UwbRange();
 //            DDL_Printf("Rx : SNR: %f ,RSSI: %d \r\n", RxDoneParams.Snr, RxDoneParams.Rssi);
-            int i=0;
+              //int i=0;
 //            for(i = 0; i < RxDoneParams.Size; i++)
 //            {
 //                printf("0x%02x ", RxDoneParams.Payload[i]);
 //            }
-            error_cnt ++;
+           // error_cnt ++;
         }
         if((rf_get_recv_flag() == RADIO_FLAG_RXTIMEOUT) || (rf_get_recv_flag() == RADIO_FLAG_RXERR))
         {
@@ -587,17 +600,17 @@
     Lora_init();
     rf_set_default_para();
 //    
-    rf_enter_continous_tx();
+    rf_enter_continous_rx();
 //    rf_set_transmit_flag(RADIO_FLAG_TXDONE);
 //    rf_set_transmit_flag(RADIO_FLAG_TXDONE);
-    if(rf_continous_tx_send_data(tx_test_buf, TX_LEN) != 0)
-    {
-        error_cnt++;
-    }
-    else
-    {
-        successful_cnt ++;
-    }     
+//    if(rf_continous_tx_send_data(tx_test_buf, TX_LEN) != 0)
+//    {
+//        error_cnt++;
+//    }
+//    else
+//    {
+//        successful_cnt ++;
+//    }     
     
     
 //  while (rf_get_transmit_flag() == RADIO_FLAG_IDLE) ;
@@ -616,19 +629,35 @@
 //    adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样
 		   Program_Init();
 //    uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback);
-//   
+//    
 //// Initialize low power mode
 //    power_init();
 //      AIR780E_Reset(); //4G模块重启,耗时1.5秒,这个是无法同步的关键
-//    sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback);
+    sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback);
 
-//    sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试
-
+    sleep_timer_start(__MS_TO_32K_CNT(1000));//测试
+#ifdef DEBUG_BOXING
+		io_pin_mux_set(IO_PIN_5,IO_FUNC0);
+		gpio_pin_set_dir(IO_PIN_5,GPIO_DIR_OUT,0);
+		io_pull_set(IO_PIN_5,IO_PULL_DOWN,IO_PULL_UP_LEVEL4);
+#endif
 //    board_acceleration_detection_init(move_handler);
     Uwbinit();
     while (1)
     {
-        UwbRange();
+			if(LORA_REV_uwb_up)
+			{
+			  LORA_REV_uwb_up=0;
+			  UwbRange();
+			}
+        if(g_start_send_flag)
+        {
+            g_start_send_flag=0;
+            
+        }
+				
+        
+       // UwbRange();
 //        rf_irq_process();
 //        if(rf_get_transmit_flag() == RADIO_FLAG_TXDONE)
 //        {

--
Gitblit v1.9.3