29
29
#include " ../../../core/esp3d_commands.h"
30
30
#include " ../../../core/esp3d_message.h"
31
31
#include " ../../../core/esp3d_settings.h"
32
+ #include " ../../../core/esp3d_string.h"
32
33
#include " ../../authentication/authentication_service.h"
33
34
34
- const unsigned char realTimeCommands[] = {
35
- ' !' , ' ~' , ' ?' , 0x18 , 0x84 , 0x85 , 0x90 , 0x92 , 0x93 , 0x94 , 0x95 ,
36
- 0x96 , 0x97 , 0x99 , 0x9A , 0x9B , 0x9C , 0x9D , 0x9E , 0xA0 , 0xA1 };
37
- bool isRealTimeCommand (unsigned char c) {
38
- for (unsigned int i = 0 ; i < sizeof (realTimeCommands); i++) {
39
- if (c == realTimeCommands[i]) {
40
- return true ;
41
- }
42
- }
43
- return false ;
44
- }
45
35
46
36
// Handle web command query and send answer//////////////////////////////
47
37
void HTTP_Server::handle_web_command () {
@@ -53,32 +43,42 @@ void HTTP_Server::handle_web_command() {
53
43
}
54
44
// esp3d_log("Authentication = %d", auth_level);
55
45
String cmd = " " ;
46
+ bool isRealTimeCommand = false ;
56
47
if (_webserver->hasArg (" cmd" )) {
57
48
cmd = _webserver->arg (" cmd" );
49
+ esp3d_log (" Command is %s" , cmd.c_str ());
58
50
if (!cmd.endsWith (" \n " )) {
59
- if (ESP3DSettings::GetFirmwareTarget () == GRBL) {
51
+ esp3d_log (" Command is not ending with \\ n" );
52
+ if (ESP3DSettings::GetFirmwareTarget () == GRBL || ESP3DSettings::GetFirmwareTarget () == GRBLHAL) {
60
53
uint len = cmd.length ();
61
- if (!((len == 1 && isRealTimeCommand (cmd[0 ])) ||
62
- (len == 2 && isRealTimeCommand (cmd[1 ])))) {
54
+ if (!((len == 1 && esp3d_string:: isRealTimeCommand (cmd[0 ])) ||
55
+ (len == 2 && esp3d_string:: isRealTimeCommand (cmd[1 ])))) {
63
56
cmd += " \n " ;
57
+ esp3d_log (" Command is not realtime, adding \\ n" );
64
58
} else { // no need \n for realtime command
59
+ esp3d_log (" Command is realtime, no need to add \\ n" );
60
+ isRealTimeCommand = true ;
65
61
// remove the 0XC2 that should not be there
66
- if (len == 2 && isRealTimeCommand (cmd[1 ]) && cmd[1 ] == 0xC2 ) {
62
+ if (len == 2 && esp3d_string:: isRealTimeCommand (cmd[1 ]) && cmd[1 ] == 0xC2 ) {
67
63
cmd[0 ] = cmd[1 ];
68
64
cmd[1 ] = 0x0 ;
65
+ esp3d_log (" Command is realtime, removing 0xC2" );
69
66
}
70
67
}
71
68
} else {
69
+ esp3d_log (" Command is not realtime, adding \\ n" );
72
70
cmd += " \n " ; // need to validate command
73
71
}
72
+ } else {
73
+ esp3d_log (" Command is ending with \\ n" );
74
74
}
75
- esp3d_log (" Web Command: %s " , cmd.c_str ());
75
+ esp3d_log (" Message type is %s for %s " , isRealTimeCommand ? " realtimecmd " : " unique " , cmd.c_str ());
76
76
if (esp3d_commands.is_esp_command ((uint8_t *)cmd.c_str (), cmd.length ())) {
77
- ESP3DMessage *msg = ESP3DMessageManager:: newMsg (
77
+ ESP3DMessage *msg = esp3d_message_manager. newMsg (
78
78
ESP3DClientType::http, esp3d_commands.getOutputClient (),
79
79
(uint8_t *)cmd.c_str (), cmd.length (), auth_level);
80
80
if (msg) {
81
- msg->type = ESP3DMessageType::unique;
81
+ msg->type = ESP3DMessageType::unique; // ESP3D command is always unique
82
82
msg->request_id .code = 200 ;
83
83
// process command
84
84
esp3d_commands.process (msg);
@@ -91,7 +91,7 @@ void HTTP_Server::handle_web_command() {
91
91
// no need to wait to answer then
92
92
_webserver->send (200 , " text/plain" , " ESP3D says: command forwarded" );
93
93
esp3d_commands.dispatch (cmd.c_str (), esp3d_commands.getOutputClient (),
94
- no_id, ESP3DMessageType::unique,
94
+ no_id, isRealTimeCommand ? ESP3DMessageType::realtimecmd : ESP3DMessageType::unique,
95
95
ESP3DClientType::http, auth_level);
96
96
}
97
97
} else if (_webserver->hasArg (" ping" )) {
0 commit comments