mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-01 04:22:03 +08:00
Fix FTP not listing on some shared SD (#958)
* Fix Rename not working on GlobalFS * esp3d_log refactoring - Rename Debug to Log - Allow now 4 level of log: None, Error, Debug, Verbose - Change original verbose log to error log when it is an error * Update configuration.h to add debug level expected * Add log for critical steps in FTP module
This commit is contained in:
parent
dc84b0bbdb
commit
3ffb7c3b4c
@ -46,23 +46,24 @@
|
||||
|
||||
/* Serial Communication protocol
|
||||
* RAW_SERIAL // Basic serial protocol, without data change
|
||||
* MKS_SERIAL // This is a MakerBase communication protocol, used with MKS printers and TFT, it encapsulated data in a custom protocol
|
||||
* MKS_SERIAL // This is a MakerBase communication protocol, used with MKS
|
||||
* printers and TFT, it encapsulated data in a custom protocol
|
||||
*/
|
||||
#define COMMUNICATION_PROTOCOL RAW_SERIAL
|
||||
|
||||
/* Main Serial port
|
||||
* which serial ESP use to communicate to printer (ESP32 has 3 serials available, ESP8266 only 2)
|
||||
* USE_SERIAL_0 //for ESP8266/32, also used by bootloader output, so consider to make it quiet
|
||||
* USE_SERIAL_1 //for ESP8266/32
|
||||
* which serial ESP use to communicate to printer (ESP32 has 3 serials
|
||||
* available, ESP8266 only 2) USE_SERIAL_0 //for ESP8266/32, also used by
|
||||
* bootloader output, so consider to make it quiet USE_SERIAL_1 //for ESP8266/32
|
||||
* USE_SERIAL_2 //for ESP32 Only
|
||||
*/
|
||||
// Main serial port
|
||||
#define ESP_SERIAL_OUTPUT USE_SERIAL_0
|
||||
|
||||
/* Bridge Serial port (deprecated on esp8266 as second serial is)
|
||||
* which serial ESP use to bridge to another device (ESP32 has 3 serials available, ESP8266 only 2)
|
||||
* USE_SERIAL_0 //for ESP8266/32, also used by bootloader output, so consider to make it quiet
|
||||
* USE_SERIAL_1 //for ESP8266/32
|
||||
* which serial ESP use to bridge to another device (ESP32 has 3 serials
|
||||
* available, ESP8266 only 2) USE_SERIAL_0 //for ESP8266/32, also used by
|
||||
* bootloader output, so consider to make it quiet USE_SERIAL_1 //for ESP8266/32
|
||||
* USE_SERIAL_2 //for ESP32 Only\
|
||||
* Comment if not used
|
||||
*/
|
||||
@ -132,7 +133,6 @@
|
||||
// Address of ethernet board
|
||||
// #define ESP3D_ETH_PHY_ADDR 0
|
||||
|
||||
|
||||
/* Use Bluetooth
|
||||
* Enable serial bluetooth communications
|
||||
*/
|
||||
@ -266,14 +266,16 @@
|
||||
* ESP_SHARED_SD //Printer SD Card is also connected to ESP3D
|
||||
* Does your system has SD card and how it is connected to your ESP3D
|
||||
*/
|
||||
//#define SD_DEVICE_CONNECTION ESP_DIRECT_SD
|
||||
// #define SD_DEVICE_CONNECTION ESP_SHARED_SD
|
||||
|
||||
/* SD card library
|
||||
* ESP_SD_NATIVE //esp32 / esp8266
|
||||
* ESP_SDIO //esp32 only
|
||||
* ESP_SDFAT2 //esp8266 / esp32
|
||||
*/
|
||||
//#define SD_DEVICE ESP_SDFAT2
|
||||
// #define SD_DEVICE ESP_SD_NATIVE
|
||||
|
||||
// #define SD_CARD_TYPE ESP_FYSETC_WIFI_PRO_SDCARD
|
||||
|
||||
/* Sdio bit mode
|
||||
* Mode used by SDIO library 1 bit / 4bits
|
||||
@ -329,7 +331,7 @@
|
||||
/* Enable global filesystem
|
||||
* Allows to access to all filesystems from same location
|
||||
*/
|
||||
//#define GLOBAL_FILESYSTEM_FEATURE
|
||||
#define GLOBAL_FILESYSTEM_FEATURE
|
||||
|
||||
/* WebDav access
|
||||
* Use WebDav to access to your filesystem
|
||||
@ -337,7 +339,7 @@
|
||||
* FS_FLASH //mount Flash FS
|
||||
* FS_SD mount SD FS
|
||||
*/
|
||||
//#define WEBDAV_FEATURE FS_ROOT
|
||||
#define WEBDAV_FEATURE FS_ROOT
|
||||
|
||||
/* FTP access
|
||||
* Use FTP to access to your filesystem (1 connection only)
|
||||
@ -361,7 +363,8 @@
|
||||
// #define PIN_RESET_FEATURE
|
||||
|
||||
/* Reset pin
|
||||
* The pin used to reset ESP3D setting if set to low for more than 1 second at start
|
||||
* The pin used to reset ESP3D setting if set to low for more than 1 second at
|
||||
* start
|
||||
*/
|
||||
#define ESP3D_RESET_PIN 0
|
||||
|
||||
@ -494,7 +497,6 @@
|
||||
*/
|
||||
// #define CAMERA_DEVICE_FLIP_VERTICALY
|
||||
|
||||
|
||||
/************************************
|
||||
*
|
||||
* Levels of security
|
||||
@ -571,28 +573,30 @@
|
||||
*/
|
||||
#define SERIAL_INDEPENDANT_TASK
|
||||
|
||||
|
||||
|
||||
/************************************
|
||||
*
|
||||
* Development setting
|
||||
* Do not modify them for production
|
||||
************************************/
|
||||
|
||||
//Enable debug mode
|
||||
// Enable log mode
|
||||
// Do not do this when connected to printer !!!
|
||||
// be noted all upload may failed if enabled
|
||||
//DEBUG_OUTPUT_SERIAL0
|
||||
//DEBUG_OUTPUT_SERIAL1
|
||||
//DEBUG_OUTPUT_SERIAL2
|
||||
//DEBUG_OUTPUT_TELNET
|
||||
//DEBUG_OUTPUT_WEBSOCKET
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// LOG_OUTPUT_SERIAL0
|
||||
// LOG_OUTPUT_SERIAL1
|
||||
// LOG_OUTPUT_SERIAL2
|
||||
// LOG_OUTPUT_TELNET
|
||||
// LOG_OUTPUT_WEBSOCKET
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
|
||||
#ifdef ESP_DEBUG_FEATURE
|
||||
#define DEBUG_BAUDRATE 115200
|
||||
#define DEBUG_ESP3D_OUTPUT_PORT 8000
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
#define ESP3D_DEBUG_LEVEL LOG_LEVEL_ERROR
|
||||
|
||||
// #define ESP_NO_SANITY_CHECK
|
||||
|
||||
#ifdef ESP_LOG_FEATURE
|
||||
#define LOG_ESP3D_BAUDRATE 115200
|
||||
#define LOG_ESP3D_OUTPUT_PORT 8000
|
||||
#endif // ESP_LOG_FEATURE
|
||||
|
||||
// Enable benchmark report in dev console
|
||||
// #define ESP_BENCHMARK_FEATURE
|
||||
@ -600,7 +604,6 @@
|
||||
// Disable sanity check at compilation
|
||||
// #define ESP_NO_SANITY_CHECK
|
||||
|
||||
|
||||
/************************************
|
||||
*
|
||||
* Sanity checks
|
||||
@ -616,9 +619,11 @@
|
||||
#endif // PRINTER_HAS_DISPLAY
|
||||
|
||||
#if defined(CAMERA_DEVICE)
|
||||
#if CAMERA_DEVICE==CAMERA_MODEL_ESP32_CAM_BOARD || CAMERA_DEVICE==CAMERA_MODEL_ESP32S2_CAM_BOARD
|
||||
#if CAMERA_DEVICE == CAMERA_MODEL_ESP32_CAM_BOARD || \
|
||||
CAMERA_DEVICE == CAMERA_MODEL_ESP32S2_CAM_BOARD
|
||||
#define USE_BOARD_HEARDER 1
|
||||
#endif // CAMERA_DEVICE==CAMERA_MODEL_ESP32_CAM_BOARD || CAMERA_DEVICE==CAMERA_MODEL_ESP32S2_CAM_BOARD
|
||||
#endif // CAMERA_DEVICE==CAMERA_MODEL_ESP32_CAM_BOARD ||
|
||||
// CAMERA_DEVICE==CAMERA_MODEL_ESP32S2_CAM_BOARD
|
||||
#endif // CAMERA_DEVICE
|
||||
|
||||
#if !defined(WIFI_FEATURE) && !defined(ETH_FEATURE)
|
||||
|
@ -17,31 +17,32 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "commands.h"
|
||||
|
||||
#include "../include/esp3d_config.h"
|
||||
#include "esp3d.h"
|
||||
#include "commands.h"
|
||||
#include "esp3doutput.h"
|
||||
#include "settings_esp3d.h"
|
||||
|
||||
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#include "../modules/mks/mks_service.h"
|
||||
#endif // COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
|
||||
Commands esp3d_commands;
|
||||
|
||||
Commands::Commands()
|
||||
{
|
||||
}
|
||||
Commands::Commands() {}
|
||||
|
||||
Commands::~Commands()
|
||||
{
|
||||
}
|
||||
Commands::~Commands() {}
|
||||
|
||||
// dispatch the command
|
||||
void Commands::process(uint8_t * sbuf, size_t len, ESP3DOutput * output, level_authenticate_type auth, ESP3DOutput * outputonly, uint8_t outputignore )
|
||||
{
|
||||
void Commands::process(uint8_t *sbuf, size_t len, ESP3DOutput *output,
|
||||
level_authenticate_type auth, ESP3DOutput *outputonly,
|
||||
uint8_t outputignore) {
|
||||
static bool lastIsESP3D = false;
|
||||
log_esp3d("Client is %d, has only %d, has ignore %d", output?output->client():0, outputonly?outputonly->client():0, outputignore);
|
||||
log_esp3d("Client is %d, has only %d, has ignore %d",
|
||||
output ? output->client() : 0,
|
||||
outputonly ? outputonly->client() : 0, outputignore);
|
||||
if (is_esp_command(sbuf, len)) {
|
||||
lastIsESP3D = true;
|
||||
size_t slen = len;
|
||||
@ -58,10 +59,18 @@ void Commands::process(uint8_t * sbuf, size_t len, ESP3DOutput * output, level_a
|
||||
cmd[2] = tmpbuf[6] == ']' ? 0 : tmpbuf[6];
|
||||
cmd[3] = 0x0;
|
||||
log_esp3d("It is ESP command %s", cmd);
|
||||
log_esp3d("Respond to client %d",(outputonly == nullptr)?output->client():outputonly->client());
|
||||
execute_internal_command (String((const char*)cmd).toInt(), (slen > (strlen((const char *)cmd)+5))?(const char*)&tmpbuf[strlen((const char *)cmd)+5]:"", auth, (outputonly == nullptr)?output:outputonly);
|
||||
log_esp3d("Respond to client %d", (outputonly == nullptr)
|
||||
? output->client()
|
||||
: outputonly->client());
|
||||
execute_internal_command(
|
||||
String((const char *)cmd).toInt(),
|
||||
(slen > (strlen((const char *)cmd) + 5))
|
||||
? (const char *)&tmpbuf[strlen((const char *)cmd) + 5]
|
||||
: "",
|
||||
auth, (outputonly == nullptr) ? output : outputonly);
|
||||
} else {
|
||||
//Work around to avoid to dispatch single \n to everyone as it is part of previous ESP3D command
|
||||
// Work around to avoid to dispatch single \n to everyone as it is part of
|
||||
// previous ESP3D command
|
||||
if (lastIsESP3D && len == 1 && sbuf[0] == '\n') {
|
||||
lastIsESP3D = false;
|
||||
return;
|
||||
@ -84,7 +93,8 @@ void Commands::process(uint8_t * sbuf, size_t len, ESP3DOutput * output, level_a
|
||||
log_esp3d("Dispatch from %d, but %d", output->client(), outputignore);
|
||||
output->dispatch(sbuf, len, outputignore);
|
||||
} else {
|
||||
log_esp3d("Dispatch from %d to only %d", output->client(), outputonly->client());
|
||||
log_esp3d("Dispatch from %d to only %d", output->client(),
|
||||
outputonly->client());
|
||||
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
if (outputonly->client() == ESP_SERIAL_CLIENT) {
|
||||
MKSService::sendGcodeFrame((const char *)sbuf);
|
||||
@ -99,19 +109,26 @@ void Commands::process(uint8_t * sbuf, size_t len, ESP3DOutput * output, level_a
|
||||
}
|
||||
|
||||
// check if current line is an [ESPXXX] command
|
||||
bool Commands::is_esp_command(uint8_t * sbuf, size_t len)
|
||||
{
|
||||
bool Commands::is_esp_command(uint8_t *sbuf, size_t len) {
|
||||
// TODO
|
||||
// M117 should be handled here and transfered to [ESP214] if it is an host
|
||||
if (len < 5) {
|
||||
return false;
|
||||
}
|
||||
if ((char(sbuf[0]) == '[') && (char(sbuf[1]) == 'E') && (char(sbuf[2]) == 'S') && (char(sbuf[3]) == 'P') && ((char(sbuf[4]) == ']') ||(char(sbuf[5]) == ']')||(char(sbuf[6]) == ']') ||(char(sbuf[7]) == ']'))) {
|
||||
if ((char(sbuf[0]) == '[') && (char(sbuf[1]) == 'E') &&
|
||||
(char(sbuf[2]) == 'S') && (char(sbuf[3]) == 'P') &&
|
||||
((char(sbuf[4]) == ']') || (char(sbuf[5]) == ']') ||
|
||||
(char(sbuf[6]) == ']') || (char(sbuf[7]) == ']'))) {
|
||||
return true;
|
||||
}
|
||||
if((char(sbuf[0]) == 'e') && (char(sbuf[1]) == 'c') && (char(sbuf[2]) == 'h') && (char(sbuf[3]) == 'o') && (char(sbuf[4]) == ':') && (char(sbuf[5]) == ' ') && (char(sbuf[6]) == '[') && (char(sbuf[7]) == 'E')) {
|
||||
if ((char(sbuf[0]) == 'e') && (char(sbuf[1]) == 'c') &&
|
||||
(char(sbuf[2]) == 'h') && (char(sbuf[3]) == 'o') &&
|
||||
(char(sbuf[4]) == ':') && (char(sbuf[5]) == ' ') &&
|
||||
(char(sbuf[6]) == '[') && (char(sbuf[7]) == 'E')) {
|
||||
if (len >= 14) {
|
||||
if ((char(sbuf[8]) == 'S') && (char(sbuf[9]) == 'P') && ((char(sbuf[4]) == ']') ||(char(sbuf[5]) == ']')||(char(sbuf[6]) == ']') ||(char(sbuf[7]) == ']'))) {
|
||||
if ((char(sbuf[8]) == 'S') && (char(sbuf[9]) == 'P') &&
|
||||
((char(sbuf[4]) == ']') || (char(sbuf[5]) == ']') ||
|
||||
(char(sbuf[6]) == ']') || (char(sbuf[7]) == ']'))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -121,8 +138,7 @@ bool Commands::is_esp_command(uint8_t * sbuf, size_t len)
|
||||
|
||||
// find space in string
|
||||
// if space is has \ before it is ignored
|
||||
int Commands::get_space_pos(const char * string, uint from)
|
||||
{
|
||||
int Commands::get_space_pos(const char *string, uint from) {
|
||||
uint len = strlen(string);
|
||||
if (len < from) {
|
||||
return -1;
|
||||
@ -142,9 +158,11 @@ int Commands::get_space_pos(const char * string, uint from)
|
||||
return -1;
|
||||
}
|
||||
|
||||
//return first label but pwd using labelseparator (usualy =) like mylabel=myvalue will return mylabel
|
||||
const char* Commands::get_label (const char * cmd_params, const char * labelseparator, uint8_t startindex)
|
||||
{
|
||||
// return first label but pwd using labelseparator (usualy =) like
|
||||
// mylabel=myvalue will return mylabel
|
||||
const char *Commands::get_label(const char *cmd_params,
|
||||
const char *labelseparator,
|
||||
uint8_t startindex) {
|
||||
static String res;
|
||||
String tmp = "";
|
||||
res = "";
|
||||
@ -186,8 +204,8 @@ const char* Commands::get_label (const char * cmd_params, const char * labelsepa
|
||||
return res.c_str();
|
||||
}
|
||||
|
||||
const char * Commands::format_response(uint cmdID, bool isjson, bool isok, const char * message)
|
||||
{
|
||||
const char *Commands::format_response(uint cmdID, bool isjson, bool isok,
|
||||
const char *message) {
|
||||
static String res;
|
||||
res = "";
|
||||
if (!isjson) {
|
||||
@ -214,8 +232,7 @@ const char * Commands::format_response(uint cmdID, bool isjson, bool isok, cons
|
||||
return res.c_str();
|
||||
}
|
||||
|
||||
const char * Commands::clean_param (const char * cmd_params)
|
||||
{
|
||||
const char *Commands::clean_param(const char *cmd_params) {
|
||||
static String res;
|
||||
res = cmd_params;
|
||||
if (strlen(cmd_params) == 0) {
|
||||
@ -240,8 +257,7 @@ const char * Commands::clean_param (const char * cmd_params)
|
||||
|
||||
// extract parameter with corresponding label
|
||||
// if label is empty give whole line without authentication label/parameter
|
||||
const char * Commands::get_param (const char * cmd_params, const char * label)
|
||||
{
|
||||
const char *Commands::get_param(const char *cmd_params, const char *label) {
|
||||
static String res;
|
||||
res = "";
|
||||
int start = 1;
|
||||
@ -275,7 +291,6 @@ const char * Commands::get_param (const char * cmd_params, const char * label)
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
// if no label remove authentication parameters
|
||||
if (strlen(label) == 0) {
|
||||
|
||||
tmp = " " + res;
|
||||
start = tmp.indexOf(" pwd=");
|
||||
if (start != -1) {
|
||||
@ -295,16 +310,14 @@ const char * Commands::get_param (const char * cmd_params, const char * label)
|
||||
// be sure no extra space
|
||||
res.trim();
|
||||
return res.c_str();
|
||||
|
||||
}
|
||||
|
||||
bool Commands::has_tag (const char * cmd_params, const char *tag)
|
||||
{
|
||||
bool Commands::has_tag(const char *cmd_params, const char *tag) {
|
||||
log_esp3d("Checking for tag: %s, in %s", tag, cmd_params);
|
||||
String tmp = "";
|
||||
String stag = " ";
|
||||
if ((strlen(cmd_params) == 0) || (strlen(tag) == 0)) {
|
||||
log_esp3d("No value provided for tag");
|
||||
log_esp3d_e("No value provided for tag");
|
||||
return false;
|
||||
}
|
||||
stag += tag;
|
||||
@ -322,7 +335,8 @@ bool Commands::has_tag (const char * cmd_params, const char *tag)
|
||||
String parameter = get_param(cmd_params, param.c_str());
|
||||
if (parameter.length() != 0) {
|
||||
log_esp3d("Parameter is %s", parameter.c_str());
|
||||
if (parameter == "YES" ||parameter == "true" ||parameter == "TRUE" || parameter == "yes" || parameter == "1") {
|
||||
if (parameter == "YES" || parameter == "true" || parameter == "TRUE" ||
|
||||
parameter == "yes" || parameter == "1") {
|
||||
return true;
|
||||
}
|
||||
log_esp3d("No parameter to enable %s ", param.c_str());
|
||||
@ -332,10 +346,10 @@ bool Commands::has_tag (const char * cmd_params, const char *tag)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// execute internal command
|
||||
bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output)
|
||||
{
|
||||
bool Commands::execute_internal_command(int cmd, const char *cmd_params,
|
||||
level_authenticate_type auth_level,
|
||||
ESP3DOutput *output) {
|
||||
#ifndef SERIAL_COMMAND_FEATURE
|
||||
if (output->client() == ESP_SERIAL_CLIENT) {
|
||||
output->printMSG("Feature disabled");
|
||||
@ -476,7 +490,8 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
#endif // TELNET_FEATURE
|
||||
#ifdef TIMESTAMP_FEATURE
|
||||
// Sync / Set / Get current time
|
||||
//[ESP140]<SYNC> <srv1=XXXXX> <srv2=XXXXX> <srv3=XXXXX> <zone=xxx> <dst=YES/NO> <time=YYYY-MM-DD#H24:MM:SS> pwd=<admin password>
|
||||
//[ESP140]<SYNC> <srv1=XXXXX> <srv2=XXXXX> <srv3=XXXXX> <zone=xxx>
|
||||
//<dst=YES/NO> <time=YYYY-MM-DD#H24:MM:SS> pwd=<admin password>
|
||||
case 140:
|
||||
response = ESP140(cmd_params, auth_type, output);
|
||||
break;
|
||||
@ -501,12 +516,14 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
#ifdef CAMERA_DEVICE
|
||||
// Get/Set Camera command value / list all values in JSON/plain
|
||||
//[ESP170]label=<value> pwd=<admin/user password>
|
||||
//label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling/colorbar/awb/agc/aec/hmirror/vflip/awb_gain/agc_gain/aec_value/aec2/cw/bpc/wpc/raw_gma/lenc/special_effect/wb_mode/ae_level
|
||||
// label can be:
|
||||
// light/framesize/quality/contrast/brightness/saturation/gainceiling/colorbar/awb/agc/aec/hmirror/vflip/awb_gain/agc_gain/aec_value/aec2/cw/bpc/wpc/raw_gma/lenc/special_effect/wb_mode/ae_level
|
||||
case 170:
|
||||
response = ESP170(cmd_params, auth_type, output);
|
||||
break;
|
||||
//Save frame to target path and filename (default target = today date, default name=timestamp.jpg)
|
||||
//[ESP171]path=<target path> filename=<target filename> pwd=<admin/user password>
|
||||
// Save frame to target path and filename (default target = today date,
|
||||
// default name=timestamp.jpg) [ESP171]path=<target path> filename=<target
|
||||
// filename> pwd=<admin/user password>
|
||||
case 171:
|
||||
response = ESP171(cmd_params, auth_type, output);
|
||||
break;
|
||||
@ -657,8 +674,9 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
response = ESP600(cmd_params, auth_type, output);
|
||||
break;
|
||||
// Set/Get Notification settings
|
||||
//[ESP610]type=<NONE/PUSHOVER/EMAIL/LINE> T1=<token1> T2=<token2> TS=<Settings> [pwd=<admin password>]
|
||||
//Get will give type and settings only not the protected T1/T2
|
||||
//[ESP610]type=<NONE/PUSHOVER/EMAIL/LINE> T1=<token1> T2=<token2>
|
||||
// TS=<Settings> [pwd=<admin password>] Get will give type and settings only
|
||||
// not the protected T1/T2
|
||||
case 610:
|
||||
response = ESP610(cmd_params, auth_type, output);
|
||||
break;
|
||||
@ -760,7 +778,8 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
#endif // BUZZER_DEVICE
|
||||
case 920:
|
||||
// Get state / Set state of output message clients
|
||||
//[ESP910]<SERIAL / SCREEN / REMOTE_SCREEN/ WEBSOCKET / TELNET /BT / ALL>=<ON/OFF>[pwd=<admin password>]
|
||||
//[ESP910]<SERIAL / SCREEN / REMOTE_SCREEN/ WEBSOCKET / TELNET /BT /
|
||||
// ALL>=<ON/OFF>[pwd=<admin password>]
|
||||
response = ESP920(cmd_params, auth_type, output);
|
||||
break;
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
@ -775,7 +794,9 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
response = ESP931(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif // defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
#if defined(ARDUINO_ARCH_ESP32) && (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3)
|
||||
#if defined(ARDUINO_ARCH_ESP32) && \
|
||||
(CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || \
|
||||
CONFIG_IDF_TARGET_ESP32C3)
|
||||
case 999:
|
||||
// Set quiet boot if strapping pin is High
|
||||
//[ESP999]<QUIETBOOT> [pwd=<admin/user password>]
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
debug_esp3d.cpp - debug esp3d functions class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This code is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../include/esp3d_config.h"
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
|
||||
#ifndef DEBUG_BAUDRATE
|
||||
#define DEBUG_BAUDRATE 115200
|
||||
#endif //~DEBUG_BAUDRATE
|
||||
|
||||
void initDebug()
|
||||
{
|
||||
#if (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL0) || (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL1)||(ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2)
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
DEBUG_OUTPUT_SERIAL.begin(DEBUG_BAUDRATE, SERIAL_8N1, SERIAL_FULL, (ESP_DEBUG_TX_PIN == -1)?1:ESP_DEBUG_TX_PIN);
|
||||
#if ESP_DEBUG_RX_PIN != -1
|
||||
DEBUG_OUTPUT_SERIAL.pins((ESP_DEBUG_TX_PIN == -1)?1:ESP_DEBUG_TX_PIN, ESP_DEBUG_RX_PIN)
|
||||
#endif //ESP_DEBUG_RX_PIN != -1
|
||||
#endif //ARDUINO_ARCH_ESP8266
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
DEBUG_OUTPUT_SERIAL.begin (DEBUG_BAUDRATE, SERIAL_8N1, ESP_DEBUG_RX_PIN, ESP_DEBUG_TX_PIN);
|
||||
#endif //ARDUINO_ARCH_ESP32
|
||||
|
||||
#endif // (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL0) || (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL1)||(ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2)
|
||||
}
|
||||
|
||||
//Telnet
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_TELNET
|
||||
Telnet_Server telnet_debug;
|
||||
#endif // ESP_DEBUG_FEATURE == DEBUG_OUTPUT_TELNET
|
||||
|
||||
//Websocket
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
WebSocket_Server websocket_debug("debug");
|
||||
#endif // ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
#endif //ESP_DEBUG_FEATURE
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
debug_esp3d.h - esp3d debug functions
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This code is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _DEBUG_ESP3D_H
|
||||
#define _DEBUG_ESP3D_H
|
||||
|
||||
#include "../include/esp3d_config.h"
|
||||
|
||||
#define DEBUG_ESP3D_INIT
|
||||
#define DEBUG_ESP3D_NETWORK_INIT
|
||||
#define DEBUG_ESP3D_NETWORK_HANDLE
|
||||
#define DEBUG_ESP3D_NETWORK_END
|
||||
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
//no need with latest esp8266 core
|
||||
#define pathToFileName(p) p
|
||||
#endif //ARDUINO_ARCH_ESP8266
|
||||
#undef log_esp3d
|
||||
#undef log_esp3ds
|
||||
//Serial
|
||||
#if (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL0) || (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL1) || (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2)
|
||||
|
||||
extern void initDebug();
|
||||
#ifndef ESP3DLIB_ENV
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL0
|
||||
#define DEBUG_OUTPUT_SERIAL Serial
|
||||
#endif //DEBUG_OUTPUT_SERIAL0
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL1
|
||||
#define DEBUG_OUTPUT_SERIAL Serial1
|
||||
#endif //DEBUG_OUTPUT_SERIAL1
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2
|
||||
#define DEBUG_OUTPUT_SERIAL Serial2
|
||||
#endif //DEBUG_OUTPUT_SERIAL2
|
||||
#undef DEBUG_ESP3D_INIT
|
||||
#define DEBUG_ESP3D_INIT initDebug();
|
||||
#else
|
||||
#define DEBUG_OUTPUT_SERIAL MYSERIAL1
|
||||
#endif //ESP3DLIB_ENV
|
||||
#define log_esp3d(format, ...) DEBUG_OUTPUT_SERIAL.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define log_esp3ds(format, ...) DEBUG_OUTPUT_SERIAL.printf(format, ##__VA_ARGS__)
|
||||
#endif //DEBUG_OUTPUT_SERIAL0 || DEBUG_OUTPUT_SERIAL1 || DEBUG_OUTPUT_SERIAL2
|
||||
|
||||
//Telnet
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_TELNET
|
||||
#include "../modules/telnet/telnet_server.h"
|
||||
extern Telnet_Server telnet_debug;
|
||||
#undef DEBUG_ESP3D_NETWORK_INIT
|
||||
#undef DEBUG_ESP3D_NETWORK_END
|
||||
#undef DEBUG_ESP3D_NETWORK_HANDLE
|
||||
#define DEBUG_ESP3D_NETWORK_INIT telnet_debug.begin(DEBUG_ESP3D_OUTPUT_PORT, true);
|
||||
#define DEBUG_ESP3D_NETWORK_HANDLE telnet_debug.handle();
|
||||
#define DEBUG_ESP3D_NETWORK_END telnet_debug.end();
|
||||
#define log_esp3d(format, ...) if(telnet_debug.isConnected())telnet_debug.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define log_esp3ds(format, ...) if(telnet_debug.isConnected())telnet_debug.printf(format , ##__VA_ARGS__)
|
||||
#endif // DEBUG_OUTPUT_TELNET
|
||||
|
||||
//Telnet
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
#include "../modules/websocket/websocket_server.h"
|
||||
extern WebSocket_Server websocket_debug;
|
||||
#undef DEBUG_ESP3D_NETWORK_INIT
|
||||
#undef DEBUG_ESP3D_NETWORK_END
|
||||
#undef DEBUG_ESP3D_NETWORK_HANDLE
|
||||
#define DEBUG_ESP3D_NETWORK_INIT websocket_debug.begin(DEBUG_ESP3D_OUTPUT_PORT, true);
|
||||
#define DEBUG_ESP3D_NETWORK_HANDLE websocket_debug.handle();
|
||||
#define DEBUG_ESP3D_NETWORK_END websocket_debug.end();
|
||||
#define log_esp3d(format, ...) websocket_debug.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define log_esp3ds(format, ...) websocket_debug.printf(format, ##__VA_ARGS__)
|
||||
#endif // DEBUG_OUTPUT_WEBSOCKET
|
||||
#else
|
||||
#define log_esp3d(format, ...)
|
||||
#define log_esp3ds(format, ...)
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
|
||||
#endif //_DEBUG_ESP3D_H
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
This file is part of ESP3D Firmware for 3D printer.
|
||||
|
||||
ESP3D Firmware for 3D printer is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
ESP3D Firmware for 3D printer is free software: you can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
ESP3D Firmware for 3D printer is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
ESP3D Firmware for 3D printer is distributed in the hope that it will be
|
||||
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this Firmware. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
This firmware is using the standard arduino IDE with module to support ESP8266/ESP32:
|
||||
https://github.com/esp8266/Arduino
|
||||
This firmware is using the standard arduino IDE with module to support
|
||||
ESP8266/ESP32: https://github.com/esp8266/Arduino
|
||||
https://github.com/espressif/arduino-esp32
|
||||
|
||||
Latest version of the code and documentation can be found here :
|
||||
@ -25,8 +25,10 @@
|
||||
|
||||
*/
|
||||
#include "esp3d.h"
|
||||
|
||||
#include "../include/esp3d_config.h"
|
||||
#include "settings_esp3d.h"
|
||||
|
||||
#if COMMUNICATION_PROTOCOL != SOCKET_SERIAL || ESP_SERIAL_BRIDGE_OUTPUT
|
||||
#include "../modules/serial/serial_service.h"
|
||||
#endif // COMMUNICATION_PROTOCOL != SOCKET_SERIAL
|
||||
@ -54,30 +56,22 @@
|
||||
#ifdef SD_UPDATE_FEATURE
|
||||
#include "../modules/update/update_service.h"
|
||||
#endif // SD_UPDATE_FEATURE
|
||||
#include "esp3doutput.h"
|
||||
#include "../modules/boot_delay/boot_delay.h"
|
||||
|
||||
#include "esp3doutput.h"
|
||||
|
||||
bool Esp3D::restart = false;
|
||||
|
||||
// Contructor
|
||||
Esp3D::Esp3D()
|
||||
{
|
||||
_started = false;
|
||||
}
|
||||
Esp3D::Esp3D() { _started = false; }
|
||||
|
||||
// Destructor
|
||||
Esp3D::~Esp3D()
|
||||
{
|
||||
end();
|
||||
}
|
||||
Esp3D::~Esp3D() { end(); }
|
||||
|
||||
// Begin which setup everything
|
||||
bool Esp3D::begin()
|
||||
{
|
||||
bool Esp3D::begin() {
|
||||
BootDelay bd;
|
||||
Hal::begin();
|
||||
DEBUG_ESP3D_INIT
|
||||
LOG_ESP3D_INIT
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
Serial2Socket.enable();
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
@ -86,7 +80,7 @@ bool Esp3D::begin()
|
||||
bool res = true;
|
||||
#if defined(CONNECTED_DEVICES_FEATURE)
|
||||
if (!DevicesServices::begin()) {
|
||||
log_esp3d("Error setup connected devices");
|
||||
log_esp3d_e("Error setup connected devices");
|
||||
res = false;
|
||||
}
|
||||
#endif // CONNECTED_DEVICES_FEATURE
|
||||
@ -110,21 +104,22 @@ bool Esp3D::begin()
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
// Serial service
|
||||
if (!serial_service.begin(ESP_SERIAL_OUTPUT)) {
|
||||
log_esp3d("Error with serial service");
|
||||
log_esp3d_e("Error with serial service");
|
||||
res = false;
|
||||
}
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
// Serial bridge
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
if (!serial_bridge_service.begin(ESP_SERIAL_BRIDGE_OUTPUT)) {
|
||||
log_esp3d("Error with serial bridge service");
|
||||
log_esp3d_e("Error with serial bridge service");
|
||||
res = false;
|
||||
}
|
||||
#endif // ESP_SERIAL_BRIDGE_OUTPUT
|
||||
// Setup Filesystem
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
if (!ESP_FileSystem::begin()) {
|
||||
log_esp3d("Error with filesystem service");
|
||||
log_esp3d_e("Error with filesystem service");
|
||||
res = false;
|
||||
}
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
@ -136,7 +131,7 @@ bool Esp3D::begin()
|
||||
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BLUETOOTH_FEATURE)
|
||||
if (Settings_ESP3D::read_byte(ESP_BOOT_RADIO_STATE) == 1) {
|
||||
if (!NetConfig::begin()) {
|
||||
log_esp3d("Error setup network");
|
||||
log_esp3d_e("Error setup network");
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
@ -155,8 +150,7 @@ bool Esp3D::begin()
|
||||
}
|
||||
|
||||
// Process which handle all input
|
||||
void Esp3D::handle()
|
||||
{
|
||||
void Esp3D::handle() {
|
||||
if (!_started) {
|
||||
return;
|
||||
}
|
||||
@ -166,7 +160,8 @@ void Esp3D::handle()
|
||||
}
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
serial_service.handle();
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
serial_bridge_service.handle();
|
||||
#endif // ESP_SERIAL_BRIDGE_OUTPUT
|
||||
@ -184,14 +179,10 @@ void Esp3D::handle()
|
||||
#endif // GCODE_HOST_FEATURE
|
||||
}
|
||||
|
||||
bool Esp3D::started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
bool Esp3D::started() { return _started; }
|
||||
|
||||
// End ESP3D
|
||||
bool Esp3D::end()
|
||||
{
|
||||
bool Esp3D::end() {
|
||||
_started = false;
|
||||
#if defined(CONNECTED_DEVICES_FEATURE)
|
||||
DevicesServices::end();
|
||||
@ -207,42 +198,40 @@ bool Esp3D::end()
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
serial_service.end();
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reset ESP3D settings
|
||||
bool Esp3D::reset()
|
||||
{
|
||||
bool Esp3D::reset() {
|
||||
bool resetOk = true;
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
if (!serial_service.reset()) {
|
||||
resetOk = false;
|
||||
log_esp3d("Reset serial error");
|
||||
log_esp3d_e("Reset serial error");
|
||||
}
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
if (!serial_bridge_service.reset()) {
|
||||
resetOk = false;
|
||||
log_esp3d("Reset serial bridge error");
|
||||
log_esp3d_e("Reset serial bridge error");
|
||||
}
|
||||
#endif // ESP_SERIAL_BRIDGE_OUTPUT
|
||||
if (!Settings_ESP3D::reset()) {
|
||||
log_esp3d("Reset settings error");
|
||||
log_esp3d_e("Reset settings error");
|
||||
resetOk = false;
|
||||
}
|
||||
return resetOk;
|
||||
}
|
||||
|
||||
// Set Restart flag
|
||||
void Esp3D::restart_esp(bool need_restart)
|
||||
{
|
||||
restart = need_restart;
|
||||
}
|
||||
void Esp3D::restart_esp(bool need_restart) { restart = need_restart; }
|
||||
|
||||
void Esp3D::restart_now()
|
||||
{
|
||||
//patch for https://github.com/espressif/arduino-esp32/issues/1912#issuecomment-426247971
|
||||
void Esp3D::restart_now() {
|
||||
// patch for
|
||||
// https://github.com/espressif/arduino-esp32/issues/1912#issuecomment-426247971
|
||||
#if defined(ETH_FEATURE) && defined(ESP3D_ETH_PHY_POWER_PIN)
|
||||
digitalWrite(ESP3D_ETH_PHY_POWER_PIN, LOW);
|
||||
#endif // ESP3D_ETH_PHY_POWER_PIN
|
||||
@ -252,16 +241,17 @@ void Esp3D::restart_now()
|
||||
serial_service.begin(ESP_SERIAL_OUTPUT);
|
||||
}
|
||||
serial_service.flush();
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
ESP_FileSystem::end();
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
serial_service.swap();
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
ESP.restart();
|
||||
while (1) {
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,7 @@
|
||||
#error Oops! Make sure you have 'ESP8266 or ESP32' compatible board selected from the 'Tools -> Boards' menu.
|
||||
#endif // ARDUINO_ARCH_ESP8266 + ARDUINO_ARCH_ESP32
|
||||
#include <Arduino.h>
|
||||
class Esp3D
|
||||
{
|
||||
class Esp3D {
|
||||
public:
|
||||
Esp3D();
|
||||
~Esp3D();
|
||||
@ -36,6 +35,7 @@ public:
|
||||
bool started();
|
||||
static bool reset();
|
||||
static void restart_esp(bool need_restart = true);
|
||||
|
||||
private:
|
||||
static bool restart;
|
||||
bool _started;
|
||||
|
@ -17,9 +17,11 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
#include "../include/esp3d_config.h"
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "esp3doutput.h"
|
||||
|
||||
#include "../include/esp3d_config.h"
|
||||
|
||||
#if COMMUNICATION_PROTOCOL != SOCKET_SERIAL || defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
#include "../modules/serial/serial_service.h"
|
||||
#endif // COMMUNICATION_PROTOCOL != SOCKET_SERIAL
|
||||
@ -43,9 +45,12 @@
|
||||
#include "../modules/gcode_host/gcode_host.h"
|
||||
#endif // GCODE_HOST_FEATURE
|
||||
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || \
|
||||
COMMUNICATION_PROTOCOL == MKS_SERIAL || \
|
||||
COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
uint8_t ESP3DOutput::_serialoutputflags = DEFAULT_SERIAL_OUTPUT_FLAG;
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#if defined(HAS_DISPLAY) || defined(HAS_SERIAL_DISPLAY)
|
||||
uint8_t ESP3DOutput::_remotescreenoutputflags = DEFAULT_REMOTE_SCREEN_FLAG;
|
||||
#endif // HAS_DISPLAY || HAS_SERIAL_DISPLAY
|
||||
@ -77,7 +82,9 @@ uint8_t ESP3DOutput::_serialBridgeoutputflags = DEFAULT_SERIAL_BRIDGE_FLAG;
|
||||
#endif // DISPLAY_DEVICE
|
||||
|
||||
const uint8_t activeClients[] = {
|
||||
#if !(defined(HAS_DISPLAY) || defined(HAS_SERIAL_DISPLAY)) && (COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL)
|
||||
#if !(defined(HAS_DISPLAY) || defined(HAS_SERIAL_DISPLAY)) && \
|
||||
(COMMUNICATION_PROTOCOL == RAW_SERIAL || \
|
||||
COMMUNICATION_PROTOCOL == MKS_SERIAL)
|
||||
ESP_SERIAL_CLIENT,
|
||||
#endif // ESP_SERIAL_CLIENT
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
@ -105,12 +112,10 @@ const uint8_t activeClients [] = {
|
||||
ESP_SOCKET_SERIAL_CLIENT,
|
||||
ESP_ECHO_SERIAL_CLIENT,
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
ESP_NO_CLIENT
|
||||
};
|
||||
ESP_NO_CLIENT};
|
||||
|
||||
// tool function to avoid string corrupt JSON files
|
||||
const char * ESP3DOutput::encodeString(const char * s)
|
||||
{
|
||||
const char *ESP3DOutput::encodeString(const char *s) {
|
||||
static String tmp;
|
||||
tmp = s;
|
||||
while (tmp.indexOf("'") != -1) {
|
||||
@ -125,8 +130,7 @@ const char * ESP3DOutput::encodeString(const char * s)
|
||||
return tmp.c_str();
|
||||
}
|
||||
|
||||
void ESP3DOutput::toScreen(uint8_t output_type, const char * s)
|
||||
{
|
||||
void ESP3DOutput::toScreen(uint8_t output_type, const char *s) {
|
||||
switch (output_type) {
|
||||
case ESP_OUTPUT_IP_ADDRESS:
|
||||
#ifdef DISPLAY_DEVICE
|
||||
@ -161,8 +165,7 @@ void ESP3DOutput::toScreen(uint8_t output_type, const char * s)
|
||||
}
|
||||
|
||||
// constructor
|
||||
ESP3DOutput::ESP3DOutput(uint8_t client)
|
||||
{
|
||||
ESP3DOutput::ESP3DOutput(uint8_t client) {
|
||||
_client = client;
|
||||
|
||||
#ifdef HTTP_FEATURE
|
||||
@ -173,8 +176,7 @@ ESP3DOutput::ESP3DOutput(uint8_t client)
|
||||
#endif // HTTP_FEATURE
|
||||
}
|
||||
|
||||
uint8_t ESP3DOutput::client(uint8_t client )
|
||||
{
|
||||
uint8_t ESP3DOutput::client(uint8_t client) {
|
||||
if (client != 0) {
|
||||
_client = client;
|
||||
}
|
||||
@ -183,8 +185,7 @@ uint8_t ESP3DOutput::client(uint8_t client )
|
||||
|
||||
#ifdef HTTP_FEATURE
|
||||
// constructor
|
||||
ESP3DOutput::ESP3DOutput(WEBSERVER * webserver)
|
||||
{
|
||||
ESP3DOutput::ESP3DOutput(WEBSERVER *webserver) {
|
||||
_client = ESP_HTTP_CLIENT;
|
||||
_code = 200;
|
||||
_headerSent = false;
|
||||
@ -194,22 +195,23 @@ ESP3DOutput::ESP3DOutput(WEBSERVER * webserver)
|
||||
#endif // HTTP_FEATURE
|
||||
|
||||
// destructor
|
||||
ESP3DOutput::~ESP3DOutput()
|
||||
{
|
||||
flush();
|
||||
}
|
||||
ESP3DOutput::~ESP3DOutput() { flush(); }
|
||||
|
||||
bool ESP3DOutput::isOutput(uint8_t flag, bool fromsettings)
|
||||
{
|
||||
bool ESP3DOutput::isOutput(uint8_t flag, bool fromsettings) {
|
||||
if (fromsettings) {
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || \
|
||||
COMMUNICATION_PROTOCOL == MKS_SERIAL || \
|
||||
COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
_serialoutputflags = Settings_ESP3D::read_byte(ESP_SERIAL_FLAG);
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
_serialBridgeoutputflags= Settings_ESP3D::read_byte (ESP_SERIAL_BRIDGE_FLAG);
|
||||
_serialBridgeoutputflags =
|
||||
Settings_ESP3D::read_byte(ESP_SERIAL_BRIDGE_FLAG);
|
||||
#endif // ESP_SERIAL_BRIDGE_OUTPUT
|
||||
#if defined(HAS_DISPLAY) || defined(HAS_SERIAL_DISPLAY)
|
||||
_remotescreenoutputflags= Settings_ESP3D::read_byte (ESP_REMOTE_SCREEN_FLAG);
|
||||
_remotescreenoutputflags =
|
||||
Settings_ESP3D::read_byte(ESP_REMOTE_SCREEN_FLAG);
|
||||
#endif // defined(HAS_DISPLAY) || defined(HAS_SERIAL_DISPLAY)
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
_websocketoutputflags = Settings_ESP3D::read_byte(ESP_WEBSOCKET_FLAG);
|
||||
@ -227,9 +229,12 @@ bool ESP3DOutput::isOutput(uint8_t flag, bool fromsettings)
|
||||
switch (flag) {
|
||||
case ESP_ECHO_SERIAL_CLIENT:
|
||||
case ESP_SERIAL_CLIENT:
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || \
|
||||
COMMUNICATION_PROTOCOL == MKS_SERIAL || \
|
||||
COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
return _serialoutputflags;
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
return 0;
|
||||
case ESP_SERIAL_BRIDGE_CLIENT:
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
@ -266,11 +271,13 @@ bool ESP3DOutput::isOutput(uint8_t flag, bool fromsettings)
|
||||
}
|
||||
}
|
||||
|
||||
size_t ESP3DOutput::dispatch (const uint8_t * sbuf, size_t len, uint8_t ignoreClient)
|
||||
{
|
||||
log_esp3d("Dispatch %d chars from client %d and ignore %d", len, _client, ignoreClient);
|
||||
size_t ESP3DOutput::dispatch(const uint8_t *sbuf, size_t len,
|
||||
uint8_t ignoreClient) {
|
||||
log_esp3d("Dispatch %d chars from client %d and ignore %d", len, _client,
|
||||
ignoreClient);
|
||||
#if defined(GCODE_HOST_FEATURE)
|
||||
if (!(_client == ESP_STREAM_HOST_CLIENT || ESP_STREAM_HOST_CLIENT==ignoreClient)) {
|
||||
if (!(_client == ESP_STREAM_HOST_CLIENT ||
|
||||
ESP_STREAM_HOST_CLIENT == ignoreClient)) {
|
||||
log_esp3d("Dispatch to gcode host");
|
||||
esp3d_gcode_host.push(sbuf, len);
|
||||
}
|
||||
@ -287,19 +294,27 @@ size_t ESP3DOutput::dispatch (const uint8_t * sbuf, size_t len, uint8_t ignoreCl
|
||||
#endif // COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
}
|
||||
}
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
if (!(_client == ESP_SOCKET_SERIAL_CLIENT || ESP_SOCKET_SERIAL_CLIENT==ignoreClient)) {
|
||||
log_esp3d("Dispatch to serial socket client %d is %d, or is %d", _client, ESP_SOCKET_SERIAL_CLIENT, ignoreClient);
|
||||
if (!(_client == ESP_SOCKET_SERIAL_CLIENT ||
|
||||
ESP_SOCKET_SERIAL_CLIENT == ignoreClient)) {
|
||||
log_esp3d("Dispatch to serial socket client %d is %d, or is %d", _client,
|
||||
ESP_SOCKET_SERIAL_CLIENT, ignoreClient);
|
||||
Serial2Socket.push(sbuf, len);
|
||||
}
|
||||
if (!(_client == ESP_ECHO_SERIAL_CLIENT || ESP_ECHO_SERIAL_CLIENT==ignoreClient ||_client == ESP_SOCKET_SERIAL_CLIENT)) {
|
||||
if (!(_client == ESP_ECHO_SERIAL_CLIENT ||
|
||||
ESP_ECHO_SERIAL_CLIENT == ignoreClient ||
|
||||
_client == ESP_SOCKET_SERIAL_CLIENT)) {
|
||||
log_esp3d("Dispatch to echo serial");
|
||||
MYSERIAL1.write(sbuf, len);
|
||||
}
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#if defined(HTTP_FEATURE) // no need to block it never
|
||||
if (!((_client == ESP_WEBSOCKET_TERMINAL_CLIENT) || (_client == ESP_HTTP_CLIENT)|| (ESP_WEBSOCKET_TERMINAL_CLIENT==ignoreClient) || (ESP_HTTP_CLIENT==ignoreClient))) {
|
||||
if (!((_client == ESP_WEBSOCKET_TERMINAL_CLIENT) ||
|
||||
(_client == ESP_HTTP_CLIENT) ||
|
||||
(ESP_WEBSOCKET_TERMINAL_CLIENT == ignoreClient) ||
|
||||
(ESP_HTTP_CLIENT == ignoreClient))) {
|
||||
if (websocket_terminal_server) {
|
||||
log_esp3d("Dispatch websocket terminal");
|
||||
websocket_terminal_server.write(sbuf, len);
|
||||
@ -315,7 +330,8 @@ size_t ESP3DOutput::dispatch (const uint8_t * sbuf, size_t len, uint8_t ignoreCl
|
||||
}
|
||||
#endif // BLUETOOTH_FEATURE
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
if (!(_client == ESP_SERIAL_BRIDGE_CLIENT || ESP_SERIAL_BRIDGE_CLIENT==ignoreClient)) {
|
||||
if (!(_client == ESP_SERIAL_BRIDGE_CLIENT ||
|
||||
ESP_SERIAL_BRIDGE_CLIENT == ignoreClient)) {
|
||||
if (isOutput(ESP_SERIAL_BRIDGE_CLIENT) && serial_bridge_service.started()) {
|
||||
log_esp3d("Dispatch to serial bridge");
|
||||
serial_bridge_service.write(sbuf, len);
|
||||
@ -331,7 +347,8 @@ size_t ESP3DOutput::dispatch (const uint8_t * sbuf, size_t len, uint8_t ignoreCl
|
||||
}
|
||||
#endif // TELNET_FEATURE
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
if (!(_client == ESP_WEBSOCKET_CLIENT || ESP_WEBSOCKET_CLIENT==ignoreClient)) {
|
||||
if (!(_client == ESP_WEBSOCKET_CLIENT ||
|
||||
ESP_WEBSOCKET_CLIENT == ignoreClient)) {
|
||||
if (isOutput(ESP_WEBSOCKET_CLIENT) && websocket_data_server.started()) {
|
||||
log_esp3d("Dispatch to websocket data server");
|
||||
websocket_data_server.write(sbuf, len);
|
||||
@ -342,8 +359,7 @@ size_t ESP3DOutput::dispatch (const uint8_t * sbuf, size_t len, uint8_t ignoreCl
|
||||
}
|
||||
|
||||
// Flush
|
||||
void ESP3DOutput::flush()
|
||||
{
|
||||
void ESP3DOutput::flush() {
|
||||
if (!isOutput(_client)) {
|
||||
return;
|
||||
}
|
||||
@ -352,7 +368,8 @@ void ESP3DOutput::flush()
|
||||
case ESP_SERIAL_CLIENT:
|
||||
serial_service.flush();
|
||||
break;
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#ifdef HTTP_FEATURE
|
||||
case ESP_HTTP_CLIENT:
|
||||
if (_webserver) {
|
||||
@ -386,8 +403,7 @@ void ESP3DOutput::flush()
|
||||
}
|
||||
}
|
||||
|
||||
size_t ESP3DOutput::printLN(const char * s)
|
||||
{
|
||||
size_t ESP3DOutput::printLN(const char *s) {
|
||||
if (!isOutput(_client)) {
|
||||
return 0;
|
||||
}
|
||||
@ -411,9 +427,7 @@ size_t ESP3DOutput::printLN(const char * s)
|
||||
return println(s);
|
||||
}
|
||||
|
||||
size_t ESP3DOutput::printMSGLine(const char * s)
|
||||
{
|
||||
|
||||
size_t ESP3DOutput::printMSGLine(const char *s) {
|
||||
if (_client == ESP_ALL_CLIENTS) {
|
||||
// process each client one by one
|
||||
log_esp3d("PrintMSG to all clients");
|
||||
@ -453,7 +467,8 @@ size_t ESP3DOutput::printMSGLine(const char * s)
|
||||
return 0;
|
||||
}
|
||||
// this is not supposed to be displayed on any screen
|
||||
if (_client == ESP_SCREEN_CLIENT || _client == ESP_REMOTE_SCREEN_CLIENT ||_client == ESP_SCREEN_CLIENT ) {
|
||||
if (_client == ESP_SCREEN_CLIENT || _client == ESP_REMOTE_SCREEN_CLIENT ||
|
||||
_client == ESP_SCREEN_CLIENT) {
|
||||
return print(s);
|
||||
}
|
||||
switch (Settings_ESP3D::GetFirmwareTarget()) {
|
||||
@ -464,7 +479,9 @@ size_t ESP3DOutput::printMSGLine(const char * s)
|
||||
break;
|
||||
case MARLIN_EMBEDDED:
|
||||
case MARLIN:
|
||||
if (((_client == ESP_ECHO_SERIAL_CLIENT) ||(_client == ESP_STREAM_HOST_CLIENT)) && (strcmp(s, "ok") == 0)) {
|
||||
if (((_client == ESP_ECHO_SERIAL_CLIENT) ||
|
||||
(_client == ESP_STREAM_HOST_CLIENT)) &&
|
||||
(strcmp(s, "ok") == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -486,12 +503,9 @@ size_t ESP3DOutput::printMSGLine(const char * s)
|
||||
}
|
||||
|
||||
return printLN(display.c_str());
|
||||
|
||||
}
|
||||
|
||||
size_t ESP3DOutput::printMSG(const char * s, bool withNL)
|
||||
{
|
||||
|
||||
size_t ESP3DOutput::printMSG(const char *s, bool withNL) {
|
||||
if (_client == ESP_ALL_CLIENTS) {
|
||||
// process each client one by one
|
||||
log_esp3d("PrintMSG to all clients");
|
||||
@ -539,7 +553,9 @@ size_t ESP3DOutput::printMSG(const char * s, bool withNL)
|
||||
break;
|
||||
case MARLIN_EMBEDDED:
|
||||
case MARLIN:
|
||||
if (((_client == ESP_ECHO_SERIAL_CLIENT) ||(_client == ESP_STREAM_HOST_CLIENT)) && (strcmp(s, "ok") == 0)) {
|
||||
if (((_client == ESP_ECHO_SERIAL_CLIENT) ||
|
||||
(_client == ESP_STREAM_HOST_CLIENT)) &&
|
||||
(strcmp(s, "ok") == 0)) {
|
||||
return 0;
|
||||
}
|
||||
if (_client == ESP_REMOTE_SCREEN_CLIENT) {
|
||||
@ -576,8 +592,7 @@ size_t ESP3DOutput::printMSG(const char * s, bool withNL)
|
||||
}
|
||||
}
|
||||
|
||||
size_t ESP3DOutput::printERROR(const char * s, int code_error)
|
||||
{
|
||||
size_t ESP3DOutput::printERROR(const char *s, int code_error) {
|
||||
String display = "";
|
||||
if (!isOutput(_client)) {
|
||||
return 0;
|
||||
@ -631,13 +646,13 @@ size_t ESP3DOutput::printERROR(const char * s, int code_error)
|
||||
return printLN(display.c_str());
|
||||
}
|
||||
|
||||
int ESP3DOutput::availableforwrite()
|
||||
{
|
||||
int ESP3DOutput::availableforwrite() {
|
||||
switch (_client) {
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
case ESP_SERIAL_CLIENT:
|
||||
return serial_service.availableForWrite();
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
case ESP_SERIAL_BRIDGE_CLIENT:
|
||||
return serial_bridge_service.availableForWrite();
|
||||
@ -660,14 +675,14 @@ int ESP3DOutput::availableforwrite()
|
||||
case ESP_ALL_CLIENTS:
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
return serial_service.availableForWrite();
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
size_t ESP3DOutput::write(uint8_t c)
|
||||
{
|
||||
size_t ESP3DOutput::write(uint8_t c) {
|
||||
if (!isOutput(_client)) {
|
||||
return 0;
|
||||
}
|
||||
@ -675,7 +690,8 @@ size_t ESP3DOutput::write(uint8_t c)
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
case ESP_SERIAL_CLIENT:
|
||||
return serial_service.write(c);
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
case ESP_ECHO_SERIAL_CLIENT:
|
||||
return MYSERIAL1.write(c);
|
||||
@ -711,7 +727,8 @@ size_t ESP3DOutput::write(uint8_t c)
|
||||
#endif // TELNET_FEATURE
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
serial_service.write(c);
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
MYSERIAL1.write(c);
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
@ -721,8 +738,7 @@ size_t ESP3DOutput::write(uint8_t c)
|
||||
}
|
||||
}
|
||||
|
||||
size_t ESP3DOutput::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t ESP3DOutput::write(const uint8_t *buffer, size_t size) {
|
||||
if (!isOutput(_client)) {
|
||||
return 0;
|
||||
}
|
||||
@ -767,11 +783,14 @@ size_t ESP3DOutput::write(const uint8_t *buffer, size_t size)
|
||||
#if defined(GCODE_HOST_FEATURE)
|
||||
case ESP_STREAM_HOST_CLIENT: {
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
log_esp3d("ESP_STREAM_HOST_CLIENT do a dispatch to all clients but socket serial");
|
||||
log_esp3d(
|
||||
"ESP_STREAM_HOST_CLIENT do a dispatch to all clients but socket "
|
||||
"serial");
|
||||
dispatch(buffer, size, ESP_SOCKET_SERIAL_CLIENT);
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
log_esp3d("ESP_STREAM_HOST_CLIENT do a dispatch to all clients but serial");
|
||||
log_esp3d(
|
||||
"ESP_STREAM_HOST_CLIENT do a dispatch to all clients but serial");
|
||||
dispatch(buffer, size, ESP_SERIAL_CLIENT);
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
}
|
||||
@ -784,7 +803,8 @@ size_t ESP3DOutput::write(const uint8_t *buffer, size_t size)
|
||||
case ESP_SERIAL_CLIENT:
|
||||
return serial_service.write(buffer, size);
|
||||
break;
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
case ESP_REMOTE_SCREEN_CLIENT:
|
||||
log_esp3d("Writing to remote screen: %s", buffer);
|
||||
@ -809,7 +829,8 @@ size_t ESP3DOutput::write(const uint8_t *buffer, size_t size)
|
||||
#endif // TELNET_FEATURE
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
serial_service.write(buffer, size);
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
MYSERIAL1.write(buffer, size);
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
@ -819,6 +840,3 @@ size_t ESP3DOutput::write(const uint8_t *buffer, size_t size)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -17,19 +17,20 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#include "../../modules/network/netconfig.h"
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/network/netconfig.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
|
||||
#define COMMANDID 111
|
||||
// Get current IP
|
||||
//[ESP111] [json=no]
|
||||
bool Commands::ESP111(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool Commands::ESP111(const char* cmd_params, level_authenticate_type auth_type,
|
||||
ESP3DOutput* output) {
|
||||
log_esp3d("Client is %d", output ? output->client() : 0);
|
||||
(void)auth_type;
|
||||
bool noError = true;
|
||||
@ -37,7 +38,8 @@ bool Commands::ESP111(const char* cmd_params, level_authenticate_type auth_type,
|
||||
String response;
|
||||
String parameter = clean_param(get_param(cmd_params, ""));
|
||||
if (parameter.length() == 0) {
|
||||
response = format_response(COMMANDID, json, true, NetConfig::localIP().c_str());
|
||||
response =
|
||||
format_response(COMMANDID, json, true, NetConfig::localIP().c_str());
|
||||
} else {
|
||||
parameter = get_param(cmd_params, "OUTPUT=");
|
||||
if (parameter != "PRINTER") {
|
||||
|
@ -18,10 +18,11 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "../../include/esp3d_config.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
|
||||
#if COMMUNICATION_PROTOCOL != SOCKET_SERIAL || defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
#include "../../modules/serial/serial_service.h"
|
||||
#endif // COMMUNICATION_PROTOCOL != SOCKET_SERIAL
|
||||
@ -81,16 +82,18 @@
|
||||
// Get ESP current status
|
||||
// output is JSON or plain text according parameter
|
||||
//[ESP420]json=<no>
|
||||
bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
ESP3DOutput* output) {
|
||||
bool noError = true;
|
||||
bool json = has_tag(cmd_params, "json");
|
||||
String response;
|
||||
String parameter;
|
||||
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
|
||||
int errorCode = 200; // unless it is a server error use 200 as default and
|
||||
// set error in json instead
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (auth_type == LEVEL_GUEST) {
|
||||
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
|
||||
response = format_response(COMMANDID, json, false,
|
||||
"Guest user can't use this command");
|
||||
noError = false;
|
||||
errorCode = 401;
|
||||
}
|
||||
@ -233,7 +236,8 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
}
|
||||
line = "";
|
||||
|
||||
#if (defined (WIFI_FEATURE) || defined (ETH_FEATURE)) && (defined(OTA_FEATURE) || defined(WEB_UPDATE_FEATURE))
|
||||
#if (defined(WIFI_FEATURE) || defined(ETH_FEATURE)) && \
|
||||
(defined(OTA_FEATURE) || defined(WEB_UPDATE_FEATURE))
|
||||
// update space
|
||||
if (json) {
|
||||
line += ",{\"id\":\"";
|
||||
@ -312,7 +316,8 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printMSGLine(line.c_str());
|
||||
}
|
||||
line = "";
|
||||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
#if defined(WIFI_FEATURE)
|
||||
if (WiFi.getMode() != WIFI_OFF) {
|
||||
// sleep mode
|
||||
@ -532,7 +537,9 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
} else {
|
||||
line += ": ";
|
||||
}
|
||||
line+=String(ftp_server.ctrlport())+","+String(ftp_server.dataactiveport())+","+String(ftp_server.datapassiveport());
|
||||
line += String(ftp_server.ctrlport()) + "," +
|
||||
String(ftp_server.dataactiveport()) + "," +
|
||||
String(ftp_server.datapassiveport());
|
||||
if (json) {
|
||||
line += "\"}";
|
||||
output->print(line.c_str());
|
||||
@ -609,8 +616,6 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
line = "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // CAMERA_DEVICE
|
||||
#if defined(DISPLAY_DEVICE)
|
||||
if (json) {
|
||||
@ -823,7 +828,9 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
line += "sta";
|
||||
} else if (WiFi.getMode() == WIFI_AP) {
|
||||
line += "ap";
|
||||
} else if (WiFi.getMode() == WIFI_AP_STA) { //we should not be in this state but just in case ....
|
||||
} else if (WiFi.getMode() ==
|
||||
WIFI_AP_STA) { // we should not be in this state but just in
|
||||
// case ....
|
||||
line += "mixed";
|
||||
} else {
|
||||
line += "unknown";
|
||||
@ -857,7 +864,9 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
line += WiFi.macAddress();
|
||||
} else if (WiFi.getMode() == WIFI_AP) {
|
||||
line += WiFi.softAPmacAddress();
|
||||
} else if (WiFi.getMode() == WIFI_AP_STA) { //we should not be in this state but just in case ....
|
||||
} else if (WiFi.getMode() ==
|
||||
WIFI_AP_STA) { // we should not be in this state but just in
|
||||
// case ....
|
||||
line += WiFi.macAddress();
|
||||
line += "/";
|
||||
line += WiFi.softAPmacAddress();
|
||||
@ -1449,7 +1458,9 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
} else {
|
||||
line += ": ";
|
||||
}
|
||||
line +=(Settings_ESP3D::GetSDDevice() == ESP_DIRECT_SD)?"direct ":(Settings_ESP3D::GetSDDevice() == ESP_SHARED_SD)?"shared ":"none ";
|
||||
line += (Settings_ESP3D::GetSDDevice() == ESP_DIRECT_SD) ? "direct "
|
||||
: (Settings_ESP3D::GetSDDevice() == ESP_SHARED_SD) ? "shared "
|
||||
: "none ";
|
||||
line += "(";
|
||||
line += ESP_SD::FilesystemName();
|
||||
line += ")";
|
||||
@ -1470,7 +1481,9 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
} else {
|
||||
line += ": ";
|
||||
}
|
||||
line +=Settings_ESP3D::read_byte (ESP_SD_CHECK_UPDATE_AT_BOOT)!=0?"ON":"OFF";
|
||||
line += Settings_ESP3D::read_byte(ESP_SD_CHECK_UPDATE_AT_BOOT) != 0
|
||||
? "ON"
|
||||
: "OFF";
|
||||
if (json) {
|
||||
line += "\"}";
|
||||
output->print(line.c_str());
|
||||
@ -1524,32 +1537,32 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
}
|
||||
line = "";
|
||||
#endif // BUZZER_DEVICE
|
||||
#if defined (ESP_DEBUG_FEATURE)
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
// debug
|
||||
if (json) {
|
||||
line += ",{\"id\":\"";
|
||||
}
|
||||
line +="debug";
|
||||
line += "log";
|
||||
if (json) {
|
||||
line += "\",\"value\":\"";
|
||||
} else {
|
||||
line += ": ";
|
||||
}
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL0
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL0
|
||||
line += "Serial";
|
||||
#endif //DEBUG_OUTPUT_SERIAL0
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL1
|
||||
#endif // LOG_OUTPUT_SERIAL0
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL1
|
||||
line += "Serial1";
|
||||
#endif //DEBUG_OUTPUT_SERIAL1
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2
|
||||
#endif // LOG_OUTPUT_SERIAL1
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL2
|
||||
line += "Serial2";
|
||||
#endif //DEBUG_OUTPUT_SERIAL2
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_TELNET
|
||||
line+="Telnet("+String( DEBUG_ESP3D_OUTPUT_PORT) +")";
|
||||
#endif //DEBUG_OUTPUT_TELNET
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
line+="Websocket("+ String(DEBUG_ESP3D_OUTPUT_PORT)+")";
|
||||
#endif //DEBUG_OUTPUT_WEBSOCKET
|
||||
#endif // LOG_OUTPUT_SERIAL2
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_TELNET
|
||||
line += "Telnet(" + String(LOG_ESP3D_OUTPUT_PORT) + ")";
|
||||
#endif // LOG_OUTPUT_TELNET
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_WEBSOCKET
|
||||
line += "Websocket(" + String(LOG_ESP3D_OUTPUT_PORT) + ")";
|
||||
#endif // LOG_OUTPUT_WEBSOCKET
|
||||
if (json) {
|
||||
line += "\"}";
|
||||
output->print(line.c_str());
|
||||
@ -1557,7 +1570,7 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printMSGLine(line.c_str());
|
||||
}
|
||||
line = "";
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
#endif // ESP_LOG_FEATURE
|
||||
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
// Target Firmware
|
||||
if (json) {
|
||||
@ -1642,7 +1655,8 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
response = format_response(COMMANDID, json, false, "This command doesn't take parameters");
|
||||
response = format_response(COMMANDID, json, false,
|
||||
"This command doesn't take parameters");
|
||||
noError = false;
|
||||
}
|
||||
}
|
||||
|
@ -17,28 +17,31 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined(GCODE_HOST_FEATURE)
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#include "../../modules/gcode_host/gcode_host.h"
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#include "../../modules/gcode_host/gcode_host.h"
|
||||
|
||||
#define COMMANDID 701
|
||||
|
||||
// Query and Control ESP700 stream
|
||||
//[ESP701]action=<PAUSE/RESUME/ABORT>
|
||||
bool Commands::ESP701(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool Commands::ESP701(const char* cmd_params, level_authenticate_type auth_type,
|
||||
ESP3DOutput* output) {
|
||||
bool noError = true;
|
||||
bool json = has_tag(cmd_params, "json");
|
||||
String response;
|
||||
String parameter;
|
||||
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
|
||||
int errorCode = 200; // unless it is a server error use 200 as default and
|
||||
// set error in json instead
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (auth_type != LEVEL_ADMIN) {
|
||||
response = format_response(COMMANDID, json, false, "Wrong authentication level");
|
||||
response =
|
||||
format_response(COMMANDID, json, false, "Wrong authentication level");
|
||||
noError = false;
|
||||
errorCode = 401;
|
||||
}
|
||||
@ -52,21 +55,24 @@ bool Commands::ESP701(const char* cmd_params, level_authenticate_type auth_type,
|
||||
if (esp3d_gcode_host.pause()) {
|
||||
response = format_response(COMMANDID, json, true, "Stream paused");
|
||||
} else {
|
||||
response = format_response(COMMANDID, json, false, "No stream to pause");
|
||||
response =
|
||||
format_response(COMMANDID, json, false, "No stream to pause");
|
||||
noError = false;
|
||||
}
|
||||
} else if (parameter.equalsIgnoreCase("RESUME")) {
|
||||
if (esp3d_gcode_host.resume()) {
|
||||
response = format_response(COMMANDID, json, true, "Stream resumed");
|
||||
} else {
|
||||
response = format_response(COMMANDID, json, false, "No stream to resume");
|
||||
response =
|
||||
format_response(COMMANDID, json, false, "No stream to resume");
|
||||
noError = false;
|
||||
}
|
||||
} else if (parameter.equalsIgnoreCase("ABORT")) {
|
||||
if (esp3d_gcode_host.abort()) {
|
||||
response = format_response(COMMANDID, json, true, "Stream aborted");
|
||||
} else {
|
||||
response = format_response(COMMANDID, json, false, "No stream to abort");
|
||||
response =
|
||||
format_response(COMMANDID, json, false, "No stream to abort");
|
||||
noError = false;
|
||||
}
|
||||
}
|
||||
@ -89,7 +95,11 @@ bool Commands::ESP701(const char* cmd_params, level_authenticate_type auth_type,
|
||||
// TODO add % of progress and filename if any
|
||||
// totalSize / processedSize / fileName
|
||||
if (json) {
|
||||
resp = "{\"status\":\"processing\",\"total\":\"" + String(esp3d_gcode_host.totalSize()) + "\",\"processed\":\"" + String(esp3d_gcode_host.processedSize()) + "\",\"type\":\"" + String(esp3d_gcode_host.getFSType());
|
||||
resp = "{\"status\":\"processing\",\"total\":\"" +
|
||||
String(esp3d_gcode_host.totalSize()) +
|
||||
"\",\"processed\":\"" +
|
||||
String(esp3d_gcode_host.processedSize()) + "\",\"type\":\"" +
|
||||
String(esp3d_gcode_host.getFSType());
|
||||
if (esp3d_gcode_host.getFSType() != TYPE_SCRIPT_STREAM) {
|
||||
resp += "\",\"name\":\"" + String(esp3d_gcode_host.fileName());
|
||||
}
|
||||
@ -110,9 +120,11 @@ bool Commands::ESP701(const char* cmd_params, level_authenticate_type auth_type,
|
||||
if (esp3d_gcode_host.getErrorNum() != ERROR_NO_ERROR) {
|
||||
noError = false;
|
||||
if (json) {
|
||||
resp= "{\"status\":\"no stream\",\"code\":\"" + String(esp3d_gcode_host.getErrorNum()) + "\"}";
|
||||
resp = "{\"status\":\"no stream\",\"code\":\"" +
|
||||
String(esp3d_gcode_host.getErrorNum()) + "\"}";
|
||||
} else {
|
||||
resp = "no stream, last error " + String(esp3d_gcode_host.getErrorNum());
|
||||
resp = "no stream, last error " +
|
||||
String(esp3d_gcode_host.getErrorNum());
|
||||
}
|
||||
} else {
|
||||
resp = "no stream";
|
||||
@ -120,7 +132,9 @@ bool Commands::ESP701(const char* cmd_params, level_authenticate_type auth_type,
|
||||
response = format_response(COMMANDID, json, noError, resp.c_str());
|
||||
break;
|
||||
default:
|
||||
response = format_response(COMMANDID, json, false, String(esp3d_gcode_host.getStatus()).c_str());
|
||||
response =
|
||||
format_response(COMMANDID, json, false,
|
||||
String(esp3d_gcode_host.getStatus()).c_str());
|
||||
noError = false;
|
||||
break;
|
||||
}
|
||||
|
@ -29,21 +29,20 @@
|
||||
// FIXME : S3 not support it yet
|
||||
#include <soc/rtc_wdt.h>
|
||||
#endif // CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
|
||||
#include <soc/rtc_cntl_reg.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <driver/adc.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <soc/rtc_cntl_reg.h>
|
||||
|
||||
TaskHandle_t Hal::xHandle = nullptr;
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
||||
#include "esp3doutput.h"
|
||||
|
||||
|
||||
uint32_t Hal::_analogRange = 255;
|
||||
uint32_t Hal::_analogWriteFreq = 1000;
|
||||
|
||||
void Hal::pinMode(uint8_t pin, uint8_t mode)
|
||||
{
|
||||
void Hal::pinMode(uint8_t pin, uint8_t mode) {
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
if ((pin == 16) && (mode == INPUT_PULLUP)) {
|
||||
::pinMode(pin, INPUT_PULLDOWN_16);
|
||||
@ -53,8 +52,7 @@ void Hal::pinMode(uint8_t pin, uint8_t mode)
|
||||
::pinMode(pin, mode);
|
||||
}
|
||||
|
||||
int Hal::analogRead(uint8_t pin)
|
||||
{
|
||||
int Hal::analogRead(uint8_t pin) {
|
||||
#ifdef ARDUINO_ARCH_ESP8266 // only one ADC on ESP8266 A0
|
||||
(void)pin;
|
||||
return ::analogRead(A0);
|
||||
@ -63,8 +61,7 @@ int Hal::analogRead(uint8_t pin)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Hal::analogWrite(uint8_t pin, uint value)
|
||||
{
|
||||
bool Hal::analogWrite(uint8_t pin, uint value) {
|
||||
if (value > (_analogRange - 1)) {
|
||||
return false;
|
||||
}
|
||||
@ -76,15 +73,13 @@ bool Hal::analogWrite(uint8_t pin, uint value)
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
return true;
|
||||
}
|
||||
void Hal::analogWriteFreq(uint32_t freq)
|
||||
{
|
||||
void Hal::analogWriteFreq(uint32_t freq) {
|
||||
_analogWriteFreq = freq;
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
::analogWriteFreq(_analogWriteFreq);
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
}
|
||||
void Hal::analogRange(uint32_t range)
|
||||
{
|
||||
void Hal::analogRange(uint32_t range) {
|
||||
_analogRange = range;
|
||||
uint8_t resolution = 0;
|
||||
switch (_analogRange) {
|
||||
@ -115,8 +110,7 @@ void Hal::analogRange(uint32_t range)
|
||||
}
|
||||
|
||||
// Setup
|
||||
bool Hal::begin()
|
||||
{
|
||||
bool Hal::begin() {
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CAMERA_DEVICE)
|
||||
log_esp3d("Disable brown out");
|
||||
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // disable brownout detector
|
||||
@ -140,13 +134,10 @@ bool Hal::begin()
|
||||
}
|
||||
|
||||
// End ESP3D
|
||||
void Hal::end()
|
||||
{
|
||||
}
|
||||
void Hal::end() {}
|
||||
|
||||
// Watchdog feeder
|
||||
void Hal::wdtFeed()
|
||||
{
|
||||
void Hal::wdtFeed() {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
ESP.wdtFeed();
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
@ -166,7 +157,7 @@ void Hal::wdtFeed()
|
||||
#ifndef DISABLE_WDT_ESP3DLIB_TASK
|
||||
if (xHandle && esp_task_wdt_status(xHandle) == ESP_OK) {
|
||||
if (esp_task_wdt_reset() != ESP_OK) {
|
||||
log_esp3d("WDT Reset failed");
|
||||
log_esp3d_e("WDT Reset failed");
|
||||
}
|
||||
}
|
||||
#endif // DISABLE_WDT_ESP3DLIB_TASK
|
||||
@ -174,8 +165,7 @@ void Hal::wdtFeed()
|
||||
}
|
||||
|
||||
// wait function
|
||||
void Hal::wait (uint32_t milliseconds)
|
||||
{
|
||||
void Hal::wait(uint32_t milliseconds) {
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
uint32_t timeout = millis();
|
||||
while ((millis() - timeout) < milliseconds) {
|
||||
@ -183,13 +173,13 @@ void Hal::wait (uint32_t milliseconds)
|
||||
}
|
||||
#else // !(ASYNCWEBSERVER
|
||||
wdtFeed();
|
||||
//before 0 was acceptable, now it seems need to put 5 to have some effect if on esp32 core 0
|
||||
// before 0 was acceptable, now it seems need to put 5 to have some effect if
|
||||
// on esp32 core 0
|
||||
delay(milliseconds < 5 ? 5 : milliseconds);
|
||||
#endif // !ASYNCWEBSERVER
|
||||
}
|
||||
|
||||
uint16_t Hal::getChipID()
|
||||
{
|
||||
uint16_t Hal::getChipID() {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
return ESP.getChipId();
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
@ -198,8 +188,7 @@ uint16_t Hal::getChipID()
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
}
|
||||
|
||||
bool Hal::has_temperature_sensor()
|
||||
{
|
||||
bool Hal::has_temperature_sensor() {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
return false;
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
@ -213,8 +202,7 @@ bool Hal::has_temperature_sensor()
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
}
|
||||
|
||||
float Hal::temperature()
|
||||
{
|
||||
float Hal::temperature() {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
return 0.0;
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
@ -229,8 +217,7 @@ float Hal::temperature()
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
}
|
||||
|
||||
bool Hal::is_pin_usable(uint pin)
|
||||
{
|
||||
bool Hal::is_pin_usable(uint pin) {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
if ((pin <= 5) || ((pin >= 12) && (pin <= 16))) {
|
||||
return true;
|
||||
|
58
esp3d/src/core/log_esp3d.cpp
Normal file
58
esp3d/src/core/log_esp3d.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
log_esp3d.cpp - log esp3d functions class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This code is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../include/esp3d_config.h"
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
|
||||
#ifndef LOG_ESP3D_BAUDRATE
|
||||
#define LOG_ESP3D_BAUDRATE 115200
|
||||
#endif //~LOG_ESP3D_BAUDRATE
|
||||
|
||||
void initEsp3dLog() {
|
||||
#if (ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL0) || \
|
||||
(ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL1) || \
|
||||
(ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL2)
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
LOG_OUTPUT_SERIAL.begin(LOG_ESP3D_BAUDRATE, SERIAL_8N1, SERIAL_FULL,
|
||||
(ESP_LOG_TX_PIN == -1) ? 1 : ESP_LOG_TX_PIN);
|
||||
#if ESP_LOG_RX_PIN != -1
|
||||
LOG_OUTPUT_SERIAL
|
||||
.pins((ESP_LOG_TX_PIN == -1) ? 1 : ESP_LOG_TX_PIN, ESP_LOG_RX_PIN)
|
||||
#endif // ESP_LOG_RX_PIN != -1
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
LOG_OUTPUT_SERIAL.begin(LOG_ESP3D_BAUDRATE, SERIAL_8N1,
|
||||
ESP_LOG_RX_PIN, ESP_LOG_TX_PIN);
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
||||
#endif // (ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL0) || (ESP_LOG_FEATURE ==
|
||||
// LOG_OUTPUT_SERIAL1)||(ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL2)
|
||||
}
|
||||
|
||||
// Telnet
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_TELNET
|
||||
Telnet_Server telnet_log;
|
||||
#endif // ESP_LOG_FEATURE == LOG_OUTPUT_TELNET
|
||||
|
||||
// Websocket
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_WEBSOCKET
|
||||
WebSocket_Server websocket_log("log");
|
||||
#endif // ESP_LOG_FEATURE == LOG_OUTPUT_WEBSOCKET
|
||||
#endif // ESP_LOG_FEATURE
|
183
esp3d/src/core/log_esp3d.h
Normal file
183
esp3d/src/core/log_esp3d.h
Normal file
@ -0,0 +1,183 @@
|
||||
/*
|
||||
log_esp3d.h - esp3d log functions
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This code is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _LOG_ESP3D_H
|
||||
#define _LOG_ESP3D_H
|
||||
#include "../include/defines.h"
|
||||
#include "../include/esp3d_config.h"
|
||||
|
||||
#ifndef ESP3D_DEBUG_LEVEL
|
||||
#define ESP3D_DEBUG_LEVEL LOG_LEVEL_NONE
|
||||
#endif // ESP3D_DEBUG_LEVEL
|
||||
|
||||
#define LOG_ESP3D_INIT
|
||||
#define LOG_ESP3D_NETWORK_INIT
|
||||
#define LOG_ESP3D_NETWORK_HANDLE
|
||||
#define LOG_ESP3D_NETWORK_END
|
||||
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
// no need with latest esp8266 core
|
||||
#define pathToFileName(p) p
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
|
||||
#undef log_esp3d
|
||||
#undef log_esp3ds
|
||||
#undef log_esp3d_e
|
||||
#undef log_esp3d_d
|
||||
// Serial
|
||||
#if (ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL0) || \
|
||||
(ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL1) || \
|
||||
(ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL2)
|
||||
|
||||
extern void initEsp3dLog();
|
||||
#ifndef ESP3DLIB_ENV
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL0
|
||||
#define LOG_OUTPUT_SERIAL Serial
|
||||
#endif // LOG_OUTPUT_SERIAL0
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL1
|
||||
#define LOG_OUTPUT_SERIAL Serial1
|
||||
#endif // LOG_OUTPUT_SERIAL1
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL2
|
||||
#define LOG_OUTPUT_SERIAL Serial2
|
||||
#endif // LOG_OUTPUT_SERIAL2
|
||||
#undef LOG_ESP3D_INIT
|
||||
#define LOG_ESP3D_INIT initEsp3dLog();
|
||||
#else
|
||||
#define LOG_OUTPUT_SERIAL MYSERIAL1
|
||||
|
||||
#endif // ESP3DLIB_ENV
|
||||
|
||||
#if ESP3D_DEBUG_LEVEL >= LOG_LEVEL_VERBOSE
|
||||
#define log_esp3d(format, ...) \
|
||||
LOG_OUTPUT_SERIAL.printf("[ESP3D][%s:%u] %s(): " format "\r\n", \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
#define log_esp3ds(format, ...) LOG_OUTPUT_SERIAL.printf(format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define log_esp3d(format, ...)
|
||||
#define log_esp3ds(format, ...)
|
||||
#endif // ESP3D_DEBUG_LEVEL>= LOG_LEVEL_VERBOSE
|
||||
|
||||
#if ESP3D_DEBUG_LEVEL >= LOG_LEVEL_DEBUG
|
||||
#define log_esp3d_d(format, ...) \
|
||||
LOG_OUTPUT_SERIAL.printf("[ESP3D-DEBUG][%s:%u] %s(): " format "\r\n", \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
#else
|
||||
#define log_esp3d_d(format, ...)
|
||||
#endif // ESP3D_DEBUG_LEVEL>= LOG_LEVEL_DEBUG
|
||||
#if ESP3D_DEBUG_LEVEL >= LOG_LEVEL_ERROR
|
||||
#define log_esp3d_e(format, ...) \
|
||||
LOG_OUTPUT_SERIAL.printf("[ESP3D-ERROR][%s:%u] %s(): " format "\r\n", \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
#else
|
||||
#define log_esp3d_e(format, ...)
|
||||
#endif // ESP3D_DEBUG_LEVEL >= LOG_LEVEL_ERROR
|
||||
#endif // LOG_OUTPUT_SERIAL0 || LOG_OUTPUT_SERIAL1 || LOG_OUTPUT_SERIAL2
|
||||
|
||||
// Telnet
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_TELNET
|
||||
#include "../modules/telnet/telnet_server.h"
|
||||
extern Telnet_Server telnet_log;
|
||||
#undef LOG_ESP3D_NETWORK_INIT
|
||||
#undef LOG_ESP3D_NETWORK_END
|
||||
#undef LOG_ESP3D_NETWORK_HANDLE
|
||||
#define LOG_ESP3D_NETWORK_INIT telnet_log.begin(LOG_ESP3D_OUTPUT_PORT, true);
|
||||
#define LOG_ESP3D_NETWORK_HANDLE telnet_log.handle();
|
||||
#define LOG_ESP3D_NETWORK_END telnet_log.end();
|
||||
#if ESP3D_DEBUG_LEVEL >= LOG_LEVEL_VERBOSE
|
||||
#define log_esp3d(format, ...) \
|
||||
if (telnet_log.isConnected()) \
|
||||
telnet_log.printf("[ESP3D][%s:%u] %s(): " format "\r\n", \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
#define log_esp3ds(format, ...) \
|
||||
if (telnet_log.isConnected()) telnet_log.printf(format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define log_esp3d(format, ...)
|
||||
#define log_esp3ds(format, ...)
|
||||
#endif // ESP3D_DEBUG_LEVEL >= LOG_LEVEL_VERBOSE
|
||||
|
||||
#if ESP3D_DEBUG_LEVEL >= LOG_LEVEL_DEBUG
|
||||
#define log_esp3d_d(format, ...) \
|
||||
if (telnet_log.isConnected()) \
|
||||
telnet_log.printf("[ESP3D-DEBUG][%s:%u] %s(): " format "\r\n", \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
#else
|
||||
#define log_esp3d_d(format, ...)
|
||||
#endif // ESP3D_DEBUG_LEVEL >= LOG_LEVEL_DEBUG
|
||||
#if ESP3D_DEBUG_LEVEL >= LOG_LEVEL_ERROR
|
||||
#define log_esp3d_e(format, ...) \
|
||||
if (telnet_log.isConnected()) \
|
||||
telnet_log.printf("[ESP3D-ERROR][%s:%u] %s(): " format "\r\n", \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
|
||||
#endif // ESP3D_DEBUG_LEVEL >= LOG_LEVEL_ERROR
|
||||
#endif // LOG_OUTPUT_TELNET
|
||||
|
||||
// Telnet
|
||||
#if ESP_LOG_FEATURE == LOG_OUTPUT_WEBSOCKET
|
||||
#include "../modules/websocket/websocket_server.h"
|
||||
extern WebSocket_Server websocket_log;
|
||||
#undef LOG_ESP3D_NETWORK_INIT
|
||||
#undef LOG_ESP3D_NETWORK_END
|
||||
#undef LOG_ESP3D_NETWORK_HANDLE
|
||||
#define LOG_ESP3D_NETWORK_INIT websocket_log.begin(LOG_ESP3D_OUTPUT_PORT, true);
|
||||
#define LOG_ESP3D_NETWORK_HANDLE websocket_log.handle();
|
||||
#define LOG_ESP3D_NETWORK_END websocket_log.end();
|
||||
#if ESP3D_DEBUG_LEVEL >= LOG_LEVEL_VERBOSE
|
||||
#define log_esp3d(format, ...) \
|
||||
websocket_log.printf("[ESP3D][%s:%u] %s(): " format "\r\n", \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
#define log_esp3ds(format, ...) websocket_log.printf(format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define log_esp3d(format, ...)
|
||||
#define log_esp3ds(format, ...)
|
||||
#endif // ESP3D_DEBUG_LEVEL >= LOG_LEVEL_VERBOSE
|
||||
|
||||
#if ESP3D_DEBUG_LEVEL >= LOG_LEVEL_DEBUG
|
||||
#define log_esp3d_d(format, ...) \
|
||||
websocket_log.printf("[ESP3D-DEBUG][%s:%u] %s(): " format "\r\n", \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
#else
|
||||
#define log_esp3d(format, ...)
|
||||
#endif // ESP3D_DEBUG_LEVEL >= ESP_LOG_DEBUG
|
||||
|
||||
#if ESP3D_DEBUG_LEVEL >= LOG_LEVEL_ERROR
|
||||
#define log_esp3d(format, ...) \
|
||||
websocket_log.printf("[ESP3D-ERROR][%s:%u] %s(): " format "\r\n", \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
#endif // ESP3D_DEBUG_LEVEL >= LOG_LEVEL_ERROR
|
||||
#endif // LOG_OUTPUT_WEBSOCKET
|
||||
#else
|
||||
#define log_esp3d(format, ...)
|
||||
#define log_esp3ds(format, ...)
|
||||
#define log_esp3d_e(format, ...)
|
||||
#define log_esp3d_d(format, ...)
|
||||
#endif // ESP_LOG_FEATURE
|
||||
|
||||
#endif //_LOG_ESP3D_H
|
@ -20,8 +20,8 @@
|
||||
|
||||
#include "../include/esp3d_config.h"
|
||||
#if defined(ESP_SAVE_SETTINGS)
|
||||
#include "settings_esp3d.h"
|
||||
#include "esp3doutput.h"
|
||||
#include "settings_esp3d.h"
|
||||
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_EEPROM
|
||||
#include <EEPROM.h>
|
||||
@ -36,7 +36,6 @@
|
||||
#endif // WIFI_FEATURE
|
||||
#endif // WIFI_FEATURE || ETH_FEATURE
|
||||
|
||||
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_PREFERENCES
|
||||
#include <Preferences.h>
|
||||
#define NAMESPACE "ESP3D"
|
||||
@ -60,7 +59,6 @@
|
||||
#define MAX_SERVER_ADDRESS_LENGTH 128
|
||||
#define MIN_SERVER_ADDRESS_LENGTH 0
|
||||
|
||||
|
||||
// default byte values
|
||||
#ifdef WIFI_FEATURE
|
||||
#define DEFAULT_STA_FALLBACK_MODE ESP_AP_SETUP
|
||||
@ -88,7 +86,6 @@
|
||||
#define DEFAULT_INTERNET_TIME 0
|
||||
#endif // TIMESTAMP_FEATURE
|
||||
|
||||
|
||||
#define DEFAULT_SETUP 0
|
||||
|
||||
#define DEFAULT_VERBOSE_BOOT 0
|
||||
@ -182,8 +179,7 @@ const uint8_t DEFAULT_ADDRESS_VALUE[] = {0, 0, 0, 0};
|
||||
uint8_t Settings_ESP3D::_FirmwareTarget = DEFAULT_FW;
|
||||
bool Settings_ESP3D::_isverboseboot = DEFAULT_VERBOSE_BOOT;
|
||||
|
||||
bool Settings_ESP3D::begin()
|
||||
{
|
||||
bool Settings_ESP3D::begin() {
|
||||
if (GetSettingsVersion() == -1) {
|
||||
return false;
|
||||
}
|
||||
@ -193,8 +189,7 @@ bool Settings_ESP3D::begin()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Settings_ESP3D::isVerboseBoot(bool fromsettings)
|
||||
{
|
||||
bool Settings_ESP3D::isVerboseBoot(bool fromsettings) {
|
||||
#if COMMUNICATION_PROTOCOL != MKS_SERIAL
|
||||
if (fromsettings) {
|
||||
_isverboseboot = read_byte(ESP_VERBOSE_BOOT);
|
||||
@ -205,8 +200,7 @@ bool Settings_ESP3D::isVerboseBoot(bool fromsettings)
|
||||
return _isverboseboot;
|
||||
}
|
||||
|
||||
uint8_t Settings_ESP3D::GetFirmwareTarget(bool fromsettings)
|
||||
{
|
||||
uint8_t Settings_ESP3D::GetFirmwareTarget(bool fromsettings) {
|
||||
#if defined(FIXED_FW_TARGET)
|
||||
(void)fromsettings;
|
||||
_FirmwareTarget = FIXED_FW_TARGET;
|
||||
@ -216,11 +210,9 @@ uint8_t Settings_ESP3D::GetFirmwareTarget(bool fromsettings)
|
||||
}
|
||||
#endif // #if defined( FIXED_FW_TARGET )
|
||||
return _FirmwareTarget;
|
||||
|
||||
}
|
||||
|
||||
uint8_t Settings_ESP3D::GetSDDevice()
|
||||
{
|
||||
uint8_t Settings_ESP3D::GetSDDevice() {
|
||||
#ifdef SD_DEVICE
|
||||
return SD_DEVICE_CONNECTION;
|
||||
#else // !SD_DEVICE
|
||||
@ -228,8 +220,7 @@ uint8_t Settings_ESP3D::GetSDDevice()
|
||||
#endif // SD_DEVICE
|
||||
}
|
||||
|
||||
const char* Settings_ESP3D::GetFirmwareTargetShortName()
|
||||
{
|
||||
const char *Settings_ESP3D::GetFirmwareTargetShortName() {
|
||||
static String response;
|
||||
|
||||
if (_FirmwareTarget == REPETIER) {
|
||||
@ -249,8 +240,7 @@ const char* Settings_ESP3D::GetFirmwareTargetShortName()
|
||||
}
|
||||
|
||||
// Default value for a byte setting
|
||||
uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
{
|
||||
uint8_t Settings_ESP3D::get_default_byte_value(int pos) {
|
||||
uint8_t res;
|
||||
switch (pos) {
|
||||
case ESP_BOOT_RADIO_STATE:
|
||||
@ -263,7 +253,8 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
case ESP_SECURE_SERIAL:
|
||||
res = DEFAULT_SECURE_SERIAL;
|
||||
break;
|
||||
#endif //#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#endif // #if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// MKS_SERIAL
|
||||
case ESP_RADIO_MODE:
|
||||
res = DEFAULT_ESP_RADIO_MODE;
|
||||
break;
|
||||
@ -397,8 +388,7 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
}
|
||||
|
||||
// Default value for a int32 setting
|
||||
uint32_t Settings_ESP3D::get_default_int32_value(int pos)
|
||||
{
|
||||
uint32_t Settings_ESP3D::get_default_int32_value(int pos) {
|
||||
uint32_t res;
|
||||
switch (pos) {
|
||||
case ESP_BAUD_RATE:
|
||||
@ -479,8 +469,7 @@ uint32_t Settings_ESP3D::get_default_int32_value(int pos)
|
||||
}
|
||||
|
||||
// Max value for a int32 setting
|
||||
uint32_t Settings_ESP3D::get_max_int32_value(int pos)
|
||||
{
|
||||
uint32_t Settings_ESP3D::get_max_int32_value(int pos) {
|
||||
uint32_t res;
|
||||
switch (pos) {
|
||||
case ESP_BOOT_DELAY:
|
||||
@ -525,8 +514,7 @@ uint32_t Settings_ESP3D::get_max_int32_value(int pos)
|
||||
}
|
||||
|
||||
// Min value for a int32 setting
|
||||
uint32_t Settings_ESP3D::get_min_int32_value(int pos)
|
||||
{
|
||||
uint32_t Settings_ESP3D::get_min_int32_value(int pos) {
|
||||
uint32_t res;
|
||||
switch (pos) {
|
||||
case ESP_BOOT_DELAY:
|
||||
@ -570,8 +558,7 @@ uint32_t Settings_ESP3D::get_min_int32_value(int pos)
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t Settings_ESP3D::get_max_byte(int pos)
|
||||
{
|
||||
uint8_t Settings_ESP3D::get_max_byte(int pos) {
|
||||
uint8_t res;
|
||||
switch (pos) {
|
||||
#if defined(WIFI_FEATURE)
|
||||
@ -590,8 +577,7 @@ uint8_t Settings_ESP3D::get_max_byte(int pos)
|
||||
return res;
|
||||
}
|
||||
|
||||
int8_t Settings_ESP3D::get_min_byte(int pos)
|
||||
{
|
||||
int8_t Settings_ESP3D::get_min_byte(int pos) {
|
||||
uint8_t res;
|
||||
switch (pos) {
|
||||
#if defined(WIFI_FEATURE)
|
||||
@ -611,14 +597,12 @@ int8_t Settings_ESP3D::get_min_byte(int pos)
|
||||
}
|
||||
|
||||
// Default value for a ip setting
|
||||
uint32_t Settings_ESP3D::get_default_IP_value(int pos)
|
||||
{
|
||||
uint32_t Settings_ESP3D::get_default_IP_value(int pos) {
|
||||
return get_default_int32_value(pos);
|
||||
}
|
||||
|
||||
// Default value for a byte setting
|
||||
const String & Settings_ESP3D::get_default_string_value(int pos)
|
||||
{
|
||||
const String &Settings_ESP3D::get_default_string_value(int pos) {
|
||||
static String res;
|
||||
switch (pos) {
|
||||
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BLUETOOTH_FEATURE)
|
||||
@ -680,8 +664,7 @@ const String & Settings_ESP3D::get_default_string_value(int pos)
|
||||
}
|
||||
|
||||
// Max size of for a string setting
|
||||
uint8_t Settings_ESP3D::get_max_string_size(int pos)
|
||||
{
|
||||
uint8_t Settings_ESP3D::get_max_string_size(int pos) {
|
||||
uint8_t res;
|
||||
switch (pos) {
|
||||
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BLUETOOTH_FEATURE)
|
||||
@ -731,8 +714,7 @@ uint8_t Settings_ESP3D::get_max_string_size(int pos)
|
||||
}
|
||||
|
||||
// Min size of for a string setting
|
||||
uint8_t Settings_ESP3D::get_min_string_size(int pos)
|
||||
{
|
||||
uint8_t Settings_ESP3D::get_min_string_size(int pos) {
|
||||
uint8_t res;
|
||||
switch (pos) {
|
||||
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BLUETOOTH_FEATURE)
|
||||
@ -778,8 +760,7 @@ uint8_t Settings_ESP3D::get_min_string_size(int pos)
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t Settings_ESP3D::read_byte (int pos, bool * haserror)
|
||||
{
|
||||
uint8_t Settings_ESP3D::read_byte(int pos, bool *haserror) {
|
||||
if (haserror) {
|
||||
*haserror = true;
|
||||
}
|
||||
@ -787,7 +768,7 @@ uint8_t Settings_ESP3D::read_byte (int pos, bool * haserror)
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_EEPROM
|
||||
// check if parameters are acceptable
|
||||
if ((pos + 1 > EEPROM_SIZE)) {
|
||||
log_esp3d("Error read byte %d", pos);
|
||||
log_esp3d_e("Error read byte %d", pos);
|
||||
return value;
|
||||
}
|
||||
// read byte
|
||||
@ -798,7 +779,7 @@ uint8_t Settings_ESP3D::read_byte (int pos, bool * haserror)
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_PREFERENCES
|
||||
Preferences prefs;
|
||||
if (!prefs.begin(NAMESPACE, true)) {
|
||||
log_esp3d("Error opening %s", NAMESPACE);
|
||||
log_esp3d_e("Error opening %s", NAMESPACE);
|
||||
return value;
|
||||
}
|
||||
String p = "P_" + String(pos);
|
||||
@ -816,18 +797,17 @@ uint8_t Settings_ESP3D::read_byte (int pos, bool * haserror)
|
||||
}
|
||||
|
||||
// write a flag / byte
|
||||
bool Settings_ESP3D::write_byte (int pos, const uint8_t value)
|
||||
{
|
||||
bool Settings_ESP3D::write_byte(int pos, const uint8_t value) {
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_EEPROM
|
||||
// check if parameters are acceptable
|
||||
if (pos + 1 > EEPROM_SIZE) {
|
||||
log_esp3d("Error read byte %d", pos);
|
||||
log_esp3d_e("Error read byte %d", pos);
|
||||
return false;
|
||||
}
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.write(pos, value);
|
||||
if (!EEPROM.commit()) {
|
||||
log_esp3d("Error commit %d", pos);
|
||||
log_esp3d_e("Error commit %d", pos);
|
||||
return false;
|
||||
}
|
||||
EEPROM.end();
|
||||
@ -835,22 +815,21 @@ bool Settings_ESP3D::write_byte (int pos, const uint8_t value)
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_PREFERENCES
|
||||
Preferences prefs;
|
||||
if (!prefs.begin(NAMESPACE, false)) {
|
||||
log_esp3d("Error opening %s", NAMESPACE);
|
||||
log_esp3d_e("Error opening %s", NAMESPACE);
|
||||
return false;
|
||||
}
|
||||
String p = "P_" + String(pos);
|
||||
uint8_t r = prefs.putChar(p.c_str(), value);
|
||||
prefs.end();
|
||||
if (r == 0) {
|
||||
log_esp3d("Error commit %s", p.c_str());
|
||||
log_esp3d_e("Error commit %s", p.c_str());
|
||||
return false;
|
||||
}
|
||||
#endif // SETTINGS_IN_PREFERENCES
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Settings_ESP3D::is_string(const char * s, uint len)
|
||||
{
|
||||
bool Settings_ESP3D::is_string(const char *s, uint len) {
|
||||
for (uint p = 0; p < len; p++) {
|
||||
if (!isPrintable(char(s[p]))) {
|
||||
return false;
|
||||
@ -860,15 +839,15 @@ bool Settings_ESP3D::is_string(const char * s, uint len)
|
||||
}
|
||||
|
||||
// read a string
|
||||
//a string is multibyte + \0, this is won't work if 1 char is multibyte like chinese char
|
||||
const char * Settings_ESP3D::read_string (int pos, bool *haserror)
|
||||
{
|
||||
// a string is multibyte + \0, this is won't work if 1 char is multibyte like
|
||||
// chinese char
|
||||
const char *Settings_ESP3D::read_string(int pos, bool *haserror) {
|
||||
uint8_t size_max = get_max_string_size(pos);
|
||||
if (haserror) {
|
||||
*haserror = true;
|
||||
}
|
||||
if (size_max == 0) {
|
||||
log_esp3d("Error size string %d", pos);
|
||||
log_esp3d_e("Error size string %d", pos);
|
||||
return DEFAULT_ESP_STRING;
|
||||
}
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_EEPROM
|
||||
@ -880,12 +859,12 @@ const char * Settings_ESP3D::read_string (int pos, bool *haserror)
|
||||
}
|
||||
// check if parameters are acceptable
|
||||
if (pos + size_max + 1 > EEPROM_SIZE) {
|
||||
log_esp3d("Error read string %d", pos);
|
||||
log_esp3d_e("Error read string %d", pos);
|
||||
return DEFAULT_ESP_STRING;
|
||||
}
|
||||
byte_buffer = (char *)malloc(size_max + 1);
|
||||
if (!byte_buffer) {
|
||||
log_esp3d("Error mem read string %d", pos);
|
||||
log_esp3d_e("Error mem read string %d", pos);
|
||||
return DEFAULT_ESP_STRING;
|
||||
}
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
@ -916,7 +895,7 @@ const char * Settings_ESP3D::read_string (int pos, bool *haserror)
|
||||
static String res;
|
||||
|
||||
if (!prefs.begin(NAMESPACE, true)) {
|
||||
log_esp3d("Error opening %s", NAMESPACE);
|
||||
log_esp3d_e("Error opening %s", NAMESPACE);
|
||||
return "";
|
||||
}
|
||||
String p = "P_" + String(pos);
|
||||
@ -928,7 +907,7 @@ const char * Settings_ESP3D::read_string (int pos, bool *haserror)
|
||||
prefs.end();
|
||||
|
||||
if (res.length() > size_max) {
|
||||
log_esp3d("String too long %d vs %d", res.length(), size_max);
|
||||
log_esp3d_e("String too long %d vs %d", res.length(), size_max);
|
||||
res = res.substring(0, size_max - 1);
|
||||
}
|
||||
|
||||
@ -941,22 +920,21 @@ const char * Settings_ESP3D::read_string (int pos, bool *haserror)
|
||||
}
|
||||
|
||||
// write a string (array of byte with a 0x00 at the end)
|
||||
bool Settings_ESP3D::write_string (int pos, const char * byte_buffer)
|
||||
{
|
||||
bool Settings_ESP3D::write_string(int pos, const char *byte_buffer) {
|
||||
int size_buffer = strlen(byte_buffer);
|
||||
uint8_t size_max = get_max_string_size(pos);
|
||||
// check if parameters are acceptable
|
||||
if (size_max == 0) {
|
||||
log_esp3d("Error unknow entry %d", pos);
|
||||
log_esp3d_e("Error unknow entry %d", pos);
|
||||
return false;
|
||||
}
|
||||
if (size_max < size_buffer) {
|
||||
log_esp3d("Error string too long %d, %d", pos, size_buffer);
|
||||
log_esp3d_e("Error string too long %d, %d", pos, size_buffer);
|
||||
return false;
|
||||
}
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_EEPROM
|
||||
if (pos + size_buffer + 1 > EEPROM_SIZE || byte_buffer == NULL) {
|
||||
log_esp3d("Error write string %d", pos);
|
||||
log_esp3d_e("Error write string %d", pos);
|
||||
return false;
|
||||
}
|
||||
// copy the value(s)
|
||||
@ -967,7 +945,7 @@ bool Settings_ESP3D::write_string (int pos, const char * byte_buffer)
|
||||
// 0 terminal
|
||||
EEPROM.write(pos + size_buffer, 0x00);
|
||||
if (!EEPROM.commit()) {
|
||||
log_esp3d("Error commit %d", pos);
|
||||
log_esp3d_e("Error commit %d", pos);
|
||||
return false;
|
||||
}
|
||||
EEPROM.end();
|
||||
@ -975,14 +953,14 @@ bool Settings_ESP3D::write_string (int pos, const char * byte_buffer)
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_PREFERENCES
|
||||
Preferences prefs;
|
||||
if (!prefs.begin(NAMESPACE, false)) {
|
||||
log_esp3d("Error opening %s", NAMESPACE);
|
||||
log_esp3d_e("Error opening %s", NAMESPACE);
|
||||
return false;
|
||||
}
|
||||
String p = "P_" + String(pos);
|
||||
uint8_t r = prefs.putString(p.c_str(), byte_buffer);
|
||||
prefs.end();
|
||||
if (r != size_buffer) {
|
||||
log_esp3d("Error commit %s", p.c_str());
|
||||
log_esp3d_e("Error commit %s", p.c_str());
|
||||
return false;
|
||||
}
|
||||
#endif // SETTINGS_IN_PREFERENCES
|
||||
@ -990,8 +968,7 @@ bool Settings_ESP3D::write_string (int pos, const char * byte_buffer)
|
||||
}
|
||||
|
||||
// read a uint32
|
||||
uint32_t Settings_ESP3D::read_uint32(int pos, bool * haserror)
|
||||
{
|
||||
uint32_t Settings_ESP3D::read_uint32(int pos, bool *haserror) {
|
||||
if (haserror) {
|
||||
*haserror = true;
|
||||
}
|
||||
@ -1000,7 +977,7 @@ uint32_t Settings_ESP3D::read_uint32(int pos, bool * haserror)
|
||||
// check if parameters are acceptable
|
||||
uint8_t size_buffer = sizeof(uint32_t);
|
||||
if (pos + size_buffer > EEPROM_SIZE) {
|
||||
log_esp3d("Error read int %d", pos);
|
||||
log_esp3d_e("Error read int %d", pos);
|
||||
return res;
|
||||
}
|
||||
uint8_t i = 0;
|
||||
@ -1015,7 +992,7 @@ uint32_t Settings_ESP3D::read_uint32(int pos, bool * haserror)
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_PREFERENCES
|
||||
Preferences prefs;
|
||||
if (!prefs.begin(NAMESPACE, true)) {
|
||||
log_esp3d("Error opening %s", NAMESPACE);
|
||||
log_esp3d_e("Error opening %s", NAMESPACE);
|
||||
return res;
|
||||
}
|
||||
String p = "P_" + String(pos);
|
||||
@ -1033,25 +1010,22 @@ uint32_t Settings_ESP3D::read_uint32(int pos, bool * haserror)
|
||||
}
|
||||
|
||||
// read an IP
|
||||
uint32_t Settings_ESP3D::read_IP(int pos, bool * haserror)
|
||||
{
|
||||
uint32_t Settings_ESP3D::read_IP(int pos, bool *haserror) {
|
||||
return read_uint32(pos, haserror);
|
||||
}
|
||||
|
||||
// read an IP
|
||||
String Settings_ESP3D::read_IP_String(int pos, bool * haserror)
|
||||
{
|
||||
String Settings_ESP3D::read_IP_String(int pos, bool *haserror) {
|
||||
return IPtoString(read_uint32(pos, haserror));
|
||||
}
|
||||
|
||||
// write a uint32
|
||||
bool Settings_ESP3D::write_uint32(int pos, const uint32_t value)
|
||||
{
|
||||
bool Settings_ESP3D::write_uint32(int pos, const uint32_t value) {
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_EEPROM
|
||||
uint8_t size_buffer = sizeof(uint32_t);
|
||||
// check if parameters are acceptable
|
||||
if (pos + size_buffer > EEPROM_SIZE) {
|
||||
log_esp3d("Error invalid entry %d", pos);
|
||||
log_esp3d_e("Error invalid entry %d", pos);
|
||||
return false;
|
||||
}
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
@ -1060,7 +1034,7 @@ bool Settings_ESP3D::write_uint32(int pos, const uint32_t value)
|
||||
EEPROM.write(pos + i, ((uint8_t *)(&value))[i]);
|
||||
}
|
||||
if (!EEPROM.commit()) {
|
||||
log_esp3d("Error commit %d", pos);
|
||||
log_esp3d_e("Error commit %d", pos);
|
||||
return false;
|
||||
}
|
||||
EEPROM.end();
|
||||
@ -1068,14 +1042,14 @@ bool Settings_ESP3D::write_uint32(int pos, const uint32_t value)
|
||||
#if ESP_SAVE_SETTINGS == SETTINGS_IN_PREFERENCES
|
||||
Preferences prefs;
|
||||
if (!prefs.begin(NAMESPACE, false)) {
|
||||
log_esp3d("Error opening %s", NAMESPACE);
|
||||
log_esp3d_e("Error opening %s", NAMESPACE);
|
||||
return false;
|
||||
}
|
||||
String p = "P_" + String(pos);
|
||||
uint8_t r = prefs.putUInt(p.c_str(), value);
|
||||
prefs.end();
|
||||
if (r == 0) {
|
||||
log_esp3d("Error commit %s", p.c_str());
|
||||
log_esp3d_e("Error commit %s", p.c_str());
|
||||
return false;
|
||||
}
|
||||
#endif // SETTINGS_IN_PREFERENCES
|
||||
@ -1083,45 +1057,66 @@ bool Settings_ESP3D::write_uint32(int pos, const uint32_t value)
|
||||
}
|
||||
|
||||
// write a IP
|
||||
bool Settings_ESP3D::write_IP(int pos, const uint32_t value)
|
||||
{
|
||||
bool Settings_ESP3D::write_IP(int pos, const uint32_t value) {
|
||||
return write_uint32(pos, value);
|
||||
}
|
||||
|
||||
// clear all entries
|
||||
bool Settings_ESP3D::reset(bool networkonly)
|
||||
{
|
||||
bool Settings_ESP3D::reset(bool networkonly) {
|
||||
// radio mode
|
||||
Settings_ESP3D::write_byte(ESP_RADIO_MODE,Settings_ESP3D::get_default_byte_value(ESP_RADIO_MODE));
|
||||
Settings_ESP3D::write_byte(ESP_BOOT_RADIO_STATE,Settings_ESP3D::get_default_byte_value(ESP_BOOT_RADIO_STATE));
|
||||
Settings_ESP3D::write_byte(ESP_STA_FALLBACK_MODE,Settings_ESP3D::get_default_byte_value(ESP_STA_FALLBACK_MODE));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_RADIO_MODE, Settings_ESP3D::get_default_byte_value(ESP_RADIO_MODE));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_BOOT_RADIO_STATE,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_BOOT_RADIO_STATE));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_STA_FALLBACK_MODE,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_STA_FALLBACK_MODE));
|
||||
#if defined(WIFI_FEATURE)
|
||||
// STA SSID
|
||||
Settings_ESP3D::write_string(ESP_STA_SSID,Settings_ESP3D::get_default_string_value(ESP_STA_SSID).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_STA_SSID,
|
||||
Settings_ESP3D::get_default_string_value(ESP_STA_SSID).c_str());
|
||||
// STA pwd
|
||||
Settings_ESP3D::write_string(ESP_STA_PASSWORD,Settings_ESP3D::get_default_string_value(ESP_STA_PASSWORD).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_STA_PASSWORD,
|
||||
Settings_ESP3D::get_default_string_value(ESP_STA_PASSWORD).c_str());
|
||||
// AP SSID
|
||||
Settings_ESP3D::write_string(ESP_AP_SSID,Settings_ESP3D::get_default_string_value(ESP_AP_SSID).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_AP_SSID,
|
||||
Settings_ESP3D::get_default_string_value(ESP_AP_SSID).c_str());
|
||||
// AP password
|
||||
Settings_ESP3D::write_string(ESP_AP_PASSWORD,Settings_ESP3D::get_default_string_value(ESP_AP_PASSWORD).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_AP_PASSWORD,
|
||||
Settings_ESP3D::get_default_string_value(ESP_AP_PASSWORD).c_str());
|
||||
// AP static IP
|
||||
Settings_ESP3D::write_IP(ESP_AP_IP_VALUE, Settings_ESP3D::get_default_IP_value(ESP_AP_IP_VALUE));
|
||||
Settings_ESP3D::write_IP(
|
||||
ESP_AP_IP_VALUE, Settings_ESP3D::get_default_IP_value(ESP_AP_IP_VALUE));
|
||||
// AP Channel
|
||||
Settings_ESP3D::write_byte(ESP_AP_CHANNEL,Settings_ESP3D::get_default_byte_value(ESP_AP_CHANNEL));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_AP_CHANNEL, Settings_ESP3D::get_default_byte_value(ESP_AP_CHANNEL));
|
||||
|
||||
#endif // WIFI_FEATURE
|
||||
|
||||
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
|
||||
// STA IP mode
|
||||
Settings_ESP3D::write_byte(ESP_STA_IP_MODE,Settings_ESP3D::get_default_byte_value(ESP_STA_IP_MODE));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_STA_IP_MODE, Settings_ESP3D::get_default_byte_value(ESP_STA_IP_MODE));
|
||||
// STA static IP
|
||||
Settings_ESP3D::write_IP(ESP_STA_IP_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_IP_VALUE));
|
||||
Settings_ESP3D::write_IP(
|
||||
ESP_STA_IP_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_IP_VALUE));
|
||||
// STA static Gateway
|
||||
Settings_ESP3D::write_IP(ESP_STA_GATEWAY_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_GATEWAY_VALUE));
|
||||
Settings_ESP3D::write_IP(
|
||||
ESP_STA_GATEWAY_VALUE,
|
||||
Settings_ESP3D::get_default_IP_value(ESP_STA_GATEWAY_VALUE));
|
||||
// STA static Mask
|
||||
Settings_ESP3D::write_IP(ESP_STA_MASK_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_MASK_VALUE));
|
||||
Settings_ESP3D::write_IP(
|
||||
ESP_STA_MASK_VALUE,
|
||||
Settings_ESP3D::get_default_IP_value(ESP_STA_MASK_VALUE));
|
||||
// STA static DNS
|
||||
Settings_ESP3D::write_IP(ESP_STA_DNS_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_DNS_VALUE));
|
||||
Settings_ESP3D::write_IP(
|
||||
ESP_STA_DNS_VALUE,
|
||||
Settings_ESP3D::get_default_IP_value(ESP_STA_DNS_VALUE));
|
||||
#endif // WIFI_FEATURE || ETH_FEATURE
|
||||
if (networkonly) {
|
||||
return true;
|
||||
@ -1144,137 +1139,225 @@ bool Settings_ESP3D::reset(bool networkonly)
|
||||
log_esp3d("clear EEPROM");
|
||||
|
||||
// Setup done (internal only)
|
||||
Settings_ESP3D::write_byte(ESP_SETUP,Settings_ESP3D::get_default_byte_value(ESP_SETUP));
|
||||
Settings_ESP3D::write_byte(ESP_SETUP,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_SETUP));
|
||||
// Verbose boot
|
||||
Settings_ESP3D::write_byte(ESP_VERBOSE_BOOT,Settings_ESP3D::get_default_byte_value(ESP_VERBOSE_BOOT));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_VERBOSE_BOOT,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_VERBOSE_BOOT));
|
||||
// Secure Serial
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
Settings_ESP3D::write_byte(ESP_SECURE_SERIAL,Settings_ESP3D::get_default_byte_value(ESP_SECURE_SERIAL));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_SECURE_SERIAL,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_SECURE_SERIAL));
|
||||
#endif // COMMUNICATION PROTOCOL
|
||||
#if defined(DISPLAY_DEVICE) && defined(DISPLAY_TOUCH_DRIVER)
|
||||
// Calibration done (internal only)
|
||||
Settings_ESP3D::write_byte(ESP_CALIBRATION,Settings_ESP3D::get_default_byte_value(ESP_CALIBRATION));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_CALIBRATION, Settings_ESP3D::get_default_byte_value(ESP_CALIBRATION));
|
||||
// Calibration data (internal only)
|
||||
Settings_ESP3D::write_uint32 (ESP_CALIBRATION_1, Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_1));
|
||||
Settings_ESP3D::write_uint32 (ESP_CALIBRATION_2, Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_2));
|
||||
Settings_ESP3D::write_uint32 (ESP_CALIBRATION_3, Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_3));
|
||||
Settings_ESP3D::write_uint32 (ESP_CALIBRATION_4, Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_4));
|
||||
Settings_ESP3D::write_uint32 (ESP_CALIBRATION_5, Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_5));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_CALIBRATION_1,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_1));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_CALIBRATION_2,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_2));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_CALIBRATION_3,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_3));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_CALIBRATION_4,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_4));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_CALIBRATION_5,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_CALIBRATION_5));
|
||||
#endif // DISPLAY_DEVICE && DISPLAY_TOUCH_DRIVER
|
||||
#ifdef BUZZER_DEVICE
|
||||
// Buzzer state
|
||||
Settings_ESP3D::write_byte(ESP_BUZZER,Settings_ESP3D::get_default_byte_value(ESP_BUZZER));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_BUZZER, Settings_ESP3D::get_default_byte_value(ESP_BUZZER));
|
||||
#endif // BUZZER_DEVICE
|
||||
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
|
||||
// Hostname
|
||||
Settings_ESP3D::write_string(ESP_HOSTNAME,Settings_ESP3D::get_default_string_value(ESP_HOSTNAME).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_HOSTNAME,
|
||||
Settings_ESP3D::get_default_string_value(ESP_HOSTNAME).c_str());
|
||||
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
// Auto Notification
|
||||
Settings_ESP3D::write_byte(ESP_AUTO_NOTIFICATION,Settings_ESP3D::get_default_byte_value(ESP_AUTO_NOTIFICATION));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_AUTO_NOTIFICATION,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_AUTO_NOTIFICATION));
|
||||
// Notification Type
|
||||
Settings_ESP3D::write_byte(ESP_NOTIFICATION_TYPE,Settings_ESP3D::get_default_byte_value(ESP_NOTIFICATION_TYPE));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_NOTIFICATION_TYPE,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_NOTIFICATION_TYPE));
|
||||
// Notification Token1
|
||||
Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN1,Settings_ESP3D::get_default_string_value(ESP_NOTIFICATION_TOKEN1).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_NOTIFICATION_TOKEN1,
|
||||
Settings_ESP3D::get_default_string_value(ESP_NOTIFICATION_TOKEN1)
|
||||
.c_str());
|
||||
// Notification Token2
|
||||
Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN2,Settings_ESP3D::get_default_string_value(ESP_NOTIFICATION_TOKEN2).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_NOTIFICATION_TOKEN2,
|
||||
Settings_ESP3D::get_default_string_value(ESP_NOTIFICATION_TOKEN2)
|
||||
.c_str());
|
||||
// Notification Settings
|
||||
Settings_ESP3D::write_string(ESP_NOTIFICATION_SETTINGS,Settings_ESP3D::get_default_string_value(ESP_NOTIFICATION_SETTINGS).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_NOTIFICATION_SETTINGS,
|
||||
Settings_ESP3D::get_default_string_value(ESP_NOTIFICATION_SETTINGS)
|
||||
.c_str());
|
||||
#endif // NOTIFICATION_FEATURE
|
||||
// radio mode
|
||||
Settings_ESP3D::write_byte(ESP_RADIO_MODE,Settings_ESP3D::get_default_byte_value(ESP_RADIO_MODE));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_RADIO_MODE, Settings_ESP3D::get_default_byte_value(ESP_RADIO_MODE));
|
||||
|
||||
#ifdef FTP_FEATURE
|
||||
// FTP On
|
||||
Settings_ESP3D::write_byte(ESP_FTP_ON,Settings_ESP3D::get_default_byte_value(ESP_FTP_ON));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_FTP_ON, Settings_ESP3D::get_default_byte_value(ESP_FTP_ON));
|
||||
// FTP Ctrl Port
|
||||
Settings_ESP3D::write_uint32 (ESP_FTP_CTRL_PORT, Settings_ESP3D::get_default_int32_value(ESP_FTP_CTRL_PORT));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_FTP_CTRL_PORT,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_FTP_CTRL_PORT));
|
||||
// FTP Active data Port
|
||||
Settings_ESP3D::write_uint32 (ESP_FTP_DATA_ACTIVE_PORT, Settings_ESP3D::get_default_int32_value(ESP_FTP_DATA_ACTIVE_PORT));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_FTP_DATA_ACTIVE_PORT,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_FTP_DATA_ACTIVE_PORT));
|
||||
// FTP Pasive data Port
|
||||
Settings_ESP3D::write_uint32 (ESP_FTP_DATA_PASSIVE_PORT, Settings_ESP3D::get_default_int32_value(ESP_FTP_DATA_PASSIVE_PORT));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_FTP_DATA_PASSIVE_PORT,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_FTP_DATA_PASSIVE_PORT));
|
||||
#endif // FTP_FEATURE
|
||||
|
||||
#ifdef HTTP_FEATURE
|
||||
// HTTP On
|
||||
Settings_ESP3D::write_byte(ESP_HTTP_ON,Settings_ESP3D::get_default_byte_value(ESP_HTTP_ON));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_HTTP_ON, Settings_ESP3D::get_default_byte_value(ESP_HTTP_ON));
|
||||
// HTTP Port
|
||||
Settings_ESP3D::write_uint32 (ESP_HTTP_PORT, Settings_ESP3D::get_default_int32_value(ESP_HTTP_PORT));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_HTTP_PORT, Settings_ESP3D::get_default_int32_value(ESP_HTTP_PORT));
|
||||
#endif // HTTP_FEATURE
|
||||
|
||||
#ifdef TELNET_FEATURE
|
||||
// TELNET On
|
||||
Settings_ESP3D::write_byte(ESP_TELNET_ON,Settings_ESP3D::get_default_byte_value(ESP_TELNET_ON));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_TELNET_ON, Settings_ESP3D::get_default_byte_value(ESP_TELNET_ON));
|
||||
// TELNET Port
|
||||
Settings_ESP3D::write_uint32 (ESP_TELNET_PORT, Settings_ESP3D::get_default_int32_value(ESP_TELNET_PORT));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_TELNET_PORT,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_TELNET_PORT));
|
||||
#endif // TELNET
|
||||
#ifdef WS_DATA_FEATURE
|
||||
// Websocket On
|
||||
Settings_ESP3D::write_byte(ESP_WEBSOCKET_ON,Settings_ESP3D::get_default_byte_value(ESP_WEBSOCKET_ON));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_WEBSOCKET_ON,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_WEBSOCKET_ON));
|
||||
// Websocket Port
|
||||
Settings_ESP3D::write_uint32 (ESP_WEBSOCKET_PORT, Settings_ESP3D::get_default_int32_value(ESP_WEBSOCKET_PORT));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_WEBSOCKET_PORT,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_WEBSOCKET_PORT));
|
||||
#endif // WS_DATA_FEATURE
|
||||
#ifdef WEBDAV_FEATURE
|
||||
// WebDav On
|
||||
Settings_ESP3D::write_byte(ESP_WEBDAV_ON,Settings_ESP3D::get_default_byte_value(ESP_WEBDAV_ON));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_WEBDAV_ON, Settings_ESP3D::get_default_byte_value(ESP_WEBDAV_ON));
|
||||
// WebDav Port
|
||||
Settings_ESP3D::write_uint32 (ESP_WEBDAV_PORT, Settings_ESP3D::get_default_int32_value(ESP_WEBDAV_PORT));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_WEBDAV_PORT,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_WEBDAV_PORT));
|
||||
#endif // WEBDAV_FEATURE
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
// Admin password
|
||||
Settings_ESP3D::write_string(ESP_ADMIN_PWD,Settings_ESP3D::get_default_string_value(ESP_ADMIN_PWD).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_ADMIN_PWD,
|
||||
Settings_ESP3D::get_default_string_value(ESP_ADMIN_PWD).c_str());
|
||||
// User password
|
||||
Settings_ESP3D::write_string(ESP_USER_PWD,Settings_ESP3D::get_default_string_value(ESP_USER_PWD).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_USER_PWD,
|
||||
Settings_ESP3D::get_default_string_value(ESP_USER_PWD).c_str());
|
||||
// Session timeout
|
||||
Settings_ESP3D::write_byte(ESP_SESSION_TIMEOUT,Settings_ESP3D::get_default_byte_value(ESP_SESSION_TIMEOUT));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_SESSION_TIMEOUT,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_SESSION_TIMEOUT));
|
||||
#endif // AUTHENTICATION_FEATURE
|
||||
// Target FW
|
||||
Settings_ESP3D::write_byte(ESP_TARGET_FW,Settings_ESP3D::get_default_byte_value(ESP_TARGET_FW));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_TARGET_FW, Settings_ESP3D::get_default_byte_value(ESP_TARGET_FW));
|
||||
// Output flags
|
||||
Settings_ESP3D::write_byte(ESP_SERIAL_FLAG,Settings_ESP3D::get_default_byte_value(ESP_SERIAL_FLAG));
|
||||
Settings_ESP3D::write_byte(ESP_SERIAL_BRIDGE_FLAG,Settings_ESP3D::get_default_byte_value(ESP_SERIAL_BRIDGE_FLAG));
|
||||
Settings_ESP3D::write_byte(ESP_REMOTE_SCREEN_FLAG,Settings_ESP3D::get_default_byte_value(ESP_REMOTE_SCREEN_FLAG));
|
||||
Settings_ESP3D::write_byte(ESP_WEBSOCKET_FLAG,Settings_ESP3D::get_default_byte_value(ESP_WEBSOCKET_FLAG));
|
||||
Settings_ESP3D::write_byte(ESP_TELNET_FLAG,Settings_ESP3D::get_default_byte_value(ESP_TELNET_FLAG));
|
||||
Settings_ESP3D::write_byte(ESP_BT_FLAG,Settings_ESP3D::get_default_byte_value(ESP_BT_FLAG));
|
||||
Settings_ESP3D::write_byte(ESP_SCREEN_FLAG,Settings_ESP3D::get_default_byte_value(ESP_SCREEN_FLAG));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_SERIAL_FLAG, Settings_ESP3D::get_default_byte_value(ESP_SERIAL_FLAG));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_SERIAL_BRIDGE_FLAG,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_SERIAL_BRIDGE_FLAG));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_REMOTE_SCREEN_FLAG,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_REMOTE_SCREEN_FLAG));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_WEBSOCKET_FLAG,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_WEBSOCKET_FLAG));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_TELNET_FLAG, Settings_ESP3D::get_default_byte_value(ESP_TELNET_FLAG));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_BT_FLAG, Settings_ESP3D::get_default_byte_value(ESP_BT_FLAG));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_SCREEN_FLAG, Settings_ESP3D::get_default_byte_value(ESP_SCREEN_FLAG));
|
||||
#ifdef SD_DEVICE
|
||||
// SPI SD Divider
|
||||
Settings_ESP3D::write_byte(ESP_SD_SPEED_DIV,Settings_ESP3D::get_default_byte_value(ESP_SD_SPEED_DIV));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_SD_SPEED_DIV,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_SD_SPEED_DIV));
|
||||
#ifdef SD_UPDATE_FEATURE
|
||||
// SD Update feature
|
||||
Settings_ESP3D::write_byte(ESP_SD_CHECK_UPDATE_AT_BOOT,Settings_ESP3D::get_default_byte_value(ESP_SD_CHECK_UPDATE_AT_BOOT));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_SD_CHECK_UPDATE_AT_BOOT,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_SD_CHECK_UPDATE_AT_BOOT));
|
||||
#endif // SD_UPDATE_FEATURE
|
||||
#endif // SD_DEVICE
|
||||
|
||||
#ifdef TIMESTAMP_FEATURE
|
||||
// Internet time
|
||||
Settings_ESP3D::write_byte(ESP_INTERNET_TIME,Settings_ESP3D::get_default_byte_value(ESP_INTERNET_TIME));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_INTERNET_TIME,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_INTERNET_TIME));
|
||||
// Time Zone
|
||||
Settings_ESP3D::write_byte(ESP_TIMEZONE,Settings_ESP3D::get_default_byte_value(ESP_TIMEZONE));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_TIMEZONE, Settings_ESP3D::get_default_byte_value(ESP_TIMEZONE));
|
||||
// Is DST Time Zone
|
||||
Settings_ESP3D::write_byte(ESP_TIME_IS_DST,Settings_ESP3D::get_default_byte_value(ESP_TIME_IS_DST));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_TIME_IS_DST, Settings_ESP3D::get_default_byte_value(ESP_TIME_IS_DST));
|
||||
// Time Server 1 address
|
||||
Settings_ESP3D::write_string(ESP_TIME_SERVER1, Settings_ESP3D::get_default_string_value(ESP_TIME_SERVER1).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_TIME_SERVER1,
|
||||
Settings_ESP3D::get_default_string_value(ESP_TIME_SERVER1).c_str());
|
||||
// Time Server 2 address
|
||||
Settings_ESP3D::write_string(ESP_TIME_SERVER2, Settings_ESP3D::get_default_string_value(ESP_TIME_SERVER2).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_TIME_SERVER2,
|
||||
Settings_ESP3D::get_default_string_value(ESP_TIME_SERVER2).c_str());
|
||||
// Time Server 3 address
|
||||
Settings_ESP3D::write_string(ESP_TIME_SERVER3, Settings_ESP3D::get_default_string_value(ESP_TIME_SERVER3).c_str());
|
||||
Settings_ESP3D::write_string(
|
||||
ESP_TIME_SERVER3,
|
||||
Settings_ESP3D::get_default_string_value(ESP_TIME_SERVER3).c_str());
|
||||
#endif // TIMESTAMP_FEATURE
|
||||
#ifdef SENSOR_DEVICE
|
||||
// Sensor device
|
||||
Settings_ESP3D::write_byte(ESP_SENSOR_TYPE,Settings_ESP3D::get_default_byte_value(ESP_SENSOR_TYPE));
|
||||
Settings_ESP3D::write_byte(
|
||||
ESP_SENSOR_TYPE, Settings_ESP3D::get_default_byte_value(ESP_SENSOR_TYPE));
|
||||
// Sensor query interval
|
||||
Settings_ESP3D::write_uint32 (ESP_SENSOR_INTERVAL, Settings_ESP3D::get_default_int32_value(ESP_SENSOR_INTERVAL));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_SENSOR_INTERVAL,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_SENSOR_INTERVAL));
|
||||
#endif // SENSOR_DEVICE
|
||||
// Start Delay
|
||||
Settings_ESP3D::write_uint32 (ESP_BOOT_DELAY, Settings_ESP3D::get_default_int32_value(ESP_BOOT_DELAY));
|
||||
Settings_ESP3D::write_uint32(
|
||||
ESP_BOOT_DELAY, Settings_ESP3D::get_default_int32_value(ESP_BOOT_DELAY));
|
||||
#endif // SETTINGS_IN_EEPROM
|
||||
// set version in settings
|
||||
if (res) {
|
||||
log_esp3d("Reset Setting Version");
|
||||
// Settings version (internal only)
|
||||
res = Settings_ESP3D::write_string(ESP_SETTINGS_VERSION, CURRENT_SETTINGS_VERSION);
|
||||
res = Settings_ESP3D::write_string(ESP_SETTINGS_VERSION,
|
||||
CURRENT_SETTINGS_VERSION);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -1283,12 +1366,12 @@ bool Settings_ESP3D::reset(bool networkonly)
|
||||
// * -1 means no version detected
|
||||
// * 00 / 01 Not used
|
||||
// * 03 and up is version
|
||||
int8_t Settings_ESP3D::GetSettingsVersion()
|
||||
{
|
||||
int8_t Settings_ESP3D::GetSettingsVersion() {
|
||||
int8_t v = -1;
|
||||
String version = Settings_ESP3D::read_string(ESP_SETTINGS_VERSION);
|
||||
if ((version == "ESP3D") ||( version.length() != 7) || (version.indexOf("ESP3D")!=0)) {
|
||||
log_esp3d("Invalid Settings Version %s",version.c_str());
|
||||
if ((version == "ESP3D") || (version.length() != 7) ||
|
||||
(version.indexOf("ESP3D") != 0)) {
|
||||
log_esp3d_e("Invalid Settings Version %s", version.c_str());
|
||||
return v;
|
||||
}
|
||||
v = version.substring(5).toInt();
|
||||
@ -1297,14 +1380,12 @@ int8_t Settings_ESP3D::GetSettingsVersion()
|
||||
}
|
||||
|
||||
// write a IP from string
|
||||
bool Settings_ESP3D::write_IP_String(int pos, const char * value)
|
||||
{
|
||||
bool Settings_ESP3D::write_IP_String(int pos, const char *value) {
|
||||
return write_uint32(pos, StringtoIP(value));
|
||||
}
|
||||
|
||||
// Helper to convert IP string to int
|
||||
uint32_t Settings_ESP3D::StringtoIP(const char *s)
|
||||
{
|
||||
uint32_t Settings_ESP3D::StringtoIP(const char *s) {
|
||||
uint32_t ip_int = 0;
|
||||
IPAddress ipaddr;
|
||||
if (ipaddr.fromString(s)) {
|
||||
@ -1314,15 +1395,13 @@ uint32_t Settings_ESP3D::StringtoIP(const char *s)
|
||||
}
|
||||
|
||||
// Helper to convert int to IP string
|
||||
String Settings_ESP3D::IPtoString(uint32_t ip_int)
|
||||
{
|
||||
String Settings_ESP3D::IPtoString(uint32_t ip_int) {
|
||||
static IPAddress ipaddr;
|
||||
ipaddr = ip_int;
|
||||
return ipaddr.toString();
|
||||
}
|
||||
|
||||
const char * Settings_ESP3D::TargetBoard()
|
||||
{
|
||||
const char *Settings_ESP3D::TargetBoard() {
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#define TYPE_BOARD "ESP32"
|
||||
@ -1345,11 +1424,11 @@ const char * Settings_ESP3D::TargetBoard()
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
}
|
||||
|
||||
bool Settings_ESP3D::isLocalPasswordValid (const char * password)
|
||||
{
|
||||
bool Settings_ESP3D::isLocalPasswordValid(const char *password) {
|
||||
char c;
|
||||
// limited size
|
||||
if ( (strlen (password) > MAX_LOCAL_PASSWORD_LENGTH) || (strlen (password) <= MIN_LOCAL_PASSWORD_LENGTH) ) {
|
||||
if ((strlen(password) > MAX_LOCAL_PASSWORD_LENGTH) ||
|
||||
(strlen(password) <= MIN_LOCAL_PASSWORD_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
// no space allowed
|
||||
|
@ -147,11 +147,16 @@
|
||||
#define HIDDEN_PASSWORD "********"
|
||||
|
||||
// Debug
|
||||
#define DEBUG_OUTPUT_SERIAL0 1
|
||||
#define DEBUG_OUTPUT_SERIAL1 2
|
||||
#define DEBUG_OUTPUT_SERIAL2 3
|
||||
#define DEBUG_OUTPUT_TELNET 4
|
||||
#define DEBUG_OUTPUT_WEBSOCKET 5
|
||||
#define LOG_OUTPUT_SERIAL0 1
|
||||
#define LOG_OUTPUT_SERIAL1 2
|
||||
#define LOG_OUTPUT_SERIAL2 3
|
||||
#define LOG_OUTPUT_TELNET 4
|
||||
#define LOG_OUTPUT_WEBSOCKET 5
|
||||
|
||||
#define LOG_LEVEL_NONE 0
|
||||
#define LOG_LEVEL_ERROR 1
|
||||
#define LOG_LEVEL_DEBUG 2
|
||||
#define LOG_LEVEL_VERBOSE 3
|
||||
|
||||
// Serial
|
||||
#define USE_SERIAL_0 1
|
||||
|
@ -21,7 +21,9 @@
|
||||
#ifndef _ESP3D_CONFIG_H
|
||||
#define _ESP3D_CONFIG_H
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "../include/defines.h"
|
||||
|
||||
#if defined __has_include
|
||||
#if __has_include("../../configuration.h")
|
||||
#include "../../configuration.h"
|
||||
@ -38,12 +40,13 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "../core/hal.h"
|
||||
#include "../core/log_esp3d.h"
|
||||
#include "../include/pins.h"
|
||||
#include "../include/sanity_esp3d.h"
|
||||
#include "../core/hal.h"
|
||||
#include "../core/debug_esp3d.h"
|
||||
#include "../include/version.h"
|
||||
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
/************************************
|
||||
*
|
||||
@ -62,11 +65,15 @@
|
||||
* **********************************/
|
||||
|
||||
// Make Flag more generic
|
||||
#if (defined(PIN_RESET_FEATURE) && defined(ESP3D_RESET_PIN) && ESP3D_RESET_PIN!=-1) || defined(SD_RECOVERY_FEATURE)
|
||||
#if (defined(PIN_RESET_FEATURE) && defined(ESP3D_RESET_PIN) && \
|
||||
ESP3D_RESET_PIN != -1) || \
|
||||
defined(SD_RECOVERY_FEATURE)
|
||||
#define RECOVERY_FEATURE
|
||||
#endif // PIN_RESET_FEATURE || SD_RECOVERY_FEATURE
|
||||
|
||||
#if defined(DISPLAY_DEVICE) || defined(SENSOR_DEVICE) || defined(RECOVERY_FEATURE) || defined(BUZZER_DEVICE) || defined(CAMERA_DEVICE) || defined(SD_DEVICE)
|
||||
#if defined(DISPLAY_DEVICE) || defined(SENSOR_DEVICE) || \
|
||||
defined(RECOVERY_FEATURE) || defined(BUZZER_DEVICE) || \
|
||||
defined(CAMERA_DEVICE) || defined(SD_DEVICE)
|
||||
#define CONNECTED_DEVICES_FEATURE
|
||||
#endif // DISPLAY_DEVICE || SENSOR_DEVICE , etc...
|
||||
|
||||
|
@ -38,12 +38,12 @@
|
||||
#endif // ESP_BRIDGE_TX_PIN
|
||||
#endif // ESP_SERIAL_BRIDGE_OUTPUT
|
||||
|
||||
#ifndef ESP_DEBUG_RX_PIN
|
||||
#define ESP_DEBUG_RX_PIN -1
|
||||
#endif // ESP_DEBUG_RX_PIN
|
||||
#ifndef ESP_DEBUG_TX_PIN
|
||||
#define ESP_DEBUG_TX_PIN -1
|
||||
#endif // ESP_DEBUG_TX_PIN
|
||||
#ifndef ESP_LOG_RX_PIN
|
||||
#define ESP_LOG_RX_PIN -1
|
||||
#endif // ESP_LOG_RX_PIN
|
||||
#ifndef ESP_LOG_TX_PIN
|
||||
#define ESP_LOG_TX_PIN -1
|
||||
#endif // ESP_LOG_TX_PIN
|
||||
|
||||
// I2C Pins
|
||||
#ifndef ESP_SDA_PIN
|
||||
|
@ -37,14 +37,14 @@
|
||||
* Debug
|
||||
* ***********************/
|
||||
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
#if ESP_DEBUG_FEATURE == ESP_SERIAL_OUTPUT
|
||||
#warning You use same serial for output and debug
|
||||
#endif // ESP_DEBUG_FEATURE == ESP_SERIAL_OUTPUT
|
||||
#if (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2) && defined(ARDUINO_ARCH_ESP8266)
|
||||
#error Serial 2 is not available in ESP8266 for debug
|
||||
#endif // ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2 ) && ARDUINO_ARCH_ESP8266
|
||||
#endif // ESP_DEBUG_FEATURE
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
#if ESP_LOG_FEATURE == ESP_SERIAL_OUTPUT
|
||||
#warning You use same serial for output and log
|
||||
#endif // ESP_LOG_FEATURE == ESP_SERIAL_OUTPUT
|
||||
#if (ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL2) && defined(ARDUINO_ARCH_ESP8266)
|
||||
#error Serial 2 is not available in ESP8266 for log
|
||||
#endif // ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL2 ) && ARDUINO_ARCH_ESP8266
|
||||
#endif // ESP_LOG_FEATURE
|
||||
|
||||
/**************************
|
||||
* Serial
|
||||
|
@ -20,28 +20,29 @@
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef CAMERA_DEVICE
|
||||
#include "camera.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/esp3d.h"
|
||||
#include <esp_camera.h>
|
||||
#include <soc/soc.h> //not sure this one is needed
|
||||
#include <soc/rtc_cntl_reg.h>
|
||||
#include <WebServer.h>
|
||||
#include <esp_camera.h>
|
||||
#include <soc/rtc_cntl_reg.h>
|
||||
#include <soc/soc.h> //not sure this one is needed
|
||||
|
||||
#include "../../core/esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "camera.h"
|
||||
|
||||
#if defined(SD_DEVICE)
|
||||
#include "../filesystem/esp_sd.h"
|
||||
#endif // SD_DEVICE
|
||||
|
||||
|
||||
#define DEFAULT_FRAME_SIZE FRAMESIZE_SVGA
|
||||
#define JPEG_COMPRESSION 80
|
||||
|
||||
Camera esp3d_camera;
|
||||
|
||||
bool Camera::handle_snap(WebServer * webserver, const char *path, const char* filename)
|
||||
{
|
||||
bool Camera::handle_snap(WebServer *webserver, const char *path,
|
||||
const char *filename) {
|
||||
log_esp3d("Camera stream reached");
|
||||
if (!_initialised) {
|
||||
log_esp3d("Camera not started");
|
||||
log_esp3d_e("Camera not started");
|
||||
if (webserver) {
|
||||
webserver->send(500, "text/plain", "Camera not started");
|
||||
}
|
||||
@ -72,26 +73,29 @@ bool Camera::handle_snap(WebServer * webserver, const char *path, const char* fi
|
||||
size_t _jpg_buf_len = 0;
|
||||
uint8_t *_jpg_buf = NULL;
|
||||
if (webserver) {
|
||||
webserver->sendHeader(String(F("Content-Type")), String(F("image/jpeg")),true);
|
||||
webserver->sendHeader(String(F("Content-Disposition")), String(F("inline; filename=capture.jpg")),true);
|
||||
webserver->sendHeader(String(F("Content-Type")), String(F("image/jpeg")),
|
||||
true);
|
||||
webserver->sendHeader(String(F("Content-Disposition")),
|
||||
String(F("inline; filename=capture.jpg")), true);
|
||||
webserver->setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
webserver->send(200);
|
||||
}
|
||||
log_esp3d("Camera capture ongoing");
|
||||
fb = esp_camera_fb_get();
|
||||
if (!fb) {
|
||||
log_esp3d("Camera capture failed");
|
||||
log_esp3d_e("Camera capture failed");
|
||||
if (webserver) {
|
||||
webserver->send(500, "text/plain", "Capture failed");
|
||||
}
|
||||
res_error = true;
|
||||
} else {
|
||||
if (fb->format != PIXFORMAT_JPEG) {
|
||||
bool jpeg_converted = frame2jpg(fb, JPEG_COMPRESSION, &_jpg_buf, &_jpg_buf_len);
|
||||
bool jpeg_converted =
|
||||
frame2jpg(fb, JPEG_COMPRESSION, &_jpg_buf, &_jpg_buf_len);
|
||||
esp_camera_fb_return(fb);
|
||||
fb = NULL;
|
||||
if (!jpeg_converted) {
|
||||
log_esp3d("JPEG compression failed");
|
||||
log_esp3d_e("JPEG compression failed");
|
||||
res_error = true;
|
||||
}
|
||||
} else {
|
||||
@ -107,11 +111,11 @@ bool Camera::handle_snap(WebServer * webserver, const char *path, const char* fi
|
||||
if (filename != nullptr && path != nullptr) {
|
||||
if (!ESP_SD::accessFS()) {
|
||||
res_error = true;
|
||||
log_esp3d("SD not available");
|
||||
log_esp3d_e("SD not available");
|
||||
} else {
|
||||
if (ESP_SD::getState(true) == ESP_SDCARD_NOT_PRESENT) {
|
||||
res_error = true;
|
||||
log_esp3d("No SD");
|
||||
log_esp3d_e("No SD");
|
||||
} else {
|
||||
ESP_SD::setState(ESP_SDCARD_BUSY);
|
||||
String wpath = path[0] == '/' ? path : String("/") + path;
|
||||
@ -130,17 +134,16 @@ bool Camera::handle_snap(WebServer * webserver, const char *path, const char* fi
|
||||
log_esp3d("Camera capture done");
|
||||
} else {
|
||||
res_error = true;
|
||||
log_esp3d("Failed to open file for writing");
|
||||
log_esp3d_e("Failed to open file for writing");
|
||||
}
|
||||
}
|
||||
}
|
||||
ESP_SD::releaseFS();
|
||||
}
|
||||
|
||||
}
|
||||
#endif // SD_DEVICE
|
||||
if (!webserver && filename == nullptr && path == nullptr) {
|
||||
log_esp3d("No output defined");
|
||||
log_esp3d_e("No output defined");
|
||||
res_error = true;
|
||||
}
|
||||
}
|
||||
@ -159,19 +162,14 @@ bool Camera::handle_snap(WebServer * webserver, const char *path, const char* fi
|
||||
return !res_error;
|
||||
}
|
||||
|
||||
Camera::Camera()
|
||||
{
|
||||
Camera::Camera() {
|
||||
_started = false;
|
||||
_initialised = false;
|
||||
}
|
||||
|
||||
Camera::~Camera()
|
||||
{
|
||||
end();
|
||||
}
|
||||
Camera::~Camera() { end(); }
|
||||
|
||||
int Camera::command(const char * param, const char * value)
|
||||
{
|
||||
int Camera::command(const char *param, const char *value) {
|
||||
log_esp3d("Camera: %s=%s\n", param, value);
|
||||
int res = 0;
|
||||
int val = atoi(value);
|
||||
@ -240,8 +238,7 @@ int Camera::command(const char * param, const char * value)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool Camera::initHardware()
|
||||
{
|
||||
bool Camera::initHardware() {
|
||||
_initialised = false;
|
||||
log_esp3d("Disable brown out");
|
||||
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // disable brownout detector
|
||||
@ -274,7 +271,7 @@ bool Camera::initHardware()
|
||||
config.grab_mode = CAMERA_GRAB_LATEST;
|
||||
if (!psramFound()) {
|
||||
_initialised = false;
|
||||
log_esp3d("psram is not enabled");
|
||||
log_esp3d_e("psram is not enabled");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("Init camera");
|
||||
@ -306,21 +303,17 @@ bool Camera::initHardware()
|
||||
log_esp3d("Init camera config");
|
||||
esp_err_t err = esp_camera_init(&config);
|
||||
if (err != ESP_OK) {
|
||||
log_esp3d("Camera init failed with error 0x%x", err);
|
||||
log_esp3d_e("Camera init failed with error 0x%x", err);
|
||||
} else {
|
||||
_initialised = true;
|
||||
}
|
||||
return _initialised;
|
||||
}
|
||||
|
||||
bool Camera::stopHardware()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool Camera::stopHardware() { return true; }
|
||||
|
||||
// need to be call by device and by network
|
||||
bool Camera::begin()
|
||||
{
|
||||
bool Camera::begin() {
|
||||
end();
|
||||
log_esp3d("Begin camera");
|
||||
if (!_initialised) {
|
||||
@ -351,23 +344,15 @@ bool Camera::begin()
|
||||
return _started;
|
||||
}
|
||||
|
||||
void Camera::end()
|
||||
{
|
||||
_started = false;
|
||||
}
|
||||
void Camera::end() { _started = false; }
|
||||
|
||||
void Camera::handle()
|
||||
{
|
||||
void Camera::handle() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
uint8_t Camera::GetModel()
|
||||
{
|
||||
return CAMERA_DEVICE;
|
||||
}
|
||||
uint8_t Camera::GetModel() { return CAMERA_DEVICE; }
|
||||
|
||||
const char *Camera::GetModelString()
|
||||
{
|
||||
const char *Camera::GetModelString() {
|
||||
#if defined(CUSTOM_CAMERA_NAME)
|
||||
return CUSTOM_CAMERA_NAME;
|
||||
#else
|
||||
|
@ -20,9 +20,9 @@
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef CONNECTED_DEVICES_FEATURE
|
||||
#include "devices_services.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "devices_services.h"
|
||||
|
||||
#ifdef DISPLAY_DEVICE
|
||||
#include "../display/display.h"
|
||||
@ -45,43 +45,42 @@
|
||||
|
||||
bool DevicesServices::_started = false;
|
||||
|
||||
bool DevicesServices::begin()
|
||||
{
|
||||
bool DevicesServices::begin() {
|
||||
bool res = true;
|
||||
_started = false;
|
||||
#ifdef SD_DEVICE
|
||||
if (!ESP_SD::begin()) {
|
||||
log_esp3d("Error sd intialization failed");
|
||||
log_esp3d_e("Error sd intialization failed");
|
||||
res = false;
|
||||
}
|
||||
#endif // SD_DEVICE
|
||||
#ifdef DISPLAY_DEVICE
|
||||
if (!esp3d_display.begin()) {
|
||||
log_esp3d("Error starting display device");
|
||||
log_esp3d_e("Error starting display device");
|
||||
res = false;
|
||||
}
|
||||
#endif // DISPLAY_DEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
if (!esp3d_sensor.begin()) {
|
||||
log_esp3d("Error starting sensor device");
|
||||
log_esp3d_e("Error starting sensor device");
|
||||
res = false;
|
||||
}
|
||||
#endif // SENSOR_DEVICE
|
||||
#ifdef BUZZER_DEVICE
|
||||
if (!esp3d_buzzer.begin()) {
|
||||
log_esp3d("Error starting buzzer device");
|
||||
log_esp3d_e("Error starting buzzer device");
|
||||
res = false;
|
||||
}
|
||||
#endif // BUZZER_DEVICE
|
||||
#ifdef RECOVERY_FEATURE
|
||||
if (!recovery_service.begin()) {
|
||||
log_esp3d("Error starting recovery service");
|
||||
log_esp3d_e("Error starting recovery service");
|
||||
res = false;
|
||||
}
|
||||
#endif // RECOVERY_FEATURE
|
||||
#ifdef CAMERA_DEVICE
|
||||
if (!esp3d_camera.initHardware()) {
|
||||
log_esp3d("Error camera intialization failed");
|
||||
log_esp3d_e("Error camera intialization failed");
|
||||
res = false;
|
||||
}
|
||||
#endif // CAMERA_DEVICE
|
||||
@ -91,8 +90,7 @@ bool DevicesServices::begin()
|
||||
_started = res;
|
||||
return _started;
|
||||
}
|
||||
void DevicesServices::end()
|
||||
{
|
||||
void DevicesServices::end() {
|
||||
if (!_started) {
|
||||
return;
|
||||
}
|
||||
@ -117,8 +115,7 @@ void DevicesServices::end()
|
||||
#endif // SENSOR_DEVICE
|
||||
}
|
||||
|
||||
void DevicesServices::handle()
|
||||
{
|
||||
void DevicesServices::handle() {
|
||||
if (_started) {
|
||||
#ifdef CAMERA_DEVICE
|
||||
esp3d_camera.handle();
|
||||
|
@ -21,8 +21,9 @@
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined(ETH_FEATURE)
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "esp_eth.h"
|
||||
#include "dhcpserver/dhcpserver_options.h"
|
||||
#include "esp_eth.h"
|
||||
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
@ -34,8 +35,7 @@ bool EthConfig::_started = false;
|
||||
bool EthConfig::_connected = false;
|
||||
const uint8_t DEFAULT_AP_MASK_VALUE[] = {255, 255, 255, 0};
|
||||
|
||||
bool EthConfig::StartSTA()
|
||||
{
|
||||
bool EthConfig::StartSTA() {
|
||||
bool res = true;
|
||||
if ((Settings_ESP3D::read_byte(ESP_STA_IP_MODE) != DHCP_MODE)) {
|
||||
int32_t IP = Settings_ESP3D::read_IP(ESP_STA_IP_VALUE);
|
||||
@ -55,7 +55,7 @@ bool EthConfig::StartSTA()
|
||||
IPAddress ip(IP), mask(DEFAULT_AP_MASK_VALUE), gateway(IP);
|
||||
if (!ETH.config(ip, gateway,mask)) {
|
||||
res = false;
|
||||
log_esp3d("Set static IP error");
|
||||
log_esp3d_e("Set static IP error");
|
||||
}
|
||||
//start DHCP server
|
||||
if(res) {
|
||||
@ -72,14 +72,13 @@ bool EthConfig::StartSTA()
|
||||
|
||||
if (tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_ETH) != ESP_OK){
|
||||
res = false;
|
||||
log_esp3d("Start DHCP server failed");
|
||||
log_esp3d_e("Start DHCP server failed");
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}*/
|
||||
|
||||
bool EthConfig::linkUp()
|
||||
{
|
||||
bool EthConfig::linkUp() {
|
||||
#if defined(ESP_IDF_VERSION_MAJOR)
|
||||
// patch for https://github.com/espressif/arduino-esp32/issues/6105
|
||||
return _connected;
|
||||
@ -91,8 +90,7 @@ bool EthConfig::linkUp()
|
||||
/**
|
||||
* begin WiFi setup
|
||||
*/
|
||||
bool EthConfig::begin(int8_t & espMode)
|
||||
{
|
||||
bool EthConfig::begin(int8_t& espMode) {
|
||||
bool res = false;
|
||||
ESP3DOutput output(ESP_ALL_CLIENTS);
|
||||
end();
|
||||
@ -119,7 +117,6 @@ bool EthConfig::begin(int8_t & espMode)
|
||||
if (Settings_ESP3D::isVerboseBoot()) {
|
||||
output.printMSG("Client started");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -131,8 +128,8 @@ bool EthConfig::begin(int8_t & espMode)
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
//if ((Settings_ESP3D::read_byte(ESP_STA_IP_MODE) != DHCP_MODE) || (espMode == ESP_ETH_SRV)){
|
||||
// if ((Settings_ESP3D::read_byte(ESP_STA_IP_MODE) != DHCP_MODE) || (espMode
|
||||
// == ESP_ETH_SRV)){
|
||||
if ((Settings_ESP3D::read_byte(ESP_STA_IP_MODE) != DHCP_MODE)) {
|
||||
// as no event to display static IP
|
||||
output.printMSG(ETH.localIP().toString().c_str());
|
||||
@ -145,24 +142,16 @@ bool EthConfig::begin(int8_t & espMode)
|
||||
* End WiFi
|
||||
*/
|
||||
|
||||
void EthConfig::end()
|
||||
{
|
||||
void EthConfig::end() {
|
||||
// esp_eth_disable();
|
||||
_started = false;
|
||||
}
|
||||
|
||||
bool EthConfig::started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
bool EthConfig::started() { return _started; }
|
||||
/**
|
||||
* Handle not critical actions that must be done in sync environement
|
||||
*/
|
||||
|
||||
void EthConfig::handle()
|
||||
{
|
||||
}
|
||||
|
||||
void EthConfig::handle() {}
|
||||
|
||||
#endif // ETH_FEATURE
|
||||
|
||||
|
@ -17,14 +17,13 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined(GLOBAL_FILESYSTEM_FEATURE)
|
||||
#include "esp_globalFS.h"
|
||||
|
||||
// to verify FS is accessible
|
||||
bool ESP_GBFS::isavailable(uint8_t FS)
|
||||
{
|
||||
bool ESP_GBFS::isavailable(uint8_t FS) {
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
if (FS == FS_FLASH) {
|
||||
return ESP_FileSystem::started();
|
||||
@ -42,8 +41,7 @@ uint8_t ESP_GBFS::_nbFS = 0;
|
||||
String ESP_GBFS::_rootlist[MAX_FS];
|
||||
|
||||
// helper to format size to readable string
|
||||
String & ESP_GBFS::formatBytes (uint64_t bytes)
|
||||
{
|
||||
String &ESP_GBFS::formatBytes(uint64_t bytes) {
|
||||
static String res;
|
||||
if (bytes < 1024) {
|
||||
res = String((uint16_t)bytes) + " B";
|
||||
@ -58,8 +56,7 @@ String & ESP_GBFS::formatBytes (uint64_t bytes)
|
||||
}
|
||||
|
||||
// depending FS
|
||||
uint64_t ESP_GBFS::totalBytes(uint8_t FS)
|
||||
{
|
||||
uint64_t ESP_GBFS::totalBytes(uint8_t FS) {
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
if (FS == FS_FLASH) {
|
||||
return ESP_FileSystem::totalBytes();
|
||||
@ -73,8 +70,7 @@ uint64_t ESP_GBFS::totalBytes(uint8_t FS)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t ESP_GBFS::usedBytes(uint8_t FS)
|
||||
{
|
||||
uint64_t ESP_GBFS::usedBytes(uint8_t FS) {
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
if (FS == FS_FLASH) {
|
||||
return ESP_FileSystem::usedBytes();
|
||||
@ -88,8 +84,7 @@ uint64_t ESP_GBFS::usedBytes(uint8_t FS)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint ESP_GBFS::maxPathLength()
|
||||
{
|
||||
uint ESP_GBFS::maxPathLength() {
|
||||
uint size = 255;
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
if (size > 32) {
|
||||
@ -104,8 +99,7 @@ uint ESP_GBFS::maxPathLength()
|
||||
return size;
|
||||
}
|
||||
|
||||
bool ESP_GBFS::accessFS(uint8_t FS)
|
||||
{
|
||||
bool ESP_GBFS::accessFS(uint8_t FS) {
|
||||
if (FS == FS_ROOT) {
|
||||
return true;
|
||||
}
|
||||
@ -125,15 +119,13 @@ bool ESP_GBFS::accessFS(uint8_t FS)
|
||||
ESP_SD::setState(ESP_SDCARD_BUSY);
|
||||
canAccess = true;
|
||||
}
|
||||
|
||||
}
|
||||
return canAccess;
|
||||
}
|
||||
#endif // SD_DEVICE
|
||||
return false;
|
||||
}
|
||||
void ESP_GBFS::releaseFS(uint8_t FS)
|
||||
{
|
||||
void ESP_GBFS::releaseFS(uint8_t FS) {
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
if (FS == FS_FLASH) {
|
||||
ESP_FileSystem::releaseFS();
|
||||
@ -146,8 +138,7 @@ void ESP_GBFS::releaseFS(uint8_t FS)
|
||||
#endif // SD_DEVICE
|
||||
}
|
||||
|
||||
uint64_t ESP_GBFS::freeBytes(uint8_t FS)
|
||||
{
|
||||
uint64_t ESP_GBFS::freeBytes(uint8_t FS) {
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
if (FS == FS_FLASH) {
|
||||
return ESP_FileSystem::freeBytes();
|
||||
@ -162,8 +153,7 @@ uint64_t ESP_GBFS::freeBytes(uint8_t FS)
|
||||
}
|
||||
|
||||
// Format is not always available for all FS
|
||||
bool format(uint8_t FS, ESP3DOutput * output = nullptr)
|
||||
{
|
||||
bool format(uint8_t FS, ESP3DOutput *output = nullptr) {
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
if (FS == FS_FLASH) {
|
||||
return ESP_FileSystem::format();
|
||||
@ -179,8 +169,7 @@ bool format(uint8_t FS, ESP3DOutput * output = nullptr)
|
||||
}
|
||||
|
||||
// check type of FS according root dir
|
||||
uint8_t ESP_GBFS::getFSType(const char * path)
|
||||
{
|
||||
uint8_t ESP_GBFS::getFSType(const char *path) {
|
||||
String p = path;
|
||||
p.trim();
|
||||
if (p == "/") {
|
||||
@ -199,8 +188,7 @@ uint8_t ESP_GBFS::getFSType(const char * path)
|
||||
return FS_UNKNOWN;
|
||||
}
|
||||
|
||||
const char * ESP_GBFS::getRealPath(const char * path)
|
||||
{
|
||||
const char *ESP_GBFS::getRealPath(const char *path) {
|
||||
static String p;
|
||||
uint8_t t = getFSType(path);
|
||||
p = "";
|
||||
@ -230,8 +218,7 @@ const char * ESP_GBFS::getRealPath(const char * path)
|
||||
}
|
||||
|
||||
// path exists on / or SD or FS
|
||||
bool ESP_GBFS::exists(const char* path)
|
||||
{
|
||||
bool ESP_GBFS::exists(const char *path) {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
uint8_t t = getFSType(path);
|
||||
if (t == FS_ROOT) {
|
||||
@ -251,8 +238,7 @@ bool ESP_GBFS::exists(const char* path)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESP_GBFS::remove(const char *path)
|
||||
{
|
||||
bool ESP_GBFS::remove(const char *path) {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
uint8_t t = getFSType(path);
|
||||
if (t == FS_ROOT) {
|
||||
@ -272,29 +258,34 @@ bool ESP_GBFS::remove(const char *path)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESP_GBFS::rename(const char *oldpath, const char *newpath)
|
||||
{
|
||||
bool ESP_GBFS::rename(const char *oldpath, const char *newpath) {
|
||||
log_esp3d("rename global %s to %s", oldpath, newpath);
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
uint8_t t = getFSType(oldpath);
|
||||
if (t == FS_ROOT) {
|
||||
log_esp3d_e("rename on root not allowed");
|
||||
return false;
|
||||
}
|
||||
String o = getRealPath(oldpath);
|
||||
String n = getRealPath(newpath);
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
if (t == FS_FLASH) {
|
||||
return ESP_FileSystem::rename(getRealPath(oldpath), getRealPath(newpath));
|
||||
log_esp3d("rename FS %s to %s", n.c_str(), o.c_str());
|
||||
return ESP_FileSystem::rename(o.c_str(), n.c_str());
|
||||
}
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
#if defined(SD_DEVICE)
|
||||
if (t == FS_SD) {
|
||||
return ESP_SD::rename(getRealPath(oldpath), getRealPath(newpath));
|
||||
log_esp3d("rename FS %s to %s", o.c_str(), n.c_str());
|
||||
return ESP_SD::rename(o.c_str(), n.c_str());
|
||||
}
|
||||
#endif // SD_DEVICE
|
||||
#endif // FILESYSTEM_FEATURE || SD_DEVICE
|
||||
log_esp3d_e("Unknow FS, rename not allowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESP_GBFS::mkdir(const char *path)
|
||||
{
|
||||
bool ESP_GBFS::mkdir(const char *path) {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
uint8_t t = getFSType(path);
|
||||
if (t == FS_ROOT) {
|
||||
@ -302,7 +293,8 @@ bool ESP_GBFS::mkdir(const char *path)
|
||||
}
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
if (t == FS_FLASH) {
|
||||
return ESP_FileSystem::mkdir(getRealPath(path));;
|
||||
return ESP_FileSystem::mkdir(getRealPath(path));
|
||||
;
|
||||
}
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
#if defined(SD_DEVICE)
|
||||
@ -314,8 +306,7 @@ bool ESP_GBFS::mkdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESP_GBFS::rmdir(const char *path)
|
||||
{
|
||||
bool ESP_GBFS::rmdir(const char *path) {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
uint8_t t = getFSType(path);
|
||||
if (t == FS_ROOT) {
|
||||
@ -328,15 +319,15 @@ bool ESP_GBFS::rmdir(const char *path)
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
#if defined(SD_DEVICE)
|
||||
if (t == FS_SD) {
|
||||
return ESP_SD::rmdir(getRealPath(path));;
|
||||
return ESP_SD::rmdir(getRealPath(path));
|
||||
;
|
||||
}
|
||||
#endif // SD_DEVICE
|
||||
#endif // FILESYSTEM_FEATURE || SD_DEVICE
|
||||
return false;
|
||||
}
|
||||
|
||||
void ESP_GBFS::closeAll()
|
||||
{
|
||||
void ESP_GBFS::closeAll() {
|
||||
getNextFS(true);
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
ESP_FileSystem::closeAll();
|
||||
@ -346,8 +337,7 @@ void ESP_GBFS::closeAll()
|
||||
#endif // SD_DEVICE
|
||||
}
|
||||
|
||||
ESP_GBFile ESP_GBFS::open(const char* path, uint8_t mode)
|
||||
{
|
||||
ESP_GBFile ESP_GBFS::open(const char *path, uint8_t mode) {
|
||||
ESP_GBFile f;
|
||||
log_esp3d("open %s", path);
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
@ -374,24 +364,18 @@ ESP_GBFile ESP_GBFS::open(const char* path, uint8_t mode)
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
// Default File is no file
|
||||
ESP_GBFile::ESP_GBFile()
|
||||
{
|
||||
_type = FS_UNKNOWN;
|
||||
}
|
||||
ESP_GBFile::ESP_GBFile() { _type = FS_UNKNOWN; }
|
||||
|
||||
// File handle for the root
|
||||
ESP_GBFile::ESP_GBFile(uint8_t FS, const char *name)
|
||||
{
|
||||
ESP_GBFile::ESP_GBFile(uint8_t FS, const char *name) {
|
||||
_type = FS;
|
||||
_name = name;
|
||||
}
|
||||
|
||||
// Handle for flash file
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
ESP_GBFile::ESP_GBFile(ESP_File & flashFile)
|
||||
{
|
||||
ESP_GBFile::ESP_GBFile(ESP_File &flashFile) {
|
||||
_type = FS_FLASH;
|
||||
_flashFile = flashFile;
|
||||
#ifdef SD_DEVICE
|
||||
@ -402,8 +386,7 @@ ESP_GBFile::ESP_GBFile(ESP_File & flashFile)
|
||||
|
||||
// Handle for SD file
|
||||
#ifdef SD_DEVICE
|
||||
ESP_GBFile::ESP_GBFile(ESP_SDFile & sdFile)
|
||||
{
|
||||
ESP_GBFile::ESP_GBFile(ESP_SDFile &sdFile) {
|
||||
_type = FS_SD;
|
||||
_sdFile = sdFile;
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
@ -413,12 +396,9 @@ ESP_GBFile::ESP_GBFile(ESP_SDFile & sdFile)
|
||||
#endif // SD_DEVICE
|
||||
|
||||
// Destructor
|
||||
ESP_GBFile::~ESP_GBFile()
|
||||
{
|
||||
}
|
||||
ESP_GBFile::~ESP_GBFile() {}
|
||||
|
||||
ESP_GBFile::operator bool() const
|
||||
{
|
||||
ESP_GBFile::operator bool() const {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return true;
|
||||
@ -437,8 +417,7 @@ ESP_GBFile::operator bool() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESP_GBFile::seek(uint32_t pos, uint8_t mode)
|
||||
{
|
||||
bool ESP_GBFile::seek(uint32_t pos, uint8_t mode) {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return false;
|
||||
@ -457,8 +436,7 @@ bool ESP_GBFile::seek(uint32_t pos, uint8_t mode)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ESP_GBFile::close()
|
||||
{
|
||||
void ESP_GBFile::close() {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
// TBD
|
||||
@ -476,8 +454,7 @@ void ESP_GBFile::close()
|
||||
#endif // SD_DEVICE
|
||||
}
|
||||
|
||||
bool ESP_GBFile::isOpen()
|
||||
{
|
||||
bool ESP_GBFile::isOpen() {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return true;
|
||||
@ -496,8 +473,7 @@ bool ESP_GBFile::isOpen()
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* ESP_GBFile::name() const
|
||||
{
|
||||
const char *ESP_GBFile::name() const {
|
||||
static String s;
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
@ -527,8 +503,7 @@ const char* ESP_GBFile::name() const
|
||||
return "";
|
||||
}
|
||||
|
||||
const char* ESP_GBFile::filename() const
|
||||
{
|
||||
const char *ESP_GBFile::filename() const {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
static String s;
|
||||
if (_type == FS_ROOT) {
|
||||
@ -552,8 +527,7 @@ const char* ESP_GBFile::filename() const
|
||||
return "";
|
||||
}
|
||||
|
||||
bool ESP_GBFile::isDirectory()
|
||||
{
|
||||
bool ESP_GBFile::isDirectory() {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return true;
|
||||
@ -572,8 +546,7 @@ bool ESP_GBFile::isDirectory()
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t ESP_GBFile::size()
|
||||
{
|
||||
size_t ESP_GBFile::size() {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return 0;
|
||||
@ -592,8 +565,7 @@ size_t ESP_GBFile::size()
|
||||
return 0;
|
||||
}
|
||||
|
||||
time_t ESP_GBFile::getLastWrite()
|
||||
{
|
||||
time_t ESP_GBFile::getLastWrite() {
|
||||
if (_type == FS_FLASH) {
|
||||
return _flashFile.getLastWrite();
|
||||
}
|
||||
@ -605,8 +577,7 @@ time_t ESP_GBFile::getLastWrite()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ESP_GBFile::available()
|
||||
{
|
||||
int ESP_GBFile::available() {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return 0;
|
||||
@ -625,8 +596,7 @@ int ESP_GBFile::available()
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ESP_GBFile::write(uint8_t i)
|
||||
{
|
||||
size_t ESP_GBFile::write(uint8_t i) {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return 0;
|
||||
@ -645,8 +615,7 @@ size_t ESP_GBFile::write(uint8_t i)
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ESP_GBFile::write(const uint8_t *buf, size_t size)
|
||||
{
|
||||
size_t ESP_GBFile::write(const uint8_t *buf, size_t size) {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return 0;
|
||||
@ -665,8 +634,7 @@ size_t ESP_GBFile::write(const uint8_t *buf, size_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ESP_GBFile::read()
|
||||
{
|
||||
int ESP_GBFile::read() {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return -1;
|
||||
@ -685,8 +653,7 @@ int ESP_GBFile::read()
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t ESP_GBFile::read(uint8_t* buf, size_t size)
|
||||
{
|
||||
size_t ESP_GBFile::read(uint8_t *buf, size_t size) {
|
||||
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
|
||||
if (_type == FS_ROOT) {
|
||||
return -1;
|
||||
@ -705,8 +672,7 @@ size_t ESP_GBFile::read(uint8_t* buf, size_t size)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ESP_GBFile::flush()
|
||||
{
|
||||
void ESP_GBFile::flush() {
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
if (_type == FS_FLASH) {
|
||||
return _flashFile.flush();
|
||||
@ -720,8 +686,7 @@ void ESP_GBFile::flush()
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_GBFile& ESP_GBFile::operator=(const ESP_GBFile & other)
|
||||
{
|
||||
ESP_GBFile &ESP_GBFile::operator=(const ESP_GBFile &other) {
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
_flashFile = other._flashFile;
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
@ -734,8 +699,7 @@ ESP_GBFile& ESP_GBFile::operator=(const ESP_GBFile & other)
|
||||
}
|
||||
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
ESP_GBFile & ESP_GBFile::operator=(const ESP_File & other)
|
||||
{
|
||||
ESP_GBFile &ESP_GBFile::operator=(const ESP_File &other) {
|
||||
_flashFile = other;
|
||||
#ifdef SD_DEVICE
|
||||
_sdFile = ESP_SDFile();
|
||||
@ -745,8 +709,7 @@ ESP_GBFile & ESP_GBFile::operator=(const ESP_File & other)
|
||||
}
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
ESP_GBFile & ESP_GBFile::operator=(const ESP_SDFile & other)
|
||||
{
|
||||
ESP_GBFile &ESP_GBFile::operator=(const ESP_SDFile &other) {
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
_flashFile = ESP_File();
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
@ -756,8 +719,7 @@ ESP_GBFile & ESP_GBFile::operator=(const ESP_SDFile & other)
|
||||
}
|
||||
#endif // SD_DEVICE
|
||||
|
||||
const char * ESP_GBFS::getNextFS(bool reset)
|
||||
{
|
||||
const char *ESP_GBFS::getNextFS(bool reset) {
|
||||
static uint8_t index = 0;
|
||||
if (reset) {
|
||||
index = 0;
|
||||
@ -782,8 +744,7 @@ const char * ESP_GBFS::getNextFS(bool reset)
|
||||
return "";
|
||||
}
|
||||
|
||||
ESP_GBFile ESP_GBFile::openNextFile()
|
||||
{
|
||||
ESP_GBFile ESP_GBFile::openNextFile() {
|
||||
ESP_GBFile f;
|
||||
if (_type == FS_ROOT) {
|
||||
String path = ESP_GBFS::getNextFS();
|
||||
|
@ -17,7 +17,7 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
// #define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef SD_DEVICE
|
||||
#include <time.h>
|
||||
@ -152,7 +152,7 @@ bool ESP_SD::accessFS(uint8_t FS) {
|
||||
log_esp3d("Access SD ok");
|
||||
return true;
|
||||
} else {
|
||||
log_esp3d("Enable shared SD failed");
|
||||
log_esp3d_e("Enable shared SD failed");
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
|
@ -17,60 +17,45 @@ fat_esp32_filesystem.cpp - ESP3D fat filesystem configuration class
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if (FILESYSTEM_FEATURE == ESP_FAT_FILESYSTEM)
|
||||
#include "../esp_filesystem.h"
|
||||
#include <stack>
|
||||
#include <FS.h>
|
||||
|
||||
#include <stack>
|
||||
|
||||
#include "../esp_filesystem.h"
|
||||
#include "FFat.h"
|
||||
|
||||
extern File tFile_handle[ESP_MAX_OPENHANDLE];
|
||||
|
||||
bool ESP_FileSystem::begin()
|
||||
{
|
||||
bool ESP_FileSystem::begin() {
|
||||
_started = FFat.begin();
|
||||
return _started;
|
||||
}
|
||||
|
||||
void ESP_FileSystem::end()
|
||||
{
|
||||
void ESP_FileSystem::end() {
|
||||
FFat.end();
|
||||
_started = false;
|
||||
}
|
||||
|
||||
size_t ESP_FileSystem::freeBytes()
|
||||
{
|
||||
return FFat.freeBytes();
|
||||
}
|
||||
size_t ESP_FileSystem::freeBytes() { return FFat.freeBytes(); }
|
||||
|
||||
size_t ESP_FileSystem::totalBytes()
|
||||
{
|
||||
return FFat.totalBytes();
|
||||
}
|
||||
size_t ESP_FileSystem::totalBytes() { return FFat.totalBytes(); }
|
||||
|
||||
size_t ESP_FileSystem::usedBytes()
|
||||
{
|
||||
size_t ESP_FileSystem::usedBytes() {
|
||||
return (FFat.totalBytes() - FFat.freeBytes());
|
||||
}
|
||||
|
||||
uint ESP_FileSystem::maxPathLength()
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
uint ESP_FileSystem::maxPathLength() { return 32; }
|
||||
|
||||
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
|
||||
{
|
||||
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath) {
|
||||
return FFat.rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
const char * ESP_FileSystem::FilesystemName()
|
||||
{
|
||||
return "FAT";
|
||||
}
|
||||
const char *ESP_FileSystem::FilesystemName() { return "FAT"; }
|
||||
|
||||
bool ESP_FileSystem::format()
|
||||
{
|
||||
bool ESP_FileSystem::format() {
|
||||
bool res = FFat.format();
|
||||
if (res) {
|
||||
res = begin();
|
||||
@ -78,33 +63,36 @@ bool ESP_FileSystem::format()
|
||||
return res;
|
||||
}
|
||||
|
||||
ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
|
||||
{
|
||||
ESP_File ESP_FileSystem::open(const char *path, uint8_t mode) {
|
||||
log_esp3d("open %s as %s", path, (mode == ESP_FILE_WRITE ? "write" : "read"));
|
||||
// do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
log_esp3d("reject %s", path);
|
||||
if (((strcmp(path, "/") == 0) &&
|
||||
((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) ||
|
||||
(strlen(path) == 0)) {
|
||||
log_esp3d_e("reject %s", path);
|
||||
return ESP_File();
|
||||
}
|
||||
// path must start by '/'
|
||||
if (path[0] != '/') {
|
||||
log_esp3d("%s is invalid path", path);
|
||||
log_esp3d_e("%s is invalid path", path);
|
||||
return ESP_File();
|
||||
}
|
||||
File tmp = FFat.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
|
||||
File tmp = FFat.open(path, (mode == ESP_FILE_READ) ? FILE_READ
|
||||
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
|
||||
: FILE_APPEND);
|
||||
if (tmp) {
|
||||
ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
ESP_File esptmp(&tmp, tmp.isDirectory(),
|
||||
(mode == ESP_FILE_READ) ? false : true, path);
|
||||
log_esp3d("%s is a %s", path, tmp.isDirectory() ? "Dir" : "File");
|
||||
log_esp3d("path is %s and filename path is %s", path, tmp.path());
|
||||
return esptmp;
|
||||
} else {
|
||||
log_esp3d("open %s failed", path);
|
||||
log_esp3d_e("open %s failed", path);
|
||||
return ESP_File();
|
||||
}
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::exists(const char* path)
|
||||
{
|
||||
bool ESP_FileSystem::exists(const char *path) {
|
||||
bool res = false;
|
||||
// root should always be there if started
|
||||
if (strcmp(path, "/") == 0) {
|
||||
@ -121,13 +109,9 @@ bool ESP_FileSystem::exists(const char* path)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::remove(const char *path)
|
||||
{
|
||||
return FFat.remove(path);
|
||||
}
|
||||
bool ESP_FileSystem::remove(const char *path) { return FFat.remove(path); }
|
||||
|
||||
bool ESP_FileSystem::mkdir(const char *path)
|
||||
{
|
||||
bool ESP_FileSystem::mkdir(const char *path) {
|
||||
String p = path;
|
||||
if (p[0] != '/') {
|
||||
p = "/" + p;
|
||||
@ -140,8 +124,7 @@ bool ESP_FileSystem::mkdir(const char *path)
|
||||
return FFat.mkdir(p);
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::rmdir(const char *path)
|
||||
{
|
||||
bool ESP_FileSystem::rmdir(const char *path) {
|
||||
String p = path;
|
||||
if (!p.startsWith("/")) {
|
||||
p = '/' + p;
|
||||
@ -192,16 +175,15 @@ bool ESP_FileSystem::rmdir(const char *path)
|
||||
return res;
|
||||
}
|
||||
|
||||
void ESP_FileSystem::closeAll()
|
||||
{
|
||||
void ESP_FileSystem::closeAll() {
|
||||
for (uint8_t i = 0; i < ESP_MAX_OPENHANDLE; i++) {
|
||||
tFile_handle[i].close();
|
||||
tFile_handle[i] = File();
|
||||
}
|
||||
}
|
||||
|
||||
ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path)
|
||||
{
|
||||
ESP_File::ESP_File(void *handle, bool isdir, bool iswritemode,
|
||||
const char *path) {
|
||||
_isdir = isdir;
|
||||
_dirlist = "";
|
||||
_isfakedir = false;
|
||||
@ -251,13 +233,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
|
||||
}
|
||||
}
|
||||
|
||||
bool ESP_File::seek(uint32_t pos, uint8_t mode)
|
||||
{
|
||||
bool ESP_File::seek(uint32_t pos, uint8_t mode) {
|
||||
return tFile_handle[_index].seek(pos, (SeekMode)mode);
|
||||
}
|
||||
|
||||
void ESP_File::close()
|
||||
{
|
||||
void ESP_File::close() {
|
||||
if (_index != -1) {
|
||||
log_esp3d("Closing File %s at index %d", _filename.c_str(), _index);
|
||||
log_esp3d("name: %s", _name.c_str());
|
||||
@ -279,15 +259,15 @@ void ESP_File::close()
|
||||
}
|
||||
}
|
||||
|
||||
ESP_File ESP_File::openNextFile()
|
||||
{
|
||||
ESP_File ESP_File::openNextFile() {
|
||||
if ((_index == -1) || !_isdir) {
|
||||
log_esp3d("openNextFile %d failed", _index);
|
||||
return ESP_File();
|
||||
}
|
||||
File tmp = tFile_handle[_index].openNextFile();
|
||||
while (tmp) {
|
||||
log_esp3d("tmp name :%s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile");
|
||||
log_esp3d("tmp name :%s %s", tmp.name(),
|
||||
(tmp.isDirectory()) ? "isDir" : "isFile");
|
||||
ESP_File esptmp(&tmp, tmp.isDirectory());
|
||||
esptmp.close();
|
||||
return esptmp;
|
||||
@ -295,5 +275,4 @@ ESP_File ESP_File::openNextFile()
|
||||
return ESP_File();
|
||||
}
|
||||
|
||||
|
||||
#endif // ESP_FAT_FILESYSTEM
|
||||
|
@ -17,60 +17,47 @@ littlefs_esp32_filesystem.cpp - ESP3D littlefs filesystem configuration class
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if (FILESYSTEM_FEATURE == ESP_LITTLEFS_FILESYSTEM) && defined(ARDUINO_ARCH_ESP32)
|
||||
#include "../esp_filesystem.h"
|
||||
#include <stack>
|
||||
#if (FILESYSTEM_FEATURE == ESP_LITTLEFS_FILESYSTEM) && \
|
||||
defined(ARDUINO_ARCH_ESP32)
|
||||
#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
#include <stack>
|
||||
|
||||
#include "../esp_filesystem.h"
|
||||
|
||||
extern File tFile_handle[ESP_MAX_OPENHANDLE];
|
||||
|
||||
bool ESP_FileSystem::begin()
|
||||
{
|
||||
bool ESP_FileSystem::begin() {
|
||||
_started = LittleFS.begin(true);
|
||||
return _started;
|
||||
}
|
||||
|
||||
void ESP_FileSystem::end()
|
||||
{
|
||||
void ESP_FileSystem::end() {
|
||||
LittleFS.end();
|
||||
_started = false;
|
||||
}
|
||||
|
||||
size_t ESP_FileSystem::freeBytes()
|
||||
{
|
||||
size_t ESP_FileSystem::freeBytes() {
|
||||
return (LittleFS.totalBytes() - LittleFS.usedBytes());
|
||||
}
|
||||
|
||||
size_t ESP_FileSystem::totalBytes()
|
||||
{
|
||||
return LittleFS.totalBytes();
|
||||
}
|
||||
size_t ESP_FileSystem::totalBytes() { return LittleFS.totalBytes(); }
|
||||
|
||||
size_t ESP_FileSystem::usedBytes()
|
||||
{
|
||||
return LittleFS.usedBytes();
|
||||
}
|
||||
size_t ESP_FileSystem::usedBytes() { return LittleFS.usedBytes(); }
|
||||
|
||||
uint ESP_FileSystem::maxPathLength()
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
uint ESP_FileSystem::maxPathLength() { return 32; }
|
||||
|
||||
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
|
||||
{
|
||||
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath) {
|
||||
log_esp3d("rename %s to %s", oldpath, newpath);
|
||||
return LittleFS.rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
const char * ESP_FileSystem::FilesystemName()
|
||||
{
|
||||
return "LittleFS";
|
||||
}
|
||||
const char *ESP_FileSystem::FilesystemName() { return "LittleFS"; }
|
||||
|
||||
bool ESP_FileSystem::format()
|
||||
{
|
||||
bool ESP_FileSystem::format() {
|
||||
bool res = LittleFS.format();
|
||||
if (res) {
|
||||
res = begin();
|
||||
@ -78,11 +65,12 @@ bool ESP_FileSystem::format()
|
||||
return res;
|
||||
}
|
||||
|
||||
ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
|
||||
{
|
||||
ESP_File ESP_FileSystem::open(const char *path, uint8_t mode) {
|
||||
log_esp3d("open %s", path);
|
||||
// do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
if (((strcmp(path, "/") == 0) &&
|
||||
((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) ||
|
||||
(strlen(path) == 0)) {
|
||||
log_esp3d("reject %s", path);
|
||||
return ESP_File();
|
||||
}
|
||||
@ -91,9 +79,12 @@ ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
|
||||
log_esp3d("%s is invalid path", path);
|
||||
return ESP_File();
|
||||
}
|
||||
File tmp = LittleFS.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
|
||||
File tmp = LittleFS.open(path, (mode == ESP_FILE_READ) ? FILE_READ
|
||||
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
|
||||
: FILE_APPEND);
|
||||
if (tmp) {
|
||||
ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
ESP_File esptmp(&tmp, tmp.isDirectory(),
|
||||
(mode == ESP_FILE_READ) ? false : true, path);
|
||||
log_esp3d("%s is a %s", path, tmp.isDirectory() ? "Dir" : "File");
|
||||
return esptmp;
|
||||
} else {
|
||||
@ -102,8 +93,7 @@ ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
|
||||
}
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::exists(const char* path)
|
||||
{
|
||||
bool ESP_FileSystem::exists(const char *path) {
|
||||
bool res = false;
|
||||
// root should always be there if started
|
||||
if (strcmp(path, "/") == 0) {
|
||||
@ -124,8 +114,7 @@ bool ESP_FileSystem::exists(const char* path)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::remove(const char *path)
|
||||
{
|
||||
bool ESP_FileSystem::remove(const char *path) {
|
||||
String p = path;
|
||||
if (p[0] != '/') {
|
||||
p = "/" + p;
|
||||
@ -133,8 +122,7 @@ bool ESP_FileSystem::remove(const char *path)
|
||||
return LittleFS.remove(p.c_str());
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::mkdir(const char *path)
|
||||
{
|
||||
bool ESP_FileSystem::mkdir(const char *path) {
|
||||
String p = path;
|
||||
if (p[0] != '/') {
|
||||
p = "/" + p;
|
||||
@ -147,8 +135,7 @@ bool ESP_FileSystem::mkdir(const char *path)
|
||||
return LittleFS.mkdir(p);
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::rmdir(const char *path)
|
||||
{
|
||||
bool ESP_FileSystem::rmdir(const char *path) {
|
||||
String p = path;
|
||||
if (!p.startsWith("/")) {
|
||||
p = '/' + p;
|
||||
@ -199,16 +186,15 @@ bool ESP_FileSystem::rmdir(const char *path)
|
||||
return res;
|
||||
}
|
||||
|
||||
void ESP_FileSystem::closeAll()
|
||||
{
|
||||
void ESP_FileSystem::closeAll() {
|
||||
for (uint8_t i = 0; i < ESP_MAX_OPENHANDLE; i++) {
|
||||
tFile_handle[i].close();
|
||||
tFile_handle[i] = File();
|
||||
}
|
||||
}
|
||||
|
||||
ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path)
|
||||
{
|
||||
ESP_File::ESP_File(void *handle, bool isdir, bool iswritemode,
|
||||
const char *path) {
|
||||
_isdir = isdir;
|
||||
_dirlist = "";
|
||||
_isfakedir = false;
|
||||
@ -258,7 +244,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
|
||||
}
|
||||
if (!set) {
|
||||
log_esp3d("No handle available");
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
for (uint8_t i = 0; (i < ESP_MAX_OPENHANDLE); i++) {
|
||||
log_esp3d("%s", tFile_handle[i].name());
|
||||
}
|
||||
@ -266,8 +252,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
|
||||
}
|
||||
}
|
||||
|
||||
void ESP_File::close()
|
||||
{
|
||||
void ESP_File::close() {
|
||||
if (_index != -1) {
|
||||
log_esp3d("Closing File at index %d", _index);
|
||||
tFile_handle[_index].close();
|
||||
@ -287,20 +272,19 @@ void ESP_File::close()
|
||||
_index = -1;
|
||||
}
|
||||
}
|
||||
bool ESP_File::seek(uint32_t pos, uint8_t mode)
|
||||
{
|
||||
bool ESP_File::seek(uint32_t pos, uint8_t mode) {
|
||||
return tFile_handle[_index].seek(pos, (SeekMode)mode);
|
||||
}
|
||||
|
||||
ESP_File ESP_File::openNextFile()
|
||||
{
|
||||
ESP_File ESP_File::openNextFile() {
|
||||
if ((_index == -1) || !_isdir) {
|
||||
log_esp3d("openNextFile %d failed", _index);
|
||||
return ESP_File();
|
||||
}
|
||||
File tmp = tFile_handle[_index].openNextFile();
|
||||
while (tmp) {
|
||||
log_esp3d("tmp name :%s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile");
|
||||
log_esp3d("tmp name :%s %s", tmp.name(),
|
||||
(tmp.isDirectory()) ? "isDir" : "isFile");
|
||||
ESP_File esptmp(&tmp, tmp.isDirectory());
|
||||
esptmp.close();
|
||||
return esptmp;
|
||||
@ -308,5 +292,4 @@ ESP_File ESP_File::openNextFile()
|
||||
return ESP_File();
|
||||
}
|
||||
|
||||
|
||||
#endif // ESP_LITTLEFS_FILESYSTEM
|
||||
|
@ -17,58 +17,42 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if (FILESYSTEM_FEATURE == ESP_SPIFFS_FILESYSTEM) && defined(ARDUINO_ARCH_ESP32)
|
||||
#include "../esp_filesystem.h"
|
||||
#include <stack>
|
||||
#include <FS.h>
|
||||
#include <SPIFFS.h>
|
||||
|
||||
#include <stack>
|
||||
|
||||
#include "../esp_filesystem.h"
|
||||
|
||||
extern File tFile_handle[ESP_MAX_OPENHANDLE];
|
||||
|
||||
bool ESP_FileSystem::begin()
|
||||
{
|
||||
bool ESP_FileSystem::begin() {
|
||||
_started = SPIFFS.begin(true);
|
||||
return _started;
|
||||
}
|
||||
void ESP_FileSystem::end()
|
||||
{
|
||||
void ESP_FileSystem::end() {
|
||||
_started = false;
|
||||
SPIFFS.end();
|
||||
}
|
||||
|
||||
size_t ESP_FileSystem::freeBytes()
|
||||
{
|
||||
return totalBytes() - usedBytes();
|
||||
}
|
||||
size_t ESP_FileSystem::freeBytes() { return totalBytes() - usedBytes(); }
|
||||
|
||||
size_t ESP_FileSystem::totalBytes()
|
||||
{
|
||||
return SPIFFS.totalBytes();
|
||||
}
|
||||
size_t ESP_FileSystem::totalBytes() { return SPIFFS.totalBytes(); }
|
||||
|
||||
size_t ESP_FileSystem::usedBytes()
|
||||
{
|
||||
return SPIFFS.usedBytes();
|
||||
}
|
||||
size_t ESP_FileSystem::usedBytes() { return SPIFFS.usedBytes(); }
|
||||
|
||||
uint ESP_FileSystem::maxPathLength()
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
uint ESP_FileSystem::maxPathLength() { return 32; }
|
||||
|
||||
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
|
||||
{
|
||||
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath) {
|
||||
return SPIFFS.rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
const char * ESP_FileSystem::FilesystemName()
|
||||
{
|
||||
return "SPIFFS";
|
||||
}
|
||||
const char *ESP_FileSystem::FilesystemName() { return "SPIFFS"; }
|
||||
|
||||
bool ESP_FileSystem::format()
|
||||
{
|
||||
bool ESP_FileSystem::format() {
|
||||
bool res = SPIFFS.format();
|
||||
if (res) {
|
||||
res = begin();
|
||||
@ -76,10 +60,11 @@ bool ESP_FileSystem::format()
|
||||
return res;
|
||||
}
|
||||
|
||||
ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
|
||||
{
|
||||
ESP_File ESP_FileSystem::open(const char *path, uint8_t mode) {
|
||||
// do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
if (((strcmp(path, "/") == 0) &&
|
||||
((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) ||
|
||||
(strlen(path) == 0)) {
|
||||
return ESP_File();
|
||||
}
|
||||
// path must start by '/'
|
||||
@ -87,9 +72,12 @@ ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
|
||||
return ESP_File();
|
||||
}
|
||||
// TODO add support if path = /DIR1/ <- with last /
|
||||
File tmp = SPIFFS.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
|
||||
File tmp = SPIFFS.open(path, (mode == ESP_FILE_READ) ? FILE_READ
|
||||
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
|
||||
: FILE_APPEND);
|
||||
if (tmp) {
|
||||
ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
ESP_File esptmp(&tmp, tmp.isDirectory(),
|
||||
(mode == ESP_FILE_READ) ? false : true, path);
|
||||
log_esp3d("%s is a %s", path, tmp.isDirectory() ? "Dir" : "File");
|
||||
return esptmp;
|
||||
} else {
|
||||
@ -98,8 +86,7 @@ ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
|
||||
}
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::exists(const char* path)
|
||||
{
|
||||
bool ESP_FileSystem::exists(const char *path) {
|
||||
bool res = false;
|
||||
// root should always be there if started
|
||||
if (strcmp(path, "/") == 0) {
|
||||
@ -137,8 +124,7 @@ bool ESP_FileSystem::exists(const char* path)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::remove(const char *path)
|
||||
{
|
||||
bool ESP_FileSystem::remove(const char *path) {
|
||||
String p = path;
|
||||
if (p[0] != '/') {
|
||||
p = "/" + p;
|
||||
@ -146,8 +132,7 @@ bool ESP_FileSystem::remove(const char *path)
|
||||
return SPIFFS.remove(p);
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::mkdir(const char *path)
|
||||
{
|
||||
bool ESP_FileSystem::mkdir(const char *path) {
|
||||
// Use file named . to simulate directory
|
||||
String p = path;
|
||||
if (p[p.length() - 1] != '/') {
|
||||
@ -164,8 +149,7 @@ bool ESP_FileSystem::mkdir(const char *path)
|
||||
}
|
||||
}
|
||||
|
||||
bool ESP_FileSystem::rmdir(const char *path)
|
||||
{
|
||||
bool ESP_FileSystem::rmdir(const char *path) {
|
||||
String spath = path;
|
||||
spath.trim();
|
||||
if (!spath.startsWith("/")) {
|
||||
@ -196,16 +180,15 @@ bool ESP_FileSystem::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
|
||||
void ESP_FileSystem::closeAll()
|
||||
{
|
||||
void ESP_FileSystem::closeAll() {
|
||||
for (uint8_t i = 0; i < ESP_MAX_OPENHANDLE; i++) {
|
||||
tFile_handle[i].close();
|
||||
tFile_handle[i] = File();
|
||||
}
|
||||
}
|
||||
|
||||
ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path)
|
||||
{
|
||||
ESP_File::ESP_File(void *handle, bool isdir, bool iswritemode,
|
||||
const char *path) {
|
||||
_isdir = isdir;
|
||||
_dirlist = "";
|
||||
_isfakedir = false;
|
||||
@ -269,13 +252,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
|
||||
}
|
||||
}
|
||||
|
||||
bool ESP_File::seek(uint32_t pos, uint8_t mode)
|
||||
{
|
||||
bool ESP_File::seek(uint32_t pos, uint8_t mode) {
|
||||
return tFile_handle[_index].seek(pos, (SeekMode)mode);
|
||||
}
|
||||
|
||||
void ESP_File::close()
|
||||
{
|
||||
void ESP_File::close() {
|
||||
if (_index != -1) {
|
||||
log_esp3d("Closing File at index %d", _index);
|
||||
tFile_handle[_index].close();
|
||||
@ -294,15 +275,15 @@ void ESP_File::close()
|
||||
}
|
||||
}
|
||||
|
||||
ESP_File ESP_File::openNextFile()
|
||||
{
|
||||
ESP_File ESP_File::openNextFile() {
|
||||
if ((_index == -1) || !_isdir) {
|
||||
log_esp3d("openNextFile failed");
|
||||
return ESP_File();
|
||||
}
|
||||
File tmp = tFile_handle[_index].openNextFile();
|
||||
while (tmp) {
|
||||
log_esp3d("tmp name :%s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile");
|
||||
log_esp3d("tmp name :%s %s", tmp.name(),
|
||||
(tmp.isDirectory()) ? "isDir" : "isFile");
|
||||
ESP_File esptmp(&tmp, tmp.isDirectory());
|
||||
esptmp.close();
|
||||
String sub = esptmp.filename();
|
||||
@ -311,13 +292,18 @@ ESP_File ESP_File::openNextFile()
|
||||
if (pos != -1) {
|
||||
// is subdir
|
||||
sub = sub.substring(0, pos);
|
||||
log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str());
|
||||
log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(),
|
||||
esptmp.name(), (esptmp.isDirectory()) ? "isDir" : "isFile",
|
||||
sub.c_str(), _filename.c_str());
|
||||
String tag = "*" + sub + "*";
|
||||
// test if already in directory list
|
||||
if (_dirlist.indexOf(tag) == -1) {//not in list so add it and return the info
|
||||
if (_dirlist.indexOf(tag) ==
|
||||
-1) { // not in list so add it and return the info
|
||||
_dirlist += tag;
|
||||
String fname = _filename.substring(0,_filename.length()-1) + sub + "/.";
|
||||
log_esp3d("Found dir # name: %s filename:%s", sub.c_str(), fname.c_str());
|
||||
String fname =
|
||||
_filename.substring(0, _filename.length() - 1) + sub + "/.";
|
||||
log_esp3d("Found dir # name: %s filename:%s", sub.c_str(),
|
||||
fname.c_str());
|
||||
if (sub == ".") {
|
||||
log_esp3d("Dir tag, ignore it");
|
||||
tmp = tFile_handle[_index].openNextFile();
|
||||
@ -330,12 +316,15 @@ ESP_File ESP_File::openNextFile()
|
||||
tmp = tFile_handle[_index].openNextFile();
|
||||
}
|
||||
} else { // is file
|
||||
log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str());
|
||||
log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(),
|
||||
esptmp.name(), (esptmp.isDirectory()) ? "isDir" : "isFile",
|
||||
sub.c_str(), _filename.c_str());
|
||||
if (sub == ".") {
|
||||
log_esp3d("Dir tag, ignore it");
|
||||
tmp = tFile_handle[_index].openNextFile();
|
||||
} else {
|
||||
log_esp3d("Found file # name: %s filename:%s", esptmp.filename(), esptmp.name());
|
||||
log_esp3d("Found file # name: %s filename:%s", esptmp.filename(),
|
||||
esptmp.name());
|
||||
return esptmp;
|
||||
}
|
||||
}
|
||||
@ -343,5 +332,4 @@ ESP_File ESP_File::openNextFile()
|
||||
return ESP_File();
|
||||
}
|
||||
|
||||
|
||||
#endif // ESP_SPIFFS_FILESYSTEM
|
||||
|
@ -150,6 +150,7 @@ uint64_t ESP_SD::freeBytes(bool refresh) {
|
||||
uint ESP_SD::maxPathLength() { return 255; }
|
||||
|
||||
bool ESP_SD::rename(const char *oldpath, const char *newpath) {
|
||||
log_esp3d("rename %s to %s", oldpath, newpath);
|
||||
return SD.rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
@ -177,7 +178,7 @@ ESP_SDFile ESP_SD::open(const char *path, uint8_t mode) {
|
||||
String p = path;
|
||||
p.remove(p.lastIndexOf('/') + 1);
|
||||
if (!exists(p.c_str())) {
|
||||
log_esp3d("Error opening: %s", path);
|
||||
log_esp3d_e("Error opening: %s", path);
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
|
@ -21,25 +21,27 @@ sd_native_esp8266.cpp - ESP3D sd support class
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && defined(SD_DEVICE)
|
||||
#if (SD_DEVICE == ESP_SD_NATIVE)
|
||||
#define FS_NO_GLOBALS
|
||||
#include "../esp_sd.h"
|
||||
#include <stack>
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include <SD.h>
|
||||
#include <SDFS.h>
|
||||
|
||||
#include <stack>
|
||||
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include "../esp_sd.h"
|
||||
|
||||
extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||
|
||||
void dateTime (uint16_t* date, uint16_t* dtime)
|
||||
{
|
||||
void dateTime(uint16_t* date, uint16_t* dtime) {
|
||||
struct tm tmstruct;
|
||||
time_t now;
|
||||
time(&now);
|
||||
localtime_r(&now, &tmstruct);
|
||||
*date = FAT_DATE ( (tmstruct.tm_year) + 1900, ( tmstruct.tm_mon) + 1, tmstruct.tm_mday);
|
||||
*date = FAT_DATE((tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1,
|
||||
tmstruct.tm_mday);
|
||||
*dtime = FAT_TIME(tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
|
||||
}
|
||||
|
||||
time_t getDateTimeFile(File & filehandle)
|
||||
{
|
||||
time_t getDateTimeFile(File& filehandle) {
|
||||
static time_t dt = 0;
|
||||
#ifdef SD_TIMESTAMP_FEATURE
|
||||
struct tm timefile;
|
||||
@ -55,10 +57,10 @@ time_t getDateTimeFile(File & filehandle)
|
||||
timefile.tm_isdst = -1;
|
||||
dt = mktime(&timefile);
|
||||
if (dt == -1) {
|
||||
log_esp3d("mktime failed");
|
||||
log_esp3d_e("mktime failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("stat file failed");
|
||||
log_esp3d_e("stat file failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("check file for stat failed");
|
||||
@ -67,12 +69,13 @@ time_t getDateTimeFile(File & filehandle)
|
||||
return dt;
|
||||
}
|
||||
|
||||
uint8_t ESP_SD::getState(bool refresh)
|
||||
{
|
||||
uint8_t ESP_SD::getState(bool refresh) {
|
||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||
// no need to go further if SD detect is not correct
|
||||
if (!((digitalRead (ESP_SD_DETECT_PIN) == ESP_SD_DETECT_VALUE) ? true : false)) {
|
||||
log_esp3d("No SD State %d vs %d", digitalRead (ESP_SD_DETECT_PIN), ESP_SD_DETECT_VALUE);
|
||||
if (!((digitalRead(ESP_SD_DETECT_PIN) == ESP_SD_DETECT_VALUE) ? true
|
||||
: false)) {
|
||||
log_esp3d("No SD State %d vs %d", digitalRead(ESP_SD_DETECT_PIN),
|
||||
ESP_SD_DETECT_VALUE);
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
return _state;
|
||||
} else {
|
||||
@ -93,23 +96,23 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
// SD is idle or not detected, let see if still the case
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
// refresh content if card was removed
|
||||
if (SD.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SD_SCK_HZ(F_CPU/_spi_speed_divider))) {
|
||||
if (SD.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN,
|
||||
SD_SCK_HZ(F_CPU / _spi_speed_divider))) {
|
||||
log_esp3d("Init SD State ok");
|
||||
if (SD.size64() > 0) {
|
||||
log_esp3d("SD available");
|
||||
_state = ESP_SDCARD_IDLE;
|
||||
} else {
|
||||
log_esp3d("Cannot get card size");
|
||||
log_esp3d_e("Cannot get card size");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("Init SD State failed");
|
||||
log_esp3d_e("Init SD State failed");
|
||||
}
|
||||
log_esp3d("SD State is %d", _state);
|
||||
return _state;
|
||||
}
|
||||
|
||||
bool ESP_SD::begin()
|
||||
{
|
||||
bool ESP_SD::begin() {
|
||||
_started = true;
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
_spi_speed_divider = Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV);
|
||||
@ -134,31 +137,28 @@ bool ESP_SD::begin()
|
||||
return _started;
|
||||
}
|
||||
|
||||
void ESP_SD::end()
|
||||
{
|
||||
void ESP_SD::end() {
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
_started = false;
|
||||
}
|
||||
|
||||
void ESP_SD::refreshStats(bool force)
|
||||
{
|
||||
void ESP_SD::refreshStats(bool force) {
|
||||
if (force || _sizechanged) {
|
||||
freeBytes(true);
|
||||
}
|
||||
_sizechanged = false;
|
||||
}
|
||||
|
||||
uint64_t ESP_SD::totalBytes(bool refresh)
|
||||
{
|
||||
uint64_t ESP_SD::totalBytes(bool refresh) {
|
||||
static uint64_t _totalBytes = 0;
|
||||
if (refresh || _totalBytes == 0) {
|
||||
_totalBytes = SD.size64();;
|
||||
_totalBytes = SD.size64();
|
||||
;
|
||||
}
|
||||
return _totalBytes;
|
||||
}
|
||||
|
||||
uint64_t ESP_SD::usedBytes(bool refresh)
|
||||
{
|
||||
uint64_t ESP_SD::usedBytes(bool refresh) {
|
||||
FSInfo64 info;
|
||||
static uint64_t _usedBytes = 0;
|
||||
if (refresh) {
|
||||
@ -170,34 +170,28 @@ uint64_t ESP_SD::usedBytes(bool refresh)
|
||||
return _usedBytes;
|
||||
}
|
||||
|
||||
uint64_t ESP_SD::freeBytes(bool refresh)
|
||||
{
|
||||
uint64_t ESP_SD::freeBytes(bool refresh) {
|
||||
return (totalBytes(refresh) - usedBytes(refresh));
|
||||
}
|
||||
|
||||
uint ESP_SD::maxPathLength()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
uint ESP_SD::maxPathLength() { return 255; }
|
||||
|
||||
bool ESP_SD::rename(const char *oldpath, const char *newpath)
|
||||
{
|
||||
bool ESP_SD::rename(const char* oldpath, const char* newpath) {
|
||||
return (bool)SDFS.rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
|
||||
bool ESP_SD::format(ESP3DOutput * output)
|
||||
{
|
||||
bool ESP_SD::format(ESP3DOutput* output) {
|
||||
if (output) {
|
||||
output->printERROR("Not implemented!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
{
|
||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) {
|
||||
// do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
if (((strcmp(path, "/") == 0) &&
|
||||
((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) ||
|
||||
(strlen(path) == 0)) {
|
||||
_sizechanged = true;
|
||||
return ESP_SDFile();
|
||||
}
|
||||
@ -214,13 +208,15 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
File tmp = SD.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_WRITE);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ
|
||||
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
|
||||
: FILE_WRITE);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),
|
||||
(mode == ESP_FILE_READ) ? false : true, path);
|
||||
return esptmp;
|
||||
}
|
||||
|
||||
bool ESP_SD::exists(const char* path)
|
||||
{
|
||||
bool ESP_SD::exists(const char* path) {
|
||||
bool res = false;
|
||||
// root should always be there if started
|
||||
if (strcmp(path, "/") == 0) {
|
||||
@ -239,19 +235,14 @@ bool ESP_SD::exists(const char* path)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ESP_SD::remove(const char *path)
|
||||
{
|
||||
bool ESP_SD::remove(const char* path) {
|
||||
_sizechanged = true;
|
||||
return SD.remove(path);
|
||||
}
|
||||
|
||||
bool ESP_SD::mkdir(const char *path)
|
||||
{
|
||||
return SD.mkdir(path);
|
||||
}
|
||||
bool ESP_SD::mkdir(const char* path) { return SD.mkdir(path); }
|
||||
|
||||
bool ESP_SD::rmdir(const char *path)
|
||||
{
|
||||
bool ESP_SD::rmdir(const char* path) {
|
||||
String p = path;
|
||||
if (!p.endsWith("/")) {
|
||||
p += '/';
|
||||
@ -301,21 +292,19 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode)
|
||||
{
|
||||
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode) {
|
||||
return tSDFile_handle[_index].seek(pos, (SeekMode)mode);
|
||||
}
|
||||
|
||||
void ESP_SD::closeAll()
|
||||
{
|
||||
void ESP_SD::closeAll() {
|
||||
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
|
||||
tSDFile_handle[i].close();
|
||||
tSDFile_handle[i] = File();
|
||||
}
|
||||
}
|
||||
|
||||
ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * path)
|
||||
{
|
||||
ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode,
|
||||
const char* path) {
|
||||
_isdir = isdir;
|
||||
_dirlist = "";
|
||||
_index = -1;
|
||||
@ -366,15 +355,12 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
||||
}
|
||||
}
|
||||
// todo need also to add short filename
|
||||
const char* ESP_SDFile::shortname() const
|
||||
{
|
||||
const char* ESP_SDFile::shortname() const {
|
||||
// not supported in native so return name
|
||||
return _name.c_str();
|
||||
|
||||
}
|
||||
|
||||
void ESP_SDFile::close()
|
||||
{
|
||||
void ESP_SDFile::close() {
|
||||
if (_index != -1) {
|
||||
// log_esp3d("Closing File at index %d", _index);
|
||||
tSDFile_handle[_index].close();
|
||||
@ -394,16 +380,16 @@ void ESP_SDFile::close()
|
||||
}
|
||||
}
|
||||
|
||||
ESP_SDFile ESP_SDFile::openNextFile()
|
||||
{
|
||||
ESP_SDFile ESP_SDFile::openNextFile() {
|
||||
if ((_index == -1) || !_isdir) {
|
||||
log_esp3d("openNextFile failed");
|
||||
log_esp3d_e("openNextFile failed");
|
||||
return ESP_SDFile();
|
||||
}
|
||||
File tmp = tSDFile_handle[_index].openNextFile();
|
||||
if (tmp) {
|
||||
String name = tmp.name();
|
||||
log_esp3d("tmp name :%s %s", name.c_str(), (tmp.isDirectory())?"isDir":"isFile");
|
||||
log_esp3d("tmp name :%s %s", name.c_str(),
|
||||
(tmp.isDirectory()) ? "isDir" : "isFile");
|
||||
String s = _filename;
|
||||
if (s != "/") {
|
||||
s += "/";
|
||||
@ -416,10 +402,7 @@ ESP_SDFile ESP_SDFile::openNextFile()
|
||||
return ESP_SDFile();
|
||||
}
|
||||
|
||||
const char * ESP_SD::FilesystemName()
|
||||
{
|
||||
return "SD native";
|
||||
}
|
||||
const char* ESP_SD::FilesystemName() { return "SD native"; }
|
||||
|
||||
#endif // SD_DEVICE == ESP_SD_NATIVE
|
||||
#endif // ARCH_ESP8266 && SD_DEVICE
|
||||
|
@ -89,13 +89,13 @@ time_t getDateTimeFile(File& filehandle) {
|
||||
timefile.tm_isdst = -1;
|
||||
dt = mktime(&timefile);
|
||||
if (dt == -1) {
|
||||
log_esp3d("mktime failed");
|
||||
log_esp3d_e("mktime failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("stat file failed");
|
||||
log_esp3d_e("stat file failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("check file for stat failed");
|
||||
log_esp3d_e("check file for stat failed");
|
||||
}
|
||||
#endif // SD_TIMESTAMP_FEATURE
|
||||
return dt;
|
||||
@ -319,12 +319,12 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) {
|
||||
((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) ||
|
||||
(strlen(path) == 0)) {
|
||||
_sizechanged = true;
|
||||
log_esp3d("reject %s", path);
|
||||
log_esp3d_e("reject %s", path);
|
||||
return ESP_SDFile();
|
||||
}
|
||||
// path must start by '/'
|
||||
if (path[0] != '/') {
|
||||
log_esp3d("%s is invalid path", path);
|
||||
log_esp3d_e("%s is invalid path", path);
|
||||
return ESP_SDFile();
|
||||
}
|
||||
if (mode != ESP_FILE_READ) {
|
||||
@ -332,7 +332,7 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) {
|
||||
String p = path;
|
||||
p.remove(p.lastIndexOf('/') + 1);
|
||||
if (!exists(p.c_str())) {
|
||||
log_esp3d("Error opening: %s", path);
|
||||
log_esp3d_e("Error opening: %s", path);
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
@ -345,7 +345,7 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) {
|
||||
log_esp3d("%s is a %s", path, tmp.isDir() ? "Dir" : "File");
|
||||
return esptmp;
|
||||
} else {
|
||||
log_esp3d("open %s failed", path);
|
||||
log_esp3d_e("open %s failed", path);
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
|
@ -17,14 +17,16 @@ sd_sdfat2_esp8266.cpp - ESP3D sd support class
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && defined(SD_DEVICE)
|
||||
#if (SD_DEVICE == ESP_SDFAT2)
|
||||
#define FS_NO_GLOBALS
|
||||
#include "../esp_sd.h"
|
||||
#include <stack>
|
||||
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include "../esp_sd.h"
|
||||
|
||||
#define NO_GLOBAL_SD
|
||||
#include <SdFat.h>
|
||||
#include <sdios.h>
|
||||
@ -33,27 +35,28 @@ sd_sdfat2_esp8266.cpp - ESP3D sd support class
|
||||
#if HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdioConfig(FIFO_SDIO)
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#define SD_CONFIG SdSpiConfig((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, DEDICATED_SPI)
|
||||
#define SD_CONFIG \
|
||||
SdSpiConfig((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, DEDICATED_SPI)
|
||||
#else // HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdSpiConfig((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SHARED_SPI)
|
||||
#define SD_CONFIG \
|
||||
SdSpiConfig((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SHARED_SPI)
|
||||
#endif // HAS_SDIO_CLASS
|
||||
|
||||
extern sdfat::File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||
using namespace sdfat;
|
||||
SdFat SD;
|
||||
|
||||
void dateTime (uint16_t* date, uint16_t* dtime)
|
||||
{
|
||||
void dateTime(uint16_t* date, uint16_t* dtime) {
|
||||
struct tm tmstruct;
|
||||
time_t now;
|
||||
time(&now);
|
||||
localtime_r(&now, &tmstruct);
|
||||
*date = FAT_DATE ( (tmstruct.tm_year) + 1900, ( tmstruct.tm_mon) + 1, tmstruct.tm_mday);
|
||||
*date = FAT_DATE((tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1,
|
||||
tmstruct.tm_mday);
|
||||
*dtime = FAT_TIME(tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
|
||||
}
|
||||
|
||||
time_t getDateTimeFile(sdfat::File & filehandle)
|
||||
{
|
||||
time_t getDateTimeFile(sdfat::File& filehandle) {
|
||||
static time_t dt = 0;
|
||||
#ifdef SD_TIMESTAMP_FEATURE
|
||||
struct tm timefile;
|
||||
@ -70,24 +73,25 @@ time_t getDateTimeFile(sdfat::File & filehandle)
|
||||
timefile.tm_isdst = -1;
|
||||
dt = mktime(&timefile);
|
||||
if (dt == -1) {
|
||||
log_esp3d("mktime failed");
|
||||
log_esp3d_e("mktime failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("stat file failed");
|
||||
log_esp3d_e("stat file failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("check file for stat failed");
|
||||
log_esp3d_e("check file for stat failed");
|
||||
}
|
||||
#endif // SD_TIMESTAMP_FEATURE
|
||||
return dt;
|
||||
}
|
||||
|
||||
uint8_t ESP_SD::getState(bool refresh)
|
||||
{
|
||||
uint8_t ESP_SD::getState(bool refresh) {
|
||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||
// no need to go further if SD detect is not correct
|
||||
if (!((digitalRead (ESP_SD_DETECT_PIN) == ESP_SD_DETECT_VALUE) ? true : false)) {
|
||||
log_esp3d("No SD State %d vs %d", digitalRead (ESP_SD_DETECT_PIN), ESP_SD_DETECT_VALUE);
|
||||
if (!((digitalRead(ESP_SD_DETECT_PIN) == ESP_SD_DETECT_VALUE) ? true
|
||||
: false)) {
|
||||
log_esp3d("No SD State %d vs %d", digitalRead(ESP_SD_DETECT_PIN),
|
||||
ESP_SD_DETECT_VALUE);
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
return _state;
|
||||
} else {
|
||||
@ -108,23 +112,23 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
// SD is idle or not detected, let see if still the case
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
// refresh content if card was removed
|
||||
if (SD.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SD_SCK_HZ(F_CPU/_spi_speed_divider))) {
|
||||
if (SD.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN,
|
||||
SD_SCK_HZ(F_CPU / _spi_speed_divider))) {
|
||||
log_esp3d("Init SD State ok");
|
||||
csd_t m_csd;
|
||||
if (SD.card()->readCSD(&m_csd) && sdCardCapacity(&m_csd) > 0) {
|
||||
_state = ESP_SDCARD_IDLE;
|
||||
} else {
|
||||
log_esp3d("Cannot get card size");
|
||||
log_esp3d_e("Cannot get card size");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("Init SD State failed");
|
||||
log_esp3d_e("Init SD State failed");
|
||||
}
|
||||
log_esp3d("SD State is %d", _state);
|
||||
return _state;
|
||||
}
|
||||
|
||||
bool ESP_SD::begin()
|
||||
{
|
||||
bool ESP_SD::begin() {
|
||||
_started = true;
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
_spi_speed_divider = Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV);
|
||||
@ -149,22 +153,19 @@ bool ESP_SD::begin()
|
||||
return _started;
|
||||
}
|
||||
|
||||
void ESP_SD::end()
|
||||
{
|
||||
void ESP_SD::end() {
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
_started = false;
|
||||
}
|
||||
|
||||
void ESP_SD::refreshStats(bool force)
|
||||
{
|
||||
void ESP_SD::refreshStats(bool force) {
|
||||
if (force || _sizechanged) {
|
||||
usedBytes(true);
|
||||
}
|
||||
_sizechanged = false;
|
||||
}
|
||||
|
||||
uint64_t ESP_SD::totalBytes(bool refresh)
|
||||
{
|
||||
uint64_t ESP_SD::totalBytes(bool refresh) {
|
||||
static uint64_t _totalBytes = 0;
|
||||
if (!SD.volumeBegin()) {
|
||||
return 0;
|
||||
@ -177,19 +178,16 @@ uint64_t ESP_SD::totalBytes(bool refresh)
|
||||
return _totalBytes;
|
||||
}
|
||||
|
||||
uint64_t ESP_SD::usedBytes(bool refresh)
|
||||
{
|
||||
uint64_t ESP_SD::usedBytes(bool refresh) {
|
||||
return totalBytes(refresh) - freeBytes(refresh);
|
||||
}
|
||||
|
||||
uint64_t ESP_SD::freeBytes(bool refresh)
|
||||
{
|
||||
uint64_t ESP_SD::freeBytes(bool refresh) {
|
||||
static uint64_t _freeBytes = 0;
|
||||
if (!SD.volumeBegin()) {
|
||||
return 0;
|
||||
}
|
||||
if (refresh || _freeBytes == 0) {
|
||||
|
||||
_freeBytes = SD.freeClusterCount();
|
||||
uint8_t sectors = SD.sectorsPerCluster();
|
||||
_freeBytes = _freeBytes * sectors * 512;
|
||||
@ -197,18 +195,13 @@ uint64_t ESP_SD::freeBytes(bool refresh)
|
||||
return _freeBytes;
|
||||
}
|
||||
|
||||
uint ESP_SD::maxPathLength()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
uint ESP_SD::maxPathLength() { return 255; }
|
||||
|
||||
bool ESP_SD::rename(const char *oldpath, const char *newpath)
|
||||
{
|
||||
bool ESP_SD::rename(const char* oldpath, const char* newpath) {
|
||||
return SD.rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
bool ESP_SD::format(ESP3DOutput * output)
|
||||
{
|
||||
bool ESP_SD::format(ESP3DOutput* output) {
|
||||
if (ESP_SD::getState(true) == ESP_SDCARD_IDLE) {
|
||||
uint32_t const ERASE_SIZE = 262144L;
|
||||
uint32_t cardSectorCount = 0;
|
||||
@ -235,7 +228,8 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
}
|
||||
|
||||
if (output) {
|
||||
String s = "Capacity detected :" + String(cardSectorCount*5.12e-7) + "GB";
|
||||
String s =
|
||||
"Capacity detected :" + String(cardSectorCount * 5.12e-7) + "GB";
|
||||
output->printMSG(s.c_str());
|
||||
}
|
||||
|
||||
@ -270,9 +264,9 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
FatFormatter fatFormatter;
|
||||
|
||||
// Format exFAT if larger than 32GB.
|
||||
bool rtn = cardSectorCount > 67108864 ?
|
||||
exFatFormatter.format(m_card, sectorBuffer, nullptr) :
|
||||
fatFormatter.format(m_card, sectorBuffer, nullptr);
|
||||
bool rtn = cardSectorCount > 67108864
|
||||
? exFatFormatter.format(m_card, sectorBuffer, nullptr)
|
||||
: fatFormatter.format(m_card, sectorBuffer, nullptr);
|
||||
|
||||
if (!rtn) {
|
||||
if (output) {
|
||||
@ -289,10 +283,11 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
{
|
||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) {
|
||||
// do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
if (((strcmp(path, "/") == 0) &&
|
||||
((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) ||
|
||||
(strlen(path) == 0)) {
|
||||
_sizechanged = true;
|
||||
return ESP_SDFile();
|
||||
}
|
||||
@ -309,13 +304,15 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
sdfat::File tmp = SD.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_WRITE);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDir(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
sdfat::File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ
|
||||
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
|
||||
: FILE_WRITE);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDir(), (mode == ESP_FILE_READ) ? false : true,
|
||||
path);
|
||||
return esptmp;
|
||||
}
|
||||
|
||||
bool ESP_SD::exists(const char* path)
|
||||
{
|
||||
bool ESP_SD::exists(const char* path) {
|
||||
bool res = false;
|
||||
// root should always be there if started
|
||||
if (strcmp(path, "/") == 0) {
|
||||
@ -334,19 +331,14 @@ bool ESP_SD::exists(const char* path)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ESP_SD::remove(const char *path)
|
||||
{
|
||||
bool ESP_SD::remove(const char* path) {
|
||||
_sizechanged = true;
|
||||
return SD.remove(path);
|
||||
}
|
||||
|
||||
bool ESP_SD::mkdir(const char *path)
|
||||
{
|
||||
return SD.mkdir(path);
|
||||
}
|
||||
bool ESP_SD::mkdir(const char* path) { return SD.mkdir(path); }
|
||||
|
||||
bool ESP_SD::rmdir(const char *path)
|
||||
{
|
||||
bool ESP_SD::rmdir(const char* path) {
|
||||
String p = path;
|
||||
if (!p.endsWith("/")) {
|
||||
p += '/';
|
||||
@ -401,8 +393,7 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode)
|
||||
{
|
||||
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode) {
|
||||
if (mode == SeekCur) {
|
||||
return tSDFile_handle[_index].seekCur(pos);
|
||||
}
|
||||
@ -413,16 +404,15 @@ bool ESP_SDFile::seek(uint32_t pos, uint8_t mode)
|
||||
return tSDFile_handle[_index].seekSet(pos);
|
||||
}
|
||||
|
||||
void ESP_SD::closeAll()
|
||||
{
|
||||
void ESP_SD::closeAll() {
|
||||
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
|
||||
tSDFile_handle[i].close();
|
||||
tSDFile_handle[i] = sdfat::File();
|
||||
}
|
||||
}
|
||||
|
||||
ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * path)
|
||||
{
|
||||
ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode,
|
||||
const char* path) {
|
||||
_isdir = isdir;
|
||||
_dirlist = "";
|
||||
_index = -1;
|
||||
@ -475,8 +465,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
||||
}
|
||||
}
|
||||
// todo need also to add short filename
|
||||
const char* ESP_SDFile::shortname() const
|
||||
{
|
||||
const char* ESP_SDFile::shortname() const {
|
||||
static char sname[13];
|
||||
sdfat::File ftmp = SD.open(_filename.c_str());
|
||||
if (ftmp) {
|
||||
@ -488,8 +477,7 @@ const char* ESP_SDFile::shortname() const
|
||||
}
|
||||
}
|
||||
|
||||
void ESP_SDFile::close()
|
||||
{
|
||||
void ESP_SDFile::close() {
|
||||
if (_index != -1) {
|
||||
// log_esp3d("Closing File at index %d", _index);
|
||||
tSDFile_handle[_index].close();
|
||||
@ -509,8 +497,7 @@ void ESP_SDFile::close()
|
||||
}
|
||||
}
|
||||
|
||||
ESP_SDFile ESP_SDFile::openNextFile()
|
||||
{
|
||||
ESP_SDFile ESP_SDFile::openNextFile() {
|
||||
if ((_index == -1) || !_isdir) {
|
||||
log_esp3d("openNextFile failed");
|
||||
return ESP_SDFile();
|
||||
@ -532,10 +519,7 @@ ESP_SDFile ESP_SDFile::openNextFile()
|
||||
return ESP_SDFile();
|
||||
}
|
||||
|
||||
const char * ESP_SD::FilesystemName()
|
||||
{
|
||||
return "SDFat - " SD_FAT_VERSION_STR ;
|
||||
}
|
||||
const char* ESP_SD::FilesystemName() { return "SDFat - " SD_FAT_VERSION_STR; }
|
||||
|
||||
#endif // SD_DEVICE == ESP_SDFAT2
|
||||
#endif // ARCH_ESP8266 && SD_DEVICE
|
||||
|
@ -20,13 +20,13 @@ sdio_esp32.cpp - ESP3D sd support class
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(SD_DEVICE)
|
||||
#if (SD_DEVICE == ESP_SDIO)
|
||||
#include "../esp_sd.h"
|
||||
#include <stack>
|
||||
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include "../esp_sd.h"
|
||||
#include "FS.h"
|
||||
#include "SD_MMC.h"
|
||||
|
||||
|
||||
extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||
|
||||
#define SDMMC_FORCE_BEGIN
|
||||
@ -35,15 +35,15 @@ extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||
#define SDIO_BIT_MODE SD_FOUR_BIT_MODE
|
||||
#endif // SDIO_BIT_MODE
|
||||
|
||||
uint8_t ESP_SD::getState(bool refresh)
|
||||
{
|
||||
uint8_t ESP_SD::getState(bool refresh) {
|
||||
static bool lastinitok = false;
|
||||
#ifdef SDMMC_FORCE_BEGIN
|
||||
lastinitok = false;
|
||||
#endif // SDMMC_LIGHT_CHECK
|
||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||
// no need to go further if SD detect is not correct
|
||||
if (!((digitalRead (ESP_SD_DETECT_PIN) == ESP_SD_DETECT_VALUE) ? true : false)) {
|
||||
if (!((digitalRead(ESP_SD_DETECT_PIN) == ESP_SD_DETECT_VALUE) ? true
|
||||
: false)) {
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
return _state;
|
||||
}
|
||||
@ -68,10 +68,10 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
lastinitok = true;
|
||||
log_esp3d("sd_mmc card type succeed");
|
||||
} else {
|
||||
log_esp3d("sd_mmc card type failed");
|
||||
log_esp3d_e("sd_mmc card type failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("sd_mmc begin failed");
|
||||
log_esp3d_e("sd_mmc begin failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("last init was ok try card type");
|
||||
@ -80,7 +80,7 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
_state = ESP_SDCARD_IDLE;
|
||||
} else {
|
||||
lastinitok = false;
|
||||
log_esp3d("Soft sd check failed");
|
||||
log_esp3d_e("Soft sd check failed");
|
||||
SD_MMC.end();
|
||||
if (SD_MMC.begin("/sdcard", SDIO_BIT_MODE)) {
|
||||
log_esp3d("new sd_mmc begin succeed");
|
||||
@ -89,7 +89,7 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
lastinitok = true;
|
||||
log_esp3d("new sd_mmc card type succeed");
|
||||
} else {
|
||||
log_esp3d("new sd_mmc card type failed");
|
||||
log_esp3d_e("new sd_mmc card type failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("new sd_mmc begin failed");
|
||||
@ -99,10 +99,12 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
return _state;
|
||||
}
|
||||
|
||||
bool ESP_SD::begin()
|
||||
{
|
||||
#if (ESP_SDIO_CLK_PIN != -1) || (ESP_SDIO_CMD_PIN != -1) || (ESP_SDIO_D0_PIN != -1) || (ESP_SDIO_D1_PIN != -1) || (ESP_SDIO_D2_PIN != -1) || (ESP_SDIO_D3_PIN != -1)
|
||||
SD_MMC.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN, ESP_SDIO_D1_PIN, ESP_SDIO_D2_PIN, ESP_SDIO_D3_PIN)
|
||||
bool ESP_SD::begin() {
|
||||
#if (ESP_SDIO_CLK_PIN != -1) || (ESP_SDIO_CMD_PIN != -1) || \
|
||||
(ESP_SDIO_D0_PIN != -1) || (ESP_SDIO_D1_PIN != -1) || \
|
||||
(ESP_SDIO_D2_PIN != -1) || (ESP_SDIO_D3_PIN != -1)
|
||||
SD_MMC.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN,
|
||||
ESP_SDIO_D1_PIN, ESP_SDIO_D2_PIN, ESP_SDIO_D3_PIN)
|
||||
#endif //(ESP_SDIO_CLK_PIN != -1)
|
||||
log_esp3d("Begin SDIO");
|
||||
_started = true;
|
||||
@ -115,32 +117,29 @@ bool ESP_SD::begin()
|
||||
return _started;
|
||||
}
|
||||
|
||||
void ESP_SD::end()
|
||||
{
|
||||
void ESP_SD::end() {
|
||||
SD_MMC.end();
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
_started = false;
|
||||
}
|
||||
|
||||
void ESP_SD::refreshStats(bool force)
|
||||
{
|
||||
void ESP_SD::refreshStats(bool force) {
|
||||
if (force || _sizechanged) {
|
||||
freeBytes(true);
|
||||
}
|
||||
_sizechanged = false;
|
||||
}
|
||||
|
||||
uint64_t ESP_SD::totalBytes(bool refresh)
|
||||
{
|
||||
uint64_t ESP_SD::totalBytes(bool refresh) {
|
||||
static uint64_t _totalBytes = 0;
|
||||
if (refresh || _totalBytes == 0) {
|
||||
_totalBytes = SD_MMC.totalBytes();;
|
||||
_totalBytes = SD_MMC.totalBytes();
|
||||
;
|
||||
}
|
||||
return _totalBytes;
|
||||
}
|
||||
|
||||
uint64_t ESP_SD::usedBytes(bool refresh)
|
||||
{
|
||||
uint64_t ESP_SD::usedBytes(bool refresh) {
|
||||
static uint64_t _usedBytes = 0;
|
||||
if (refresh || _usedBytes == 0) {
|
||||
_usedBytes = SD_MMC.usedBytes();
|
||||
@ -148,23 +147,17 @@ uint64_t ESP_SD::usedBytes(bool refresh)
|
||||
return _usedBytes;
|
||||
}
|
||||
|
||||
uint64_t ESP_SD::freeBytes(bool refresh)
|
||||
{
|
||||
uint64_t ESP_SD::freeBytes(bool refresh) {
|
||||
return (totalBytes(refresh) - usedBytes(refresh));
|
||||
}
|
||||
|
||||
uint ESP_SD::maxPathLength()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
uint ESP_SD::maxPathLength() { return 255; }
|
||||
|
||||
bool ESP_SD::rename(const char *oldpath, const char *newpath)
|
||||
{
|
||||
bool ESP_SD::rename(const char *oldpath, const char *newpath) {
|
||||
return SD_MMC.rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
bool ESP_SD::format(ESP3DOutput * output)
|
||||
{
|
||||
bool ESP_SD::format(ESP3DOutput *output) {
|
||||
// not available yet
|
||||
if (output) {
|
||||
output->printERROR("Not implemented!");
|
||||
@ -172,16 +165,17 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
{
|
||||
ESP_SDFile ESP_SD::open(const char *path, uint8_t mode) {
|
||||
// do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
log_esp3d("File open check : failed");
|
||||
if (((strcmp(path, "/") == 0) &&
|
||||
((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) ||
|
||||
(strlen(path) == 0)) {
|
||||
log_esp3d_e("File open check : failed");
|
||||
return ESP_SDFile();
|
||||
}
|
||||
// path must start by '/'
|
||||
if (path[0] != '/') {
|
||||
log_esp3d("File open path is invalid");
|
||||
log_esp3d_e("File open path is invalid");
|
||||
return ESP_SDFile();
|
||||
}
|
||||
if (mode != ESP_FILE_READ) {
|
||||
@ -189,17 +183,19 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
String p = path;
|
||||
p.remove(p.lastIndexOf('/') + 1);
|
||||
if (!exists(p.c_str())) {
|
||||
log_esp3d("Error opening: %s, %s does not exists", path,p.c_str());
|
||||
log_esp3d_e("Error opening: %s, %s does not exists", path, p.c_str());
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
File tmp = SD_MMC.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
File tmp = SD_MMC.open(path, (mode == ESP_FILE_READ) ? FILE_READ
|
||||
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
|
||||
: FILE_APPEND);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),
|
||||
(mode == ESP_FILE_READ) ? false : true, path);
|
||||
return esptmp;
|
||||
}
|
||||
|
||||
bool ESP_SD::exists(const char* path)
|
||||
{
|
||||
bool ESP_SD::exists(const char *path) {
|
||||
bool res = false;
|
||||
String p = path;
|
||||
// root should always be there if started
|
||||
@ -220,13 +216,9 @@ bool ESP_SD::exists(const char* path)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ESP_SD::remove(const char *path)
|
||||
{
|
||||
return SD_MMC.remove(path);
|
||||
}
|
||||
bool ESP_SD::remove(const char *path) { return SD_MMC.remove(path); }
|
||||
|
||||
bool ESP_SD::mkdir(const char *path)
|
||||
{
|
||||
bool ESP_SD::mkdir(const char *path) {
|
||||
String p = path;
|
||||
if (p.endsWith("/")) {
|
||||
p.remove(p.length() - 1, 1);
|
||||
@ -234,8 +226,7 @@ bool ESP_SD::mkdir(const char *path)
|
||||
return SD_MMC.mkdir(p.c_str());
|
||||
}
|
||||
|
||||
bool ESP_SD::rmdir(const char *path)
|
||||
{
|
||||
bool ESP_SD::rmdir(const char *path) {
|
||||
if (!exists(path)) {
|
||||
return false;
|
||||
}
|
||||
@ -281,16 +272,15 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return res;
|
||||
}
|
||||
|
||||
void ESP_SD::closeAll()
|
||||
{
|
||||
void ESP_SD::closeAll() {
|
||||
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
|
||||
tSDFile_handle[i].close();
|
||||
tSDFile_handle[i] = File();
|
||||
}
|
||||
}
|
||||
|
||||
ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * path)
|
||||
{
|
||||
ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode,
|
||||
const char *path) {
|
||||
_isdir = isdir;
|
||||
_dirlist = "";
|
||||
_index = -1;
|
||||
@ -334,13 +324,11 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
||||
}
|
||||
}
|
||||
|
||||
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode)
|
||||
{
|
||||
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode) {
|
||||
return tSDFile_handle[_index].seek(pos, (SeekMode)mode);
|
||||
}
|
||||
|
||||
void ESP_SDFile::close()
|
||||
{
|
||||
void ESP_SDFile::close() {
|
||||
if (_index != -1) {
|
||||
// log_esp3d("Closing File at index %d", _index);
|
||||
tSDFile_handle[_index].close();
|
||||
@ -360,15 +348,15 @@ void ESP_SDFile::close()
|
||||
}
|
||||
}
|
||||
|
||||
ESP_SDFile ESP_SDFile::openNextFile()
|
||||
{
|
||||
ESP_SDFile ESP_SDFile::openNextFile() {
|
||||
if ((_index == -1) || !_isdir) {
|
||||
log_esp3d("openNextFile failed");
|
||||
return ESP_SDFile();
|
||||
}
|
||||
File tmp = tSDFile_handle[_index].openNextFile();
|
||||
if (tmp) {
|
||||
log_esp3d("tmp name :%s %s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile", _filename.c_str());
|
||||
log_esp3d("tmp name :%s %s %s", tmp.name(),
|
||||
(tmp.isDirectory()) ? "isDir" : "isFile", _filename.c_str());
|
||||
String s = tmp.name();
|
||||
// if (s!="/")s+="/";
|
||||
// s += tmp.name();
|
||||
@ -380,14 +368,8 @@ ESP_SDFile ESP_SDFile::openNextFile()
|
||||
}
|
||||
|
||||
// TODO need to find reliable way
|
||||
const char* ESP_SDFile::shortname() const
|
||||
{
|
||||
return _name.c_str();
|
||||
}
|
||||
const char *ESP_SDFile::shortname() const { return _name.c_str(); }
|
||||
|
||||
const char * ESP_SD::FilesystemName()
|
||||
{
|
||||
return "SDIO";
|
||||
}
|
||||
const char *ESP_SD::FilesystemName() { return "SDIO"; }
|
||||
#endif // SD_DEVICE == ESP_SDIO
|
||||
#endif // ARCH_ESP32 && SD_DEVICE
|
||||
|
@ -65,17 +65,19 @@
|
||||
* 2019-10-27 Modified version for ESP3D by Luc LEBOSSE @luc-github
|
||||
* support for ESP8266 and ESP32 in ESP3D project
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined(FTP_FEATURE)
|
||||
#include <WiFiServer.h>
|
||||
#include <WiFiClient.h>
|
||||
#include "FtpServer.h"
|
||||
#include "ExtStreaming.h"
|
||||
#include "../network/netconfig.h"
|
||||
#include "../authentication/authentication_service.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include <WiFiServer.h>
|
||||
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../authentication/authentication_service.h"
|
||||
#include "../network/netconfig.h"
|
||||
#include "ExtStreaming.h"
|
||||
#include "FtpServer.h"
|
||||
|
||||
#if FTP_FEATURE == FS_ROOT
|
||||
#include "../filesystem/esp_globalFS.h"
|
||||
typedef ESP_GBFile FTPFile;
|
||||
@ -105,28 +107,19 @@ FTPFile file;
|
||||
|
||||
FtpServer ftp_server;
|
||||
|
||||
bool legalChar( char c )
|
||||
{
|
||||
if( c == '"' || c == '*' || c == '?' || c == ':' ||
|
||||
c == '<' || c == '>' || c == '|' ) {
|
||||
bool legalChar(char c) {
|
||||
if (c == '"' || c == '*' || c == '?' || c == ':' || c == '<' || c == '>' ||
|
||||
c == '|') {
|
||||
return false;
|
||||
}
|
||||
return 0x1f < c && c < 0x7f;
|
||||
}
|
||||
|
||||
void FtpServer::closeClient() { client.stop(); }
|
||||
|
||||
void FtpServer::closeClient()
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
bool FtpServer::isConnected() { return client.connected(); }
|
||||
|
||||
bool FtpServer::isConnected()
|
||||
{
|
||||
return client.connected();
|
||||
}
|
||||
|
||||
FtpServer::FtpServer()
|
||||
{
|
||||
FtpServer::FtpServer() {
|
||||
ftpServer = nullptr;
|
||||
dataServer = nullptr;
|
||||
ctrlPort = 0;
|
||||
@ -135,13 +128,9 @@ FtpServer::FtpServer()
|
||||
_root = FS_ROOT;
|
||||
}
|
||||
|
||||
FtpServer::~FtpServer()
|
||||
{
|
||||
end();
|
||||
}
|
||||
FtpServer::~FtpServer() { end(); }
|
||||
|
||||
void FtpServer::end()
|
||||
{
|
||||
void FtpServer::end() {
|
||||
if (ftpServer) {
|
||||
delete (ftpServer);
|
||||
ftpServer = nullptr;
|
||||
@ -157,8 +146,7 @@ void FtpServer::end()
|
||||
_root = FS_ROOT;
|
||||
}
|
||||
|
||||
const char* FtpServer::clientIPAddress()
|
||||
{
|
||||
const char* FtpServer::clientIPAddress() {
|
||||
static String res;
|
||||
res = "0.0.0.0";
|
||||
if (client && client.connected()) {
|
||||
@ -167,13 +155,9 @@ const char* FtpServer::clientIPAddress()
|
||||
return res.c_str();
|
||||
}
|
||||
|
||||
bool FtpServer::started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
bool FtpServer::started() { return _started; }
|
||||
|
||||
bool FtpServer::begin()
|
||||
{
|
||||
bool FtpServer::begin() {
|
||||
end();
|
||||
if (Settings_ESP3D::read_byte(ESP_FTP_ON) != 1) {
|
||||
return true;
|
||||
@ -201,17 +185,16 @@ bool FtpServer::begin()
|
||||
return _started;
|
||||
}
|
||||
|
||||
bool FtpServer::accessFS(const char* path)
|
||||
{
|
||||
bool FtpServer::accessFS(const char* path) {
|
||||
if (_fsType != FS_UNKNOWN) {
|
||||
log_esp3d("FTP: accessFS: already accessed");
|
||||
log_esp3d_e("FTP: accessFS: already accessed");
|
||||
return false;
|
||||
}
|
||||
_fsType = FTPFS::getFSType(path);
|
||||
if (FTPFS::accessFS(_fsType)) {
|
||||
#if FTP_FEATURE == FS_SD
|
||||
if (FTPFS::getState(true) == ESP_SDCARD_NOT_PRESENT) {
|
||||
log_esp3d("FTP: accessFS:No SD card");
|
||||
log_esp3d_e("FTP: accessFS:No SD card");
|
||||
_fsType = FS_UNKNOWN;
|
||||
FTPFS::releaseFS();
|
||||
return false;
|
||||
@ -222,11 +205,10 @@ bool FtpServer::accessFS(const char* path)
|
||||
#endif // FTP_FEATURE == FS_SD
|
||||
return true;
|
||||
}
|
||||
log_esp3d("FTP: accessFS: Access denied");
|
||||
log_esp3d_e("FTP: accessFS: Access denied");
|
||||
return false;
|
||||
}
|
||||
void FtpServer::releaseFS()
|
||||
{
|
||||
void FtpServer::releaseFS() {
|
||||
if (_fsType != FS_UNKNOWN) {
|
||||
FTPFS::releaseFS(_fsType);
|
||||
log_esp3d("FTP: accessFS: Access revoked");
|
||||
@ -234,8 +216,7 @@ void FtpServer::releaseFS()
|
||||
}
|
||||
}
|
||||
|
||||
void FtpServer::iniVariables()
|
||||
{
|
||||
void FtpServer::iniVariables() {
|
||||
// Default for data port
|
||||
dataPort = activePort;
|
||||
|
||||
@ -249,9 +230,7 @@ void FtpServer::iniVariables()
|
||||
transferStage = FTP_Close;
|
||||
}
|
||||
|
||||
|
||||
void FtpServer::handle()
|
||||
{
|
||||
void FtpServer::handle() {
|
||||
if (!_started) {
|
||||
return;
|
||||
}
|
||||
@ -284,13 +263,16 @@ void FtpServer::handle()
|
||||
}
|
||||
if (client.connected()) { // A client connected
|
||||
clientConnected();
|
||||
millisEndConnection = millis() + 1000L * FTP_AUTH_TIME_OUT; // wait client id for 10 s.
|
||||
millisEndConnection =
|
||||
millis() + 1000L * FTP_AUTH_TIME_OUT; // wait client id for 10 s.
|
||||
cmdStage = FTP_User;
|
||||
}
|
||||
} else if (readChar() > 0) { // got response
|
||||
processCommand();
|
||||
if (cmdStage == FTP_Stop) {
|
||||
millisEndConnection = millis() + 1000L * FTP_AUTH_TIME_OUT; // wait authentication for 10 s.
|
||||
millisEndConnection =
|
||||
millis() +
|
||||
1000L * FTP_AUTH_TIME_OUT; // wait authentication for 10 s.
|
||||
} else if (cmdStage < FTP_Cmd) {
|
||||
millisDelay = millis() + 200; // delay of 100 ms
|
||||
} else {
|
||||
@ -303,26 +285,26 @@ void FtpServer::handle()
|
||||
if (transferStage == FTP_Retrieve) { // Retrieve data
|
||||
if (!doRetrieve()) {
|
||||
transferStage = FTP_Close;
|
||||
} else {
|
||||
log_esp3d("Release FS");
|
||||
releaseFS();
|
||||
}
|
||||
} else if (transferStage == FTP_Store) { // Store data
|
||||
if (!doStore()) {
|
||||
transferStage = FTP_Close;
|
||||
} else {
|
||||
log_esp3d("Release FS");
|
||||
releaseFS();
|
||||
}
|
||||
} else if (transferStage == FTP_List ||
|
||||
transferStage == FTP_Nlst) { // LIST or NLST
|
||||
if (!doList()) {
|
||||
transferStage = FTP_Close;
|
||||
} else {
|
||||
log_esp3d("Release FS");
|
||||
releaseFS();
|
||||
}
|
||||
} else if (transferStage == FTP_Mlsd) { // MLSD listing
|
||||
if (!doMlsd()) {
|
||||
transferStage = FTP_Close;
|
||||
} else {
|
||||
log_esp3d("Release FS");
|
||||
releaseFS();
|
||||
}
|
||||
} else if (cmdStage > FTP_Client &&
|
||||
@ -330,31 +312,32 @@ void FtpServer::handle()
|
||||
client << F("530 Timeout") << eol;
|
||||
millisDelay = millis() + 200; // delay of 200 ms
|
||||
cmdStage = FTP_Stop;
|
||||
releaseFS();
|
||||
}
|
||||
|
||||
#ifdef FTP_DEBUG
|
||||
uint8_t dstat = data.status();
|
||||
if (cmdStage != cmdStage0 || transferStage != transferStage0 ||
|
||||
dstat != data0) {
|
||||
log_esp3d (" Command: %d Transfer: %d Data: %d", cmdStage, transferStage, _HEX( dstat ));
|
||||
log_esp3d(" Command: %d Transfer: %d Data: %d", cmdStage, transferStage,
|
||||
_HEX(dstat));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void FtpServer::clientConnected()
|
||||
{
|
||||
void FtpServer::clientConnected() {
|
||||
log_esp3d(" Client connected!");
|
||||
client << F("220--- Welcome to FTP for ESP3D ---") << eol;
|
||||
client << F("220 -- Version ") << FW_VERSION << F(" --") << eol;
|
||||
iCL = 0;
|
||||
}
|
||||
|
||||
bool FtpServer::isUser(const char * user)
|
||||
{
|
||||
bool FtpServer::isUser(const char* user) {
|
||||
log_esp3d("Check User");
|
||||
_currentUser = "";
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if ((user != nullptr) && ((strcmp(user, DEFAULT_ADMIN_LOGIN) == 0) || (strcmp(user, DEFAULT_USER_LOGIN) == 0))) {
|
||||
if ((user != nullptr) && ((strcmp(user, DEFAULT_ADMIN_LOGIN) == 0) ||
|
||||
(strcmp(user, DEFAULT_USER_LOGIN) == 0))) {
|
||||
_currentUser = user;
|
||||
return true;
|
||||
}
|
||||
@ -364,14 +347,14 @@ bool FtpServer::isUser(const char * user)
|
||||
_currentUser = DEFAULT_ADMIN_LOGIN;
|
||||
log_esp3d("User is %s", _currentUser.c_str());
|
||||
return true;
|
||||
|
||||
}
|
||||
bool FtpServer::isPassword(const char * password)
|
||||
{
|
||||
bool FtpServer::isPassword(const char* password) {
|
||||
log_esp3d("Check Password");
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if(((_currentUser == DEFAULT_ADMIN_LOGIN) && AuthenticationService::isadmin(password)) ||
|
||||
((_currentUser == DEFAULT_USER_LOGIN) && AuthenticationService::isuser(password))) {
|
||||
if (((_currentUser == DEFAULT_ADMIN_LOGIN) &&
|
||||
AuthenticationService::isadmin(password)) ||
|
||||
((_currentUser == DEFAULT_USER_LOGIN) &&
|
||||
AuthenticationService::isuser(password))) {
|
||||
log_esp3d("Password ok");
|
||||
return true;
|
||||
}
|
||||
@ -382,8 +365,7 @@ bool FtpServer::isPassword(const char * password)
|
||||
return true;
|
||||
}
|
||||
|
||||
void FtpServer::disconnectClient()
|
||||
{
|
||||
void FtpServer::disconnectClient() {
|
||||
log_esp3d(" Disconnecting client");
|
||||
abortTransfer();
|
||||
client << F("221 Goodbye") << eol;
|
||||
@ -391,8 +373,7 @@ void FtpServer::disconnectClient()
|
||||
_currentUser = "";
|
||||
}
|
||||
|
||||
bool FtpServer::processCommand()
|
||||
{
|
||||
bool FtpServer::processCommand() {
|
||||
log_esp3d("Process Command");
|
||||
///////////////////////////////////////
|
||||
// //
|
||||
@ -404,13 +385,14 @@ bool FtpServer::processCommand()
|
||||
// USER - User Identity
|
||||
//
|
||||
if (CommandIs("USER")) {
|
||||
log_esp3d("USER : Command: %s Param: %s", command, (parameter == nullptr)?"":parameter);
|
||||
log_esp3d("USER : Command: %s Param: %s", command,
|
||||
(parameter == nullptr) ? "" : parameter);
|
||||
if (isUser(parameter)) {
|
||||
client << F("331 Ok. Password required") << eol;
|
||||
strcpy(cwdName, "/");
|
||||
cmdStage = FTP_Pass;
|
||||
} else {
|
||||
log_esp3d("Error USER");
|
||||
log_esp3d_e("Error USER");
|
||||
client << F("530 ") << eol;
|
||||
cmdStage = FTP_Stop;
|
||||
}
|
||||
@ -419,9 +401,10 @@ bool FtpServer::processCommand()
|
||||
// PASS - Password
|
||||
//
|
||||
else if (CommandIs("PASS")) {
|
||||
log_esp3d("PASS : Command: %s Param: %s", command, (parameter == nullptr)?"":parameter);
|
||||
log_esp3d("PASS : Command: %s Param: %s", command,
|
||||
(parameter == nullptr) ? "" : parameter);
|
||||
if (cmdStage != FTP_Pass) {
|
||||
log_esp3d("Error PASS");
|
||||
log_esp3d_e("Error PASS");
|
||||
client << F("503 ") << eol;
|
||||
cmdStage = FTP_Stop;
|
||||
}
|
||||
@ -430,7 +413,7 @@ bool FtpServer::processCommand()
|
||||
client << F("230 Ok") << eol;
|
||||
cmdStage = FTP_Cmd;
|
||||
} else {
|
||||
log_esp3d("Wrong PASS");
|
||||
log_esp3d_e("Wrong PASS");
|
||||
client << F("530 ") << eol;
|
||||
cmdStage = FTP_Stop;
|
||||
}
|
||||
@ -457,8 +440,10 @@ bool FtpServer::processCommand()
|
||||
//
|
||||
// OPTS / SYST - Not implemented
|
||||
//
|
||||
else if((cmdStage < FTP_Cmd) && ( CommandIs( "OPTS" ) || CommandIs( "SYST" ) || CommandIs( "TYPE" ))) {
|
||||
log_esp3d("Unsupported Command: %s Param: %s stage %d", command, (parameter == nullptr)?"":parameter, cmdStage);
|
||||
else if ((cmdStage < FTP_Cmd) &&
|
||||
(CommandIs("OPTS") || CommandIs("SYST") || CommandIs("TYPE"))) {
|
||||
log_esp3d_e("Unsupported Command: %s Param: %s stage %d", command,
|
||||
(parameter == nullptr) ? "" : parameter, cmdStage);
|
||||
client << F("500 ") << eol;
|
||||
cmdStage = FTP_User;
|
||||
}
|
||||
@ -466,7 +451,8 @@ bool FtpServer::processCommand()
|
||||
// Unrecognized commands at stage of authentication
|
||||
//
|
||||
else if (cmdStage < FTP_Cmd) {
|
||||
log_esp3d("Unknow Command: %s Param: %s stage %d", command, (parameter == nullptr)?"":parameter, cmdStage);
|
||||
log_esp3d_e("Unknow Command: %s Param: %s stage %d", command,
|
||||
(parameter == nullptr) ? "" : parameter, cmdStage);
|
||||
client << F("200 ") << eol;
|
||||
cmdStage = FTP_Stop;
|
||||
}
|
||||
@ -480,15 +466,14 @@ bool FtpServer::processCommand()
|
||||
//
|
||||
// PWD - Print Directory
|
||||
//
|
||||
else if( CommandIs( "PWD" ) ||
|
||||
( CommandIs( "CWD" ) && ParameterIs( "." ))) {
|
||||
client << F("257 \"") << cwdName << F("\"") << F(" is your current directory") << eol;
|
||||
else if (CommandIs("PWD") || (CommandIs("CWD") && ParameterIs("."))) {
|
||||
client << F("257 \"") << cwdName << F("\"")
|
||||
<< F(" is your current directory") << eol;
|
||||
}
|
||||
//
|
||||
// CDUP - Change to Parent Directory
|
||||
//
|
||||
else if( CommandIs( "CDUP" ) ||
|
||||
( CommandIs( "CWD" ) && ParameterIs( ".." ))) {
|
||||
else if (CommandIs("CDUP") || (CommandIs("CWD") && ParameterIs(".."))) {
|
||||
bool ok = false;
|
||||
|
||||
if (strlen(cwdName) > 1) { // do nothing if cwdName is root
|
||||
@ -509,6 +494,7 @@ bool FtpServer::processCommand()
|
||||
releaseFS();
|
||||
} else {
|
||||
ok = false;
|
||||
log_esp3d_e("FTP: access is denied");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -566,9 +552,8 @@ bool FtpServer::processCommand()
|
||||
dataPort = passivePort;
|
||||
log_esp3d(" Connection management set to passive");
|
||||
log_esp3d(" Data port set to %d", dataPort);
|
||||
client << F("227 Entering Passive Mode") << F(" (")
|
||||
<< dataIp[0] << F(",") << dataIp[1] << F(",")
|
||||
<< dataIp[2] << F(",") << dataIp[3] << F(",")
|
||||
client << F("227 Entering Passive Mode") << F(" (") << dataIp[0] << F(",")
|
||||
<< dataIp[1] << F(",") << dataIp[2] << F(",") << dataIp[3] << F(",")
|
||||
<< (dataPort >> 8) << F(",") << (dataPort & 255) << F(")") << eol;
|
||||
dataConn = FTP_Pasive;
|
||||
}
|
||||
@ -607,6 +592,7 @@ bool FtpServer::processCommand()
|
||||
// else if( ParameterIs( "R" ))
|
||||
// client << F("200 B Ok") << eol;
|
||||
else {
|
||||
log_esp3d_e("504 Only F(ile) is suported");
|
||||
client << F("504 Only F(ile) is suported") << eol;
|
||||
}
|
||||
}
|
||||
@ -648,14 +634,17 @@ bool FtpServer::processCommand()
|
||||
client << F("250 Deleted ") << parameter << eol;
|
||||
} else {
|
||||
client << F("450 Can't delete ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't delete %s", parameter);
|
||||
}
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else {
|
||||
client << F("550 Can't access ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", parameter);
|
||||
}
|
||||
} else {
|
||||
client << F("550 Can't access ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", parameter);
|
||||
}
|
||||
}
|
||||
//
|
||||
@ -670,24 +659,31 @@ bool FtpServer::processCommand()
|
||||
access = accessFS(cwdName);
|
||||
if (access) {
|
||||
dir = FTPFS::open(cwdName);
|
||||
log_esp3d("Open %s", cwdName);
|
||||
}
|
||||
}
|
||||
if (dir) {
|
||||
log_esp3d("Dir open");
|
||||
nbMatch = 0;
|
||||
if (CommandIs("LIST")) {
|
||||
log_esp3d("FTP: LIST");
|
||||
transferStage = FTP_List;
|
||||
} else if (CommandIs("NLST")) {
|
||||
log_esp3d("FTP: NLST");
|
||||
transferStage = FTP_Nlst;
|
||||
} else {
|
||||
log_esp3d("FTP: MLSD");
|
||||
transferStage = FTP_Mlsd;
|
||||
}
|
||||
} else {
|
||||
log_esp3d("FTP: Can't open directory %s", cwdName);
|
||||
// we got access but file opening failed, so let's release the FS
|
||||
if (access) {
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
}
|
||||
client << F("550 Can't open directory ") << cwdName << eol;
|
||||
log_esp3d_e("FTP: Can't open directory %s", cwdName);
|
||||
data.stop();
|
||||
}
|
||||
}
|
||||
@ -704,23 +700,26 @@ bool FtpServer::processCommand()
|
||||
if (accessFS(path)) {
|
||||
if (!getFileModTime(path, t)) {
|
||||
client << F("550 Unable to retrieve time for ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Unable to retrieve time for %s", parameter);
|
||||
} else {
|
||||
if (file = FTPFS::open(path)) {
|
||||
isdir = file.isDirectory();
|
||||
t = file.getLastWrite();
|
||||
file.close();
|
||||
}
|
||||
client << F("250-Begin") << eol
|
||||
<< F(" Type=") << ( isdir ? F("dir") : F("file"))
|
||||
<< F(";Modify=") << makeDateTimeStr( dtStr, t );
|
||||
client << F("250-Begin") << eol << F(" Type=")
|
||||
<< (isdir ? F("dir") : F("file")) << F(";Modify=")
|
||||
<< makeDateTimeStr(dtStr, t);
|
||||
if (!isdir) {
|
||||
client << F(";Size=") << file.size();
|
||||
}
|
||||
client << F("; ") << path << eol
|
||||
<< F("250 End.") << eol;
|
||||
client << F("; ") << path << eol << F("250 End.") << eol;
|
||||
}
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else {
|
||||
client << F("550 Can't access ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -741,6 +740,7 @@ bool FtpServer::processCommand()
|
||||
file = FTPFS::open(path);
|
||||
if (!file.isOpen()) {
|
||||
client << F("450 Can't open ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't open %s", parameter);
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else if (dataConnect(false)) {
|
||||
@ -751,6 +751,9 @@ bool FtpServer::processCommand()
|
||||
bytesTransfered = 0;
|
||||
transferStage = FTP_Retrieve;
|
||||
}
|
||||
} else {
|
||||
client << F("550 Can't access ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -764,12 +767,15 @@ bool FtpServer::processCommand()
|
||||
log_esp3d("FTP: check accessFS");
|
||||
if (accessFS(path)) {
|
||||
if (FTPFS::exists(path)) {
|
||||
file = FTPFS::open( path, ESP_FILE_WRITE | ( CommandIs( "APPE" ) ? ESP_FILE_APPEND : ESP_FILE_WRITE ));
|
||||
file = FTPFS::open(
|
||||
path, ESP_FILE_WRITE |
|
||||
(CommandIs("APPE") ? ESP_FILE_APPEND : ESP_FILE_WRITE));
|
||||
} else {
|
||||
file = FTPFS::open(path, ESP_FILE_WRITE);
|
||||
}
|
||||
if (!file.isOpen()) {
|
||||
client << F("451 Can't open/create ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't open/create %s", parameter);
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else if (!dataConnect()) {
|
||||
@ -782,6 +788,9 @@ bool FtpServer::processCommand()
|
||||
bytesTransfered = 0;
|
||||
transferStage = FTP_Store;
|
||||
}
|
||||
} else {
|
||||
client << F("550 Can't access ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -794,17 +803,23 @@ bool FtpServer::processCommand()
|
||||
log_esp3d("FTP: check accessFS");
|
||||
if (accessFS(path)) {
|
||||
if (FTPFS::exists(path)) {
|
||||
client << F("521 \"") << parameter << F("\" directory already exists") << eol;
|
||||
client << F("521 \"") << parameter << F("\" directory already exists")
|
||||
<< eol;
|
||||
} else {
|
||||
log_esp3d(" Creating directory %s", parameter);
|
||||
if (FTPFS::mkdir(path)) {
|
||||
client << F("257 \"") << parameter << F("\"") << F(" created") << eol;
|
||||
client << F("257 \"") << parameter << F("\"") << F(" created")
|
||||
<< eol;
|
||||
} else {
|
||||
client << F("550 Can't create \"") << parameter << F("\"") << eol;
|
||||
log_esp3d_e("FTP: Can't create %s", parameter);
|
||||
}
|
||||
}
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else {
|
||||
client << F("550 Can't access ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -820,10 +835,15 @@ bool FtpServer::processCommand()
|
||||
log_esp3d(" Deleting %s", path);
|
||||
client << F("250 \"") << parameter << F("\" deleted") << eol;
|
||||
} else {
|
||||
client << F("550 Can't remove \"") << parameter << F("\". Directory not empty?") << eol;
|
||||
client << F("550 Can't remove \"") << parameter
|
||||
<< F("\". Directory not empty?") << eol;
|
||||
log_esp3d_e("FTP: Can't remove %s", parameter);
|
||||
}
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else {
|
||||
client << F("550 Can't access ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -834,7 +854,8 @@ bool FtpServer::processCommand()
|
||||
rnfrName[0] = 0;
|
||||
if (haveParameter() && makeExistsPath(rnfrName)) {
|
||||
log_esp3d(" Ready for renaming %s", rnfrName);
|
||||
client << F("350 RNFR accepted - file exists, ready for destination") << eol;
|
||||
client << F("350 RNFR accepted - file exists, ready for destination")
|
||||
<< eol;
|
||||
rnfrCmd = true;
|
||||
}
|
||||
}
|
||||
@ -876,10 +897,14 @@ bool FtpServer::processCommand()
|
||||
}
|
||||
if (fail) {
|
||||
client << F("451 Rename/move failure") << eol;
|
||||
log_esp3d_e("FTP: Rename/move failure");
|
||||
}
|
||||
}
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else {
|
||||
client << F("550 Can't access ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", parameter);
|
||||
}
|
||||
}
|
||||
rnfrCmd = false;
|
||||
@ -892,7 +917,6 @@ bool FtpServer::processCommand()
|
||||
client << F("215 ESP3D") << eol;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
// //
|
||||
// EXTENSIONS COMMANDS (RFC 3659) //
|
||||
@ -922,6 +946,7 @@ bool FtpServer::processCommand()
|
||||
client << "213 " << dt << eol;
|
||||
} else {
|
||||
client << "550 Unable to modify time" << eol;
|
||||
log_esp3d_e("FTP: Unable to modify time");
|
||||
}
|
||||
} else if (mdtm) { // get file modification time
|
||||
time_t t = 0;
|
||||
@ -932,11 +957,13 @@ bool FtpServer::processCommand()
|
||||
client << "213 " << makeDateTimeStr(dtStr, t) << eol;
|
||||
} else {
|
||||
client << "550 Unable to retrieve time" << eol;
|
||||
log_esp3d_e("FTP: Unable to retrieve time");
|
||||
}
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else {
|
||||
client << "550 Unable to retrieve time" << eol;
|
||||
log_esp3d_e("FTP: Unable to retrieve time for %s", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -951,15 +978,22 @@ bool FtpServer::processCommand()
|
||||
log_esp3d("FTP: check accessFS");
|
||||
if (accessFS(path)) {
|
||||
file = FTPFS::open(path);
|
||||
}
|
||||
|
||||
if (!file.isOpen()) {
|
||||
client << F("450 Can't open ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't open %s", parameter);
|
||||
} else {
|
||||
client << F("213 ") << file.size() << eol;
|
||||
file.close();
|
||||
}
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else {
|
||||
client << F("550 Can't access ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", parameter);
|
||||
}
|
||||
} else {
|
||||
log_esp3d_e("FTP:no parameter");
|
||||
}
|
||||
}
|
||||
//
|
||||
@ -990,9 +1024,13 @@ bool FtpServer::processCommand()
|
||||
<< FTPFS::formatBytes(capacity) << F(" capacity") << eol;
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else {
|
||||
client << F("550 Can't access ") << cwdName << eol;
|
||||
log_esp3d_e("FTP: Can't access %s", cwdName);
|
||||
}
|
||||
} else {
|
||||
client << F("500 Unknow SITE command ") << parameter << eol;
|
||||
log_esp3d_e("FTP: Unknow SITE command %s", parameter);
|
||||
}
|
||||
}
|
||||
//
|
||||
@ -1000,12 +1038,12 @@ bool FtpServer::processCommand()
|
||||
//
|
||||
else {
|
||||
client << F("500 Unknow command") << eol;
|
||||
log_esp3d_e("FTP: Unknow command %s", command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int FtpServer::dataConnect( bool out150 )
|
||||
{
|
||||
int FtpServer::dataConnect(bool out150) {
|
||||
if (!data.connected()) {
|
||||
if (dataConn == FTP_Pasive) {
|
||||
uint16_t count = 1000; // wait up to a second
|
||||
@ -1029,8 +1067,7 @@ int FtpServer::dataConnect( bool out150 )
|
||||
return data.connected();
|
||||
}
|
||||
|
||||
bool FtpServer::dataConnected()
|
||||
{
|
||||
bool FtpServer::dataConnected() {
|
||||
if (data.connected()) {
|
||||
return true;
|
||||
}
|
||||
@ -1040,8 +1077,7 @@ bool FtpServer::dataConnected()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FtpServer::doRetrieve()
|
||||
{
|
||||
bool FtpServer::doRetrieve() {
|
||||
if (!dataConnected()) {
|
||||
file.close();
|
||||
return false;
|
||||
@ -1056,8 +1092,7 @@ bool FtpServer::doRetrieve()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FtpServer::doStore()
|
||||
{
|
||||
bool FtpServer::doStore() {
|
||||
int16_t na = data.available();
|
||||
if (na == 0) {
|
||||
if (data.connected()) {
|
||||
@ -1080,14 +1115,15 @@ bool FtpServer::doStore()
|
||||
return true;
|
||||
}
|
||||
client << F("552 Probably insufficient storage space") << eol;
|
||||
log_esp3d_e("FTP: Probably insufficient storage space");
|
||||
file.close();
|
||||
data.stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FtpServer::doList()
|
||||
{
|
||||
bool FtpServer::doList() {
|
||||
if (!dataConnected()) {
|
||||
log_esp3d_e("FTP: data not connected");
|
||||
dir.close();
|
||||
return false;
|
||||
}
|
||||
@ -1099,16 +1135,22 @@ bool FtpServer::doList()
|
||||
if (file) {
|
||||
time_t t = file.getLastWrite();
|
||||
char dtStr[15];
|
||||
data << (file.isDirectory()?"d":"-") << "rwxrwxrwx 1 " << _currentUser.c_str() << " " << _currentUser.c_str();
|
||||
data << (file.isDirectory() ? "d" : "-") << "rwxrwxrwx 1 "
|
||||
<< _currentUser.c_str() << " " << _currentUser.c_str();
|
||||
String s = String(file.size());
|
||||
for (uint i = 0; i < SIZELISTPADING - s.length(); i++) {
|
||||
data << " ";
|
||||
}
|
||||
data << file.size() << " " << makeDateTimeString(dtStr,t) << " " << file.name() << eol;
|
||||
data << file.size() << " " << makeDateTimeString(dtStr, t) << " "
|
||||
<< file.name() << eol;
|
||||
nbMatch++;
|
||||
file.close();
|
||||
return true;
|
||||
} else {
|
||||
log_esp3d("FTP: no more file");
|
||||
}
|
||||
} else {
|
||||
log_esp3d_e("FTP: dir not open");
|
||||
}
|
||||
client << F("226 ") << nbMatch << F(" matches total") << eol;
|
||||
dir.close();
|
||||
@ -1116,13 +1158,14 @@ bool FtpServer::doList()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FtpServer::doMlsd()
|
||||
{
|
||||
bool FtpServer::doMlsd() {
|
||||
if (!dataConnected()) {
|
||||
log_esp3d_e("FTP: data not connected");
|
||||
dir.close();
|
||||
return false;
|
||||
}
|
||||
if (dir) {
|
||||
log_esp3d("FTP: dir open");
|
||||
if (file) {
|
||||
file.close();
|
||||
}
|
||||
@ -1130,12 +1173,19 @@ bool FtpServer::doMlsd()
|
||||
if (file) {
|
||||
char dtStr[15];
|
||||
time_t t = file.getLastWrite();
|
||||
data << "Type=" << ( file.isDirectory() ? F("dir") : F("file")) << ";Size=" << file.size() << ";Modify=" << makeDateTimeStr( dtStr, t) << "; " << file.name() << eol;
|
||||
log_esp3d("%s %u %s %s", file.isDirectory() ? "dir" : "file", file.size(), makeDateTimeStr( dtStr, t), file.name());
|
||||
data << "Type=" << (file.isDirectory() ? F("dir") : F("file"))
|
||||
<< ";Size=" << file.size() << ";Modify=" << makeDateTimeStr(dtStr, t)
|
||||
<< "; " << file.name() << eol;
|
||||
log_esp3d("%s %u %s %s", file.isDirectory() ? "dir" : "file", file.size(),
|
||||
makeDateTimeStr(dtStr, t), file.name());
|
||||
file.close();
|
||||
nbMatch++;
|
||||
return true;
|
||||
} else {
|
||||
log_esp3d("FTP: no more file");
|
||||
}
|
||||
} else {
|
||||
log_esp3d_e("FTP: dir not open");
|
||||
}
|
||||
client << F("226-options: -a -l") << eol;
|
||||
client << F("226 ") << nbMatch << F(" matches total") << eol;
|
||||
@ -1144,14 +1194,14 @@ bool FtpServer::doMlsd()
|
||||
return false;
|
||||
}
|
||||
|
||||
void FtpServer::closeTransfer()
|
||||
{
|
||||
void FtpServer::closeTransfer() {
|
||||
uint32_t deltaT = (int32_t)(millis() - millisBeginTrans);
|
||||
if (deltaT > 0 && bytesTransfered > 0) {
|
||||
log_esp3d(" Transfer completed in %d ms, %f kbytes/s", deltaT, 1.0*bytesTransfered / deltaT);
|
||||
log_esp3d(" Transfer completed in %d ms, %f kbytes/s", deltaT,
|
||||
1.0 * bytesTransfered / deltaT);
|
||||
client << F("226-File successfully transferred") << eol;
|
||||
client << F("226 ") << deltaT << F(" ms, ")
|
||||
<< bytesTransfered / deltaT << F(" kbytes/s") << eol;
|
||||
client << F("226 ") << deltaT << F(" ms, ") << bytesTransfered / deltaT
|
||||
<< F(" kbytes/s") << eol;
|
||||
} else {
|
||||
client << F("226 File successfully transferred") << eol;
|
||||
}
|
||||
@ -1160,13 +1210,12 @@ void FtpServer::closeTransfer()
|
||||
data.stop();
|
||||
}
|
||||
|
||||
void FtpServer::abortTransfer()
|
||||
{
|
||||
void FtpServer::abortTransfer() {
|
||||
if (transferStage != FTP_Close) {
|
||||
file.close();
|
||||
dir.close();
|
||||
client << F("426 Transfer aborted") << eol;
|
||||
log_esp3d(" Transfer aborted!");
|
||||
log_esp3d_e(" Transfer aborted!");
|
||||
transferStage = FTP_Close;
|
||||
}
|
||||
// if( data.connected())
|
||||
@ -1183,8 +1232,7 @@ void FtpServer::abortTransfer()
|
||||
// 0 if empty line received
|
||||
// length of cmdLine (positive) if no empty line received
|
||||
|
||||
int8_t FtpServer::readChar()
|
||||
{
|
||||
int8_t FtpServer::readChar() {
|
||||
int8_t rc = -1;
|
||||
|
||||
if (client.available()) {
|
||||
@ -1236,23 +1284,25 @@ int8_t FtpServer::readChar()
|
||||
if (rc == -2) {
|
||||
iCL = 0;
|
||||
client << F("500 Syntax error") << eol;
|
||||
log_esp3d_e("FTP: Syntax error");
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool FtpServer::haveParameter()
|
||||
{
|
||||
bool FtpServer::haveParameter() {
|
||||
if (parameter != NULL && strlen(parameter) > 0) {
|
||||
return true;
|
||||
}
|
||||
client << "501 No file name" << eol;
|
||||
log_esp3d_e("FTP: No file name");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make complete path/name from cwdName and param
|
||||
//
|
||||
// 3 possible cases: parameter can be absolute path, relative path or only the name
|
||||
// 3 possible cases: parameter can be absolute path, relative path or only the
|
||||
// name
|
||||
//
|
||||
// parameter:
|
||||
// fullName : where to store the path/name
|
||||
@ -1260,8 +1310,7 @@ bool FtpServer::haveParameter()
|
||||
// return:
|
||||
// true, if done
|
||||
|
||||
bool FtpServer::makePath( char * fullName, char * param )
|
||||
{
|
||||
bool FtpServer::makePath(char* fullName, char* param) {
|
||||
if (param == NULL) {
|
||||
param = parameter;
|
||||
}
|
||||
@ -1288,25 +1337,37 @@ bool FtpServer::makePath( char * fullName, char * param )
|
||||
}
|
||||
if (strlen(fullName) >= FTP_CWD_SIZE) {
|
||||
client << F("500 Command line too long") << eol;
|
||||
log_esp3d_e("FTP: Command line too long");
|
||||
return false;
|
||||
}
|
||||
for (uint8_t i = 0; i < strlen(fullName); i++)
|
||||
if (!legalChar(fullName[i])) {
|
||||
client << F("553 File name not allowed") << eol;
|
||||
log_esp3d_e("FTP: File name not allowed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FtpServer::makeExistsPath( char * path, char * param )
|
||||
{
|
||||
bool FtpServer::makeExistsPath(char* path, char* param) {
|
||||
if (!makePath(path, param)) {
|
||||
return false;
|
||||
}
|
||||
if( FTPFS::exists( path )) {
|
||||
bool pathExists = false;
|
||||
log_esp3d("FTP: check accessFS");
|
||||
if (accessFS(path)) {
|
||||
pathExists = FTPFS::exists(path);
|
||||
log_esp3d("FTP: releaseFS");
|
||||
releaseFS();
|
||||
} else {
|
||||
pathExists = false;
|
||||
log_esp3d_e("FTP: access is denied");
|
||||
}
|
||||
if (pathExists) {
|
||||
return true;
|
||||
}
|
||||
client << F("550 ") << path << F(" not found.") << eol;
|
||||
log_esp3d_e("FTP: %s not found.", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1327,9 +1388,9 @@ bool FtpServer::makeExistsPath( char * path, char * param )
|
||||
// Date/time are expressed as a 14 digits long string
|
||||
// terminated by a space and followed by name of file
|
||||
|
||||
uint8_t FtpServer::getDateTime( char * dt, uint16_t * pyear, uint8_t * pmonth, uint8_t * pday,
|
||||
uint8_t * phour, uint8_t * pminute, uint8_t * psecond )
|
||||
{
|
||||
uint8_t FtpServer::getDateTime(char* dt, uint16_t* pyear, uint8_t* pmonth,
|
||||
uint8_t* pday, uint8_t* phour, uint8_t* pminute,
|
||||
uint8_t* psecond) {
|
||||
uint8_t i;
|
||||
dt[0] = 0;
|
||||
if (strlen(parameter) < 15) { //|| parameter[ 14 ] != ' ' )
|
||||
@ -1364,7 +1425,8 @@ uint8_t FtpServer::getDateTime( char * dt, uint16_t * pyear, uint8_t * pmonth, u
|
||||
dt[4] = 0;
|
||||
*pyear = atoi(dt);
|
||||
strncpy(dt, parameter, 14);
|
||||
log_esp3d(" Modification time: %d/%d/%d %d:%d:%d of file: %s", * pyear, * pmonth, * pday, * phour, * pminute, * psecond, (char *) ( parameter + i ));
|
||||
log_esp3d(" Modification time: %d/%d/%d %d:%d:%d of file: %s", *pyear,
|
||||
*pmonth, *pday, *phour, *pminute, *psecond, (char*)(parameter + i));
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -1377,10 +1439,11 @@ uint8_t FtpServer::getDateTime( char * dt, uint16_t * pyear, uint8_t * pmonth, u
|
||||
// return:
|
||||
// pointer to tstr
|
||||
|
||||
char * FtpServer::makeDateTimeStr( char * tstr, time_t timefile )
|
||||
{
|
||||
char* FtpServer::makeDateTimeStr(char* tstr, time_t timefile) {
|
||||
struct tm* tmstruct = localtime(&timefile);
|
||||
sprintf( tstr, "%04u%02u%02u%02u%02u%02u",(tmstruct->tm_year)+1900,(tmstruct->tm_mon)+1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
sprintf(tstr, "%04u%02u%02u%02u%02u%02u", (tmstruct->tm_year) + 1900,
|
||||
(tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour,
|
||||
tmstruct->tm_min, tmstruct->tm_sec);
|
||||
return tstr;
|
||||
}
|
||||
|
||||
@ -1393,8 +1456,7 @@ char * FtpServer::makeDateTimeStr( char * tstr, time_t timefile )
|
||||
// return:
|
||||
// pointer to tstr
|
||||
|
||||
char * FtpServer::makeDateTimeString( char * tstr, time_t timefile )
|
||||
{
|
||||
char* FtpServer::makeDateTimeString(char* tstr, time_t timefile) {
|
||||
struct tm* tmstruct = localtime(&timefile);
|
||||
time_t now;
|
||||
time(&now);
|
||||
@ -1408,22 +1470,21 @@ char * FtpServer::makeDateTimeString( char * tstr, time_t timefile )
|
||||
return tstr;
|
||||
}
|
||||
|
||||
|
||||
bool FtpServer::getFileModTime(const char * path, time_t & t)
|
||||
{
|
||||
bool FtpServer::getFileModTime(const char* path, time_t& t) {
|
||||
FTPFile f = FTPFS::open(path);
|
||||
if (f) {
|
||||
t = f.getLastWrite();
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
log_esp3d("Cannot get getLastWrite");
|
||||
log_esp3d_e("Cannot get getLastWrite");
|
||||
t = 0;
|
||||
return false;
|
||||
}
|
||||
// TODO
|
||||
bool FtpServer::timeStamp( const char * path, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second )
|
||||
{
|
||||
bool FtpServer::timeStamp(const char* path, uint16_t year, uint8_t month,
|
||||
uint8_t day, uint8_t hour, uint8_t minute,
|
||||
uint8_t second) {
|
||||
// TODO
|
||||
// Not available yet
|
||||
(void)path;
|
||||
|
@ -17,13 +17,14 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined(GCODE_HOST_FEATURE)
|
||||
#include "gcode_host.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/commands.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "gcode_host.h"
|
||||
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
#include "../filesystem/esp_filesystem.h"
|
||||
ESP_File FSfileHandle;
|
||||
@ -36,27 +37,18 @@ ESP_SDFile SDfileHandle;
|
||||
#define ESP_HOST_TIMEOUT 16000
|
||||
#define MAX_TRY_2_SEND 5
|
||||
|
||||
|
||||
GcodeHost esp3d_gcode_host;
|
||||
|
||||
GcodeHost::GcodeHost()
|
||||
{
|
||||
end();
|
||||
}
|
||||
GcodeHost::GcodeHost() { end(); }
|
||||
|
||||
GcodeHost::~GcodeHost()
|
||||
{
|
||||
end();
|
||||
}
|
||||
GcodeHost::~GcodeHost() { end(); }
|
||||
|
||||
bool GcodeHost::begin()
|
||||
{
|
||||
bool GcodeHost::begin() {
|
||||
end();
|
||||
return true;
|
||||
}
|
||||
|
||||
void GcodeHost::end()
|
||||
{
|
||||
void GcodeHost::end() {
|
||||
_commandNumber = 0;
|
||||
_error = ERROR_NO_ERROR;
|
||||
_step = HOST_NO_STREAM;
|
||||
@ -67,8 +59,7 @@ void GcodeHost::end()
|
||||
_processedSize = 0;
|
||||
}
|
||||
|
||||
bool GcodeHost::push(const uint8_t * sbuf, size_t len)
|
||||
{
|
||||
bool GcodeHost::push(const uint8_t *sbuf, size_t len) {
|
||||
if (_step == HOST_NO_STREAM) {
|
||||
return false;
|
||||
}
|
||||
@ -94,8 +85,7 @@ bool GcodeHost::push(const uint8_t * sbuf, size_t len)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GcodeHost::isAck(String & line)
|
||||
{
|
||||
bool GcodeHost::isAck(String &line) {
|
||||
if (line.indexOf("ok") != -1) {
|
||||
log_esp3d("got ok");
|
||||
return true;
|
||||
@ -109,8 +99,7 @@ bool GcodeHost::isAck(String & line)
|
||||
return false;
|
||||
}
|
||||
|
||||
void GcodeHost::flush()
|
||||
{
|
||||
void GcodeHost::flush() {
|
||||
// analyze buffer and do action if needed
|
||||
// look for \n, ok , error, ack
|
||||
// then clean buffer accordingly
|
||||
@ -130,7 +119,7 @@ void GcodeHost::flush()
|
||||
}
|
||||
} else {
|
||||
if (_response.indexOf("error") != -1) {
|
||||
log_esp3d("Got error");
|
||||
log_esp3d_e("Got error");
|
||||
_step = HOST_ERROR_STREAM;
|
||||
}
|
||||
}
|
||||
@ -139,8 +128,7 @@ void GcodeHost::flush()
|
||||
_bufferSize = 0;
|
||||
}
|
||||
|
||||
void GcodeHost::startStream()
|
||||
{
|
||||
void GcodeHost::startStream() {
|
||||
if (_fsType == TYPE_SCRIPT_STREAM) {
|
||||
_totalSize = _script.length();
|
||||
log_esp3d("Script line %s opened, size is %d", _script.c_str(), _totalSize);
|
||||
@ -156,7 +144,7 @@ void GcodeHost::startStream()
|
||||
} else {
|
||||
_error = ERROR_FILE_NOT_FOUND;
|
||||
_step = HOST_ERROR_STREAM;
|
||||
log_esp3d("File not found: %s", _fileName.c_str());
|
||||
log_esp3d_e("File not found: %s", _fileName.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -167,14 +155,14 @@ void GcodeHost::startStream()
|
||||
_error = ERROR_FILE_NOT_FOUND;
|
||||
_step = HOST_ERROR_STREAM;
|
||||
_needRelease = false;
|
||||
log_esp3d("File not found: %s", _fileName.c_str());
|
||||
log_esp3d_e("File not found: %s", _fileName.c_str());
|
||||
return;
|
||||
}
|
||||
_needRelease = true;
|
||||
if (ESP_SD::getState(true) == ESP_SDCARD_NOT_PRESENT) {
|
||||
_error = ERROR_FILE_NOT_FOUND;
|
||||
_step = HOST_ERROR_STREAM;
|
||||
log_esp3d("File not found: %s", _fileName.c_str());
|
||||
log_esp3d_e("File not found: %s", _fileName.c_str());
|
||||
return;
|
||||
}
|
||||
ESP_SD::setState(ESP_SDCARD_BUSY);
|
||||
@ -188,7 +176,7 @@ void GcodeHost::startStream()
|
||||
} else {
|
||||
_error = ERROR_FILE_NOT_FOUND;
|
||||
_step = HOST_ERROR_STREAM;
|
||||
log_esp3d("File not found: %s", _fileName.c_str());
|
||||
log_esp3d_e("File not found: %s", _fileName.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -202,8 +190,7 @@ void GcodeHost::startStream()
|
||||
_processedSize = 0;
|
||||
}
|
||||
|
||||
void GcodeHost::endStream()
|
||||
{
|
||||
void GcodeHost::endStream() {
|
||||
log_esp3d("Ending Stream");
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
if (_fsType == TYPE_FS_STREAM) {
|
||||
@ -225,15 +212,15 @@ void GcodeHost::endStream()
|
||||
_step = HOST_NO_STREAM;
|
||||
}
|
||||
|
||||
void GcodeHost::readNextCommand()
|
||||
{
|
||||
void GcodeHost::readNextCommand() {
|
||||
_currentCommand = "";
|
||||
_step = HOST_PROCESS_LINE;
|
||||
if (_fsType == TYPE_SCRIPT_STREAM) {
|
||||
log_esp3d("Reading next command from script");
|
||||
if (_currentPosition < _script.length()) {
|
||||
if (_script.indexOf(';', _currentPosition) != -1) {
|
||||
_currentCommand = _script.substring(_currentPosition, _script.indexOf(';', _currentPosition));
|
||||
_currentCommand = _script.substring(
|
||||
_currentPosition, _script.indexOf(';', _currentPosition));
|
||||
_currentPosition = _script.indexOf(';', _currentPosition) + 1;
|
||||
} else {
|
||||
_currentCommand = _script.substring(_currentPosition);
|
||||
@ -301,11 +288,11 @@ void GcodeHost::readNextCommand()
|
||||
#endif // SD_DEVICE
|
||||
}
|
||||
|
||||
bool GcodeHost::isCommand()
|
||||
{
|
||||
bool GcodeHost::isCommand() {
|
||||
// clean the command
|
||||
if (_currentCommand.indexOf(';') != -1) {
|
||||
_currentCommand = _currentCommand.substring(0, _currentCommand.indexOf(';'));
|
||||
_currentCommand =
|
||||
_currentCommand.substring(0, _currentCommand.indexOf(';'));
|
||||
}
|
||||
_currentCommand.trim();
|
||||
if (_currentCommand.length() == 0 || _currentCommand.startsWith(";")) {
|
||||
@ -313,20 +300,19 @@ bool GcodeHost::isCommand()
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool GcodeHost::isAckNeeded()
|
||||
{
|
||||
bool GcodeHost::isAckNeeded() {
|
||||
// TODO: what command do not need for ack ?
|
||||
return true;
|
||||
}
|
||||
void GcodeHost::processCommand()
|
||||
{
|
||||
void GcodeHost::processCommand() {
|
||||
if (!isCommand()) {
|
||||
log_esp3d("Command %s is not valid", _currentCommand.c_str());
|
||||
log_esp3d_e("Command %s is not valid", _currentCommand.c_str());
|
||||
_step = HOST_READ_LINE;
|
||||
} else {
|
||||
log_esp3d("Command %s is valid", _currentCommand.c_str());
|
||||
String cmd = _currentCommand + "\n";
|
||||
bool isESPcmd = esp3d_commands.is_esp_command((uint8_t *)_currentCommand.c_str(), _currentCommand.length());
|
||||
bool isESPcmd = esp3d_commands.is_esp_command(
|
||||
(uint8_t *)_currentCommand.c_str(), _currentCommand.length());
|
||||
// TODO need to change if ESP3D
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
ESP3DOutput output(ESP_SOCKET_SERIAL_CLIENT);
|
||||
@ -336,17 +322,25 @@ void GcodeHost::processCommand()
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
ESP3DOutput outputhost(ESP_STREAM_HOST_CLIENT);
|
||||
if (isESPcmd) {
|
||||
esp3d_commands.process((uint8_t *)cmd.c_str(), cmd.length(),&outputhost, _auth_type) ;
|
||||
esp3d_commands.process((uint8_t *)cmd.c_str(), cmd.length(), &outputhost,
|
||||
_auth_type);
|
||||
// we display error in output but it is not a blocking error
|
||||
log_esp3d("Command is ESP command: %s", cmd.c_str());
|
||||
_step = HOST_READ_LINE;
|
||||
} else {
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
esp3d_commands.process((uint8_t *)cmd.c_str(), cmd.length(),&_outputStream, _auth_type,&output,_outputStream.client()==ESP_ECHO_SERIAL_CLIENT?ESP_SOCKET_SERIAL_CLIENT:0 ) ;
|
||||
esp3d_commands.process((uint8_t *)cmd.c_str(), cmd.length(),
|
||||
&_outputStream, _auth_type, &output,
|
||||
_outputStream.client() == ESP_ECHO_SERIAL_CLIENT
|
||||
? ESP_SOCKET_SERIAL_CLIENT
|
||||
: 0);
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
log_esp3d("Command is not ESP command:%s, client is %d and only is %d",cmd.c_str(), (&_outputStream?_outputStream.client():0),(&output?output.client():0));
|
||||
esp3d_commands.process((uint8_t *)cmd.c_str(), cmd.length(),&_outputStream, _auth_type,&output) ;
|
||||
log_esp3d("Command is not ESP command:%s, client is %d and only is %d",
|
||||
cmd.c_str(), (&_outputStream ? _outputStream.client() : 0),
|
||||
(&output ? output.client() : 0));
|
||||
esp3d_commands.process((uint8_t *)cmd.c_str(), cmd.length(),
|
||||
&_outputStream, _auth_type, &output);
|
||||
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
_startTimeOut = millis();
|
||||
log_esp3d("Command is GCODE command");
|
||||
@ -360,8 +354,7 @@ void GcodeHost::processCommand()
|
||||
}
|
||||
}
|
||||
|
||||
void GcodeHost::handle()
|
||||
{
|
||||
void GcodeHost::handle() {
|
||||
if (_step == HOST_NO_STREAM) {
|
||||
return;
|
||||
}
|
||||
@ -403,7 +396,7 @@ void GcodeHost::handle()
|
||||
// TODO check _response to put right error
|
||||
_error = ERROR_UNKNOW;
|
||||
}
|
||||
log_esp3d("Error %d", _error);
|
||||
log_esp3d_e("Error %d", _error);
|
||||
Error = "error: stream failed: " + String(_error) + "\n";
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
ESP3DOutput output(ESP_SOCKET_SERIAL_CLIENT);
|
||||
@ -413,16 +406,14 @@ void GcodeHost::handle()
|
||||
#endif // COMMUNICATION_PROTOCOL
|
||||
output.dispatch((const uint8_t *)Error.c_str(), Error.length());
|
||||
_step = HOST_STOP_STREAM;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
default: // Not handled step
|
||||
log_esp3d("Not handled step %d", _step);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool GcodeHost::abort()
|
||||
{
|
||||
bool GcodeHost::abort() {
|
||||
if (_step == HOST_NO_STREAM) {
|
||||
return false;
|
||||
}
|
||||
@ -434,8 +425,7 @@ bool GcodeHost::abort()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GcodeHost::pause()
|
||||
{
|
||||
bool GcodeHost::pause() {
|
||||
if (_step == HOST_NO_STREAM) {
|
||||
return false;
|
||||
}
|
||||
@ -443,8 +433,7 @@ bool GcodeHost::pause()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GcodeHost::resume()
|
||||
{
|
||||
bool GcodeHost::resume() {
|
||||
if (_step != HOST_PAUSE_STREAM) {
|
||||
return false;
|
||||
}
|
||||
@ -452,8 +441,7 @@ bool GcodeHost::resume()
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t GcodeHost::Checksum(const char * command, uint32_t commandSize)
|
||||
{
|
||||
uint8_t GcodeHost::Checksum(const char *command, uint32_t commandSize) {
|
||||
uint8_t checksum_val = 0;
|
||||
if (command == NULL) {
|
||||
return 0;
|
||||
@ -464,16 +452,14 @@ uint8_t GcodeHost::Checksum(const char * command, uint32_t commandSize)
|
||||
return checksum_val;
|
||||
}
|
||||
|
||||
String GcodeHost::CheckSumCommand(const char* command, uint32_t commandnb)
|
||||
{
|
||||
String GcodeHost::CheckSumCommand(const char *command, uint32_t commandnb) {
|
||||
String commandchecksum = "N" + String((uint32_t)commandnb) + " " + command;
|
||||
uint8_t crc = Checksum(commandchecksum.c_str(), commandchecksum.length());
|
||||
commandchecksum += "*" + String(crc);
|
||||
return commandchecksum;
|
||||
}
|
||||
|
||||
bool GcodeHost::resetCommandNumbering()
|
||||
{
|
||||
bool GcodeHost::resetCommandNumbering() {
|
||||
String resetcmd = "M110 N0";
|
||||
if (Settings_ESP3D::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
resetcmd = "N0 M110";
|
||||
@ -485,8 +471,7 @@ bool GcodeHost::resetCommandNumbering()
|
||||
return _outputStream.printLN(resetcmd.c_str());
|
||||
}
|
||||
|
||||
uint32_t GcodeHost::getCommandNumber(String & response)
|
||||
{
|
||||
uint32_t GcodeHost::getCommandNumber(String &response) {
|
||||
uint32_t l = 0;
|
||||
String sresend = "Resend:";
|
||||
if (Settings_ESP3D::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
@ -494,7 +479,7 @@ uint32_t GcodeHost::getCommandNumber(String & response)
|
||||
}
|
||||
int pos = response.indexOf(sresend);
|
||||
if (pos == -1) {
|
||||
log_esp3d("Cannot find label %d", _error);
|
||||
log_esp3d_e("Cannot find label %d", _error);
|
||||
return -1;
|
||||
}
|
||||
pos += sresend.length();
|
||||
@ -503,12 +488,13 @@ uint32_t GcodeHost::getCommandNumber(String & response)
|
||||
// remove potential unwished char
|
||||
snum.replace("\r", "");
|
||||
l = snum.toInt();
|
||||
log_esp3d("Command number to resend is %s", String((uint32_t)l).c_str());
|
||||
log_esp3d_e("Command number to resend is %s", String((uint32_t)l).c_str());
|
||||
return l;
|
||||
}
|
||||
|
||||
bool GcodeHost::processScript(const char * line, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool GcodeHost::processScript(const char *line,
|
||||
level_authenticate_type auth_type,
|
||||
ESP3DOutput *output) {
|
||||
_script = line;
|
||||
_script.trim();
|
||||
log_esp3d("Processing script: %s", _script.c_str());
|
||||
@ -526,15 +512,18 @@ bool GcodeHost::processScript(const char * line, level_authenticate_type auth_ty
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GcodeHost::processFile(const char * filename, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool GcodeHost::processFile(const char *filename,
|
||||
level_authenticate_type auth_type,
|
||||
ESP3DOutput *output) {
|
||||
bool target_found = false;
|
||||
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
log_esp3d("Processing file client is %d", output?output->client():ESP_SOCKET_SERIAL_CLIENT);
|
||||
log_esp3d("Processing file client is %d",
|
||||
output ? output->client() : ESP_SOCKET_SERIAL_CLIENT);
|
||||
_outputStream.client(output ? output->client() : ESP_SOCKET_SERIAL_CLIENT);
|
||||
#endif // COMMUNICATION_PROTOCOL
|
||||
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
log_esp3d("Processing file client is %d", output?output->client():ESP_SERIAL_CLIENT);
|
||||
log_esp3d("Processing file client is %d",
|
||||
output ? output->client() : ESP_SERIAL_CLIENT);
|
||||
_outputStream.client(output ? output->client() : ESP_SERIAL_CLIENT);
|
||||
#endif // COMMUNICATION_PROTOCOL
|
||||
// sanity check
|
||||
@ -555,14 +544,16 @@ bool GcodeHost::processFile(const char * filename, level_authenticate_type auth_
|
||||
if (_fileName.startsWith(ESP_SD_FS_HEADER)) {
|
||||
log_esp3d("Processing SD file");
|
||||
target_found = true;
|
||||
_fileName= _fileName.substring(strlen(ESP_SD_FS_HEADER),_fileName.length());
|
||||
_fileName =
|
||||
_fileName.substring(strlen(ESP_SD_FS_HEADER), _fileName.length());
|
||||
_fsType = TYPE_SD_STREAM;
|
||||
}
|
||||
#endif // SD_DEVICE
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
if (!target_found && _fileName.startsWith(ESP_FLASH_FS_HEADER)) {
|
||||
target_found = true;
|
||||
_fileName= _fileName.substring(strlen(ESP_FLASH_FS_HEADER),_fileName.length());
|
||||
_fileName =
|
||||
_fileName.substring(strlen(ESP_FLASH_FS_HEADER), _fileName.length());
|
||||
log_esp3d("Processing /FS file %s", _fileName.c_str());
|
||||
_fsType = TYPE_FS_STREAM;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
// #define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if defined(HTTP_FEATURE) && defined(SD_DEVICE)
|
||||
#include "../http_server.h"
|
||||
|
@ -26,8 +26,9 @@
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WebServer.h>
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
#include "../../filesystem/esp_filesystem.h"
|
||||
#include "../../authentication/authentication_service.h"
|
||||
#include "../../filesystem/esp_filesystem.h"
|
||||
|
||||
#if defined(SD_DEVICE)
|
||||
#include "../../filesystem/esp_sd.h"
|
||||
#endif // SD_DEVICE
|
||||
@ -38,8 +39,7 @@
|
||||
#endif // ESP3DLIB_ENV && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
|
||||
// Handle not registred path on FS neither SD ///////////////////////
|
||||
void HTTP_Server:: handle_not_found()
|
||||
{
|
||||
void HTTP_Server::handle_not_found() {
|
||||
if (AuthenticationService::authenticated_level() == LEVEL_GUEST) {
|
||||
_webserver->send(401, "text/plain", "Wrong authentication!");
|
||||
return;
|
||||
@ -49,7 +49,8 @@ void HTTP_Server:: handle_not_found()
|
||||
String pathWithGz = path + ".gz";
|
||||
log_esp3d("URI: %s", path.c_str());
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
if(ESP_FileSystem::exists(pathWithGz.c_str()) || ESP_FileSystem::exists(path.c_str())) {
|
||||
if (ESP_FileSystem::exists(pathWithGz.c_str()) ||
|
||||
ESP_FileSystem::exists(path.c_str())) {
|
||||
log_esp3d("Path found `%s`", path.c_str());
|
||||
if (ESP_FileSystem::exists(pathWithGz.c_str())) {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
@ -57,13 +58,14 @@ void HTTP_Server:: handle_not_found()
|
||||
log_esp3d("Path is gz `%s`", path.c_str());
|
||||
}
|
||||
if (!StreamFSFile(path.c_str(), contentType.c_str())) {
|
||||
log_esp3d("Stream `%s` failed", path.c_str());
|
||||
log_esp3d_e("Stream `%s` failed", path.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (path == "favicon.ico" || path == "/favicon.ico") {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
_webserver->send_P(200,"image/x-icon",(const char *)favicon,favicon_size);
|
||||
_webserver->send_P(200, "image/x-icon", (const char *)favicon,
|
||||
favicon_size);
|
||||
return;
|
||||
}
|
||||
#endif // #if defined (FILESYSTEM_FEATURE)
|
||||
@ -75,7 +77,8 @@ void HTTP_Server:: handle_not_found()
|
||||
if (ESP_SD::accessFS()) {
|
||||
if (ESP_SD::getState(true) != ESP_SDCARD_NOT_PRESENT) {
|
||||
ESP_SD::setState(ESP_SDCARD_BUSY);
|
||||
if(ESP_SD::exists(pathWithGz.c_str()) || ESP_SD::exists(path.c_str())) {
|
||||
if (ESP_SD::exists(pathWithGz.c_str()) ||
|
||||
ESP_SD::exists(path.c_str())) {
|
||||
if (ESP_SD::exists(pathWithGz.c_str())) {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
path = pathWithGz;
|
||||
@ -84,7 +87,7 @@ void HTTP_Server:: handle_not_found()
|
||||
Serial2Socket.pause();
|
||||
#endif // ESP3DLIB_ENV && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
if (!StreamSDFile(path.c_str(), contentType.c_str())) {
|
||||
log_esp3d("Stream `%s` failed", path.c_str());
|
||||
log_esp3d_e("Stream `%s` failed", path.c_str());
|
||||
}
|
||||
#if defined(ESP3DLIB_ENV) && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
Serial2Socket.pause(false);
|
||||
@ -103,19 +106,19 @@ void HTTP_Server:: handle_not_found()
|
||||
path = "/404.htm";
|
||||
contentType = getContentType(path.c_str());
|
||||
pathWithGz = path + ".gz";
|
||||
if(ESP_FileSystem::exists(pathWithGz.c_str()) || ESP_FileSystem::exists(path.c_str())) {
|
||||
if (ESP_FileSystem::exists(pathWithGz.c_str()) ||
|
||||
ESP_FileSystem::exists(path.c_str())) {
|
||||
if (ESP_FileSystem::exists(pathWithGz.c_str())) {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
path = pathWithGz;
|
||||
}
|
||||
if (!StreamFSFile(path.c_str(), contentType.c_str())) {
|
||||
log_esp3d("Stream `%s` failed", path.c_str());
|
||||
log_esp3d_e("Stream `%s` failed", path.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif // FILESYSTEM_FEATURE
|
||||
// let's keep simple just send minimum
|
||||
_webserver->send(404);
|
||||
|
||||
}
|
||||
#endif // HTTP_FEATURE
|
||||
|
@ -30,8 +30,7 @@
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
#include "../../filesystem/esp_filesystem.h"
|
||||
// Root of Webserver/////////////////////////////////////////////////////
|
||||
void HTTP_Server::handle_root()
|
||||
{
|
||||
void HTTP_Server::handle_root() {
|
||||
String path = ESP3D_HOST_PATH;
|
||||
// Some sanity check
|
||||
if (path[0] != '/') {
|
||||
@ -44,7 +43,10 @@ void HTTP_Server::handle_root()
|
||||
String contentType = getContentType(path.c_str());
|
||||
String pathWithGz = path + ".gz";
|
||||
// if have a index.html or gzip version this is default root page
|
||||
if((ESP_FileSystem::exists(pathWithGz.c_str()) || ESP_FileSystem::exists(path.c_str())) && !_webserver->hasArg("forcefallback") && _webserver->arg("forcefallback")!="yes") {
|
||||
if ((ESP_FileSystem::exists(pathWithGz.c_str()) ||
|
||||
ESP_FileSystem::exists(path.c_str())) &&
|
||||
!_webserver->hasArg("forcefallback") &&
|
||||
_webserver->arg("forcefallback") != "yes") {
|
||||
log_esp3d("Path found `%s`", path.c_str());
|
||||
if (ESP_FileSystem::exists(pathWithGz.c_str())) {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
@ -52,12 +54,13 @@ void HTTP_Server::handle_root()
|
||||
log_esp3d("Path is gz `%s`", path.c_str());
|
||||
}
|
||||
if (!StreamFSFile(path.c_str(), contentType.c_str())) {
|
||||
log_esp3d("Stream `%s` failed", path.c_str());
|
||||
log_esp3d_e("Stream `%s` failed", path.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
// if no lets launch the default content
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
_webserver->send_P(200,"text/html",(const char *)tool_html_gz,tool_html_gz_size);
|
||||
_webserver->send_P(200, "text/html", (const char *)tool_html_gz,
|
||||
tool_html_gz_size);
|
||||
}
|
||||
#endif // HTTP_FEATURE
|
||||
|
@ -17,7 +17,7 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if defined(HTTP_FEATURE) && defined(SD_DEVICE)
|
||||
#include "../http_server.h"
|
||||
@ -27,8 +27,9 @@
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WebServer.h>
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
#include "../../filesystem/esp_sd.h"
|
||||
#include "../../authentication/authentication_service.h"
|
||||
#include "../../filesystem/esp_sd.h"
|
||||
|
||||
#ifdef ESP_BENCHMARK_FEATURE
|
||||
#include "../../../core/benchmark.h"
|
||||
#endif // ESP_BENCHMARK_FEATURE
|
||||
@ -38,15 +39,15 @@
|
||||
#include "../../websocket/websocket_server.h"
|
||||
|
||||
// SD files uploader handle
|
||||
void HTTP_Server::SDFileupload ()
|
||||
{
|
||||
void HTTP_Server::SDFileupload() {
|
||||
#ifdef ESP_BENCHMARK_FEATURE
|
||||
static uint64_t bench_start;
|
||||
static size_t bench_transfered;
|
||||
#endif // ESP_BENCHMARK_FEATURE
|
||||
static uint64_t last_WS_update;
|
||||
// get authentication status
|
||||
level_authenticate_type auth_level= AuthenticationService::authenticated_level();
|
||||
level_authenticate_type auth_level =
|
||||
AuthenticationService::authenticated_level();
|
||||
static String filename;
|
||||
static ESP_SDFile fsUploadFile;
|
||||
// Guest cannot upload - only admin
|
||||
@ -56,7 +57,8 @@ void HTTP_Server::SDFileupload ()
|
||||
} else {
|
||||
HTTPUpload& upload = _webserver->upload();
|
||||
String upload_filename = upload.filename;
|
||||
if ((_upload_status != UPLOAD_STATUS_FAILED) || (upload.status == UPLOAD_FILE_START)) {
|
||||
if ((_upload_status != UPLOAD_STATUS_FAILED) ||
|
||||
(upload.status == UPLOAD_FILE_START)) {
|
||||
#if defined(ESP3DLIB_ENV) && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
Serial2Socket.pause(true);
|
||||
#endif // ESP3DLIB_ENV && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
@ -116,7 +118,8 @@ void HTTP_Server::SDFileupload ()
|
||||
String currentPath = path.substring(0, pos);
|
||||
if (!ESP_SD::exists(currentPath.c_str())) {
|
||||
if (!ESP_SD::mkdir(currentPath.c_str())) {
|
||||
pushError(ESP_ERROR_FILE_CREATION, "Failed to create path", 500);
|
||||
pushError(ESP_ERROR_FILE_CREATION, "Failed to create path",
|
||||
500);
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
break;
|
||||
}
|
||||
@ -127,7 +130,6 @@ void HTTP_Server::SDFileupload ()
|
||||
} else {
|
||||
pos = path.indexOf('/', pos + 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,9 +161,8 @@ void HTTP_Server::SDFileupload ()
|
||||
// if no set cancel flag
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
pushError(ESP_ERROR_FILE_CREATION, "File creation failed");
|
||||
log_esp3d("File creation failed");
|
||||
log_esp3d_e("File creation failed");
|
||||
}
|
||||
|
||||
}
|
||||
// Upload write
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
@ -179,14 +180,15 @@ void HTTP_Server::SDFileupload ()
|
||||
int writeddatanb = fsUploadFile.write(upload.buf, upload.currentSize);
|
||||
if (upload.currentSize != (size_t)writeddatanb) {
|
||||
// we have a problem set flag UPLOAD_STATUS_FAILED
|
||||
log_esp3d("File write failed du to mismatch size %d vs %d", writeddatanb, upload.currentSize);
|
||||
log_esp3d_e("File write failed du to mismatch size %d vs %d",
|
||||
writeddatanb, upload.currentSize);
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
pushError(ESP_ERROR_FILE_WRITE, "File write failed");
|
||||
}
|
||||
} else {
|
||||
// we have a problem set flag UPLOAD_STATUS_FAILED
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
log_esp3d("Error detected");
|
||||
log_esp3d_e("Error detected");
|
||||
pushError(ESP_ERROR_FILE_WRITE, "File write failed");
|
||||
}
|
||||
// Upload end
|
||||
|
@ -17,7 +17,7 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if defined(HTTP_FEATURE) && defined(FILESYSTEM_FEATURE)
|
||||
#include "../http_server.h"
|
||||
@ -27,27 +27,26 @@
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WebServer.h>
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
#include "../../filesystem/esp_filesystem.h"
|
||||
#include "../../authentication/authentication_service.h"
|
||||
#include "../../filesystem/esp_filesystem.h"
|
||||
|
||||
#if defined(ESP3DLIB_ENV) && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#include "../../serial2socket/serial2socket.h"
|
||||
#endif // ESP3DLIB_ENV && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
|
||||
|
||||
|
||||
#ifdef ESP_BENCHMARK_FEATURE
|
||||
#include "../../../core/benchmark.h"
|
||||
#endif // ESP_BENCHMARK_FEATURE
|
||||
|
||||
// FS files uploader handle
|
||||
void HTTP_Server::FSFileupload ()
|
||||
{
|
||||
void HTTP_Server::FSFileupload() {
|
||||
#ifdef ESP_BENCHMARK_FEATURE
|
||||
static uint64_t bench_start;
|
||||
static size_t bench_transfered;
|
||||
#endif // ESP_BENCHMARK_FEATURE
|
||||
// get authentication status
|
||||
level_authenticate_type auth_level= AuthenticationService::authenticated_level();
|
||||
level_authenticate_type auth_level =
|
||||
AuthenticationService::authenticated_level();
|
||||
static String filename;
|
||||
static ESP_File fsUploadFile;
|
||||
// Guest cannot upload - only admin
|
||||
@ -57,7 +56,8 @@ void HTTP_Server::FSFileupload ()
|
||||
} else {
|
||||
HTTPUpload& upload = _webserver->upload();
|
||||
String upload_filename = upload.filename;
|
||||
if ((_upload_status != UPLOAD_STATUS_FAILED) || (upload.status == UPLOAD_FILE_START)) {
|
||||
if ((_upload_status != UPLOAD_STATUS_FAILED) ||
|
||||
(upload.status == UPLOAD_FILE_START)) {
|
||||
#if defined(ESP3DLIB_ENV) && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
Serial2Socket.pause();
|
||||
#endif // ESP3DLIB_ENV && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
@ -99,7 +99,8 @@ void HTTP_Server::FSFileupload ()
|
||||
String currentPath = path.substring(0, pos);
|
||||
if (!ESP_FileSystem::exists(currentPath.c_str())) {
|
||||
if (!ESP_FileSystem::mkdir(currentPath.c_str())) {
|
||||
pushError(ESP_ERROR_FILE_CREATION, "Failed to create path", 500);
|
||||
pushError(ESP_ERROR_FILE_CREATION, "Failed to create path",
|
||||
500);
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
break;
|
||||
}
|
||||
@ -110,7 +111,6 @@ void HTTP_Server::FSFileupload ()
|
||||
} else {
|
||||
pos = path.indexOf('/', pos + 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,8 @@ void HTTP_Server::FSFileupload ()
|
||||
}
|
||||
String sizeargname = upload.filename + "S";
|
||||
if (_webserver->hasArg(sizeargname.c_str())) {
|
||||
size_t freespace = ESP_FileSystem::totalBytes() - ESP_FileSystem::usedBytes();
|
||||
size_t freespace =
|
||||
ESP_FileSystem::totalBytes() - ESP_FileSystem::usedBytes();
|
||||
size_t filesize = _webserver->arg(sizeargname.c_str()).toInt();
|
||||
if (freespace < filesize) {
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
@ -138,7 +139,6 @@ void HTTP_Server::FSFileupload ()
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
pushError(ESP_ERROR_FILE_CREATION, "File creation failed");
|
||||
}
|
||||
|
||||
}
|
||||
// Upload write
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
@ -148,7 +148,8 @@ void HTTP_Server::FSFileupload ()
|
||||
#ifdef ESP_BENCHMARK_FEATURE
|
||||
bench_transfered += upload.currentSize;
|
||||
#endif // ESP_BENCHMARK_FEATURE
|
||||
if(upload.currentSize != fsUploadFile.write(upload.buf, upload.currentSize)) {
|
||||
if (upload.currentSize !=
|
||||
fsUploadFile.write(upload.buf, upload.currentSize)) {
|
||||
// we have a problem set flag UPLOAD_STATUS_FAILED
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
pushError(ESP_ERROR_FILE_WRITE, "File write failed");
|
||||
@ -174,9 +175,11 @@ void HTTP_Server::FSFileupload ()
|
||||
uint32_t filesize = fsUploadFile.size();
|
||||
_upload_status = UPLOAD_STATUS_SUCCESSFUL;
|
||||
if (_webserver->hasArg(sizeargname.c_str())) {
|
||||
log_esp3d("Size check: %s vs %s", _webserver->arg (sizeargname.c_str()).c_str(), String(filesize).c_str());
|
||||
log_esp3d("Size check: %s vs %s",
|
||||
_webserver->arg(sizeargname.c_str()).c_str(),
|
||||
String(filesize).c_str());
|
||||
if (_webserver->arg(sizeargname.c_str()) != String(filesize)) {
|
||||
log_esp3d("Size Error");
|
||||
log_esp3d_e("Size Error");
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
pushError(ESP_ERROR_SIZE, "File upload failed");
|
||||
}
|
||||
@ -186,7 +189,7 @@ void HTTP_Server::FSFileupload ()
|
||||
}
|
||||
} else {
|
||||
// we have a problem set flag UPLOAD_STATUS_FAILED
|
||||
log_esp3d("Close Error");
|
||||
log_esp3d_e("Close Error");
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
pushError(ESP_ERROR_FILE_CLOSE, "File close failed");
|
||||
}
|
||||
@ -197,7 +200,6 @@ void HTTP_Server::FSFileupload ()
|
||||
} else {
|
||||
if (_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
// #define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
|
||||
#ifdef MDNS_FEATURE
|
||||
@ -97,38 +97,38 @@ void mDNS_Service::end() {
|
||||
if (_hMDNSServiceQuery) {
|
||||
log_esp3d("Remove mdns service for %s", _hostname.c_str());
|
||||
if (!MDNS.removeServiceQuery(_hMDNSServiceQuery)) {
|
||||
log_esp3d("failed");
|
||||
log_esp3d_e("failed");
|
||||
}
|
||||
}
|
||||
_hMDNSServiceQuery = 0;
|
||||
log_esp3d("Remove mdns for %s", _hostname.c_str());
|
||||
if (!MDNS.removeService(_hostname.c_str(), MDNS_SERVICE_NAME,
|
||||
MDNS_SERVICE_TYPE)) {
|
||||
log_esp3d("failed");
|
||||
log_esp3d_e("failed");
|
||||
}
|
||||
#if defined(HTTP_FEATURE)
|
||||
if (!MDNS.removeService(_hostname.c_str(), "http", "tcp")) {
|
||||
log_esp3d("failed");
|
||||
log_esp3d_e("failed");
|
||||
}
|
||||
#endif // HTTP_FEATURE
|
||||
#if defined(FTP_FEATURE)
|
||||
if (!MDNS.removeService(_hostname.c_str(), "ftp", "tcp")) {
|
||||
log_esp3d("failed");
|
||||
log_esp3d_e("failed");
|
||||
}
|
||||
#endif // FTP_FEATURE
|
||||
#if defined(TELNET_FEATURE)
|
||||
if (!MDNS.removeService(_hostname.c_str(), "telnet", "tcp")) {
|
||||
log_esp3d("failed");
|
||||
log_esp3d_e("failed");
|
||||
}
|
||||
#endif // TELNET_FEATURE
|
||||
#if defined(WEBDAV_FEATURE)
|
||||
if (!MDNS.removeService(_hostname.c_str(), "webdav", "tcp")) {
|
||||
log_esp3d("failed");
|
||||
log_esp3d_e("failed");
|
||||
}
|
||||
#endif // WEBDAV_FEATURE
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
if (!MDNS.removeService(_hostname.c_str(), "websocket", "tcp")) {
|
||||
log_esp3d("failed");
|
||||
log_esp3d_e("failed");
|
||||
}
|
||||
#endif // WS_DATA_FEATURE
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
@ -194,7 +194,7 @@ void mDNS_Service::addESP3DServices(uint16_t port) {
|
||||
if (_hMDNSServiceQuery) {
|
||||
log_esp3d("MDNS Service query services installed.");
|
||||
} else {
|
||||
log_esp3d("MDNS Service query services installation failed.");
|
||||
log_esp3d_e("MDNS Service query services installation failed.");
|
||||
}
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
}
|
||||
|
@ -20,15 +20,14 @@
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#include "mks_service.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../network/netconfig.h"
|
||||
#include "../wifi/wificonfig.h"
|
||||
#include "../telnet/telnet_server.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../http/http_server.h"
|
||||
#include "../network/netconfig.h"
|
||||
#include "../serial/serial_service.h"
|
||||
#include "../telnet/telnet_server.h"
|
||||
#include "../wifi/wificonfig.h"
|
||||
#include "mks_service.h"
|
||||
|
||||
// Flag Pins
|
||||
#define ESP_FLAG_PIN 0
|
||||
@ -62,7 +61,6 @@
|
||||
#define MKS_FRAME_CLOUD_DISCONNECTED_STATE (char)0x10
|
||||
#define MKS_FRAME_CLOUD_DISABLED_STATE (char)0x00
|
||||
|
||||
|
||||
// Data types
|
||||
#define MKS_FRAME_DATA_NETWORK_TYPE (char)0x0
|
||||
#define MKS_FRAME_DATA_COMMAND_TYPE (char)0x1
|
||||
@ -106,56 +104,43 @@ uint8_t MKSService::_uploadStatus = UNKNOW_STATE;
|
||||
long MKSService::_commandBaudRate = 115200;
|
||||
bool MKSService::_uploadMode = false;
|
||||
|
||||
bool MKSService::isHead(const char c)
|
||||
{
|
||||
return (c==MKS_FRAME_HEAD_FLAG);
|
||||
}
|
||||
bool MKSService::isTail(const char c)
|
||||
{
|
||||
return (c==MKS_FRAME_TAIL_FLAG);
|
||||
}
|
||||
bool MKSService::isCommand(const char c)
|
||||
{
|
||||
return (c==MKS_TYPE_TRANSFER);
|
||||
}
|
||||
bool MKSService::isFrame(const char c)
|
||||
{
|
||||
bool MKSService::isHead(const char c) { return (c == MKS_FRAME_HEAD_FLAG); }
|
||||
bool MKSService::isTail(const char c) { return (c == MKS_FRAME_TAIL_FLAG); }
|
||||
bool MKSService::isCommand(const char c) { return (c == MKS_TYPE_TRANSFER); }
|
||||
bool MKSService::isFrame(const char c) {
|
||||
if ((c >= MKS_TYPE_NET) && (c <= MKS_TYPE_WIFI_CTRL)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool MKSService::begin()
|
||||
{
|
||||
bool MKSService::begin() {
|
||||
// setup the pins
|
||||
pinMode(BOARD_FLAG_PIN, INPUT);
|
||||
pinMode(ESP_FLAG_PIN, OUTPUT);
|
||||
_started = true;
|
||||
// max size is 21
|
||||
sprintf (_moduleId, "HJNLM000%02X%02X%02X%02X%02X%02X", WiFi.macAddress()[0], WiFi.macAddress()[1], WiFi.macAddress()[2], WiFi.macAddress()[3], WiFi.macAddress()[4], WiFi.macAddress()[5]);
|
||||
sprintf(_moduleId, "HJNLM000%02X%02X%02X%02X%02X%02X", WiFi.macAddress()[0],
|
||||
WiFi.macAddress()[1], WiFi.macAddress()[2], WiFi.macAddress()[3],
|
||||
WiFi.macAddress()[4], WiFi.macAddress()[5]);
|
||||
commandMode(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MKSService::commandMode(bool fromSettings)
|
||||
{
|
||||
void MKSService::commandMode(bool fromSettings) {
|
||||
if (fromSettings) {
|
||||
_commandBaudRate = Settings_ESP3D::read_uint32(ESP_BAUD_RATE);
|
||||
}
|
||||
log_esp3d("Cmd Mode");
|
||||
_uploadMode = false;
|
||||
serial_service.updateBaudRate(_commandBaudRate);
|
||||
|
||||
}
|
||||
void MKSService::uploadMode()
|
||||
{
|
||||
void MKSService::uploadMode() {
|
||||
log_esp3d("Upload Mode");
|
||||
_uploadMode = true;
|
||||
serial_service.updateBaudRate(UPLOAD_BAUD_RATE);
|
||||
}
|
||||
|
||||
uint MKSService::getFragmentID(uint32_t fragmentNumber, bool isLast)
|
||||
{
|
||||
uint MKSService::getFragmentID(uint32_t fragmentNumber, bool isLast) {
|
||||
log_esp3d("Fragment: %d %s", fragmentNumber, isLast ? " is last" : "");
|
||||
if (isLast) {
|
||||
fragmentNumber |= (1 << 31);
|
||||
@ -166,8 +151,7 @@ uint MKSService::getFragmentID(uint32_t fragmentNumber, bool isLast)
|
||||
return fragmentNumber;
|
||||
}
|
||||
|
||||
bool MKSService::sendFirstFragment(const char* filename, size_t filesize)
|
||||
{
|
||||
bool MKSService::sendFirstFragment(const char *filename, size_t filesize) {
|
||||
uint fileNameLen = strlen(filename);
|
||||
uint dataLen = fileNameLen + 5;
|
||||
clearFrame();
|
||||
@ -208,9 +192,8 @@ bool MKSService::sendFirstFragment(const char* filename, size_t filesize)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool MKSService::sendFragment(const uint8_t * dataFrame, const size_t dataSize,uint fragmentID)
|
||||
{
|
||||
bool MKSService::sendFragment(const uint8_t *dataFrame, const size_t dataSize,
|
||||
uint fragmentID) {
|
||||
uint dataLen = dataSize + 4;
|
||||
log_esp3d("Fragment datalen:%d", dataSize);
|
||||
// Head Flag
|
||||
@ -245,16 +228,14 @@ bool MKSService::sendFragment(const uint8_t * dataFrame, const size_t dataSize,u
|
||||
sendFrameDone();
|
||||
return true;
|
||||
}
|
||||
log_esp3d("Error with size sent");
|
||||
log_esp3d_e("Error with size sent");
|
||||
}
|
||||
log_esp3d("Failed");
|
||||
log_esp3d_e("Failed");
|
||||
sendFrameDone();
|
||||
return false;
|
||||
}
|
||||
|
||||
void MKSService::sendWifiHotspots()
|
||||
{
|
||||
|
||||
void MKSService::sendWifiHotspots() {
|
||||
uint8_t ssid_name_length;
|
||||
uint dataOffset = 1;
|
||||
uint8_t total_hotspots = 0;
|
||||
@ -281,10 +262,11 @@ void MKSService::sendWifiHotspots()
|
||||
}
|
||||
signal_rssi = WiFi.RSSI(i);
|
||||
// Print SSID and RSSI for each network found
|
||||
log_esp3d("%d: %s (%d) %s",i + 1,WiFi.SSID(i).c_str(), signal_rssi,(WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*" );
|
||||
log_esp3d("%d: %s (%d) %s", i + 1, WiFi.SSID(i).c_str(), signal_rssi,
|
||||
(WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
|
||||
ssid_name_length = WiFi.SSID(i).length();
|
||||
if (ssid_name_length > MAX_SSID_LENGTH) {
|
||||
log_esp3d("Name too long, ignored" );
|
||||
log_esp3d_e("Name too long, ignored");
|
||||
continue;
|
||||
}
|
||||
if (signal_rssi < MIN_RSSI) {
|
||||
@ -295,7 +277,8 @@ void MKSService::sendWifiHotspots()
|
||||
for (uint8_t p = 0; p < ssid_name_length; p++) {
|
||||
_frame[MKS_FRAME_DATA_OFFSET + dataOffset + 1 + p] = WiFi.SSID(i)[p];
|
||||
}
|
||||
_frame[MKS_FRAME_DATA_OFFSET + dataOffset + ssid_name_length + 1] = WiFi.RSSI(i);
|
||||
_frame[MKS_FRAME_DATA_OFFSET + dataOffset + ssid_name_length + 1] =
|
||||
WiFi.RSSI(i);
|
||||
dataOffset += ssid_name_length + 2;
|
||||
total_hotspots++;
|
||||
}
|
||||
@ -313,10 +296,10 @@ void MKSService::sendWifiHotspots()
|
||||
log_esp3d("Ok");
|
||||
sendFrameDone();
|
||||
} else {
|
||||
log_esp3d("Send scan failed");
|
||||
log_esp3d_e("Send scan failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("Cannot send scan");
|
||||
log_esp3d_e("Cannot send scan");
|
||||
}
|
||||
// clean memory
|
||||
WiFi.scanDelete();
|
||||
@ -326,8 +309,8 @@ void MKSService::sendWifiHotspots()
|
||||
sendFrameDone();
|
||||
}
|
||||
|
||||
void MKSService::handleFrame(const uint8_t type, const uint8_t * dataFrame, const size_t dataSize )
|
||||
{
|
||||
void MKSService::handleFrame(const uint8_t type, const uint8_t *dataFrame,
|
||||
const size_t dataSize) {
|
||||
log_esp3d("Command is %d", type);
|
||||
switch (type) {
|
||||
// wifi setup
|
||||
@ -378,12 +361,12 @@ void MKSService::handleFrame(const uint8_t type, const uint8_t * dataFrame, cons
|
||||
messageWiFiControl(dataFrame, dataSize);
|
||||
break;
|
||||
default:
|
||||
log_esp3d("Unknow type");
|
||||
log_esp3d_e("Unknow type");
|
||||
}
|
||||
}
|
||||
|
||||
void MKSService::messageWiFiControl(const uint8_t * dataFrame, const size_t dataSize )
|
||||
{
|
||||
void MKSService::messageWiFiControl(const uint8_t *dataFrame,
|
||||
const size_t dataSize) {
|
||||
if (dataSize != 1) {
|
||||
return;
|
||||
}
|
||||
@ -408,12 +391,12 @@ void MKSService::messageWiFiControl(const uint8_t * dataFrame, const size_t data
|
||||
Settings_ESP3D::reset(true);
|
||||
break;
|
||||
default:
|
||||
log_esp3d("WiFi control flag not supported");
|
||||
log_esp3d_e("WiFi control flag not supported");
|
||||
}
|
||||
}
|
||||
// Exception handle - but actually not used
|
||||
void MKSService::messageException(const uint8_t * dataFrame, const size_t dataSize )
|
||||
{
|
||||
void MKSService::messageException(const uint8_t *dataFrame,
|
||||
const size_t dataSize) {
|
||||
if (dataSize != 1) {
|
||||
return;
|
||||
}
|
||||
@ -422,12 +405,12 @@ void MKSService::messageException(const uint8_t * dataFrame, const size_t dataSi
|
||||
log_esp3d("Tranfer: %s", dataFrame[0] == ERROR_STATE ? "Error" : "Success");
|
||||
} else {
|
||||
_uploadStatus = UNKNOW_STATE;
|
||||
log_esp3d("Tranfer state unknown" );
|
||||
log_esp3d_e("Tranfer state unknown");
|
||||
}
|
||||
}
|
||||
|
||||
void MKSService::messageWiFiConfig(const uint8_t * dataFrame, const size_t dataSize )
|
||||
{
|
||||
void MKSService::messageWiFiConfig(const uint8_t *dataFrame,
|
||||
const size_t dataSize) {
|
||||
String ssid;
|
||||
String password;
|
||||
String savedSsid;
|
||||
@ -435,23 +418,25 @@ void MKSService::messageWiFiConfig(const uint8_t * dataFrame, const size_t dataS
|
||||
bool needrestart = false;
|
||||
// Sanity check
|
||||
if (dataSize < 2) {
|
||||
log_esp3d("Invalid data");
|
||||
log_esp3d_e("Invalid data");
|
||||
return;
|
||||
}
|
||||
if((dataFrame[0] != MKS_FRAME_NETWORK_AP_MODE) && (dataFrame[0] != MKS_FRAME_NETWORK_STA_MODE)) {
|
||||
log_esp3d("Invalid mode");
|
||||
if ((dataFrame[0] != MKS_FRAME_NETWORK_AP_MODE) &&
|
||||
(dataFrame[0] != MKS_FRAME_NETWORK_STA_MODE)) {
|
||||
log_esp3d_e("Invalid mode");
|
||||
return;
|
||||
}
|
||||
if ((dataFrame[1] > dataSize - 3) || (dataFrame[1]==0) || (dataFrame[1]>MAX_SSID_LENGTH)) {
|
||||
log_esp3d("Invalid ssid size");
|
||||
if ((dataFrame[1] > dataSize - 3) || (dataFrame[1] == 0) ||
|
||||
(dataFrame[1] > MAX_SSID_LENGTH)) {
|
||||
log_esp3d_e("Invalid ssid size");
|
||||
return;
|
||||
}
|
||||
if ((uint)(dataFrame[1] + 3) > dataSize) {
|
||||
log_esp3d("Overflow password size");
|
||||
log_esp3d_e("Overflow password size");
|
||||
return;
|
||||
}
|
||||
if ((dataFrame[dataFrame[1] + 2]) > MAX_PASSWORD_LENGTH) {
|
||||
log_esp3d("Invalid password size");
|
||||
log_esp3d_e("Invalid password size");
|
||||
return;
|
||||
}
|
||||
// get SSID and password
|
||||
@ -495,7 +480,6 @@ void MKSService::messageWiFiConfig(const uint8_t * dataFrame, const size_t dataS
|
||||
// change also to DHCP for new value
|
||||
Settings_ESP3D::write_byte(ESP_STA_IP_MODE, DHCP_MODE);
|
||||
}
|
||||
|
||||
}
|
||||
if (needrestart) {
|
||||
log_esp3d("Modifications done - restarting network");
|
||||
@ -503,8 +487,7 @@ void MKSService::messageWiFiConfig(const uint8_t * dataFrame, const size_t dataS
|
||||
}
|
||||
}
|
||||
|
||||
bool MKSService::canSendFrame()
|
||||
{
|
||||
bool MKSService::canSendFrame() {
|
||||
log_esp3d("Is board ready for frame?");
|
||||
digitalWrite(ESP_FLAG_PIN, BOARD_READY_FLAG_VALUE);
|
||||
uint32_t startTime = millis();
|
||||
@ -519,14 +502,11 @@ bool MKSService::canSendFrame()
|
||||
return false;
|
||||
}
|
||||
|
||||
void MKSService::sendFrameDone()
|
||||
{
|
||||
void MKSService::sendFrameDone() {
|
||||
digitalWrite(ESP_FLAG_PIN, !BOARD_READY_FLAG_VALUE);
|
||||
|
||||
}
|
||||
|
||||
bool MKSService::sendGcodeFrame(const char* cmd)
|
||||
{
|
||||
bool MKSService::sendGcodeFrame(const char *cmd) {
|
||||
if (_uploadMode) {
|
||||
return false;
|
||||
}
|
||||
@ -545,7 +525,8 @@ bool MKSService::sendGcodeFrame(const char* cmd)
|
||||
_frame[MKS_FRAME_DATA_OFFSET + strlen(tmp.c_str()) + 1] = '\n';
|
||||
_frame[MKS_FRAME_DATA_OFFSET + strlen(tmp.c_str()) + 2] = MKS_FRAME_TAIL_FLAG;
|
||||
_frame[MKS_FRAME_DATALEN_OFFSET] = (strlen(tmp.c_str()) + 2) & 0xff;
|
||||
_frame[MKS_FRAME_DATALEN_OFFSET+1] = ((strlen(tmp.c_str())+2) >> 8) & 0xff;
|
||||
_frame[MKS_FRAME_DATALEN_OFFSET + 1] =
|
||||
((strlen(tmp.c_str()) + 2) >> 8) & 0xff;
|
||||
|
||||
log_esp3d("Size of data in frame %d ", strlen(tmp.c_str()) + 2);
|
||||
// for (uint i =0; i< strlen(tmp.c_str())+7;i++){
|
||||
@ -554,20 +535,19 @@ bool MKSService::sendGcodeFrame(const char* cmd)
|
||||
|
||||
if (canSendFrame()) {
|
||||
ESP3DOutput output(ESP_SERIAL_CLIENT);
|
||||
if (output.write(_frame,strlen(tmp.c_str())+7) == (strlen(tmp.c_str())+7)) {
|
||||
if (output.write(_frame, strlen(tmp.c_str()) + 7) ==
|
||||
(strlen(tmp.c_str()) + 7)) {
|
||||
log_esp3d("Ok");
|
||||
sendFrameDone();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
log_esp3d("Failed");
|
||||
_e("Failed");
|
||||
sendFrameDone();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MKSService::sendNetworkFrame()
|
||||
{
|
||||
|
||||
bool MKSService::sendNetworkFrame() {
|
||||
size_t dataOffset = 0;
|
||||
String s;
|
||||
static uint32_t lastsend = 0;
|
||||
@ -592,7 +572,10 @@ bool MKSService::sendNetworkFrame()
|
||||
_frame[MKS_FRAME_DATA_OFFSET + 1] = ip[1];
|
||||
_frame[MKS_FRAME_DATA_OFFSET + 2] = ip[2];
|
||||
_frame[MKS_FRAME_DATA_OFFSET + 3] = ip[3];
|
||||
log_esp3d("IP %d.%d.%d.%d", _frame[MKS_FRAME_DATA_OFFSET],_frame[MKS_FRAME_DATA_OFFSET + 1],_frame[MKS_FRAME_DATA_OFFSET + 2],_frame[MKS_FRAME_DATA_OFFSET + 3]);
|
||||
log_esp3d("IP %d.%d.%d.%d", _frame[MKS_FRAME_DATA_OFFSET],
|
||||
_frame[MKS_FRAME_DATA_OFFSET + 1],
|
||||
_frame[MKS_FRAME_DATA_OFFSET + 2],
|
||||
_frame[MKS_FRAME_DATA_OFFSET + 3]);
|
||||
//////////////////////////////////
|
||||
// State Segment
|
||||
// Connected state (OK)
|
||||
@ -627,7 +610,8 @@ bool MKSService::sendNetworkFrame()
|
||||
// Wifi_key Segment
|
||||
strcpy((char *)&_frame[dataOffset], s.c_str());
|
||||
dataOffset += s.length();
|
||||
} else if (NetConfig::getMode() == ESP_WIFI_AP || (NetConfig::getMode() == ESP_AP_SETUP)) {
|
||||
} else if (NetConfig::getMode() == ESP_WIFI_AP ||
|
||||
(NetConfig::getMode() == ESP_AP_SETUP)) {
|
||||
log_esp3d("AP Mode");
|
||||
///////////////////////////////////
|
||||
// IP Segment
|
||||
@ -664,7 +648,7 @@ bool MKSService::sendNetworkFrame()
|
||||
dataOffset += s.length();
|
||||
} else {
|
||||
// not supported
|
||||
log_esp3d("Mode not supported : %d ", NetConfig::getMode());
|
||||
log_esp3d_e("Mode not supported : %d ", NetConfig::getMode());
|
||||
return false;
|
||||
}
|
||||
//////////////////////////////////
|
||||
@ -733,28 +717,21 @@ bool MKSService::sendNetworkFrame()
|
||||
}
|
||||
}
|
||||
sendFrameDone();
|
||||
log_esp3d("Failed");
|
||||
log_esp3d_e("Failed");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void MKSService::clearFrame(uint start)
|
||||
{
|
||||
void MKSService::clearFrame(uint start) {
|
||||
memset(&_frame[start], 0, sizeof(_frame) - start);
|
||||
}
|
||||
void MKSService::handle()
|
||||
{
|
||||
void MKSService::handle() {
|
||||
if (_started) {
|
||||
sendNetworkFrame();
|
||||
}
|
||||
// network frame every 10s
|
||||
}
|
||||
void MKSService::end()
|
||||
{
|
||||
_started = false;
|
||||
}
|
||||
|
||||
|
||||
void MKSService::end() { _started = false; }
|
||||
|
||||
#endif // COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
|
@ -40,9 +40,9 @@
|
||||
#if defined(BLUETOOTH_FEATURE)
|
||||
#include "../bluetooth/BT_service.h"
|
||||
#endif // BLUETOOTH_FEATURE
|
||||
#include "netservices.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "netservices.h"
|
||||
|
||||
String NetConfig::_hostname = "";
|
||||
bool NetConfig::_needReconnect2AP = false;
|
||||
@ -51,21 +51,19 @@ bool NetConfig::_started = false;
|
||||
uint8_t NetConfig::_mode = ESP_NO_NETWORK;
|
||||
|
||||
// just simple helper to convert mac address to string
|
||||
char * NetConfig::mac2str (uint8_t mac [8])
|
||||
{
|
||||
char* NetConfig::mac2str(uint8_t mac[8]) {
|
||||
static char macstr[18];
|
||||
if (0 > sprintf (macstr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]) ) {
|
||||
if (0 > sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1],
|
||||
mac[2], mac[3], mac[4], mac[5])) {
|
||||
strcpy(macstr, "00:00:00:00:00:00");
|
||||
}
|
||||
return macstr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper to convert IP string to int
|
||||
*/
|
||||
uint32_t NetConfig::IP_int_from_string(const char * s)
|
||||
{
|
||||
uint32_t NetConfig::IP_int_from_string(const char* s) {
|
||||
uint32_t ip_int = 0;
|
||||
IPAddress ipaddr;
|
||||
if (ipaddr.fromString(s)) {
|
||||
@ -77,8 +75,7 @@ uint32_t NetConfig::IP_int_from_string(const char * s)
|
||||
/**
|
||||
* Helper to convert int to IP string
|
||||
*/
|
||||
String NetConfig::IP_string_from_int(uint32_t ip_int)
|
||||
{
|
||||
String NetConfig::IP_string_from_int(uint32_t ip_int) {
|
||||
IPAddress ipaddr(ip_int);
|
||||
return ipaddr.toString();
|
||||
}
|
||||
@ -87,11 +84,11 @@ String NetConfig::IP_string_from_int(uint32_t ip_int)
|
||||
* Check if Hostname string is valid
|
||||
*/
|
||||
|
||||
bool NetConfig::isHostnameValid (const char * hostname)
|
||||
{
|
||||
bool NetConfig::isHostnameValid(const char* hostname) {
|
||||
// limited size
|
||||
char c;
|
||||
if (strlen (hostname) > MAX_HOSTNAME_LENGTH || strlen (hostname) < MIN_HOSTNAME_LENGTH) {
|
||||
if (strlen(hostname) > MAX_HOSTNAME_LENGTH ||
|
||||
strlen(hostname) < MIN_HOSTNAME_LENGTH) {
|
||||
return false;
|
||||
}
|
||||
// only letter and digit
|
||||
@ -107,12 +104,10 @@ bool NetConfig::isHostnameValid (const char * hostname)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get IP Integer what ever is enabled
|
||||
*/
|
||||
IPAddress NetConfig::localIPAddress()
|
||||
{
|
||||
IPAddress NetConfig::localIPAddress() {
|
||||
IPAddress current_ip = IPAddress(0, 0, 0, 0);
|
||||
#if defined(WIFI_FEATURE)
|
||||
if (WiFi.getMode() == WIFI_STA) {
|
||||
@ -133,8 +128,7 @@ IPAddress NetConfig::localIPAddress()
|
||||
/**
|
||||
* Get IP string what ever is enabled
|
||||
*/
|
||||
String NetConfig::localIP()
|
||||
{
|
||||
String NetConfig::localIP() {
|
||||
static String currentIP = "";
|
||||
#if defined(WIFI_FEATURE)
|
||||
if (WiFi.getMode() == WIFI_STA) {
|
||||
@ -158,16 +152,13 @@ String NetConfig::localIP()
|
||||
* Check if IP string is valid
|
||||
*/
|
||||
|
||||
bool NetConfig::isValidIP(const char * string)
|
||||
{
|
||||
bool NetConfig::isValidIP(const char* string) {
|
||||
IPAddress ip;
|
||||
return ip.fromString(string);
|
||||
}
|
||||
|
||||
|
||||
// wifi event
|
||||
void NetConfig::onWiFiEvent(WiFiEvent_t event)
|
||||
{
|
||||
void NetConfig::onWiFiEvent(WiFiEvent_t event) {
|
||||
ESP3DOutput output(ESP_ALL_CLIENTS);
|
||||
switch (event) {
|
||||
case WIFI_EVENT_STAMODE_CONNECTED:
|
||||
@ -178,18 +169,15 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event)
|
||||
output.printMSG("Disconnected");
|
||||
//_needReconnect2AP = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case WIFI_EVENT_STAMODE_GOT_IP: {
|
||||
#if COMMUNICATION_PROTOCOL != MKS_SERIAL
|
||||
output.printMSG(WiFi.localIP().toString().c_str());
|
||||
#endif // #if COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case WIFI_EVENT_SOFTAPMODE_STACONNECTED: {
|
||||
output.printMSG("New client");
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||
if (_started) {
|
||||
@ -202,18 +190,15 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event)
|
||||
if (Settings_ESP3D::isVerboseBoot()) {
|
||||
output.printMSG("Checking connection");
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED: {
|
||||
output.printMSG("Cable connected");
|
||||
EthConfig::setConnected(true);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED: {
|
||||
output.printMSG("Cable disconnected");
|
||||
EthConfig::setConnected(false);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
output.printMSG(ETH.localIP().toString().c_str());
|
||||
EthConfig::setConnected(true);
|
||||
@ -228,21 +213,14 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void NetConfig::setMode(uint8_t mode)
|
||||
{
|
||||
_mode=mode;
|
||||
}
|
||||
void NetConfig::setMode(uint8_t mode) { _mode = mode; }
|
||||
|
||||
uint8_t NetConfig::getMode()
|
||||
{
|
||||
return _mode;
|
||||
}
|
||||
uint8_t NetConfig::getMode() { return _mode; }
|
||||
|
||||
/**
|
||||
* begin WiFi setup
|
||||
*/
|
||||
bool NetConfig::begin()
|
||||
{
|
||||
bool NetConfig::begin() {
|
||||
bool res = false;
|
||||
// clear everything
|
||||
end();
|
||||
@ -283,7 +261,8 @@ bool NetConfig::begin()
|
||||
return true;
|
||||
}
|
||||
#if defined(WIFI_FEATURE)
|
||||
if ((espMode == ESP_AP_SETUP) || (espMode == ESP_WIFI_AP) || (espMode == ESP_WIFI_STA)) {
|
||||
if ((espMode == ESP_AP_SETUP) || (espMode == ESP_WIFI_AP) ||
|
||||
(espMode == ESP_WIFI_STA)) {
|
||||
output.printMSG("Setup wifi");
|
||||
res = WiFiConfig::begin(espMode);
|
||||
}
|
||||
@ -353,12 +332,13 @@ bool NetConfig::begin()
|
||||
}
|
||||
#endif // WIFI_FEATURE
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
DEBUG_ESP3D_NETWORK_INIT
|
||||
LOG_ESP3D_NETWORK_INIT
|
||||
if (res) {
|
||||
log_esp3d("Network config started");
|
||||
|
||||
} else {
|
||||
end();
|
||||
log_esp3d("Network config failed");
|
||||
log_esp3d_e("Network config failed");
|
||||
}
|
||||
ESP3DOutput::toScreen(ESP_OUTPUT_IP_ADDRESS, nullptr);
|
||||
return res;
|
||||
@ -368,10 +348,9 @@ bool NetConfig::begin()
|
||||
* End WiFi
|
||||
*/
|
||||
|
||||
void NetConfig::end()
|
||||
{
|
||||
void NetConfig::end() {
|
||||
NetServices::end();
|
||||
DEBUG_ESP3D_NETWORK_END
|
||||
LOG_ESP3D_NETWORK_END
|
||||
_mode = ESP_NO_NETWORK;
|
||||
#if defined(WIFI_FEATURE)
|
||||
WiFiConfig::end();
|
||||
@ -389,8 +368,7 @@ void NetConfig::end()
|
||||
_started = false;
|
||||
}
|
||||
|
||||
const char* NetConfig::hostname(bool fromsettings)
|
||||
{
|
||||
const char* NetConfig::hostname(bool fromsettings) {
|
||||
if (fromsettings) {
|
||||
_hostname = Settings_ESP3D::read_string(ESP_HOSTNAME);
|
||||
return _hostname.c_str();
|
||||
@ -419,12 +397,10 @@ const char* NetConfig::hostname(bool fromsettings)
|
||||
* Handle not critical actions that must be done in sync environement
|
||||
*/
|
||||
|
||||
void NetConfig::handle()
|
||||
{
|
||||
void NetConfig::handle() {
|
||||
if (_started) {
|
||||
#if defined(WIFI_FEATURE)
|
||||
if (_needReconnect2AP) {
|
||||
|
||||
if (WiFi.getMode() != WIFI_OFF) {
|
||||
begin();
|
||||
}
|
||||
@ -439,16 +415,18 @@ void NetConfig::handle()
|
||||
#endif // BLUETOOTH_FEATURE
|
||||
NetServices::handle();
|
||||
// Debug
|
||||
DEBUG_ESP3D_NETWORK_HANDLE
|
||||
LOG_ESP3D_NETWORK_HANDLE
|
||||
}
|
||||
}
|
||||
|
||||
bool NetConfig::isIPModeDHCP (uint8_t mode)
|
||||
{
|
||||
bool NetConfig::isIPModeDHCP(uint8_t mode) {
|
||||
bool started = false;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
tcpip_adapter_dhcp_status_t dhcp_status;
|
||||
tcpip_adapter_dhcpc_get_status ((mode == ESP_WIFI_STA)?TCPIP_ADAPTER_IF_STA:(mode == ESP_WIFI_AP)?TCPIP_ADAPTER_IF_AP:TCPIP_ADAPTER_IF_ETH, &dhcp_status);
|
||||
tcpip_adapter_dhcpc_get_status((mode == ESP_WIFI_STA) ? TCPIP_ADAPTER_IF_STA
|
||||
: (mode == ESP_WIFI_AP) ? TCPIP_ADAPTER_IF_AP
|
||||
: TCPIP_ADAPTER_IF_ETH,
|
||||
&dhcp_status);
|
||||
started = (dhcp_status == TCPIP_ADAPTER_DHCP_STARTED);
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
@ -458,12 +436,14 @@ bool NetConfig::isIPModeDHCP (uint8_t mode)
|
||||
return started;
|
||||
}
|
||||
|
||||
bool NetConfig::isDHCPServer (uint8_t mode)
|
||||
{
|
||||
bool NetConfig::isDHCPServer(uint8_t mode) {
|
||||
bool itis = false;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
tcpip_adapter_dhcp_status_t dhcp_status;
|
||||
tcpip_adapter_dhcps_get_status ((mode == ESP_WIFI_STA)?TCPIP_ADAPTER_IF_STA:(mode == ESP_WIFI_AP)?TCPIP_ADAPTER_IF_AP:TCPIP_ADAPTER_IF_ETH, &dhcp_status);
|
||||
tcpip_adapter_dhcps_get_status((mode == ESP_WIFI_STA) ? TCPIP_ADAPTER_IF_STA
|
||||
: (mode == ESP_WIFI_AP) ? TCPIP_ADAPTER_IF_AP
|
||||
: TCPIP_ADAPTER_IF_ETH,
|
||||
&dhcp_status);
|
||||
itis = (dhcp_status == TCPIP_ADAPTER_DHCP_STARTED);
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
@ -474,4 +454,3 @@ bool NetConfig::isDHCPServer (uint8_t mode)
|
||||
}
|
||||
|
||||
#endif // WIFI_FEATURE || ETH_FEATURE
|
||||
|
||||
|
@ -28,25 +28,29 @@
|
||||
// - https://github.com/CosmicBoris/ESP8266SMTP
|
||||
// - https://www.electronicshub.org/send-an-email-using-esp8266/
|
||||
//* Telegram
|
||||
// - https://medium.com/@xabaras/sending-a-message-to-a-telegram-channel-the-easy-way-eb0a0b32968
|
||||
// -
|
||||
// https://medium.com/@xabaras/sending-a-message-to-a-telegram-channel-the-easy-way-eb0a0b32968
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
#include "notifications_service.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../network/netconfig.h"
|
||||
#include <WiFiClientSecure.h>
|
||||
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../network/netconfig.h"
|
||||
#include "notifications_service.h"
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <libb64/cdecode.h>
|
||||
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <WiFi.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
extern "C" {
|
||||
#include "libb64/cdecode.h"
|
||||
}
|
||||
@ -80,21 +84,23 @@ extern "C" {
|
||||
NotificationsService notificationsservice;
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
void NotificationsService::BearSSLSetup(WiFiClientSecure & Notificationclient)
|
||||
{
|
||||
if (Notificationclient.probeMaxFragmentLength(_serveraddress.c_str(), _port, BEARSSL_MFLN_SIZE)) {
|
||||
void NotificationsService::BearSSLSetup(WiFiClientSecure& Notificationclient) {
|
||||
if (Notificationclient.probeMaxFragmentLength(_serveraddress.c_str(), _port,
|
||||
BEARSSL_MFLN_SIZE)) {
|
||||
log_esp3d("Handshake success");
|
||||
Notificationclient.setBufferSizes(BEARSSL_MFLN_SIZE, 512);
|
||||
} else {
|
||||
log_esp3d("Handshake failed");
|
||||
log_esp3d_e("Handshake failed");
|
||||
Notificationclient.setBufferSizes(BEARSSL_MFLN_SIZE_FALLBACK, 512);
|
||||
}
|
||||
}
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
|
||||
// TODO: put error in variable to allow better error handling
|
||||
bool NotificationsService::Wait4Answer(WiFiClientSecure & client, const char * linetrigger, const char * expected_answer, uint32_t timeout)
|
||||
{
|
||||
bool NotificationsService::Wait4Answer(WiFiClientSecure& client,
|
||||
const char* linetrigger,
|
||||
const char* expected_answer,
|
||||
uint32_t timeout) {
|
||||
if (client.connected()) {
|
||||
String answer;
|
||||
uint32_t starttimeout = millis();
|
||||
@ -118,13 +124,13 @@ bool NotificationsService::Wait4Answer(WiFiClientSecure & client, const char * l
|
||||
return true;
|
||||
}
|
||||
}
|
||||
log_esp3d("Failed to send message");
|
||||
log_esp3d_e("Failed to send message");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NotificationsService::sendAutoNotification(const char * msg)
|
||||
{
|
||||
if (!(NetConfig::started()) || (NetConfig::getMode() != ESP_WIFI_STA)|| (!_started) || (!_autonotification)) {
|
||||
bool NotificationsService::sendAutoNotification(const char* msg) {
|
||||
if (!(NetConfig::started()) || (NetConfig::getMode() != ESP_WIFI_STA) ||
|
||||
(!_started) || (!_autonotification)) {
|
||||
log_esp3d("Auto notification rejected");
|
||||
return false;
|
||||
}
|
||||
@ -135,7 +141,7 @@ bool NotificationsService::sendAutoNotification(const char * msg)
|
||||
msgtpl.replace("%ESP_NAME%", NetConfig::hostname());
|
||||
}
|
||||
if (!sendMSG(ESP_NOTIFICATION_TITLE, msgtpl.c_str())) {
|
||||
log_esp3d("Auto notification failed");
|
||||
log_esp3d_e("Auto notification failed");
|
||||
return false;
|
||||
} else {
|
||||
log_esp3d("Auto notification sent");
|
||||
@ -143,26 +149,18 @@ bool NotificationsService::sendAutoNotification(const char * msg)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationsService::NotificationsService()
|
||||
{
|
||||
NotificationsService::NotificationsService() {
|
||||
_started = false;
|
||||
_notificationType = 0;
|
||||
_token1 = "";
|
||||
_token1 = "";
|
||||
_settings = "";
|
||||
}
|
||||
NotificationsService::~NotificationsService()
|
||||
{
|
||||
end();
|
||||
}
|
||||
NotificationsService::~NotificationsService() { end(); }
|
||||
|
||||
bool NotificationsService::started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
bool NotificationsService::started() { return _started; }
|
||||
|
||||
const char * NotificationsService::getTypeString()
|
||||
{
|
||||
const char* NotificationsService::getTypeString() {
|
||||
switch (_notificationType) {
|
||||
case ESP_PUSHOVER_NOTIFICATION:
|
||||
return "pushover";
|
||||
@ -180,10 +178,9 @@ const char * NotificationsService::getTypeString()
|
||||
return "none";
|
||||
}
|
||||
|
||||
bool NotificationsService::sendMSG(const char * title, const char * message)
|
||||
{
|
||||
bool NotificationsService::sendMSG(const char* title, const char* message) {
|
||||
if (!_started) {
|
||||
log_esp3d("Error notification not started");
|
||||
log_esp3d_e("Error notification not started");
|
||||
return false;
|
||||
}
|
||||
if (!((strlen(title) == 0) && (strlen(message) == 0))) {
|
||||
@ -222,8 +219,8 @@ bool NotificationsService::sendMSG(const char * title, const char * message)
|
||||
// Messages are currently limited to 1024 4-byte UTF-8 characters
|
||||
// but we do not do any check
|
||||
// TODO: put error in variable to allow better error handling
|
||||
bool NotificationsService::sendPushoverMSG(const char * title, const char * message)
|
||||
{
|
||||
bool NotificationsService::sendPushoverMSG(const char* title,
|
||||
const char* message) {
|
||||
String data;
|
||||
String postcmd;
|
||||
bool res;
|
||||
@ -236,7 +233,8 @@ bool NotificationsService::sendPushoverMSG(const char * title, const char * mess
|
||||
BearSSLSetup(Notificationclient);
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
if (!Notificationclient.connect(_serveraddress.c_str(), _port)) {
|
||||
log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port);
|
||||
log_esp3d_e("Error connecting server %s:%d", _serveraddress.c_str(),
|
||||
_port);
|
||||
return false;
|
||||
}
|
||||
// build data for post
|
||||
@ -251,7 +249,11 @@ bool NotificationsService::sendPushoverMSG(const char * title, const char * mess
|
||||
data += "&device=";
|
||||
data += NetConfig::hostname();
|
||||
// build post query
|
||||
postcmd = "POST /1/messages.json HTTP/1.1\r\nHost: api.pushover.net\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Length: ";
|
||||
postcmd =
|
||||
"POST /1/messages.json HTTP/1.1\r\nHost: api.pushover.net\r\nConnection: "
|
||||
"close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: "
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,*/"
|
||||
"*;q=0.8\r\nContent-Length: ";
|
||||
postcmd += data.length();
|
||||
postcmd += "\r\n\r\n";
|
||||
postcmd += data;
|
||||
@ -265,8 +267,8 @@ bool NotificationsService::sendPushoverMSG(const char * title, const char * mess
|
||||
|
||||
// Telegram
|
||||
// TODO: put error in variable to allow better error handling
|
||||
bool NotificationsService::sendTelegramMSG(const char * title, const char * message)
|
||||
{
|
||||
bool NotificationsService::sendTelegramMSG(const char* title,
|
||||
const char* message) {
|
||||
String data;
|
||||
String postcmd;
|
||||
bool res;
|
||||
@ -292,7 +294,13 @@ bool NotificationsService::sendTelegramMSG(const char * title, const char * mess
|
||||
// build post query
|
||||
postcmd = "POST /bot";
|
||||
postcmd += _token1;
|
||||
postcmd += "/sendMessage HTTP/1.1\r\nHost: api.telegram.org\r\nConnection: close\r\nContent-Type: application/x-www-form-urlencoded\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Length: ";
|
||||
postcmd +=
|
||||
"/sendMessage HTTP/1.1\r\nHost: api.telegram.org\r\nConnection: "
|
||||
"close\r\nContent-Type: "
|
||||
"application/x-www-form-urlencoded\r\nCache-Control: "
|
||||
"no-cache\r\nUser-Agent: ESP3D\r\nAccept: "
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,*/"
|
||||
"*;q=0.8\r\nContent-Length: ";
|
||||
postcmd += data.length();
|
||||
postcmd += "\r\n\r\n";
|
||||
postcmd += data;
|
||||
@ -305,8 +313,8 @@ bool NotificationsService::sendTelegramMSG(const char * title, const char * mess
|
||||
}
|
||||
|
||||
// TODO: put error in variable to allow better error handling
|
||||
bool NotificationsService::sendEmailMSG(const char * title, const char * message)
|
||||
{
|
||||
bool NotificationsService::sendEmailMSG(const char* title,
|
||||
const char* message) {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
WiFiClientSecure Notificationclient;
|
||||
@ -317,19 +325,20 @@ bool NotificationsService::sendEmailMSG(const char * title, const char * message
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
log_esp3d("Connect to server");
|
||||
if (!Notificationclient.connect(_serveraddress.c_str(), _port)) {
|
||||
log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port);
|
||||
log_esp3d_e("Error connecting server %s:%d", _serveraddress.c_str(),
|
||||
_port);
|
||||
return false;
|
||||
}
|
||||
// Check answer of connection
|
||||
if (!Wait4Answer(Notificationclient, "220", "220", EMAILTIMEOUT)) {
|
||||
log_esp3d("Connection failed!");
|
||||
log_esp3d_e("Connection failed!");
|
||||
return false;
|
||||
}
|
||||
// Do HELO
|
||||
log_esp3d("HELO");
|
||||
Notificationclient.print("HELO friend\r\n");
|
||||
if (!Wait4Answer(Notificationclient, "250", "250", EMAILTIMEOUT)) {
|
||||
log_esp3d("HELO failed!");
|
||||
log_esp3d_e("HELO failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("AUTH LOGIN");
|
||||
@ -343,35 +352,35 @@ bool NotificationsService::sendEmailMSG(const char * title, const char * message
|
||||
// sent Login
|
||||
Notificationclient.printf("%s\r\n", _token1.c_str());
|
||||
if (!Wait4Answer(Notificationclient, "334", "334", EMAILTIMEOUT)) {
|
||||
log_esp3d("Sent login failed!");
|
||||
log_esp3d_e("Sent login failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("Send PASSWORD");
|
||||
// Send password
|
||||
Notificationclient.printf("%s\r\n", _token2.c_str());
|
||||
if (!Wait4Answer(Notificationclient, "235", "235", EMAILTIMEOUT)) {
|
||||
log_esp3d("Sent password failed!");
|
||||
log_esp3d_e("Sent password failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("MAIL FROM");
|
||||
// Send From
|
||||
Notificationclient.printf("MAIL FROM: <%s>\r\n", _settings.c_str());
|
||||
if (!Wait4Answer(Notificationclient, "250", "250", EMAILTIMEOUT)) {
|
||||
log_esp3d("MAIL FROM failed!");
|
||||
log_esp3d_e("MAIL FROM failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("RCPT TO");
|
||||
// Send To
|
||||
Notificationclient.printf("RCPT TO: <%s>\r\n", _settings.c_str());
|
||||
if (!Wait4Answer(Notificationclient, "250", "250", EMAILTIMEOUT)) {
|
||||
log_esp3d("RCPT TO failed!");
|
||||
log_esp3d_e("RCPT TO failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("DATA");
|
||||
// Send Data
|
||||
Notificationclient.print("DATA\r\n");
|
||||
if (!Wait4Answer(Notificationclient, "354", "354", EMAILTIMEOUT)) {
|
||||
log_esp3d("Preparing DATA failed!");
|
||||
log_esp3d_e("Preparing DATA failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("Send message");
|
||||
@ -385,22 +394,21 @@ bool NotificationsService::sendEmailMSG(const char * title, const char * message
|
||||
// Send Final dot
|
||||
Notificationclient.print(".\r\n");
|
||||
if (!Wait4Answer(Notificationclient, "250", "250", EMAILTIMEOUT)) {
|
||||
log_esp3d("Sending final dot failed!");
|
||||
log_esp3d_e("Sending final dot failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("QUIT");
|
||||
// Quit
|
||||
Notificationclient.print("QUIT\r\n");
|
||||
if (!Wait4Answer(Notificationclient, "221", "221", EMAILTIMEOUT)) {
|
||||
log_esp3d("QUIT failed!");
|
||||
log_esp3d_e("QUIT failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Notificationclient.stop();
|
||||
return true;
|
||||
}
|
||||
bool NotificationsService::sendLineMSG(const char * title, const char * message)
|
||||
{
|
||||
bool NotificationsService::sendLineMSG(const char* title, const char* message) {
|
||||
String data;
|
||||
String postcmd;
|
||||
bool res;
|
||||
@ -414,14 +422,19 @@ bool NotificationsService::sendLineMSG(const char * title, const char * message)
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
(void)title;
|
||||
if (!Notificationclient.connect(_serveraddress.c_str(), _port)) {
|
||||
log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port);
|
||||
log_esp3d_e("Error connecting server %s:%d", _serveraddress.c_str(),
|
||||
_port);
|
||||
return false;
|
||||
}
|
||||
// build data for post
|
||||
data = "message=";
|
||||
data += message;
|
||||
// build post query
|
||||
postcmd = "POST /api/notify HTTP/1.1\r\nHost: notify-api.line.me\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\n";
|
||||
postcmd =
|
||||
"POST /api/notify HTTP/1.1\r\nHost: notify-api.line.me\r\nConnection: "
|
||||
"close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: "
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,*/"
|
||||
"*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\n";
|
||||
postcmd += "Authorization: Bearer ";
|
||||
postcmd += _token1 + "\r\n";
|
||||
postcmd += "Content-Length: ";
|
||||
@ -437,8 +450,8 @@ bool NotificationsService::sendLineMSG(const char * title, const char * message)
|
||||
}
|
||||
|
||||
// IFTTT
|
||||
bool NotificationsService::sendIFTTTMSG(const char * title, const char * message)
|
||||
{
|
||||
bool NotificationsService::sendIFTTTMSG(const char* title,
|
||||
const char* message) {
|
||||
String data;
|
||||
String postcmd;
|
||||
bool res;
|
||||
@ -452,7 +465,8 @@ bool NotificationsService::sendIFTTTMSG(const char * title, const char * message
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
(void)title;
|
||||
if (!Notificationclient.connect(_serveraddress.c_str(), _port)) {
|
||||
log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port);
|
||||
log_esp3d_e("Error connecting server %s:%d", _serveraddress.c_str(),
|
||||
_port);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -466,7 +480,12 @@ bool NotificationsService::sendIFTTTMSG(const char * title, const char * message
|
||||
data += NetConfig::hostname();
|
||||
|
||||
// build post query
|
||||
postcmd = "POST /trigger/" + _token1 + "/with/key/" + _token2 + " HTTP/1.1\r\nHost: maker.ifttt.com\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ";
|
||||
postcmd = "POST /trigger/" + _token1 + "/with/key/" + _token2 +
|
||||
" HTTP/1.1\r\nHost: maker.ifttt.com\r\nConnection: "
|
||||
"close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: "
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,*/"
|
||||
"*;q=0.8\r\nContent-Type: "
|
||||
"application/x-www-form-urlencoded\r\nContent-Length: ";
|
||||
postcmd += data.length();
|
||||
postcmd += "\r\n\r\n";
|
||||
postcmd += data;
|
||||
@ -474,14 +493,14 @@ bool NotificationsService::sendIFTTTMSG(const char * title, const char * message
|
||||
// log_esp3d("Query: %s", postcmd.c_str());
|
||||
// send query
|
||||
Notificationclient.print(postcmd);
|
||||
res = Wait4Answer(Notificationclient, "Congratulations", "Congratulations", IFTTTTIMEOUT);
|
||||
res = Wait4Answer(Notificationclient, "Congratulations", "Congratulations",
|
||||
IFTTTTIMEOUT);
|
||||
Notificationclient.stop();
|
||||
return res;
|
||||
}
|
||||
|
||||
// Email#serveraddress:port
|
||||
bool NotificationsService::getPortFromSettings()
|
||||
{
|
||||
bool NotificationsService::getPortFromSettings() {
|
||||
String tmp = Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS);
|
||||
int pos = tmp.lastIndexOf(':');
|
||||
if (pos == -1) {
|
||||
@ -496,8 +515,7 @@ bool NotificationsService::getPortFromSettings()
|
||||
}
|
||||
}
|
||||
// Email#serveraddress:port
|
||||
bool NotificationsService::getServerAddressFromSettings()
|
||||
{
|
||||
bool NotificationsService::getServerAddressFromSettings() {
|
||||
String tmp = Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS);
|
||||
int pos1 = tmp.indexOf('#');
|
||||
int pos2 = tmp.lastIndexOf(':');
|
||||
@ -511,8 +529,7 @@ bool NotificationsService::getServerAddressFromSettings()
|
||||
return true;
|
||||
}
|
||||
// Email#serveraddress:port
|
||||
bool NotificationsService::getEmailFromSettings()
|
||||
{
|
||||
bool NotificationsService::getEmailFromSettings() {
|
||||
String tmp = Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS);
|
||||
int pos = tmp.indexOf('#');
|
||||
if (pos == -1) {
|
||||
@ -524,8 +541,7 @@ bool NotificationsService::getEmailFromSettings()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NotificationsService::decode64(const char* encodedURL, char *decodedURL)
|
||||
{
|
||||
bool NotificationsService::decode64(const char* encodedURL, char* decodedURL) {
|
||||
size_t out_len = 0;
|
||||
out_len = base64_decode_chars(encodedURL, strlen(encodedURL), decodedURL);
|
||||
log_esp3d("URLE: %s", encodedURL);
|
||||
@ -533,11 +549,11 @@ bool NotificationsService::decode64(const char* encodedURL, char *decodedURL)
|
||||
return (out_len > 0);
|
||||
}
|
||||
|
||||
bool NotificationsService::GET(const char * URL64)
|
||||
{
|
||||
bool NotificationsService::GET(const char* URL64) {
|
||||
// TODO do we need https client ?
|
||||
WiFiClient client;
|
||||
HTTPClient http; //must be declared after WiFiClient for correct destruction order, because used by http.begin(client,...)
|
||||
HTTPClient http; // must be declared after WiFiClient for correct destruction
|
||||
// order, because used by http.begin(client,...)
|
||||
char* decodedurl[255];
|
||||
bool res = false;
|
||||
if (decode64(URL64, (char*)decodedurl)) {
|
||||
@ -554,8 +570,7 @@ bool NotificationsService::GET(const char * URL64)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool NotificationsService::begin()
|
||||
{
|
||||
bool NotificationsService::begin() {
|
||||
bool res = true;
|
||||
end();
|
||||
_notificationType = Settings_ESP3D::read_byte(ESP_NOTIFICATION_TYPE);
|
||||
@ -587,11 +602,14 @@ bool NotificationsService::begin()
|
||||
_serveraddress = IFTTTSERVER;
|
||||
break;
|
||||
case ESP_EMAIL_NOTIFICATION:
|
||||
_token1 = base64::encode(Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1));
|
||||
_token2 = base64::encode(Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN2));
|
||||
_token1 =
|
||||
base64::encode(Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1));
|
||||
_token2 =
|
||||
base64::encode(Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN2));
|
||||
// log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1));
|
||||
// log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN2));
|
||||
if(!getEmailFromSettings() || !getPortFromSettings()|| !getServerAddressFromSettings()) {
|
||||
if (!getEmailFromSettings() || !getPortFromSettings() ||
|
||||
!getServerAddressFromSettings()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@ -599,15 +617,15 @@ bool NotificationsService::begin()
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
_autonotification = (Settings_ESP3D::read_byte(ESP_AUTO_NOTIFICATION) == 0) ? false: true;
|
||||
_autonotification =
|
||||
(Settings_ESP3D::read_byte(ESP_AUTO_NOTIFICATION) == 0) ? false : true;
|
||||
if (!res) {
|
||||
end();
|
||||
}
|
||||
_started = res;
|
||||
return _started;
|
||||
}
|
||||
void NotificationsService::end()
|
||||
{
|
||||
void NotificationsService::end() {
|
||||
if (!_started) {
|
||||
return;
|
||||
}
|
||||
@ -620,8 +638,7 @@ void NotificationsService::end()
|
||||
_port = 0;
|
||||
}
|
||||
|
||||
void NotificationsService::handle()
|
||||
{
|
||||
void NotificationsService::handle() {
|
||||
if (_started) {
|
||||
}
|
||||
}
|
||||
|
@ -21,29 +21,24 @@
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef SENSOR_DEVICE
|
||||
#if SENSOR_DEVICE == BMP280_DEVICE || SENSOR_DEVICE == BME280_DEVICE
|
||||
#include "bmx280.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include <BMx280I2C.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "bmx280.h"
|
||||
|
||||
|
||||
#define NB_TYPE_SENSOR 2
|
||||
const char *SENSOR_NAME[NB_TYPE_SENSOR] = {"BMP280", "BME280"};
|
||||
const uint8_t SENSOR_ID[NB_TYPE_SENSOR] = {BMP280_DEVICE, BME280_DEVICE};
|
||||
BMx280I2C *bmx280_device;
|
||||
|
||||
BMX280SensorDevice::BMX280SensorDevice()
|
||||
{
|
||||
bmx280_device = nullptr;
|
||||
}
|
||||
BMX280SensorDevice::BMX280SensorDevice() { bmx280_device = nullptr; }
|
||||
|
||||
BMX280SensorDevice::~BMX280SensorDevice()
|
||||
{
|
||||
end();
|
||||
}
|
||||
BMX280SensorDevice::~BMX280SensorDevice() { end(); }
|
||||
|
||||
bool BMX280SensorDevice::begin()
|
||||
{
|
||||
bool BMX280SensorDevice::begin() {
|
||||
end();
|
||||
uint8_t sensortype = Settings_ESP3D::read_byte(ESP_SENSOR_TYPE);
|
||||
if (sensortype == 0) {
|
||||
@ -51,7 +46,7 @@ bool BMX280SensorDevice::begin()
|
||||
return true;
|
||||
}
|
||||
if (!isModelValid(sensortype)) {
|
||||
log_esp3d("No valid id ");
|
||||
log_esp3d_e("No valid id ");
|
||||
return false;
|
||||
}
|
||||
// Setup Wire pins first as lib does setup wire
|
||||
@ -59,7 +54,7 @@ bool BMX280SensorDevice::begin()
|
||||
log_esp3d("Starting wire SDA:%d SCL:%d", ESP_SDA_PIN, ESP_SCL_PIN);
|
||||
bmx280_device = new BMx280I2C(SENSOR_ADDR);
|
||||
if (!bmx280_device) {
|
||||
log_esp3d("Cannot instanciate sensor");
|
||||
log_esp3d_e("Cannot instanciate sensor");
|
||||
return false;
|
||||
}
|
||||
if (!bmx280_device->begin()) {
|
||||
@ -75,23 +70,22 @@ bool BMX280SensorDevice::begin()
|
||||
bmx280_device->writeOversamplingPressure(BMx280MI::OSRS_P_x16);
|
||||
bmx280_device->writeOversamplingTemperature(BMx280MI::OSRS_T_x16);
|
||||
|
||||
//if sensor is a BME280, set an oversampling setting for humidity measurements.
|
||||
// if sensor is a BME280, set an oversampling setting for humidity
|
||||
// measurements.
|
||||
if (bmx280_device->isBME280()) {
|
||||
bmx280_device->writeOversamplingHumidity(BMx280MI::OSRS_H_x16);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void BMX280SensorDevice::end()
|
||||
{
|
||||
void BMX280SensorDevice::end() {
|
||||
if (bmx280_device) {
|
||||
delete bmx280_device;
|
||||
}
|
||||
bmx280_device = nullptr;
|
||||
}
|
||||
|
||||
bool BMX280SensorDevice::isModelValid(uint8_t model)
|
||||
{
|
||||
bool BMX280SensorDevice::isModelValid(uint8_t model) {
|
||||
for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) {
|
||||
if (model == SENSOR_ID[i]) {
|
||||
return true;
|
||||
@ -100,8 +94,7 @@ bool BMX280SensorDevice::isModelValid(uint8_t model)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t BMX280SensorDevice::getIDFromString(const char *s)
|
||||
{
|
||||
uint8_t BMX280SensorDevice::getIDFromString(const char *s) {
|
||||
for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) {
|
||||
log_esp3d("checking %s with %s", s, SENSOR_NAME[i]);
|
||||
if (strcmp(s, SENSOR_NAME[i]) == 0) {
|
||||
@ -113,21 +106,16 @@ uint8_t BMX280SensorDevice::getIDFromString(const char *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t BMX280SensorDevice::nbType()
|
||||
{
|
||||
return NB_TYPE_SENSOR;
|
||||
}
|
||||
uint8_t BMX280SensorDevice::nbType() { return NB_TYPE_SENSOR; }
|
||||
|
||||
uint8_t BMX280SensorDevice::GetModel(uint8_t i)
|
||||
{
|
||||
uint8_t BMX280SensorDevice::GetModel(uint8_t i) {
|
||||
if (i < NB_TYPE_SENSOR) {
|
||||
return SENSOR_ID[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *BMX280SensorDevice::GetCurrentModelString()
|
||||
{
|
||||
const char *BMX280SensorDevice::GetCurrentModelString() {
|
||||
uint8_t sensortype = Settings_ESP3D::read_byte(ESP_SENSOR_TYPE);
|
||||
for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) {
|
||||
if ((sensortype == SENSOR_TYPE[i]) {
|
||||
@ -137,8 +125,7 @@ const char *BMX280SensorDevice::GetCurrentModelString()
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
const char * BMX280SensorDevice::GetModelString(uint8_t i)
|
||||
{
|
||||
const char *BMX280SensorDevice::GetModelString(uint8_t i) {
|
||||
if (i < NB_TYPE_SENSOR) {
|
||||
return SENSOR_NAME[i];
|
||||
}
|
||||
@ -146,13 +133,9 @@ const char * BMX280SensorDevice::GetModelString(uint8_t i)
|
||||
}
|
||||
|
||||
// helper function
|
||||
float toFahrenheit(float fromCelcius)
|
||||
{
|
||||
return 1.8 * fromCelcius + 32.0;
|
||||
};
|
||||
float toFahrenheit(float fromCelcius) { return 1.8 * fromCelcius + 32.0; };
|
||||
|
||||
const char * BMX280SensorDevice::GetData()
|
||||
{
|
||||
const char *BMX280SensorDevice::GetData() {
|
||||
static String s;
|
||||
if (bmx280_device) {
|
||||
if (!bmx280_device->measure()) {
|
||||
@ -187,20 +170,19 @@ const char * BMX280SensorDevice::GetData()
|
||||
}
|
||||
} else {
|
||||
s = "DISCONNECTED";
|
||||
log_esp3d("No valid data");
|
||||
log_esp3d_e("No valid data");
|
||||
}
|
||||
} else {
|
||||
s = "DISCONNECTED";
|
||||
log_esp3d("No valid data");
|
||||
log_esp3_ed("No valid data");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s = "DISCONNECTED";
|
||||
log_esp3d("No device");
|
||||
log_esp3d_e("No device");
|
||||
}
|
||||
return s.c_str();
|
||||
}
|
||||
|
||||
|
||||
#endif // BMP280_DEVICE || BME280_DEVICE
|
||||
#endif // SENSOR_DEVICE
|
||||
|
@ -21,66 +21,63 @@
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef SENSOR_DEVICE
|
||||
#if SENSOR_DEVICE == DHT11_DEVICE || SENSOR_DEVICE == DHT22_DEVICE
|
||||
#include "dht.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include <DHTesp.h>
|
||||
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "dht.h"
|
||||
|
||||
#define NB_TYPE_SENSOR 2
|
||||
const char *SENSOR_NAME[NB_TYPE_SENSOR] = {"DHT11", "DHT22"};
|
||||
const uint8_t SENSOR_ID[NB_TYPE_SENSOR] = {DHT11_DEVICE, DHT22_DEVICE};
|
||||
const DHTesp::DHT_MODEL_t SENSOR_TYPE[NB_TYPE_SENSOR] = {DHTesp::DHT11, DHTesp::DHT22};
|
||||
const DHTesp::DHT_MODEL_t SENSOR_TYPE[NB_TYPE_SENSOR] = {DHTesp::DHT11,
|
||||
DHTesp::DHT22};
|
||||
DHTesp *dht_device;
|
||||
|
||||
DHTSensorDevice::DHTSensorDevice()
|
||||
{
|
||||
dht_device = nullptr;
|
||||
}
|
||||
DHTSensorDevice::DHTSensorDevice() { dht_device = nullptr; }
|
||||
|
||||
DHTSensorDevice::~DHTSensorDevice()
|
||||
{
|
||||
end();
|
||||
}
|
||||
DHTSensorDevice::~DHTSensorDevice() { end(); }
|
||||
|
||||
bool DHTSensorDevice::begin()
|
||||
{
|
||||
bool DHTSensorDevice::begin() {
|
||||
end();
|
||||
uint8_t dhttype = Settings_ESP3D::read_byte(ESP_SENSOR_TYPE);
|
||||
log_esp3d("Read %d, %s", dhttype, dhttype==1?"DHT11":dhttype==2?"DHT22":dhttype==0?"NONE":"Unknow type");
|
||||
log_esp3d("Read %d, %s", dhttype,
|
||||
dhttype == 1 ? "DHT11"
|
||||
: dhttype == 2 ? "DHT22"
|
||||
: dhttype == 0 ? "NONE"
|
||||
: "Unknow type");
|
||||
if (dhttype == 0) {
|
||||
log_esp3d("No Sensor active");
|
||||
return true;
|
||||
}
|
||||
if (!isModelValid(dhttype)) {
|
||||
log_esp3d("No valid id ");
|
||||
log_esp3d_e("No valid id ");
|
||||
return false;
|
||||
}
|
||||
dht_device = new DHTesp;
|
||||
if (!dht_device) {
|
||||
log_esp3d("Cannot instanciate dht");
|
||||
log_esp3d_e("Cannot instanciate dht");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("DHT PIN %d", ESP3D_SENSOR_PIN);
|
||||
dht_device->setup(ESP3D_SENSOR_PIN, (DHTesp::DHT_MODEL_t)dhttype);
|
||||
if (strcmp(dht_device->getStatusString(), "OK") != 0) {
|
||||
log_esp3d("No valid dht status: %d, %s",dht_device->getStatus(), dht_device->getStatusString());
|
||||
log_esp3d_e("No valid dht status: %d, %s", dht_device->getStatus(),
|
||||
dht_device->getStatusString());
|
||||
return false;
|
||||
}
|
||||
log_esp3d("DHT ok");
|
||||
return true;
|
||||
}
|
||||
|
||||
void DHTSensorDevice::end()
|
||||
{
|
||||
void DHTSensorDevice::end() {
|
||||
if (dht_device) {
|
||||
delete dht_device;
|
||||
}
|
||||
dht_device = nullptr;
|
||||
}
|
||||
|
||||
bool DHTSensorDevice::isModelValid(uint8_t model)
|
||||
{
|
||||
bool DHTSensorDevice::isModelValid(uint8_t model) {
|
||||
for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) {
|
||||
if (model == SENSOR_ID[i]) {
|
||||
return true;
|
||||
@ -89,8 +86,7 @@ bool DHTSensorDevice::isModelValid(uint8_t model)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t DHTSensorDevice::getIDFromString(const char *s)
|
||||
{
|
||||
uint8_t DHTSensorDevice::getIDFromString(const char *s) {
|
||||
for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) {
|
||||
log_esp3d("checking %s with %s", s, SENSOR_NAME[i]);
|
||||
if (strcmp(s, SENSOR_NAME[i]) == 0) {
|
||||
@ -102,21 +98,16 @@ uint8_t DHTSensorDevice::getIDFromString(const char *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t DHTSensorDevice::nbType()
|
||||
{
|
||||
return NB_TYPE_SENSOR;
|
||||
}
|
||||
uint8_t DHTSensorDevice::nbType() { return NB_TYPE_SENSOR; }
|
||||
|
||||
uint8_t DHTSensorDevice::GetModel(uint8_t i)
|
||||
{
|
||||
uint8_t DHTSensorDevice::GetModel(uint8_t i) {
|
||||
if (i < NB_TYPE_SENSOR) {
|
||||
return SENSOR_ID[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *DHTSensorDevice::GetCurrentModelString()
|
||||
{
|
||||
const char *DHTSensorDevice::GetCurrentModelString() {
|
||||
uint8_t dhttype = Settings_ESP3D::read_byte(ESP_SENSOR_TYPE);
|
||||
for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) {
|
||||
if ((DHTesp::DHT_MODEL_t)dhttype == SENSOR_TYPE[i]) {
|
||||
@ -126,16 +117,14 @@ const char *DHTSensorDevice::GetCurrentModelString()
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
const char * DHTSensorDevice::GetModelString(uint8_t i)
|
||||
{
|
||||
const char *DHTSensorDevice::GetModelString(uint8_t i) {
|
||||
if (i < NB_TYPE_SENSOR) {
|
||||
return SENSOR_NAME[i];
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
const char * DHTSensorDevice::GetData()
|
||||
{
|
||||
const char *DHTSensorDevice::GetData() {
|
||||
static String s;
|
||||
if (dht_device) {
|
||||
float temperature = dht_device->getTemperature();
|
||||
@ -151,15 +140,14 @@ const char * DHTSensorDevice::GetData()
|
||||
s += "] " + String(humidity, 1) + "[%]";
|
||||
} else {
|
||||
s = "DISCONNECTED";
|
||||
log_esp3d("No valid data");
|
||||
log_esp3d_e("No valid data");
|
||||
}
|
||||
} else {
|
||||
s = "DISCONNECTED";
|
||||
log_esp3d("No device");
|
||||
log_esp3d_e("No device");
|
||||
}
|
||||
return s.c_str();
|
||||
}
|
||||
|
||||
|
||||
#endif // DHT11_DEVICE || DHT22_DEVICE
|
||||
#endif // SENSOR_DEVICE
|
||||
|
@ -20,9 +20,10 @@
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef SENSOR_DEVICE
|
||||
#include "sensor.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "sensor.h"
|
||||
|
||||
// Include file according sensor
|
||||
#if SENSOR_DEVICE == DHT11_DEVICE || SENSOR_DEVICE == DHT22_DEVICE
|
||||
#include "dht.h"
|
||||
@ -40,20 +41,15 @@
|
||||
|
||||
ESP3DSensor esp3d_sensor;
|
||||
|
||||
ESP3DSensor::ESP3DSensor()
|
||||
{
|
||||
ESP3DSensor::ESP3DSensor() {
|
||||
_started = false;
|
||||
_interval = 0;
|
||||
_device = nullptr;
|
||||
}
|
||||
|
||||
ESP3DSensor::~ESP3DSensor()
|
||||
{
|
||||
end();
|
||||
}
|
||||
ESP3DSensor::~ESP3DSensor() { end(); }
|
||||
|
||||
bool ESP3DSensor::begin()
|
||||
{
|
||||
bool ESP3DSensor::begin() {
|
||||
log_esp3d("Sensor Begin");
|
||||
bool res = true;
|
||||
end();
|
||||
@ -68,7 +64,7 @@ bool ESP3DSensor::begin()
|
||||
_device = (ESP3DSensorDevice*)new BMX280SensorDevice();
|
||||
#endif // DHT11_DEVICE || DHT22_DEVICE
|
||||
if (!_device) {
|
||||
log_esp3d("No device created");
|
||||
log_esp3d_e("No device created");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("Sensor Device created");
|
||||
@ -88,8 +84,7 @@ bool ESP3DSensor::begin()
|
||||
return _started;
|
||||
}
|
||||
|
||||
void ESP3DSensor::end()
|
||||
{
|
||||
void ESP3DSensor::end() {
|
||||
if (_device) {
|
||||
delete _device;
|
||||
_device = nullptr;
|
||||
@ -98,8 +93,7 @@ void ESP3DSensor::end()
|
||||
_interval = 0;
|
||||
}
|
||||
|
||||
uint8_t ESP3DSensor::GetModel(uint8_t i)
|
||||
{
|
||||
uint8_t ESP3DSensor::GetModel(uint8_t i) {
|
||||
if (_device) {
|
||||
return _device->GetModel(i);
|
||||
} else {
|
||||
@ -107,66 +101,54 @@ uint8_t ESP3DSensor::GetModel(uint8_t i)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ESP3DSensor::nbType()
|
||||
{
|
||||
uint8_t ESP3DSensor::nbType() {
|
||||
if (_device) {
|
||||
|
||||
return _device->nbType();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool ESP3DSensor::isModelValid(uint8_t model)
|
||||
{
|
||||
bool ESP3DSensor::isModelValid(uint8_t model) {
|
||||
if (_device) {
|
||||
return _device->isModelValid(model);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * ESP3DSensor::GetCurrentModelString()
|
||||
{
|
||||
const char* ESP3DSensor::GetCurrentModelString() {
|
||||
if (_device) {
|
||||
|
||||
return _device->GetCurrentModelString();
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
const char * ESP3DSensor::GetModelString(uint8_t i)
|
||||
{
|
||||
const char* ESP3DSensor::GetModelString(uint8_t i) {
|
||||
if (_device) {
|
||||
|
||||
return _device->GetModelString(i);
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
uint8_t ESP3DSensor::getIDFromString(const char * s)
|
||||
{
|
||||
uint8_t ESP3DSensor::getIDFromString(const char* s) {
|
||||
if (_device) {
|
||||
return _device->getIDFromString(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ESP3DSensor::setInterval(uint interval)
|
||||
{
|
||||
bool ESP3DSensor::setInterval(uint interval) {
|
||||
_interval = interval;
|
||||
return true;
|
||||
}
|
||||
|
||||
const char * ESP3DSensor::GetData()
|
||||
{
|
||||
const char* ESP3DSensor::GetData() {
|
||||
if (_started && _device) {
|
||||
return _device->GetData();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void ESP3DSensor::handle()
|
||||
{
|
||||
void ESP3DSensor::handle() {
|
||||
if (_interval == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -19,11 +19,13 @@
|
||||
*/
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == RAW_SERIAL || defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
#include "serial_service.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#if COMMUNICATION_PROTOCOL == MKS_SERIAL || \
|
||||
COMMUNICATION_PROTOCOL == RAW_SERIAL || defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
#include "../../core/commands.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "serial_service.h"
|
||||
|
||||
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#include "../mks/mks_service.h"
|
||||
#endif // COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
@ -45,7 +47,6 @@ HardwareSerial * Serials[MAX_SERIAL] = {&Serial, &Serial1};
|
||||
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
||||
|
||||
// Serial Parameters
|
||||
#define ESP_SERIAL_PARAM SERIAL_8N1
|
||||
|
||||
@ -62,12 +63,13 @@ SerialService serial_bridge_service = SerialService(BRIDGE_SERIAL);
|
||||
TaskHandle_t _hserialtask = nullptr;
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
||||
const long SupportedBaudList[] = {9600, 19200, 38400, 57600, 74880, 115200, 230400, 250000, 500000, 921600, 1958400};
|
||||
const long SupportedBaudList[] = {9600, 19200, 38400, 57600,
|
||||
74880, 115200, 230400, 250000,
|
||||
500000, 921600, 1958400};
|
||||
|
||||
#define TIMEOUT_SERIAL_FLUSH 1500
|
||||
// Constructor
|
||||
SerialService::SerialService(uint8_t id)
|
||||
{
|
||||
SerialService::SerialService(uint8_t id) {
|
||||
_buffer_size = 0;
|
||||
_started = false;
|
||||
_needauthentication = true;
|
||||
@ -94,15 +96,11 @@ SerialService::SerialService(uint8_t id)
|
||||
}
|
||||
|
||||
// Destructor
|
||||
SerialService::~SerialService()
|
||||
{
|
||||
end();
|
||||
}
|
||||
SerialService::~SerialService() { end(); }
|
||||
|
||||
// dedicated serial task
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(SERIAL_INDEPENDANT_TASK)
|
||||
void ESP3DSerialTaskfn( void * parameter )
|
||||
{
|
||||
void ESP3DSerialTaskfn(void *parameter) {
|
||||
for (;;) {
|
||||
serial_service.process();
|
||||
Hal::wait(SERIAL_YIELD); // Yield to other tasks
|
||||
@ -112,26 +110,27 @@ void ESP3DSerialTaskfn( void * parameter )
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
||||
// extra parameters that do not need a begin
|
||||
void SerialService::setParameters()
|
||||
{
|
||||
void SerialService::setParameters() {
|
||||
#if defined(AUTHENTICATION_FEATURE)
|
||||
_needauthentication = (Settings_ESP3D::read_byte (ESP_SECURE_SERIAL)==0)?false:true;
|
||||
_needauthentication =
|
||||
(Settings_ESP3D::read_byte(ESP_SECURE_SERIAL) == 0) ? false : true;
|
||||
#else
|
||||
_needauthentication = false;
|
||||
#endif // AUTHENTICATION_FEATURE
|
||||
}
|
||||
|
||||
// Setup Serial
|
||||
bool SerialService::begin(uint8_t serialIndex)
|
||||
{
|
||||
bool SerialService::begin(uint8_t serialIndex) {
|
||||
_serialIndex = serialIndex - 1;
|
||||
log_esp3d("Serial %d begin for %d", _serialIndex, _id);
|
||||
if (_id== BRIDGE_SERIAL && Settings_ESP3D::read_byte(ESP_SERIAL_BRIDGE_ON)==0) {
|
||||
if (_id == BRIDGE_SERIAL &&
|
||||
Settings_ESP3D::read_byte(ESP_SERIAL_BRIDGE_ON) == 0) {
|
||||
log_esp3d("Serial %d for %d is disabled", _serialIndex, _id);
|
||||
return true;
|
||||
}
|
||||
if (_serialIndex >= MAX_SERIAL) {
|
||||
log_esp3d("Serial %d begin for %d failed, index out of range", _serialIndex, _id);
|
||||
log_esp3d_e("Serial %d begin for %d failed, index out of range",
|
||||
_serialIndex, _id);
|
||||
return false;
|
||||
}
|
||||
_lastflush = millis();
|
||||
@ -146,11 +145,13 @@ bool SerialService::begin(uint8_t serialIndex)
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
case BRIDGE_SERIAL:
|
||||
br = Settings_ESP3D::read_uint32(ESP_SERIAL_BRIDGE_BAUD);
|
||||
defaultBr = Settings_ESP3D::get_default_int32_value(ESP_SERIAL_BRIDGE_BAUD);
|
||||
defaultBr =
|
||||
Settings_ESP3D::get_default_int32_value(ESP_SERIAL_BRIDGE_BAUD);
|
||||
break;
|
||||
#endif // ESP_SERIAL_BRIDGE_OUTPUT
|
||||
default:
|
||||
log_esp3d("Serial %d begin for %d failed, unknown id", _serialIndex, _id);
|
||||
log_esp3d_e("Serial %d begin for %d failed, unknown id", _serialIndex,
|
||||
_id);
|
||||
return false;
|
||||
}
|
||||
setParameters();
|
||||
@ -163,7 +164,8 @@ bool SerialService::begin(uint8_t serialIndex)
|
||||
}
|
||||
Serials[_serialIndex]->setRxBufferSize(SERIAL_RX_BUFFER_SIZE);
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
Serials[_serialIndex]->begin(br, ESP_SERIAL_PARAM, SERIAL_FULL, (_txPin == -1)?1:_txPin);
|
||||
Serials[_serialIndex]->begin(br, ESP_SERIAL_PARAM, SERIAL_FULL,
|
||||
(_txPin == -1) ? 1 : _txPin);
|
||||
if (_rxPin != -1) {
|
||||
Serials[_serialIndex]->pins((_txPin == -1) ? 1 : _txPin, _rxPin);
|
||||
}
|
||||
@ -186,7 +188,7 @@ bool SerialService::begin(uint8_t serialIndex)
|
||||
);
|
||||
}
|
||||
if (_hserialtask == nullptr) {
|
||||
log_esp3d("Serial %d for %d Task creation failed",_serialIndex, _id);
|
||||
log_esp3d_e("Serial %d for %d Task creation failed", _serialIndex, _id);
|
||||
return false;
|
||||
}
|
||||
#endif // SERIAL_INDEPENDANT_TASK
|
||||
@ -197,8 +199,7 @@ bool SerialService::begin(uint8_t serialIndex)
|
||||
return true;
|
||||
}
|
||||
// End serial
|
||||
bool SerialService::end()
|
||||
{
|
||||
bool SerialService::end() {
|
||||
flush();
|
||||
delay(100);
|
||||
swap();
|
||||
@ -209,8 +210,7 @@ bool SerialService::end()
|
||||
}
|
||||
|
||||
// return the array of long and array size
|
||||
const long * SerialService::get_baudratelist(uint8_t * count)
|
||||
{
|
||||
const long *SerialService::get_baudratelist(uint8_t *count) {
|
||||
if (count) {
|
||||
*count = sizeof(SupportedBaudList) / sizeof(long);
|
||||
}
|
||||
@ -218,8 +218,7 @@ const long * SerialService::get_baudratelist(uint8_t * count)
|
||||
}
|
||||
|
||||
// check if value is in baudrate list
|
||||
bool SerialService::is_valid_baudrate(long br)
|
||||
{
|
||||
bool SerialService::is_valid_baudrate(long br) {
|
||||
uint8_t listesize = sizeof(SupportedBaudList) / sizeof(long);
|
||||
for (uint8_t i = 0; i < listesize; i++) {
|
||||
if (SupportedBaudList[i] == br) {
|
||||
@ -230,8 +229,7 @@ bool SerialService::is_valid_baudrate(long br)
|
||||
}
|
||||
|
||||
// Function which could be called in other loop
|
||||
void SerialService::process()
|
||||
{
|
||||
void SerialService::process() {
|
||||
if (!_started) {
|
||||
return;
|
||||
}
|
||||
@ -259,8 +257,7 @@ void SerialService::process()
|
||||
}
|
||||
|
||||
// Function which could be called in other loop
|
||||
void SerialService::handle()
|
||||
{
|
||||
void SerialService::handle() {
|
||||
// the serial bridge do not use independant task
|
||||
// not sure if it is sill necessary to do it for the main serial
|
||||
// TBC..
|
||||
@ -272,21 +269,20 @@ void SerialService::handle()
|
||||
process();
|
||||
}
|
||||
|
||||
void SerialService::flushbuffer()
|
||||
{
|
||||
void SerialService::flushbuffer() {
|
||||
ESP3DOutput output(_client);
|
||||
_buffer[_buffer_size] = 0x0;
|
||||
// dispatch command
|
||||
if (_started) {
|
||||
esp3d_commands.process(_buffer, _buffer_size, &output,_needauthentication?LEVEL_GUEST:LEVEL_ADMIN);
|
||||
esp3d_commands.process(_buffer, _buffer_size, &output,
|
||||
_needauthentication ? LEVEL_GUEST : LEVEL_ADMIN);
|
||||
}
|
||||
_lastflush = millis();
|
||||
_buffer_size = 0;
|
||||
}
|
||||
|
||||
// push collected data to buffer and proceed accordingly
|
||||
void SerialService::push2buffer(uint8_t * sbuf, size_t len)
|
||||
{
|
||||
void SerialService::push2buffer(uint8_t *sbuf, size_t len) {
|
||||
if (!_started) {
|
||||
return;
|
||||
}
|
||||
@ -318,7 +314,7 @@ void SerialService::push2buffer(uint8_t * sbuf, size_t len)
|
||||
isCommandFrame = false;
|
||||
}
|
||||
} else {
|
||||
log_esp3d("wrong frame type");
|
||||
log_esp3d_e("wrong frame type");
|
||||
isFrameStarted = false;
|
||||
_buffer_size = 0;
|
||||
}
|
||||
@ -330,7 +326,7 @@ void SerialService::push2buffer(uint8_t * sbuf, size_t len)
|
||||
datalen += (sbuf[i] << 8);
|
||||
log_esp3d("Data len: %d", datalen);
|
||||
if (datalen > (ESP3D_SERIAL_BUFFER_SIZE - 5)) {
|
||||
log_esp3d("Overflow in data len");
|
||||
log_esp3d_e("Overflow in data len");
|
||||
isFrameStarted = false;
|
||||
_buffer_size = 0;
|
||||
}
|
||||
@ -345,10 +341,11 @@ void SerialService::push2buffer(uint8_t * sbuf, size_t len)
|
||||
if (isCommandFrame) {
|
||||
flushbuffer();
|
||||
} else {
|
||||
MKSService::handleFrame(type,(const uint8_t*)_buffer, _buffer_size);
|
||||
MKSService::handleFrame(type, (const uint8_t *)_buffer,
|
||||
_buffer_size);
|
||||
}
|
||||
} else {
|
||||
log_esp3d("Error in data len");
|
||||
log_esp3d_e("Error in data len");
|
||||
}
|
||||
// clear frame infos
|
||||
_buffer_size = 0;
|
||||
@ -360,11 +357,10 @@ void SerialService::push2buffer(uint8_t * sbuf, size_t len)
|
||||
_buffer[_buffer_size] = sbuf[i];
|
||||
_buffer_size++;
|
||||
} else {
|
||||
log_esp3d("Overflow in data len");
|
||||
log_esp3d_e("Overflow in data len");
|
||||
isFrameStarted = false;
|
||||
_buffer_size = 0;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
// frame is not started let see if it is a head
|
||||
@ -377,7 +373,7 @@ void SerialService::push2buffer(uint8_t * sbuf, size_t len)
|
||||
} else {
|
||||
// no so let reset all and just ignore it
|
||||
// TODO should we handle these data ?
|
||||
log_esp3d("Unidentified data : %c %x", sbuf[i],sbuf[i]);
|
||||
log_esp3d_e("Unidentified data : %c %x", sbuf[i], sbuf[i]);
|
||||
isCommandFrame = false;
|
||||
framePos = -1;
|
||||
datalen = 0;
|
||||
@ -418,25 +414,30 @@ void SerialService::push2buffer(uint8_t * sbuf, size_t len)
|
||||
}
|
||||
|
||||
// Reset Serial Setting (baud rate)
|
||||
bool SerialService::reset()
|
||||
{
|
||||
bool SerialService::reset() {
|
||||
log_esp3d("Reset serial");
|
||||
bool res = false;
|
||||
switch (_id) {
|
||||
case MAIN_SERIAL:
|
||||
return Settings_ESP3D::write_uint32 (ESP_BAUD_RATE, Settings_ESP3D::get_default_int32_value(ESP_BAUD_RATE));
|
||||
return Settings_ESP3D::write_uint32(
|
||||
ESP_BAUD_RATE,
|
||||
Settings_ESP3D::get_default_int32_value(ESP_BAUD_RATE));
|
||||
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
|
||||
case BRIDGE_SERIAL:
|
||||
res = Settings_ESP3D::write_byte (ESP_SERIAL_BRIDGE_ON, Settings_ESP3D::get_default_byte_value(ESP_SERIAL_BRIDGE_ON));
|
||||
return res && Settings_ESP3D::write_uint32 (ESP_SERIAL_BRIDGE_BAUD, Settings_ESP3D::get_default_int32_value(ESP_SERIAL_BRIDGE_BAUD));
|
||||
res = Settings_ESP3D::write_byte(
|
||||
ESP_SERIAL_BRIDGE_ON,
|
||||
Settings_ESP3D::get_default_byte_value(ESP_SERIAL_BRIDGE_ON));
|
||||
return res && Settings_ESP3D::write_uint32(
|
||||
ESP_SERIAL_BRIDGE_BAUD,
|
||||
Settings_ESP3D::get_default_int32_value(
|
||||
ESP_SERIAL_BRIDGE_BAUD));
|
||||
#endif // ESP_SERIAL_BRIDGE_OUTPUT
|
||||
default:
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
void SerialService::updateBaudRate(long br)
|
||||
{
|
||||
void SerialService::updateBaudRate(long br) {
|
||||
if (br != baudRate()) {
|
||||
Serials[_serialIndex]->flush();
|
||||
Serials[_serialIndex]->updateBaudRate(br);
|
||||
@ -444,8 +445,7 @@ void SerialService::updateBaudRate(long br)
|
||||
}
|
||||
|
||||
// Get current baud rate
|
||||
long SerialService::baudRate()
|
||||
{
|
||||
long SerialService::baudRate() {
|
||||
long br = 0;
|
||||
br = Serials[_serialIndex]->baudRate();
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
@ -460,16 +460,14 @@ long SerialService::baudRate()
|
||||
return br;
|
||||
}
|
||||
|
||||
size_t SerialService::write(uint8_t c)
|
||||
{
|
||||
size_t SerialService::write(uint8_t c) {
|
||||
if (!_started) {
|
||||
return 0;
|
||||
}
|
||||
return Serials[_serialIndex]->write(c);
|
||||
}
|
||||
|
||||
size_t SerialService::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t SerialService::write(const uint8_t *buffer, size_t size) {
|
||||
if (!_started) {
|
||||
return 0;
|
||||
}
|
||||
@ -485,7 +483,9 @@ size_t SerialService::write(const uint8_t *buffer, size_t size)
|
||||
size_t available = Serials[_serialIndex]->availableForWrite();
|
||||
if (available > 0) {
|
||||
// in case less is sent
|
||||
available = Serials[_serialIndex]->write(&buffertmp[sizesent], (available >= sizetosend)?sizetosend:available);
|
||||
available = Serials[_serialIndex]->write(
|
||||
&buffertmp[sizesent],
|
||||
(available >= sizetosend) ? sizetosend : available);
|
||||
sizetosend -= available;
|
||||
sizesent += available;
|
||||
starttime = millis();
|
||||
@ -497,51 +497,46 @@ size_t SerialService::write(const uint8_t *buffer, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
int SerialService::availableForWrite()
|
||||
{
|
||||
int SerialService::availableForWrite() {
|
||||
if (!_started) {
|
||||
return 0;
|
||||
}
|
||||
return Serials[_serialIndex]->availableForWrite();
|
||||
}
|
||||
|
||||
int SerialService::available()
|
||||
{
|
||||
int SerialService::available() {
|
||||
if (!_started) {
|
||||
return 0;
|
||||
}
|
||||
return Serials[_serialIndex]->available();
|
||||
}
|
||||
|
||||
int SerialService::read()
|
||||
{
|
||||
int SerialService::read() {
|
||||
if (!_started) {
|
||||
return -1;
|
||||
}
|
||||
return Serials[_serialIndex]->read();
|
||||
}
|
||||
|
||||
size_t SerialService::readBytes(uint8_t * sbuf, size_t len)
|
||||
{
|
||||
size_t SerialService::readBytes(uint8_t *sbuf, size_t len) {
|
||||
if (!_started) {
|
||||
return -1;
|
||||
}
|
||||
return Serials[_serialIndex]->readBytes(sbuf, len);
|
||||
}
|
||||
|
||||
void SerialService::flush()
|
||||
{
|
||||
void SerialService::flush() {
|
||||
if (!_started) {
|
||||
return;
|
||||
}
|
||||
Serials[_serialIndex]->flush();
|
||||
}
|
||||
|
||||
void SerialService::swap()
|
||||
{
|
||||
void SerialService::swap() {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
Serials[_serialIndex]->swap();
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
}
|
||||
|
||||
#endif //COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == RAW_SERIAL
|
||||
#endif // COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL ==
|
||||
// RAW_SERIAL
|
||||
|
@ -18,38 +18,25 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
|
||||
#if defined(ESP3DLIB_ENV) && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#include <Arduino.h>
|
||||
#include "serial2socket.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
|
||||
#include "../../core/commands.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "serial2socket.h"
|
||||
|
||||
Serial_2_Socket Serial2Socket;
|
||||
|
||||
Serial_2_Socket::Serial_2_Socket() { end(); }
|
||||
Serial_2_Socket::~Serial_2_Socket() { end(); }
|
||||
void Serial_2_Socket::begin(long speed) { end(); }
|
||||
|
||||
Serial_2_Socket::Serial_2_Socket()
|
||||
{
|
||||
end();
|
||||
}
|
||||
Serial_2_Socket::~Serial_2_Socket()
|
||||
{
|
||||
end();
|
||||
}
|
||||
void Serial_2_Socket::begin(long speed)
|
||||
{
|
||||
end();
|
||||
}
|
||||
void Serial_2_Socket::enable(bool enable) { _started = enable; }
|
||||
|
||||
void Serial_2_Socket::enable(bool enable)
|
||||
{
|
||||
_started = enable;
|
||||
}
|
||||
|
||||
void Serial_2_Socket::pause(bool state)
|
||||
{
|
||||
void Serial_2_Socket::pause(bool state) {
|
||||
_paused = state;
|
||||
if (_paused) {
|
||||
_TXbufferSize = 0;
|
||||
@ -60,13 +47,9 @@ void Serial_2_Socket::pause(bool state)
|
||||
}
|
||||
}
|
||||
|
||||
bool Serial_2_Socket::isPaused()
|
||||
{
|
||||
return _paused;
|
||||
}
|
||||
bool Serial_2_Socket::isPaused() { return _paused; }
|
||||
|
||||
void Serial_2_Socket::end()
|
||||
{
|
||||
void Serial_2_Socket::end() {
|
||||
_TXbufferSize = 0;
|
||||
_RXbufferSize = 0;
|
||||
_RXbufferpos = 0;
|
||||
@ -75,40 +58,27 @@ void Serial_2_Socket::end()
|
||||
_lastflush = millis();
|
||||
}
|
||||
|
||||
long Serial_2_Socket::baudRate()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
long Serial_2_Socket::baudRate() { return 0; }
|
||||
|
||||
bool Serial_2_Socket::started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
bool Serial_2_Socket::started() { return _started; }
|
||||
|
||||
Serial_2_Socket::operator bool() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
Serial_2_Socket::operator bool() const { return true; }
|
||||
|
||||
int Serial_2_Socket::available()
|
||||
{
|
||||
int Serial_2_Socket::available() {
|
||||
if (_paused) {
|
||||
return 0;
|
||||
}
|
||||
return _RXbufferSize;
|
||||
}
|
||||
|
||||
|
||||
size_t Serial_2_Socket::write(uint8_t c)
|
||||
{
|
||||
size_t Serial_2_Socket::write(uint8_t c) {
|
||||
if (!_started || _paused) {
|
||||
return 1;
|
||||
}
|
||||
return write(&c, 1);
|
||||
}
|
||||
|
||||
size_t Serial_2_Socket::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t Serial_2_Socket::write(const uint8_t *buffer, size_t size) {
|
||||
if (buffer == NULL || size == 0 || !_started || _paused) {
|
||||
log_esp3d("Serial2Socket: no data, not started or paused");
|
||||
return size;
|
||||
@ -133,8 +103,7 @@ size_t Serial_2_Socket::write(const uint8_t *buffer, size_t size)
|
||||
return size;
|
||||
}
|
||||
|
||||
int Serial_2_Socket::peek(void)
|
||||
{
|
||||
int Serial_2_Socket::peek(void) {
|
||||
if (_RXbufferSize > 0 && _started) {
|
||||
return _RXbuffer[_RXbufferpos];
|
||||
} else {
|
||||
@ -142,8 +111,7 @@ int Serial_2_Socket::peek(void)
|
||||
}
|
||||
}
|
||||
|
||||
bool Serial_2_Socket::push (const uint8_t *buffer, size_t size)
|
||||
{
|
||||
bool Serial_2_Socket::push(const uint8_t *buffer, size_t size) {
|
||||
if (buffer == NULL || size == 0 || !_started || _paused) {
|
||||
return false;
|
||||
}
|
||||
@ -167,8 +135,7 @@ bool Serial_2_Socket::push (const uint8_t *buffer, size_t size)
|
||||
return false;
|
||||
}
|
||||
|
||||
int Serial_2_Socket::read(void)
|
||||
{
|
||||
int Serial_2_Socket::read(void) {
|
||||
if (_RXbufferSize > 0 && _started && !_paused) {
|
||||
int v = _RXbuffer[_RXbufferpos];
|
||||
_RXbufferpos++;
|
||||
@ -180,25 +147,20 @@ int Serial_2_Socket::read(void)
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Serial_2_Socket::handle()
|
||||
{
|
||||
handle_flush();
|
||||
}
|
||||
void Serial_2_Socket::handle() { handle_flush(); }
|
||||
|
||||
void Serial_2_Socket::handle_flush()
|
||||
{
|
||||
void Serial_2_Socket::handle_flush() {
|
||||
if (_TXbufferSize > 0 && _started && !_paused) {
|
||||
if ((_TXbufferSize>=S2S_TXBUFFERSIZE) || ((millis()- _lastflush) > S2S_FLUSHTIMEOUT)) {
|
||||
if ((_TXbufferSize >= S2S_TXBUFFERSIZE) ||
|
||||
((millis() - _lastflush) > S2S_FLUSHTIMEOUT)) {
|
||||
log_esp3d("force socket flush");
|
||||
flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
void Serial_2_Socket::flush(void)
|
||||
{
|
||||
void Serial_2_Socket::flush(void) {
|
||||
if (_TXbufferSize > 0 && _started && !_paused) {
|
||||
ESP3DOutput output(ESP_SOCKET_SERIAL_CLIENT);
|
||||
// dispatch command
|
||||
|
@ -164,7 +164,7 @@ bool TimeServer::setTime(const char* stime) {
|
||||
log_esp3d("Invalid time format, try without seconds");
|
||||
// allow not to set seconds for lazy guys typing command line
|
||||
if (strptime(stime, "%Y-%m-%dT%H:%M", &tmstruct) == nullptr) {
|
||||
log_esp3d("Invalid time format");
|
||||
log_esp3d_e("Invalid time format");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -21,28 +21,28 @@
|
||||
#include "../../include/esp3d_config.h"
|
||||
|
||||
#ifdef SD_UPDATE_FEATURE
|
||||
#include "esp_config_file.h"
|
||||
#include "../filesystem/esp_sd.h"
|
||||
#include "esp_config_file.h"
|
||||
|
||||
#define LINE_MAX_SIZE 255
|
||||
#define SECTION_MAX_SIZE 10
|
||||
#define KEY_MAX_SIZE 30
|
||||
#define VALUE_MAX_SIZE 128
|
||||
|
||||
const char * protectedkeys[] = {"NOTIF_TOKEN1","NOTIF_TOKEN2","AP_Password","STA_Password","ADMIN_PASSWORD","USER_PASSWORD"} ;
|
||||
const char *protectedkeys[] = {"NOTIF_TOKEN1", "NOTIF_TOKEN2",
|
||||
"AP_Password", "STA_Password",
|
||||
"ADMIN_PASSWORD", "USER_PASSWORD"};
|
||||
|
||||
ESP_ConfigFile::ESP_ConfigFile(const char * path, TProcessingFunction fn)
|
||||
{
|
||||
ESP_ConfigFile::ESP_ConfigFile(const char *path, TProcessingFunction fn) {
|
||||
_filename = (char *)malloc(strlen(path) + 1);
|
||||
strcpy(_filename, path);
|
||||
_pfunction = fn;
|
||||
}
|
||||
|
||||
bool ESP_ConfigFile::processFile()
|
||||
{
|
||||
bool ESP_ConfigFile::processFile() {
|
||||
bool res = true;
|
||||
if (!ESP_SD::exists(_filename)) {
|
||||
log_esp3d("No ini file");
|
||||
log_esp3d_e("No ini file");
|
||||
return false;
|
||||
}
|
||||
ESP_SDFile rFile = ESP_SD::open(_filename);
|
||||
@ -65,7 +65,8 @@ bool ESP_ConfigFile::processFile()
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
if ((c =='\n') || (c =='\r') || !processing || (pos==(LINE_MAX_SIZE-1))) {
|
||||
if ((c == '\n') || (c == '\r') || !processing ||
|
||||
(pos == (LINE_MAX_SIZE - 1))) {
|
||||
line[pos] = '\0';
|
||||
char *stmp = trimSpaces(line);
|
||||
if (strlen(stmp) > 0) {
|
||||
@ -94,12 +95,11 @@ bool ESP_ConfigFile::processFile()
|
||||
rFile.close();
|
||||
return res;
|
||||
}
|
||||
log_esp3d("Cannot open ini file");
|
||||
log_esp3d_e("Cannot open ini file");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESP_ConfigFile::isComment(char * line)
|
||||
{
|
||||
bool ESP_ConfigFile::isComment(char *line) {
|
||||
if (strlen(line) > 0) {
|
||||
if ((line[0] == ';') || (line[0] == '#')) {
|
||||
return true;
|
||||
@ -108,8 +108,7 @@ bool ESP_ConfigFile::isComment(char * line)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESP_ConfigFile::isSection(char * line)
|
||||
{
|
||||
bool ESP_ConfigFile::isSection(char *line) {
|
||||
if (strlen(line) > 0) {
|
||||
if ((line[0] == '[') && (line[strlen(line) - 1] == ']')) {
|
||||
return true;
|
||||
@ -118,8 +117,7 @@ bool ESP_ConfigFile::isSection(char * line)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESP_ConfigFile::isValue(char * line)
|
||||
{
|
||||
bool ESP_ConfigFile::isValue(char *line) {
|
||||
if (strlen(line) > 3) {
|
||||
for (uint8_t i = 1; i < strlen(line) - 2; i++) {
|
||||
if (line[i] == '=') {
|
||||
@ -130,14 +128,12 @@ bool ESP_ConfigFile::isValue(char * line)
|
||||
return false;
|
||||
}
|
||||
|
||||
char * ESP_ConfigFile::getSectionName(char * line)
|
||||
{
|
||||
char *ESP_ConfigFile::getSectionName(char *line) {
|
||||
line[strlen(line) - 1] = '\0';
|
||||
return trimSpaces(&line[1], SECTION_MAX_SIZE);
|
||||
}
|
||||
|
||||
char * ESP_ConfigFile::getKeyName(char * line)
|
||||
{
|
||||
char *ESP_ConfigFile::getKeyName(char *line) {
|
||||
for (uint8_t i = 0; i < strlen(line); i++) {
|
||||
if (line[i] == '=') {
|
||||
line[i] = '\0';
|
||||
@ -147,8 +143,7 @@ char * ESP_ConfigFile::getKeyName(char * line)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char * ESP_ConfigFile::getValue(char * line)
|
||||
{
|
||||
char *ESP_ConfigFile::getValue(char *line) {
|
||||
char *startptr = line + strlen(line) + 1;
|
||||
while (*startptr == '\0') {
|
||||
startptr++;
|
||||
@ -156,8 +151,7 @@ char * ESP_ConfigFile::getValue(char * line)
|
||||
return trimSpaces(startptr, VALUE_MAX_SIZE);
|
||||
}
|
||||
|
||||
char * ESP_ConfigFile::trimSpaces(char * line, uint8_t maxsize)
|
||||
{
|
||||
char *ESP_ConfigFile::trimSpaces(char *line, uint8_t maxsize) {
|
||||
char *endptr = line + strlen(line) - 1;
|
||||
char *startptr = line;
|
||||
while (endptr >= line && isspace(*endptr)) {
|
||||
@ -173,13 +167,9 @@ char * ESP_ConfigFile::trimSpaces(char * line, uint8_t maxsize)
|
||||
return startptr;
|
||||
}
|
||||
|
||||
ESP_ConfigFile::~ESP_ConfigFile()
|
||||
{
|
||||
free(_filename);
|
||||
}
|
||||
ESP_ConfigFile::~ESP_ConfigFile() { free(_filename); }
|
||||
|
||||
bool ESP_ConfigFile::isScrambleKey(const char *key, const char * str)
|
||||
{
|
||||
bool ESP_ConfigFile::isScrambleKey(const char *key, const char *str) {
|
||||
if (strlen(key) > strlen(str)) {
|
||||
return false;
|
||||
}
|
||||
@ -202,8 +192,7 @@ bool ESP_ConfigFile::isScrambleKey(const char *key, const char * str)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESP_ConfigFile::revokeFile()
|
||||
{
|
||||
bool ESP_ConfigFile::revokeFile() {
|
||||
char *filename;
|
||||
if (!ESP_SD::exists(_filename)) {
|
||||
log_esp3d("No ini file to revoke");
|
||||
@ -233,7 +222,8 @@ bool ESP_ConfigFile::revokeFile()
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
if ((c =='\n') || (c =='\r') || !processing || (pos==(LINE_MAX_SIZE-1))) {
|
||||
if ((c == '\n') || (c == '\r') || !processing ||
|
||||
(pos == (LINE_MAX_SIZE - 1))) {
|
||||
line[pos] = '\0';
|
||||
char *stmp = trimSpaces(line);
|
||||
if (strlen(stmp) > 0) {
|
||||
@ -262,7 +252,7 @@ bool ESP_ConfigFile::revokeFile()
|
||||
ESP_SD::remove(_filename);
|
||||
return true;
|
||||
}
|
||||
log_esp3d("Cannot open / create revoked file");
|
||||
log_esp3d_e("Cannot open / create revoked file");
|
||||
if (wFile) {
|
||||
wFile.close();
|
||||
}
|
||||
|
@ -20,13 +20,14 @@
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef SD_UPDATE_FEATURE
|
||||
#include "update_service.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/commands.h"
|
||||
#include "esp_config_file.h"
|
||||
#include "../filesystem/esp_sd.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../filesystem/esp_filesystem.h"
|
||||
#include "../filesystem/esp_sd.h"
|
||||
#include "esp_config_file.h"
|
||||
#include "update_service.h"
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <Update.h>
|
||||
#define U_FS U_SPIFFS
|
||||
@ -35,62 +36,36 @@
|
||||
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
|
||||
|
||||
UpdateService update_service;
|
||||
|
||||
#define CONFIG_FILE "/esp3dcnf.ini"
|
||||
#define FW_FILE "/esp3dfw.bin"
|
||||
#define FS_FILE "/esp3dfs.bin"
|
||||
|
||||
const char * NetstringKeysVal[] = {"hostname",
|
||||
"STA_SSID",
|
||||
"STA_Password",
|
||||
"AP_SSID",
|
||||
"AP_Password"
|
||||
} ;
|
||||
const char* NetstringKeysVal[] = {"hostname", "STA_SSID", "STA_Password",
|
||||
"AP_SSID", "AP_Password"};
|
||||
|
||||
const uint16_t NetstringKeysPos[] = {ESP_HOSTNAME,
|
||||
ESP_STA_SSID,
|
||||
ESP_STA_PASSWORD,
|
||||
ESP_AP_SSID,
|
||||
ESP_AP_PASSWORD
|
||||
} ;
|
||||
const uint16_t NetstringKeysPos[] = {
|
||||
ESP_HOSTNAME, ESP_STA_SSID, ESP_STA_PASSWORD, ESP_AP_SSID, ESP_AP_PASSWORD};
|
||||
|
||||
const char* ServstringKeysVal[] = {
|
||||
"Time_server1",
|
||||
"Time_server2",
|
||||
"Time_server3",
|
||||
"ADMIN_PASSWORD",
|
||||
"USER_PASSWORD",
|
||||
"NOTIF_TOKEN1",
|
||||
"NOTIF_TOKEN2",
|
||||
"NOTIF_TOKEN_Settings"
|
||||
} ;
|
||||
"Time_server1", "Time_server2", "Time_server3", "ADMIN_PASSWORD",
|
||||
"USER_PASSWORD", "NOTIF_TOKEN1", "NOTIF_TOKEN2", "NOTIF_TOKEN_Settings"};
|
||||
|
||||
const uint16_t ServstringKeysPos[] = {
|
||||
ESP_TIME_SERVER1,
|
||||
const uint16_t ServstringKeysPos[] = {ESP_TIME_SERVER1,
|
||||
ESP_TIME_SERVER2,
|
||||
ESP_TIME_SERVER3,
|
||||
ESP_ADMIN_PWD,
|
||||
ESP_USER_PWD,
|
||||
ESP_NOTIFICATION_TOKEN1,
|
||||
ESP_NOTIFICATION_TOKEN2,
|
||||
ESP_NOTIFICATION_SETTINGS
|
||||
} ;
|
||||
ESP_NOTIFICATION_SETTINGS};
|
||||
|
||||
const char * IPKeysVal[] = {"STA_IP",
|
||||
"STA_GW",
|
||||
"STA_MSK",
|
||||
"STA_DNS",
|
||||
"AP_IP"
|
||||
} ;
|
||||
const char* IPKeysVal[] = {"STA_IP", "STA_GW", "STA_MSK", "STA_DNS", "AP_IP"};
|
||||
|
||||
const uint16_t IPKeysPos[] = {ESP_STA_IP_VALUE,
|
||||
ESP_STA_GATEWAY_VALUE,
|
||||
ESP_STA_MASK_VALUE,
|
||||
ESP_STA_DNS_VALUE,
|
||||
ESP_AP_IP_VALUE
|
||||
} ;
|
||||
const uint16_t IPKeysPos[] = {ESP_STA_IP_VALUE, ESP_STA_GATEWAY_VALUE,
|
||||
ESP_STA_MASK_VALUE, ESP_STA_DNS_VALUE,
|
||||
ESP_AP_IP_VALUE};
|
||||
|
||||
const char* ServintKeysVal[] = {
|
||||
"Serial_Bridge_Baud"
|
||||
@ -101,28 +76,18 @@ const char * ServintKeysVal[] = {
|
||||
"WebDav_Port",
|
||||
"FTP_Control_Port",
|
||||
"FTP_Active_Port ",
|
||||
"FTP_Passive_Port"
|
||||
} ;
|
||||
"FTP_Passive_Port"};
|
||||
|
||||
const uint16_t ServintKeysPos[] = {
|
||||
ESP_SERIAL_BRIDGE_BAUD,
|
||||
ESP_HTTP_PORT,
|
||||
ESP_TELNET_PORT,
|
||||
ESP_SENSOR_INTERVAL,
|
||||
ESP_WEBSOCKET_PORT,
|
||||
ESP_WEBDAV_PORT,
|
||||
ESP_FTP_CTRL_PORT,
|
||||
ESP_FTP_DATA_ACTIVE_PORT,
|
||||
ESP_FTP_DATA_PASSIVE_PORT
|
||||
} ;
|
||||
ESP_SERIAL_BRIDGE_BAUD, ESP_HTTP_PORT,
|
||||
ESP_TELNET_PORT, ESP_SENSOR_INTERVAL,
|
||||
ESP_WEBSOCKET_PORT, ESP_WEBDAV_PORT,
|
||||
ESP_FTP_CTRL_PORT, ESP_FTP_DATA_ACTIVE_PORT,
|
||||
ESP_FTP_DATA_PASSIVE_PORT};
|
||||
|
||||
const char * SysintKeysVal[] = {"Baud_rate",
|
||||
"Boot_delay"
|
||||
} ;
|
||||
const char* SysintKeysVal[] = {"Baud_rate", "Boot_delay"};
|
||||
|
||||
const uint16_t SysintKeysPos[] = {ESP_BAUD_RATE,
|
||||
ESP_BOOT_DELAY
|
||||
} ;
|
||||
const uint16_t SysintKeysPos[] = {ESP_BAUD_RATE, ESP_BOOT_DELAY};
|
||||
|
||||
const char* ServboolKeysVal[] = {"Serial_Bridge_active",
|
||||
"AUTONOTIFICATION",
|
||||
@ -134,21 +99,15 @@ const char * ServboolKeysVal[] = {"Serial_Bridge_active",
|
||||
"CHECK_FOR_UPDATE",
|
||||
"Active_buzzer",
|
||||
"Active_Internet_time",
|
||||
"Radio_enabled"
|
||||
} ;
|
||||
"Radio_enabled"};
|
||||
|
||||
const uint16_t ServboolKeysPos[] = {ESP_SERIAL_BRIDGE_ON,
|
||||
ESP_AUTO_NOTIFICATION,
|
||||
ESP_HTTP_ON,
|
||||
ESP_TELNET_ON,
|
||||
ESP_WEBSOCKET_ON,
|
||||
ESP_WEBDAV_ON,
|
||||
ESP_TIME_IS_DST,
|
||||
ESP_SD_CHECK_UPDATE_AT_BOOT,
|
||||
ESP_BUZZER,
|
||||
ESP_INTERNET_TIME,
|
||||
ESP_BOOT_RADIO_STATE
|
||||
} ;
|
||||
const uint16_t ServboolKeysPos[] = {
|
||||
ESP_SERIAL_BRIDGE_ON, ESP_AUTO_NOTIFICATION,
|
||||
ESP_HTTP_ON, ESP_TELNET_ON,
|
||||
ESP_WEBSOCKET_ON, ESP_WEBDAV_ON,
|
||||
ESP_TIME_IS_DST, ESP_SD_CHECK_UPDATE_AT_BOOT,
|
||||
ESP_BUZZER, ESP_INTERNET_TIME,
|
||||
ESP_BOOT_RADIO_STATE};
|
||||
|
||||
const char* SysboolKeysVal[] = {"Active_Serial_Bridge",
|
||||
"Active_Remote_Screen",
|
||||
@ -158,8 +117,7 @@ const char * SysboolKeysVal[] = {"Active_Serial_Bridge",
|
||||
"Active_Telnet",
|
||||
"Active_BT",
|
||||
"Boot_verbose",
|
||||
"Secure_serial"
|
||||
} ;
|
||||
"Secure_serial"};
|
||||
|
||||
const uint16_t SysboolKeysPos[] = {ESP_SERIAL_BRIDGE_FLAG,
|
||||
ESP_REMOTE_SCREEN_FLAG,
|
||||
@ -169,30 +127,19 @@ const uint16_t SysboolKeysPos[] = {ESP_SERIAL_BRIDGE_FLAG,
|
||||
ESP_TELNET_FLAG,
|
||||
ESP_BT_FLAG,
|
||||
ESP_VERBOSE_BOOT,
|
||||
ESP_SECURE_SERIAL
|
||||
} ;
|
||||
ESP_SECURE_SERIAL};
|
||||
|
||||
const char * NetbyteKeysVal[] = {
|
||||
"AP_channel"
|
||||
} ;
|
||||
const char* NetbyteKeysVal[] = {"AP_channel"};
|
||||
|
||||
const uint16_t NetbyteKeysPos[] = {
|
||||
ESP_AP_CHANNEL
|
||||
} ;
|
||||
const char * ServbyteKeysVal[] = {"Time_zone",
|
||||
"Sesion_timeout",
|
||||
"SD_SPEED"
|
||||
} ;
|
||||
const uint16_t NetbyteKeysPos[] = {ESP_AP_CHANNEL};
|
||||
const char* ServbyteKeysVal[] = {"Time_zone", "Sesion_timeout", "SD_SPEED"};
|
||||
|
||||
const uint16_t ServbyteKeysPos[] = {ESP_TIMEZONE,
|
||||
ESP_SESSION_TIMEOUT,
|
||||
ESP_SD_SPEED_DIV
|
||||
} ;
|
||||
|
||||
|
||||
bool processString(const char** keysval, const uint16_t * keypos, const size_t size, const char * key, const char * value, char & T, int & P )
|
||||
{
|
||||
const uint16_t ServbyteKeysPos[] = {ESP_TIMEZONE, ESP_SESSION_TIMEOUT,
|
||||
ESP_SD_SPEED_DIV};
|
||||
|
||||
bool processString(const char** keysval, const uint16_t* keypos,
|
||||
const size_t size, const char* key, const char* value,
|
||||
char& T, int& P) {
|
||||
for (uint i = 0; i < size; i++) {
|
||||
if (strcasecmp(keysval[i], key) == 0) {
|
||||
// if it is a previouly saved scrambled password ignore it
|
||||
@ -206,8 +153,9 @@ bool processString(const char** keysval, const uint16_t * keypos, const size_t s
|
||||
return false;
|
||||
}
|
||||
|
||||
bool processInt(const char** keysval, const uint16_t * keypos, const size_t size, const char * key, const char * value, char & T, int & P, uint32_t & v)
|
||||
{
|
||||
bool processInt(const char** keysval, const uint16_t* keypos, const size_t size,
|
||||
const char* key, const char* value, char& T, int& P,
|
||||
uint32_t& v) {
|
||||
for (uint i = 0; i < size; i++) {
|
||||
if (strcasecmp(keysval[i], key) == 0) {
|
||||
T = 'I';
|
||||
@ -219,15 +167,20 @@ bool processInt(const char** keysval, const uint16_t * keypos, const size_t size
|
||||
return false;
|
||||
}
|
||||
|
||||
bool processBool(const char** keysval, const uint16_t * keypos, const size_t size, const char * key, const char * value, char & T, int & P, byte & b)
|
||||
{
|
||||
bool processBool(const char** keysval, const uint16_t* keypos,
|
||||
const size_t size, const char* key, const char* value, char& T,
|
||||
int& P, byte& b) {
|
||||
for (uint i = 0; i < size; i++) {
|
||||
if (strcasecmp(keysval[i], key) == 0) {
|
||||
T = 'B';
|
||||
P = keypos[i];
|
||||
if ((strcasecmp("yes",value)==0)||(strcasecmp("on", value)==0)||(strcasecmp("true", value)==0)||(strcasecmp("1", value)==0) ) {
|
||||
if ((strcasecmp("yes", value) == 0) || (strcasecmp("on", value) == 0) ||
|
||||
(strcasecmp("true", value) == 0) || (strcasecmp("1", value) == 0)) {
|
||||
b = 1;
|
||||
} else if ((strcasecmp("no", value)==0)||(strcasecmp("off", value)==0)||(strcasecmp("false", value)==0)||(strcasecmp("0", value)==0) ) {
|
||||
} else if ((strcasecmp("no", value) == 0) ||
|
||||
(strcasecmp("off", value) == 0) ||
|
||||
(strcasecmp("false", value) == 0) ||
|
||||
(strcasecmp("0", value) == 0)) {
|
||||
b = 0;
|
||||
} else {
|
||||
P = -1;
|
||||
@ -238,11 +191,10 @@ bool processBool(const char** keysval, const uint16_t * keypos, const size_t siz
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Parsing all entries of file once is faster that checking all possible parameters for each line of file
|
||||
bool processingFileFunction (const char * section, const char * key, const char * value)
|
||||
{
|
||||
// Parsing all entries of file once is faster that checking all possible
|
||||
// parameters for each line of file
|
||||
bool processingFileFunction(const char* section, const char* key,
|
||||
const char* value) {
|
||||
bool res = true;
|
||||
char T = '\0';
|
||||
int P = -1;
|
||||
@ -253,16 +205,21 @@ bool processingFileFunction (const char * section, const char * key, const char
|
||||
// network / services / system sections
|
||||
if (strcasecmp("network", section) == 0) {
|
||||
if (!done) {
|
||||
done = processString(NetstringKeysVal,NetstringKeysPos,sizeof(NetstringKeysVal)/sizeof(char*), key, value, T, P );
|
||||
done = processString(NetstringKeysVal, NetstringKeysPos,
|
||||
sizeof(NetstringKeysVal) / sizeof(char*), key, value,
|
||||
T, P);
|
||||
}
|
||||
if (!done) {
|
||||
done = processString(IPKeysVal,IPKeysPos,sizeof(IPKeysVal)/sizeof(char*), key, value, T, P );
|
||||
done = processString(IPKeysVal, IPKeysPos,
|
||||
sizeof(IPKeysVal) / sizeof(char*), key, value, T, P);
|
||||
if (done) {
|
||||
T = 'A';
|
||||
}
|
||||
}
|
||||
if (!done) {
|
||||
done = processInt(NetbyteKeysVal,NetbyteKeysPos,sizeof(NetbyteKeysVal)/sizeof(char*), key, value, T, P, v);
|
||||
done = processInt(NetbyteKeysVal, NetbyteKeysPos,
|
||||
sizeof(NetbyteKeysVal) / sizeof(char*), key, value, T,
|
||||
P, v);
|
||||
if (done) {
|
||||
T = 'B';
|
||||
b = v;
|
||||
@ -326,16 +283,24 @@ bool processingFileFunction (const char * section, const char * key, const char
|
||||
}
|
||||
} else if (strcasecmp("services", section) == 0) {
|
||||
if (!done) {
|
||||
done = processString(ServstringKeysVal,ServstringKeysPos,sizeof(ServstringKeysVal)/sizeof(char*), key, value, T, P );
|
||||
done = processString(ServstringKeysVal, ServstringKeysPos,
|
||||
sizeof(ServstringKeysVal) / sizeof(char*), key,
|
||||
value, T, P);
|
||||
}
|
||||
if (!done) {
|
||||
done = processInt(ServintKeysVal,ServintKeysPos,sizeof(ServintKeysVal)/sizeof(char*), key, value, T, P, v);
|
||||
done = processInt(ServintKeysVal, ServintKeysPos,
|
||||
sizeof(ServintKeysVal) / sizeof(char*), key, value, T,
|
||||
P, v);
|
||||
}
|
||||
if (!done) {
|
||||
done = processBool(ServboolKeysVal,ServboolKeysPos,sizeof(ServboolKeysVal)/sizeof(char*), key, value, T, P, b);
|
||||
done = processBool(ServboolKeysVal, ServboolKeysPos,
|
||||
sizeof(ServboolKeysVal) / sizeof(char*), key, value, T,
|
||||
P, b);
|
||||
}
|
||||
if (!done) {
|
||||
done = processInt(ServbyteKeysVal,ServbyteKeysPos,sizeof(ServbyteKeysVal)/sizeof(char*), key, value, T, P, v);
|
||||
done = processInt(ServbyteKeysVal, ServbyteKeysPos,
|
||||
sizeof(ServbyteKeysVal) / sizeof(char*), key, value, T,
|
||||
P, v);
|
||||
if (done) {
|
||||
T = 'B';
|
||||
b = v;
|
||||
@ -389,12 +354,17 @@ bool processingFileFunction (const char * section, const char * key, const char
|
||||
}
|
||||
} else if (strcasecmp("system", section) == 0) {
|
||||
if (!done) {
|
||||
done = processInt(SysintKeysVal,SysintKeysPos,sizeof(SysintKeysVal)/sizeof(char*), key, value, T, P, v);
|
||||
done = processInt(SysintKeysVal, SysintKeysPos,
|
||||
sizeof(SysintKeysVal) / sizeof(char*), key, value, T, P,
|
||||
v);
|
||||
}
|
||||
if (!done) {
|
||||
done = processBool(SysboolKeysVal,SysboolKeysPos,sizeof(SysboolKeysVal)/sizeof(char*), key, value, T, P, b);
|
||||
done = processBool(SysboolKeysVal, SysboolKeysPos,
|
||||
sizeof(SysboolKeysVal) / sizeof(char*), key, value, T,
|
||||
P, b);
|
||||
}
|
||||
//Target Firmware None / Marlin / Repetier / MarlinKimbra / Smoothieware / GRBL
|
||||
// Target Firmware None / Marlin / Repetier / MarlinKimbra / Smoothieware /
|
||||
// GRBL
|
||||
if (!done) {
|
||||
if (strcasecmp("TargetFW", key) == 0) {
|
||||
T = 'B';
|
||||
@ -446,8 +416,7 @@ bool processingFileFunction (const char * section, const char * key, const char
|
||||
UpdateService::UpdateService() {}
|
||||
UpdateService::~UpdateService() {}
|
||||
|
||||
bool UpdateService::flash(const char * filename, int type)
|
||||
{
|
||||
bool UpdateService::flash(const char* filename, int type) {
|
||||
bool res = false;
|
||||
if (ESP_SD::exists(filename)) {
|
||||
log_esp3d("Update found");
|
||||
@ -475,12 +444,12 @@ bool UpdateService::flash(const char * filename, int type)
|
||||
}
|
||||
} else {
|
||||
Update.end();
|
||||
log_esp3d("Wrong size");
|
||||
log_esp3d_e("Wrong size");
|
||||
}
|
||||
}
|
||||
sdfile.close();
|
||||
} else {
|
||||
log_esp3d("Cannot open file");
|
||||
log_esp3d_e("Cannot open file");
|
||||
}
|
||||
if (issucess) {
|
||||
res = true;
|
||||
@ -504,8 +473,7 @@ bool UpdateService::flash(const char * filename, int type)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool UpdateService::begin()
|
||||
{
|
||||
bool UpdateService::begin() {
|
||||
bool res = false;
|
||||
if (Settings_ESP3D::read_byte(ESP_SD_CHECK_UPDATE_AT_BOOT) != 0) {
|
||||
if (ESP_SD::accessFS()) {
|
||||
@ -519,10 +487,10 @@ bool UpdateService::begin()
|
||||
log_esp3d("Revoking ini file done");
|
||||
res = true;
|
||||
} else {
|
||||
log_esp3d("Revoking ini file failed");
|
||||
log_esp3d_e("Revoking ini file failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("Processing ini file failed");
|
||||
log_esp3d_e("Processing ini file failed");
|
||||
}
|
||||
if (flash(FW_FILE, U_FLASH)) {
|
||||
res = true;
|
||||
@ -540,9 +508,7 @@ bool UpdateService::begin()
|
||||
|
||||
return res;
|
||||
}
|
||||
void UpdateService::end()
|
||||
{
|
||||
}
|
||||
void UpdateService::end() {}
|
||||
|
||||
void UpdateService::handle() {}
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
Lebosse (ESP3D Integration)
|
||||
|
||||
*/
|
||||
// #define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
|
||||
#if defined(WEBDAV_FEATURE)
|
||||
@ -35,7 +35,6 @@
|
||||
|
||||
#include "ESPWebDAV.h"
|
||||
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <PolledTimeout.h>
|
||||
@ -821,7 +820,7 @@ void ESPWebDAVCore::handleGet(ResourceType resource, WebDavFile& file,
|
||||
|
||||
// no lock on GET
|
||||
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
long tStart = millis();
|
||||
#endif
|
||||
|
||||
@ -899,7 +898,7 @@ void ESPWebDAVCore::handleGet(ResourceType resource, WebDavFile& file,
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
for (size_t i = 0; i < 80 && i < numRead; i++) {
|
||||
log_esp3ds("%c", buf[i] < 32 || buf[i] > 127 ? '.' : buf[i]);
|
||||
}
|
||||
@ -953,7 +952,7 @@ void ESPWebDAVCore::handlePut(ResourceType resource) {
|
||||
|
||||
if (contentLengthHeader != 0) {
|
||||
uint8_t buf[BUFFER_SIZE];
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
long tStart = millis();
|
||||
#endif
|
||||
size_t numRemaining = contentLengthHeader;
|
||||
@ -1542,7 +1541,7 @@ void ESPWebDAVCore::send(const String& code, const char* content_type,
|
||||
|
||||
if (content.length()) {
|
||||
sendContent(content);
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
log_esp3d("send content (%d bytes):", (int)content.length());
|
||||
for (size_t i = 0; i < DEBUG_LEN && i < content.length(); i++) {
|
||||
log_esp3ds("%c", content[i] < 32 || content[i] > 127 ? '.' : content[i]);
|
||||
@ -1571,7 +1570,7 @@ bool ESPWebDAVCore::sendContent(const char* data, size_t size) {
|
||||
log_esp3d("---- chunk %s", chunkSize);
|
||||
}
|
||||
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
#if defined(ESP_LOG_FEATURE)
|
||||
log_esp3d("---- %scontent (%d bytes):", _chunked ? "chunked " : "",
|
||||
(int)size);
|
||||
for (size_t i = 0; i < DEBUG_LEN && i < size; i++) {
|
||||
|
@ -23,7 +23,7 @@
|
||||
Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling)
|
||||
Modified 22 Jan 2021 by Luc Lebosse (ESP3D Integration)
|
||||
*/
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
// #define ESP_LOG_FEATURE LOG_OUTPUT_SERIAL0
|
||||
#include "../../include/esp3d_config.h"
|
||||
|
||||
#if defined(WEBDAV_FEATURE)
|
||||
@ -31,8 +31,7 @@
|
||||
|
||||
// Sections are copied from ESP8266Webserver
|
||||
|
||||
String ESPWebDAV::getMimeType(const String& path)
|
||||
{
|
||||
String ESPWebDAV::getMimeType(const String& path) {
|
||||
if (path.endsWith(".html")) {
|
||||
return "text/html";
|
||||
} else if (path.endsWith(".htm")) {
|
||||
@ -82,11 +81,7 @@ String ESPWebDAV::getMimeType(const String& path)
|
||||
return "application/octet-stream";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
String ESPWebDAV::urlDecode(const String& text)
|
||||
{
|
||||
String ESPWebDAV::urlDecode(const String& text) {
|
||||
String decoded = "";
|
||||
char temp[] = "0x00";
|
||||
unsigned int len = text.length();
|
||||
@ -110,10 +105,9 @@ String ESPWebDAV::urlDecode(const String& text)
|
||||
return decoded;
|
||||
}
|
||||
|
||||
void ESPWebDAV::handleClient()
|
||||
{
|
||||
void ESPWebDAV::handleClient() {
|
||||
if (!server) {
|
||||
log_esp3d("handleClient: server is null");
|
||||
log_esp3d_e("handleClient: server is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -123,7 +117,8 @@ void ESPWebDAV::handleClient()
|
||||
// take it over
|
||||
locClient = server->available();
|
||||
m_persistent_timer_ms = millis();
|
||||
log_esp3d("NEW CLIENT-------------------------------------------------------");
|
||||
log_esp3d(
|
||||
"NEW CLIENT-------------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,14 +134,14 @@ void ESPWebDAV::handleClient()
|
||||
if (!m_persistent)
|
||||
// close the connection
|
||||
{
|
||||
log_esp3d("CLOSE CONNECTION-------------------------------------------------------");
|
||||
log_esp3d(
|
||||
"CLOSE "
|
||||
"CONNECTION-------------------------------------------------------");
|
||||
locClient.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ESPWebDAV::parseRequest()
|
||||
{
|
||||
bool ESPWebDAV::parseRequest() {
|
||||
// Read the first line of HTTP request
|
||||
String req = locClient.readStringUntil('\r');
|
||||
locClient.readStringUntil('\n');
|
||||
|
@ -18,32 +18,30 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
|
||||
#if defined(HTTP_FEATURE) || defined(WS_DATA_FEATURE)
|
||||
|
||||
|
||||
#include "websocket_server.h"
|
||||
#include <WebSocketsServer.h>
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
|
||||
#include "../../core/commands.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../authentication/authentication_service.h"
|
||||
#include "websocket_server.h"
|
||||
|
||||
WebSocket_Server websocket_terminal_server("webui-v3");
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
WebSocket_Server websocket_data_server("arduino");
|
||||
#endif // WS_DATA_FEATURE
|
||||
void WebSocket_Server::pushMSG (const char * data)
|
||||
{
|
||||
void WebSocket_Server::pushMSG(const char *data) {
|
||||
if (_websocket_server) {
|
||||
_websocket_server->broadcastTXT(data);
|
||||
log_esp3d("[%u]Broadcast %s", _current_id, data);
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocket_Server::enableOnly (uint num)
|
||||
{
|
||||
void WebSocket_Server::enableOnly(uint num) {
|
||||
// some sanity check
|
||||
if (_websocket_server) {
|
||||
for (uint8_t i = 0; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++)
|
||||
@ -53,61 +51,62 @@ void WebSocket_Server::enableOnly (uint num)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WebSocket_Server::pushMSG (uint num, const char * data)
|
||||
{
|
||||
void WebSocket_Server::pushMSG(uint num, const char *data) {
|
||||
if (_websocket_server) {
|
||||
_websocket_server->sendTXT(num, data);
|
||||
log_esp3d("[%u]Send %s", num, data);
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocket_Server::closeClients()
|
||||
{
|
||||
void WebSocket_Server::closeClients() {
|
||||
if (_websocket_server) {
|
||||
_websocket_server->disconnect();
|
||||
}
|
||||
}
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
// Events for Websocket bridge
|
||||
void handle_Websocket_Server_Event(uint8_t num, uint8_t type, uint8_t * payload, size_t length)
|
||||
{
|
||||
void handle_Websocket_Server_Event(uint8_t num, uint8_t type, uint8_t *payload,
|
||||
size_t length) {
|
||||
(void)num;
|
||||
switch (type) {
|
||||
case WStype_DISCONNECTED:
|
||||
log_esp3d("[%u] Disconnected! port %d", num,websocket_data_server.port());
|
||||
log_esp3d("[%u] Disconnected! port %d", num,
|
||||
websocket_data_server.port());
|
||||
break;
|
||||
case WStype_CONNECTED: {
|
||||
log_esp3d("[%u] Connected! port %d, %s", num,websocket_data_server.port(), payload);
|
||||
}
|
||||
break;
|
||||
log_esp3d("[%u] Connected! port %d, %s", num,
|
||||
websocket_data_server.port(), payload);
|
||||
} break;
|
||||
case WStype_TEXT:
|
||||
log_esp3d("[%u] get Text: %s port %d", num, payload,websocket_data_server.port());
|
||||
log_esp3d("[%u] get Text: %s port %d", num, payload,
|
||||
websocket_data_server.port());
|
||||
websocket_data_server.push2RXbuffer(payload, length);
|
||||
break;
|
||||
case WStype_BIN:
|
||||
log_esp3d("[%u] get binary length: %u port %d", num, length,websocket_data_server.port());
|
||||
log_esp3d("[%u] get binary length: %u port %d", num, length,
|
||||
websocket_data_server.port());
|
||||
websocket_data_server.push2RXbuffer(payload, length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
#endif // WS_DATA_FEATURE
|
||||
#if defined(HTTP_FEATURE)
|
||||
// Events for Websocket used in WebUI for events and serial bridge
|
||||
void handle_Websocket_Terminal_Event(uint8_t num, uint8_t type, uint8_t * payload, size_t length)
|
||||
{
|
||||
void handle_Websocket_Terminal_Event(uint8_t num, uint8_t type,
|
||||
uint8_t *payload, size_t length) {
|
||||
(void)payload;
|
||||
(void)length;
|
||||
String msg;
|
||||
switch (type) {
|
||||
case WStype_DISCONNECTED:
|
||||
log_esp3d("[%u] Socket Disconnected port %d!", num,websocket_terminal_server.port());
|
||||
log_esp3d("[%u] Socket Disconnected port %d!", num,
|
||||
websocket_terminal_server.port());
|
||||
break;
|
||||
case WStype_CONNECTED: {
|
||||
log_esp3d("[%u] Connected! port %d, %s", num,websocket_terminal_server.port(), (const char *)payload);
|
||||
log_esp3d("[%u] Connected! port %d, %s", num,
|
||||
websocket_terminal_server.port(), (const char *)payload);
|
||||
msg = "currentID:" + String(num);
|
||||
// send message to client
|
||||
websocket_terminal_server.set_currentID(num);
|
||||
@ -115,9 +114,9 @@ void handle_Websocket_Terminal_Event(uint8_t num, uint8_t type, uint8_t * payloa
|
||||
msg = "activeID:" + String(num);
|
||||
websocket_terminal_server.pushMSG(msg.c_str());
|
||||
websocket_terminal_server.enableOnly(num);
|
||||
log_esp3d("[%u] Socket connected port %d", num,websocket_terminal_server.port());
|
||||
}
|
||||
break;
|
||||
log_esp3d("[%u] Socket connected port %d", num,
|
||||
websocket_terminal_server.port());
|
||||
} break;
|
||||
case WStype_TEXT:
|
||||
#if defined(AUTHENTICATION_FEATURE)
|
||||
// we do not expect any input but ping to get session timeout if any
|
||||
@ -125,35 +124,33 @@ void handle_Websocket_Terminal_Event(uint8_t num, uint8_t type, uint8_t * payloa
|
||||
msg = (const char *)payload;
|
||||
if (msg.startsWith("PING:")) {
|
||||
String session = msg.substring(5);
|
||||
String response = "PING:"+String(AuthenticationService::getSessionRemaining(session.c_str()));
|
||||
String response =
|
||||
"PING:" + String(AuthenticationService::getSessionRemaining(
|
||||
session.c_str()));
|
||||
response += ":" + String(AuthenticationService::getSessionTimeout());
|
||||
websocket_terminal_server.pushMSG(num, response.c_str());
|
||||
}
|
||||
}
|
||||
#endif // AUTHENTICATION_FEATURE
|
||||
//log_esp3d("[IGNORED][%u] get Text: %s port %d", num, payload, websocket_terminal_server.port());
|
||||
// log_esp3d("[IGNORED][%u] get Text: %s port %d", num, payload,
|
||||
// websocket_terminal_server.port());
|
||||
break;
|
||||
case WStype_BIN:
|
||||
// we do not expect any input
|
||||
//log_esp3d("[IGNORED][%u] get binary length: %u port %d", num, length, websocket_terminal_server.port());
|
||||
// log_esp3d("[IGNORED][%u] get binary length: %u port %d", num, length,
|
||||
// websocket_terminal_server.port());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
#endif // HTTP_FEATURE
|
||||
|
||||
int WebSocket_Server::available()
|
||||
{
|
||||
return _RXbufferSize;
|
||||
}
|
||||
int WebSocket_Server::availableForWrite()
|
||||
{
|
||||
int WebSocket_Server::available() { return _RXbufferSize; }
|
||||
int WebSocket_Server::availableForWrite() {
|
||||
return TXBUFFERSIZE - _TXbufferSize;
|
||||
}
|
||||
WebSocket_Server::WebSocket_Server(const char * protocol )
|
||||
{
|
||||
WebSocket_Server::WebSocket_Server(const char *protocol) {
|
||||
_websocket_server = nullptr;
|
||||
_started = false;
|
||||
_port = 0;
|
||||
@ -161,14 +158,9 @@ WebSocket_Server::WebSocket_Server(const char * protocol )
|
||||
_RXbuffer = nullptr;
|
||||
_RXbufferSize = 0;
|
||||
_protocol = protocol;
|
||||
|
||||
}
|
||||
WebSocket_Server::~WebSocket_Server()
|
||||
{
|
||||
end();
|
||||
}
|
||||
bool WebSocket_Server::begin(uint16_t port)
|
||||
{
|
||||
WebSocket_Server::~WebSocket_Server() { end(); }
|
||||
bool WebSocket_Server::begin(uint16_t port) {
|
||||
end();
|
||||
if (port == 0) {
|
||||
_port = Settings_ESP3D::read_uint32(ESP_HTTP_PORT) + 1;
|
||||
@ -187,7 +179,7 @@ bool WebSocket_Server::begin(uint16_t port)
|
||||
}
|
||||
#endif // HTTP_FEATURE
|
||||
#if defined(WS_DATA_FEATURE) // terminal websocket for HTTP
|
||||
if((port != 0) && _protocol!="debug") {
|
||||
if ((port != 0) && _protocol != "log") {
|
||||
_websocket_server->onEvent(handle_Websocket_Server_Event);
|
||||
_RXbuffer = (uint8_t *)malloc(RXBUFFERSIZE + 1);
|
||||
if (!_RXbuffer) {
|
||||
@ -202,8 +194,7 @@ bool WebSocket_Server::begin(uint16_t port)
|
||||
return _started;
|
||||
}
|
||||
|
||||
void WebSocket_Server::end()
|
||||
{
|
||||
void WebSocket_Server::end() {
|
||||
_current_id = 0;
|
||||
_TXbufferSize = 0;
|
||||
if (_RXbuffer) {
|
||||
@ -220,28 +211,16 @@ void WebSocket_Server::end()
|
||||
_started = false;
|
||||
}
|
||||
|
||||
WebSocket_Server::operator bool() const { return _started; }
|
||||
|
||||
WebSocket_Server::operator bool() const
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
|
||||
void WebSocket_Server::set_currentID(uint8_t current_id)
|
||||
{
|
||||
void WebSocket_Server::set_currentID(uint8_t current_id) {
|
||||
_current_id = current_id;
|
||||
}
|
||||
uint8_t WebSocket_Server::get_currentID()
|
||||
{
|
||||
return _current_id;
|
||||
}
|
||||
uint8_t WebSocket_Server::get_currentID() { return _current_id; }
|
||||
|
||||
size_t WebSocket_Server::write(uint8_t c)
|
||||
{
|
||||
return write(&c,1);
|
||||
}
|
||||
size_t WebSocket_Server::write(uint8_t c) { return write(&c, 1); }
|
||||
|
||||
size_t WebSocket_Server::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t WebSocket_Server::write(const uint8_t *buffer, size_t size) {
|
||||
if (_started) {
|
||||
if ((buffer == nullptr) || (!_websocket_server) || (size == 0)) {
|
||||
return 0;
|
||||
@ -266,8 +245,7 @@ size_t WebSocket_Server::write(const uint8_t *buffer, size_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WebSocket_Server::push2RXbuffer(uint8_t * sbuf, size_t len)
|
||||
{
|
||||
void WebSocket_Server::push2RXbuffer(uint8_t *sbuf, size_t len) {
|
||||
if (!_RXbuffer || !_started) {
|
||||
return;
|
||||
}
|
||||
@ -302,8 +280,7 @@ void WebSocket_Server::push2RXbuffer(uint8_t * sbuf, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocket_Server::flushRXbuffer()
|
||||
{
|
||||
void WebSocket_Server::flushRXbuffer() {
|
||||
if (!_RXbuffer || !_started) {
|
||||
_RXbufferSize = 0;
|
||||
return;
|
||||
@ -316,18 +293,18 @@ void WebSocket_Server::flushRXbuffer()
|
||||
_RXbufferSize = 0;
|
||||
}
|
||||
|
||||
|
||||
void WebSocket_Server::handle()
|
||||
{
|
||||
void WebSocket_Server::handle() {
|
||||
Hal::wait(0);
|
||||
if (_started) {
|
||||
if (_TXbufferSize > 0) {
|
||||
if ((_TXbufferSize>=TXBUFFERSIZE) || ((millis()- _lastTXflush) > FLUSHTIMEOUT)) {
|
||||
if ((_TXbufferSize >= TXBUFFERSIZE) ||
|
||||
((millis() - _lastTXflush) > FLUSHTIMEOUT)) {
|
||||
flushTXbuffer();
|
||||
}
|
||||
}
|
||||
if (_RXbufferSize > 0) {
|
||||
if ((_RXbufferSize>=RXBUFFERSIZE) || ((millis()- _lastRXflush) > FLUSHTIMEOUT)) {
|
||||
if ((_RXbufferSize >= RXBUFFERSIZE) ||
|
||||
((millis() - _lastRXflush) > FLUSHTIMEOUT)) {
|
||||
flushRXbuffer();
|
||||
}
|
||||
}
|
||||
@ -337,31 +314,24 @@ void WebSocket_Server::handle()
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocket_Server::flush(void)
|
||||
{
|
||||
void WebSocket_Server::flush(void) {
|
||||
flushTXbuffer();
|
||||
flushRXbuffer();
|
||||
}
|
||||
|
||||
void WebSocket_Server::flushTXbuffer(void)
|
||||
{
|
||||
void WebSocket_Server::flushTXbuffer(void) {
|
||||
if (_started) {
|
||||
if ((_TXbufferSize > 0) && (_websocket_server->connectedClients() > 0)) {
|
||||
|
||||
if (_websocket_server) {
|
||||
_websocket_server->broadcastBIN(_TXbuffer, _TXbufferSize);
|
||||
log_esp3d("WS Broadcast bin port %d: %d bytes", port(), _TXbufferSize);
|
||||
}
|
||||
// refresh timout
|
||||
_lastTXflush = millis();
|
||||
|
||||
}
|
||||
}
|
||||
// reset buffer
|
||||
_TXbufferSize = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // HTTP_FEATURE || WS_DATA_FEATURE
|
||||
|
||||
|
@ -25,19 +25,18 @@
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
#include "../wifi/wificonfig.h"
|
||||
#include "../network/netconfig.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../network/netconfig.h"
|
||||
#include "../wifi/wificonfig.h"
|
||||
|
||||
|
||||
const uint8_t DEFAULT_AP_MASK_VALUE[] = {255, 255, 255, 0};
|
||||
|
||||
|
||||
/**
|
||||
* Check if SSID string is valid
|
||||
*/
|
||||
bool WiFiConfig::isSSIDValid (const char * ssid)
|
||||
{
|
||||
bool WiFiConfig::isSSIDValid(const char* ssid) {
|
||||
// limited size
|
||||
// char c;
|
||||
if (strlen(ssid) > MAX_SSID_LENGTH || strlen(ssid) < MIN_SSID_LENGTH) {
|
||||
@ -52,8 +51,7 @@ bool WiFiConfig::isSSIDValid (const char * ssid)
|
||||
return true;
|
||||
}
|
||||
|
||||
const char * WiFiConfig::hostname()
|
||||
{
|
||||
const char* WiFiConfig::hostname() {
|
||||
static String tmp;
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
if (WiFi.getMode() == WIFI_AP) {
|
||||
@ -61,7 +59,6 @@ const char * WiFiConfig::hostname()
|
||||
tmp = NetConfig::hostname(true);
|
||||
} else {
|
||||
tmp = WiFi.hostname();
|
||||
|
||||
}
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
@ -80,13 +77,13 @@ const char * WiFiConfig::hostname()
|
||||
* Check if password string is valid
|
||||
*/
|
||||
|
||||
bool WiFiConfig::isPasswordValid (const char * password)
|
||||
{
|
||||
bool WiFiConfig::isPasswordValid(const char* password) {
|
||||
if (strlen(password) == 0) {
|
||||
return true; // open network
|
||||
}
|
||||
// limited size
|
||||
if ((strlen (password) > MAX_PASSWORD_LENGTH) || (strlen (password) < MIN_PASSWORD_LENGTH)) {
|
||||
if ((strlen(password) > MAX_PASSWORD_LENGTH) ||
|
||||
(strlen(password) < MIN_PASSWORD_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -96,8 +93,7 @@ bool WiFiConfig::isPasswordValid (const char * password)
|
||||
* Get WiFi signal strength
|
||||
*/
|
||||
|
||||
int32_t WiFiConfig::getSignal (int32_t RSSI, bool filter)
|
||||
{
|
||||
int32_t WiFiConfig::getSignal(int32_t RSSI, bool filter) {
|
||||
if (RSSI < MIN_RSSI && filter) {
|
||||
return 0;
|
||||
}
|
||||
@ -108,15 +104,13 @@ int32_t WiFiConfig::getSignal (int32_t RSSI, bool filter)
|
||||
return 100;
|
||||
}
|
||||
return (2 * (RSSI + 100));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect client to AP
|
||||
*/
|
||||
|
||||
bool WiFiConfig::ConnectSTA2AP()
|
||||
{
|
||||
bool WiFiConfig::ConnectSTA2AP() {
|
||||
String msg, msg_out;
|
||||
uint8_t count = 0;
|
||||
uint8_t dot = 0;
|
||||
@ -130,7 +124,6 @@ bool WiFiConfig::ConnectSTA2AP()
|
||||
}
|
||||
#endif // #if COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
while (status != WL_CONNECTED && count < 40) {
|
||||
|
||||
switch (status) {
|
||||
case WL_NO_SSID_AVAIL:
|
||||
msg = "No SSID";
|
||||
@ -165,8 +158,7 @@ bool WiFiConfig::ConnectSTA2AP()
|
||||
/*
|
||||
* Start client mode (Station)
|
||||
*/
|
||||
bool WiFiConfig::StartSTA()
|
||||
{
|
||||
bool WiFiConfig::StartSTA() {
|
||||
log_esp3d("StartSTA");
|
||||
if ((WiFi.getMode() == WIFI_AP) || (WiFi.getMode() == WIFI_AP_STA)) {
|
||||
WiFi.softAPdisconnect();
|
||||
@ -195,10 +187,12 @@ bool WiFiConfig::StartSTA()
|
||||
ESP3DOutput output(ESP_ALL_CLIENTS);
|
||||
if (Settings_ESP3D::isVerboseBoot()) {
|
||||
String stmp;
|
||||
stmp = "Connecting to '" + SSID + "'";;
|
||||
stmp = "Connecting to '" + SSID + "'";
|
||||
;
|
||||
output.printMSG(stmp.c_str());
|
||||
}
|
||||
if (WiFi.begin(SSID.c_str(), (password.length() > 0)?password.c_str():nullptr)) {
|
||||
if (WiFi.begin(SSID.c_str(),
|
||||
(password.length() > 0) ? password.c_str() : nullptr)) {
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
WiFi.setSleepMode(WIFI_NONE_SLEEP);
|
||||
WiFi.hostname(NetConfig::hostname(true));
|
||||
@ -218,8 +212,7 @@ bool WiFiConfig::StartSTA()
|
||||
* Setup and start Access point
|
||||
*/
|
||||
|
||||
bool WiFiConfig::StartAP(bool setupMode)
|
||||
{
|
||||
bool WiFiConfig::StartAP(bool setupMode) {
|
||||
ESP3DOutput output(ESP_ALL_CLIENTS);
|
||||
// Sanity check
|
||||
if ((WiFi.getMode() == WIFI_STA) || (WiFi.getMode() == WIFI_AP_STA)) {
|
||||
@ -249,7 +242,8 @@ bool WiFiConfig::StartAP(bool setupMode)
|
||||
IPAddress gw(0, 0, 0, 0);
|
||||
IPAddress mask(DEFAULT_AP_MASK_VALUE);
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
log_esp3d("Use: %s / %s / %s", ip.toString().c_str(),ip.toString().c_str(),mask.toString().c_str());
|
||||
log_esp3d("Use: %s / %s / %s", ip.toString().c_str(), ip.toString().c_str(),
|
||||
mask.toString().c_str());
|
||||
if (!WiFi.softAPConfig(ip, setupMode ? ip : gw, mask)) {
|
||||
output.printERROR("Set IP to AP failed");
|
||||
} else {
|
||||
@ -257,7 +251,9 @@ bool WiFiConfig::StartAP(bool setupMode)
|
||||
}
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
// Start AP
|
||||
if(WiFi.softAP(SSID.c_str(), (password.length() > 0)?password.c_str():nullptr, channel)) {
|
||||
if (WiFi.softAP(SSID.c_str(),
|
||||
(password.length() > 0) ? password.c_str() : nullptr,
|
||||
channel)) {
|
||||
String stmp = "AP SSID: '" + SSID;
|
||||
if (password.length() > 0) {
|
||||
stmp += "' is started and protected by password";
|
||||
@ -275,7 +271,8 @@ bool WiFiConfig::StartAP(bool setupMode)
|
||||
// on some phone 100 is ok but on some other it is not enough so 2000 is ok
|
||||
Hal::wait(2000);
|
||||
// Set static IP
|
||||
log_esp3d("Use: %s / %s / %s", ip.toString().c_str(),ip.toString().c_str(),mask.toString().c_str());
|
||||
log_esp3d("Use: %s / %s / %s", ip.toString().c_str(), ip.toString().c_str(),
|
||||
mask.toString().c_str());
|
||||
if (!WiFi.softAPConfig(ip, setupMode ? ip : gw, mask)) {
|
||||
output.printERROR("Set IP to AP failed");
|
||||
} else {
|
||||
@ -287,21 +284,17 @@ bool WiFiConfig::StartAP(bool setupMode)
|
||||
return true;
|
||||
} else {
|
||||
output.printERROR("Starting AP failed");
|
||||
log_esp3d("Starting AP failed");
|
||||
log_esp3d_e("Starting AP failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool WiFiConfig::started()
|
||||
{
|
||||
return (WiFi.getMode() != WIFI_OFF);
|
||||
}
|
||||
bool WiFiConfig::started() { return (WiFi.getMode() != WIFI_OFF); }
|
||||
|
||||
/**
|
||||
* begin WiFi setup
|
||||
*/
|
||||
bool WiFiConfig::begin(int8_t & espMode)
|
||||
{
|
||||
bool WiFiConfig::begin(int8_t& espMode) {
|
||||
bool res = false;
|
||||
end();
|
||||
log_esp3d("Starting Wifi Config");
|
||||
@ -330,7 +323,6 @@ bool WiFiConfig::begin(int8_t & espMode)
|
||||
// let setup to handle the change
|
||||
res = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return res;
|
||||
@ -340,8 +332,7 @@ bool WiFiConfig::begin(int8_t & espMode)
|
||||
* End WiFi
|
||||
*/
|
||||
|
||||
void WiFiConfig::end()
|
||||
{
|
||||
void WiFiConfig::end() {
|
||||
// Sanity check
|
||||
if ((WiFi.getMode() == WIFI_STA) || (WiFi.getMode() == WIFI_AP_STA)) {
|
||||
if (WiFi.isConnected()) {
|
||||
@ -360,8 +351,7 @@ void WiFiConfig::end()
|
||||
* Handle not critical actions that must be done in sync environement
|
||||
*/
|
||||
|
||||
void WiFiConfig::handle()
|
||||
{
|
||||
void WiFiConfig::handle() {
|
||||
// to avoid mixed mode
|
||||
if (WiFi.getMode() == WIFI_AP_STA) {
|
||||
if (WiFi.scanComplete() != WIFI_SCAN_RUNNING) {
|
||||
@ -370,8 +360,7 @@ void WiFiConfig::handle()
|
||||
}
|
||||
}
|
||||
|
||||
const char* WiFiConfig::getSleepModeString ()
|
||||
{
|
||||
const char* WiFiConfig::getSleepModeString() {
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if (WiFi.getSleep()) {
|
||||
return "modem";
|
||||
@ -393,11 +382,13 @@ const char* WiFiConfig::getSleepModeString ()
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
}
|
||||
|
||||
const char* WiFiConfig::getPHYModeString (uint8_t wifimode)
|
||||
{
|
||||
const char* WiFiConfig::getPHYModeString(uint8_t wifimode) {
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
uint8_t PhyMode;
|
||||
esp_wifi_get_protocol ((wifi_interface_t)((wifimode == WIFI_STA)?ESP_IF_WIFI_STA:ESP_IF_WIFI_AP), &PhyMode);
|
||||
esp_wifi_get_protocol(
|
||||
(wifi_interface_t)((wifimode == WIFI_STA) ? ESP_IF_WIFI_STA
|
||||
: ESP_IF_WIFI_AP),
|
||||
&PhyMode);
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
(void)wifimode;
|
||||
@ -414,8 +405,7 @@ const char* WiFiConfig::getPHYModeString (uint8_t wifimode)
|
||||
}
|
||||
}
|
||||
|
||||
bool WiFiConfig::is_AP_visible()
|
||||
{
|
||||
bool WiFiConfig::is_AP_visible() {
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
wifi_config_t conf;
|
||||
esp_wifi_get_config((wifi_interface_t)ESP_IF_WIFI_AP, &conf);
|
||||
@ -428,8 +418,7 @@ bool WiFiConfig::is_AP_visible()
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
}
|
||||
|
||||
const char * WiFiConfig::AP_SSID()
|
||||
{
|
||||
const char* WiFiConfig::AP_SSID() {
|
||||
static String ssid;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
wifi_config_t conf;
|
||||
@ -444,8 +433,7 @@ const char * WiFiConfig::AP_SSID()
|
||||
return ssid.c_str();
|
||||
}
|
||||
|
||||
const char * WiFiConfig::AP_Auth_String()
|
||||
{
|
||||
const char* WiFiConfig::AP_Auth_String() {
|
||||
uint8_t mode = 0;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
wifi_config_t conf;
|
||||
@ -471,8 +459,7 @@ const char * WiFiConfig::AP_Auth_String()
|
||||
}
|
||||
}
|
||||
|
||||
const char * WiFiConfig::AP_Gateway_String()
|
||||
{
|
||||
const char* WiFiConfig::AP_Gateway_String() {
|
||||
static String tmp;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
tcpip_adapter_ip_info_t ip_AP;
|
||||
@ -482,15 +469,14 @@ const char * WiFiConfig::AP_Gateway_String()
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
struct ip_info ip_AP;
|
||||
if (!wifi_get_ip_info(SOFTAP_IF, &ip_AP)) {
|
||||
log_esp3d("Error getting gateway ip");
|
||||
log_esp3d_e("Error getting gateway ip");
|
||||
}
|
||||
tmp = IPAddress(ip_AP.gw).toString();
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
return tmp.c_str();
|
||||
}
|
||||
|
||||
const char * WiFiConfig::AP_Mask_String()
|
||||
{
|
||||
const char* WiFiConfig::AP_Mask_String() {
|
||||
static String tmp;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
tcpip_adapter_ip_info_t ip_AP;
|
||||
@ -500,15 +486,14 @@ const char * WiFiConfig::AP_Mask_String()
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
struct ip_info ip_AP;
|
||||
if (!wifi_get_ip_info(SOFTAP_IF, &ip_AP)) {
|
||||
log_esp3d("Error getting mask ip");
|
||||
log_esp3d_e("Error getting mask ip");
|
||||
}
|
||||
tmp = IPAddress(ip_AP.netmask).toString();
|
||||
#endif // ARDUINO_ARCH_ESP8266
|
||||
return tmp.c_str();
|
||||
}
|
||||
|
||||
const char * WiFiConfig::getConnectedSTA(uint8_t * totalcount, bool reset)
|
||||
{
|
||||
const char* WiFiConfig::getConnectedSTA(uint8_t* totalcount, bool reset) {
|
||||
static uint8_t count = 0;
|
||||
static uint8_t current = 0;
|
||||
static String data;
|
||||
@ -577,4 +562,3 @@ const char * WiFiConfig::getConnectedSTA(uint8_t * totalcount, bool reset)
|
||||
}
|
||||
|
||||
#endif // WIFI_FEATURE
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user