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
$(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/*)
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;}
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")
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;
TYPEDEF(s8, int8_t)
TYPEDEF(u16, uint16_t)
TYPEDEF(s32, int32_t)
+TYPEDEF(u32, uint32_t)
TYPEDEF(bool, _Bool)
// Set callback union
typedef union {
+ void *ptr;
#define TYPEDEF(TYPE, ...) void (*set_##TYPE)(TYPE);
#include "type.def"
#undef TYPEDEF
// Get callback union
typedef union {
+ void *ptr;
#define TYPEDEF(TYPE, ...) TYPE (*get_##TYPE)();
#include "type.def"
#undef TYPEDEF
}
-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;
}
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);
}
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;
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);
}
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")
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")
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();
def load_next_command(self, cmd):
- log.info('< ' + cmd)
+ log.info('< ' + json.dumps(cmd).strip('"'))
self.command = bytes(cmd.strip() + '\n', 'utf-8')
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
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'])