BMS查询改成远程帧
This commit is contained in:
parent
15b9046d8b
commit
e6f549cc2a
@ -1,10 +1,12 @@
|
|||||||
#ifndef CAN_STRUCT_H
|
#ifndef CAN_STRUCT_H
|
||||||
#define CAN_STRUCT_H
|
#define CAN_STRUCT_H
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <array>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "can_driver.h"
|
#include "can_driver.h"
|
||||||
|
|
||||||
#pragma pack(push, 1) // 禁止结构体补齐,确保8字节紧密排列
|
#pragma pack(push, 1) // 禁止结构体补齐,确保8字节紧密排列
|
||||||
@ -14,17 +16,14 @@ struct can_BMS_query_0x100
|
|||||||
// 报文ID与控制标志定义
|
// 报文ID与控制标志定义
|
||||||
static constexpr uint32_t CMD_ID = 0x100; // 标准帧ID
|
static constexpr uint32_t CMD_ID = 0x100; // 标准帧ID
|
||||||
static constexpr bool EXT_FLAG = false; // 11位标准帧
|
static constexpr bool EXT_FLAG = false; // 11位标准帧
|
||||||
static constexpr bool RTR_FLAG = false; // 普通数据帧(非远程帧)
|
static constexpr bool RTR_FLAG = true; // 普通数据帧(非远程帧)
|
||||||
static constexpr uint8_t DLC = 8; // 数据长度为8字节
|
static constexpr uint8_t DLC = 8; // 数据长度为8字节
|
||||||
|
|
||||||
// 数据区(主机查询时通常发送全0)
|
// 数据区(主机查询时通常发送全0)
|
||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
|
|
||||||
// 构造函数:初始化数据为0
|
// 构造函数:初始化数据为0
|
||||||
can_BMS_query_0x100()
|
can_BMS_query_0x100() { memset(data, 0, sizeof(data)); }
|
||||||
{
|
|
||||||
memset(data, 0, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 生成CAN帧
|
// 生成CAN帧
|
||||||
CANFrame toFrame() const
|
CANFrame toFrame() const
|
||||||
@ -44,17 +43,14 @@ struct can_BMS_query_0x101
|
|||||||
// 报文ID与控制标志定义
|
// 报文ID与控制标志定义
|
||||||
static constexpr uint32_t CMD_ID = 0x101; // 标准帧ID
|
static constexpr uint32_t CMD_ID = 0x101; // 标准帧ID
|
||||||
static constexpr bool EXT_FLAG = false; // 11位标准帧
|
static constexpr bool EXT_FLAG = false; // 11位标准帧
|
||||||
static constexpr bool RTR_FLAG = false; // 普通数据帧(非远程帧)
|
static constexpr bool RTR_FLAG = true; // 普通数据帧(非远程帧)
|
||||||
static constexpr uint8_t DLC = 8; // 数据长度为8字节
|
static constexpr uint8_t DLC = 8; // 数据长度为8字节
|
||||||
|
|
||||||
// 数据区(主机查询时通常发送全0)
|
// 数据区(主机查询时通常发送全0)
|
||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
|
|
||||||
// 构造函数:初始化数据为0
|
// 构造函数:初始化数据为0
|
||||||
can_BMS_query_0x101()
|
can_BMS_query_0x101() { memset(data, 0, sizeof(data)); }
|
||||||
{
|
|
||||||
memset(data, 0, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 生成CAN帧
|
// 生成CAN帧
|
||||||
CANFrame toFrame() const
|
CANFrame toFrame() const
|
||||||
@ -140,10 +136,7 @@ struct can_MCU_cmd
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置使能状态
|
// 设置使能状态
|
||||||
void setEnabled(bool en)
|
void setEnabled(bool en) { data.fields.can_enabled = en ? 1 : 0; }
|
||||||
{
|
|
||||||
data.fields.can_enabled = en ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置档位 (0空挡,1后退,2前进,3保留)
|
// 设置档位 (0空挡,1后退,2前进,3保留)
|
||||||
void setGear(uint8_t gear)
|
void setGear(uint8_t gear)
|
||||||
@ -152,10 +145,7 @@ struct can_MCU_cmd
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置刹车状态
|
// 设置刹车状态
|
||||||
void setBrake(bool brake_on)
|
void setBrake(bool brake_on) { data.fields.switch_status.brake = brake_on ? 1 : 0; }
|
||||||
{
|
|
||||||
data.fields.switch_status.brake = brake_on ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置转速 (0-6000rpm)
|
// 设置转速 (0-6000rpm)
|
||||||
void setRPM(uint16_t rpm)
|
void setRPM(uint16_t rpm)
|
||||||
@ -208,10 +198,7 @@ struct can_EPS_cmd
|
|||||||
data.fields.angle_l = raw & 0xFF;
|
data.fields.angle_l = raw & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCenterCmd(uint8_t cmd)
|
void setCenterCmd(uint8_t cmd) { data.fields.center_cmd = cmd; }
|
||||||
{
|
|
||||||
data.fields.center_cmd = cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAngularSpeed(uint16_t angle_speed)
|
void setAngularSpeed(uint16_t angle_speed)
|
||||||
{
|
{
|
||||||
@ -285,52 +272,28 @@ struct can_VCU_motor1_cmd
|
|||||||
int8_t data[8]{};
|
int8_t data[8]{};
|
||||||
|
|
||||||
// 设置Byte0
|
// 设置Byte0
|
||||||
void setByte0(int8_t direction)
|
void setByte0(int8_t direction) { data[0] = std::clamp(direction, static_cast<int8_t>(0), static_cast<int8_t>(2)); }
|
||||||
{
|
|
||||||
data[0] = std::clamp(direction, static_cast<int8_t>(0), static_cast<int8_t>(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte1
|
// 设置Byte1
|
||||||
void setByte1(int8_t value)
|
void setByte1(int8_t value) { data[1] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[1] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte2
|
// 设置Byte2
|
||||||
void setByte2(int8_t value)
|
void setByte2(int8_t value) { data[2] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[2] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte3
|
// 设置Byte3
|
||||||
void setByte3(int8_t value)
|
void setByte3(int8_t value) { data[3] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[3] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte4
|
// 设置Byte4
|
||||||
void setByte4(int8_t value)
|
void setByte4(int8_t value) { data[4] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[4] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte5
|
// 设置Byte5
|
||||||
void setByte5(int8_t value)
|
void setByte5(int8_t value) { data[5] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[5] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte6
|
// 设置Byte6
|
||||||
void setByte6(int8_t value)
|
void setByte6(int8_t value) { data[6] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[6] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte7
|
// 设置Byte7
|
||||||
void setByte7(int8_t value)
|
void setByte7(int8_t value) { data[7] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[7] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
CANFrame toFrame() const
|
CANFrame toFrame() const
|
||||||
{
|
{
|
||||||
@ -354,52 +317,28 @@ struct can_VCU_motor2_cmd
|
|||||||
int8_t data[8]{};
|
int8_t data[8]{};
|
||||||
|
|
||||||
// 设置Byte0
|
// 设置Byte0
|
||||||
void setByte0(int8_t value)
|
void setByte0(int8_t value) { data[0] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[0] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte1
|
// 设置Byte1
|
||||||
void setByte1(int8_t value)
|
void setByte1(int8_t value) { data[1] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[1] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte2
|
// 设置Byte2
|
||||||
void setByte2(int8_t value)
|
void setByte2(int8_t value) { data[2] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[2] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte3
|
// 设置Byte3
|
||||||
void setByte3(int8_t value)
|
void setByte3(int8_t value) { data[3] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[3] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte4
|
// 设置Byte4
|
||||||
void setByte4(int8_t value)
|
void setByte4(int8_t value) { data[4] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[4] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte5
|
// 设置Byte5
|
||||||
void setByte5(int8_t value)
|
void setByte5(int8_t value) { data[5] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[5] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte6
|
// 设置Byte6
|
||||||
void setByte6(int8_t value)
|
void setByte6(int8_t value) { data[6] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[6] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置Byte7
|
// 设置Byte7
|
||||||
void setByte7(int8_t value)
|
void setByte7(int8_t value) { data[7] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100)); }
|
||||||
{
|
|
||||||
data[7] = std::clamp(value, static_cast<int8_t>(-100), static_cast<int8_t>(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
CANFrame toFrame() const
|
CANFrame toFrame() const
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user