| | |
| | | #include "stdio.h" |
| | | #include "delay.h" |
| | | #include "dw_mbx_anc.h" |
| | | #include "Flash.h" |
| | | |
| | | #define USE_MODEM_LORA |
| | | //#define USE_MODEM_FSK |
| | | #define REGION_CN779 |
| | |
| | | { |
| | | rec_lp_count = HAL_LPTIM_ReadCounter(&hlptim1); |
| | | rxbuff_len = size; |
| | | |
| | | memcpy( rxbuffer, payload, size ); |
| | | RssiValue = rssi; |
| | | SnrValue = snr; |
| | |
| | | static uint16_t current_count1,target_count1,end_count1,start_count1; |
| | | uint8_t huifushengjibaoerror_num; |
| | | uint8_t final_bag_num; |
| | | uint16_t testflag; |
| | | uint32_t Zhongjian_data[60]; |
| | | void LoraUp_Poll() |
| | | { uint16_t result ; |
| | | uint16_t crc16; |
| | | memcpy(&rec_wenjian_daxiao,&rxbuffer[WRITEPARA_VALUE_IDX],2);//网关ID 占用2个字节 |
| | | memcpy(&rec_wenjian_daxiao,&rxbuffer[WRITEPATE_VALUE_IDX],2);//文件大小 |
| | | // rec_wenjian_daxiao=rxbuffer[WRITEPATE_VALUE_IDX]; |
| | | if(rec_wenjian_daxiao>0XAC00) |
| | | {}//文件过大,超出范围 |
| | | else |
| | | { |
| | | __disable_irq(); |
| | | while(1) |
| | | { |
| | | FLASH_Prepare(APP2_ADRESS, APP_SIZE); |
| | | delay_ms(500); |
| | | if(testflag==0) |
| | | {break;} |
| | | } |
| | | // FLASH_Write(APP2_ADRESS, (const uint8_t*)&tmp111, 2); |
| | | __enable_irq(); |
| | | final_bag_num=(rec_wenjian_daxiao/220)+1;//计算一共要请求多少包 |
| | | wangguan_up_id=rxbuffer[SOURCE_ID_IDX]; |
| | | memcpy(&wangguan_up_id,&rxbuffer[WG_ID_IDX],2);//网关ID 占用2个字节 |
| | | send_lora_data[MSG_TYPE_IDX]=LORA_MSGTYPE_UPDATE_CONFIRM; |
| | | memcpy(&send_lora_data[WANGGUAN_ID],&wangguan_up_id,2);//网关ID 占用2个字节 |
| | | memcpy(&send_lora_data[JIZHAN_ID],&dev_id,2);//标签或者基站的设备ID 2个字节 |
| | |
| | | huifushengjibao_flag=0; |
| | | LoraUp_flag=1; |
| | | Radio.Send(send_lora_data,8);//基站发送升级确认回复 |
| | | Delay_Ms(2000); |
| | | while(1) |
| | | { |
| | | if(huifushengjibao_flag==1) |
| | |
| | | current_count1=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while(!lora_up_rec_flag) |
| | | { |
| | | current_count1=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_count1>=end_count1&¤t_count1<end_count1+15000) |
| | | { |
| | | break; |
| | | } |
| | | // current_count1=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // if(current_count1>=end_count1&¤t_count1<end_count1+15000) |
| | | // { |
| | | // break; |
| | | // } |
| | | delay_ms(100); |
| | | Radio.Send(send_lora_data,8); |
| | | } |
| | | // while(1); |
| | | if(lora_up_rec_flag) |
| | | { |
| | | |
| | | crc16=Cal_CRC16(rxbuffer,6+ONE_BAG_DAXIAO); |
| | | if(!memcmp(&crc16,&rxbuffer[6+ONE_BAG_DAXIAO],2)&&!memcmp(&dev_id,&RX_Buffer[JIZHAN_ID],2)&& !memcmp(&wangguan_up_id,&RX_Buffer[WANGGUAN_ID],2)) |
| | | if(muqiandeshengjibao==rxbuffer[MUQIAN_BAG]&&!memcmp(&crc16,&rxbuffer[6+ONE_BAG_DAXIAO],2)&&!memcmp(&dev_id,&rxbuffer[JIZHAN_ID],2)&& !memcmp(&wangguan_up_id,&rxbuffer[WANGGUAN_ID],2)) |
| | | { |
| | | result = FLASH_Prepare(APP2_ADRESS+ONE_BAG_DAXIAO*rxbuffer[MUQIAN_BAG], ONE_BAG_DAXIAO); |
| | | if(result) |
| | | result = FLASH_Write(APP2_ADRESS+ONE_BAG_DAXIAO*rxbuffer[MUQIAN_BAG],rxbuffer[DATA_IDX],ONE_BAG_DAXIAO); |
| | | memcpy(Zhongjian_data,&rxbuffer[DATA_IDX],ONE_BAG_DAXIAO); |
| | | // __disable_irq(); |
| | | FLASH_Write(APP2_ADRESS+ONE_BAG_DAXIAO*rxbuffer[MUQIAN_BAG],(uint8_t*)Zhongjian_data,ONE_BAG_DAXIAO); |
| | | // __enable_irq(); |
| | | muqiandeshengjibao++; |
| | | } |
| | | } |
| | |
| | | if(huifushengjibaoerror_num>=20) |
| | | { |
| | | huifushengjibaoerror_num=0; |
| | | muqiandeshengjibao=0; |
| | | break; |
| | | } |
| | | } |
| | |
| | | else |
| | | { |
| | | Delay_Ms(500); |
| | | huifushengjibao_flag=0; |
| | | // huifushengjibao_flag=0; |
| | | Radio.Send(send_lora_data,8);//基站发送升级确认回复 |
| | | huifushengjibaoerror_num++; |
| | | if(huifushengjibaoerror_num>=5) |
| | |
| | | // } |
| | | } |
| | | } |
| | | |
| | | uint8_t fsad; |
| | | //void test1() |
| | | //{ |
| | | // if(!memcmp(&dev_id,&rxbuffer[ANCTAG_DEVICEID_IDX],2)) |
| | | // {LoraUp_Poll();} |
| | | //} |
| | | //} |