#ifndef _SOFT_OBSTACLE_H
#define _SOFT_OBSTACLE_H
#include "stdint.h"
#include "stdbool.h"
#include "common.h"

#define OBS_X 1
#define OBS_Y 2

//莫之比雷达发送升级命令
#define CAN_UAVRH_UPDATE_S1    (0x7E0)
//发送消息到莫之比雷达
#define SEND_UAV20_MSG   (0x00FFEE01)
//发送消息到莫之比雷达读取版本
#define SEND_UAV20_VER   (0x00FFEE02)
//莫之比雷达反馈版本信息，读取命令是SEND_UAV20_VER
#define CAN_UAVRH_VER_R        (0x7E8)
//莫之比雷达设置灵敏度及反馈
#define CAN_UAVRH_SENSI_SA      (0x7F6)
//莫之比雷达读取灵敏度及反馈
#define CAN_UAVRH_SENSI_RA      (0x7F8)

#define CAN_UAVRH_TEST      (0x7F9)

#define RAD ((float)57.3)
#define DEG_TO_RAD 0.017453292519943295769236907684886f // 度换算弧度
#define RAD_TO_DEG 57.295779513082320876798154814105f   // 弧度换算度

#define CAN_UAVRH_UPDATE_R1 (0x7E1)
//恩曌避障
#define CAN_MIMO_ATTI_INFO1 0xDF00
#define CAN_MIMO_ATTI_INFO2 0xDF01
#define RADAR_NER_VERSION    0x220718
#define MIMO_360_TotalSect   60
#pragma pack(1)
typedef struct
{
  unsigned long long FrameID : 4;
  unsigned long long PackageID : 4;
  long long RCS : 8;
  long long Vel : 10;
  unsigned long long FrameType : 2;
  long long Distance : 12;
  long long Amuzith : 12;
  long long Elevation : 12;
}mimo_part_radar;
#pragma pack()
extern mimo_part_radar F_radar[3];
extern mimo_part_radar B_radar[3];
extern mimo_part_radar T_radar[3];
extern bool obs_f_is_link;
extern bool obs_b_is_link;

extern bool uavrhup_getr1_ack;

extern short obsfradar_sensitivity;
extern short obsbradar_sensitivity;

//避障雷达
#pragma pack(1)
typedef struct 
{

  Connect_check Link;

  //距离数据
  short distance_x;
  short distance_y;
  uint8_t signal_qulity;

  //灵敏度
  short get_radar_sensi;
  bool get_radar_sensi_flag;
  bool fcu_set_sensi_flag;
  char send_fcu_sensi_count;
  char get_radar_sensi_count;
  char set_radar_sensi_count;
  char set_radar_sensi_ack;

  //版本信息
  int soft_verison; //软件版本 区分新旧雷达，旧版本设置灵敏度进BOOT
  char version[11];
  int hard_version;

  bool get_radar_ver_flag; //检测到雷达一直发，上电发几次可能收不到
  bool get_radar_sn_flag;
  bool get_radar_blind_flag;
  bool get_radar_power_flag;
  bool get_radar_rawSwitch_flag;

  //SN号
  //char send_radar_sn_count; 和版本用一个count
  char sn[20];
}uavr_obs;
#pragma pack()
extern uavr_obs uavr11_info;  
extern uavr_obs uavr12_info;
extern uavr_obs mimo_f_info; 
extern uavr_obs mimo_b_info;
extern uavr_obs DM_f_info;
//extern uavr_obs DM_b_info;
#pragma pack(1)


// #pragma pack(1)
// typedef struct
// {
//   uint8_t TotalSect;
//   int16_t RangeRes:14;
//   int16_t rev:10;
//   int16_t Pitch:10;
//   int16_t Roll:10;
//   uint16_t nTarget:12;

//   uint8_t index;
// }mimo_360status;
// #pragma pack()
// extern mimo_360status mimo360_status;

// #pragma pack(1)
// typedef struct
// {
//   uint8_t sectId0;
//   uint8_t dis0;
//   int8_t rcs0;
//   int8_t el0;
// }mimo_360info;
// #pragma pack()
// extern mimo_360info mimo360_info[MIMO_360_TotalSect];

// #pragma pack(1)
// typedef struct
// {
//   uint16_t sec_angle;//当前目标角度 0-360
//   uint16_t distance;//当前目标距离 cm
//   uint8_t rcs0; //强度
//   int8_t el0; //当前俯仰角 -80-80
// }mimo_360_data;

// #pragma pack()

// #pragma pack(1)
// typedef struct
// {
//   uint8_t TotalSect;//分区数
//   uint8_t total_tar;//目标总数
//   mimo_360_data data[40];
// }mimo_360_cont;
// #pragma pack()
// extern mimo_360_cont fmu_360info;
// extern Connect_check mimo_360_info;
// extern char can_get_uavr21_ver_comp;
// extern uint8_t radar360_proflag;

void can_set_radar_sensi(void);
void can_recv_mocib_updata_read_set_hookfunction(uint32_t cellCanID, uint8_t data[]);
void can_recv_mocib_360_obstacle(uint32_t cellCanID, uint8_t data[], uint8_t len);
void lidar_function(void);
void can_recv_mocib_version_info(uint32_t cellCanID, uint8_t data[], uint8_t len);
void can_recv_enzhao_obstacle(uint32_t cellCanID, uint8_t data[], uint8_t len);
void send_mocib_radar_sensi(void);
void can_recv_mocib_F_obstacle(uint8_t *data);
void can_recv_mocib_B_obstacle(uint8_t *data);
void can_sendmsg_uavr20(void);
bool check_radar_update(void);
void can_recv_mocib_new360_obstacle(uint32_t cellCanID, uint8_t data[], uint8_t len);
void can_recv_mimo_signal_obstacle(uint32_t cellCanID, uint8_t data[], uint8_t len);
void can_recv_mimo_radar_version(uint32_t cellCanID, uint8_t data[], uint8_t len);
void mimomocib_buf_sort(mimo_part_radar *arr, uint16_t length);
void get_radar_blindAndPower_function( void );
void can_recv_mocib_obstacle(uint32_t cellCanID, uint8_t data[], uint8_t len);
#endif 

