|
| 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 |
0 commit comments