Skip to content

Commit ac20d3d

Browse files
committed
Sync with ESP3D 3.0
some fix for esp32 core 3.0.4 / idf 5.1.4
1 parent 214526b commit ac20d3d

File tree

12 files changed

+81
-50
lines changed

12 files changed

+81
-50
lines changed

src/core/commands/ESP201.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ void ESP3DCommands::ESP201(int cmd_params_pos, ESP3DMessage* msg) {
123123
}
124124
}
125125
value = digitalRead(pin);
126-
ok_msg = String(value);
127126
}
127+
ok_msg = String(value);
128128
}
129129
}
130130
}

src/esp3dlib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "core/esp3d_commands.h"
3232
#include "core/esp3d_hal.h"
3333
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
34-
#include <soc/rtc_wdt.h>
34+
#include <rtc_wdt.h>
3535
#endif // CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
3636
#ifdef SDSUPPORT
3737
#include "modules/filesystem/esp_sd.h"

src/include/esp3d_defines.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ typedef uint ESP3DSettingIndex;
137137
#define ESP_SERIAL_BRIDGE_BAUD 1225 // 4 bytes= int
138138
#define ESP_TIME_ZONE 1229 // 7 bytes 6+1 = string
139139
#define ESP_ETH_STA_IP_VALUE 1237 // 4 bytes xxx.xxx.xxx.xxx
140-
#define ESP_ETH_STA_MASK_VALUE 1240 // 4 bytes xxx.xxx.xxx.xxx
141-
#define ESP_ETH_STA_GATEWAY_VALUE 1244 // 4 bytes xxx.xxx.xxx.xxx
142-
#define ESP_ETH_STA_DNS_VALUE 1248 // 4 bytes xxx.xxx.xxx.xxx
143-
#define ESP_USB_SERIAL_BAUD_RATE 1252 // 4 bytes= int
140+
#define ESP_ETH_STA_MASK_VALUE 1241 // 4 bytes xxx.xxx.xxx.xxx
141+
#define ESP_ETH_STA_GATEWAY_VALUE 1245 // 4 bytes xxx.xxx.xxx.xxx
142+
#define ESP_ETH_STA_DNS_VALUE 1249 // 4 bytes xxx.xxx.xxx.xxx
143+
#define ESP_USB_SERIAL_BAUD_RATE 1253 // 4 bytes= int
144144

145145
// Hidden password
146146
#define HIDDEN_PASSWORD "********"

src/include/esp3d_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define _VERSION_ESP3D_H
2323

2424
// version and sources location
25-
#define FW_VERSION "3.0.0.2b1"
25+
#define FW_VERSION "3.0.0.4b1"
2626
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
2727

2828
#endif //_VERSION_ESP3D_H

