Skip to content

Commit 2d42348

Browse files
committed
Remove debug statements
Add more flexible ack detection in case of data corruption
1 parent c192036 commit 2d42348

File tree

4 files changed

+31
-29
lines changed

4 files changed

+31
-29
lines changed

hardware/drivers_usb_otg/usb_serial/usb_serial.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ void usb_lib_task(void *arg) {
4242
try {
4343
usb_host_lib_handle_events(portMAX_DELAY, &event_flags);
4444
} catch (...) {
45-
esp3d_log_d("Error handling usb event");
45+
esp3d_log("Error handling usb event");
4646
}
4747
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) {
4848
if (ESP_OK != usb_host_device_free_all()) {
4949
esp3d_log_e("Failed to free all devices");
5050
}
5151
}
5252
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE) {
53-
esp3d_log_d("USB: All devices freed");
53+
esp3d_log("USB: All devices freed");
5454
// Continue handling USB events to allow device reconnection
5555
}
5656
}
@@ -106,7 +106,7 @@ esp_err_t usb_serial_init() {
106106
//.enum_filter_cb = NULL,
107107
};
108108
// Install USB Host driver. Should only be called once in entire application
109-
esp3d_log_d("Installing USB Host");
109+
esp3d_log("Installing USB Host");
110110
esp_err_t err = usb_host_install(&host_config);
111111
if (err != ESP_OK) {
112112
esp3d_log_e("Failed to install USB Host %s", esp_err_to_name(err));
@@ -133,14 +133,14 @@ esp_err_t usb_serial_create_task() {
133133
NULL, ESP3D_USB_LIB_TASK_PRIORITY,
134134
&usb_serial_xHandle, ESP3D_USB_LIB_TASK_CORE);
135135
if (res == pdPASS && usb_serial_xHandle) {
136-
esp3d_log_d("Installing CDC-ACM driver");
136+
esp3d_log("Installing CDC-ACM driver");
137137
if (cdc_acm_host_install(NULL) == ESP_OK) {
138138
// Register VCP drivers to VCP service.
139-
esp3d_log_d("Registering FT23x driver");
139+
esp3d_log("Registering FT23x driver");
140140
esp_usb::VCP::register_driver<esp_usb::FT23x>();
141-
esp3d_log_d("Registering CP210x driver");
141+
esp3d_log("Registering CP210x driver");
142142
esp_usb::VCP::register_driver<esp_usb::CP210x>();
143-
esp3d_log_d("Registering CH34x driver");
143+
esp3d_log("Registering CH34x driver");
144144
esp_usb::VCP::register_driver<esp_usb::CH34x>();
145145
return ESP_OK;
146146
} else {

main/modules/usb_serial/esp3d_usb_serial_client.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx) {
8585
#endif // ESP3D_HTTP_FEATURE
8686
break;
8787
case CDC_ACM_HOST_DEVICE_DISCONNECTED:
88-
esp3d_log_d("Device suddenly disconnected");
88+
esp3d_log("Device suddenly disconnected");
8989
usbSerialClient.setConnected(false);
9090
break;
9191
case CDC_ACM_HOST_SERIAL_STATE:
92-
esp3d_log_d("Serial state notif 0x%04X", event->data.serial_state.val);
92+
esp3d_log("Serial state notif 0x%04X", event->data.serial_state.val);
9393
break;
9494
case CDC_ACM_HOST_NETWORK_CONNECTION:
9595
default:
@@ -130,15 +130,15 @@ void ESP3DUsbSerialClient::connectDevice() {
130130

131131
esp3d_hal::wait(10);
132132

133-
esp3d_log_d("USB device found");
133+
esp3d_log("USB device found");
134134

135135
if (_vcp_ptr->line_coding_set(&line_coding) == ESP_OK) {
136-
esp3d_log_d("USB Connected");
136+
esp3d_log("USB Connected");
137137
usbSerialClient.setConnected(true);
138138
esp3d_hal::wait(10);
139139
_vcp_ptr = nullptr;
140140
} else {
141-
esp3d_log_d("USB device not identified");
141+
esp3d_log("USB device not identified");
142142
}
143143
}
144144

@@ -152,7 +152,7 @@ static void esp3d_usb_serial_connection_task(void *pvParameter) {
152152
if (usbSerialClient.started()) {
153153
usbSerialClient.connectDevice();
154154
} else {
155-
esp3d_log_d("USB serial client not started");
155+
esp3d_log("USB serial client not started");
156156
}
157157

158158
}
@@ -164,7 +164,7 @@ void ESP3DUsbSerialClient::setConnected(bool connected) {
164164
_connected = connected;
165165

166166
if (_connected) {
167-
esp3d_log_d("USB device connected");
167+
esp3d_log("USB device connected");
168168
#if ESP3D_HTTP_FEATURE
169169
esp3dWsWebUiService.pushNotification("Connected");
170170
#endif // ESP3D_HTTP_FEATURE
@@ -173,7 +173,7 @@ void ESP3DUsbSerialClient::setConnected(bool connected) {
173173
_connected=false;
174174
}
175175
} else {
176-
esp3d_log_d("USB device disconnected");
176+
esp3d_log("USB device disconnected");
177177
#if ESP3D_HTTP_FEATURE
178178
esp3dWsWebUiService.pushNotification("Disconnected");
179179
#endif // ESP3D_HTTP_FEATURE
@@ -195,7 +195,7 @@ ESP3DUsbSerialClient::ESP3DUsbSerialClient() {
195195
ESP3DUsbSerialClient::~ESP3DUsbSerialClient() { end(); }
196196

197197
void ESP3DUsbSerialClient::process(ESP3DMessage *msg) {
198-
esp3d_log_d("Add message to queue");
198+
esp3d_log("Add message to queue");
199199
if (!addTxData(msg)) {
200200
flush();
201201
if (!addTxData(msg)) {
@@ -244,7 +244,7 @@ bool ESP3DUsbSerialClient::begin() {
244244
_baudrate = esp3dTftsettings.getDefaultIntegerSetting(
245245
ESP3DSettingIndex::esp3d_usb_serial_baud_rate);
246246
}
247-
esp3d_log_d("Use %ld USB Serial Baud Rate", _baudrate);
247+
esp3d_log("Use %ld USB Serial Baud Rate", _baudrate);
248248

249249
// Serial is never stopped so no need to kill the task from outside
250250
_started = true;
@@ -254,8 +254,8 @@ bool ESP3DUsbSerialClient::begin() {
254254
&_xHandle, ESP3D_USB_SERIAL_TASK_CORE);
255255

256256
if (res == pdPASS && _xHandle) {
257-
esp3d_log_d("Created USB Serial Connection Task");
258-
esp3d_log_d("USB serial client started");
257+
esp3d_log("Created USB Serial Connection Task");
258+
esp3d_log("USB serial client started");
259259
flush();
260260
return true;
261261
} else {
@@ -303,13 +303,13 @@ void ESP3DUsbSerialClient::handle() {
303303
if (getTxMsgsCount() > 0) {
304304
ESP3DMessage *msg = popTx();
305305
if (msg) {
306-
esp3d_log_d("Got message to send");
306+
esp3d_log("Got message to send");
307307
if (_connected) {
308-
esp3d_log_d("Send message");
308+
esp3d_log("Send message");
309309
// TODO: check if msg->size < ESP3D_USB_SERIAL_TX_BUFFER_SIZE
310310
if (_vcp_ptr && _vcp_ptr->tx_blocking(msg->data, msg->size) == ESP_OK) {
311311
if (!(_vcp_ptr && _vcp_ptr->set_control_line_state(true, true) == ESP_OK)) {
312-
esp3d_log_d("Failed set line");
312+
esp3d_log("Failed set line");
313313
}
314314
} else {
315315
esp3d_log_e("Failed to send message");
@@ -328,9 +328,9 @@ void ESP3DUsbSerialClient::end() {
328328
if (_started) {
329329
flush();
330330
_started = false;
331-
esp3d_log_d("Clearing queue Rx messages");
331+
esp3d_log("Clearing queue Rx messages");
332332
clearRxQueue();
333-
esp3d_log_d("Clearing queue Tx messages");
333+
esp3d_log("Clearing queue Tx messages");
334334
clearTxQueue();
335335
esp3d_hal::wait(1000);
336336
if (pthread_mutex_destroy(&_tx_mutex) != 0) {
@@ -339,7 +339,7 @@ void ESP3DUsbSerialClient::end() {
339339
if (pthread_mutex_destroy(&_rx_mutex) != 0) {
340340
esp3d_log_w("Mutex destruction for rx failed");
341341
}
342-
esp3d_log_d("Uninstalling USB Serial drivers");
342+
esp3d_log("Uninstalling USB Serial drivers");
343343
setConnected(false);
344344
vSemaphoreDelete(_device_disconnected_sem);
345345
_device_disconnected_sem = NULL;

main/target/3dprinter/marlin/esp3d_gcode_parser_service.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ ESP3DDataType ESP3DGCodeParserService::getType(const char* data) {
408408
}
409409

410410
// is it ack ?
411-
if ((ptr[0] == 'o' && ptr[1] == 'k') &&
412-
(ptr[2] == '\n' || ptr[2] == '\r' || ptr[2] == ' ' || ptr[2] == 0x0)) {
411+
if (((ptr[0] == 'o' && ptr[1] == 'k') &&
412+
(ptr[2] == '\n' || ptr[2] == '\r' || ptr[2] == ' ' || ptr[2] == 0x0)) || strstr(ptr, "ok") != nullptr) {
413+
esp3d_log_d("Ack found in %s", ptr);
413414
return ESP3DDataType::ack;
414415
}
415416

main/target/3dprinter/repetier/esp3d_gcode_parser_service.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ ESP3DDataType ESP3DGCodeParserService::getType(const char* data) {
408408
}
409409

410410
// is it ack ?
411-
if ((ptr[0] == 'o' && ptr[1] == 'k') &&
412-
(ptr[2] == '\n' || ptr[2] == '\r' || ptr[2] == ' ' || ptr[2] == 0x0)) {
411+
if (((ptr[0] == 'o' && ptr[1] == 'k') &&
412+
(ptr[2] == '\n' || ptr[2] == '\r' || ptr[2] == ' ' || ptr[2] == 0x0))|| strstr(ptr, "ok")!= nullptr) {
413+
esp3d_log("Ack found in %s", ptr);
413414
return ESP3DDataType::ack;
414415
}
415416

0 commit comments

Comments
 (0)