TSMaster实现周期发送报文
1. 项目背景
针对已经实现了BMS应用层软件开发后进行调试,对上下电、充电、热管理、故障诊断、故障事件管理、采样以及SOC/SOH/SOP计算进行初步的功能测试,主要有三个控制器节点,分别是BMS、上位机Tester以及采样控制器BIU。三个节点都是通过CAN网络进行通讯,其中,采样控制器BIU会将电芯电压、模组温度、电流、继电器状态、采样线状态以及心跳信号周期发送给BMS,Tester主要将强闭继电器、清除故障、上高压、KL15以及SOC校正等指令发送给BMS,利用TSMaster模拟BIU和Tester进行信号仿真。
2. TSMaster基本应用
TSMaster是一款支持众多CAN卡的CAN总线软件工具,非常像Vector CANoe,能够实现CAN测量仿真、CCP/XCP标定、自动化、MATLAB联合SIL/HIL仿真测试等功能,其功能非常强大,以下是其一些基本教程。
- https://www.tosunai.com/
- https://github.com/TOSUN-Shanghai/TSMaster
- https://github.com/TOSUN-Shanghai/TSMaster/blob/main/TSMaster_features_cn.md
- https://space.bilibili.com/2042371333/channel/collectiondetail?sid=776383
- https://blog.csdn.net/TOSUN_CAN?type=blog
在该软件功能调试项目中,需要用到TSMaster的面板Panel功能、C代码小程序、CAN发送等功能,其中,利用Panel搭建出BMS的信号采样界面、故障信息界面、Tester强控指令界面、采样有效性校验界面,利用C代码小程序实现Tester以及BIU信号的周期发送,如下所示。
3. 实现周期发送特定报文
3.1 功能需求
由于需要Tester周期发送上高压、KL15、清除故障等指令,不想通过TSMaster简单的CANTX模块实现,需要实现更为复杂的逻辑,所以将其做在C程序中,通过在C程序中定义内部系统变量,关联到Panel的控件,实现Tester周期发送BMS进行上下电指令。
3.2 功能实现
- 系统变量:在C程序中定义所需的系统变量;
- Panel设置:将相关的控件拖入到Panel中后,对控件进行信号关联,基本上关联CAN信号和系统变量即可;
- C程序脚本设计:周期发送Tester信号、周期发送BIU AliveCount,程序启动,生命信号自增,加到255后清零,继续自增,模拟BIU AliveCount;
Step1:全局定义
TTester_CtrlBMSCmd_1 Tester_CtrlBMSCmd_1;
TBIU_Sts_1 BIU_Sts_1;
Step2: 报文初始化
Tester_CtrlBMSCmd_1.init();
BIU_Sts_1.init();
Step3: 定义50ms定时器 TesterTimer50ms
TMPTimerMS TesterTimer50ms_1;
Step4: 在定时器触发事件中,设置报文的周期发送
// Set Tester PowerOn Signal
Tester_CtrlBMSCmd_1.BMS_PowerOnReqEn_flg = PowerOnEnSysVal.get();
Tester_CtrlBMSCmd_1.BMS_PowerOnReq_flg = PowerOnReqSysVal.get();
// Set Tester KL15On Signal
//Tester_CtrlBMSCmd_1.BMS_KL15En_flg = KeyOnEnSysVal.get();
//Tester_CtrlBMSCmd_1.BMS_KL15_flg = KeyOnReqSysVal.get();
Tester_CtrlBMSCmd_1.BMS_KL15En_flg = KL15OnEn.get();
Tester_CtrlBMSCmd_1.BMS_KL15_flg = KL15OnReq.get();
// Set Tester RelayClose Signal
Tester_CtrlBMSCmd_1.BMS_Relay01CloseReqEn_flg = MainPosClEn.get();
Tester_CtrlBMSCmd_1.BMS_Relay01CloseReq_flg =MainPosClCmd.get();
Tester_CtrlBMSCmd_1.BMS_Relay02CloseReqEn_flg = PrechgClEn.get();
Tester_CtrlBMSCmd_1.BMS_Relay02CloseReq_flg = PrechgClCmd.get();
Tester_CtrlBMSCmd_1.BMS_Relay03CloseReqEn_flg = ChrgPosClEn.get();
Tester_CtrlBMSCmd_1.BMS_Relay03CloseReq_flg = ChrgPosClCmd.get();
Tester_CtrlBMSCmd_1.BMS_Relay04CloseReqEn_flg = HeatClEn.get();
Tester_CtrlBMSCmd_1.BMS_Relay04CloseReq_flg = HeatClCmd.get();
Tester_CtrlBMSCmd_1.BMS_Relay05CloseReqEn_flg = CoolClEn.get();
Tester_CtrlBMSCmd_1.BMS_Relay05CloseReq_flg = CoolClCmd.get();
Tester_CtrlBMSCmd_1.BMS_Relay06CloseReqEn_flg = ChrgNegClEn.get();
Tester_CtrlBMSCmd_1.BMS_Relay06CloseReq_flg = ChrgNegClCmd.get();
// Set Tester ClearCommand Signal
Tester_CtrlBMSCmd_1.BMS_CurrentFaultResetCmd_flg = ResetCurrFltCmd.get();
Tester_CtrlBMSCmd_1.BMS_HistoryFaultResetCmd_flg = ClearHisFltCmd.get();
Tester_CtrlBMSCmd_1.BMS_ClearEEPROMCmd_flg = ResetEEPOMCmd.get();
// Set Tester FunSet Signal
Tester_CtrlBMSCmd_1.BMS_ReadSnapShotCmd_flg = ReadSnpShotCmd.get();
Tester_CtrlBMSCmd_1.BMS_BattBalanceFunReq_flg = BattBalReqCmd.get();
Tester_CtrlBMSCmd_1.BMS_InsulationDetFunReq_flg = InsultDetReqCmd.get();
Tester_CtrlBMSCmd_1.BMS_BattSOCCorrectReq_flg = BattSOCCorrectCmd.get();
Tester_CtrlBMSCmd_1.BMS_BatteySOCCorrectValue_pct = BatterySOCSetVal.get();
// Set BIU AliveCount Signal(up to 255 and reset to 0)
u8 n;
n=temp.get();
n=n+1;
temp.set(n);
BIU_Sts_1.BMS_LiveCnt_cnt = n;
BIU_Sts_1.BMS_BatCur1_A = BatCurrent.get();
// Send the Tester_CtrlBMSCmd Message
com.transmit_can_async(&Tester_CtrlBMSCmd_1.FCAN);
// Send the BIU_Sts_1 Message
com.transmit_can_async(&BIU_Sts_1.FCAN);
3.3 功能测试
将设计好的C程序编译通过后,为了后续测试不用时不时的运行该C程序,打开自动启动功能,运行TSMaster仿真测量即可进行功能测试。
4. 总结
- 查询TSMaster Help文档,掌握基本的应用
- 规范化运用C小程序模块