|
|
@ -87,15 +87,12 @@ void motor_drive_set_packages_ctr(double position) { |
|
|
|
uint8_t position_buffer_size = 5; //从第五位开始(低位) |
|
|
|
uint8_t checksum = 0; |
|
|
|
uint8_t buffer[10] = {0x3E, 0XA7, 0X01, 0X04, 0XEA, 0X00, 0X00, 0X00, 0X00, 0X00}; |
|
|
|
// uint8_t strbuffer[20] = {0}; |
|
|
|
|
|
|
|
position_int = position * 100; |
|
|
|
// ESP_LOGI(MOTOR_DRIVE, "%d", position_int); |
|
|
|
|
|
|
|
if (position_int != 0) { |
|
|
|
while ((position_int / 0XFF) > 0) { |
|
|
|
position_remainder = position_int & 0XFF; |
|
|
|
// ESP_LOGI(MOTOR_DRIVE, "position_remainder :%d", position_remainder); |
|
|
|
buffer[position_buffer_size] = position_remainder; |
|
|
|
position_buffer_size += 1; |
|
|
|
position_int = position_int >> 8; |
|
|
@ -106,21 +103,24 @@ void motor_drive_set_packages_ctr(double position) { |
|
|
|
checksum = checksum & 0XFF; |
|
|
|
buffer[9] = checksum; |
|
|
|
} |
|
|
|
// for (int i = 0; i < 10; i++) { |
|
|
|
// ESP_LOGI(MOTOR_DRIVE, "%d", buffer[i]); |
|
|
|
// } |
|
|
|
// ESP_LOGI(MOTOR_DRIVE, "0X%X", buffer[0]); |
|
|
|
// motor_drive_hex_to_str((const char *)buffer, 10, (char *)strbuffer); |
|
|
|
// ESP_LOGI(MOTOR_DRIVE, "%s", strbuffer); |
|
|
|
// ESP_LOGI(MOTOR_DRIVE, "0X%X", buffer[0]); |
|
|
|
|
|
|
|
// Send cmd |
|
|
|
uart_flush(uart_num); |
|
|
|
uart_write_bytes(uart_num, buffer, 10); |
|
|
|
|
|
|
|
position_buffer_size = 0; |
|
|
|
memset(buffer, 0, sizeof(uint8_t) * 10); |
|
|
|
|
|
|
|
// Wait uart receive,if time out return error and output log |
|
|
|
position_buffer_size = uart_read_bytes(uart_num, buffer, 13, 2000 / portTICK_RATE_MS); |
|
|
|
if (position_buffer_size != 13 || buffer[0] != 0X3E) { |
|
|
|
ESP_LOGW(MOTOR_DRIVE, "set motor size error ,buffer_size:%d,buffer[0] = 0X%x", position_buffer_size, buffer[0]); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Parse receive |
|
|
|
// motor_drive_buffer_cmd_parse(buffer); |
|
|
|
|
|
|
|
// Process the data |
|
|
|
} |
|
|
|
|
|
|
|
void motor_drive_hex_to_str(const char *hex, int hex_len, char *str) { |
|
|
|