144 lines
6.0 KiB
C
144 lines
6.0 KiB
C
#ifndef __CONTROL_OUT_H__
|
||
#define __CONTROL_OUT_H__
|
||
#include "cm_os.h"
|
||
#include "cm_gpio.h"
|
||
#include "jt808_set_TermParam.h"
|
||
|
||
|
||
#define BAT_SxP1 4 // 电池四串一并
|
||
#define BAT_VOLT(_Volt) (_Volt * BAT_SxP1) //电压单位转换
|
||
#define BAT_Low_VOLT BAT_VOLT(105) //10.5V x 4 = 42V
|
||
#define BAT_Full_VOLT BAT_VOLT(144) //14.4V x 4 = 57.6V
|
||
|
||
// #define BAT_LEVEL_0PERCENT_VOLT BAT_VOLT(105) // 0%:(105~110]=(42.0V~44.0V]
|
||
// #define BAT_LEVEL_10PERCENT_VOLT BAT_VOLT(113) // 10%:(110~113]=(44.0V~45.2V]
|
||
// #define BAT_LEVEL_20PERCENT_VOLT BAT_VOLT(116) // 20%:(113~116]=(45.2V~46.4V]
|
||
// #define BAT_LEVEL_30PERCENT_VOLT BAT_VOLT(119) // 30%:(116~119]=(46.4V~47.6V]
|
||
// #define BAT_LEVEL_40PERCENT_VOLT BAT_VOLT(122) // 40%:(119~122]=(47.6V~48.8V]
|
||
// #define BAT_LEVEL_50PERCENT_VOLT BAT_VOLT(125) // 50%:(122~125]=(48.8V~50.0V]
|
||
// #define BAT_LEVEL_60PERCENT_VOLT BAT_VOLT(128) // 60%:(125~128]=(50.0V~51.2V]
|
||
// #define BAT_LEVEL_70PERCENT_VOLT BAT_VOLT(131) // 70%:(128~131]=(51.2V~52.4V]
|
||
// #define BAT_LEVEL_80PERCENT_VOLT BAT_VOLT(134) // 80%:(131~134]=(52.4V~53.6V]
|
||
// #define BAT_LEVEL_90PERCENT_VOLT BAT_VOLT(137) // 90%:(134~137]=(53.6V~54.8V]
|
||
// #define BAT_LEVEL_100PERCENT_VOLT BAT_VOLT(144) //100%:(137~144]=(54.8V~57.6V]
|
||
|
||
// 内阻 20mΩ * 4 =80mΩ // 线损 10A 0.1V
|
||
|
||
#define BAT_LEVEL_0PERCENT_VOLT BAT_VOLT(105) // 0%
|
||
#define BAT_LEVEL_10PERCENT_VOLT BAT_VOLT(107) // 10%
|
||
#define BAT_LEVEL_20PERCENT_VOLT BAT_VOLT(109) // 20%
|
||
#define BAT_LEVEL_30PERCENT_VOLT BAT_VOLT(111) // 30%
|
||
#define BAT_LEVEL_40PERCENT_VOLT BAT_VOLT(113) // 40%
|
||
#define BAT_LEVEL_50PERCENT_VOLT BAT_VOLT(115) // 50%
|
||
#define BAT_LEVEL_60PERCENT_VOLT BAT_VOLT(117) // 60%
|
||
#define BAT_LEVEL_70PERCENT_VOLT BAT_VOLT(119) // 70%
|
||
#define BAT_LEVEL_80PERCENT_VOLT BAT_VOLT(123) // 80%
|
||
#define BAT_LEVEL_90PERCENT_VOLT BAT_VOLT(127) // 90%
|
||
#define BAT_LEVEL_100PERCENT_VOLT BAT_VOLT(134) //100%
|
||
|
||
|
||
// 充电状态
|
||
typedef enum {
|
||
Bat_Low_STA=(1<<0),
|
||
Bat_30_STA=(1<<1),
|
||
Bat_60_STA=(1<<2),
|
||
Bat_80_STA=(1<<3),
|
||
Bat_100_STA=(1<<4),
|
||
Bat_NotCharge_STA=(1<<5),
|
||
Bat_Charge_STA=(1<<6),
|
||
} BAT_STA_t;
|
||
|
||
|
||
typedef struct BAT_Message{
|
||
uint8_t Bat_STA;
|
||
uint8_t Bat_Percent; // 42=42%
|
||
uint8_t Bat_Low_Volt_count; // 低压计数
|
||
uint16_t Bat_Voltage; // 480=48.0V
|
||
uint16_t Rsp_BigBat_Voltage;
|
||
uint16_t Runing_Time; // 系统运行时间
|
||
uint16_t Deep_ACC_Time; // 深踩油门时间
|
||
} BAT_Message_t;
|
||
|
||
#if 1
|
||
#define ACC_RES_UP 10000
|
||
#define ACC_RES_DOWN 3300
|
||
|
||
#define VIN_RES_UP 240000
|
||
#define VIN_RES_DOWN 3300
|
||
#else
|
||
#define ACC_RES_UP 47000
|
||
#define ACC_RES_DOWN 20000
|
||
|
||
#define VIN_RES_UP 94000
|
||
#define VIN_RES_DOWN 3300
|
||
#endif
|
||
|
||
// ACC 输出设置
|
||
#define ACC_OUT_RES_UP 5100
|
||
#define ACC_OUT_RES_DOWN 3300
|
||
#define ACC_OUT_PERIOD_US 1000000
|
||
#define ACC_OUT_Voltage_MAX 3820
|
||
#define ACC_OUT_Voltage_MIN 880
|
||
|
||
// #define ACC_Dmin (((880*ACC_OUT_RES_DOWN)/(ACC_OUT_RES_UP+ACC_OUT_RES_DOWN))*(ACC_OUT_PERIOD_US/(1800)))
|
||
// #define ACC_Dmax (((3820*ACC_OUT_RES_DOWN)/(ACC_OUT_RES_UP+ACC_OUT_RES_DOWN))*(ACC_OUT_PERIOD_US/(1800)))
|
||
|
||
typedef enum{
|
||
OUT_Door_lock = CM_GPIO_NUM_21, // 门锁
|
||
IO_MANAGER_MODE = CM_GPIO_NUM_12, // 管理模式
|
||
IO_RX_BACK = CM_GPIO_NUM_3, // 倒车
|
||
IO_TX_BRAKE = CM_GPIO_NUM_4, // 刹车
|
||
}control_io_t;
|
||
|
||
// typedef struct{
|
||
// union{
|
||
// uint16_t VERSION; // 软件版本号
|
||
// struct{
|
||
// uint16_t SW_version:11; // 软件版本序号
|
||
// uint16_t HW_version:4; // 硬件版本序号
|
||
// uint16_t VER_type:1; // 当前固件类型0:0x04000;1:0x20000
|
||
// };
|
||
// };
|
||
// uint8_t Modbus_addr; // MODBUS地址
|
||
// uint8_t Manager_sLim; // 管理员模式油门极限(Unit:%)
|
||
// uint8_t Tourist_sLim; // 游客模式油门极限
|
||
// uint8_t Speed_Cut_sLim; // 减速油门极限(Unit:%)(自动减速时油门极限)
|
||
// uint16_t Brake_DLimit; // 刹车距离极限(前进)(Unit:mm)
|
||
// uint16_t Speed_Cut_DLimit; // 减速距离极限
|
||
// uint16_t Brake_DLimit_B; // 刹车距离极限(后退)
|
||
// uint16_t Speed_Cut_DLimit_B;// 减速距离极限
|
||
// uint16_t CRC16; // 配置信息CRC16校验码
|
||
// }SYS_CONF_t;
|
||
|
||
// extern SYS_CONF_t sys_conf;
|
||
|
||
#define SYS_CONF_MANAGER_ACC jt808_term_param_item.set_term_param.ManagerACC // 管理员模式油门极限(Unit:%)
|
||
#define SYS_CONF_TOURIST_ACC jt808_term_param_item.set_term_param.TouristACC // 游客模式油门极限
|
||
#define SYS_CONF_SPEED_CUT_ACC jt808_term_param_item.set_term_param.SpeedCutACC // 减速油门极限(Unit:%)(自动减速时油门极限)
|
||
#define SYS_CONF_BRAKE_LIMIT jt808_term_param_item.set_term_param.BrakeLimit // 刹车距离极限(前进)(Unit:mm)
|
||
#define SYS_CONF_SPEED_CUT_LIMIT jt808_term_param_item.set_term_param.SpeedCutLimit // 减速距离极限
|
||
#define SYS_CONF_BRAKE_LIMIT_B jt808_term_param_item.set_term_param.BrakeLimit_B // 刹车距离极限(后退)
|
||
#define SYS_CONF_SPEED_CUT_LIMIT_B jt808_term_param_item.set_term_param.SpeedCutLimit_B // 减速距离极限
|
||
|
||
typedef struct{
|
||
union{// 输入输出状态
|
||
struct{
|
||
uint8_t O_door_lock :1; // 1:电门锁打开,0:电门锁关闭
|
||
uint8_t MAG_MODE :1; // 1:游客模式,0:管理模式
|
||
uint8_t PLT_MODE :1; // 1:游客模式,0:管理模式
|
||
uint8_t IO_RX_back :1; // 1:正常 0:倒车
|
||
uint8_t IO_TX_brake :1; // 1:正常 0:刹车
|
||
uint8_t A_brake :1; // 1:自动刹车,0:手动刹车
|
||
uint8_t A_Speed_Cut :1; // 1:自动减速,0:手动减速
|
||
uint8_t P_Radar_EN :2; // 2:雷达暂时关闭,1:雷达使能,0:雷达禁止
|
||
};
|
||
uint8_t IO_STA;
|
||
};
|
||
} sys_sta_t;
|
||
|
||
extern sys_sta_t sys_sta;
|
||
extern BAT_Message_t BAT_Message;
|
||
|
||
void control_out_init(void);
|
||
|
||
#endif //__CONTROL_OUT_H__
|