def __encode(self, block): type, id = block['type'], block['id'] if type != 'set': log.info('Cmd:' + log_json(block)) if type == 'line': self._enqueue_line_time(block) return Cmd.line(block['target'], block['exit-vel'], block['max-accel'], block['max-jerk'], block['times'], block.get('speeds', [])) if type == 'set': name, value = block['name'], block['value'] if name == 'message': msg = dict(message=value) self.cmdq.enqueue(id, self.ctrl.msgs.broadcast, msg) if name in ['line', 'tool']: self._enqueue_set_cmd(id, name, value) if name == 'speed': return Cmd.speed(value) if len(name) and name[0] == '_': # Don't queue axis positions, can be triggered by new position if len(name) != 2 or name[1] not in 'xyzabc': self._enqueue_set_cmd(id, name[1:], value) if name == '_feed': # Must come after _enqueue_set_cmd() above return Cmd.set_sync('if', 1 / value if value else 0) if name[0:1] == '_' and name[1:2] in 'xyzabc': if name[2:] == '_home': return Cmd.set_axis(name[1], value) if name[2:] == '_homed': motor = self.ctrl.state.find_motor(name[1]) if motor is not None: return Cmd.set_sync('%dh' % motor, value) return if type == 'input': # TODO handle timeout self.planner.synchronize(0) # TODO Fix this return Cmd.input(block['port'], block['mode'], block['timeout']) if type == 'output': return Cmd.output(block['port'], int(float(block['value']))) if type == 'dwell': self._enqueue_dwell_time(block) return Cmd.dwell(block['seconds']) if type == 'pause': return Cmd.pause(block['pause-type']) if type == 'seek': return Cmd.seek(block['switch'], block['active'], block['error']) if type == 'end': return '' # Sends id raise Exception('Unknown planner command "%s"' % type)
def __encode(self, block): log.info('Cmd:' + json.dumps(block)) type, id = block['type'], block['id'] if type == 'line': return Cmd.line(block['target'], block['exit-vel'], block['max-accel'], block['max-jerk'], block['times']) if type == 'set': name, value = block['name'], block['value'] if name == 'message': self.cmdq.enqueue(id, True, self.ctrl.msgs.broadcast, {'message': value}) if name in ['line', 'tool']: self._enqueue_set_cmd(id, name, value) if name == 'speed': return Cmd.speed(value) if len(name) and name[0] == '_': self._enqueue_set_cmd(id, name[1:], value) if name[0:1] == '_' and name[1:2] in 'xyzabc': if name[2:] == '_home': return Cmd.set_axis(name[1], value) if name[2:] == '_homed': motor = self.ctrl.state.find_motor(name[1]) if motor is not None: return Cmd.set('%dh' % motor, value) return if type == 'input': # TODO handle timeout self.planner.synchronize(0) # TODO Fix this return Cmd.input(block['port'], block['mode'], block['timeout']) if type == 'output': return Cmd.output(block['port'], int(float(block['value']))) if type == 'dwell': return Cmd.dwell(block['seconds']) if type == 'pause': return Cmd.pause(block['pause-type']) if type == 'seek': return Cmd.seek(block['switch'], block['active'], block['error']) raise Exception('Unknown planner command "%s"' % type)