keil/include/board/board.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
keil/include/drivers/global_param.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
keil/include/drivers/serial_at_cmd_app.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
keil/include/drivers/serial_at_cmd_app.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
keil/include/drivers/uwb_app.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
keil/include/main/main.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
keil/include/src/Radio/lora_1268.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
keil/include/src/Radio/lora_1268.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
pin_config.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
keil/include/board/board.c
@@ -414,11 +414,13 @@ // 判断是Airtag还是免布线模式 io_pin_mux_set(MODE_CHANGE_PIN, IO_FUNC0); gpio_pin_set_dir( MODE_CHANGE_PIN, GPIO_DIR_IN, 0); io_pull_set(MODE_CHANGE_PIN , IO_PULL_DOWN, IO_PULL_UP_LEVEL2); //io_pull_set(MODE_CHANGE_PIN , IO_PULL_DOWN, IO_PULL_UP_LEVEL2); io_pull_set(MODE_CHANGE_PIN , IO_PULL_DOWN, IO_PULL_UP_NONE);// 修改了 // 判断是休眠还是工作模式 io_pin_mux_set(SLEEP_PIN, IO_FUNC0); gpio_pin_set_dir(SLEEP_PIN, GPIO_DIR_IN, 0); io_pull_set(SLEEP_PIN , IO_PULL_DOWN, IO_PULL_UP_LEVEL2); //io_pull_set(SLEEP_PIN , IO_PULL_DOWN, IO_PULL_UP_LEVEL2);// 修改了 io_pull_set(SLEEP_PIN , IO_PULL_DOWN, IO_PULL_UP_NONE);// 修改了 //初始化NRST脚 io_pin_mux_set(LORA_NRST, IO_FUNC0); gpio_pin_set_dir(LORA_NRST , GPIO_DIR_OUT, 1); keil/include/drivers/global_param.h
@@ -51,6 +51,7 @@ #define NEARBASE_ID10 0x1a #define POWER 0x1B #define SET_START_TIME 0x1B #define IMU_THRES 0x1C #define NOMOVESLEEP_TIME 0x1D #define MOTOR_ENABLE 0x1E @@ -66,7 +67,7 @@ #define CNT_RESTART 0x30 #define CNT_REBOOT 0x31 #define CNT_UPDATE 0x32 #define BIND_DEV_ID 0x40 /*------------END Map Definition-------------------*/ keil/include/drivers/serial_at_cmd_app.c
@@ -72,7 +72,7 @@ send_frame[1] = 0xAA; send_frame[2] = 0x03; send_frame[3] = data_length+5; send_frame[4] = CMD_REPLY; // send_frame[4] = CMD_REPLY; send_frame[5] = index; send_frame[6] = data_length; memcpy(&send_frame[7], &g_com_map[index], data_length); @@ -93,7 +93,7 @@ send_frame[1] = 0xAA; send_frame[2] = 0x03; send_frame[3] = data_length+5; send_frame[4] = CMD_REPLY; // send_frame[4] = CMD_REPLY; send_frame[5] = index; send_frame[6] = data_length; memcpy(&send_frame[7], &g_com_map[index], data_length); @@ -235,7 +235,7 @@ send_frame[0] = 0x55; send_frame[1] = 0xAA; send_frame[2] = 0x40; send_frame[3] = CMD_REPLY; //send_frame[3] = CMD_REPLY; send_frame[4] = data_length+6; send_frame[5] = index; memcpy(&send_frame[6], &g_com_map[index], data_length); @@ -275,7 +275,7 @@ uart_send(UART_ID0, send_frame,8, NULL); } uint16_t pack_checksum_test=0,test_calculate = 0; void Usart0ParseDataHandler(uint8_t data)//UART蓝牙数据分析处理 void Usart3ParseDataHandler(uint8_t data)//UART蓝牙数据分析处理 { // 全局变量 static Usart0ReceiveState usart0_receive_state = Usart0ReceiveWaitHead0; @@ -381,7 +381,7 @@ // 校验通过,处理数据 switch(pack_msg_type) { case CMD_REPLY: //case CMD_REPLY: case CMD_WRITE: //从mUsartReceivePack中读取pack_length长度的字节,放到全局变量中,赋值保存的参数并且存入flash @@ -495,5 +495,185 @@ // pack_length = 0; // } } extern uint16_t set_mk_time; void Send_Reply_To_Ble(void) { static uint8_t send_frame[100]; // uint16_t checksum = 0; send_frame[0] = 0x55; send_frame[1] = 0xAA; send_frame[2] = 0x41; send_frame[3] = CMD_MK_REPLY; uart_send(UART_ID0, send_frame,4, NULL); } void mk_send_message_to_BLE(void) { static uint8_t send_frame[100]; uint16_t checksum = 0; send_frame[0] = 0x55; send_frame[1] = 0xAA; send_frame[2] = 0x40; send_frame[3] = CMD_MK_TO_BLE; send_frame[4]=8;//数据长度 send_frame[5]=0; send_frame[6]=0; send_frame[7]=0; memcpy(&send_frame[8],&set_mk_time,2); checksum=Checksum_u16(&send_frame[2],8); memcpy(&send_frame[10],&checksum,2); uart_send(UART_ID0, send_frame,12, NULL); } extern uint8_t bat_percent; extern uint32_t dev_id; void Usart0ParseDataHandler(uint8_t data)//UART蓝牙数据分析处理 { // // 全局变量 //static Usart0ReceiveState usart0_receive_state = Usart0ReceiveWaitHead0; //static uint8_t index = 0; // 缓冲区索引 //static uint8_t pack_cmd_type = 0; // 指令类型 //static uint8_t pack_msg_type = 0; // 消息类型 //static uint8_t pack_data_len = 0; // 数据长度 //static uint8_t pack_param_addr = 0; // 参数地址 //static uint16_t pack_checksum = 0; // 接收到的校验和 //static uint16_t calculated_checksum = 0; // 计算得到的校验和 //static uint8_t send_frame[256]; // 用于计算校验和的帧 //static uint8_t frame_index = 0; // 帧缓冲区索引 //static uint8_t pack_datalen = 0; // // LOG_INFO(TRACE_MODULE_APP,"收到 %#x\r\n",data); // switch(usart0_receive_state) { // case Usart0ReceiveWaitHead0: // if(data == 0x55) { // usart0_receive_state = Usart0ReceiveWaitHead1; // // 初始化帧缓冲区 // frame_index = 0; // send_frame[frame_index++] = data; // } // break; // // case Usart0ReceiveWaitHead1: // if(data == 0xAA) { // usart0_receive_state = Usart0ReceiveWaitCmdType; // send_frame[frame_index++] = data; // } else { // usart0_receive_state = Usart0ReceiveWaitHead0; // } // break; // // case Usart0ReceiveWaitCmdType: // if(data == 64) { // pack_cmd_type = data; // usart0_receive_state = Usart0ReceiveWaitMsgType; // send_frame[frame_index++] = data; // } else { // usart0_receive_state = Usart0ReceiveWaitHead0; // } // break; // // case Usart0ReceiveWaitMsgType: // if(data == 0x2||data==0x1) { // 读写回复消息类型 // pack_msg_type = data; // usart0_receive_state = Usart0ReceiveWaitDataLen; // send_frame[frame_index++] = data; // } else { // usart0_receive_state = Usart0ReceiveWaitHead0; // } // break; // // case Usart0ReceiveWaitDataLen: // pack_data_len = data; // index = 0; // usart0_receive_state = Usart0ReceiveWaitData; // send_frame[frame_index++] = data; // break; // //// case Usart0ReceiveWaitParamAddr: //// pack_param_addr = data; //// if(pack_msg_type==CMD_READ) //// { //// usart0_receive_state = Usart0ReceiveWaitChecksum1; //// pack_datalen=pack_data_len-6; //// }else{ //// usart0_receive_state = Usart0ReceiveWaitData; //// } //// send_frame[frame_index++] = data; //// break; // // case Usart0ReceiveWaitData: // send_frame[frame_index++] = data; // mUsart2ReceivePack[index++] = data; // // if(index == pack_data_len-3) { // usart0_receive_state = Usart0ReceiveWaitChecksum1; // //pack_datalen=pack_data_len; // } // break; // // case Usart0ReceiveWaitChecksum1: // pack_checksum = data; // 高字节 // pack_checksum_test = data; // 高字节 // send_frame[frame_index++] = data; // usart0_receive_state = Usart0ReceiveWaitChecksum2; // LOG_INFO(TRACE_MODULE_APP,"收到校验1 %#x\r\n",data); // break; // case Usart0ReceiveWaitChecksum2: // pack_checksum |= data<<8; // 低字节 // pack_checksum_test |= data<<8; // 低字节 // LOG_INFO(TRACE_MODULE_APP,"收到校验2 %#x\r\n",data); // // 计算校验和 (从第3个字节开始,长度为4+数据长度) //// if(pack_msg_type!=CMD_REPLY) //// { // calculated_checksum = Checksum_u16(&send_frame[2],pack_data_len); //// }else{ //// //calculated_checksum = Checksum_u16(&send_frame[2],4); //// //// } // test_calculate=calculated_checksum; // LOG_INFO(TRACE_MODULE_APP,"收到校验 %#x,%#x\r\n",calculated_checksum,pack_checksum); // // 验证校验和 // if(pack_checksum == calculated_checksum) { // // 校验通过,处理数据 // switch(pack_msg_type) // { // case CMD_BLE_TO_MK: // memcpy(&dev_id,&mUsart2ReceivePack[0],2); // bat_percent=mUsart2ReceivePack[2]; // memcpy(&set_mk_time,&mUsart2ReceivePack[3],2); // memcpy(&g_com_map[DEV_ID],&dev_id,2); // memcpy(&g_com_map[SET_START_TIME],&set_mk_time,2); // Send_Reply_To_Ble(); // LOG_INFO(TRACE_MODULE_APP,"收到蓝牙数据 set_mk_time %d,dev_id %04x,bat_percent %d\r\n",set_mk_time,dev_id,bat_percent); // save_com_map_to_flash(); // //memcpy((uint8_t*)&g_com_map + pack_param_addr*2, mUsart2ReceivePack, pack_datalen); // // break; //// case CMD_MK_TO_BLE: //// //uart0_send_ComMap_to_BLE(pack_datalen,pack_param_addr); //// //// break; ////// case CMD_REPLY: ////// memcpy((uint8_t*)&g_com_map + pack_param_addr, mUsart2ReceivePack, pack_datalen); ////// save_com_map_to_flash(); ////// break; // default: // break; // } // } // // // 重置状态机 // usart0_receive_state = Usart0ReceiveWaitHead0; // index = 0; // frame_index = 0; // break; // // default: // usart0_receive_state = Usart0ReceiveWaitHead0; // index = 0; // frame_index = 0; // break; // } } keil/include/drivers/serial_at_cmd_app.h
@@ -5,9 +5,11 @@ #include "stdint.h" #define MAX_FRAME_LEN 50 #define CMD_READ 1 #define CMD_WRITE 2 #define CMD_REPLY 3 #define CMD_WRITE 1 #define CMD_READ 2 #define CMD_BLE_TO_MK 1 #define CMD_MK_TO_BLE 2 #define CMD_MK_REPLY 2 #define APP_CONFIG_IAPFLAG_MAP 0x0402D010 #define APP_CONFIG_IAPFLAG_SECTOR_ADDR 0x0402D000 typedef enum{ UsartReceiveWaitHead0,// 55 0d @@ -40,7 +42,7 @@ void UsartParseDataHandler(uint8_t data); void Usart0ParseDataHandler(uint8_t data); void Usart3ParseDataHandler(uint8_t data);//UART蓝牙数据分析处理 void UpdateProcess(uint8_t index); #endif keil/include/drivers/uwb_app.c
@@ -751,6 +751,7 @@ Anchor_RecNearPoll(rec_nearbase_num); } } //LOG_INFO(TRACE_MODULE_APP,"存在时间%d. \r\n", tagofflinetime[0]); } @@ -1064,7 +1065,7 @@ } //gpio_pin_clr(SCL_PIN);//测试 LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度ANT0:%f,信号强度ANT2: %f\r\n",g_com_map[BIND_DEV_ID],distance,sts_rssi[0],sts_rssi[2]); //LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度ANT0:%f,信号强度ANT2: %f\r\n",g_com_map[BIND_DEV_ID],distance,sts_rssi[0],sts_rssi[2]); return 1;//返回发送成功标志 } keil/include/main/main.c
@@ -118,6 +118,7 @@ uint8_t group_id,enable_sleep_count; uint32_t dev_id; uint16_t disoffset; uint16_t set_mk_time; uint8_t flag_sleeptimer,flag_secondtask,secondtask_count; float nomove_count; // Default pool descriptor. @@ -351,6 +352,8 @@ } uint8_t bat_percent; uint8_t stationary_flag; extern uint8_t send_flag; extern uint8_t txdone; void mcu_deep_sleep(void) { uint32_t lock; @@ -368,10 +371,7 @@ // Disable watchdog timer wdt_close(WDT_ID0); LOG_INFO(TRACE_MODULE_APP, "UCI FiRa example\r\n"); // delay_ms(300); // LOG_INFO(TRACE_MODULE_APP, "进入休眠模式\r\n");//测试 // power_init(); // mcu_deep_sleep(); if(gpio_pin_get_val(SLEEP_PIN)) { if(gpio_pin_get_val(MODE_CHANGE_PIN))//记得改回来与正式的相反 @@ -475,6 +475,7 @@ power_manage(); if(!gpio_pin_get_val(SLEEP_PIN)) { gpio_pin_clr(LORA_NRST);//lora休眠 LOG_INFO(TRACE_MODULE_APP, "进入休眠模式\r\n"); mcu_deep_sleep(); } @@ -493,6 +494,11 @@ sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试 while (1) { if(send_flag) { LOG_INFO(TRACE_MODULE_APP,"发送数量%d. \r\n",txdone); send_flag=0; } uwb_app_poll();//我们的测距逻辑 if(flag_secondtask) { @@ -503,6 +509,7 @@ Lora_Tx_Poll(); if(!gpio_pin_get_val(SLEEP_PIN)) { //gpio_pin_clr(LORA_NRST);//lora休眠 LOG_INFO(TRACE_MODULE_APP, "进入休眠模式\r\n"); mcu_deep_sleep(); } @@ -512,6 +519,9 @@ }else{ //delay_ms(300); LOG_INFO(TRACE_MODULE_APP, "进入休眠模式\r\n"); //gpio_pin_clr(LORA_NRST);//lora休眠 // spi_close(SPI_ID0); //lora_in_sleep(); power_init(); mcu_deep_sleep(); } keil/include/src/Radio/lora_1268.c
@@ -313,7 +313,7 @@ checksum = Checksum_u16(lora_sendbuffer,9+data_length); memcpy(&lora_sendbuffer[9+data_length],&checksum,2); Radio.Send(lora_sendbuffer,data_length+11); LOG_INFO(TRACE_MODULE_APP, "进入回复\r\n"); //LORA_3029_SINGLE_SEND(lora_sendbuffer,data_length+11,0); // Delay_Ms(100); } @@ -360,7 +360,19 @@ } void lora_in_sleep(void) { //SPI0/MOSI/MISO/CLK/CS // gpio_pin_set(LORA_CS); // gpio_pin_clr(LORA_MOSI); // gpio_pin_clr(LORA_MISO); // gpio_pin_clr(LORA_CLK); // gpio_pin_clr(LORA_IRQ); //gpio_pin_clr(LORA_NRST); //gpio_pin_clr(LORA_NRST);//lora休眠 Radio.Standby(); Radio.Sleep(); } ////States_t State = LOWPOWER; //////int8_t RssiValue = 0; @@ -377,9 +389,11 @@ //uint16_t current_count; //extern wg_state_enum wg_state; uint8_t txdone=0; uint8_t send_flag; void OnTxDone( void ) { txdone++; if(flag_writepara_needreset) //配置写入完成设备需要重启 { printf("网关下发配置写入完成,重启"); @@ -393,7 +407,9 @@ } else { Radio.Rx( 50 ); send_flag=1; //LORA_LED_OFF; } } @@ -427,6 +443,8 @@ uint8_t LoraUp_flag; uint16_t REV_WG_pack=0; uint8_t rxdone=0; extern uint16_t set_mk_time; extern mk_send_message_to_BLE(void); void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { uint16_t checksum1; @@ -516,7 +534,13 @@ default : memcpy(&rec_value,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],2); g_com_map[rec_index/2] = rec_value; save_com_map_to_flash(); // if(rec_index/2==POWER)//新增判断 // { // memcpy(&set_mk_time,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],2); // //mk_send_message_to_BLE(); //发送给蓝牙 // //LOG_INFO(TRACE_MODULE_APP, "修改成功g_com表为%#x,时间为%#x\r\n",g_com_map[POWER],set_mk_time); // } // save_com_map_to_flash(); LoraRspWriteCommap(SUBMSG_WRITE_ANCPARA); flag_writepara_needreset = 1; no_rx_flag = 1; @@ -546,7 +570,8 @@ } } } } LOG_INFO(TRACE_MODULE_APP, "进入回复2\r\n"); if(!no_rx_flag) { if(lora_jianting_flag&&LoraUp_flag==0) @@ -570,6 +595,7 @@ void OnRxTimeout( void ) { Radio.Standby(); if(lora_jianting_flag) { SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0); keil/include/src/Radio/lora_1268.h
@@ -199,4 +199,5 @@ void OnRxTimeout( void ); void OnRxError( void ); void SwitchLoraSettings(uint32_t freq,uint8_t sf,uint8_t power); void lora_in_sleep(void); #endif pin_config.c
@@ -42,6 +42,7 @@ #include "board.h" extern void (*Usart0ParseDataCallback)(uint8_t); extern void Usart0ParseDataHandler(uint8_t data); extern void Usart3ParseDataHandler(uint8_t data);//UART蓝牙数据分析处理 struct UART_CFG_T test_uart_cfg = { .parity = UART_PARITY_NONE, @@ -103,6 +104,9 @@ io_pin_mux_set(LORA_CLK, IO_FUNC2); io_pin_mux_set(LORA_IRQ, IO_FUNC0); io_pin_mux_set(LORA_NRST, IO_FUNC0); // io_pull_set(IO_PIN_11, IO_HIGH_Z, IO_PULL_UP_NONE); // io_pull_set(IO_PIN_12, IO_HIGH_Z, IO_PULL_UP_NONE); // io_pull_set(IO_PIN_13, IO_HIGH_Z, IO_PULL_UP_NONE); //初始化lora引脚 // UART0 TX/RX io_pin_mux_set(IO_PIN_5, IO_FUNC4); @@ -134,7 +138,7 @@ { // io_pin_mux_set(_4G_USART_RX_Pin,IO_FUNC0);//把原先io 变为普通GPIO gpio_pin_set_dir(LORA_IRQ , GPIO_DIR_IN, 0); io_pull_set(LORA_IRQ, IO_PULL_DOWN, IO_PULL_UP_NONE);//此处中间参数修改过现在这个能少190ua左右电流 io_pull_set(LORA_IRQ, IO_PULL_DOWN, IO_PULL_UP_LEVEL2);//此处中间参数修改过现在这个能少190ua左右电流 gpio_enable_irq(LORA_IRQ, GPIO_IRQ_TYPE_RISING_EDGE, irq_handler); } void uart0_Init_normal(void)