@@ -1144,8 +1144,8 @@ void ESP3DCommands::process(ESP3DMessage *msg) {
1144
1144
esp3d_log (" Execute internal command %d" , cmdId);
1145
1145
execute_internal_command (cmdId, espcmdpos, msg);
1146
1146
} else {
1147
- esp3d_log (" Dispatch command, len %d, to %d" , msg->size ,
1148
- static_cast <uint8_t >(msg->target ));
1147
+ esp3d_log (" Dispatch command, len %d, from %d(%s) to %d(%s) " , msg->size ,
1148
+ static_cast <uint8_t >(msg->origin ), GETCLIENTSTR (msg-> origin ), static_cast < uint8_t >(msg-> target ), GETCLIENTSTR (msg-> target ));
1149
1149
1150
1150
// Work around to avoid to dispatch single \n or \r to everyone as it is
1151
1151
// part of previous ESP3D command
@@ -1359,14 +1359,11 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1359
1359
break ;
1360
1360
#endif // PRINTER_HAS_DISPLAY
1361
1361
case ESP3DClientType::all_clients:
1362
- esp3d_log (" All clients message" );
1362
+ esp3d_log (" All clients message" );
1363
1363
// Add each client one by one
1364
1364
#ifdef PRINTER_HAS_DISPLAY
1365
1365
if (msg->origin != ESP3DClientType::remote_screen &&
1366
1366
msg->origin != getOutputClient ()) {
1367
- String msgstr = (const char *)msg->data ;
1368
- msgstr.trim ();
1369
- if (msgstr.length () > 0 ) {
1370
1367
if (msg->target == ESP3DClientType::all_clients) {
1371
1368
// become the reference message
1372
1369
msg->target = ESP3DClientType::remote_screen;
@@ -1380,16 +1377,12 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1380
1377
esp3d_log_e (" Cannot duplicate message for remote screen" );
1381
1378
}
1382
1379
}
1383
- }
1384
1380
}
1385
1381
#endif // PRINTER_HAS_DISPLAY
1386
1382
1387
1383
#if defined(DISPLAY_DEVICE)
1388
1384
if (msg->origin != ESP3DClientType::rendering &&
1389
1385
msg->origin != getOutputClient ()) {
1390
- String msgstr = (const char *)msg->data ;
1391
- msgstr.trim ();
1392
- if (msgstr.length () > 0 ) {
1393
1386
if (msg->target == ESP3DClientType::all_clients) {
1394
1387
// become the reference message
1395
1388
msg->target = ESP3DClientType::rendering;
@@ -1405,16 +1398,12 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1405
1398
esp3d_log_e (" Cannot duplicate message for display" );
1406
1399
}
1407
1400
}
1408
- }
1409
1401
}
1410
1402
#endif // defined(DISPLAY_DEVICE)
1411
1403
1412
1404
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
1413
1405
if (msg->origin != ESP3DClientType::echo_serial &&
1414
1406
msg->origin != ESP3DClientType::socket_serial) {
1415
- String msgstr = (const char *)msg->data ;
1416
- msgstr.trim ();
1417
- if (msgstr.length () > 0 ) {
1418
1407
if (msg->target == ESP3DClientType::all_clients) {
1419
1408
// become the reference message
1420
1409
msg->target = ESP3DClientType::echo_serial;
@@ -1428,15 +1417,11 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1428
1417
esp3d_log_e (" Cannot duplicate message for echo serial" );
1429
1418
}
1430
1419
}
1431
- }
1432
1420
}
1433
1421
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
1434
1422
1435
1423
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
1436
1424
if (msg->origin != ESP3DClientType::serial_bridge) {
1437
- String msgstr = (const char *)msg->data ;
1438
- msgstr.trim ();
1439
- if (msgstr.length () > 0 ) {
1440
1425
if (msg->target == ESP3DClientType::all_clients) {
1441
1426
// become the reference message
1442
1427
msg->target = ESP3DClientType::serial_bridge;
@@ -1450,16 +1435,11 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1450
1435
esp3d_log_e (" Cannot duplicate message for serial bridge" );
1451
1436
}
1452
1437
}
1453
- }
1454
1438
}
1455
1439
#endif // ESP_SERIAL_BRIDGE_OUTPUT
1456
1440
1457
1441
#ifdef BLUETOOTH_FEATURE
1458
- // FIXME: add test if connected to avoid unnecessary copy
1459
- if (msg->origin != ESP3DClientType::bluetooth) {
1460
- String msgstr = (const char *)msg->data ;
1461
- msgstr.trim ();
1462
- if (msgstr.length () > 0 ) {
1442
+ if (msg->origin != ESP3DClientType::bluetooth && bt_service.isConnected ()) {
1463
1443
if (msg->target == ESP3DClientType::all_clients) {
1464
1444
// become the reference message
1465
1445
msg->target = ESP3DClientType::bluetooth;
@@ -1473,15 +1453,11 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1473
1453
esp3d_log_e (" Cannot duplicate message for bluetooth" );
1474
1454
}
1475
1455
}
1476
- }
1477
1456
}
1478
1457
#endif // BLUETOOTH_FEATURE
1479
1458
1480
1459
#ifdef TELNET_FEATURE
1481
1460
if (msg->origin != ESP3DClientType::telnet && telnet_server.isConnected ()) {
1482
- String msgstr = (const char *)msg->data ;
1483
- msgstr.trim ();
1484
- if (msgstr.length () > 0 ) {
1485
1461
if (msg->target == ESP3DClientType::all_clients) {
1486
1462
// become the reference message
1487
1463
msg->target = ESP3DClientType::telnet;
@@ -1495,17 +1471,14 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1495
1471
esp3d_log_e (" Cannot duplicate message for telnet" );
1496
1472
}
1497
1473
}
1498
- }
1474
+ } else {
1475
+ if (msg->origin != ESP3DClientType::telnet)esp3d_log (" Telnet not connected" );
1499
1476
}
1500
1477
#endif // TELNET_FEATURE
1501
1478
1502
1479
#ifdef HTTP_FEATURE // http cannot be in all client because it depend of any
1503
1480
// connection of the server
1504
- // FIXME: add test if connected to avoid unnecessary copy
1505
- if (msg->origin != ESP3DClientType::webui_websocket) {
1506
- String msgstr = (const char *)msg->data ;
1507
- msgstr.trim ();
1508
- if (msgstr.length () > 0 ) {
1481
+ if (msg->origin != ESP3DClientType::webui_websocket && websocket_terminal_server.isConnected ()) {
1509
1482
if (msg->target == ESP3DClientType::all_clients) {
1510
1483
// become the reference message
1511
1484
msg->target = ESP3DClientType::webui_websocket;
@@ -1519,16 +1492,13 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1519
1492
esp3d_log_e (" Cannot duplicate message for webui_websocket" );
1520
1493
}
1521
1494
}
1522
- }
1495
+ } else {
1496
+ if (msg->origin != ESP3DClientType::webui_websocket)esp3d_log (" Webui websocket not connected" );
1523
1497
}
1524
1498
#endif // HTTP_FEATURE
1525
1499
1526
1500
#ifdef WS_DATA_FEATURE
1527
- // FIXME: add test if connected to avoid unnecessary copy
1528
- if (msg->origin != ESP3DClientType::websocket) {
1529
- String msgstr = (const char *)msg->data ;
1530
- msgstr.trim ();
1531
- if (msgstr.length () > 0 ) {
1501
+ if (msg->origin != ESP3DClientType::websocket && websocket_data_server.isConnected ()) {
1532
1502
if (msg->target == ESP3DClientType::all_clients) {
1533
1503
// become the reference message
1534
1504
msg->target = ESP3DClientType::websocket;
@@ -1542,14 +1512,16 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1542
1512
esp3d_log_e (" Cannot duplicate message for websocket" );
1543
1513
}
1544
1514
}
1545
- }
1515
+ } else {
1516
+ if (msg->origin != ESP3DClientType::websocket)esp3d_log (" Websocket not connected" );
1546
1517
}
1547
1518
#endif // WS_DATA_FEATURE
1548
1519
1549
1520
// ...
1550
1521
1551
1522
// Send pending if any or cancel message is no client did handle it
1552
1523
if (msg->target == ESP3DClientType::all_clients) {
1524
+ esp3d_log (" No client handled message, send pending" );
1553
1525
sendOk = false ;
1554
1526
} else {
1555
1527
return dispatch (msg);
0 commit comments