@@ -1144,8 +1144,8 @@ void ESP3DCommands::process(ESP3DMessage *msg) {
11441144 esp3d_log (" Execute internal command %d" , cmdId);
11451145 execute_internal_command (cmdId, espcmdpos, msg);
11461146 } 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 ));
11491149
11501150 // Work around to avoid to dispatch single \n or \r to everyone as it is
11511151 // part of previous ESP3D command
@@ -1359,14 +1359,11 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
13591359 break ;
13601360#endif // PRINTER_HAS_DISPLAY
13611361 case ESP3DClientType::all_clients:
1362- esp3d_log (" All clients message" );
1362+ esp3d_log (" All clients message" );
13631363 // Add each client one by one
13641364#ifdef PRINTER_HAS_DISPLAY
13651365 if (msg->origin != ESP3DClientType::remote_screen &&
13661366 msg->origin != getOutputClient ()) {
1367- String msgstr = (const char *)msg->data ;
1368- msgstr.trim ();
1369- if (msgstr.length () > 0 ) {
13701367 if (msg->target == ESP3DClientType::all_clients) {
13711368 // become the reference message
13721369 msg->target = ESP3DClientType::remote_screen;
@@ -1380,16 +1377,12 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
13801377 esp3d_log_e (" Cannot duplicate message for remote screen" );
13811378 }
13821379 }
1383- }
13841380 }
13851381#endif // PRINTER_HAS_DISPLAY
13861382
13871383#if defined(DISPLAY_DEVICE)
13881384 if (msg->origin != ESP3DClientType::rendering &&
13891385 msg->origin != getOutputClient ()) {
1390- String msgstr = (const char *)msg->data ;
1391- msgstr.trim ();
1392- if (msgstr.length () > 0 ) {
13931386 if (msg->target == ESP3DClientType::all_clients) {
13941387 // become the reference message
13951388 msg->target = ESP3DClientType::rendering;
@@ -1405,16 +1398,12 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
14051398 esp3d_log_e (" Cannot duplicate message for display" );
14061399 }
14071400 }
1408- }
14091401 }
14101402#endif // defined(DISPLAY_DEVICE)
14111403
14121404#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
14131405 if (msg->origin != ESP3DClientType::echo_serial &&
14141406 msg->origin != ESP3DClientType::socket_serial) {
1415- String msgstr = (const char *)msg->data ;
1416- msgstr.trim ();
1417- if (msgstr.length () > 0 ) {
14181407 if (msg->target == ESP3DClientType::all_clients) {
14191408 // become the reference message
14201409 msg->target = ESP3DClientType::echo_serial;
@@ -1428,15 +1417,11 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
14281417 esp3d_log_e (" Cannot duplicate message for echo serial" );
14291418 }
14301419 }
1431- }
14321420 }
14331421#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
14341422
14351423#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
14361424 if (msg->origin != ESP3DClientType::serial_bridge) {
1437- String msgstr = (const char *)msg->data ;
1438- msgstr.trim ();
1439- if (msgstr.length () > 0 ) {
14401425 if (msg->target == ESP3DClientType::all_clients) {
14411426 // become the reference message
14421427 msg->target = ESP3DClientType::serial_bridge;
@@ -1450,16 +1435,11 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
14501435 esp3d_log_e (" Cannot duplicate message for serial bridge" );
14511436 }
14521437 }
1453- }
14541438 }
14551439#endif // ESP_SERIAL_BRIDGE_OUTPUT
14561440
14571441#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 ()) {
14631443 if (msg->target == ESP3DClientType::all_clients) {
14641444 // become the reference message
14651445 msg->target = ESP3DClientType::bluetooth;
@@ -1473,15 +1453,11 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
14731453 esp3d_log_e (" Cannot duplicate message for bluetooth" );
14741454 }
14751455 }
1476- }
14771456 }
14781457#endif // BLUETOOTH_FEATURE
14791458
14801459#ifdef TELNET_FEATURE
14811460 if (msg->origin != ESP3DClientType::telnet && telnet_server.isConnected ()) {
1482- String msgstr = (const char *)msg->data ;
1483- msgstr.trim ();
1484- if (msgstr.length () > 0 ) {
14851461 if (msg->target == ESP3DClientType::all_clients) {
14861462 // become the reference message
14871463 msg->target = ESP3DClientType::telnet;
@@ -1495,17 +1471,14 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
14951471 esp3d_log_e (" Cannot duplicate message for telnet" );
14961472 }
14971473 }
1498- }
1474+ } else {
1475+ if (msg->origin != ESP3DClientType::telnet)esp3d_log (" Telnet not connected" );
14991476 }
15001477#endif // TELNET_FEATURE
15011478
15021479#ifdef HTTP_FEATURE // http cannot be in all client because it depend of any
15031480 // 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 ()) {
15091482 if (msg->target == ESP3DClientType::all_clients) {
15101483 // become the reference message
15111484 msg->target = ESP3DClientType::webui_websocket;
@@ -1519,16 +1492,13 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
15191492 esp3d_log_e (" Cannot duplicate message for webui_websocket" );
15201493 }
15211494 }
1522- }
1495+ } else {
1496+ if (msg->origin != ESP3DClientType::webui_websocket)esp3d_log (" Webui websocket not connected" );
15231497 }
15241498#endif // HTTP_FEATURE
15251499
15261500#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 ()) {
15321502 if (msg->target == ESP3DClientType::all_clients) {
15331503 // become the reference message
15341504 msg->target = ESP3DClientType::websocket;
@@ -1542,14 +1512,16 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
15421512 esp3d_log_e (" Cannot duplicate message for websocket" );
15431513 }
15441514 }
1545- }
1515+ } else {
1516+ if (msg->origin != ESP3DClientType::websocket)esp3d_log (" Websocket not connected" );
15461517 }
15471518#endif // WS_DATA_FEATURE
15481519
15491520 // ...
15501521
15511522 // Send pending if any or cancel message is no client did handle it
15521523 if (msg->target == ESP3DClientType::all_clients) {
1524+ esp3d_log (" No client handled message, send pending" );
15531525 sendOk = false ;
15541526 } else {
15551527 return dispatch (msg);
0 commit comments