24
24
#include " esp3d.h"
25
25
#include " esp3d_settings.h"
26
26
27
+ #if defined(ESP_LOG_FEATURE)
28
+ const char * esp3dclientstr[]={
29
+ " no_client" ,
30
+ " serial" ,
31
+ " usb_serial" ,
32
+ " stream" ,
33
+ " telnet" ,
34
+ " http" ,
35
+ " webui_websocket" ,
36
+ " websocket" ,
37
+ " rendering" ,
38
+ " bluetooth" ,
39
+ " socket_serial" ,
40
+ " echo_serial" ,
41
+ " serial_bridge" ,
42
+ " remote_screen" ,
43
+ " mks_serial" ,
44
+ " command" ,
45
+ " system" ,
46
+ " all_clients"
47
+ };
48
+ #define GETCLIENTSTR (id ) static_cast <uint8_t >(id)>=0 && static_cast <uint8_t >(id)<=static_cast <uint8_t >(ESP3DClientType::all_clients)?esp3dclientstr[static_cast <uint8_t >(id)] :" Out of index"
49
+
50
+ const char * esp3dmsgstr[] = {
51
+ " head" , " core" , " tail" , " unique"
52
+ };
53
+ #define GETMSGTYPESTR (id ) static_cast <uint8_t >(id)>=0 && static_cast <uint8_t >(id)<=static_cast <uint8_t >(ESP3DMessageType::unique)?esp3dmsgstr[static_cast <uint8_t >(id)] :" Out of index"
54
+
55
+ #endif // defined(ESP_LOG_FEATURE)
56
+
57
+
27
58
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
28
59
#include " ../modules/mks/mks_service.h"
29
60
#endif // COMMUNICATION_PROTOCOL == MKS_SERIAL
@@ -1180,16 +1211,19 @@ bool ESP3DCommands::dispatch(const char *sbuf, ESP3DClientType target,
1180
1211
ESP3DClientType ESP3DCommands::getOutputClient (bool fromSettings) {
1181
1212
// TODO: add setting for it when necessary
1182
1213
(void )fromSettings;
1214
+ esp3d_log (" OutputClient: %d %s" , static_cast <uint8_t >(_output_client), GETCLIENTSTR (_output_client));
1183
1215
return _output_client;
1184
1216
}
1185
1217
1186
1218
bool ESP3DCommands::dispatch (ESP3DMessage *msg) {
1187
1219
bool sendOk = true ;
1188
1220
String tmp;
1189
- esp3d_log (" Dispatch message origin %d to client %d , size: %d, type: %d" ,
1221
+ esp3d_log (" Dispatch message origin %d(%s) to client %d(%s) , size: %d, type: %d(%s) " ,
1190
1222
static_cast <uint8_t >(msg->origin ),
1191
- static_cast <uint8_t >(msg->target ), msg->size ,
1192
- static_cast <uint8_t >(msg->type ));
1223
+ esp3dclientstr[static_cast <uint8_t >(msg->origin )],
1224
+ static_cast <uint8_t >(msg->target ), GETCLIENTSTR (msg->target ),
1225
+ msg->size , static_cast <uint8_t >(msg->type ),GETMSGTYPESTR (msg->type ));
1226
+ esp3d_log (" Dispatch message data: %s" , (const char *)msg->data );
1193
1227
if (!msg) {
1194
1228
esp3d_log_e (" no msg" );
1195
1229
return false ;
@@ -1199,6 +1233,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1199
1233
switch (msg->target ) {
1200
1234
#if COMMUNICATION_PROTOCOL == RAW_SERIAL
1201
1235
case ESP3DClientType::serial:
1236
+ esp3d_log (" Serial message" );
1202
1237
if (!esp3d_serial_service.dispatch (msg)) {
1203
1238
sendOk = false ;
1204
1239
esp3d_log_e (" Serial dispatch failed" );
@@ -1208,6 +1243,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1208
1243
1209
1244
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
1210
1245
case ESP3DClientType::echo_serial:
1246
+ esp3d_log (" Echo serial message" );
1211
1247
MYSERIAL1.write (msg->data , msg->size );
1212
1248
if (msg->type == ESP3DMessageType::unique || msg->type == ESP3DMessageType::tail) {
1213
1249
if (msg->data [msg->size -1 ]!=' \n ' ){
@@ -1216,10 +1252,19 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1216
1252
}
1217
1253
ESP3DMessageManager::deleteMsg (msg);
1218
1254
break ;
1255
+
1256
+ case ESP3DClientType::socket_serial:
1257
+ esp3d_log (" Socket serial message" );
1258
+ if (!Serial2Socket.dispatch (msg)) {
1259
+ sendOk = false ;
1260
+ esp3d_log_e (" Socket dispatch failed" );
1261
+ }
1262
+ break ;
1219
1263
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
1220
1264
1221
1265
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
1222
1266
case ESP3DClientType::serial_bridge:
1267
+ esp3d_log (" Serial bridge message" );
1223
1268
if (!serial_bridge_service.dispatch (msg)) {
1224
1269
sendOk = false ;
1225
1270
esp3d_log_e (" Serial bridge dispatch failed" );
@@ -1229,6 +1274,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1229
1274
1230
1275
#ifdef WS_DATA_FEATURE
1231
1276
case ESP3DClientType::websocket:
1277
+ esp3d_log (" Websocket message" );
1232
1278
if (!websocket_data_server.dispatch (msg)) {
1233
1279
sendOk = false ;
1234
1280
esp3d_log_e (" Telnet dispatch failed" );
@@ -1238,6 +1284,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1238
1284
1239
1285
#ifdef TELNET_FEATURE
1240
1286
case ESP3DClientType::telnet:
1287
+ esp3d_log (" Telnet message" );
1241
1288
if (!telnet_server.dispatch (msg)) {
1242
1289
sendOk = false ;
1243
1290
esp3d_log_e (" Telnet dispatch failed" );
@@ -1247,30 +1294,24 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1247
1294
1248
1295
#ifdef BLUETOOTH_FEATURE
1249
1296
case ESP3DClientType::bluetooth:
1297
+ esp3d_log (" Bluetooth message" );
1250
1298
if (!bt_service.dispatch (msg)) {
1251
1299
sendOk = false ;
1252
1300
esp3d_log_e (" Bluetooth dispatch failed" );
1253
1301
}
1254
1302
break ;
1255
1303
#endif // BLUETOOTH_FEATURE
1256
1304
1257
- #if defined(ESP3DLIB_ENV) && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
1258
- case ESP3DClientType::socket_serial:
1259
- if (!Serial2Socket.dispatch (msg)) {
1260
- sendOk = false ;
1261
- esp3d_log_e (" Socket dispatch failed" );
1262
- }
1263
- break ;
1264
- #endif // defined(ESP3DLIB_ENV) && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
1265
-
1266
1305
#ifdef HTTP_FEATURE
1267
1306
case ESP3DClientType::webui_websocket:
1307
+ esp3d_log (" Webui websocket message" );
1268
1308
if (!websocket_terminal_server.dispatch (msg)) {
1269
1309
sendOk = false ;
1270
1310
esp3d_log_e (" Webui websocket dispatch failed" );
1271
1311
}
1272
1312
break ;
1273
1313
case ESP3DClientType::http:
1314
+ esp3d_log (" Http message" );
1274
1315
if (!HTTP_Server::dispatch (msg)) {
1275
1316
sendOk = false ;
1276
1317
esp3d_log_e (" Webui websocket dispatch failed" );
@@ -1279,6 +1320,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1279
1320
#endif // HTTP_FEATURE
1280
1321
#if defined(DISPLAY_DEVICE)
1281
1322
case ESP3DClientType::rendering:
1323
+ esp3d_log (" Rendering message" );
1282
1324
if (!esp3d_display.dispatch (msg)) {
1283
1325
sendOk = false ;
1284
1326
esp3d_log_e (" Display dispatch failed" );
@@ -1288,6 +1330,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1288
1330
1289
1331
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
1290
1332
case ESP3DClientType::mks_serial:
1333
+ esp3d_log (" MKS Serial message" );
1291
1334
if (!MKSService::dispatch (msg)) {
1292
1335
sendOk = false ;
1293
1336
esp3d_log_e (" MKS Serial dispatch failed" );
@@ -1297,6 +1340,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1297
1340
1298
1341
#ifdef PRINTER_HAS_DISPLAY
1299
1342
case ESP3DClientType::remote_screen:
1343
+ esp3d_log (" Remote screen message" );
1300
1344
// change target to output client
1301
1345
msg->target = getOutputClient ();
1302
1346
// change text to GCODE M117
@@ -1315,6 +1359,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1315
1359
break ;
1316
1360
#endif // PRINTER_HAS_DISPLAY
1317
1361
case ESP3DClientType::all_clients:
1362
+ esp3d_log (" All clients message" );
1318
1363
// Add each client one by one
1319
1364
#ifdef PRINTER_HAS_DISPLAY
1320
1365
if (msg->origin != ESP3DClientType::remote_screen &&
@@ -1410,6 +1455,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1410
1455
#endif // ESP_SERIAL_BRIDGE_OUTPUT
1411
1456
1412
1457
#ifdef BLUETOOTH_FEATURE
1458
+ // FIXME: add test if connected to avoid unnecessary copy
1413
1459
if (msg->origin != ESP3DClientType::bluetooth) {
1414
1460
String msgstr = (const char *)msg->data ;
1415
1461
msgstr.trim ();
@@ -1432,7 +1478,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1432
1478
#endif // BLUETOOTH_FEATURE
1433
1479
1434
1480
#ifdef TELNET_FEATURE
1435
- if (msg->origin != ESP3DClientType::telnet) {
1481
+ if (msg->origin != ESP3DClientType::telnet && telnet_server. isConnected () ) {
1436
1482
String msgstr = (const char *)msg->data ;
1437
1483
msgstr.trim ();
1438
1484
if (msgstr.length () > 0 ) {
@@ -1455,6 +1501,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1455
1501
1456
1502
#ifdef HTTP_FEATURE // http cannot be in all client because it depend of any
1457
1503
// connection of the server
1504
+ // FIXME: add test if connected to avoid unnecessary copy
1458
1505
if (msg->origin != ESP3DClientType::webui_websocket) {
1459
1506
String msgstr = (const char *)msg->data ;
1460
1507
msgstr.trim ();
@@ -1477,6 +1524,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1477
1524
#endif // HTTP_FEATURE
1478
1525
1479
1526
#ifdef WS_DATA_FEATURE
1527
+ // FIXME: add test if connected to avoid unnecessary copy
1480
1528
if (msg->origin != ESP3DClientType::websocket) {
1481
1529
String msgstr = (const char *)msg->data ;
1482
1530
msgstr.trim ();
@@ -1514,7 +1562,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
1514
1562
}
1515
1563
// clear message
1516
1564
if (!sendOk) {
1517
- esp3d_log (" Send msg failed" );
1565
+ esp3d_log_e (" Send msg failed" );
1518
1566
ESP3DMessageManager::deleteMsg (msg);
1519
1567
}
1520
1568
return sendOk;
0 commit comments