fix bugs
This commit is contained in:
parent
7995848f05
commit
9fbe044705
101
protocol.c
101
protocol.c
@ -2,12 +2,12 @@
|
||||
#include <string.h>
|
||||
|
||||
static DeviceStatus deviceStatus = {0};
|
||||
DeviceDefaultParam dp = {
|
||||
DeviceDefaultParam dp = {{
|
||||
{"pump1", 1, 100, 100, 100},
|
||||
{"pump2", 2, 100, 100, 100},
|
||||
{"valve1", 3, 100, 100, 100},
|
||||
{"valve2", 4, 100, 100, 100}
|
||||
};
|
||||
}};
|
||||
|
||||
|
||||
|
||||
@ -108,41 +108,7 @@ void updateInitStatus(InitStatus_t status) {
|
||||
deviceStatus.initStatus = status;
|
||||
}
|
||||
|
||||
uint8_t InitPump(void) {
|
||||
// 初始化泵
|
||||
WriteJogAcc(dp.pump[0].id, dp.pump[0].maxAccel);
|
||||
WriteJogDec(dp.pump[0].id, dp.pump[0].maxDecel);
|
||||
WriteJogSpeed(dp.pump[0].id, dp.pump[0].maxSpeed);
|
||||
WriteStepAcc(dp.pump[0].id, dp.pump[0].maxAccel);
|
||||
WriteStepDec(dp.pump[0].id, dp.pump[0].maxDecel);
|
||||
WriteStepSpeed(dp.pump[0].id, dp.pump[0].maxSpeed);
|
||||
|
||||
WriteJogAcc(dp.pump[1].id, dp.pump[1].maxAccel);
|
||||
WriteJogDec(dp.pump[1].id, dp.pump[1].maxDecel);
|
||||
WriteJogSpeed(dp.pump[1].id, dp.pump[1].maxSpeed);
|
||||
WriteStepAcc(dp.pump[1].id, dp.pump[1].maxAccel);
|
||||
WriteStepDec(dp.pump[1].id, dp.pump[1].maxDecel);
|
||||
WriteStepSpeed(dp.pump[1].id, dp.pump[1].maxSpeed);
|
||||
}
|
||||
|
||||
// 初始化设备状态
|
||||
void InitDeviceStatus() {
|
||||
// 初始化泵
|
||||
InitPump();
|
||||
|
||||
|
||||
// 更新设备状态
|
||||
updateDeviceStatus(DEVICE_ONLINE);
|
||||
updateValveStatus(1, 120);
|
||||
updateValveStatus(2, 210);
|
||||
updatePumpStatus(1, PUMP_CLOCKWISE);
|
||||
updatePumpStatus(2, PUMP_ANTICLOCKWISE);
|
||||
updatePumpSpeedStatus(1, 100);
|
||||
updatePumpSpeedStatus(2, 100);
|
||||
updateBubbleSensor(BUBBLE_DETECTED);
|
||||
updateEmergencyStop(ESTOP_NORMAL);
|
||||
updateInitStatus(INIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
//modBUS RTU 写命令
|
||||
@ -515,10 +481,6 @@ static uint8_t SetValveHomeTime(uint8_t index, uint16_t time) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_TIME, time);
|
||||
}
|
||||
|
||||
uint8_t updateValveStatus(uint8_t index, uint16_t status) {
|
||||
// writeValve1Reg(index, RTU_VALVE_CMD_STATUS, status);
|
||||
}
|
||||
|
||||
uint8_t ValveBackToOrigin(uint8_t index) {
|
||||
// 1.设置原点回归方式
|
||||
// (0416h)=37;17=负限位,18=正限位
|
||||
@ -555,7 +517,7 @@ uint8_t ValveRunInit(uint8_t index) {
|
||||
// 2.4设置位移的减速度 (03FEh)(用户单位/s2);
|
||||
SetValvePPDec(index, 40000);
|
||||
// 3.写控制字使电机使能
|
||||
// (0380h)= 0x06→0x07→ 0x0F,电机使能:
|
||||
// (0380h)= 0x06→0x07→ 0x0F 电机使能:
|
||||
SetValveFunc(index, RTU_VALVE_CFG_PREPARE);
|
||||
SetValveFunc(index, RTU_VALVE_CFG_DISABLE);
|
||||
SetValveFunc(index, RTU_VALVE_CFG_ENABLE);
|
||||
@ -597,9 +559,42 @@ void UpdatePumpStatus() {
|
||||
ReadPumpAlarm(1);
|
||||
}
|
||||
|
||||
uint8_t InitPump(void) {
|
||||
// 初始化泵
|
||||
log_e("InitPump");
|
||||
WriteJogAcc(dp.pump[0].id, dp.pump[0].maxAccel);
|
||||
WriteJogDec(dp.pump[0].id, dp.pump[0].maxDecel);
|
||||
WriteJogSpeed(dp.pump[0].id, dp.pump[0].maxSpeed);
|
||||
WriteStepAcc(dp.pump[0].id, dp.pump[0].maxAccel);
|
||||
WriteStepDec(dp.pump[0].id, dp.pump[0].maxDecel);
|
||||
WriteStepSpeed(dp.pump[0].id, dp.pump[0].maxSpeed);
|
||||
|
||||
WriteJogAcc(dp.pump[1].id, dp.pump[1].maxAccel);
|
||||
WriteJogDec(dp.pump[1].id, dp.pump[1].maxDecel);
|
||||
WriteJogSpeed(dp.pump[1].id, dp.pump[1].maxSpeed);
|
||||
WriteStepAcc(dp.pump[1].id, dp.pump[1].maxAccel);
|
||||
WriteStepDec(dp.pump[1].id, dp.pump[1].maxDecel);
|
||||
WriteStepSpeed(dp.pump[1].id, dp.pump[1].maxSpeed);
|
||||
}
|
||||
// 初始化设备状态
|
||||
void InitDeviceStatus() {
|
||||
// 初始化泵
|
||||
|
||||
|
||||
// 更新设备状态
|
||||
updateDeviceStatus(DEVICE_ONLINE);
|
||||
updateValveStatus(1, 120);
|
||||
updateValveStatus(2, 210);
|
||||
updatePumpStatus(1, PUMP_CLOCKWISE);
|
||||
updatePumpStatus(2, PUMP_ANTICLOCKWISE);
|
||||
updatePumpSpeedStatus(1, 100);
|
||||
updatePumpSpeedStatus(2, 100);
|
||||
updateBubbleSensor(BUBBLE_DETECTED);
|
||||
updateEmergencyStop(ESTOP_NORMAL);
|
||||
updateInitStatus(INIT_SUCCESS);
|
||||
}
|
||||
// 初始化处理
|
||||
static uint8_t HandleInit(uint8_t *rxBuf, uint8_t *txBuf, uint16_t *txLen) {
|
||||
static uint8_t HandleInit(void) {
|
||||
// 实现初始化逻辑
|
||||
InitDeviceStatus();
|
||||
return 1;
|
||||
@ -620,18 +615,18 @@ static uint8_t HandleValveControl(uint8_t *Buff, uint8_t len) {
|
||||
// 实现三通阀控制逻辑
|
||||
|
||||
if(len != 8) {
|
||||
printf("三通阀控制错误\r\n");
|
||||
log_e("三通阀控制错误");
|
||||
return 0;
|
||||
}
|
||||
uint8_t index = Buff[0];
|
||||
uint8_t direction = Buff[1];
|
||||
uint16_t angle = (Buff[2]<<8) | Buff[3];
|
||||
if(angle > 360) {
|
||||
printf("三通阀控制错误\r\n");
|
||||
log_e("三通阀控制错误");
|
||||
return 1;
|
||||
}
|
||||
if (angle != VALVE_ANGLE_120 && angle != VALVE_ANGLE_210) {
|
||||
printf("三通阀控制错误\r\n");
|
||||
log_e("三通阀控制错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -647,7 +642,7 @@ static uint8_t HandleValveControl(uint8_t *Buff, uint8_t len) {
|
||||
static uint8_t HandlePumpTimeControl(uint8_t *Buff, uint8_t len) {
|
||||
// 实现泵时长控制逻辑
|
||||
|
||||
// 暂未知控制方法,是直接设置泵运行时间,还是设置泵运行步数
|
||||
// 使用定时器更靠谱
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -656,13 +651,13 @@ static uint8_t HandlePumpTimeControl(uint8_t *Buff, uint8_t len) {
|
||||
static uint8_t HandlePumpSpeedControl(uint8_t *Buff, uint8_t len) {
|
||||
// 实现泵速度设置逻辑
|
||||
if(len != 4) {
|
||||
printf("泵速度设置错误\r\n");
|
||||
log_e("泵速度设置错误");
|
||||
return 0;
|
||||
}
|
||||
uint8_t index = Buff[0];
|
||||
uint16_t speed = Buff[1];
|
||||
if (speed > 100) {
|
||||
printf("泵速度设置错误\r\n");
|
||||
log_e("泵速度设置错误");
|
||||
return 0;
|
||||
}
|
||||
WriteJogSpeed(index, speed);
|
||||
@ -670,7 +665,7 @@ static uint8_t HandlePumpSpeedControl(uint8_t *Buff, uint8_t len) {
|
||||
index = Buff[2];
|
||||
speed = Buff[3];
|
||||
if (speed > 100) {
|
||||
printf("泵速度设置错误\r\n");
|
||||
log_e("泵速度设置错误");
|
||||
return 0;
|
||||
}
|
||||
WriteJogSpeed(index, speed);
|
||||
@ -680,7 +675,7 @@ static uint8_t HandlePumpSpeedControl(uint8_t *Buff, uint8_t len) {
|
||||
|
||||
static uint8_t HandlePumpStepControl(uint8_t *Buff, uint8_t len) {
|
||||
if(len != 10) {
|
||||
printf("泵步进设置错误\r\n");
|
||||
log_e("泵步进设置错误");
|
||||
return 0;
|
||||
}
|
||||
uint8_t index = Buff[0];
|
||||
@ -693,7 +688,7 @@ static uint8_t HandlePumpStepControl(uint8_t *Buff, uint8_t len) {
|
||||
// 软急停功能处理
|
||||
static uint8_t HandleSoftStop(uint8_t *rxBuf, uint16_t rxLen) {
|
||||
if(rxLen != 1) {
|
||||
printf("软急停设置错误\r\n");
|
||||
log_e("软急停设置错误");
|
||||
return 1;
|
||||
}
|
||||
// 实现软急停功能逻辑
|
||||
@ -767,7 +762,7 @@ CmdFrameError_t ProcessHostCommand(uint8_t *rxBuf, uint16_t rxLen) {
|
||||
error = HandlePumpStep(data, dataLen);
|
||||
break;
|
||||
case CMD_SYSTEM_INIT:
|
||||
error = HandleInit(data, dataLen);
|
||||
error = HandleInit();
|
||||
break;
|
||||
default:
|
||||
error = CMD_FRAME_CMD_ERROR;
|
||||
@ -775,4 +770,4 @@ CmdFrameError_t ProcessHostCommand(uint8_t *rxBuf, uint16_t rxLen) {
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
#define PROTOCOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#define LOG_TAG "motor"
|
||||
#include <elog.h>
|
||||
|
||||
// 帧头帧尾定义
|
||||
#define FRAME_HEADER 0xA55A5AA5
|
||||
|
Loading…
Reference in New Issue
Block a user