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


#define WEIGHT_DEVICE 1
#define SEED_DEVICE 2

#define NEED_SET 1
#define NO_NEED_SET 2

struct weight_init_step
{
    uint8_t read_k_flag:1;
    uint8_t fac_num_flag:1;
    uint8_t weight_mode_flag:1;
    uint8_t dose_rate_flag:1;
    uint8_t reserve:4;
};

typedef union 
{
    uint8_t status;
    struct weight_init_step step;
}Dev_weight_init;
extern Dev_weight_init weight_init_eft;
extern Dev_weight_init weight_init_vk;
struct seed_init_step
{
    uint8_t version_flag:1;
    uint8_t sn_flag:1;
    uint8_t set_mode_flag:1;
    uint8_t reserve:4;
};

typedef union 
{
    uint8_t status;
    struct seed_init_step step;
}Dev_seed_init;
extern Dev_seed_init seed_init;


enum FACID
{
    FAC_VK = 0,        // 默认VK
    FAC_EFT = 1,       // EFT
    FAC_LIFTWEIGHT = 2, //吊运称重
    FAC_QIFEI = 3,     // 启飞播撒
    FAC_VK_ALLINONE = 4,  //VK一体化
    FAC_MIMO_SIG = 5,  // 恩曌单管
    FAC_MIMO_DOU = 6,  // 恩曌双管
    FAC_QIFEI_SIG = 7, // 启飞单管流量计
    FAC_QIFEI_DOU = 8, // 启飞双管流量计
    FAC_LPUMP = 9, //线性水泵

    FAC_VK_BMS = 10,   // vk电池
    FAC_TATTU = 11,    // 格式电池
    FAC_POWERAMP = 12, // 极目电池
    FAC_FULLY = 13,    // 富赖电池
    FAC_HEREWIN = 14,  // 海盈电池
    FAC_OKCELL = 15,   // 正方电池

    FAC_HW_ESC = 16,   // 好盈水泵电调

    FAC_MIMO_RT = 20,  //恩曌防地
    FAC_MIMO_RF = 21,  //恩曌前避障
    FAC_MIMO_RB = 22, //恩曌后避障

    FAC_MOCIB_RT = 23,  //莫之比防地
    FAC_MOCIB_RF = 24,  //莫之比前避障
    FAC_MOCIB_RB = 25, //莫之比后避障

    FAC_DM_RT = 26,  //DM防地
    FAC_DM_RF = 27,  //DM前避障
    FAC_DM_RB = 28, //DM后避障

    FAC_QX_BMS = 30,  //协氢电池
    FAC_DM_CHECKLOW = 31,//电目断料计

    FAC_DM_RT_4D = 36,  //DM 4d防地
    FAC_DM_RF_4D = 37,  //DM 4d前避障
    FAC_DM_RB_4D = 38, //DM  4d后避障

    FAC_CHURN_SEED = 40, //绞龙播撒

};
typedef struct
{
    uint8_t cap_low; // 断药
    uint32_t weight;
    comp_status low_drug_link;
    comp_status weight_link;
    comp_status spreader_link;
    uint8_t company_type_seed;
    uint8_t company_type_weight;
    uint16_t sensor_k[4];
    uint16_t dose_rate;
    uint8_t mode;
    uint16_t warn_flag;
    uint16_t weight_rate;
    uint16_t valve_persent;
    uint16_t speed_rpm;
    uint16_t pump1_rpm;
    uint16_t pump2_rpm;
    uint16_t cent1_rpm;
    uint16_t cent2_rpm;
    uint16_t watering_warn;
} send_seed_device;
extern send_seed_device seed_dev;

extern comp_status seed_dev_link_status;
extern bool recv_fmu_seed_info;
extern uint8_t weight_init_count;
// typedef struct
// {

// } QIFEI_device;
// extern QIFEI_device QIFEI_info;


#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint8_t angle;
    uint16_t speed;
    uint8_t caplow;
    uint16_t warn;
    uint16_t runtime;
    uint16_t churn_rpm;
    uint16_t churn_warn;
} Seed_info;
#pragma pack()

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint8_t mode;
    uint16_t kg;
    uint16_t rate;
    uint16_t k1;
    uint16_t k2;
    uint16_t k3;
    uint16_t k4;
    uint16_t warn;
    uint16_t dose_rate;
    uint16_t runtime;
} Weight_info;
#pragma pack()

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint16_t rpm1;
    uint16_t rpm2;
    uint16_t rpm3;
    uint16_t rpm4;
    uint16_t warn;
    uint16_t runtime1;
    uint16_t runtime2;  
    uint16_t runtime3;
    uint16_t runtime4;
} Pump_info;
#pragma pack()

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    short rpm1;
    short rpm2;
    short rpm3;
    short rpm4;
    uint16_t warn;
    uint16_t runtime1; //转成10MIN
    uint16_t runtime2;  
    uint16_t runtime3;
    uint16_t runtime4;
} Nozzle_info;
#pragma pack()

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint16_t status;
} Arm_info;
#pragma pack()

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint16_t speed1;
    uint16_t speed2;
    uint32_t ml1;
    uint32_t ml2;
    uint16_t warn1;
    uint16_t warn2;
    uint16_t k1;
    uint16_t k2;
} Flow_info;
#pragma pack()

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint16_t L1_status;
    uint16_t L2_status;
    uint16_t liquid_persent;
    uint16_t seed_lackloss;
    uint16_t warn;
    uint16_t lack_distance;
    uint16_t lack_power;
} CheckLow_info;
#pragma pack()


