|
@ -16,7 +16,7 @@ using namespace smtp2; |
|
|
#define SEND_CMD(fmt, ...) sendcmd(true, 1, "/1" fmt "R\r", ##__VA_ARGS__);
|
|
|
#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_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__);
|
|
|
#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) { |
|
|
void SMTP2V2::initialize(UART_HandleTypeDef* uart, uint8_t id, DMA_HandleTypeDef* hdma_rx, DMA_HandleTypeDef* hdma_tx) { |
|
|
m_uart = uart; |
|
|
m_uart = uart; |
|
|
m_hdma_rx = hdma_rx; |
|
|
m_hdma_rx = hdma_rx; |
|
@ -68,14 +68,14 @@ int32_t SMTP2V2::pump_get_motor_pos_ul(int32_t* ul) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_stop() { return sendcmd(true, 1, "/1TR\r"); } |
|
|
int32_t SMTP2V2::pump_stop() { return sendcmd(true, 1, "/1TR\r"); } |
|
|
int32_t SMTP2V2::pump_set_vstart(int32_t vel) { return SEND_CMD("v%d", vel); } |
|
|
|
|
|
int32_t SMTP2V2::pump_set_vstop(int32_t vel) { return SEND_CMD("c%d", vel); } |
|
|
|
|
|
int32_t SMTP2V2::pump_set_vmax(int32_t vel) { return SEND_CMD("V%d", vel); } |
|
|
|
|
|
|
|
|
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_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_set_plld_start_delay(int32_t delay_ms) { return SEND_CMD("T%d", delay_ms); } |
|
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_put_tip() { return SEND_CMD("E1"); } |
|
|
int32_t SMTP2V2::pump_put_tip() { return SEND_CMD("E1"); } |
|
|
int32_t SMTP2V2::pump_init(int32_t v) { return SEND_CMD("V%dZ", v); } |
|
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_init(int32_t v) { return SEND_CMD("N2V%dZ", v * 319); } |
|
|
int32_t SMTP2V2::pump_reset() { |
|
|
int32_t SMTP2V2::pump_reset() { |
|
|
_sendcmd(true, "/1!0R\r"); // 复位指令没有回执,所以这里只能使用方法_sendcmd
|
|
|
_sendcmd(true, "/1!0R\r"); // 复位指令没有回执,所以这里只能使用方法_sendcmd
|
|
|
return 0; |
|
|
return 0; |
|
@ -101,25 +101,36 @@ int32_t SMTP2V2::pump_move_to_ul(int32_t v, int32_t ul) { |
|
|
* ul:0->1000 |
|
|
* ul:0->1000 |
|
|
*/ |
|
|
*/ |
|
|
ZLOGI(TAG, "pump_move_to_ul %d", ul); |
|
|
ZLOGI(TAG, "pump_move_to_ul %d", ul); |
|
|
int stepNum = ul / 0.319 + 0.5; //+0.5 是为了浮点数强转成正数时采用四舍五入的方式
|
|
|
|
|
|
return SEND_CMD("N%dV%dA%d", 0 /*模式*/, v, stepNum); |
|
|
|
|
|
|
|
|
int stepNum = ul * 1000; //+0.5 是为了浮点数强转成正数时采用四舍五入的方式
|
|
|
|
|
|
return SEND_CMD("V%dA%d", v * 319, stepNum); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_aspirate(int32_t v, int32_t ul) { |
|
|
int32_t SMTP2V2::pump_aspirate(int32_t v, int32_t ul) { |
|
|
ZLOGI(TAG, "pump_aspirate %d", ul); |
|
|
ZLOGI(TAG, "pump_aspirate %d", ul); |
|
|
int stepNum = ul / 0.319 + 0.5; |
|
|
|
|
|
return SEND_CMD("N%dV%dP%d", 0 /*模式*/, v, stepNum); |
|
|
|
|
|
|
|
|
int stepNum = ul * 1000; |
|
|
|
|
|
return SEND_CMD("V%dP%d", v * 319, stepNum); |
|
|
} |
|
|
} |
|
|
int32_t SMTP2V2::pump_distribut(int32_t v, int32_t ul) { |
|
|
int32_t SMTP2V2::pump_distribut(int32_t v, int32_t ul) { |
|
|
ZLOGI(TAG, "pump_distribut %d", ul); |
|
|
ZLOGI(TAG, "pump_distribut %d", ul); |
|
|
int stepNum = ul / 0.319 + 0.5; |
|
|
|
|
|
return SEND_CMD("N%dV%dD%d", 0 /*模式*/, v, stepNum); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t nownl = 0; |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_distribut_plld(int32_t pumpv, int32_t pressure_threshold) { |
|
|
int32_t SMTP2V2::pump_distribut_plld(int32_t pumpv, int32_t pressure_threshold) { |
|
|
// M100V100t50,0R
|
|
|
// M100V100t50,0R
|
|
|
ZLOGI(TAG, "pump_distribut_plld %d %d", pumpv, pressure_threshold); |
|
|
ZLOGI(TAG, "pump_distribut_plld %d %d", pumpv, pressure_threshold); |
|
|
return SEND_CMD("V%dt%d,0", pumpv, pressure_threshold); |
|
|
|
|
|
|
|
|
return SEND_CMD("V%dt%d,0", pumpv * 319, pressure_threshold); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int32_t SMTP2V2::pump_distribut_plld_get_state(int32_t* detected) { |
|
|
int32_t SMTP2V2::pump_distribut_plld_get_state(int32_t* detected) { |
|
@ -150,7 +161,7 @@ int32_t SMTP2V2::pump_clld_get_state(int32_t* detected) { |
|
|
// B<n1>,<n2>
|
|
|
// B<n1>,<n2>
|
|
|
int32_t SMTP2V2::pump_distribut_mlld(int32_t pumpv, int32_t c_threshold, int32_t pressure_threshold) { |
|
|
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); |
|
|
ZLOGI(TAG, "pump_distribut_mlld %d %d %d", pumpv, c_threshold, pressure_threshold); |
|
|
return SEND_CMD("V%dB%d,%d", pumpv, c_threshold, pressure_threshold); |
|
|
|
|
|
|
|
|
return SEND_CMD("V%dB%d,%d", pumpv * 319, c_threshold, pressure_threshold); |
|
|
} |
|
|
} |
|
|
int32_t SMTP2V2::pump_distribut_mlld_get_state(int32_t* detected) { |
|
|
int32_t SMTP2V2::pump_distribut_mlld_get_state(int32_t* detected) { |
|
|
int32_t isbusy; |
|
|
int32_t isbusy; |
|
@ -234,11 +245,20 @@ bool SMTP2V2::sendcmd_auto_retry(bool dump, int auto_retry_times, const char* cm |
|
|
if (_sendcmd(dump, cmd)) { |
|
|
if (_sendcmd(dump, cmd)) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
osDelay(10); |
|
|
|
|
|
|
|
|
osDelay(50); |
|
|
m_rxNum = 0; |
|
|
m_rxNum = 0; |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static const char* hex2str(const char* hex, size_t len) { |
|
|
|
|
|
static char buf[256]; |
|
|
|
|
|
memset(buf, 0, sizeof(buf)); |
|
|
|
|
|
for (size_t i = 0; i < len; i++) { |
|
|
|
|
|
sprintf(buf + i * 2, "%02X", hex[i]); |
|
|
|
|
|
} |
|
|
|
|
|
return buf; |
|
|
|
|
|
} |
|
|
bool SMTP2V2::_sendcmd(bool dump, const char* cmd) { |
|
|
bool SMTP2V2::_sendcmd(bool dump, const char* cmd) { |
|
|
m_rxNum = 0; |
|
|
m_rxNum = 0; |
|
|
|
|
|
|
|
@ -252,7 +272,7 @@ bool SMTP2V2::_sendcmd(bool dump, const char* cmd) { |
|
|
|
|
|
|
|
|
#if DUMP_HEX
|
|
|
#if DUMP_HEX
|
|
|
if (dump) { |
|
|
if (dump) { |
|
|
ZLOGI(TAG, "rx:%s", m_rxbuf); |
|
|
|
|
|
|
|
|
ZLOGI(TAG, "rx:(%d) (%s) %s", m_rxNum, hex2str(m_rxbuf, m_rxNum), m_rxbuf); |
|
|
} |
|
|
} |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
@ -286,5 +306,15 @@ bool SMTP2V2::_sendcmd_dma(const char* cmd) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
m_rxNum = SMTP2_BUF_LEN - __HAL_DMA_GET_COUNTER(m_hdma_rx); |
|
|
m_rxNum = SMTP2_BUF_LEN - __HAL_DMA_GET_COUNTER(m_hdma_rx); |
|
|
|
|
|
if (m_rxNum < 6) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
uint8_t errorcode = (uint8_t)m_rxbuf[2]; |
|
|
|
|
|
if (errorcode < '@') { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (m_rxbuf[m_rxNum - 1] != '\n' || m_rxbuf[m_rxNum - 2] != '\r' || m_rxbuf[m_rxNum - 3] != 3) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |