Skip to content

Commit

Permalink
Merge pull request #448 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored May 23, 2022
2 parents 74150e7 + 8fdb9c7 commit 57ed5e0
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 35 deletions.
Binary file modified FluidNC/data/index.html.gz
Binary file not shown.
5 changes: 5 additions & 0 deletions FluidNC/src/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "Machine/MachineConfig.h" // config
#include "Serial.h" // execute_realtime_command

void Channel::flushRx() {
_linelen = 0;
_lastWasCR = false;
}

Channel* Channel::pollLine(char* line) {
handle();
while (1) {
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ class Channel : public Stream {
virtual void ack(Error status);
const char* name() { return _name; }
virtual int rx_buffer_available() = 0;
virtual void flushRx();
};
1 change: 1 addition & 0 deletions FluidNC/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static void reset_variables() {
// Sync cleared gcode and planner positions to current system position.
plan_sync_position();
gc_sync_position();
allChannels.flushRx();
report_init_message(allChannels);
mc_init();
}
Expand Down
6 changes: 6 additions & 0 deletions FluidNC/src/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ String AllChannels::info() {
return retval;
}

void AllChannels::flushRx() {
for (auto channel : _channelq) {
channel->flushRx();
}
}

size_t AllChannels::write(uint8_t data) {
for (auto channel : _channelq) {
channel->write(data);
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AllChannels : public Channel {
int available() override { return 0; }
int read() { return -1; }
int peek() { return -1; }
void flush() {}
void flushRx();

// All channels cannot be a direct command source so
// its rx_buffer_available() method should not be called.
Expand Down
1 change: 0 additions & 1 deletion FluidNC/src/StartupLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class StartupLog : public Channel {
size_t readBytes(char* buffer, size_t length) override { return 0; };
int peek(void) override { return -1; }
size_t write(uint8_t data) override;
void flush() override {}

Channel* pollLine(char* line) override { return nullptr; }

Expand Down
9 changes: 9 additions & 0 deletions FluidNC/src/Uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,12 @@ void uartInit() {
void Uart::config_message(const char* prefix, const char* usage) {
log_info(prefix << usage << "Uart Tx:" << _txd_pin.name() << " Rx:" << _rxd_pin.name() << " RTS:" << _rts_pin.name() << " Baud:" << baud);
}

void Uart::flushRx() {
uart_flush_input(_uart_num);
_pushback = -1;
while (_queue.size()) {
_queue.pop();
}
Channel::flushRx();
}
2 changes: 1 addition & 1 deletion FluidNC/src/Uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Uart : public Channel, public Configuration::Configurable {
size_t write(const uint8_t* buffer, size_t length) override;
// inline size_t write(const char* buffer, size_t size) { return write(reinterpret_cast<const uint8_t*>(buffer), size); }
// size_t write(const char* text) override;
void flush() { uart_flush(_uart_num); }
void flushRx() override;
bool flushTxTimed(TickType_t ticks);

bool setCr(bool on) {
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/WebUI/BTConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace WebUI {
int available() override { return SerialBT.available(); }
int read() override { return SerialBT.read(); }
int peek() override { return SerialBT.peek(); }
void flush() override { return SerialBT.flush(); }
void flush() override { SerialBT.flush(); }
size_t write(uint8_t data) override;
// 512 is RX_QUEUE_SIZE which is defined in BluetoothSerial.cpp but not in its .h
int rx_buffer_available() override { return 512 - available(); }
Expand Down
18 changes: 6 additions & 12 deletions FluidNC/src/WebUI/InputBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ namespace WebUI {
_RXbufferpos = 0;
}

void InputBuffer::end() {
_RXbufferSize = 0;
_RXbufferpos = 0;
void InputBuffer::flushRx() {
begin();
Channel::flushRx();
}

void InputBuffer::end() { begin(); }

InputBuffer::operator bool() const { return true; }

int InputBuffer::available() { return _RXbufferSize; }
Expand Down Expand Up @@ -70,13 +72,5 @@ namespace WebUI {
}
}

void InputBuffer::flush(void) {
//No need currently
//keep for compatibility
}

InputBuffer::~InputBuffer() {
_RXbufferSize = 0;
_RXbufferpos = 0;
}
InputBuffer::~InputBuffer() { begin(); }
}
2 changes: 1 addition & 1 deletion FluidNC/src/WebUI/InputBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace WebUI {
int read(void);
bool push(const char* data);
bool push(char data);
void flush(void);
void flushRx(void) override;

int rx_buffer_available() { return RXBUFFERSIZE - available(); }

Expand Down
6 changes: 6 additions & 0 deletions FluidNC/src/WebUI/Serial2Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ namespace WebUI {
}
}

void Serial_2_Socket::flushRx() {
_RXbufferSize = 0;
_RXbufferpos = 0;
Channel::flush();
}

Serial_2_Socket::~Serial_2_Socket() {
if (_web_socket) {
detachWS();
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/WebUI/Serial2Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace WebUI {
bool push(const uint8_t* data, size_t length);
bool push(const char* data);
void flush(void);
void flushRx(void) override;
void handle_flush();
bool attachWS(WebSocketsServer* web_socket);
bool detachWS();
Expand Down
6 changes: 6 additions & 0 deletions FluidNC/src/WebUI/TelnetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ namespace WebUI {
return no_error;
}

void Telnet_Server::flushRx() {
_RXbufferSize = 0;
_RXbufferpos = 0;
Channel::flushRx();
}

void Telnet_Server::end() {
_setupdone = false;
_RXbufferSize = 0;
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/WebUI/TelnetServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace WebUI {
bool push(uint8_t data);
bool push(const uint8_t* data, int datasize);
void flush() override {}
void flushRx() override;

int rx_buffer_available() override;

Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/WebUI/WebClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace WebUI {
_buflen = 0;
}
}
void WebClient::flushRx() { Channel::flushRx(); }

WebClient::~WebClient() {
flush();
Expand Down
2 changes: 2 additions & 0 deletions FluidNC/src/WebUI/WebClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace WebUI {
int read() { return -1; }
int peek() { return -1; }

void flushRx() override;

int rx_buffer_available() { return BUFLEN - available(); }

private:
Expand Down
34 changes: 17 additions & 17 deletions FluidNC/src/WebUI/WebSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,32 +367,31 @@ namespace WebUI {
return deleteObject(LocalFS, parameter, out);
}

static void listDir(fs::FS& fs, const char* dirname, size_t levels, Channel& out) {
File root = fs.open(dirname);
if (!root) {
report_status_message(Error::FsFailedOpenDir, out);
return;
}
static void listDir(fs::FS& fs, File root, String indent, size_t levels, Channel& out) {
if (!root.isDirectory()) {
report_status_message(Error::FsDirNotFound, out);
log_info("Not directory");
root.close();
return;
}
File file = root.openNextFile();
while (file) {

File file;
while (file = root.openNextFile()) {
if (file.isDirectory()) {
if (levels) {
listDir(fs, file.name(), levels - 1, out);
out << "[DIR: " << indent << file.name() << "]\n";
listDir(fs, file, indent + " ", levels - 1, out);
}
} else {
allChannels << "[FILE:" << file.name() << "|SIZE:" << file.size() << "]\n";
out << "[FILE:" << indent << file.name() << "|SIZE:" << file.size() << "]\n";
}
file = root.openNextFile();
file.close();
}
root.close();
}

static void listFs(fs::FS& fs, const char* fsname, size_t levels, uint64_t totalBytes, uint64_t usedBytes, Channel& out) {
out << '\n';
listDir(fs, "/", levels, out);
listDir(fs, fs.open("/"), " ", levels, out);
out << "[" << fsname;
out << " Free:" << formatBytes(totalBytes - usedBytes);
out << " Used:" << formatBytes(usedBytes);
Expand Down Expand Up @@ -422,32 +421,33 @@ namespace WebUI {
return Error::Ok;
}

static void listDirJSON(fs::FS fs, const char* dirname, size_t levels, JSONencoder* j) {
static void listDirJSON(fs::FS fs, File root, size_t levels, JSONencoder* j) {
j->begin_array("files");
File root = fs.open(dirname);
File file = root.openNextFile();
while (file) {
const char* tailName = strchr(file.name(), '/');
tailName = tailName ? tailName + 1 : file.name();
if (file.isDirectory() && levels) {
j->begin_array(tailName);
listDirJSON(fs, file.name(), levels - 1, j);
listDirJSON(fs, file, levels - 1, j);
j->end_array();
} else {
j->begin_object();
j->member("name", tailName);
j->member("size", file.size());
j->end_object();
}
file.close();
file = root.openNextFile();
}
root.close();
j->end_array();
}

static Error listLocalFilesJSON(char* parameter, AuthenticationLevel auth_level, Channel& out) { // No ESP command
JSONencoder j(false, out);
j.begin();
listDirJSON(LocalFS, "/", 4, &j);
listDirJSON(LocalFS, LocalFS.open("/"), 4, &j);
j.member("total", LocalFS.totalBytes());
j.member("used", LocalFS.usedBytes());
j.member("occupation", String(long(100 * LocalFS.usedBytes() / LocalFS.totalBytes())));
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ wifi_deps =
arduinoWebSockets=https://github.com/Links2004/arduinoWebSockets

[common_esp32]
platform = espressif32@4.2.0
platform = espressif32@^4.3.0

; See FluidNC/ld/esp32/README.md
extra_scripts = FluidNC/ld/esp32/vtable_in_dram.py
Expand Down

0 comments on commit 57ed5e0

Please sign in to comment.