From fe98a053642d66ac01e524d10dd8a0fbe8d40937 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Sun, 31 Dec 2017 13:48:18 -0800 Subject: [PATCH] Handle planner ID and line --- src/avr/Makefile | 9 ++++++++- src/avr/src/exec.c | 1 + src/avr/src/messages.def | 1 + src/avr/src/type.c | 7 +++++++ src/avr/src/type.def | 1 + src/avr/src/vars.c | 28 +++++++++++++++------------- src/avr/src/vars.def | 5 +++-- src/avr/src/vars.h | 4 ++-- src/py/bbctrl/AVR.py | 2 +- src/py/bbctrl/Cmd.py | 14 +++++++------- src/py/bbctrl/Planner.py | 4 ++-- 11 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/avr/Makefile b/src/avr/Makefile index 27ca410..3a234d8 100644 --- a/src/avr/Makefile +++ b/src/avr/Makefile @@ -84,6 +84,13 @@ size: $(TARGET) avr-size -$$X --mcu=$(MCU) $(TARGET) ;\ done +data-usage: $(TARGET) + avr-nm -S --size-sort -t decimal $(TARGET) | grep ' [BbDd] ' + + +prog-usage: $(TARGET) + avr-nm -S --size-sort -t decimal $(TARGET) | grep -v ' [BbDd] ' + # Program init: $(MAKE) erase @@ -133,7 +140,7 @@ clean: tidy $(PROJECT).map build .PHONY: tidy clean size all reset erase program fuses read_fuses prodsig -.PHONY: signature usersig +.PHONY: signature usersig data-usage prog-usage # Dependencies -include $(shell mkdir -p build/dep) $(wildcard build/dep/*) diff --git a/src/avr/src/exec.c b/src/avr/src/exec.c index 59798e8..02e7da8 100644 --- a/src/avr/src/exec.c +++ b/src/avr/src/exec.c @@ -132,6 +132,7 @@ float get_feed_override() {return ex.feed_override;} float get_speed_override() {return ex.spindle_override;} float get_axis_position(int axis) {return ex.position[axis];} +void set_line(int32_t line) {ex.line = line;} void set_tool(uint8_t tool) {ex.tool = tool;} void set_feed_override(float value) {ex.feed_override = value;} void set_speed_override(float value) {ex.spindle_override = value;} diff --git a/src/avr/src/messages.def b/src/avr/src/messages.def index 8e43a17..2613ac0 100644 --- a/src/avr/src/messages.def +++ b/src/avr/src/messages.def @@ -45,5 +45,6 @@ STAT_MSG(QUEUE_EMPTY, "Queue empty") STAT_MSG(BAD_FLOAT, "Failed to parse float") STAT_MSG(INVALID_VARIABLE, "Invalid variable") STAT_MSG(INVALID_VALUE, "Invalid value") +STAT_MSG(READ_ONLY, "Variable is read only") STAT_MSG(BUFFER_OVERFLOW, "Buffer overflow") STAT_MSG(BAD_SEG_TIME, "Bad s-curve segment time") diff --git a/src/avr/src/type.c b/src/avr/src/type.c index 09724ae..c1d80e5 100644 --- a/src/avr/src/type.c +++ b/src/avr/src/type.c @@ -153,6 +153,13 @@ void type_print_s32(s32 x) {printf_P(PSTR("%"PRIi32), x);} s32 type_parse_s32(const char *value) {return strtol(value, 0, 0);} +// u32 +bool type_eq_u32(u32 a, u32 b) {return a == b;} +float type_u32_to_float(u32 x) {return x;} +void type_print_u32(u32 x) {printf_P(PSTR("%"PRIu32), x);} +u32 type_parse_u32(const char *value) {return strtol(value, 0, 0);} + + type_u type_parse(type_t type, const char *s) { type_u value; diff --git a/src/avr/src/type.def b/src/avr/src/type.def index ab5447f..3790b08 100644 --- a/src/avr/src/type.def +++ b/src/avr/src/type.def @@ -38,4 +38,5 @@ TYPEDEF(u8, uint8_t) TYPEDEF(s8, int8_t) TYPEDEF(u16, uint16_t) TYPEDEF(s32, int32_t) +TYPEDEF(u32, uint32_t) TYPEDEF(bool, _Bool) diff --git a/src/avr/src/vars.c b/src/avr/src/vars.c index ae92830..8ccc776 100644 --- a/src/avr/src/vars.c +++ b/src/avr/src/vars.c @@ -65,6 +65,7 @@ enum { // Set callback union typedef union { + void *ptr; #define TYPEDEF(TYPE, ...) void (*set_##TYPE)(TYPE); #include "type.def" #undef TYPEDEF @@ -77,6 +78,7 @@ typedef union { // Get callback union typedef union { + void *ptr; #define TYPEDEF(TYPE, ...) TYPE (*get_##TYPE)(); #include "type.def" #undef TYPEDEF @@ -294,26 +296,27 @@ static void _set(type_t type, int8_t index, set_cb_u cb, type_u value) { } -bool vars_print(const char *name) { +stat_t vars_print(const char *name) { var_info_t info; - if (!_find_var(name, &info)) return false; + if (!_find_var(name, &info)) return STAT_UNRECOGNIZED_NAME; printf("{\"%s\":", info.name); type_print(info.type, _get(info.type, info.index, info.get)); putchar('}'); putchar('\n'); - return true; + return STAT_OK; } -bool vars_set(const char *name, const char *value) { +stat_t vars_set(const char *name, const char *value) { var_info_t info; - if (!_find_var(name, &info)) return false; + if (!_find_var(name, &info)) return STAT_UNRECOGNIZED_NAME; + if (!info.set.ptr) return STAT_READ_ONLY; _set(info.type, info.index, info.set, type_parse(info.type, value)); - return true; + return STAT_OK; } @@ -354,12 +357,10 @@ stat_t command_var(char *cmd) { char *value = strchr(cmd, '='); if (value) { *value++ = 0; - if (vars_set(cmd, value)) return STAT_OK; - - } else if (vars_print(cmd)) return STAT_OK; + return vars_set(cmd, value); + } - STATUS_ERROR(STAT_UNRECOGNIZED_NAME, "'%s'", cmd); - return STAT_UNRECOGNIZED_NAME; + return vars_print(cmd); } @@ -379,6 +380,7 @@ stat_t command_sync_var(char *cmd) { var_info_t info; if (!_find_var(cmd + 1, &info)) return STAT_UNRECOGNIZED_NAME; + if (!info.set.ptr) return STAT_READ_ONLY; var_cmd_t buffer; @@ -397,8 +399,8 @@ unsigned command_sync_var_size() {return sizeof(var_cmd_t);} void command_sync_var_exec(char *data) { - var_cmd_t *buffer = (var_cmd_t *)data; - _set(buffer->type, buffer->index, buffer->set, buffer->value); + var_cmd_t *cmd = (var_cmd_t *)data; + _set(cmd->type, cmd->index, cmd->set, cmd->value); } diff --git a/src/avr/src/vars.def b/src/avr/src/vars.def index 59f9d1c..2d16891 100644 --- a/src/avr/src/vars.def +++ b/src/avr/src/vars.def @@ -111,7 +111,8 @@ VAR(hy_debug, hb, bool, 0, 1, 1, "Huanyang debugging") VAR(hy_connected, he, bool, 0, 0, 1, "Huanyang connected") // Machine state -VAR(line, ln, s32, 0, 0, 1, "Last line executed") +VAR(id, id, u32, 0, 1, 1, "Last executed command ID") +VAR(line, ln, s32, 0, 1, 1, "Last line executed") VAR(speed, s, f32, 0, 1, 1, "Current spindle speed") VAR(tool, t, u8, 0, 1, 1, "Current tool") VAR(feed_override, fo, f32, 0, 1, 1, "Feed rate override") @@ -123,7 +124,7 @@ VAR(flood_coolant, fc, bool, 0, 1, 1, "Flood coolant enabled") VAR(velocity, v, f32, 0, 0, 1, "Current velocity") VAR(acceleration, a, f32, 0, 0, 1, "Current acceleration") VAR(jerk, j, f32, 0, 0, 1, "Current jerk") -VAR(hw_id, id, str, 0, 0, 1, "Hardware ID") +VAR(hw_id, hid, str, 0, 0, 1, "Hardware ID") VAR(echo, ec, bool, 0, 1, 1, "Enable or disable echo") VAR(estop, es, bool, 0, 1, 1, "Emergency stop") VAR(estop_reason, er, pstr, 0, 0, 1, "Emergency stop reason") diff --git a/src/avr/src/vars.h b/src/avr/src/vars.h index abafea4..517a32e 100644 --- a/src/avr/src/vars.h +++ b/src/avr/src/vars.h @@ -40,7 +40,7 @@ void vars_init(); void vars_report(bool full); void vars_report_all(bool enable); void vars_report_var(const char *code, bool enable); -bool vars_print(const char *name); -bool vars_set(const char *name, const char *value); +stat_t vars_print(const char *name); +stat_t vars_set(const char *name, const char *value); float vars_get_number(const char *name); void vars_print_help(); diff --git a/src/py/bbctrl/AVR.py b/src/py/bbctrl/AVR.py index 08df973..2a9e3c7 100644 --- a/src/py/bbctrl/AVR.py +++ b/src/py/bbctrl/AVR.py @@ -125,7 +125,7 @@ class AVR(): def load_next_command(self, cmd): - log.info('< ' + cmd) + log.info('< ' + json.dumps(cmd).strip('"')) self.command = bytes(cmd.strip() + '\n', 'utf-8') diff --git a/src/py/bbctrl/Cmd.py b/src/py/bbctrl/Cmd.py index 9d05d1e..f0067e2 100644 --- a/src/py/bbctrl/Cmd.py +++ b/src/py/bbctrl/Cmd.py @@ -34,19 +34,19 @@ def encode_axes(axes): def line_number(line): return '#ln=%d' % line -def line(target, exitVel, maxJerk, times): - data = 'l' +def line(id, target, exitVel, maxJerk, times): + cmd = '#id=%u\nl' % id - data += encode_float(exitVel) - data += encode_float(maxJerk) - data += encode_axes(target) + cmd += encode_float(exitVel) + cmd += encode_float(maxJerk) + cmd += encode_axes(target) # S-Curve time parameters for i in range(7): if times[i]: - data += str(i) + encode_float(times[i] / 60000) # to mins + cmd += str(i) + encode_float(times[i] / 60000) # to mins - return data + return cmd def tool(tool): return '#t=%d' % tool diff --git a/src/py/bbctrl/Planner.py b/src/py/bbctrl/Planner.py index 545d408..2695a49 100644 --- a/src/py/bbctrl/Planner.py +++ b/src/py/bbctrl/Planner.py @@ -57,12 +57,12 @@ class Planner(): def encode(self, block): type = block['type'] - line = block.get('line', None) if type == 'line': - return Cmd.line(block['target'], block['exit-vel'], + return Cmd.line(block['id'], block['target'], block['exit-vel'], block['max-jerk'], block['times']) + if type == 'ln': return Cmd.line_number(block['line']) if type == 'tool': return Cmd.tool(block['tool']) if type == 'speed': return Cmd.speed(block['speed']) if type == 'dwell': return Cmd.dwell(block['seconds']) -- 2.27.0