|
|
@ -11,11 +11,8 @@ using namespace smtp2; |
|
|
|
#define TAG "SMTP2"
|
|
|
|
|
|
|
|
#define OVERTIME 100
|
|
|
|
#define DUMP_HEX 0
|
|
|
|
#define DUMP_HEX 1
|
|
|
|
|
|
|
|
#define SEND_CMD(fmt, ...) sendcmd(true, 1, "/1" fmt "R\r", ##__VA_ARGS__);
|
|
|
|
#define SEND_CMD_AUTO_RETRY(retry_times, fmt, ...) sendcmd(true, retry_times, "/1" fmt "R\r", ##__VA_ARGS__);
|
|
|
|
#define SEND_CMD_NLOG(fmt, ...) sendcmd(false, 1, "/1" fmt "R\r", ##__VA_ARGS__);
|
|
|
|
// 模式2
|
|
|
|
void SMTP2V2::initialize(UART_HandleTypeDef* uart, uint8_t id, DMA_HandleTypeDef* hdma_rx, DMA_HandleTypeDef* hdma_tx) { |
|
|
|
m_uart = uart; |
|
|
@ -30,7 +27,7 @@ bool SMTP2V2::pump_ping() { |
|
|
|
} |
|
|
|
int32_t SMTP2V2::pump_get_state(int32_t* isbusy) { |
|
|
|
size_t rxlen = 0; |
|
|
|
int ret = sendcmd(false /*dump*/, 5 /*retry_times*/, "/1QR\r"); |
|
|
|
int ret = readstate(false, "/1QR\r"); |
|
|
|
if (ret != 0) return ret; |
|
|
|
|
|
|
|
uint8_t errorcode = (uint8_t)m_rxbuf[2]; |
|
|
@ -43,7 +40,7 @@ int32_t SMTP2V2::pump_get_state(int32_t* isbusy) { |
|
|
|
} |
|
|
|
int32_t SMTP2V2::pump_get_state_as_int(int32_t state_index, int32_t* val) { |
|
|
|
size_t rxlen = 0; |
|
|
|
int ret = SEND_CMD_AUTO_RETRY(3, "?%d\r", state_index); |
|
|
|
int ret = readstate(true, "/1?%d\r", state_index); |
|
|
|
if (ret != 0) { |
|
|
|
return ret; |
|
|
|
} |
|
|
@ -67,20 +64,20 @@ int32_t SMTP2V2::pump_get_motor_pos_ul(int32_t* ul) { |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_stop() { return sendcmd(true, 1, "/1TR\r"); } |
|
|
|
int32_t SMTP2V2::pump_set_vstart(int32_t vel) { return SEND_CMD("N2v%d", vel * 319); } |
|
|
|
int32_t SMTP2V2::pump_set_vstop(int32_t vel) { return SEND_CMD("N2c%d", vel * 319); } |
|
|
|
int32_t SMTP2V2::pump_set_vmax(int32_t vel) { return SEND_CMD("N2V%d", vel * 319); } |
|
|
|
int32_t SMTP2V2::pump_set_acc_and_dec(int32_t acc, int32_t dec) { return SEND_CMD("L%d,%d", acc, dec); } |
|
|
|
int32_t SMTP2V2::pump_set_plld_start_delay(int32_t delay_ms) { return SEND_CMD("T%d", delay_ms); } |
|
|
|
int32_t SMTP2V2::pump_stop() { return setstate(true, "/1TR\r"); } |
|
|
|
int32_t SMTP2V2::pump_set_vstart(int32_t vel) { return setstate(true, "/1N2v%dR\r", vel * 319); } |
|
|
|
int32_t SMTP2V2::pump_set_vstop(int32_t vel) { return setstate(true, "/1N2c%dR\r", vel * 319); } |
|
|
|
int32_t SMTP2V2::pump_set_vmax(int32_t vel) { return setstate(true, "/1N2V%dR\r", vel * 319); } |
|
|
|
int32_t SMTP2V2::pump_set_acc_and_dec(int32_t acc, int32_t dec) { return setstate(true, "/1L%d,%dR\r", acc, dec); } |
|
|
|
int32_t SMTP2V2::pump_set_plld_start_delay(int32_t delay_ms) { return setstate(true, "/1T%dR\r", delay_ms); } |
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_put_tip() { return SEND_CMD("E1"); } |
|
|
|
int32_t SMTP2V2::pump_init(int32_t v) { return SEND_CMD("N2V%dZ", v * 319); } |
|
|
|
int32_t SMTP2V2::pump_put_tip() { return runaction(true, "/1E1R\r"); } |
|
|
|
int32_t SMTP2V2::pump_init(int32_t v) { return runaction(true, "/1N2V%dZR\r", v * 319); } |
|
|
|
int32_t SMTP2V2::pump_reset() { |
|
|
|
_sendcmd(true, "/1!0R\r"); // 复位指令没有回执,所以这里只能使用方法_sendcmd
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
#if 0
|
|
|
|
static int32_t Get1fromfloat(const float& val) { |
|
|
|
float temp1 = val; |
|
|
|
int32_t t1 = (uint32_t)(temp1 * 10) % 10; |
|
|
@ -91,6 +88,7 @@ static int32_t Get1fromfloat(const float& val) { |
|
|
|
} |
|
|
|
return (int32_t)temp1; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_move_to_ul(int32_t v, int32_t ul) { |
|
|
|
/**
|
|
|
@ -102,13 +100,23 @@ int32_t SMTP2V2::pump_move_to_ul(int32_t v, int32_t ul) { |
|
|
|
*/ |
|
|
|
ZLOGI(TAG, "pump_move_to_ul %d", ul); |
|
|
|
int stepNum = ul * 1000; //+0.5 是为了浮点数强转成正数时采用四舍五入的方式
|
|
|
|
return SEND_CMD("V%dA%d", v * 319, stepNum); |
|
|
|
return pump_move_to_nl(v, ul * 1000); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_move_to_nl(int32_t v, int32_t nl) { |
|
|
|
ZLOGI(TAG, "pump_move_to_nl %d", nl); |
|
|
|
return runaction(true, "/1V%dA%dR\r", v * 319, nl); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_aspirate(int32_t v, int32_t ul) { |
|
|
|
ZLOGI(TAG, "pump_aspirate %d", ul); |
|
|
|
int stepNum = ul * 1000; |
|
|
|
return SEND_CMD("V%dP%d", v * 319, stepNum); |
|
|
|
int32_t nownl; |
|
|
|
|
|
|
|
int32_t ret = pump_get_state_as_int(kstate_pump_pos_nl, &nownl); |
|
|
|
if (ret != 0) return ret; |
|
|
|
|
|
|
|
int targetnl = nownl + ul * 1000; |
|
|
|
return pump_move_to_nl(v, targetnl); |
|
|
|
} |
|
|
|
int32_t SMTP2V2::pump_distribut(int32_t v, int32_t ul) { |
|
|
|
ZLOGI(TAG, "pump_distribut %d", ul); |
|
|
@ -118,19 +126,15 @@ int32_t SMTP2V2::pump_distribut(int32_t v, int32_t ul) { |
|
|
|
int32_t ret = pump_get_state_as_int(kstate_pump_pos_nl, &nownl); |
|
|
|
if (ret != 0) return ret; |
|
|
|
|
|
|
|
int stepNum = ul * 1000; |
|
|
|
|
|
|
|
if (stepNum > nownl) { |
|
|
|
stepNum = nownl; |
|
|
|
} |
|
|
|
|
|
|
|
return SEND_CMD("V%dD%d", v * 319, stepNum); |
|
|
|
int targetnl = nownl - ul * 1000; |
|
|
|
if (targetnl < 0) targetnl = 0; |
|
|
|
return pump_move_to_nl(v, targetnl); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_distribut_plld(int32_t pumpv, int32_t pressure_threshold) { |
|
|
|
// M100V100t50,0R
|
|
|
|
ZLOGI(TAG, "pump_distribut_plld %d %d", pumpv, pressure_threshold); |
|
|
|
return SEND_CMD("V%dt%d,0", pumpv * 319, pressure_threshold); |
|
|
|
return runaction(true, "/1V%dt%d,0R\r", pumpv * 319, pressure_threshold); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_distribut_plld_get_state(int32_t* detected) { |
|
|
@ -146,7 +150,7 @@ int32_t SMTP2V2::pump_distribut_plld_get_state(int32_t* detected) { |
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_clld(int32_t c_threshold) { //
|
|
|
|
ZLOGI(TAG, "pump_clld %d", c_threshold); |
|
|
|
return SEND_CMD("^%d", c_threshold); |
|
|
|
return runaction(true, "/1^%dR\r", c_threshold); |
|
|
|
} |
|
|
|
int32_t SMTP2V2::pump_clld_get_state(int32_t* detected) { |
|
|
|
int32_t isbusy; |
|
|
@ -161,7 +165,7 @@ int32_t SMTP2V2::pump_clld_get_state(int32_t* detected) { |
|
|
|
// B<n1>,<n2>
|
|
|
|
int32_t SMTP2V2::pump_distribut_mlld(int32_t pumpv, int32_t c_threshold, int32_t pressure_threshold) { |
|
|
|
ZLOGI(TAG, "pump_distribut_mlld %d %d %d", pumpv, c_threshold, pressure_threshold); |
|
|
|
return SEND_CMD("V%dB%d,%d", pumpv * 319, c_threshold, pressure_threshold); |
|
|
|
return runaction(true, "/1V%dB%d,%dR\r", pumpv * 319, c_threshold, pressure_threshold); |
|
|
|
} |
|
|
|
int32_t SMTP2V2::pump_distribut_mlld_get_state(int32_t* detected) { |
|
|
|
int32_t isbusy; |
|
|
@ -179,7 +183,7 @@ int32_t SMTP2V2::pump_distribut_mlld_get_state(int32_t* detected) { |
|
|
|
***********************************************************************************************************************/ |
|
|
|
bool SMTP2V2::write_cmd(const char* cmd) { |
|
|
|
int32_t ret = 0; |
|
|
|
ret = sendcmd(true, 1, cmd); |
|
|
|
ret = _sendcmd(true, cmd); |
|
|
|
return ret == 0; |
|
|
|
} |
|
|
|
void SMTP2V2::getack(char* rx, int32_t* rxbufsize) { |
|
|
@ -228,28 +232,96 @@ int32_t SMTP2V2::getAck0AsInt() { |
|
|
|
int intval = atoi(&m_rxprocessbuf[3]); |
|
|
|
return intval; |
|
|
|
} |
|
|
|
int32_t SMTP2V2::runaction(bool dump, const char* format, ...) { |
|
|
|
static char cmdbuf[256]; |
|
|
|
va_list args; |
|
|
|
va_start(args, format); |
|
|
|
vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); |
|
|
|
va_end(args); |
|
|
|
return _runaction(dump, cmdbuf); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t SMTP2V2::sendcmd(bool dump, int auto_retry_times, const char* format, ...) { |
|
|
|
static char buf[256]; |
|
|
|
int32_t SMTP2V2::_runaction(bool dump, const char* cmd) { |
|
|
|
for (size_t i = 0; i < 3; i++) { |
|
|
|
if (i != 0) { |
|
|
|
ZLOGE(TAG, "resend cmd ......................................................."); |
|
|
|
osDelay(10); |
|
|
|
} |
|
|
|
|
|
|
|
if (!_sendcmd(dump, "/1T\r")) continue; |
|
|
|
if (!_sendcmd(dump, "/1CR\r")) continue; |
|
|
|
if (!_sendcmd(dump, cmd)) continue; |
|
|
|
return getAckEcode(); |
|
|
|
} |
|
|
|
return getAckEcode(); |
|
|
|
} |
|
|
|
int32_t SMTP2V2::readstate(bool dump, const char* format, ...) { |
|
|
|
static char cmdbuf[256]; |
|
|
|
va_list args; |
|
|
|
va_start(args, format); |
|
|
|
vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); |
|
|
|
va_end(args); |
|
|
|
|
|
|
|
for (size_t i = 0; i < 3; i++) { |
|
|
|
if (_sendcmd(dump, cmdbuf)) { |
|
|
|
return getAckEcode(); |
|
|
|
} |
|
|
|
osDelay(20); |
|
|
|
} |
|
|
|
return getAckEcode(); |
|
|
|
} |
|
|
|
int32_t SMTP2V2::setstate(bool dump, const char* format, ...) { |
|
|
|
static char cmdbuf[256]; |
|
|
|
va_list args; |
|
|
|
va_start(args, format); |
|
|
|
vsnprintf(buf, sizeof(buf), format, args); |
|
|
|
vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); |
|
|
|
va_end(args); |
|
|
|
|
|
|
|
sendcmd_auto_retry(dump, auto_retry_times, buf); |
|
|
|
for (size_t i = 0; i < 3; i++) { |
|
|
|
if (_sendcmd(dump, cmdbuf)) { |
|
|
|
return getAckEcode(); |
|
|
|
} |
|
|
|
osDelay(20); |
|
|
|
} |
|
|
|
return getAckEcode(); |
|
|
|
} |
|
|
|
|
|
|
|
bool SMTP2V2::sendcmd_auto_retry(bool dump, int auto_retry_times, const char* cmd) { |
|
|
|
#if 0
|
|
|
|
int32_t SMTP2V2::sendcmd(bool dump, int auto_retry_times, const char* format, ...) { |
|
|
|
static char cmdbuf[256]; |
|
|
|
va_list args; |
|
|
|
va_start(args, format); |
|
|
|
vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); |
|
|
|
va_end(args); |
|
|
|
|
|
|
|
for (size_t i = 0; i < auto_retry_times; i++) { |
|
|
|
if (_sendcmd(dump, cmd)) { |
|
|
|
if (_sendcmd(dump, cmdbuf)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
osDelay(50); |
|
|
|
m_rxNum = 0; |
|
|
|
} |
|
|
|
return false; |
|
|
|
return getAckEcode(); |
|
|
|
} |
|
|
|
int32_t SMTP2V2::send_action_cmd(bool dump, int auto_retry_times, const char* format, ...) { |
|
|
|
static char cmdbuf[256]; |
|
|
|
va_list args; |
|
|
|
va_start(args, format); |
|
|
|
vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); |
|
|
|
va_end(args); |
|
|
|
|
|
|
|
for (size_t i = 0; i < auto_retry_times; i++) { |
|
|
|
if (_sendcmd(dump, cmdbuf)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "send_action_cmd retry %d", i); |
|
|
|
osDelay(10); |
|
|
|
sendcmd(true, 2, "/1TR\r"); |
|
|
|
osDelay(20); |
|
|
|
} |
|
|
|
return getAckEcode(); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
static const char* hex2str(const char* hex, size_t len) { |
|
|
|
static char buf[256]; |
|
|
@ -259,6 +331,7 @@ static const char* hex2str(const char* hex, size_t len) { |
|
|
|
} |
|
|
|
return buf; |
|
|
|
} |
|
|
|
|
|
|
|
bool SMTP2V2::_sendcmd(bool dump, const char* cmd) { |
|
|
|
m_rxNum = 0; |
|
|
|
|
|
|
|