diff --git a/protocol.c b/protocol.c index 6923bc8..90c0537 100644 --- a/protocol.c +++ b/protocol.c @@ -327,8 +327,9 @@ uint16_t ReadPump1Reg(uint8_t id, uint16_t reg) { uint16_t crc = CalculateCRC16(data, 6); // 小端序填充 memcpy(&data[6], &crc, 2); + elog_hexdump("writeCMD", 16, data, sizeof(data)); + transDataToMotorValve(data, 8); - transDataToHost(data, 8); uint8_t rxBuf[30] = {0}; uint16_t rxLen = 7; uint8_t ret = readDataFromMotorValve(rxBuf, rxLen, READ_ACK_TIMEOUT); @@ -357,8 +358,9 @@ uint32_t ReadPump2Reg(uint8_t id, uint16_t reg) { uint16_t crc = CalculateCRC16(data, 6); // 小端序填充 memcpy(&data[6], &crc, 2); - + elog_hexdump("writeCMD", 16, data, sizeof(data)); transDataToMotorValve(data, sizeof(data)); + uint8_t rxBuf[30] = {0}; uint16_t rxLen = 9; uint8_t ret = readDataFromMotorValve(rxBuf, rxLen, READ_ACK_TIMEOUT*10); @@ -520,7 +522,8 @@ static uint8_t SetPumpStepDec(uint8_t index, uint16_t dec) { * @return 实际速度值 */ uint16_t transSpeedPercentToSpeed(uint8_t index, uint8_t speedPercent) { - return speedPercent*PUMP_SPEED_RPS * dp.pump[index].fullSpeed / 100; + uint32_t tmp = speedPercent * PUMP_SPEED_RPS * dp.pump[index].fullSpeed; + return tmp/100; } /** @@ -1594,9 +1597,9 @@ static uint8_t HandlePumpTimeControl(uint8_t *Buff, uint8_t len) { } else { // 使用步数方式更靠谱,通过时间和速度计算步数,结束时不用发送停止命令 - uint16_t cnt = ReadPumpCNT(index);//8000 + uint16_t cnt = ReadPumpCNT(index);//10000 log_d("cnt=%d",cnt); - int32_t step = direction*time*systemStatus.pumpsSpeed[index]*cnt; + int32_t step = direction*systemStatus.pumpsSpeed[index]/PUMP_SPEED_RPS*cnt*time; StopPump(index);//stop first SetPumpStepTarget(index, step); StartPumpRelativeMove(index);