Handle planner ID and line
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 31 Dec 2017 21:48:18 +0000 (13:48 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 14 Jan 2018 23:40:55 +0000 (15:40 -0800)
src/avr/Makefile
src/avr/src/exec.c
src/avr/src/messages.def
src/avr/src/type.c
src/avr/src/type.def
src/avr/src/vars.c
src/avr/src/vars.def
src/avr/src/vars.h
src/py/bbctrl/AVR.py
src/py/bbctrl/Cmd.py
src/py/bbctrl/Planner.py

index 27ca41009845e1f5ee14c075811c37d6f3e9391f..3a234d8fc008a819c3b1ee6e10ded4e2e40e707e 100644 (file)
@@ -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/*)
index 59798e8e6d4ecf5cf1e75318558e8fe9f2ce4841..02e7da8b6644969afe6c0c72b8073ae37e8d7be6 100644 (file)
@@ -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;}
index 8e43a170e71ea9f197a5b157943cba34d86d9e25..2613ac01d3a893f8a7b8fb3a33a9afa377594c09 100644 (file)
@@ -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")
index 09724ae3921588960ec8b2b7d9db3583f46e2036..c1d80e5e973678b9e27b6f857a8705cac4703302 100644 (file)
@@ -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;
 
index ab5447ffaacc5863427b9564524ebbb53be7a925..3790b0887a95344aee739515668dabdf7f1598b4 100644 (file)
@@ -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)
index ae92830af2aaa914d070fadafcbe44881a0e9bdd..8ccc7766a92cf2457280d31c3c892edeeb132789 100644 (file)
@@ -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);
 }
 
 
index 59f9d1c4946efb76a27dfa045399b222e178f26b..2d1689142af25c1647ce4c510f60b27c6ce7ddcf 100644 (file)
@@ -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")
index abafea41e4682dbe9891def1c5c9896e207f7b21..517a32e194bcc1222893ffc906799f30878ff53a 100644 (file)
@@ -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();
index 08df97378f2cecc420e4d83a23b9ef737dce2d4f..2a9e3c7ea39e49b7ff3787065e0c53f103d7d694 100644 (file)
@@ -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')
 
 
index 9d05d1ee214274858c987b626271dce13049724e..f0067e2c89fc492903d6ed77f694a1b893219cee 100644 (file)
@@ -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
index 545d408a9f2cb754fd5126a61d8cc866ad481564..2695a495e09fa611e95d9a6ca84f8fefa24abd2e 100644 (file)
@@ -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'])