#ifndef _SOFT_SEED_DEVICE_H_
#define _SOFT_SEED_DEVICE_H_
#include "common.h"
#include "soft_eft.h"

void Weight_recieved_hookfuction(uint32_t CanID, uint8_t data[], uint8_t len);
void update_device_type_data(void);

#define WEIGHT_DEVICE 1
#define SEED_DEVICE 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 verison:1;
    uint8_t reserve:3;
};

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;


#pragma pack(1)
typedef struct
{
    uint8_t sensor_status; // 工作状态
    uint8_t warn_status;   // 报警状态
    uint16_t weight_rate;  // 重量变化率
    int weight;            // 重量
    int serial_num;        // 厂家编号
    uint16_t senor_k[4];   // 称重传感器K值
    uint8_t mode;          // 称重模式 1播撒 2喷洒
    uint16_t dose_rate;    // 最高下药率 kg/min
    uint16_t Single_sensor[4];
} weight;
#pragma pack()
extern weight weight_vkinfo;

#pragma pack(1)
typedef struct
{
    uint8_t work_status; // 工作状态
    uint8_t warn_status; // 报警状态
    uint8_t output;      // 输出信号源
    uint16_t can_rate;   // CAN波特率
    uint8_t reserve;     // 保留
    uint8_t warn_switch; // 报警开关
    uint8_t recv_conut;  // 计数
    int serial_num;      // 厂家编号
} seed;
#pragma pack()
extern seed seed_vkinfo;

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,//电目断料计

};
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;
} Seed_info;
#pragma pack(0)

#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 run_time;
    uint16_t single_sensor[4];
} Weight_info;
#pragma pack(0)

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

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint16_t rpm1;
    uint16_t rpm2;
    uint16_t rpm3;
    uint16_t rpm4;
    uint16_t warn;
} Nozzle_info;
#pragma pack(0)

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

#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(0)

#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(0)

#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(0)

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

#pragma pack(1)
typedef struct
{
    uint8_t facid;
    uint16_t tempture;
    uint16_t voltage;
    uint16_t current;
} Current_info;
#pragma pack(0)

#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_part1;
    uint16_t height_part2;
    uint16_t height_part3;
} Part_Tradar;
#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()

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;

    Current_info Current;
    Connect_check Current_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_Fradar Part_radarF;
    Connect_check Part_Fradar_Link;

    _Temp_sensor Temp_sensor;
    Connect_check Temp_Sensor_Link;
		
    Connect_check Part_Bradar_Link;
} Device_type;
extern Device_type Dev;

#pragma pack(1)
typedef struct
{
    uint8_t type;
    uint16_t order_con1;
    uint16_t order_con2;
    uint16_t order_con3;
} Weight_cal;
#pragma pack(0)
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
};

void can_sendmsg_VK(void);
void seed_init_send_info(uint8_t device_type, char *factory);
void Set_Seed_Weight_Par(uint8_t device_type, char *factory);
void DM_obs_test( void );

#endif
