添加函数注释

This commit is contained in:
CSSC-WORK\murmur 2024-12-13 16:31:59 +08:00
parent 2b0a184d40
commit 33c8967a37

View File

@ -56,6 +56,13 @@ static const uint16_t crcTable[] = {
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
}; };
/**
* CRC16校验值
*
* @param data CRC的数据缓冲区
* @param length
* @return CRC16校验值
*/
uint16_t CalculateCRC16(uint8_t *data, uint16_t length) { uint16_t CalculateCRC16(uint8_t *data, uint16_t length) {
uint16_t crc = 0xFFFF; uint16_t crc = 0xFFFF;
@ -67,11 +74,21 @@ uint16_t CalculateCRC16(uint8_t *data, uint16_t length) {
return crc; return crc;
} }
// 更新下挂设备状态 /**
*
*
* @param status (线/线)
*/
void updateDeviceStatus(DeviceStatus_t status) { void updateDeviceStatus(DeviceStatus_t status) {
deviceStatus.deviceStatus = status; deviceStatus.deviceStatus = status;
} }
// 更新三通阀状态
/**
*
*
* @param index (12)
* @param angle (120°210°)
*/
void updateValveStatus(uint8_t index, ValveAngle_t angle) { void updateValveStatus(uint8_t index, ValveAngle_t angle) {
if (index == 1) { if (index == 1) {
deviceStatus.valves.angle1 = angle; deviceStatus.valves.angle1 = angle;
@ -80,7 +97,12 @@ void updateValveStatus(uint8_t index, ValveAngle_t angle) {
} }
} }
// 更新泵状态 /**
*
*
* @param index (12)
* @param status (//)
*/
void updatePumpStatus(uint8_t index, PumpStatus_t status) { void updatePumpStatus(uint8_t index, PumpStatus_t status) {
if (index == 1) { if (index == 1) {
deviceStatus.pumps.status1 = status; deviceStatus.pumps.status1 = status;
@ -89,7 +111,12 @@ void updatePumpStatus(uint8_t index, PumpStatus_t status) {
} }
} }
// 更新泵速度状态 /**
*
*
* @param index (12)
* @param speed (0-100%)
*/
void updatePumpSpeedStatus(uint8_t index, uint8_t speed) { void updatePumpSpeedStatus(uint8_t index, uint8_t speed) {
if (index == 1) { if (index == 1) {
deviceStatus.pumps.speed1 = speed; deviceStatus.pumps.speed1 = speed;
@ -98,21 +125,38 @@ void updatePumpSpeedStatus(uint8_t index, uint8_t speed) {
} }
} }
// 更新气泡传感器读数 /**
*
*
* @param value (/)
*/
void updateBubbleSensor(BubbleStatus_t value) { void updateBubbleSensor(BubbleStatus_t value) {
deviceStatus.bubbleStatus = value; deviceStatus.bubbleStatus = value;
} }
// 更新急停状态 /**
*
*
* @param status (/)
*/
void updateEmergencyStop(EstopStatus_t status) { void updateEmergencyStop(EstopStatus_t status) {
deviceStatus.stopStatus = status; deviceStatus.stopStatus = status;
} }
// 更新错误码
/**
*
*
* @param errorCode
*/
void updateErrorCode(ErrorCode_t errorCode) { void updateErrorCode(ErrorCode_t errorCode) {
deviceStatus.errorCode = errorCode; deviceStatus.errorCode = errorCode;
} }
// 更新初始化状态 /**
*
*
* @param status (//)
*/
void updateInitStatus(InitStatus_t status) { void updateInitStatus(InitStatus_t status) {
deviceStatus.initStatus = status; deviceStatus.initStatus = status;
} }
@ -120,14 +164,26 @@ void updateInitStatus(InitStatus_t status) {
//modBUS RTU 写命令 /**
* ModBUS RTU写命令
* ModBUS RTU格式的命令
*
* @param txBuf
* @param txLen
*/
void writeCMD(uint8_t *txBuf, uint16_t txLen) { void writeCMD(uint8_t *txBuf, uint16_t txLen) {
} }
uint8_t SendToHost(uint8_t *txBuf, uint16_t txLen) { /**
// 发送数据到主机 *
// 具体实现 *
return 0; * @param txBuf
* @param txLen
* @return 0: :
*/
void sendMsgToHost(uint8_t *txBuf, uint16_t txLen) {
// 发送数据
HAL_UART_Transmit_DMA(&huart2, txBuf, txLen);
} }
@ -259,12 +315,35 @@ uint8_t WritePump2Reg(uint8_t index, uint16_t reg, uint32_t value) {
+--------------+--------------------------------+ +--------------+--------------------------------+
*/ */
/**
*
*
* @param index
* @param acc
* @return 0: :
*/
static uint8_t WriteJogAcc(uint8_t index, uint16_t acc) { static uint8_t WriteJogAcc(uint8_t index, uint16_t acc) {
WritePump1Reg(index, RTU_PUMP_CMD_JA, acc); WritePump1Reg(index, RTU_PUMP_CMD_JA, acc);
} }
/**
*
*
* @param index
* @param dec
* @return 0: :
*/
static uint8_t WriteJogDec(uint8_t index, uint16_t dec) { static uint8_t WriteJogDec(uint8_t index, uint16_t dec) {
WritePump1Reg(index, RTU_PUMP_CMD_JL, dec); WritePump1Reg(index, RTU_PUMP_CMD_JL, dec);
} }
/**
*
*
* @param index
* @param speed
* @return 0: :
*/
static uint8_t WriteJogSpeed(uint8_t index, uint16_t speed) { static uint8_t WriteJogSpeed(uint8_t index, uint16_t speed) {
WritePump1Reg(index, RTU_PUMP_CMD_JS, speed); WritePump1Reg(index, RTU_PUMP_CMD_JS, speed);
} }
@ -292,68 +371,141 @@ static uint8_t StopJogControl(uint8_t index) {
+--------------+--------------------------------+ +--------------+--------------------------------+
| 2. | DI | | 2. | DI |
+--------------+--------------------------------+ +--------------+--------------------------------+
| 3. | FLFP | | 3. | FLFP |
+--------------+--------------------------------+ +--------------+--------------------------------+
| 4. | SK | | 4. | SK |
+--------------+--------------------------------+ +--------------+--------------------------------+
*/ */
/**
*
*
* @param index
* @param acc
* @return 0: :
*/
static uint8_t WriteStepAcc(uint8_t index, uint16_t acc) { static uint8_t WriteStepAcc(uint8_t index, uint16_t acc) {
WritePump1Reg(index, RTU_PUMP_CMD_AC, acc); WritePump1Reg(index, RTU_PUMP_CMD_AC, acc);
} }
/**
*
*
* @param index
* @param dec
* @return 0: :
*/
static uint8_t WriteStepDec(uint8_t index, uint16_t dec) { static uint8_t WriteStepDec(uint8_t index, uint16_t dec) {
WritePump1Reg(index, RTU_PUMP_CMD_DE, dec); WritePump1Reg(index, RTU_PUMP_CMD_DE, dec);
} }
/**
*
*
*
* @param index
* @param speed (0-100)
* @return 0: :
*/
static uint8_t WriteStepSpeed(uint8_t index, uint16_t speed) { static uint8_t WriteStepSpeed(uint8_t index, uint16_t speed) {
// 目标速度转换为实际速度 // 目标速度转换为实际速度
speed = (uint16_t)(speed * dp.pump[index].maxSpeed / 100); speed = (uint16_t)(speed * dp.pump[index].maxSpeed / 100);
WritePump1Reg(index, RTU_PUMP_CMD_VE, speed); WritePump1Reg(index, RTU_PUMP_CMD_VE, speed);
} }
/**
*
*
* @param index
* @param target
* @return 0: :
*/
static uint8_t WriteStepTarget(uint8_t index, uint32_t target) { static uint8_t WriteStepTarget(uint8_t index, uint32_t target) {
WritePump2Reg(index, RTU_PUMP_CMD_DI, target); WritePump2Reg(index, RTU_PUMP_CMD_DI, target);
} }
// FL=feed length /**
// 写入命令操作码寄存器(40125)数据0x0066(FL),即执行相对位置控制 *
* FL(feed length)
*
* @param index
* @return 0: :
*/
static uint8_t RelativePositionControl(uint8_t index) { static uint8_t RelativePositionControl(uint8_t index) {
WritePump1Reg(index, RTU_PUMP_CMD_CO, 0x0066); WritePump1Reg(index, RTU_PUMP_CMD_CO, 0x0066);
} }
// FP=feed position /**
// 写入命令操作码寄存器(40125)数据0x0067(FP),即执行绝对位置控制 *
* FP(feed position)
*
* @param index
* @return 0: :
*/
static uint8_t AbsolutePositionControl(uint8_t index) { static uint8_t AbsolutePositionControl(uint8_t index) {
WritePump1Reg(index, RTU_PUMP_CMD_CO, 0x0067); WritePump1Reg(index, RTU_PUMP_CMD_CO, 0x0067);
} }
// SK=Stop Move & Kill Buffer, Max Decel /**
// 写入命令操作码寄存器(40125)数据0x00E1(SK),即执行停止控制 *
* SK(Stop & Kill)
*
* @param index
* @return 0: :
*/
static uint8_t StopPump(uint8_t index) { static uint8_t StopPump(uint8_t index) {
WritePump1Reg(index, RTU_PUMP_CMD_CO, 0x00E1); WritePump1Reg(index, RTU_PUMP_CMD_CO, 0x00E1);
} }
// 获取固件版本 /**
*
*
* @param index
* @return 0: :
*/
uint8_t ReadHWReg(uint8_t index) { uint8_t ReadHWReg(uint8_t index) {
ReadPump1Reg(index, RTU_PUMP_CMD_HW); ReadPump1Reg(index, RTU_PUMP_CMD_HW);
} }
// 设置波特率 /**
*
*
* @param index
* @param br
* @return 0: :
*/
uint8_t WriteBRReg(uint8_t index, uint16_t br) { uint8_t WriteBRReg(uint8_t index, uint16_t br) {
WritePump1Reg(index, RTU_PUMP_CMD_BR, br); WritePump1Reg(index, RTU_PUMP_CMD_BR, br);
} }
// 设置通信协议 /**
*
*
* @param index
* @param pr
* @return 0: :
*/
uint8_t WritePRReg(uint8_t index, uint16_t pr) { uint8_t WritePRReg(uint8_t index, uint16_t pr) {
WritePump1Reg(index, RTU_PUMP_CMD_PR, pr); WritePump1Reg(index, RTU_PUMP_CMD_PR, pr);
} }
// 获取泵状态 /**
*
*
* @param index
*/
void ReadPumpStatus(uint8_t index) { void ReadPumpStatus(uint8_t index) {
ReadPump1Reg(index, RTU_PUMP_CMD_SC); ReadPump1Reg(index, RTU_PUMP_CMD_SC);
} }
// 获取泵告警信息 /**
*
*
* @param index
*/
void ReadPumpAlarm(uint8_t index) { void ReadPumpAlarm(uint8_t index) {
ReadPump1Reg(index, RTU_PUMP_CMD_AL); ReadPump1Reg(index, RTU_PUMP_CMD_AL);
} }
// 解码告警信息 /**
*
*
* @param reg4001
*/
void DecodePumpAlarmMsg(uint16_t reg4001) { void DecodePumpAlarmMsg(uint16_t reg4001) {
static AlarmCode_t alarmCode = {0}; static AlarmCode_t alarmCode = {0};
// 与上次告警信息相同,则不更新,仅打印一次 // 与上次告警信息相同,则不更新,仅打印一次
@ -383,7 +535,11 @@ void DecodePumpAlarmMsg(uint16_t reg4001) {
return 1; return 1;
} }
// 解码状态信息 /**
*
*
* @param reg4002
*/
void DecodePumpStatusMsg(uint16_t reg4002) { void DecodePumpStatusMsg(uint16_t reg4002) {
static StatusCode_t statusCode = {0}; static StatusCode_t statusCode = {0};
// 与上次状态信息相同,则不更新,仅打印一次 // 与上次状态信息相同,则不更新,仅打印一次
@ -446,50 +602,158 @@ void (*writeValve2Reg)(uint8_t index, uint16_t reg, uint32_t value) = WritePump2
void (*readValve1Reg)(uint8_t index, uint16_t reg) = ReadPump1Reg; void (*readValve1Reg)(uint8_t index, uint16_t reg) = ReadPump1Reg;
void (*readValve2Reg)(uint8_t index, uint16_t reg) = ReadPump2Reg; void (*readValve2Reg)(uint8_t index, uint16_t reg) = ReadPump2Reg;
/**
*
*
* @param index
* @param mode (CIA402模式)
* @return 0: :
*/
static uint8_t SetValveCOMMMode(uint8_t index, uint16_t mode) { static uint8_t SetValveCOMMMode(uint8_t index, uint16_t mode) {
WritePump1Reg(index, RTU_VALVE_CMD_CTL_MODE, mode); WritePump1Reg(index, RTU_VALVE_CMD_CTL_MODE, mode);
} }
/**
*
*
* @param index
* @param mode (HMPP)
* @return 0: :
*/
static uint8_t SetValveRunMode(uint8_t index, uint16_t mode) { static uint8_t SetValveRunMode(uint8_t index, uint16_t mode) {
WritePump1Reg(index, RTU_VALVE_CMD_RUN_MODE, mode); WritePump1Reg(index, RTU_VALVE_CMD_RUN_MODE, mode);
} }
// PP=轮廓位置模式 // PP=轮廓位置模式
/**
*
*
* @param index
* @param pos ()
* @return 0: :
*/
static uint8_t SetValvePPPos(uint8_t index, uint32_t pos) { static uint8_t SetValvePPPos(uint8_t index, uint32_t pos) {
writeValve2Reg(index, RTU_VALVE_CMD_PP_POS, pos); writeValve2Reg(index, RTU_VALVE_CMD_PP_POS, pos);
} }
/**
*
*
* @param index
* @param speed (/s)
* @return 0: :
*/
static uint8_t SetValvePPSpeed(uint8_t index, uint32_t speed) { static uint8_t SetValvePPSpeed(uint8_t index, uint32_t speed) {
writeValve2Reg(index, RTU_VALVE_CMD_PP_SPEED, speed); writeValve2Reg(index, RTU_VALVE_CMD_PP_SPEED, speed);
} }
/**
*
*
* @param index
* @param acc (/s²)
* @return 0: :
*/
static uint8_t SetValvePPAcc(uint8_t index, uint32_t acc) { static uint8_t SetValvePPAcc(uint8_t index, uint32_t acc) {
writeValve2Reg(index, RTU_VALVE_CMD_PP_ACCEL, acc); writeValve2Reg(index, RTU_VALVE_CMD_PP_ACCEL, acc);
} }
/**
*
*
* @param index
* @param dec (/s²)
* @return 0: :
*/
static uint8_t SetValvePPDec(uint8_t index, uint32_t dec) { static uint8_t SetValvePPDec(uint8_t index, uint32_t dec) {
writeValve2Reg(index, RTU_VALVE_CMD_PP_DECEL, dec); writeValve2Reg(index, RTU_VALVE_CMD_PP_DECEL, dec);
} }
// HM=原点回归模式 // HM=原点回归模式
/**
*
*
* @param index
* @param mode ()
* @return 0: :
*/
static uint8_t SetValveHomeDetectMode(uint8_t index, uint16_t mode) { static uint8_t SetValveHomeDetectMode(uint8_t index, uint16_t mode) {
writeValve1Reg(index, RTU_VALVE_CMD_HOME_MODE, mode); writeValve1Reg(index, RTU_VALVE_CMD_HOME_MODE, mode);
} }
/**
*
*
* @param index
* @param speed
* @return 0: :
*/
static uint8_t SetValveHomeSwtSpeed(uint8_t index, uint32_t speed) { static uint8_t SetValveHomeSwtSpeed(uint8_t index, uint32_t speed) {
writeValve2Reg(index, RTU_VALVE_CMD_HOME_SWT_SPEED, speed); writeValve2Reg(index, RTU_VALVE_CMD_HOME_SWT_SPEED, speed);
} }
/**
*
*
* @param index
* @param speed
* @return 0: :
*/
static uint8_t SetValveHomeOriSpeed(uint8_t index, uint32_t speed) { static uint8_t SetValveHomeOriSpeed(uint8_t index, uint32_t speed) {
writeValve2Reg(index, RTU_VALVE_CMD_HOME_ORI_SPEED, speed); writeValve2Reg(index, RTU_VALVE_CMD_HOME_ORI_SPEED, speed);
} }
/**
*
*
* @param index
* @param acc
* @return 0: :
*/
static uint8_t SetValveHomeAcc(uint8_t index, uint32_t acc) { static uint8_t SetValveHomeAcc(uint8_t index, uint32_t acc) {
writeValve2Reg(index, RTU_VALVE_CMD_HOME_ACCEL, acc); writeValve2Reg(index, RTU_VALVE_CMD_HOME_ACCEL, acc);
} }
/**
*
*
* @param index
* @param func (使)
* @return 0: :
*/
static uint8_t SetValveFunc(uint8_t index, uint16_t func) { static uint8_t SetValveFunc(uint8_t index, uint16_t func) {
writeValve1Reg(index, RTU_VALVE_CMD_FUNC, func); writeValve1Reg(index, RTU_VALVE_CMD_FUNC, func);
} }
/**
*
*
* @param index
* @param torque
* @return 0: :
*/
static uint8_t SetValveHomeTorque(uint8_t index, uint16_t torque) { static uint8_t SetValveHomeTorque(uint8_t index, uint16_t torque) {
writeValve1Reg(index, RTU_VALVE_CMD_HOME_TORQUE, torque); writeValve1Reg(index, RTU_VALVE_CMD_HOME_TORQUE, torque);
} }
/**
*
*
* @param index
* @param time (ms)
* @return 0: :
*/
static uint8_t SetValveHomeTime(uint8_t index, uint16_t time) { static uint8_t SetValveHomeTime(uint8_t index, uint16_t time) {
writeValve1Reg(index, RTU_VALVE_CMD_HOME_TIME, time); writeValve1Reg(index, RTU_VALVE_CMD_HOME_TIME, time);
} }
/**
*
*
*
* @param index
* @return 0: :
*/
uint8_t ValveBackToOrigin(uint8_t index) { uint8_t ValveBackToOrigin(uint8_t index) {
// 1.设置原点回归方式 // 1.设置原点回归方式
// (0416h)=37;17=负限位18=正限位 // (0416h)=37;17=负限位18=正限位
@ -514,6 +778,13 @@ uint8_t ValveBackToOrigin(uint8_t index) {
SetValveFunc(index, RTU_VALVE_CFG_RUN_ORIGIN); SetValveFunc(index, RTU_VALVE_CFG_RUN_ORIGIN);
} }
/**
*
*
*
* @param index
* @return 0: :
*/
uint8_t ValveRunInit(uint8_t index) { uint8_t ValveRunInit(uint8_t index) {
// 1.配置模式: // 1.配置模式:
// 00B1h=0、运行模式 03C2h=0x01使设备工作在轮廓位置模式 // 00B1h=0、运行模式 03C2h=0x01使设备工作在轮廓位置模式
@ -532,6 +803,13 @@ uint8_t ValveRunInit(uint8_t index) {
SetValveFunc(index, RTU_VALVE_CFG_ENABLE); SetValveFunc(index, RTU_VALVE_CFG_ENABLE);
} }
/**
*
*
* @param index
* @param angle (0/120/210)
* @return 0: :
*/
uint8_t ValveRunToAngle(uint8_t index, uint32_t angle) { uint8_t ValveRunToAngle(uint8_t index, uint32_t angle) {
// 限制角度为0,120,210 // 限制角度为0,120,210
if(angle != 0 && angle != 120 && angle != 210) { if(angle != 0 && angle != 120 && angle != 210) {
@ -547,6 +825,12 @@ uint8_t ValveRunToAngle(uint8_t index, uint32_t angle) {
SetValveFunc(index, 0x3F); SetValveFunc(index, 0x3F);
} }
/**
*
*
*
* @return 0: :
*/
uint8_t InitValve(void) { uint8_t InitValve(void) {
SetValvePPSpeed(dp.valve[0].id, dp.valve[0].maxSpeed); SetValvePPSpeed(dp.valve[0].id, dp.valve[0].maxSpeed);
SetValvePPAcc(dp.valve[0].id, dp.valve[0].maxAccel); SetValvePPAcc(dp.valve[0].id, dp.valve[0].maxAccel);
@ -557,9 +841,10 @@ uint8_t InitValve(void) {
SetValvePPDec(dp.valve[1].id, dp.valve[1].maxDecel); SetValvePPDec(dp.valve[1].id, dp.valve[1].maxDecel);
} }
// 定时1s更新设备状态 /**
// 活度计通过网口获取 *
// 下挂设备通过485获取 *
*/
void UpdatePumpStatus() { void UpdatePumpStatus() {
// 更新设备状态 // 更新设备状态
ReadPumpStatus(0); ReadPumpStatus(0);
@ -568,6 +853,12 @@ void UpdatePumpStatus() {
ReadPumpAlarm(1); ReadPumpAlarm(1);
} }
/**
*
*
*
* @return 0: :
*/
uint8_t InitPump(void) { uint8_t InitPump(void) {
// 初始化泵 // 初始化泵
log_e("InitPump"); log_e("InitPump");
@ -585,7 +876,11 @@ uint8_t InitPump(void) {
WriteStepDec(dp.pump[1].id, dp.pump[1].maxDecel); WriteStepDec(dp.pump[1].id, dp.pump[1].maxDecel);
WriteStepSpeed(dp.pump[1].id, dp.pump[1].maxSpeed); WriteStepSpeed(dp.pump[1].id, dp.pump[1].maxSpeed);
} }
// 初始化设备状态
/**
*
* 线
*/
void InitDeviceStatus() { void InitDeviceStatus() {
// 初始化泵 // 初始化泵
@ -602,6 +897,7 @@ void InitDeviceStatus() {
updateEmergencyStop(ESTOP_NORMAL); updateEmergencyStop(ESTOP_NORMAL);
updateInitStatus(INIT_SUCCESS); updateInitStatus(INIT_SUCCESS);
} }
// 初始化处理 // 初始化处理
static uint8_t HandleInit(void) { static uint8_t HandleInit(void) {
// 实现初始化逻辑 // 实现初始化逻辑
@ -611,15 +907,27 @@ static uint8_t HandleInit(void) {
// 状态查询处理 // 状态查询处理
/**
*
*
* @return 0: :
*/
static uint8_t HandleStatusQuery(void) { static uint8_t HandleStatusQuery(void) {
// 填充并返回数据 // 填充并返回数据
uint8_t txBuf[sizeof(DeviceStatus)] = {0}; uint8_t txBuf[sizeof(DeviceStatus)] = {0};
memcpy(txBuf, &deviceStatus, sizeof(DeviceStatus)); memcpy(txBuf, &deviceStatus, sizeof(DeviceStatus));
SendToHost(txBuf, sizeof(txBuf)); // sendMsgToHost(txBuf, sizeof(txBuf));
return 0; return 0;
} }
// 三通阀控制处理 // 三通阀控制处理
/**
*
*
* @param Buff
* @param len
* @return 0: :
*/
static uint8_t HandleValveControl(uint8_t *Buff, uint8_t len) { static uint8_t HandleValveControl(uint8_t *Buff, uint8_t len) {
// 实现三通阀控制逻辑 // 实现三通阀控制逻辑
@ -648,17 +956,31 @@ static uint8_t HandleValveControl(uint8_t *Buff, uint8_t len) {
} }
// 泵时长控制处理 // 泵时长控制处理
/**
*
*
* @param Buff
* @param len
* @return 0: :
*/
static uint8_t HandlePumpTimeControl(uint8_t *Buff, uint8_t len) { static uint8_t HandlePumpTimeControl(uint8_t *Buff, uint8_t len) {
// 实现泵时长控制逻辑 // 实现泵时长控制逻辑
// 使用定时器更靠谱 // 使用步数方式更靠谱,通过时间和速度计算步数,结束时不用发送停止命令
return 1; return 1;
} }
// 泵速度设置处理 // 泵速度设置处理
/**
*
*
* @param Buff
* @param len
* @return 0: :
*/
static uint8_t HandlePumpSpeedControl(uint8_t *Buff, uint8_t len) { static uint8_t HandlePumpSpeedControl(uint8_t *Buff, uint8_t len) {
// 实现泵速度设置逻辑 // 实现速度设置逻辑
if(len != 4) { if(len != 4) {
log_e("泵速度设置错误"); log_e("泵速度设置错误");
return 0; return 0;
@ -682,6 +1004,14 @@ static uint8_t HandlePumpSpeedControl(uint8_t *Buff, uint8_t len) {
return 1; return 1;
} }
// 泵步进控制处理
/**
*
*
* @param Buff
* @param len
* @return 0: :
*/
static uint8_t HandlePumpStepControl(uint8_t *Buff, uint8_t len) { static uint8_t HandlePumpStepControl(uint8_t *Buff, uint8_t len) {
if(len != 10) { if(len != 10) {
log_e("泵步进设置错误"); log_e("泵步进设置错误");
@ -694,7 +1024,13 @@ static uint8_t HandlePumpStepControl(uint8_t *Buff, uint8_t len) {
return 0; return 0;
} }
// 软急停功能处理 /**
*
*
* @param rxBuf
* @param rxLen
* @return 0: 1:
*/
static uint8_t HandleSoftStop(uint8_t *rxBuf, uint16_t rxLen) { static uint8_t HandleSoftStop(uint8_t *rxBuf, uint16_t rxLen) {
if(rxLen != 1) { if(rxLen != 1) {
log_e("软急停设置错误"); log_e("软急停设置错误");
@ -715,14 +1051,25 @@ static uint8_t HandleSoftStop(uint8_t *rxBuf, uint16_t rxLen) {
} }
return 0; return 0;
} }
/**
*
*
* @param rxBuf
* @param rxLen
*/
void ProcessMotorMsg(uint8_t *rxBuf, uint16_t rxLen) { void ProcessMotorMsg(uint8_t *rxBuf, uint16_t rxLen) {
// 实现电机消息处理逻辑 // 实现电机消息处理逻辑
log_d("ProcessMotorMsg"); log_d("ProcessMotorMsg");
} }
void sendMsgToHost(uint8_t *txBuf, uint16_t txLen) {
// 发送数据 /**
HAL_UART_Transmit_DMA(&huart2, txBuf, txLen); *
} * :+(2Byte)+(1Byte)+(NByte)+CRC16校验位+
*
* @param funcCode
* @param isOK
*/
void packMsgToHost(uint16_t funcCode, uint8_t isOK) { void packMsgToHost(uint16_t funcCode, uint8_t isOK) {
// 实现打包消息到上位机逻辑 // 实现打包消息到上位机逻辑
// 帧头+功能码(2Byte)+数据长度(1Byte)+ 具体数据(NByte)+CRC16校验位+帧尾 // 帧头+功能码(2Byte)+数据长度(1Byte)+ 具体数据(NByte)+CRC16校验位+帧尾
@ -763,9 +1110,16 @@ void packMsgToHost(uint16_t funcCode, uint8_t isOK) {
sendMsgToHost(msgBuf, len); sendMsgToHost(msgBuf, len);
} }
/**
*
*
* @param rxBuf
* @param rxLen
* @return
*/
CmdFrameError_t checkHostCmd(uint8_t *rxBuf, uint16_t rxLen) { CmdFrameError_t checkHostCmd(uint8_t *rxBuf, uint16_t rxLen) {
// 检查命令是否正确 // 检查命令是否正确
// FRAME_HEADER是按小端序存储的而rxBuf是按大端序存储的 // FRAME_HEADER是按小端序存储的而rxBuf是按大端序存
uint32_t header; uint32_t header;
FillBigEndian32(&header, FRAME_HEADER); FillBigEndian32(&header, FRAME_HEADER);
uint32_t tail; uint32_t tail;
@ -789,9 +1143,14 @@ CmdFrameError_t checkHostCmd(uint8_t *rxBuf, uint16_t rxLen) {
} }
// 上位机命令处理函数采用的自定协议非modbus协议 /**
// rxBuf: 接收到的数据 *
// rxLen: 接收到的数据长度 * ,modbus协议
*
* @param rxBuf
* @param rxLen
* @return
*/
CmdFrameError_t ProcessHostCommand(uint8_t *rxBuf, uint16_t rxLen) { CmdFrameError_t ProcessHostCommand(uint8_t *rxBuf, uint16_t rxLen) {
CmdFrameError_t error = checkHostCmd(rxBuf, rxLen); CmdFrameError_t error = checkHostCmd(rxBuf, rxLen);