2929#include " ../../../core/esp3d_commands.h"
3030#include " ../../../core/esp3d_message.h"
3131#include " ../../../core/esp3d_settings.h"
32+ #include " ../../../core/esp3d_string.h"
3233#include " ../../authentication/authentication_service.h"
3334
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- }
4535
4636// Handle web command query and send answer//////////////////////////////
4737void HTTP_Server::handle_web_command () {
@@ -53,32 +43,42 @@ void HTTP_Server::handle_web_command() {
5343 }
5444 // esp3d_log("Authentication = %d", auth_level);
5545 String cmd = " " ;
46+ bool isRealTimeCommand = false ;
5647 if (_webserver->hasArg (" cmd" )) {
5748 cmd = _webserver->arg (" cmd" );
49+ esp3d_log (" Command is %s" , cmd.c_str ());
5850 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) {
6053 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 ])))) {
6356 cmd += " \n " ;
57+ esp3d_log (" Command is not realtime, adding \\ n" );
6458 } else { // no need \n for realtime command
59+ esp3d_log (" Command is realtime, no need to add \\ n" );
60+ isRealTimeCommand = true ;
6561 // 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 ) {
6763 cmd[0 ] = cmd[1 ];
6864 cmd[1 ] = 0x0 ;
65+ esp3d_log (" Command is realtime, removing 0xC2" );
6966 }
7067 }
7168 } else {
69+ esp3d_log (" Command is not realtime, adding \\ n" );
7270 cmd += " \n " ; // need to validate command
7371 }
72+ } else {
73+ esp3d_log (" Command is ending with \\ n" );
7474 }
75- esp3d_log (" Web Command: %s " , cmd.c_str ());
75+ esp3d_log (" Message type is %s for %s " , isRealTimeCommand ? " realtimecmd " : " unique " , cmd.c_str ());
7676 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 (
7878 ESP3DClientType::http, esp3d_commands.getOutputClient (),
7979 (uint8_t *)cmd.c_str (), cmd.length (), auth_level);
8080 if (msg) {
81- msg->type = ESP3DMessageType::unique;
81+ msg->type = ESP3DMessageType::unique; // ESP3D command is always unique
8282 msg->request_id .code = 200 ;
8383 // process command
8484 esp3d_commands.process (msg);
@@ -91,7 +91,7 @@ void HTTP_Server::handle_web_command() {
9191 // no need to wait to answer then
9292 _webserver->send (200 , " text/plain" , " ESP3D says: command forwarded" );
9393 esp3d_commands.dispatch (cmd.c_str (), esp3d_commands.getOutputClient (),
94- no_id, ESP3DMessageType::unique,
94+ no_id, isRealTimeCommand ? ESP3DMessageType::realtimecmd : ESP3DMessageType::unique,
9595 ESP3DClientType::http, auth_level);
9696 }
9797 } else if (_webserver->hasArg (" ping" )) {
0 commit comments