| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925 |
- #include "main_task.h"
- #include "soft_led.h"
- #include "stdio.h"
- #include "stdbool.h"
- #include "string.h"
- #include "main.h"
- #include "soft_usart.h"
- #include "usart_data_handle.h"
- #include "soft_flash.h"
- #include "soft_crc.h"
- #include "soft_radar_handle.h"
- #include "soft_engine.h"
- #include "soft_device.h"
- #include "soft_timer.h"
- #include "config.h"
- #include "soft_can.h"
- #include "soft_bms.h"
- #include "soft_adc.h"
- #include "soft_version.h"
- #include "soft_update.h"
- #include "soft_obstacle.h"
- #include "soft_water.h"
- //#include "can_debug.h"
- uint8_t msg_buf[256] = {0};
- bool terrain_is_link = false;
- bool obs_f_is_link = false;
- bool obs_b_is_link = false;
- /**
- * @file Update_ack_func
- * @brief PMU回复ACK 回复升级工具
- * @param 组件ID,消息ID,ACK数据
- * @details 升级应答FMU透传,协议和升级工具一致,和FMU不一样
- * @author Zhang Sir
- **/
- void Update_ack_func(uint8_t group_id, uint8_t msg_id, uint8_t *ackbuf)
- {
-
- int index = 0;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = group_id;
- msg_buf[index++] = _MSGID_ACK;
- msg_buf[index++] = msg_id;
- msg_buf[index++] = *ackbuf;
- msg_buf[index++] = *(ackbuf + 1);
- msg_buf[index++] = 1;
- msg_buf[1] = index - 6;
- uint16_t uart_crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &uart_crc, 2);
- index += 2;
- usart1_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_set_ack
- * @brief PMU应答FMU
- * @param 命令 命令内容 123
- * @details
- * @author Zhang Sir
- **/
- char ack_id = 0;
- short ack_content = 0;
- short ack_content1 = 0;
- short ack_content2 = 0;
- void pmu_set_ack(uint8_t id,short content1, short content2,short content3)
- {
- pmu_send = PMU_SEND_ACK;
- ack_id = id;
- ack_content = content1;
- ack_content1 = content2;
- ack_content2 = content3;
- }
- /**
- * @file pmu_to_con_voltage_data
- * @brief PMU发送电压、温度信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_con_voltage_data()
- {
- int index = 0;
- uint16_t temp_16t = 0;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0; //组件计数
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSGID_VOL;
- temp_16t = Adc_Get(ADC_Bms) / 10.0f + cur_par.voltage * 10; // 获取当前板子电压
- memcpy(&msg_buf[index], &temp_16t, 2);
- index += 2;
- temp_16t = Adc_Get(ADC_Tempture);
- memcpy(&msg_buf[index], &temp_16t, 2);
- index += 2;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- temp_16t = (uint16_t)stor_par.abnormal_outage_flag;
- memcpy(&msg_buf[index], &temp_16t, 2);
- index += 2;
- msg_buf[1] = index - 6;
- uint16_t crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- usart1_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_con_heart_data
- * @brief PMU_发送心跳
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_con_heart_data()
- {
- int index = 0;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 21;
- msg_buf[index++] = _MSGID_HEART;
- ack_content = 0x56;
- memcpy(&msg_buf[index],&ack_content,2);
- index += 2;
- memcpy(&msg_buf[index],&ack_content1,2);
- index += 2;
- memcpy(&msg_buf[index],&ack_content2,2);
- index += 2;
-
- msg_buf[1] = index - 6;
- uint16_t crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- usart1_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_con_engin_data
- * @brief PMU发送发动机信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_con_engine_data(void)
- {
- uint8_t index = 0;
- if(engine_link_status == COMP_NORMAL)
- {
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0; //组件计数
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSG_ENGIN;
-
- memcpy(&msg_buf[index],&engine_data.engine_type,sizeof(engine_data));
- index += (sizeof(engine_data));
- msg_buf[1] = index - 6;
- uint16_t crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- usart1_send_msg(msg_buf, index);
- }
- }
- /**
- * @file pmu_to_con_devtype_data
- * @brief PMU发送播撒、称重、水泵、离心喷头、在位传感器信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void check_and_put_msg(uint8_t *buf, uint16_t len)
- {
- buf[1] = len - 6;
- uint16_t crc = Get_Crc16(buf, len);
- msg_buf[len++] = crc;
- msg_buf[len++] = (crc >> 8) & 0xff;
- usart1_send_msg(msg_buf, len);
- }
- void pmu_to_con_devtype_data(void)
- {
- uint16_t index = 0;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0; //组件计数
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSGID_DEV_INFO;
- if(send_devinfo_time.flow == true)
- {
- msg_buf[index++] = DEV_FLOW;
- memcpy(&msg_buf[index],&Dev.Flow.facid,sizeof(Flow_info));
- index += sizeof(Flow_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.flow = false;
- }
- if (send_devinfo_time.radar == true)
- {
- msg_buf[index++] = DEV_RADAR;
- memcpy(&msg_buf[index],&Dev.Radar.facid_T,sizeof(Radar_info));
- index += sizeof(Radar_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.radar = false;
- }
- if(send_devinfo_time.checklow == true)
- {
- msg_buf[index++] = DEV_CHECKLOW;
- memcpy(&msg_buf[index],&Dev.Checklow.facid,sizeof(CheckLow_info));
- index += sizeof(CheckLow_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.checklow = false;
- }
- if(Dev.L_pump1_Link.connect_status == COMP_NORMAL && send_devinfo_time.L_pump1 == true)
- {
- msg_buf[index++] = DEV_L_PUMP1;
- memcpy(&msg_buf[index],&Dev.L_pump1.facid,sizeof(Linear_pump_info));
- index += sizeof(Linear_pump_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.L_pump1 = false;
- }
- if(Dev.L_pump2_Link.connect_status == COMP_NORMAL && send_devinfo_time.L_pump2 == true)
- {
- msg_buf[index++] = DEV_L_PUMP2;
- memcpy(&msg_buf[index],&Dev.L_pump2.facid,sizeof(Linear_pump_info));
- index += sizeof(Linear_pump_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.L_pump2 = false;
- }
- if(Dev.Weight_Link.connect_status == COMP_NORMAL && send_devinfo_time.weight == true)
- {
- msg_buf[index++] = DEV_WEIGHT;
- memcpy(&msg_buf[index],&Dev.Weight.facid,sizeof(Weight_info));
- index += sizeof(Weight_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.weight = false;
- }
- if(Dev.Part_Tradar_Link.connect_status == COMP_NORMAL && send_devinfo_time.part_radar == true)
- {
- msg_buf[index++] = DEV_PART_RADAR;
- memcpy(&msg_buf[index],&Dev.Part_radarT.facid,sizeof(Part_Tradar));
- index += sizeof(Part_Tradar);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.part_radar = false;
- }
- if(Dev.Part_Fradar_Link.connect_status == COMP_NORMAL && send_devinfo_time.part_Fradar == true)
- {
- msg_buf[index++] = DEV_PART_FRADAR;
- memcpy(&msg_buf[index],&Dev.Part_radarF.facid,sizeof(Part_FBradar));
- index += sizeof(Part_FBradar);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.part_Fradar = false;
- }
- if(Dev.Part_Bradar_Link.connect_status == COMP_NORMAL && send_devinfo_time.part_Bradar == true)
- {
- msg_buf[index++] = DEV_PART_BRADAR;
- memcpy(&msg_buf[index],&Dev.Part_radarB.facid,sizeof(Part_FBradar));
- index += sizeof(Part_FBradar);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.part_Bradar = false;
- }
- if(Dev.Bms_Link.connect_status == COMP_NORMAL && send_devinfo_time.bms == true)
- {
- msg_buf[index++] = DEV_BMS;
- memcpy(&msg_buf[index],&Dev.Bms.facid,Dev.Bms.index + 1);
- index += Dev.Bms.index + 1;
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.bms = false;
- }
- if(Dev.Seed_Link.connect_status == COMP_NORMAL && send_devinfo_time.seed == true)
- {
- msg_buf[index++] = DEV_SEED;
- memcpy(&msg_buf[index],&Dev.Seed.facid,sizeof(Seed_info));
- index += sizeof(Seed_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.seed = false;
- }
- if (Dev.Pump_Link.connect_status == COMP_NORMAL && send_devinfo_time.pump == true)
- {
- msg_buf[index++] = DEV_PUMP;
- memcpy(&msg_buf[index],&Dev.Pump.facid,sizeof(Pump_info));
- index += sizeof(Pump_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.pump = false;
- }
- if (Dev.Nozzle_Link.connect_status == COMP_NORMAL && send_devinfo_time.nozzle == true)
- {
- msg_buf[index++] = DEV_NOZZLE;
- memcpy(&msg_buf[index],&Dev.Nozzle.facid,sizeof(Nozzle_info));
- index += sizeof(Nozzle_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.nozzle = false;
- }
- if (Dev.Arm_Link.connect_status == COMP_NORMAL && send_devinfo_time.arm == true)
- {
- msg_buf[index++] = DEV_ARM;
- memcpy(&msg_buf[index],&Dev.Arm.facid,sizeof(Arm_info));
- index += sizeof(Arm_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.arm = false;
- }
- if(Dev.Temperature_Sensor_Link.connect_status == COMP_NORMAL && send_devinfo_time.temperature == true)
- {
- msg_buf[index++] = DEV_TEMP_SENSOR;
- memcpy(&msg_buf[index],&Dev.Temperature_Sensor.facid,sizeof(Temperature_Sensor_info));
- index += sizeof(Temperature_Sensor_info);
- check_and_put_msg(msg_buf, index);
- index = 6;
- send_devinfo_time.temperature = false;
- }
- // else if(Dev.L_pump2_Link.connect_status == COMP_NORMAL && send_devinfo_time.L_pump2 == true)
- // {
- // msg_buf[index++] = DEV_L_PUMP2;
- // memcpy(&msg_buf[index],&Dev.L_pump2.facid,sizeof(Linear_pump_info));
- // index += sizeof(Linear_pump_info);
- // send_devinfo_time.L_pump2 = false;
- // }
- // msg_buf[1] = index - 6;
- // uint16_t crc = Get_Crc16(msg_buf, index);
- // msg_buf[index++] = crc;
- // msg_buf[index++] = (crc >> 8) & 0xff;
- // usart1_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_con_version_data
- * @brief PMU发送版本信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_con_version_data()
- {
- //版本信息 0 - 5 硬件版本 IAP版本 APP版本
- uint32_t ver_msg_buf[4] = {0};
-
- int index = 0;
- ver_msg_buf[0] = cur_par.pmu_serial; //硬件版本号
- ver_msg_buf[1] = IAP_VERSION; //IAP版本号
- ver_msg_buf[2] = APP_VERSION; //APP版本号
- ver_msg_buf[3] = cur_par.pmu_serial;//serial.num;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = MSGID_REQ_VERSION;
- radar_version_check();
- memcpy(&msg_buf[index], ver_msg_buf, 16);
- index += 16;
- memcpy(&msg_buf[index], &radar_version[0][0], 10);
- index += 10;
- memcpy(&msg_buf[index], &radar_version[1][0], 10);
- index += 10;
- memcpy(&msg_buf[index], &radar_version[2][0], 10);
- index += 10;
- msg_buf[1] = index - 6;
- uint16_t crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- usart1_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_fcu_version_data
- * @brief 版本信息发送,新协议还没用
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_fcu_version_data()
- {
-
- //short dev_num = 40;
- uint8_t i = 0;
- dev_version_content *ptr = NULL;
- for(i = 0;i < dev_num;i++)
- {
- ptr = dev_ptr[i];
- if(ptr->send_times > 0)
- {
- break;
- }
- if(i == dev_num - 1)
- {
- return;
- }
- }
- uint8_t index = 0;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSGID_DEV_LIST;
- memcpy(&msg_buf[index],&ptr->num,sizeof(dev_version_content) - sizeof(regist_type) - 1);
- index += sizeof(dev_version_content) - sizeof(regist_type) - 1;
- msg_buf[1] = index - 6;
- uint16_t crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- usart1_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_fcu_key_data
- * @brief PMU发送秘钥信息
- * @param none
- * @details 格式电池秘钥匹配
- * @author Zhang Sir
- **/
- void pmu_to_fcu_key_data(void)
- {
- uint8_t index = 0;
-
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSGID_SHA1;
- msg_buf[index++] = start_msg.Dev_type;
- msg_buf[index++] = start_msg.Id;
- msg_buf[index++] = start_msg.Id_content;
- // if(start_msg.Id == 4)
- // {
- // start_msg.key_info_checking = false; //发送状态后结束发送
- // }
- memcpy(&msg_buf[index],&start_msg.key_data[0],20);
- index += 20;
- msg_buf[1] = index - 6;
- uint16_t crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- usart1_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_con_request_data
- * @brief PMU发送请求信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- char request_id = 0;
- short request_1_content = 0;
- int request_2_content = 0;
- void pmu_to_con_request_data()
- {
- int index = 0;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 20;
- msg_buf[index++] = request_id;
- memcpy(&msg_buf[index],&request_1_content,2);
- index += 2;
- memcpy(&msg_buf[index],&request_2_content,4);
- index += 4;
- msg_buf[1] = index - 6;
- uint16_t crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- usart1_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_con_radar360_data
- * @brief PMU发送360信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_con_radar360_data(void)
- {
- uint8_t index = 0;
- uint32_t send_byte = 0;
- uint16_t crc = 0;
- if(mimo_360_info.connect_status == COMP_NORMAL)
- {
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSGID_360RADAR;
-
- radar360_proflag = 1;
- send_byte = sizeof(mimo_360_data) * fmu_360info.total_tar + 2;
-
- memcpy(&msg_buf[index],&fmu_360info,send_byte);
- index += send_byte;
- radar360_proflag = 0;
- msg_buf[1] = index - 6;
- crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- usart1_send_msg(msg_buf, index);
- }
- }
- /**
- * @file pmu_to_con_request_data
- * @brief PMU发送应答信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_con_ack_data()
- {
- int index = 0;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 21;
- msg_buf[index++] = ack_id;
- memcpy(&msg_buf[index],&ack_content,2);
- index += 2;
- memcpy(&msg_buf[index],&ack_content1,2);
- index += 2;
- memcpy(&msg_buf[index],&ack_content2,2);
- index += 2;
-
- msg_buf[1] = index - 6;
- uint16_t crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- usart1_send_msg(msg_buf, index);
- }
- //4D雷达回复fmu
- void pmu_to_con_DM4DBradar_msg(void)
- {
- uint8_t index = 0;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSGID_GET4D;
- msg_buf[index++] = 'V';
- msg_buf[index++] = 'K';
- msg_buf[index++] = 'Z';
- msg_buf[index++] = '1';
- memcpy(&msg_buf[index],&DM_4DRADARMAG.angel_4DF,18);
- index += 18;
- msg_buf[1] = index - 6;
- uint16_t crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- usart1_send_msg(msg_buf, index);
- }
- /**
- * @file Can_send_debug_to_app
- * @brief can模拟
- * @param none
- * @details UART2
- * @author Zhang Sir
- **/
- /*
- void Can_send_debug_to_app(void)
- {
- int index = 0;
- uint16_t crc = 0;
- uint8_t send_time = debug_can.Total_Dev_num / 16 + 1;
- uint8_t element_num = 0,total_pack_num = 0;
- check_can_dev_connect();
- for(uint8_t i = 0;i < send_time; i++)
- {
- index = 0;
- crc = 0;
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0; //组件计数
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSGID_CANDEBUG;
- debug_can.Len = get_data_total_len;
- if(send_time > 1)
- {
- element_num = i * 15;
- total_pack_num = (send_time - 1 - i) == 0? debug_can.Total_Dev_num - (i *15) : 15;
- }
- else
- {
- element_num = 0;
- total_pack_num = debug_can.Total_Dev_num;
- }
- msg_buf[index++] = total_pack_num;
-
- for(uint8_t i=0;i<total_pack_num;i++)
- {
- memcpy(&msg_buf[index], &debug_can.ID_buf[i + element_num].ID, debug_can.Len(debug_can.ID_buf[i + element_num].len));
- index += debug_can.Len(debug_can.ID_buf[i + element_num].len);
- }
- msg_buf[1] = index - 6;
- crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- usart1_send_msg(msg_buf, index);
- //uart3_send_msg(msg_buf, index);
- if(send_time > 1)
- {
- HAL_Delay(50);
- }
- }
- }
-
- */
- uint32_t DM4d_to_fmu10s_flag = 0;
- /**
- * @file pmu_to_fcu
- * @brief PMU发送信息给FMU
- * @param none
- * @details UART2
- * @author Zhang Sir
- **/
- uint8_t pmu_send = PMU_SEND_YAOCE;
- void pmu_to_fcu()
- {
- //串口阻塞 和雷达升级不发送
- if(update_info.vk_dev_update_flag != true && EZup_par.update_flag != true)
- {
- switch (pmu_send)
- {
- case PMU_SEND_YAOCE:
- //心跳包单独发
- if(pmu_heart_flag == true)
- {
- pmu_to_con_heart_data();
- pmu_heart_flag = false;
- }
- //发送电压信息
- else if (vol_flag == true)
- {
- pmu_to_con_voltage_data();
- vol_flag = false;
- }
- // //发动机信息
- // else if (engine_flag == true)
- // {
- // pmu_to_con_engine_data();
- // engine_flag = false;
- // }
- // //mimo360测试
- // else if (mimo360_radar_flag == true)
- // {
- // pmu_to_con_radar360_data();
- // mimo360_radar_flag = false;
- // }
- else if(devtype_flag == true)
- {
- pmu_to_con_devtype_data();
- devtype_flag = false;
- }
- //CAN调试信息
- // else if(can_debug_flag == true)
- // {
- // //Can_send_debug_to_app();
- // can_debug_flag = false;
- // }
- //设备SN号,软硬件号
- else if (dev_version_flag == true)
- {
- pmu_to_fcu_version_data();
- dev_version_flag = false;
- }
-
- break;
- case PMU_SEND_REQINFO:
- pmu_to_con_request_data();
- pmu_send = PMU_SEND_YAOCE;
- break;
- case PMU_SEND_ACK:
- pmu_to_con_ack_data();
- pmu_send = PMU_SEND_YAOCE;
- break;
- case PMU_SEND_VERSION:
- pmu_to_con_version_data();
- pmu_send = PMU_SEND_YAOCE;
- break;
- case PMU_SEND_SHA1:
- pmu_to_fcu_key_data();
- pmu_send = PMU_SEND_YAOCE;
- break;
- default:
- pmu_send = PMU_SEND_YAOCE;
- break;
- }
- if(DM4Dmsg_send_fmu == true || (pmu_to_DM4Dmsg_flag == true && DM4d_to_fmu10s_flag <= 10000))
- {
- pmu_to_con_DM4DBradar_msg();
- pmu_to_DM4Dmsg_flag = false;
- DM4d_to_fmu10s_flag = HAL_GetTick();
- DM4Dmsg_send_fmu = false;
- }
- }
- }
- /**
- * @file timer_check_other_func
- * @brief FMU异常断电检测
- * @param none
- * @details UART2
- * @author Zhang Sir
- **/
- void timer_check_other_func()
- {
- //static uint32_t time1 = 0;
- static uint32_t time2 = 0;
- // if(Check_Timer_Ready(&time1,_1_HZ_))
- // {
- // if((planep.lock_status != STA_LOCK) && (fcu.connect_status == COMP_NORMAL) &&
- // (HAL_GetTick() - fcu.recv_time > 500))
- // {
- // stor_par.abnormal_outage_flag = 1;
- // write_flash_flag = true;
- // fcu.connect_status = COMP_LOST;
- // }
- // }
- if(Check_Timer_Ready(&time2,_2_HZ_))
- {
- if(HAL_GetTick() > 10000 && start_msg.version_info == false)
- {
- pmu_send = PMU_SEND_VERSION;
- start_msg.version_info = true;
- }
- else if (start_msg.key_info_checking == true && Device1.Vkbms_Link.connect_status == COMP_NORMAL)
- {
- pmu_send = PMU_SEND_SHA1;
- }
- else
- {
- //给FMU发送雷达灵敏度信息
- send_mocib_radar_sensi();
- }
- }
- }
- extern CAN_HandleTypeDef hcan1;
- extern CAN_HandleTypeDef hcan2;
- void thread_main_task_handle(void *param)
- {
- // if(Check_Chip_Verified != true)
- // {
- // while (1)
- // {
- // rt_thread_mdelay(5);
- // }
-
- // }
- while(1)
- {
- //数据发送定时器
- timer_function();
- //ADC采集
- ADC_GET_DATA();
- //点亮pmu内部led灯
- pmu_inside_led();
- // /*测试发送rkprintf*/
- // static uint32_t lastPrintTime = 0;
- // if( HAL_GetTick() - lastPrintTime > 1000){
- // rt_kprintf("this is a test!\r\n");
- // lastPrintTime = HAL_GetTick();
- // }
- //发送数据给主控制器 雷达升级不发送数据
- pmu_to_fcu();
- //更新播撒,称重,水泵,离心喷头,流量计等设备信息
- update_device_type_data();
- //智能电池相关功能
- bms_function();
- //雷达相关功能
- lidar_function();
- //判断异常断电,上电发送版本信息
- timer_check_other_func();
- //液位计相关功能
- //L1L2_GPIO_check();
- //获取设备版本和SN号
- get_device_version_and_sn();
- //写flash
- write_flash_function();
- #ifdef mimo_update
- mimo_obs_update_func();
- #else
- //设备升级
- Vk_Update_Device_Protocol();
- #endif
- eft_dev_update_func();
- send_uartfifo_msg();
- //CAN DEBUG
- // if(planep.Candebug_flag == true)
- // {
- // seek_can_debug_buf_adr();
- // }
- rt_thread_mdelay(2);
- }
- }
|