| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813 |
- #include "soft_p_2_c.h"
- #include "soft_uart.h"
- #include "usart.h"
- #include "stdbool.h"
- #include "soft_timer.h"
- #include "soft_adc.h"
- #include "soft_flow.h"
- #include "soft_crc.h"
- #include <string.h>
- #include "stdbool.h"
- #include "tim.h"
- #include "hard_led.h"
- #include "soft_can.h"
- #include "stdio.h"
- #include "soft_bms.h"
- #include "soft_terrain.h"
- #include "soft_obstacle.h"
- #include "soft_okcell.h"
- #include "soft_adc.h"
- #include "config.h"
- #include "soft_calibration.h"
- #include "soft_flash.h"
- #include "bsp_serial.h"
- #include "rkfifo.h"
- #include "soft_engine.h"
- #include "soft_eft.h"
- #include "math.h"
- #include "stdlib.h"
- #include "soft_water_device.h"
- #include "soft_seed_device.h"
- #include "soft_test.h"
- #include "can_debug.h"
- #include "soft_version.h"
- #include "soft_update.h"
- #include "qingxie_bms.h"
- #include "soft_flash.h"
- uint8_t msg_buf[256] = {0};
- uint16_t crc = 0;
- pmu_data pmu;
- plane_para planep = {.Candebug_flag = 0};
- /**
- * @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++] = 21;
- 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;
- uart2_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_set_ack
- * @brief PMU应答FMU
- * @param 命令 命令内容 123
- * @details
- * @author Zhang Sir
- **/
- 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;
- 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;
- pmu.voltage = ADC_gather() / 10.0f + volinf.cal_vol * 10; // 获取当前板子电压
- memcpy(&msg_buf[index], &pmu.voltage, 2);
- index += 2;
- pmu.temperature = ADC_read_temptrue();
- memcpy(&msg_buf[index], &pmu.temperature, 2);
- index += 2;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0;
- memcpy(&msg_buf[index], &uavinf.abnormal_outage_flag, 2);
- index += 2;
- msg_buf[1] = index - 6;
- crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- uart2_send_msg(msg_buf, index); //10
- //for(int i = 0;i<10;i++){
- //printf("%d ",msg_buf[6]);
- //printf("%d\n",msg_buf[7]);
- //}
- }
- /**
- * @file get_radar_info
- * @brief 获取雷达信息
- * @param Info_Type:避障雷达 X:1 Y:2
- * @details
- * @author Zhang Sir
- **/
- short get_radar_info(uint8_t Radar_Type,uint8_t Info_Type)
- {
- uavr_terrain *Ptr_T = NULL;
- uavr_obs *Ptr_O = NULL;
-
- if(Radar_Type == MSGID_SET_T_RADAR)
- {
- if(mimo_ter_info.Link.connect_status != COMP_NOEXIST)
- Ptr_T = &mimo_ter_info;
- else if(DM_ter_info.Link.connect_status != COMP_NOEXIST)
- Ptr_T = &DM_ter_info;
- else if(uavr56_info.Link.connect_status != COMP_NOEXIST)
- Ptr_T = &uavr56_info;
-
- if(Ptr_T->Link.connect_status == COMP_LOST) {return -2;}
- else if(Ptr_T == NULL) {return -1;}
- else {return Ptr_T->height;}
- }
- else if(Radar_Type == MSGID_SET_F_RADAR)
- {
- if(uavr11_info.Link.connect_status != COMP_NOEXIST)
- Ptr_O = &uavr11_info;
- else if(mimo_f_info.Link.connect_status != COMP_NOEXIST)
- Ptr_O = &mimo_f_info;
- else if(DM_f_info.Link.connect_status != COMP_NOEXIST)
- Ptr_O = &DM_f_info;
- if(Ptr_O->Link.connect_status == COMP_LOST) {return -2;}
- else if(Ptr_O == NULL) {return -1;}
- else
- {
- if(Info_Type == OBS_X)
- return Ptr_O->distance_x;
- else if((Info_Type == OBS_Y))
- return Ptr_O->distance_y;
- }
- }
- else if(Radar_Type == MSGID_SET_B_RADAR)
- {
- if(uavr12_info.Link.connect_status != COMP_NOEXIST)
- Ptr_O = &uavr12_info;
- else if(mimo_b_info.Link.connect_status != COMP_NOEXIST)
- Ptr_O = &mimo_b_info;
- if(Ptr_O->Link.connect_status == COMP_LOST) {return -2;}
- else if(Ptr_O == NULL) {return -1;}
- else
- {
- if(Info_Type == OBS_X)
- return Ptr_O->distance_x;
- else if((Info_Type == OBS_Y))
- return Ptr_O->distance_y;
- }
- }
- return 0;
- }
- /**
- * @file pmu_to_con_radar_data
- * @brief PMU发送雷达信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_con_radar_data()
- {
- int index = 0;
- //检查各种雷达连接状态
- check_radar_link_status();
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 10;
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSGID_RADAR;
- pmu.radar_buf[0] = get_radar_info(MSGID_SET_T_RADAR,0);
- pmu.radar_buf[1] = get_radar_info(MSGID_SET_F_RADAR,OBS_Y);
- pmu.radar_buf[2] = get_radar_info(MSGID_SET_F_RADAR,OBS_X);
- pmu.radar_buf[3] = get_radar_info(MSGID_SET_B_RADAR,OBS_Y);
- pmu.radar_buf[4] = get_radar_info(MSGID_SET_B_RADAR,OBS_X);
- terrain_is_link = pmu.radar_buf[0] > -1? true:false;
- obs_f_is_link = pmu.radar_buf[1] > -1? true:false;
- obs_b_is_link = pmu.radar_buf[3] > -1? true:false;
- // //发送木牛或者恩曌数据或者莫之比仿地
- // if ((muniu_ter_info.muniu_time == 0) && (mimo_ter_info.heart_time == 0) && (uavr56_info.heart_time == 0)) //上电没通讯
- // {
- // pmu.radar_buf[0] = -1;
- // terrain_is_link = false;
- // }
- // else if ((muniu_ter_info.muniu_heart_flag == false) && (mimo_ter_info.heart_flag == false) &&
- // (uavr56_info.heart_flag == false)) //持续3秒没有接收到数据 显示断开连接
- // {
- // pmu.radar_buf[0] = -2;
- // terrain_is_link = false;
- // }
- // else
- // {
- // if (muniu_ter_info.muniu_heart_flag == true)
- // {
- // pmu.radar_buf[0] = muniu_ter_info.muniu_hight;
- // terrain_height = muniu_ter_info.muniu_hight;
- // //printf("%d\n", muniu_hight);
- // }
- // else if (uavr56_info.heart_flag == true)
- // {
- // pmu.radar_buf[0] = uavr56_info.height;
- // terrain_height = uavr56_info.height;
- // // printf("%d\n",uavr56_info.height);
- // }
- // else if (mimo_ter_info.heart_flag == true)
- // {
- // pmu.radar_buf[0] = mimo_ter_info.height;
- // terrain_height = mimo_ter_info.height;
- // // printf("%d %d %d %d\n",mimo_ter_info.height,keep_time,ez_count,ez_count2);
- // }
- // terrain_is_link = true;
- // }
- // //前避障
- // if (uavr11_info.heart_time == 0 && mimo_f_info.heart_time == 0)
- // {
- // pmu.radar_buf[1] = -1;
- // obs_f_is_link = false;
- // }
- // else if (uavr11_info.heart_flag == false && mimo_f_info.heart_flag == false)
- // {
- // pmu.radar_buf[1] = -2;
- // obs_f_is_link = false;
- // }
- // else
- // {
- // if (uavr11_info.heart_flag == true)
- // {
- // if(Fobs_handle_function())
- // {
- // pmu.radar_buf[1] = uavr11_info.distance_y;
- // pmu.radar_buf[2] = uavr11_info.distance_x;
- // }
- // else
- // {
- // pmu.radar_buf[1] = 0;
- // pmu.radar_buf[2] = 0;
- // }
- // }
- // if (mimo_f_info.heart_flag == true)
- // {
- // if(Fobs_handle_function())
- // {
- // pmu.radar_buf[1] = mimo_f_info.distance_y;
- // pmu.radar_buf[2] = mimo_f_info.distance_x;
- // }
- // else
- // {
- // pmu.radar_buf[1] = 0;
- // pmu.radar_buf[2] = 0;
- // }
- // //printf("%d\n",ez_obs_distance_y);
- // // printf("%d %d %d %d\n",mimo_f_info.distance_y,keep_time,ez_count,ez_count2);
- // }
- // obs_f_is_link = true;
- // }
- // //后避障
- // if (uavr12_info.heart_time == 0 && mimo_b_info.heart_time == 0)
- // {
- // pmu.radar_buf[3] = -1;
- // obs_b_is_link = false;
- // }
- // else if (uavr12_info.heart_flag == false && mimo_b_info.heart_flag == false)
- // {
- // pmu.radar_buf[3] = -2;
- // obs_b_is_link = false;
- // }
- // else
- // {
- // if (uavr12_info.heart_flag == true)
- // {
- // if(Bobs_handle_function())
- // {
- // pmu.radar_buf[3] = uavr12_info.distance_y;
- // pmu.radar_buf[4] = uavr12_info.distance_x;
- // }
- // else
- // {
- // pmu.radar_buf[3] = 0;
- // pmu.radar_buf[4] = 0;
- // }
- // }
- // else if(mimo_b_info.heart_flag == true)
- // {
- // if(Bobs_handle_function())
- // {
- // pmu.radar_buf[3] = mimo_b_info.distance_y;
- // pmu.radar_buf[4] = mimo_b_info.distance_x;
- // }
- // else
- // {
- // pmu.radar_buf[3] = 0;
- // pmu.radar_buf[4] = 0;
- // }
- // }
-
- // obs_b_is_link = true;
- // }
- memcpy(&msg_buf[index], &pmu.radar_buf[0], 10);
- index += 10;
- msg_buf[1] = index - 6;
- crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- uart2_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_con_barttery_data
- * @brief PMU发送智能电池信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_con_barttery_data()
- {
- int index = 0;
- if (Dev.Bms_Link.connect_status == COMP_NORMAL)
- {
- uint8_t size_elong = 3 + 1 + 1 + bms_data.bms_num * 2; //前5字节:协议版本3 电池串数1 电池组数1
- uint8_t size_elong2 = 1 + bms_data2.bms_num * 2; //电池串数 加 电压
- msg_buf[index++] = 0xFE;
- msg_buf[index++] = 0; // 31 电池ID后的变量字节数
- msg_buf[index++] = 0;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = 0x00;
- msg_buf[index++] = _MSGID_BMS;
- bms_data.bms_version[0] = 'V';
- bms_data.bms_version[1] = 'K';
- bms_data.bms_version[2] = '3';
- bms_data.bms_group = group_num;
- //一组电池
- if (bms_data.bms_group == 1)
- {
- memcpy(&msg_buf[index], &bms_data, size_elong); //变长数组 赋值到最后一个电压
- index += size_elong;
- memcpy(&msg_buf[index], &bms_data.bms_ids, 45); //从id 到状态 31字节 + 2字节 厂商编号
- index += 45; //新加32字节 33+12=45
- msg_buf[1] = index - 6;
- crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- uart2_send_msg(msg_buf, index);
- }
- //两组电池
- else if (bms_data.bms_group == 2)
- {
- memcpy(&msg_buf[index], &bms_data, size_elong); //变长数组 赋值到最后一个电压
- index += size_elong;
- memcpy(&msg_buf[index], &bms_data.bms_ids, 45); //从id 到状态 31字节
- index += 45;
- memcpy(&msg_buf[index], &bms_data2.bms_num, size_elong2);
- index += size_elong2;
- memcpy(&msg_buf[index], &bms_data2.bms_ids, 45);
- index += 45;
- msg_buf[1] = index - 6;
- crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- uart2_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;
- crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- uart2_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;
- // 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;
- // uart2_send_msg(msg_buf, index);
- // }
- // }
- /**
- * @file pmu_to_con_radar360_data
- * @brief PMU发送360信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_con_DMradar_data(void)
- {
- uint8_t index = 0;
- if(DM_status.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_DMRADAR;
-
- DM_recv_flag = 1;
- memcpy(&msg_buf[index],&FMU_DM_info.target_num,3);
- index += 3;
- memcpy(&msg_buf[index],&FMU_DM_info.warn,2);
- index += 2;
-
- memcpy(&msg_buf[index],FMU_DM_info.buf,DM_T_info.target_num * 4);
- index += DM_T_info.target_num * 4;
- DM_recv_flag = 0;
- msg_buf[1] = index - 6;
- crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- uart2_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;
- uint32_t time = 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;
- ack_content1 = uavinf.reset_reason;
- memcpy(&msg_buf[index],&ack_content1,2);
- index += 2;
-
- memcpy(&msg_buf[index],&ack_content2,2);
- index += 2;
-
- time = HAL_GetTick();
- memcpy(&msg_buf[index],&time,4);
- index += 4;
- msg_buf[1] = index - 6;
- crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- uart2_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;
- // uart2_send_msg(msg_buf, len);
- // }
- void pmu_to_con_devtype_data(void)
- {
- uint16_t index = 0;
- bool send_flag = true;
- 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((Dev.Bms_Link.connect_status == COMP_NORMAL || _Aqx_bms_link.connect_status == COMP_NORMAL) &&
- devinfo_time.bms == true)
- {
- if(Dev.Bms.facid == FAC_QX_BMS)
- msg_buf[index++] = DEV_QQ_BMS;
- else
- msg_buf[index++] = DEV_BMS;
-
- memcpy(&msg_buf[index],&Dev.Bms.facid,Dev.Bms.index + 1);
- index += Dev.Bms.index + 1;
- devinfo_time.bms = false;
- }
- else if(devinfo_time.flow == true)
- {
- msg_buf[index++] = DEV_FLOW;
- memcpy(&msg_buf[index],&Dev.Flow.facid,sizeof(Flow_info));
- index += sizeof(Flow_info);
- devinfo_time.flow = false;
- }
- else if (devinfo_time.radar == true)
- {
- msg_buf[index++] = DEV_RADAR;
- memcpy(&msg_buf[index],&Dev.Radar.facid_T,sizeof(Radar_info));
- index += sizeof(Radar_info);
- devinfo_time.radar = false;
- }
- else if(devinfo_time.checklow == true)
- {
- msg_buf[index++] = DEV_CHECKLOW;
- memcpy(&msg_buf[index],&Dev.Checklow.facid,sizeof(CheckLow_info));
- index += sizeof(CheckLow_info);
- devinfo_time.checklow = false;
- }
- else if(Dev.Part_Tradar_Link.connect_status == COMP_NORMAL && 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);
- devinfo_time.part_radar = false;
- }
- // else if(Dev.Bms_Link.connect_status == COMP_NORMAL && 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;
- // devinfo_time.bms = false;
- // }
- else if(Dev.L_pump1_Link.connect_status == COMP_NORMAL && 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);
- devinfo_time.L_pump1 = false;
- }
- else if(Dev.L_pump2_Link.connect_status == COMP_NORMAL && 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);
- devinfo_time.L_pump2 = false;
- }
- else if(Dev.Weight_Link.connect_status == COMP_NORMAL && devinfo_time.weight == true)
- {
- msg_buf[index++] = DEV_WEIGHT;
- memcpy(&msg_buf[index],&Dev.Weight.facid,sizeof(Weight_info));
- index += sizeof(Weight_info);
- devinfo_time.weight = false;
- }
- else if(Dev.Seed_Link.connect_status == COMP_NORMAL && devinfo_time.seed == true)
- {
- msg_buf[index++] = DEV_SEED;
- memcpy(&msg_buf[index],&Dev.Seed.facid,sizeof(Seed_info));
- index += sizeof(Seed_info);
- devinfo_time.seed = false;
- }
- else if (Dev.Pump_Link.connect_status == COMP_NORMAL && devinfo_time.pump == true)
- {
- msg_buf[index++] = DEV_PUMP;
- memcpy(&msg_buf[index],&Dev.Pump.facid,sizeof(Pump_info));
- index += sizeof(Pump_info);
- devinfo_time.pump = false;
- }
- else if (Dev.Nozzle_Link.connect_status == COMP_NORMAL && devinfo_time.nozzle == true)
- {
- msg_buf[index++] = DEV_NOZZLE;
- memcpy(&msg_buf[index],&Dev.Nozzle.facid,sizeof(Nozzle_info));
- index += sizeof(Nozzle_info);
- devinfo_time.nozzle = false;
- }
- else if (Dev.Arm_Link.connect_status == COMP_NORMAL && devinfo_time.arm == true)
- {
- msg_buf[index++] = DEV_ARM;
- memcpy(&msg_buf[index],&Dev.Arm.facid,sizeof(Arm_info));
- index += sizeof(Arm_info);
- devinfo_time.arm = false;
- }
- else if(Dev.Current_Link.connect_status == COMP_NORMAL && devinfo_time.current == true)
- {
- msg_buf[index++] = DEV_CURRENT;
- memcpy(&msg_buf[index],&Dev.Current.facid,sizeof(Current_info));
- index += sizeof(Current_info);
- devinfo_time.current = false;
- }
- else if(Dev.Temp_Sensor_Link.connect_status == COMP_NORMAL && devinfo_time.tempSensor == true)
- {
- msg_buf[index++] = DEV_TEMPSENSOR;
- memcpy(&msg_buf[index],&Dev.Temp_sensor.facid,sizeof(_Temp_sensor));
- index += sizeof(_Temp_sensor);
- devinfo_time.tempSensor = false;
- }
- else
- {
- send_flag = false;
- }
- msg_buf[1] = index - 6;
- crc = Get_Crc16(msg_buf, index);
- msg_buf[index++] = crc;
- msg_buf[index++] = (crc >> 8) & 0xff;
- if(send_flag == true)
- uart2_send_msg(msg_buf, index);
- }
- /**
- * @file radar_version_check
- * @brief 更改雷达版本格式
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void radar_version_check(void)
- {
- //前避障
- if(uavr11_info.Link.connect_status == COMP_NORMAL || uavr11_info.Link.boot_flag == true)
- {
- if(uavr11_info.soft_verison == 0 && uavr11_info.get_radar_ver_flag == false)
- {
- uavr11_info.version[0] = 'M';
- uavr11_info.version[1] = '1';
- for(uint8_t i = 2;i < 10; i++)
- {
- uavr11_info.version[i] = '0';
- }
- }
- memcpy(&radar_version[0][0],&uavr11_info.version[0],10);
- }
- else if (mimo_f_info.Link.connect_status == COMP_NORMAL)
- {
- if(mimo_f_info.Link.boot_flag == true)
- {
- memcpy(&mimo_f_info.version,"E100000000",10);
- }
- memcpy(&radar_version[0][0],&mimo_f_info.version[0],10);
- }
- else if(DM_f_info.Link.connect_status == COMP_NORMAL)
- {
- memcpy(&radar_version[0][0],&DM_f_info.version[0],10);
- }
-
- //后避障
- if(uavr12_info.Link.connect_status == COMP_NORMAL )
- {
- if(uavr12_info.soft_verison == 0 && uavr12_info.get_radar_ver_flag == false)
- {
- uavr12_info.version[0] = 'M';
- uavr12_info.version[1] = '2';
- for(uint8_t i = 2;i < 10; i++)
- {
- uavr12_info.version[i] = '0';
- }
- }
- memcpy(&radar_version[1][0],&uavr12_info.version[0],10);
- }
- else if(mimo_b_info.Link.connect_status == COMP_NORMAL)
- {
- if(mimo_b_info.Link.boot_flag == true)
- {
- memcpy(&mimo_b_info.version,"E200000000",10);
- }
- memcpy(&radar_version[1][0],&mimo_b_info.version[0],10);
- }
- if(uavr56_info.Link.connect_status == COMP_NORMAL )
- {
- if(uavr56_info.soft_verison == 0 && uavr56_info.get_radar_ver_flag == false)
- {
- uavr56_info.version[0] = 'M';
- uavr56_info.version[1] = 'B';
- for(uint8_t i = 2;i < 10; i++)
- {
- uavr56_info.version[i] = '0';
- }
- }
-
- memcpy(&radar_version[2][0],&uavr56_info.version[0],10);
- }
- else if(mimo_ter_info.Link.connect_status == COMP_NORMAL)
- {
- if(mimo_ter_info.Link.boot_flag == true)
- {
- memcpy(&mimo_ter_info.version,"EB00000000",10);
- }
- memcpy(&radar_version[2][0],&mimo_ter_info.version[0],10);
- }
- else if(DM_ter_info.Link.connect_status == COMP_NORMAL)
- {
- memcpy(&radar_version[2][0],&DM_ter_info.version[0],10);
- }
- }
- /**
- * @file pmu_to_con_version_data
- * @brief PMU发送版本信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- char radar_version[3][10] = {0}; //0 前避障 1后避障 2仿地
- void pmu_to_con_version_data()
- {
- //版本信息 0 - 5 硬件版本 IAP版本 APP版本
- uint32_t ver_msg_buf[4] = {0};
-
- int index = 0;
- ver_msg_buf[0] = serial.num; //硬件版本号
- ver_msg_buf[1] = IAP_VERSION; //IAP版本号
- ver_msg_buf[2] = APP_VERSION; //APP版本号
- ver_msg_buf[3] = serial.num;//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;
- crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- uart2_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_fcu_version_data
- * @brief 版本信息发送,新协议还没用
- * @param none
- * @details
- * @author Zhang Sir
- **/
- void pmu_to_fcu_version_data()
- {
- dev_version_content *ptr = NULL;
- for(uint8_t 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;
- crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- uart2_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;
- crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- uart2_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;
- crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- uart2_send_msg(msg_buf, index);
- }
- /**
- * @file pmu_to_con_request_data
- * @brief PMU发送应答信息
- * @param none
- * @details
- * @author Zhang Sir
- **/
- char ack_id = 0;
- short ack_content = 0;
- short ack_content1 = 0;
- short ack_content2 = 0;
- 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;
- crc = Get_Crc16(msg_buf, index);
- memcpy(&msg_buf[index], &crc, 2);
- index += 2;
- uart2_send_msg(msg_buf, index);
- }
- /******************void pmu_to_fcu()******************************
- * ****************PMU发送信息给主控********************************
- * ****************************************************************/
- /**
- * @file pmu_to_fcu
- * @brief PMU发送信息给FMU
- * @param none
- * @details UART2
- * @author Zhang Sir
- **/
- uint8_t pmu_send = PMU_SEND_YAOCE;
- uint32_t utc_time = 0;
- void pmu_to_fcu()
- {
- //串口阻塞 和雷达升级不发送
- if(uart_info.vk_dev_update_flag != true && EZup_par.update_flag != true && Rupdate.update_flag != true)
- {
- switch (pmu_send)
- {
- case PMU_SEND_YAOCE:
- //发送电压信息
- 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(DM_radar_flag == true)
- {
- pmu_to_con_DMradar_data();
- DM_radar_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;
- }
- //设备信息
- else if (devtype_flag == true)
- {
- pmu_to_con_devtype_data();
- devtype_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;
- case PMU_SEND_DEV_INFO:
- pmu_to_fcu_version_data();
- pmu_send = PMU_SEND_YAOCE;
- break;
- default:
- break;
- }
- //心跳包单独发
- if(pmu_heart_flag == true)
- {
- pmu_to_con_heart_data();
- pmu_heart_flag = false;
- }
- }
- }
- void Check_Rst(void)
- {
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET ) // NRST 引脚复位
- {
- uavinf.reset_reason = R_NRST;
- write_uav_information = true;
- __HAL_RCC_CLEAR_RESET_FLAGS();
- }
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET ) // 上电掉电复位
- {
- uavinf.reset_reason = R_POWER;
- write_uav_information = true;
- __HAL_RCC_CLEAR_RESET_FLAGS();
- }
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET ) // 软件复位
- {
- uavinf.reset_reason = R_SOFT;
- write_uav_information = true;
- __HAL_RCC_CLEAR_RESET_FLAGS();
- }
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET ) // 独立看门狗复位
- {
- uavinf.reset_reason = R_IWD;
- write_uav_information = true;
- __HAL_RCC_CLEAR_RESET_FLAGS();
- }
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST) != RESET ) // 窗口看门狗复位
- {
- uavinf.reset_reason = R_WWD;
- write_uav_information = true;
- __HAL_RCC_CLEAR_RESET_FLAGS();
- }
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST) != RESET ) // 低功耗复位
- {
- uavinf.reset_reason = R_LOPWER;
- write_uav_information = true;
- __HAL_RCC_CLEAR_RESET_FLAGS();
- }
-
-
- }
- /******************void check_fmu_link()************************
- * ****************检查是否收到FMU信息************************************
- * ****************************************************************/
- static uint32_t fmu_link_time = 0;
- void check_fmu_link()
- {
- //FMU串口通讯连接检测
- if(HAL_GetTick() > 15000)
- {
- if(recv_fmu_data == true && HAL_GetTick() - fmu_link_time > 3000)
- {
- recv_fmu_data = false;
- }
- }
- //FMU异常断电检测
- if((planep.lock_status != STA_LOCK) && (recv_fmu_data == true) && (HAL_GetTick() - fmu_link_time > 500))
- {
- uavinf.abnormal_outage_flag = 1;
- write_uav_information = true;
- recv_fmu_data = false;
- }
- //Check_Rst();
- }
- /******************void uart_recv_con_msg()************************
- * ****************PMU收控制消息************************************
- * ****************************************************************/
- _pmu_pin pmu_pin;
- bool recv_fmu_data = false;
- Set_info msgidset;
- void uart_recv_con_msg()
- {
- check_fmu_link();
- check_uart_data(&recv_rkfifo);
- if (uart_info.fcu_buf_flag == true)
- {
- uint32_t tem_32t = 0;
- FLASH_EraseInitTypeDef f;
- fmu_link_time = HAL_GetTick();
- recv_fmu_data = true;
- switch (fcu_protocol.msg_id)
- {
- case _MSGID_PWM:
- memcpy(&pmu_pin.pump1, &fcu_protocol.payload[6], sizeof(_pmu_pin));
- if(set_HWesc_ESCid == true && setESCidInfo.setESCidStep == SETESCID_SET)
- {
- memset(&pmu_pin.pump1,0,4);
-
- if(setESCidInfo.setESCidNum == 1)
- pmu_pin.pump1 = 1000;
- else if(setESCidInfo.setESCidNum == 2)
- pmu_pin.pump2 = 1000;
- }
- __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, pmu_pin.pump1);
- __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, pmu_pin.pump2);
-
- if(planep.UAV_type == VK_ALL_IN_ONE)
- {
- __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz1_fm);
- __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz2_zp);
- }
- else
- {
- __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz1_fm);
- __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz2_zp);
- }
- if(planep.UAV_type == VK_ALL_IN_ONE)
- {
- //分电板离心喷头
- distributor.nozzle1 = pmu_pin.nozz1_fm;
- distributor.nozzle2 = pmu_pin.nozz2_zp;
-
- //离心喷头34
- __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, pmu_pin.nozz3); // PB8 nozzle
- __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, pmu_pin.nozz4); // PB9 nozzle
- //前后灯
- if((pmu_pin.aux_light & 0x1) > 0)
- HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_SET);
- else
- HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_RESET);
- if((pmu_pin.aux_light & 0x2) > 0)
- HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
- else
- HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);
- //摄像头舵机
- __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, pmu_pin.aux_steer);
- }
-
- break;
- case _MSGID_LED:
- for(uint8_t i = 0; i < 7; i++)
- {
- if(planep.UAV_type != VK_ALL_IN_ONE ) //青岛机型不用LED
- {
- led_set_blink(i, fcu_protocol.payload[i*3+6], fcu_protocol.payload[i*3+7], fcu_protocol.payload[i*3+8]);
- }
- }
- break;
- //飞机姿态信息
- case _MSGID_ATTITUDE:
- memcpy(&planep.yaw, &fcu_protocol.payload[6], sizeof(plane_para));
- if(uavinf.uavtype != planep.UAV_type)
- {
- write_uav_information = true;
- }
- break;
- case _MSGID_TIME:
- //tem_32t = 1684136124;
- memcpy(&utc_time, &fcu_protocol.payload[6], 4);
- covUnixTimeStp2Beijing(utc_time,&beijing_time);
- pmu_set_ack(_MSGID_TIME,0,0,0);
- break;
- //eft播撒器
- case _MSGID_EFT_CON:
- recv_fmu_seed_info = true;
- memcpy(&tppwm_value, &fcu_protocol.payload[6], 2);
- memcpy(&sow_rotate_value, &fcu_protocol.payload[8], 2);
- break;
- //请求信息包
- case _MSGID_REQ:
- switch (fcu_protocol.payload[6])
- {
- case MSGID_REQ_VERSION:
- pmu_send = PMU_SEND_VERSION;
- break;
- default:
- break;
- }
- break;
- //主控应答
- case _MSGID_ACK:
- msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
- switch (fcu_protocol.payload[6])
- {
- case MSGID_ACK_HEART:
- uavinf.abnormal_outage_flag = 0;
- write_uav_information = true;
- break;
- case MSGID_ACK_VERSION:
- start_msg.version_info = true;
- break;
- case MSGID_ACK_DEV:
- {
- if(msgidset.content1 < DEVICE_END - 1)
- {
- dev_version_content *Pt = dev_ptr[msgidset.content1];
- if(Pt->send_times > 0)
- Pt->send_times--;
- }
- }
- break;
- default:
- break;
- }
- break;
- //设置雷达灵敏度
- case _MSGID_SET:
- msgidset.num = fcu_protocol.payload[6];
- msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
- msgidset.content2 = fcu_protocol.payload[9] + 256 * fcu_protocol.payload[10];
- switch (msgidset.num)
- {
- //前雷达
- case MSGID_SET_F_RADAR:
- if(uavr12_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
- {
- uavr11_info.fcu_set_sensi_flag = true;
- }
- memcpy(&obsfradar_sensitivity, &fcu_protocol.payload[7], 2);
- if(obsfradar_sensitivity == uavr11_info.get_radar_sensi)
- {
- uavr11_info.fcu_set_sensi_flag = false;
- pmu_set_ack(_MSGID_SET,MSGID_SET_F_RADAR,uavr11_info.get_radar_sensi,0);
- }
- break;
- //后雷达
- case MSGID_SET_B_RADAR:
- if(uavr11_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
- {
- uavr12_info.fcu_set_sensi_flag = true;
- }
- memcpy(&obsbradar_sensitivity, &fcu_protocol.payload[7], 2);
- if(obsbradar_sensitivity == uavr12_info.get_radar_sensi)
- {
- uavr12_info.fcu_set_sensi_flag = false;
- pmu_set_ack(_MSGID_SET,MSGID_SET_B_RADAR,uavr12_info.get_radar_sensi,0);
- }
- break;
- //仿地
- case MSGID_SET_T_RADAR:
- if(uavr11_info.fcu_set_sensi_flag != true && uavr12_info.fcu_set_sensi_flag != true && radar_update_flag == false)
- {
- uavr56_info.fcu_set_sensi_flag = true;
- }
- memcpy(&uavr56_info.fcu_set_sensi, &fcu_protocol.payload[7], 2);
- if(uavr56_info.fcu_set_sensi == uavr56_info.get_radar_sensi)
- {
- uavr56_info.fcu_set_sensi_flag = false;
- pmu_set_ack(_MSGID_SET,MSGID_SET_T_RADAR,uavr56_info.get_radar_sensi,0);
- }
- break;
- case MSGID_SET_TR_BLIND:
- {
- uint8_t can_buf[8] = {0};
- uint32_t can_id = 0;
- if(msgidset.content1 == 0x11)
- can_id = 0xA81300;
- else if (msgidset.content1 == 0x56)
- can_id = 0x981300;
- put_date_to_can(can_buf,0x5,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
- can_send_msg_normal(&can_buf[0], 8, can_id);
- }
- break;
- case MSGID_SET_BR_POWER:
- {
- uint8_t can_buf[8] = {0};
- uint32_t can_id = 0;
- if(msgidset.content1 == 0x11)
- can_id = 0xA81300;
- else if (msgidset.content1 == 0x56)
- can_id = 0x981300;
- put_date_to_can(can_buf,0x7,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
- can_send_msg_normal(&can_buf[0], 8, can_id);
- }
- break;
- case MSGID_SET_R_FUNC:
- {
- uint8_t can_buf[8] = {0};
- uint32_t can_id = 0;
- if(msgidset.content1 == 3)
- can_id = 0x981300;
- else if(msgidset.content1 == 5)
- can_id = 0xA81300;
- put_date_to_can(can_buf,0x4,(msgidset.content1 & 0xff),((msgidset.content1 >> 8) & 0xff),0,0,0,0,0X7);
- can_send_msg_normal(&can_buf[0], 8, can_id);
- }
- break;
- case MSGID_SET_RAW_SWITCH:
- {
- uint8_t can_buf[8] = {0};
- uint32_t can_id = 0;
- if(msgidset.content1 == 0x11)
- can_id = 0xA81300;
- else if (msgidset.content1 == 0x56)
- can_id = 0x981300;
- put_date_to_can(can_buf,0xA,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
- can_send_msg_normal(&can_buf[0], 8, can_id);
- }
- break;
- case MSGID_SET_GEELY:
- switch (fcu_protocol.payload[7])
- {
- case SET_START_OR_STOP:
- if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
- {
- if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 0)
- {
- sendto_geely.ExtenderControl = 1;
- }
- start_engine = 0x80;
- }
- else if(0x0 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
- {
- if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 1)
- {
- sendto_geely.ExtenderControl = 0;
- }
- start_engine = 0;
- }
- break;
- case SET_PROTECT_TIME:
- if (geely_engin_link.connect_status == COMP_NORMAL)
- {
- geely_set_tcd = true;
-
- sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
- }
- break;
- case SET_LOCK_TIME:
- if (geely_engin_link.connect_status == COMP_NORMAL)
- {
- geely_set_tlock = true;
-
- sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
- }
- break;
- case SET_LOWVOL_PROTECT:
- if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
- {
- if (geely_engin_link.connect_status == COMP_NORMAL)
- {
- sendto_geely.ExtenderControl = 1;
- geely_set_protect = true;
- }
- }
- else
- {
- geely_set_protect = false;
- }
- break;
- default:
- break;
- }
- break;
- case MSGID_SET_VOL:
- set_cali_voltage = (fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8]) - (int)(ADC_gather() /100.0f) ;
- write_vol_information = true;
- pmu_set_ack(_MSGID_SET,MSGID_SET_VOL,0,0);
- break;
- case MSGID_SET_MIMO_FLOW:
- if(msgidset.content1 != 0)
- {
- if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
- {
- tem_32t = flow_mimo1.flow_k * msgidset.content1 / 100;
-
- if(tem_32t >= 500 && tem_32t <= 20000)
- {
- flow_mimo1.flow_calk = tem_32t;
- }
- else{
- flow_mimo1.flow_calk = 10000;
- }
- flow_mimo1.send_k_count = 5;
- }
- else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
- {
- tem_32t = flow_inf.ch1.k * msgidset.content1 / 100;
-
- if(tem_32t >= 500 && tem_32t <= 20000)
- {
- flow_inf.ch1.cal_k = tem_32t;
- }
- else{
- flow_inf.ch1.cal_k = 10000;
- }
- flow_inf.ch1.set_k = true;
- }
- }
- if(msgidset.content2 != 0)
- {
- if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
- {
- tem_32t = flow_mimo2.flow_k * msgidset.content2 / 100;
- if(tem_32t >= 500 && tem_32t <= 20000)
- {
- flow_mimo2.flow_calk = tem_32t;
- }
- else{
- flow_mimo2.flow_calk = 10000;
- }
- flow_mimo2.send_k_count = 5;
- }
- else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
- {
- tem_32t = flow_inf.ch2.k * msgidset.content2 / 100;
-
- if(tem_32t >= 500 && tem_32t <= 20000)
- {
- flow_inf.ch2.cal_k = tem_32t;
- }
- else{
- flow_inf.ch2.cal_k = 10000;
- }
- flow_inf.ch1.set_k = true;
- }
- }
- break;
- case MSGID_SET_FLOW_BACKGROUND:
- if(Dev.Flow.facid == FAC_MIMO_SIG)
- {
- flow_inf.ch1.clear_background = true;
- }
- if(Dev.Flow.facid == FAC_MIMO_DOU)
- {
- flow_inf.ch1.clear_background = true;
- flow_inf.ch2.clear_background = true;
- }
- break;
- case MSGID_SET_WEIGHT_K:
- //calib_aux = msgidset.content1 + (msgidset.content2 << 2); //bit 0-1 编号 2-15K值
- weight_order.type = Weight_Set_K;
- weight_order.order_con1 = msgidset.content1;
- weight_order.order_con2 = msgidset.content2;
- break;
- case MSGID_SET_SEED_OUT_TYPE:
- recv_fmu_seed_info = true;
- seed_output_mode = msgidset.content1;
- pmu_set_ack(_MSGID_SET,MSGID_SET_SEED_OUT_TYPE,0,0);
- break;
- case MSGID_SET_SEED_CAL_TYPE:
- switch (msgidset.content1)
- {
- case Cal_Remove_Peel:
- weight_order.type = Weight_Peer;
- break;
- case Cal_Weight:
- weight_order.type = Weight_Kg;
- weight_order.order_con2 = msgidset.content2;
- break;
- case Cal_Seed_Back:
- weight_order.type = Weight_Bcak;
- break;
- default:
- break;
- }
- break;
- case MSGID_SET_WEIGHT_MODE:
- weight_order.type = Weight_Mode;
- weight_order.order_con1 = msgidset.content1;
- break;
- case MSGID_SET_MAX_RATE:
- weight_order.type = Weight_Drug_Rate;
- weight_order.order_con1 = msgidset.content1;
- break;
- case MSGID_SET_PMU_SERIAL:
- set_pmu_serail = msgidset.content1 + ((msgidset.content2 << 16) & 0xffff0000);
- if(serial.num == PMU_SERIAL || set_pmu_serail == PMU_SERIAL)
- {
- write_serial_information = true;
- pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
- dev_pmu.send_times += 5;
- }
- else if(set_pmu_serail == serial.num)
- {
- pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
- }
- break;
- case MSGID_SET_RADAR_FB:
- {
- uint8_t can_buf[8] = {0};
- if(msgidset.content1 == 0x11)
- {
- put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X01,0X65,0X00);
- can_send_msg_normalstd(can_buf,7,0xFA);
- }
- else if (msgidset.content1 == 0x12)
- {
- put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X02,0X66,0X00);
- can_send_msg_normalstd(can_buf,7,0xFA);
- }
- else if(msgidset.content1 == 0x100)
- {
- if(msgidset.content2 == 0x11 || msgidset.content2 == 0x12)
- {
- put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X00,0X03,0X64,0X00);
- can_send_msg_normalstd(can_buf,7,0xFA);
- }
- else if(msgidset.content2 == 0x56)
- {
- put_date_to_can(can_buf,0x55,0XAA,0X02,0X60,0X03,0X63,0X00,0X00);
- can_send_msg_normalstd(can_buf,6,0xFA);
- }
- }
- }
- break;
- case MSGID_SET_LACKLOSS_CAL:
- {
- uint8_t can_buf[8] = {0};
- if(Dev.Lackloss_Link.connect_status == COMP_NORMAL)
- {
- mimo_lackloss.cal_distance = mimo_lackloss.distance / 10 + 5;
- put_date_to_can(can_buf,0xFA,0x03,0x00,0xB1,0XC1,0x00,0X00,0X00);
- can_buf[6] = mimo_lackloss.cal_distance & 0xff;
- can_buf[5] = (mimo_lackloss.cal_distance >> 8) & 0xff;
- can_buf[7] = (can_buf[1]+can_buf[2]+can_buf[3]+can_buf[4]+can_buf[5]+can_buf[6]) & 0xff;
- can_send_msg_normalstd(can_buf,8,0xFA);
- }
- }
- break;
- case MSGID_SET_PUMP_ID:
- set_HWesc_ESCid = true;
- setESCidInfo.setESCidNum = 1;
- setESCidInfo.setESCidStep = SETESCID_INIT;
- pmu_set_ack(_MSGID_SET,MSGID_SET_PUMP_ID,0,2);
- break;
- case MSGID_SET_FRADAR_SN:
- {
- int radar_Sn = 0;
- uint8_t can_buf[8] = {0};
- radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
- can_buf[0] = 2;
- memcpy(&can_buf[1],&radar_Sn,4);
- can_buf[7] = 7;
- can_send_msg_normal(can_buf,8,0xA81300);
- DM_f_info.get_radar_ver_flag = false;
- dev_obsf.regist.sn = false;
- pmu_set_ack(_MSGID_SET,MSGID_SET_FRADAR_SN,msgidset.content1,msgidset.content2);
- }
- break;
- case MSGID_SET_BRADAR_SN:
- {
- int radar_Sn = 0;
- uint8_t can_buf[8] = {0};
- radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
- can_buf[0] = 2;
- memcpy(&can_buf[1],&radar_Sn,4);
- can_buf[7] = 7;
- can_send_msg_normal(can_buf,8,0xB81300);
- dev_obsb.regist.sn = false;
- //DM_b_info.get_radar_ver_flag = false;
- pmu_set_ack(_MSGID_SET,MSGID_SET_BRADAR_SN,msgidset.content1,msgidset.content2);
- }
- break;
- case MSGID_SET_TRADAR_SN:
- {
- int radar_Sn = 0;
- uint8_t can_buf[8] = {0};
- radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
- can_buf[0] = 2;
- memcpy(&can_buf[1],&radar_Sn,4);
- can_buf[7] = 7;
- can_send_msg_normal(can_buf,8,0x981300);
- DM_ter_info.get_radar_ver_flag = false;
- dev_ter.regist.sn = false; //重新获取sn
- pmu_set_ack(_MSGID_SET,MSGID_SET_TRADAR_SN,msgidset.content1,msgidset.content2);
- }
- break;
- default:
- break;
- }
- break;
- case _MSGID_HEART:
- pmu_heart_flag = true;
- break;
- case _MSGID_SHA1:
- //智能电池秘钥
- if(fcu_protocol.payload[6] == 1)
- {
- //有秘钥
- if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 1)
- {
- if(start_msg.key_info_checking == true)
- {
- memcpy(&start_msg.key_data[0],&fcu_protocol.payload[9],20);
- start_msg.key_to_bms = true;//给电池发送秘钥
- start_msg.key_info_checking = false;
- }
- }
- //无秘钥
- else if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 2)
- {
- start_msg.key_info_checking = false;
- }
- //回馈,防止PMU一直发
- else if(fcu_protocol.payload[7] == 3 || fcu_protocol.payload[7] == 4)
- {
- start_msg.key_info_checking = false;
- }
- }
- break;
- //升级固件标志
- case _MSGID_UPDATA:
- {
- __disable_irq();
- HAL_FLASH_Unlock();
- __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
- f.TypeErase = FLASH_TYPEERASE_PAGES;
- f.PageAddress = UPDATE_FLAG;
- f.NbPages = 1;
- uint32_t PageError = 0;
- HAL_FLASHEx_Erase(&f, &PageError);
- uint16_t TempBuf = 0x01;
- HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, UPDATE_FLAG, TempBuf);
- HAL_FLASH_Lock();
- __enable_irq();
- HAL_NVIC_DisableIRQ(USART2_IRQn);
- HAL_Delay(100);
- //软件复位
- HAL_NVIC_SystemReset();
- }
- break;
- default:
- break;
- }
- uart_info.fcu_buf_flag = false;
- memset(fcu_protocol.payload, 0, 256);
- }
- }
- /******************void pmu_start_info()*******************
- * ****************上电时PMU发送的信息*******************************
- * ****************************************************************/
- Start_info start_msg = {.key_info_checking = true,
- .Dev_type = 1,
- .Id = 1,
- };
- void pmu_start_info()
- {
- static uint32_t circu_time_2hz = 0;
- if(Check_Timer_Ready(&circu_time_2hz,_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;
- }
- }
- }
|