| | |
| | | #include "stdio.h" |
| | | #include "delay.h" |
| | | #include "lora.h" |
| | | #include "dps310.h" |
| | | #include "dw_mbx_anc.h" |
| | | #define NSH1 0x0001 |
| | | #define GP 0x0002 |
| | | #define FLASH_HARDWARE_VERSION_MAP (uint32_t)0x08004F00 //硬件版本号和批次信息位置 |
| | | #define DEBUG_MODE |
| | | //#define DEBUG_MODE |
| | | |
| | | /* USER CODE END Includes */ |
| | | |
| | | /* Private typedef -----------------------------------------------------------*/ |
| | |
| | | |
| | | /* Private user code ---------------------------------------------------------*/ |
| | | /* USER CODE BEGIN 0 */ |
| | | uint16_t Anchor_Vcc_time; |
| | | #define DIANLIANG_TIME 3600 |
| | | uint8_t Anchor_Vcc_Flag; |
| | | uint16_t Anchor_Vcc_time=DIANLIANG_TIME-2; |
| | | uint32_t dev_id; |
| | | uint16_t heartbeat_timer,poll_timer,sync_timer; |
| | | uint8_t aRxBuffer[1],group_id; |
| | |
| | | hardware_pici = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+2); |
| | | hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4); |
| | | //deca_sleep(1000); |
| | | g_com_map[VERSION] = (3<<8)|0; |
| | | g_com_map[VERSION] = (1<<8)|0; |
| | | // testprogram(); |
| | | // g_com_map[DEV_ID]=0x6777; |
| | | #ifdef DEBUG_MODE |
| | |
| | | // g_com_map[NOMOVESLEEP_TIME]=10; |
| | | #endif |
| | | g_com_map[ACTIVE_INDEX] = 1; |
| | | g_com_map[GROUP_ID]=5; |
| | | g_com_map[GROUP_ID]=88; |
| | | g_com_map[UWBPOLLTIME_MS_IDX] = 520; |
| | | g_com_map[COM_INTERVAL] = 1000; |
| | | if(g_com_map[COM_INTERVAL]<1000) |
| | | {g_com_map[COM_INTERVAL] = 1000;} |
| | | active_flag = g_com_map[ACTIVE_INDEX]; |
| | | g_com_map[POWER]=0; |
| | | // g_com_map[POWER]=0; |
| | | module_power = g_com_map[POWER]; |
| | | g_com_map[IMU_ENABLE] = 0; |
| | | imu_enable=g_com_map[IMU_ENABLE]; |
| | |
| | | Error_Handler(); |
| | | } |
| | | //g_com_map[NOMOVESLEEP_TIME]=5; |
| | | printf("固件版本: LORA免布线基站 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); |
| | | printf("固件版本: LORA免布线基站-工装测试 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); |
| | | memcpy(g_com_map2,g_com_map,COM_MAP_SIZE); |
| | | // printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]); |
| | | // printf("DEVICE ALARM DISTANCE: 1.%d 2.%d 3.%d .\r\n",g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],g_com_map[ALARM_DISTANCE3]); |
| | |
| | | uint32_t temp; |
| | | extern uint8_t sleep_flag,m_bEUARTTxEn; |
| | | uint16_t waitusart_timer; |
| | | //void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle) |
| | | //{ |
| | | // /* Set transmission flag: trasfer complete*/ |
| | | // waitusart_timer = tag_frequency*USART_KEEPWAKE_TIME; |
| | | // |
| | | |
| | | //} |
| | | void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) |
| | | { |
| | | //SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | |
| | | HAL_ADCEx_DisableVREFINT(); |
| | | } |
| | | extern uint8_t TX_Buffer; |
| | | void Uwb_Lora_Switch(uint8_t uwb, uint8_t lora) |
| | | { |
| | | if(uwb) |
| | | HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET); |
| | | else |
| | | HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET); |
| | | |
| | | if(lora) |
| | | HAL_GPIO_WritePin(GPIOB, RADIO_NSS_Pin, GPIO_PIN_SET); |
| | | else |
| | | HAL_GPIO_WritePin(GPIOB, RADIO_NSS_Pin, GPIO_PIN_RESET); |
| | | } |
| | | uint8_t tx_num; |
| | | void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) |
| | | { |
| | |
| | | RadioIrqProcess(); |
| | | } |
| | | } |
| | | extern uint16_t AD_value[500]; |
| | | u16 poll_startcount; |
| | | u16 Anchor_Vcc_time1; |
| | | uint8_t TX_Anchor_Vcc[100]={0x55,0xAA,0x14,20,0,0/*标签id*/,0,0/*基站ID*/,0/*保留*/,}; |
| | | extern float bat_volt; |
| | | void Send_Anchor_Vcc_Poll() |
| | | { |
| | | uint8_t vcc_send; |
| | | if(Anchor_Vcc_time>=3600) |
| | | { |
| | | Lora470_Init(); |
| | | SX126xSetRfTxPower( 22 );//切换大发射功率 |
| | | g_start_send_flag=0; |
| | | Anchor_Vcc_time=0; |
| | | memcpy(&TX_Anchor_Vcc[6],&g_com_map[DEV_ID],2); |
| | | memcpy(&TX_Anchor_Vcc[9],&g_com_map[VERSION],2); |
| | | vcc_send=(bat_volt-2.8)*100; |
| | | memcpy(&TX_Anchor_Vcc[11],&vcc_send,1); |
| | | memcpy(&TX_Anchor_Vcc[12],&g_com_map[POWER],1); |
| | | memcpy(&TX_Anchor_Vcc[13],&g_com_map[GROUP_ID],2); |
| | | memcpy(&TX_Anchor_Vcc[15],&g_com_map[DIST_OFFSET],2); |
| | | // memcpy(&TX_Anchor_Vcc[18],&g_com_map[DIST_OFFSET],2); |
| | | Radio.Send( TX_Anchor_Vcc, 2+20); |
| | | SX126xSetRfTxPower( 22 );//切换回小发射功率; |
| | | |
| | | Lora_Init(); |
| | | |
| | | } |
| | | } |
| | | u8 flag_entersleep = 1; |
| | | uint32_t status_reg111 = 0; |
| | | void Get_Dianliang_Poll() |
| | | { |
| | | if(Anchor_Vcc_Flag) |
| | | { |
| | | Anchor_Vcc_Flag=0; |
| | | bat_percent=Get_VDDVlotage(); |
| | | UWB_Wkup(); |
| | | Delay_Ms(50); |
| | | dwt_setrxtimeout(0);////设定接收超时时间,0位没有超时时间 |
| | | dwt_rxenable(0);//打开接收 |
| | | while(1) |
| | | { |
| | | while (!((status_reg111 = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误 |
| | | { |
| | | bat_percent=Get_VDDVlotage();} |
| | | if (status_reg111 & SYS_STATUS_RXFCG)//如果成功接收 |
| | | { |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG | SYS_STATUS_TXFRS);//清楚寄存器标志位 |
| | | dwt_setrxtimeout(0);////设定接收超时时间,0位没有超时时间 |
| | | dwt_rxenable(0);//打开接收 |
| | | } |
| | | else |
| | | { |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | dwt_rxenable(0); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | Delay_Ms(50); |
| | | dwt_forcetrxoff(); |
| | | dwt_entersleep(); |
| | | } |
| | | } |
| | | extern dwt_config_t config ; |
| | | uint8_t shuzu[3]={0xff,0xff,0xff}; |
| | | uint8_t datashuju[50]; |
| | | uint8_t datachangdu; |
| | | /*mode:区域 UART_PushFrame(send_frame, data_length+9); */ |
| | | void uartsend(uint8_t quyu,uint16_t data) |
| | | { |
| | | if(quyu==4) |
| | | { |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t4.txt=\"%d\"",data); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | } |
| | | if(quyu==5) |
| | | { |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t5.txt=\"YES\""); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | } |
| | | if(quyu==6) |
| | | { |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t6.txt=\"%d\"",data); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | } |
| | | if(quyu==7) |
| | | { |
| | | // memset(datashuju,0,sizeof(datashuju)); |
| | | // USART_puts(shuzu, 3);//开始结束都要发 |
| | | // datachangdu=sprintf(datashuju,"t7.txt=\"%f\"",data); |
| | | // USART_puts(datashuju, datachangdu); |
| | | // USART_puts(shuzu, 3); |
| | | } |
| | | if(quyu==8) |
| | | { |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t8.txt=\"%d\"",data); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | } |
| | | } |
| | | void Lcd_Rest() |
| | | { |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t0.bco=63488"); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t1.bco=63488"); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t2.bco=63488"); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t3.bco=63488"); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t4.txt=\"0\""); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t5.txt=\"0\""); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t6.txt=\"0\""); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t7.txt=\"0\""); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | // memset(datashuju,0,sizeof(datashuju)); |
| | | // USART_puts(shuzu, 3);//开始结束都要发 |
| | | // datachangdu=sprintf(datashuju,"t8.txt=\"power\""); |
| | | // USART_puts(datashuju, datachangdu); |
| | | // USART_puts(shuzu, 3); |
| | | } |
| | | uint8_t ceshimode; |
| | | /* USER CODE END 0 */ |
| | | |
| | | /** |
| | |
| | | MX_LPTIM1_Init(); |
| | | MX_SPI1_Init(); |
| | | MX_USART1_UART_Init(); |
| | | // MX_IWDG_Init(); |
| | | MX_IWDG_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | LED_LG_ON; |
| | | Program_Init(); |
| | | if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE)) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | Lcd_Rest(); |
| | | // LIS3DH_Data_Init(); |
| | | // Uwb_Lora_Switch(1,0); |
| | | // if(g_com_map[NEARBASE_ID10]==0) |
| | | // { |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t8.txt=\"功率\""); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | 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 |
| | | dwt_configure(&config);//配置DW1000 |
| | | dwt_setrxantennadelay(32899); //设置接收天线延迟 |
| | | dwt_settxantennadelay(0); //设置发射天线延迟 |
| | | Dw1000_App_Init(); |
| | | Delay_Ms(10); |
| | | dwt_configcontinuousframemode(124800); |
| | | dwt_writetxfctrl(13, 0); |
| | | // dwt_starttx(DWT_START_TX_IMMEDIATE); |
| | | while(1) |
| | | { |
| | | IdleTask(); |
| | | // ceshimode=1; |
| | | if(ceshimode) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | // } |
| | | // else |
| | | // { |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t8.txt=\"测试\""); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | |
| | | Dw1000_Init(); |
| | | Dw1000_App_Init(); |
| | | Delay_Ms(10); |
| | |
| | | dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN); |
| | | dwt_entersleep(); |
| | | DW_DISABLE; |
| | | if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE)) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | HAL_Delay(1500); |
| | | Lora_Init(); |
| | | MbxInit(); |
| | | // SwitchLoraSettingstest(UWB_CHANNEL_FRQ,UWB_CHANNEL_SF); |
| | | Delay_Ms(10); |
| | | |
| | | #ifdef _USE_BAR_ |
| | | BarInit(); |
| | | #endif |
| | | // HAL_ADC_Start_DMA(&hadc,(uint32_t*)&AD_value,sizeof(AD_value)); |
| | | /* USER CODE END 2 */ |
| | | //HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); |
| | | //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET); |
| | | // Delay_Ms(10); |
| | | // Delay_Ms(10); |
| | | //HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); |
| | | //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET); |
| | | // Delay_Ms(10); |
| | | // Delay_Ms(10); |
| | | |
| | | /* Infinite loop */ |
| | | /* USER CODE BEGIN WHILE */ |
| | | while (1) |
| | |
| | | |
| | | /* USER CODE BEGIN 3 */ |
| | | // Send_Anchor_Vcc_Poll(); |
| | | if(g_start_send_flag&&g_com_map[ACTIVE_INDEX]) |
| | | { |
| | | if(g_start_send_flag/*&&g_com_map[ACTIVE_INDEX]*/) |
| | | { |
| | | SystemClock_Config(); |
| | | g_start_send_flag = 0; |
| | | // HAL_IWDG_Refresh(&hiwdg); |
| | | HAL_IWDG_Refresh(&hiwdg); |
| | | if(bat_percent>15) |
| | | { |
| | | LED_TB_ON; |
| | |
| | | } |
| | | // if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | // HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
| | | #ifndef DEBUG_MODE |
| | | // #ifndef DEBUG_MODE |
| | | if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)&&flag_entersleep) |
| | | HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
| | | #endif |
| | | // #endif |
| | | } |
| | | // HAL_Delay(100); |
| | | // Get_Battary(); |
| | | |
| | | // LIS3DH_Data_Init(); |
| | | } |
| | | // } |
| | | /* USER CODE END 3 */ |
| | | } |
| | | |
| | |
| | | extern uint8_t tx_near_msg[80],stationary_flag; |
| | | float key_keeptime; |
| | | extern float freqlost_count,range_lost_time; |
| | | extern uint16_t verfint_cal; |
| | | extern float bat_volt; |
| | | extern u16 rec_nearbaseid,temp_index,adc_val1,adc_val_min; |
| | | void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) |
| | | { |
| | | static uint8_t i=0; |
| | | i++; |
| | | |
| | | Anchor_Vcc_time++; |
| | | if(Anchor_Vcc_time>2) |
| | | { |
| | | // Anchor_Vcc_Flag=1; |
| | | // Anchor_Vcc_time=0; |
| | | Anchor_Vcc_time=0; |
| | | READC_Init(); |
| | | verfint_cal = *(__IO uint16_t *)(0X1FF80078); |
| | | adc_val1 = Get_ADC_Value(); |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); |
| | | Anchor_Vcc_Flag=0; |
| | | MX_ADC_DeInit(); |
| | | bat_volt = 3*(float)verfint_cal/adc_val1-0.28; |
| | | |
| | | } |
| | | current_slotnum++; |
| | | freqlost_count+=1/(float)tag_frequency; |
| | | range_lost_time +=1/(float)tag_frequency; |