#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint16_t Battery_positive_temperature;
    uint16_t Battery_negative_temperature;
} Temperature_Sensor_info;
#pragma pack()
#pragma pack(1)
typedef struct
{
    uint8_t facid;
    int16_t X1;
    int16_t Y1;
    int16_t Z1;
    int16_t X2;
    int16_t Y2;
    int16_t Z2;
    int16_t X3;
    int16_t Y3;
    int16_t Z3;
} Part_Fradar;
#pragma pack()
#pragma pack(1)
typedef struct
{
    uint8_t facid_T;
    short height_T;
    short warn_T;

    uint8_t facid_F;
    short distance_F_Y;
    short distance_F_X;
    uint16_t warn_F;
    uint16_t signal_F_qulity;
    short distance_F_Y_ori;

    uint8_t facid_B;
    short distance_B_Y;
    short distance_B_X;
    uint16_t warn_B;
    uint16_t signal_B_qulity;
    short distance_B_Y_ori;
} Radar_info;
#pragma pack()

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint8_t buf[230];
    uint8_t index;
} Bms_info;
#pragma pack()

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint16_t warn;
    uint16_t rpm;
} Linear_pump_info;
#pragma pack()

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint16_t height_part[5];
    uint16_t raw_height_part[5];
    short angle_part[5];
} Part_Tradar;

typedef struct
{
    uint8_t facid;
    uint16_t height_part[3];
    uint16_t raw_height_part[3];
    short angle_Horpart[3];
    short angle_Velpart[3];
} Part_FBradar;

#pragma pack()
typedef struct
{
    Seed_info Seed;
    Connect_check Seed_Link;

    Weight_info Weight;
    Connect_check Weight_Link;

    Pump_info Pump;
    Connect_check Pump_Link;

    Nozzle_info Nozzle;
    Connect_check Nozzle_Link;

    Arm_info Arm;
    Connect_check Arm_Link;

    Flow_info Flow;
    Connect_check Flow_Link1;
    Connect_check Flow_Link2;

    CheckLow_info Checklow;
    Connect_check Checklow_Link;

    Radar_info Radar;
    Connect_check Radar_Link;

    Bms_info Bms;
    Connect_check Bms_Link;

    Connect_check Lackloss_Link;

    Linear_pump_info L_pump1;
    Connect_check L_pump1_Link;

    Linear_pump_info L_pump2;
    Connect_check L_pump2_Link;

    Part_Tradar Part_radarT;
    Connect_check Part_Tradar_Link;

    Part_FBradar Part_radarF;
    Connect_check Part_Fradar_Link;
    
    Part_FBradar Part_radarB;
    Connect_check Part_Bradar_Link;

    Connect_check DM_Part_Bradar_Link;
    Part_Fradar DM_Part_radarB;	
    
    Connect_check DM_Part_Fradar_Link;
    Part_Fradar DM_Part_radarF;

    Connect_check Eft_CanDev_Link[6]; //柔性双水泵 四离心  获取版本信息使用

    Temperature_Sensor_info Temperature_Sensor;
    Connect_check Temperature_Sensor_Link;
} Device_type;
extern Device_type Dev;

#pragma pack(1)
typedef struct
{
    uint8_t type;
    uint16_t order_con1;
    uint16_t order_con2;
} Weight_cal;
#pragma pack()
extern Weight_cal weight_order;

enum CalEnum
{
    Default_PAR = 0,
    Weight_Peer = 1,
    Weight_Kg = 2,
    Weight_Reserve = 3,
    Weight_Bcak = 4,
    Weight_Set_K = 5,
    Weight_Mode = 6,
    Weight_Drug_Rate = 7
};
extern bool set_eftdev_canid_flag;
extern uint32_t set_eftdev_canid_time;
extern uint16_t set_eftdev_canid_status;
extern uint8_t auto_set_canid_flag;
extern uint32_t auto_eft_dev_status;
void update_device_type_data(void);
void set_eft_dev_canid_func( void );
void DM_obs_test( void );
#endif
