chen
2025-05-26 1e1b1b9f73152b17b960c5c2b1531d66ca4ddbe0
移植完新版lora和新版测距代码,lora传输有问题未解决
已修改5个文件
155 ■■■■ 文件已修改
keil/include/drivers/uwb_app.c 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
keil/include/main/main.c 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
keil/include/src/Radio/lora_1268.c 117 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
keil/include/src/Radio/lora_1268.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pin_config.c 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
keil/include/drivers/uwb_app.c
@@ -281,7 +281,7 @@
/* RX done process handler. */
int8_t rssi;
uint32_t range_timeout_us = 2000000;//yuan5000
uint8_t flag_temp2,flag_temp1;
uint8_t flag_temp2,flag_temp1,resp_tx_flag;
uint16_t uwb_losttimer;
static void rx_int_callback(struct MAC_HW_REPORT_T *rx_report)
{        uint8_t valid_sts=0;
@@ -290,7 +290,7 @@
    /** UWB RX success */
    if (rx_report->err_code == UWB_RX_OK)
    {
    {        resp_tx_flag=0;
        /* Received data does not contain FCS */
        rx_length = rx_report->pkt_len;
        memcpy(rx_buf, rx_report->pkt_data, rx_length);
@@ -303,6 +303,10 @@
        rssi = rx_report->rssi;
        receive_flag=1;
                Anchor_App();
            if(resp_tx_flag==0)
            {
              OpenUWB();
            }
            #ifdef STS_MODE
                valid_sts= sts_valid_check();
      if (valid_sts)
@@ -330,9 +334,9 @@
                    temp_count= phy_timer_count_get();
        memcpy(&rx_rpt, rx_report, sizeof(struct MAC_HW_REPORT_T));
        rx_length = 0;
            //    OpenUWB();//再次开启UWB接收
                OpenUWB();//再次开启UWB接收
    }
    OpenUWB();//再次开启UWB接收
    //OpenUWB();//再次开启UWB接收
}
/* TX done process handler. */
@@ -346,6 +350,7 @@
    {
        temp_count= phy_timer_count_get();
        temp_internal=temp_count;
                OpenUWB();
        resp_tx_num++;
        //        OpenUWB();//再次开启UWB接收
        //LOG_INFO(TRACE_MODULE_APP, "poll_rx_num is %d,resp_tx_num is %d\r\n",poll_rx_num,resp_tx_num);
@@ -468,7 +473,7 @@
    for(i=0; i<taglist_num; i++)
    {        
            
            if(tagofflinetime[i]++<REPORT_TAG_KEEPTIMES)
            if(tagofflinetime[i]<REPORT_TAG_KEEPTIMES)
        {
            report_ancid[k]=tagid_list[i];
            report_ancdist[k++]=(uint16_t)tagdist_list[i];
@@ -517,6 +522,7 @@
    temp_resp_i64=resp_tx_ts_i64;
    temp_count3= phy_timer_count_get();
    flag_temp2=uwb_tx(send_buffer, 40,1 ,resp_tx_en_start_u32);//立即发送测试size大小
        resp_tx_flag=1;//限制重复开启
        tagofflinetime[taglist_pos] = 0;//更新标签通信
//    temp_count1=phy_timer_count_get();
    //while(mac_is_busy());
@@ -595,7 +601,7 @@
        if(secondtask_search_flag)//更新S时间TICK
        {
        HIDO_TimerTick();
        TagListUpdate();
        //TagListUpdate();
//    GPS_Poll();
//        if(nomove_count<=g_com_map[NOMOVESLEEP_TIME])//防止溢出
//    nomove_count++;
keil/include/main/main.c
@@ -170,8 +170,12 @@
    port = g_com_map[TCP_PORT];
    g_com_map[VERSION] = (1<<8)|0;
    LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id);
    LOG_INFO(TRACE_MODULE_APP,"固件版本:MK_Air_tag_免布线模式 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
    LOG_INFO(TRACE_MODULE_APP,"服务器地址: %d.%d.%d.%d:%d.\r\n",ip0,ip1,ip2,ip3,port);
        if(gpio_pin_get_val(MODE_CHANGE_PIN))
    LOG_INFO(TRACE_MODULE_APP,"固件版本:MK_Air_tag模式 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
        else{
        LOG_INFO(TRACE_MODULE_APP,"固件版本:MK_免布线模式 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
        }
    //LOG_INFO(TRACE_MODULE_APP,"服务器地址: %d.%d.%d.%d:%d.\r\n",ip0,ip1,ip2,ip3,port);
}
void MinuteTask(void)
{        
@@ -300,10 +304,11 @@
    // Configure IO_04 for RF Switch
    gpio_pin_set_dir(IO_PIN_4, GPIO_DIR_OUT, 0);
#else
        Program_Init();
        spi_init();
    // 模式判断脚和spi nrst脚初始化
    board_mode_pin_init();
                Program_Init();
//    board_led_on(BOARD_LED_1);
#endif
        Board_LORA_NVIC_Init(Lora_irq_handler);
@@ -353,7 +358,7 @@
     // Disable watchdog timer
    wdt_close(WDT_ID0);
    LOG_INFO(TRACE_MODULE_APP, "UCI FiRa example\r\n");
    if(gpio_pin_get_val(MODE_CHANGE_PIN))
    if(gpio_pin_get_val(MODE_CHANGE_PIN))//记得改回来与正式的相反
    {
        // Platform init for WSF
    PalSysInit();
keil/include/src/Radio/lora_1268.c
@@ -187,117 +187,6 @@
#define GET_USERKEY gpio_pin_get_val(SOS_PIN)
void LoraReportPoll(void)
{
////    // delay_ms(100);
////#ifdef _USE_BAR
////    GetPressAndHeight();
////    intheight = Height*100;
////#endif
////#ifdef _SMT_TEST
////    printf("气压值:%d",intheight);
////#endif
//////    TagListUpdate();
////    LoraReportFreqPoll();
////    flag_getwgresp = 0;
//    SwitchLoraSettings(478,REPORT_CHANNEL_SF,22);
////    if(heatbeat_count++>HEATBEAT_UPDATE_TIME && WG_Connected == wg_state) //如果心跳包到达上传时间,并且网关处于链接状态,就上传心跳包
////    {
////        heatbeat_count = 0;
////        LoraHeartBeartPoll();
////        return;
////    }
////    for(uint16_t i=0; i<report_ancnum-1; i++)
////    {
////        for(uint16_t j=0; j<report_ancnum-1-i; j++)
////        {
////            if(report_ancdist[j]>report_ancdist[j+1])
////            {
////                uint16_t id,dist;
////                uint8_t bat;
////                id = report_ancid[j];
////                dist = report_ancdist[j];
////                report_ancid[j] = report_ancid[j+1];
////                report_ancdist[j] = report_ancdist[j+1];
////                report_ancid[j+1] = id;
////                report_ancdist[j+1] = dist;
////            }
////        }
////    }
////
////    if(report_ancnum>LORA_REPORT_MAXANC_NUM)                                  //考虑lora传输时间,最多发送10个基站数据。
////        {
////      report_ancnum = LORA_REPORT_MAXANC_NUM;
////        }
////
////#ifdef USE_GPS
////    lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_GPS;
////    lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+30;
////#else
////        BT_NUM=DMA_RXBuf_BT[0];
////        if(SOS_KEY_STATE)
////        {
////            BT_NUM=0;
//////        }
////    lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG;
//        lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_BT;
//    //lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+4*BT_NUM+ANCID_IDX+3;
////#endif
//    memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2);
//    memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2);
//    lora_sendbuffer[SEQNUM_IDX] = seq_num++;
//    lora_sendbuffer[BAT_IDX] = bat_percent;
////        lora_sendbuffer[STATE_IDX] = !GET_USERKEY|stationary_flag<<1;
////        //GET_USERKEY这个是那个lora——busy那个引脚
//////        lora_sendbuffer[STATE_IDX]=0x01;
//////        lora_sendbuffer[GATEWAY_CHANL]=0x02;
//////        lora_sendbuffer[CHANL_NUM]=0x03;
////
////#ifdef USE_GPS
////    memcpy(&lora_sendbuffer[GPS_JINGDU_IDX],&gps_jingdu,8);
////    memcpy(&lora_sendbuffer[GPS_WEIDU_IDX],&gps_jingdu,8);
////    memcpy(&lora_sendbuffer[GPS_HEIGHT_IDX],&gps_height,8);
////    lora_sendbuffer[GPS_STATE_IDX] = gps_state;
////    lora_sendbuffer[GPS_SATEL_NUM_IDX] = gps_satel_num;
////    lora_sendbuffer[GPS_SPOWER_IDX] = gps_signalpower;
////    lora_sendbuffer[GPS_CHAFENLINGQI] = gps_chafenlingqi;
////#endif
////    memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&intheight,2);
////    lora_sendbuffer[BT_ANCID_IDX] = report_ancnum;
////    memcpy(&lora_sendbuffer[BT_ANCID_IDX+1],report_ancid,report_ancnum*2);
////    memcpy(&lora_sendbuffer[BT_ANCID_IDX+report_ancnum*2+1],report_ancdist,report_ancnum*2);
////        uint8_t LORA_RETRANSNUSSION_BT=0;
//////
//////        num[0]=REV_RX_NUM;
//////        num[1]=REV_POLL_NUM;
//////        num[2]=REPLY_POLL_NUM;
////        LORA_RETRANSNUSSION_BT=BT_ANCID_IDX+report_ancnum*4+1;
////        lora_sendbuffer[LORA_RETRANSNUSSION_BT] = 0x2D;         //蓝牙上传标识符
////    memcpy(&lora_sendbuffer[LORA_RETRANSNUSSION_BT+1],&DMA_RXBuf_BT[0],BT_NUM*2+1);                                     //基站ID
////    memcpy(&lora_sendbuffer[LORA_RETRANSNUSSION_BT+BT_NUM*2+2],&DMA_RXBuf_BT[1+BT_NUM*2],BT_NUM*2);//基站距离
////        lora_sendbuffer[MSG_LENGTH] = LORA_RETRANSNUSSION_BT+4*BT_NUM+2;
//////        }
//////        if(lora_sendbuffer[LORA_RETRANSNUSSION_BT]==0x2D)
//////        {
////        checksum = Checksum_u16(lora_sendbuffer,4*BT_NUM+4*report_ancnum+BT_ANCID_IDX+3);
////        memcpy(&lora_sendbuffer[LORA_RETRANSNUSSION_BT+BT_NUM*4+2],&checksum,2);
//        BT_SEND_flag=BT_ANCID_IDX+report_ancnum*4+BT_NUM*4+5;
//        Radio.Send(lora_sendbuffer,BT_SEND_flag);
////        LORA_POLL_COUNT++;
//////        LORA_3029_SINGLE_SEND(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+4,0);
//////        }
//////        else
//////        {
//////        checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX);
//////        memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2);
//////        Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+2);
//////        }
#ifdef _USE_BAR
    GetPressAndHeight();
    intheight = Height*100;
@@ -570,8 +459,8 @@
                                        switch(RX_Buffer[PWTAG_RW_FLAG_IDX])
                                        {
                                                case WGRSP_RWTAG_NONE:
//                                                REV_WG_pack++;
//                        wg_report_freq = RX_Buffer[POLL_FREQ_IDX]+400;
                                                REV_WG_pack++;
                        wg_report_freq = RX_Buffer[POLL_FREQ_IDX]+400;
//                        memcpy(&rec_delaytime,&RX_Buffer[NEXTPOLL_TIME_IDX],2);
//                        if(report_ancnum<2)
@@ -629,7 +518,7 @@
                            g_com_map[rec_index/2] = rec_value;
                            save_com_map_to_flash();
                            LoraRspWriteCommap(SUBMSG_WRITE_ANCPARA);
                            //flag_writepara_needreset = 1;
                            flag_writepara_needreset = 1;
                            no_rx_flag = 1;                           
                                                            }
keil/include/src/Radio/lora_1268.h
@@ -41,7 +41,7 @@
#define UWB_CHANNEL_FRQ 470
#define UWB_CHANNEL_SF 5
#define REPORT_MANGE_CHANNEL_FRQ 478
#define REPORT_MANGE_CHANNEL_FRQ 500
#define REPORT_CHANNEL_SF 7
#define LR_DATA_CHANNEL_FRQ 475
pin_config.c
@@ -116,7 +116,10 @@
    // UART1 RX/TX
    io_pin_mux_set(IO_PIN_14, IO_FUNC4);
    io_pin_mux_set(IO_PIN_1, IO_FUNC4);
        //PA引脚开启
        io_pin_mux_set(IO_PIN_9, IO_FUNC6);
        io_pin_mux_set(IO_PIN_10, IO_FUNC6);
#elif BOARD_TYPE == MK8000_DK