src/modules/buzzer/buzzer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ bool BuzzerDevice::begin() {
5454
end();
5555
}
5656
#if defined(ARDUINO_ARCH_ESP32)
57-
setToneChannel(0);
58-
ledcSetup(0, 12000, 8);
59-
#endif // defined(ARDUINO_ARCH_ESP32)
57+
ledcAttachChannel(0, 12000, 8, 0);
58+
#endif // defined(ARDUINO_ARCH_ESP32)
6059
if (ESP3DSettings::readByte(ESP_BUZZER) == 1) {
6160
_started = true;
6261
playsound(5000, 240);

src/modules/ethernet/ethconfig.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,14 @@ bool EthConfig::begin(int8_t& espMode) {
161161
}
162162
if (res) {
163163
// Static IP or DHCP client ?
164-
if ((ESP3DSettings::readByte(ESP_ETH_STA_IP_MODE) == DHCP_MODE)) {
164+
if ((ESP3DSettings::readByte(ESP_ETH_STA_IP_MODE) != DHCP_MODE)) {
165+
int32_t IP = ESP3DSettings::read_IP(ESP_ETH_STA_IP_VALUE);
166+
int32_t GW = ESP3DSettings::read_IP(ESP_ETH_STA_GATEWAY_VALUE);
167+
int32_t MK = ESP3DSettings::read_IP(ESP_ETH_STA_MASK_VALUE);
168+
int32_t DNS = ESP3DSettings::read_IP(ESP_ETH_STA_DNS_VALUE);
169+
IPAddress ip(IP), mask(MK), gateway(GW), dns(DNS);
170+
ETH.config(ip, gateway, mask, dns);
171+
} else {
165172
uint64_t start = millis();
166173
String ip = ETH.localIP().toString();
167174
esp3d_log("IP");

src/modules/ftp/FtpServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void FtpServer::handle() {
260260
} else if (cmdStage == FTP_Client) { // Ftp server idle
261261
if (ftpServer->hasClient()) {
262262
client.stop();
263-
client = ftpServer->available();
263+
client = ftpServer->accept();
264264
}
265265
if (client.connected()) { // A client connected
266266
clientConnected();
@@ -1051,7 +1051,7 @@ int FtpServer::dataConnect(bool out150) {
10511051
while (!data.connected() && count-- > 0) {
10521052
if (dataServer->hasClient()) {
10531053
data.stop();
1054-
data = dataServer->available();
1054+
data = dataServer->accept();
10551055
}
10561056
delay(1);
10571057
}

src/modules/http/handlers/handle-command.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,9 @@
2929
#include "../../../core/esp3d_commands.h"
3030
#include "../../../core/esp3d_message.h"
3131
#include "../../../core/esp3d_settings.h"
32+
#include "../../../core/esp3d_string.h"
3233
#include "../../authentication/authentication_service.h"
3334

34-
const unsigned char realTimeCommands[] = {
35-
'!', '~', '?', 0x18, 0x84, 0x85, 0x90, 0x92, 0x93, 0x94, 0x95,
36-
0x96, 0x97, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0xA0, 0xA1};
37-
bool isRealTimeCommand(unsigned char c) {
38-
for (unsigned int i = 0; i < sizeof(realTimeCommands); i++) {
39-
if (c == realTimeCommands[i]) {
40-
return true;
41-
}
42-
}
43-
return false;
44-
}
4535

4636
// Handle web command query and send answer//////////////////////////////
4737
void HTTP_Server::handle_web_command() {
@@ -53,32 +43,42 @@ void HTTP_Server::handle_web_command() {
5343
}
5444
// esp3d_log("Authentication = %d", auth_level);
5545
String cmd = "";
46+
bool isRealTimeCommand = false;
5647
if (_webserver->hasArg("cmd")) {
5748
cmd = _webserver->arg("cmd");
49+
esp3d_log("Command is %s", cmd.c_str());
5850
if (!cmd.endsWith("\n")) {
59-
if (ESP3DSettings::GetFirmwareTarget() == GRBL) {
51+
esp3d_log("Command is not ending with \\n");
52+
if (ESP3DSettings::GetFirmwareTarget() == GRBL || ESP3DSettings::GetFirmwareTarget() == GRBLHAL) {
6053
uint len = cmd.length();
61-
if (!((len == 1 && isRealTimeCommand(cmd[0])) ||
62-
(len == 2 && isRealTimeCommand(cmd[1])))) {
54+
if (!((len == 1 && esp3d_string::isRealTimeCommand(cmd[0])) ||
55+
(len == 2 && esp3d_string::isRealTimeCommand(cmd[1])))) {
6356
cmd += "\n";
57+
esp3d_log("Command is not realtime, adding \\n");
6458
} else { // no need \n for realtime command
59+
esp3d_log("Command is realtime, no need to add \\n");
60+
isRealTimeCommand = true;
6561
// remove the 0XC2 that should not be there
66-
if (len == 2 && isRealTimeCommand(cmd[1]) && cmd[1] == 0xC2) {
62+
if (len == 2 && esp3d_string::isRealTimeCommand(cmd[1]) && cmd[1] == 0xC2) {
6763
cmd[0] = cmd[1];
6864
cmd[1] = 0x0;
65+
esp3d_log("Command is realtime, removing 0xC2");
6966
}
7067
}
7168
} else {
69+
esp3d_log("Command is not realtime, adding \\n");
7270
cmd += "\n"; // need to validate command
7371
}
72+
} else {
73+
esp3d_log("Command is ending with \\n");
7474
}
75-
esp3d_log("Web Command: %s", cmd.c_str());
75+
esp3d_log("Message type is %s for %s", isRealTimeCommand ? "realtimecmd" : "unique", cmd.c_str());
7676
if (esp3d_commands.is_esp_command((uint8_t *)cmd.c_str(), cmd.length())) {
77-
ESP3DMessage *msg = ESP3DMessageManager::newMsg(
77+
ESP3DMessage *msg = esp3d_message_manager.newMsg(
7878
ESP3DClientType::http, esp3d_commands.getOutputClient(),
7979
(uint8_t *)cmd.c_str(), cmd.length(), auth_level);
8080
if (msg) {
81-
msg->type = ESP3DMessageType::unique;
81+
msg->type = ESP3DMessageType::unique; //ESP3D command is always unique
8282
msg->request_id.code = 200;
8383
// process command
8484
esp3d_commands.process(msg);
@@ -91,7 +91,7 @@ void HTTP_Server::handle_web_command() {
9191
// no need to wait to answer then
9292
_webserver->send(200, "text/plain", "ESP3D says: command forwarded");
9393
esp3d_commands.dispatch(cmd.c_str(), esp3d_commands.getOutputClient(),
94-
no_id, ESP3DMessageType::unique,
94+
no_id, isRealTimeCommand ? ESP3DMessageType::realtimecmd :ESP3DMessageType::unique,
9595
ESP3DClientType::http, auth_level);
9696
}
9797
} else if (_webserver->hasArg("ping")) {

src/modules/http/handlers/handle-config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void HTTP_Server::handle_config() {
3939
if (_webserver->hasArg("json")) {
4040
cmd += " json=" + _webserver->arg("json");
4141
}
42-
ESP3DMessage *msg = ESP3DMessageManager::newMsg(
42+
ESP3DMessage *msg = esp3d_message_manager.newMsg(
4343
ESP3DClientType::http, ESP3DClientType::http, (uint8_t *)cmd.c_str(),
4444
cmd.length(), auth_level);
4545
if (msg) {

src/modules/serial/serial_service_esp32.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,35 @@ void ESP3DSerialService::receiveCb() {
8686
if (!started()) {
8787
return;
8888
}
89+
//take mutex
8990
if (xSemaphoreTake(_mutex, portMAX_DELAY)) {
90-
uint32_t now = millis();
91-
while ((millis() - now) < SERIAL_COMMUNICATION_TIMEOUT) {
92-
if (Serials[_serialIndex]->available()) {
93-
_buffer[_buffer_size] = Serials[_serialIndex]->read();
94-
now = millis();
95-
if (esp3d_string::isRealTimeCommand(_buffer[_buffer_size])) {
96-
flushChar(_buffer[_buffer_size]);
97-
_buffer[_buffer_size] = '\0'; //remove realtime command from buffer
98-
} else {
99-
_buffer_size++;
100-
if (_buffer_size > ESP3D_SERIAL_BUFFER_SIZE ||
101-
_buffer[_buffer_size - 1] == '\n') {
102-
flushBuffer();
103-
}
91+
// Get expected len of data
92+
size_t count = Serials[_serialIndex]->available();
93+
94+
//loop until each byte is handled
95+
while (count > 0) {
96+
int data = Serials[_serialIndex]->read();
97+
98+
// If read() failed we leave
99+
if (data == -1) {
100+
esp3d_log_e("Serial read failed unexpectedly");
101+
break; // only break to release mutex
102+
}
103+
//take the char
104+
count--;
105+
_buffer[_buffer_size] = (uint8_t)data;
106+
//check what next step is
107+
if (esp3d_string::isRealTimeCommand(_buffer[_buffer_size])) {
108+
flushChar(_buffer[_buffer_size]);
109+
_buffer[_buffer_size] = '\0'; //remove realtime command from buffer
110+
} else {
111+
_buffer_size++;
112+
if (_buffer_size > ESP3D_SERIAL_BUFFER_SIZE || _buffer[_buffer_size - 1] == '\n') {
113+
flushBuffer();
104114
}
105115
}
106116
}
107-
117+
//release mutex
108118
xSemaphoreGive(_mutex);
109119
} else {
110120
esp3d_log_e("Mutex not taken");
@@ -256,4 +266,4 @@ bool ESP3DSerialService::reset() {
256266

257267
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL ||
258268
// defined(ESP_SERIAL_BRIDGE_OUTPUT)
259-
#endif // ARDUINO_ARCH_ESP32
269+
#endif // ARDUINO_ARCH_ESP32

0 commit comments

Comments
 (0)