Skip to content

Commit

Permalink
Undo UART looping changes for now (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley authored Oct 31, 2024
1 parent 2b63638 commit 3c58324
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 261 deletions.
61 changes: 0 additions & 61 deletions FluidNC/src/FixedCircularBuffer.h

This file was deleted.

8 changes: 3 additions & 5 deletions FluidNC/src/Flowcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,8 @@ Error flowcontrol(uint32_t o_label, char* line, size_t& pos, bool& skip) {
case Op_Repeat:
if (Job::active()) {
if (!skipping && (status = expression(line, pos, value)) == Error::Ok) {
// TODO - return an error if value < 0
// For now, just guard against negative values
stack_push(o_label, operation, !(value > 0.0));
if (value > 0.0) {
stack_push(o_label, operation, !value);
if (value) {
context.top().file = Job::source();
context.top().file_pos = context.top().file->position();
context.top().repeats = (uint32_t)value;
Expand All @@ -251,7 +249,7 @@ Error flowcontrol(uint32_t o_label, char* line, size_t& pos, bool& skip) {
if (Job::active()) {
if (last_op == Op_Repeat) {
if (o_label == context.top().o_label) {
if (context.top().repeats && --context.top().repeats > 0.0) {
if (context.top().repeats && --context.top().repeats) {
context.top().file->set_position(context.top().file_pos);
} else {
stack_pull();
Expand Down
32 changes: 9 additions & 23 deletions FluidNC/src/Job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,17 @@
#include "Job.h"
#include <map>
#include <stack>
#include "Protocol.h"

std::stack<JobSource*> job;

Channel* Job::leader = nullptr;

bool Job::active() {
return !job.empty() || activeChannel;
return !job.empty();
}

JobSource activeChannelJobSource(nullptr);

JobSource* Job::source() {
if (job.empty()) {
if (activeChannel) {
activeChannelJobSource.set_channel(activeChannel);
return &activeChannelJobSource;
} else {
return nullptr;
}
} else {
return job.top();
}
return job.empty() ? nullptr : job.top();
}

// save() and restore() are use to close/reopen an SD file atop the job stack
Expand All @@ -50,11 +38,9 @@ void Job::nest(Channel* in_channel, Channel* out_channel) {
job.push(source);
}
void Job::pop() {
if (!job.empty()) {
auto source = job.top();
job.pop();
delete source;
}
auto source = job.top();
job.pop();
delete source;
if (!active()) {
leader = nullptr;
}
Expand All @@ -74,14 +60,14 @@ void Job::abort() {
}

bool Job::get_param(const std::string& name, float& value) {
return source()->get_param(name, value);
return job.top()->get_param(name, value);
}
bool Job::set_param(const std::string& name, float value) {
return source()->set_param(name, value);
return job.top()->set_param(name, value);
}
bool Job::param_exists(const std::string& name) {
return source()->param_exists(name);
return job.top()->param_exists(name);
}
Channel* Job::channel() {
return source()->channel();
return job.top()->channel();
}
1 change: 0 additions & 1 deletion FluidNC/src/Job.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class JobSource {
void set_position(size_t pos) { _channel->set_position(pos); }

Channel* channel() { return _channel; }
void set_channel(Channel* channel) { _channel = channel; }

~JobSource() { delete _channel; }
};
Expand Down
2 changes: 0 additions & 2 deletions FluidNC/src/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ extern volatile bool rtCycleStop;

extern volatile bool runLimitLoop;

extern Channel* activeChannel;

// Alarm codes.
enum class ExecAlarm : uint8_t {
None = 0,
Expand Down
21 changes: 3 additions & 18 deletions FluidNC/src/UartChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
#include "Serial.h" // allChannels

UartChannel::UartChannel(int num, bool addCR) : Channel("uart_channel", num, addCR) {
_lineedit = new Lineedit(this, _line, Channel::maxLine - 1);
_active = false;
_history_buffer = FixedCircularBuffer<char>(512);
_history_buffer_pos = 0;
_lineedit = new Lineedit(this, _line, Channel::maxLine - 1);
_active = false;
}

void UartChannel::init() {
Expand Down Expand Up @@ -65,13 +63,10 @@ size_t UartChannel::write(const uint8_t* buffer, size_t length) {
}

int UartChannel::available() {
return (_history_buffer_pos < _history_buffer.position()) || _uart->available();
return _uart->available();
}

int UartChannel::peek() {
if (_history_buffer_pos < _history_buffer.position()) {
return _history_buffer.at(_history_buffer_pos).value();
}
return _uart->peek();
}

Expand All @@ -95,22 +90,12 @@ bool UartChannel::lineComplete(char* line, char c) {
}

int UartChannel::read() {
if (_history_buffer_pos < _history_buffer.position()) {
int c = _history_buffer.at(_history_buffer_pos).value();
_history_buffer_pos += 1;
return c;
}

int c = _uart->read();
if (c == 0x11) {
// 0x11 is XON. If we receive that, it is a request to use software flow control
_uart->setSwFlowControl(true, -1, -1);
return -1;
}
if (c != -1) {
_history_buffer.push((char)c);
_history_buffer_pos += 1;
}
return c;
}

Expand Down
10 changes: 2 additions & 8 deletions FluidNC/src/UartChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
#include "Uart.h"
#include "Channel.h"
#include "lineedit.h"
#include "FixedCircularBuffer.h"

class UartChannel : public Channel, public Configuration::Configurable {
private:
Lineedit* _lineedit;
Uart* _uart;
FixedCircularBuffer<char> _history_buffer;
std::size_t _history_buffer_pos;
Lineedit* _lineedit;
Uart* _uart;

int _uart_num = 0;
int _report_interval_ms = 0;
Expand Down Expand Up @@ -52,9 +49,6 @@ class UartChannel : public Channel, public Configuration::Configurable {
handler.item("uart_num", _uart_num);
handler.item("message_level", _message_level, messageLevels2);
}

size_t position() override { return _history_buffer_pos; }
void set_position(size_t pos) override { _history_buffer_pos = pos; }
};

extern UartChannel Uart0;
Expand Down
42 changes: 0 additions & 42 deletions FluidNC/tests/FixedCircularBufferTest.cpp

This file was deleted.

45 changes: 0 additions & 45 deletions fixture_tests/fixtures/flow_control_repeat.nc

This file was deleted.

9 changes: 1 addition & 8 deletions fixture_tests/run_fixture
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ else:
def run_fixture(fixture_path, controller):
op_entries_parsed = op_entries.parse_file(fixture_path)

print(
colored(f"--- Run fixture ", "blue")
+ colored(fixture_path, "blue", attrs=["bold"])
+ colored(" ---", "blue")
)

try:
for op_entry in op_entries_parsed:
if not op_entry.execute(controller):
Expand All @@ -45,8 +39,7 @@ def run_fixture(fixture_path, controller):
exit(1)

except KeyboardInterrupt:
print("Interrupted by user")
exit(1)
print("Interrupt")

except TimeoutError as e:
print("Timeout waiting for response, line: " + e.args[0])
Expand Down
Loading

0 comments on commit 3c58324

Please sign in to comment.