Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
blesscat committed Sep 20, 2017
2 parents b5cd845 + 0d8f8f3 commit c7c4f39
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 21 deletions.
2 changes: 1 addition & 1 deletion fluxclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def check_platform():
p = "OSX"
return (p, platform.architecture()[0])

__version__ = "1.3.4"
__version__ = "1.3.5"
SUPPORT_PCL = check_pcl()
6 changes: 6 additions & 0 deletions fluxclient/commands/toolpath.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from argparse import ArgumentParser
from datetime import datetime
from PIL import Image
import getpass
import sys
import os
Expand All @@ -12,6 +13,11 @@
logger = None


def process_to_gray_bitmap(filename):
pil_image = Image.open(filename).convert('L')
return pil_image.size[0], pil_image.size[1], pil_image.tobytes()


def prepare_bitmap_factory(options):
from fluxclient.toolpath.bitmap_factory import BitmapImage, BitmapFactory

Expand Down
12 changes: 6 additions & 6 deletions fluxclient/device/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ def add_master_key(self, uuid, serial, master_key, disc_ver):
if uuid in self.devices:
device = self.devices[uuid]
if device.master_key != master_key:
raise Exception("Device %s got vart master keys",
raise Exception("Device %s got vart master keys" % device,
device.master_key, master_key)
if device.serial != serial:
raise Exception("Device %s got vart master keys",
raise Exception("Device %s got vart master keys" % device,
device.serial, serial)
return device
else:
Expand Down Expand Up @@ -398,7 +398,7 @@ def handle_message(self, endpoint, action_id, payload):

def _handle_discover(self, endpoint, payload):
args = struct.unpack("<16s8s", payload[:24])
uuid_bytes, session = args[:3]
uuid_bytes, session = args[:2]

uuid = UUID(bytes=uuid_bytes)
if not self.server.source_filter(uuid, endpoint):
Expand Down Expand Up @@ -454,8 +454,8 @@ def _handle_touch(self, endpoint, payload):
rawdata[k] = v

sn = rawdata.get("serial", None)
if sn and validate_identify(uuid, pubkey_signuture, serial=sn,
masterkey_doc=pubkey_der):
if sn and uuid in self.session_swap and \
validate_identify(uuid, pubkey_signuture, serial=sn, masterkey_doc=pubkey_der):
device = self.server.add_master_key(uuid, sn, dev_pubkey, 2)
device.model_id = rawdata.get("model", "UNKNOW_MODEL")
device.has_password = rawdata.get("pwd") == "T"
Expand All @@ -464,7 +464,7 @@ def _handle_touch(self, endpoint, payload):
device.discover_endpoint = endpoint
device.ipaddr = endpoint[0]

self.session_cache[uuid] = self.session_swap.pop(uuid, None)
self.session_cache[uuid] = self.session_swap.pop(uuid)
return uuid
else:
logger.error("Validate identify failed (uuid=%s, serial=%s)",
Expand Down
16 changes: 16 additions & 0 deletions fluxclient/robot/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def unload_filament_in_play(self, index):
def press_button_in_play(self):
return self._backend.press_button_in_play()

@blocked_validator
def restart_play(self):
return self._backend.restart_play()

@blocked_validator
def quit_play(self):
"""Quits from current task status."""
Expand Down Expand Up @@ -438,6 +442,7 @@ def calibrate(self, threshold=None, clean=False, process_callback=None):
return self._backend.maintain_calibration(self, threshold, clean,
process_callback)

@invalied_validator
def calibration(self, threshold=None, clean=False, process_callback=None):
warnings.warn("Use 'calibrate' method instead", DeprecationWarning)
return self.calibrate(threshold=threshold, clean=clean,
Expand Down Expand Up @@ -476,13 +481,24 @@ def diagnosis_sensor(self):
def diagnosis(self, option):
return self._backend.maintain_diagnosis(option)

@invalied_validator
def move(self, *ignore, **commands):
return self._backend.maintain_move(**commands)

@invalied_validator
def load_filament(self, index=0, temperature=210.0,
process_callback=None):
"""Loads the filament"""
return self._backend.maintain_load_filament(self, index, temperature,
process_callback)

@invalied_validator
def load_flexible_filament(self, index=0, temperature=210.0,
process_callback=None):
"""Loads the filament"""
return self._backend.maintain_load_flexible_filament(
self, index, temperature, process_callback)

@invalied_validator
def unload_filament(self, index=0, temperature=210.0,
process_callback=None):
Expand Down
25 changes: 22 additions & 3 deletions fluxclient/robot/robot_backend_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,16 @@ def maintain_diagnosis(self, option):
else:
raise_error(ret)

def maintain_load_filament(self, instance, index, temp, process_callback):
ret = self.make_cmd(
("load_filament %i %.1f" % (index, temp)).encode())
def maintain_move(self, *ignore, **commands):
params = tuple(' %s:%f' % (k, v) for k, v in commands.items() if k in 'fxyze')
if not params:
raise TypeError('maintain_move need at least 1 keyword argumens of f, x, y, z, e')
ret = self.make_cmd(('move' + ''.join(params)).encode())
if ret != "ok":
raise_error(ret)

def __load_filament(self, instance, cmd, process_callback):
ret = self.make_cmd(cmd)

if ret == "continue":
while True:
Expand All @@ -174,6 +181,14 @@ def maintain_load_filament(self, instance, index, temp, process_callback):
else:
raise_error(ret)

def maintain_load_filament(self, instance, index, temp, process_callback):
cmd = ("load_filament %i %.1f" % (index, temp)).encode()
self.__load_filament(instance, cmd, process_callback)

def maintain_load_flexible_filament(self, instance, index, temp, process_callback):
cmd = ("load_flexible_filament %i %.1f" % (index, temp)).encode()
self.__load_filament(instance, cmd, process_callback)

def maintain_unload_filament(self, instance, index, temp,
process_callback):
ret = self.make_cmd(
Expand Down Expand Up @@ -594,6 +609,10 @@ def play_info(self):
else:
raise_error(resp)

@ok_or_error
def restart_play(self):
return self.make_cmd(b"player restart")

@ok_or_error
def quit_play(self):
return self.make_cmd(b"player quit")
Expand Down
2 changes: 1 addition & 1 deletion fluxclient/robot/ssl_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _do_flux_handshake(self):
# TODO: check cert

binuuid = from_hex(cert["uuid"])
tosign = HMAC(binuuid, self.__bufferv.tobytes(), sha1).digest()
tosign = HMAC(binuuid, self.__bufferv[:64].tobytes(), sha1).digest()
access_id = self.client_key.get_access_id(binary=True)

self.__buffered = 0
Expand Down
2 changes: 1 addition & 1 deletion setup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_version():

def get_install_requires():
return ['setuptools', 'pycrypto', 'pyserial', 'pillow', 'numpy', 'scipy',
'ecdsa', 'lxml', 'pyasn1']
'ecdsa', 'lxml', 'pyasn1==0.1.9']


def get_packages():
Expand Down
6 changes: 6 additions & 0 deletions src/toolpath/_toolpath.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ cdef class FCodeV1MemoryWriter(ToolpathProcessor):
def get_metadata(self):
return dict(self.metadata)

def get_travled(self):
return (<_FCodeV1MemoryWriter*>self._proc).travled

def get_time_cost(self):
return (<_FCodeV1MemoryWriter*>self._proc).time_cost

def errors(self):
return (<_FCodeV1MemoryWriter*>self._proc).errors

Expand Down
2 changes: 2 additions & 0 deletions src/toolpath/_toolpathlib.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ cdef extern from "fcode.h" namespace "FLUX":
vector[pair[string, string]] *metadata
vector[string] *previews
vector[string] errors
double travled
double time_cost

cdef cppclass FCodeV1FileWriter:
FCodeV1FileWriter(const char*, string*, vector[pair[string, string]]*, vector[string]*) nogil
Expand Down
4 changes: 2 additions & 2 deletions src/toolpath/fcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace FLUX {
void begin(void);
public:
std::string *head_type;
float travled;
float time_cost;
double travled;
double time_cost;
float home_x, home_y, home_z;
float current_feedrate, current_x, current_y, current_z;
float max_x, max_y, max_z, max_r, filament[3];
Expand Down
10 changes: 5 additions & 5 deletions src/toolpath/fcode_v1_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ FLUX::FCodeV1::FCodeV1(std::string *type, std::vector<std::pair<std::string, std
home_x = 0; home_y = 0, home_z = 240;
current_feedrate = 0;
current_x = 0; current_y = 0; current_z = 0;
time_cost = 0;
travled = time_cost = 0;
max_x = max_y = max_z = max_r = filament[0] = filament[1] = filament[2] = 0;

head_type = type;
Expand Down Expand Up @@ -138,14 +138,14 @@ void FLUX::FCodeV1::moveto(int flags, float feedrate, float x, float y, float z,
if(flags & FLAG_HAS_E(2)) { fm[2] = filament[2] - e2; filament[2] = e2; }

if(has_move) {
float dist = sqrtf(pow(mv[0], 2) + pow(mv[1], 2) + pow(mv[2], 2));
double dist = sqrt(pow(mv[0], 2) + pow(mv[1], 2) + pow(mv[2], 2));
if(!isnan(dist)) {
travled += dist;
if(feedrate > 0) {
float tc = (dist / feedrate) * 60.0;
if(current_feedrate > 0) {
float tc = (dist / current_feedrate) * 60.0;
if(!isnan(tc)) time_cost += tc;
} else {
on_error(false, "UNDEF_FEEDRATE", 14);
on_error(false, "BAD_FEEDRATE", 14);
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/toolpath/gcode_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ int FLUX::GCodeParser::handle_g92(const char* linep, int offset, int size) {
case 'Z':
if(from_inch) { val = inch2mm(val); }
axis = param - 'X';
position_offset[axis] = val - position[axis];
position_offset[axis] = position[axis] - val;
break;
case 'E':
if(from_inch) { val = inch2mm(val); }
axis = T;
filaments_offset[axis] = val - filaments[axis];
filaments_offset[axis] = filaments[axis] - val;
break;
default:
has_param_error = true;
Expand Down

0 comments on commit c7c4f39

Please sign in to comment.