Skip to content

Commit abd3a0c

Browse files
committed
Sync with latest ESP3D - fix Websocket overload
1 parent 7bee09b commit abd3a0c

19 files changed

+211
-54
lines changed

src/core/commands/ESP0.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ const char* help[] = {
102102
"[ESP210](type=NONE/xxx) (interval=xxxx) - display and read/set SENSOR "
103103
"info",
104104
#endif // SENSOR_DEVICE
105+
#if defined(PRINTER_HAS_DISPLAY)
106+
"[ESP212](text) - display (text) to printer screen status",
107+
#endif // PRINTER_HAS_DISPLAY
105108
#if defined(DISPLAY_DEVICE)
106109
"[ESP214](text) - display (text) to ESP screen status",
107110
#if defined(DISPLAY_TOUCH_DRIVER)
@@ -240,6 +243,9 @@ const uint cmdlist[] = {
240243
#ifdef SENSOR_DEVICE
241244
210,
242245
#endif // SENSOR_DEVICE
246+
#if defined(PRINTER_HAS_DISPLAY)
247+
212,
248+
#endif // PRINTER_HAS_DISPLAY
243249
#if defined(DISPLAY_DEVICE)
244250
214,
245251
#if defined(DISPLAY_TOUCH_DRIVER)

src/core/commands/ESP111.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ void ESP3DCommands::ESP111(int cmd_params_pos, ESP3DMessage* msg) {
4848
return;
4949
}
5050
#endif // AUTHENTICATION_FEATURE
51-
tmpstr = get_clean_param(msg, cmd_params_pos);
52-
5351
tmpstr = get_param(msg, cmd_params_pos, "OUTPUT=");
5452
if (tmpstr == "PRINTER") {
5553
msg->target = ESP3DClientType::remote_screen;

src/core/commands/ESP212.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
ESP212.cpp - ESP3D command class
3+
4+
Copyright (c) 2014 Luc Lebosse. All rights reserved.
5+
6+
This code is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This code is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with This code; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
#include "../../include/esp3d_config.h"
21+
#if defined(PRINTER_HAS_DISPLAY)
22+
#include "../../modules/authentication/authentication_service.h"
23+
#include "../../modules/display/display.h"
24+
#include "../esp3d_commands.h"
25+
#include "../esp3d_settings.h"
26+
#include "../esp3d_string.h"
27+
28+
#define COMMAND_ID 212
29+
// Output to printer screen status
30+
//[ESP212]<Text>json=<no> pwd=<user/admin password>
31+
void ESP3DCommands::ESP212(int cmd_params_pos, ESP3DMessage* msg) {
32+
ESP3DClientType target = msg->origin;
33+
ESP3DRequest requestId = msg->request_id;
34+
(void)requestId;
35+
msg->target = target;
36+
msg->origin = ESP3DClientType::command;
37+
bool hasError = false;
38+
String error_msg = "Invalid parameters";
39+
String ok_msg = "ok";
40+
bool json = hasTag(msg, cmd_params_pos, "json");
41+
String tmpstr;
42+
#if defined(AUTHENTICATION_FEATURE)
43+
if (msg->authentication_level == ESP3DAuthenticationLevel::guest) {
44+
msg->authentication_level = ESP3DAuthenticationLevel::not_authenticated;
45+
dispatchAuthenticationError(msg, COMMAND_ID, json);
46+
return;
47+
}
48+
#endif // AUTHENTICATION_FEATURE
49+
tmpstr = get_clean_param(msg, cmd_params_pos);
50+
tmpstr = esp3d_string::expandString(tmpstr.c_str());
51+
hasError = !esp3d_commands.dispatch(tmpstr.c_str(), ESP3DClientType::remote_screen,
52+
no_id, ESP3DMessageType::unique,
53+
ESP3DClientType::system,
54+
ESP3DAuthenticationLevel::admin);
55+
if (!dispatchAnswer(msg, COMMAND_ID, json, hasError,
56+
hasError ? error_msg.c_str() : ok_msg.c_str())) {
57+
esp3d_log_e("Error sending response to clients");
58+
}
59+
}
60+
61+
#endif // PRINTER_HAS_DISPLAY

src/core/commands/ESP214.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "../../modules/display/display.h"
2424
#include "../esp3d_commands.h"
2525
#include "../esp3d_settings.h"
26+
#include "../esp3d_string.h"
2627

2728
#define COMMAND_ID 214
2829
// Output to esp screen status
@@ -46,6 +47,7 @@ void ESP3DCommands::ESP214(int cmd_params_pos, ESP3DMessage* msg) {
4647
}
4748
#endif // AUTHENTICATION_FEATURE
4849
tmpstr = get_clean_param(msg, cmd_params_pos);
50+
tmpstr = esp3d_string::expandString(tmpstr.c_str());
4951
esp3d_display.setStatus(tmpstr.c_str());
5052
if (!dispatchAnswer(msg, COMMAND_ID, json, hasError,
5153
hasError ? error_msg.c_str() : ok_msg.c_str())) {

src/core/commands/ESP400.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const char* SupportedApChannelsStr[] = {"1", "2", "3", "4", "5", "6", "7",
110110

111111
const char* SupportedBaudListSizeStr[] = {
112112
"9600", "19200", "38400", "57600", "74880", "115200",
113-
"230400", "250000", "500000", "921600", "1958400"};
113+
"230400", "250000", "500000", "921600", "1000000", "1958400","2000000"};
114114

115115
#ifdef SENSOR_DEVICE
116116

src/core/esp3d.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ bool Esp3D::begin() {
7272
BootDelay bd;
7373
ESP3DHal::begin();
7474
ESP3D_LOG_INIT_FN
75+
#if defined(GCODE_HOST_FEATURE)
76+
esp3d_gcode_host.begin();
77+
#endif // GCODE_HOST_FEATURE
7578
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
7679
Serial2Socket.enable();
7780
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL

src/core/esp3d_commands.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,13 @@ void ESP3DCommands::execute_internal_command(int cmd, int cmd_params_pos,
596596
ESP210(cmd_params_pos, msg);
597597
break;
598598
#endif // #ifdef SENSOR_DEVICE
599+
#if defined (PRINTER_HAS_DISPLAY)
600+
// Output to printer screen status
601+
//[ESP212]<Text>json=<no> pwd=<user/admin password>
602+
case 212:
603+
ESP212(cmd_params_pos, msg);
604+
break;
605+
#endif // PRINTER_HAS_DISPLAY
599606
#if defined(DISPLAY_DEVICE)
600607
// Output to esp screen status
601608
//[ESP214]<Text>pwd=<user password>
@@ -1231,6 +1238,10 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
12311238
// currently only echo back no test done on success
12321239
// TODO check add is successful
12331240
switch (msg->target) {
1241+
case ESP3DClientType::no_client:
1242+
esp3d_log("No client message");
1243+
ESP3DMessageManager::deleteMsg(msg);
1244+
break;
12341245
#if COMMUNICATION_PROTOCOL == RAW_SERIAL
12351246
case ESP3DClientType::serial:
12361247
esp3d_log("Serial message");
@@ -1528,8 +1539,8 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) {
15281539
}
15291540
break;
15301541
default:
1531-
esp3d_log_e("No valid target specified %d",
1532-
static_cast<uint8_t>(msg->target));
1542+
esp3d_log_e("No valid target specified %d for %s",
1543+
static_cast<uint8_t>(msg->target), (char *)msg->data);
15331544
sendOk = false;
15341545
}
15351546
// clear message

src/core/esp3d_commands.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class ESP3DCommands {
117117
#ifdef DIRECT_PIN_FEATURE
118118
void ESP201(int cmd_params_pos, ESP3DMessage* msg);
119119
#endif // DIRECT_PIN_FEATURE
120+
#if defined(PRINTER_HAS_DISPLAY)
121+
void ESP212(int cmd_params_pos, ESP3DMessage* msg);
122+
#endif // PRINTER_HAS_DISPLAY
120123
#if defined(DISPLAY_DEVICE)
121124
void ESP214(int cmd_params_pos, ESP3DMessage* msg);
122125
#if defined(DISPLAY_TOUCH_DRIVER)

src/core/esp3d_string.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
#include "../include/esp3d_config.h"
2525

26+
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
27+
#include "../modules/network/netconfig.h"
28+
#endif // WIFI_FEATURE || ETH_FEATURE
29+
2630
#if defined(TIMESTAMP_FEATURE)
2731
#include "../modules/time/time_service.h"
2832
#endif // TIMESTAMP_FEATURE
@@ -180,10 +184,32 @@ const char* esp3d_string::formatBytes(uint64_t bytes) {
180184
return res.c_str();
181185
}
182186

183-
bool esp3d_string::isPrintableChar(char ch){
184-
int c = static_cast<int>(ch);
185-
if (c==9 || (c >= 32 && c <= 126) || c>=128) {
187+
bool esp3d_string::isPrintableChar(char ch) {
188+
int c = static_cast<int>(ch);
189+
if (c == 9 || (c >= 32 && c <= 126) || c >= 128) {
186190
return true;
187191
}
188192
return false;
189193
}
194+
195+
const char* esp3d_string::expandString(const char* s, bool formatspace) {
196+
static String tmp;
197+
tmp = s;
198+
if (tmp.indexOf("%") != -1) {
199+
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
200+
tmp.replace("%ESP_IP%", NetConfig::localIP().c_str());
201+
tmp.replace("%ESP_NAME%", NetConfig::hostname());
202+
#else
203+
tmp.replace("%ESP_IP%", "???");
204+
tmp.replace("%ESP_NAME%", "???");
205+
#endif // WIFI_FEATURE || ETH_FEATURE
206+
#if defined(TIMESTAMP_FEATURE)
207+
String dt = timeService.getCurrentTime();
208+
if (formatspace) dt.replace(" ", "\\ ");
209+
tmp.replace("%ESP_DATETIME%", dt.c_str());
210+
#else
211+
tmp.replace("%ESP_DATETIME%", "???");
212+
#endif // TIMESTAMP_FEATURE
213+
}
214+
return tmp.c_str();
215+
}

src/core/esp3d_string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const char* getContentType(const char* filename);
2828
const char* encodeString(const char* s);
2929
const char* formatBytes(uint64_t bytes);
3030
bool isPrintableChar(char c);
31+
const char * expandString(const char *s, bool formatspace = false);
3132
} // namespace esp3d_string
3233

3334
#endif //_ESP3D_STRING_H

0 commit comments

Comments
 (0)