From 58a541017ed3ae0d7427d185314ae0ac2b01151f Mon Sep 17 00:00:00 2001 From: manuIO Date: Tue, 3 Feb 2015 11:42:32 +0100 Subject: [PATCH 1/9] update GPIO events name --- www/libs/weio/weioApi.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/www/libs/weio/weioApi.js b/www/libs/weio/weioApi.js index 8e5e3555..8198f1ec 100755 --- a/www/libs/weio/weioApi.js +++ b/www/libs/weio/weioApi.js @@ -53,7 +53,7 @@ var weioCallbacks = { /** * This is where callback names are stored behind pin numbers */ -var weioInterrupts = []; +var s = []; $(document).ready(function() { @@ -177,8 +177,8 @@ var PULL_DOWN = 4 var LOW = 0 var HIGH = 1 var CHANGE = 2 -var RISE = 3 -var FALL = 4 +var RISING = 3 +var FALLING = 4 /* * Unique UUID number of this session From 7c3c2545ec08a7c3189daa107853c1640829bda9 Mon Sep 17 00:00:00 2001 From: manuIO Date: Tue, 3 Feb 2015 12:21:09 +0100 Subject: [PATCH 2/9] fix typo --- www/libs/weio/weioApi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/libs/weio/weioApi.js b/www/libs/weio/weioApi.js index 8198f1ec..28e952c8 100755 --- a/www/libs/weio/weioApi.js +++ b/www/libs/weio/weioApi.js @@ -53,7 +53,7 @@ var weioCallbacks = { /** * This is where callback names are stored behind pin numbers */ -var s = []; +var weioInterrupts = []; $(document).ready(function() { From 86dafd2ab88880d37625b09e91f3b6a05df09a92 Mon Sep 17 00:00:00 2001 From: manuIO Date: Tue, 3 Feb 2015 12:57:56 +0100 Subject: [PATCH 3/9] fixing attachInterrupt JS --- weioLib/weioParser.py | 2 +- www/libs/weio/weioApi.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/weioLib/weioParser.py b/weioLib/weioParser.py index 377f8f12..efd5be58 100755 --- a/weioLib/weioParser.py +++ b/weioLib/weioParser.py @@ -147,7 +147,7 @@ def callProportion(data) : def callAttachInterrupt(data) : if (weioRunnerGlobals.WEIO_SERIAL_LINKED is True): - attachInterrupt(data[0], data[1]) + attachInterrupt(data[0], data[1], data[2], data[3]) else: print "attachInterrupt ON PC", data return None diff --git a/www/libs/weio/weioApi.js b/www/libs/weio/weioApi.js index 28e952c8..3a85b03d 100755 --- a/www/libs/weio/weioApi.js +++ b/www/libs/weio/weioApi.js @@ -350,11 +350,10 @@ function callInbox(data) { } }; -function attachInterrupt(pin, mode, callback) { +function attachInterrupt(pin, mode, callback, obj) { var fName = callback.name; weioInterrupts[pin] = fName; - weioCallbacks[fName] = callback; - genericMessage("attachInterrupt", [pin, mode], null); + genericMessage("attachInterrupt", [pin, mode,fName,obj], null); } function weioExecuteInterrupt(data) { From e936ee615aa18353af1f236d62450b6ac72b3288 Mon Sep 17 00:00:00 2001 From: Paul RATHGEB Date: Wed, 4 Feb 2015 11:40:23 +0100 Subject: [PATCH 4/9] Refactored the FQC script Instead of detecting the bootloader, which needs to parse all block devices and takes a lot of time, this version use SFP to detect if the firmware is compatible with WeIO. The execution time has been divided by 10, from 7.45s to 0.8s. Now, the script is more stable. No side effects have been noticed anymore. In addition, the START and STOP levels have been optimized in the init.d script. --- openWrt/files/etc/init.d/weio_fqc | 3 +- scripts/weioFQC.py | 185 ++++++++++++++++++++---------- 2 files changed, 126 insertions(+), 62 deletions(-) diff --git a/openWrt/files/etc/init.d/weio_fqc b/openWrt/files/etc/init.d/weio_fqc index 7826966a..9827e92f 100755 --- a/openWrt/files/etc/init.d/weio_fqc +++ b/openWrt/files/etc/init.d/weio_fqc @@ -1,7 +1,8 @@ #!/bin/sh /etc/rc.common # Copyright (C) 2006 OpenWrt.org -START=99 +START=80 +STOP=91 start() { echo "Launching WeIO FQC" diff --git a/scripts/weioFQC.py b/scripts/weioFQC.py index 49c03475..07570f08 100755 --- a/scripts/weioFQC.py +++ b/scripts/weioFQC.py @@ -1,76 +1,139 @@ -#!/usr/bin/python -u -import sys, os, glob, logging, platform, json, signal, datetime -sys.path.append(os.getcwd()) -import time +#!/usr/bin/env python +# encoding: utf-8 -# This class detect if the LPC is shown on the USB bus -class Detector: - def __init__(self, reset_pin=17, program_pin=22): - reset_pin_str = str(reset_pin) - program_pin_str = str(program_pin) - self._gpio(reset_pin_str, "/sys/class/gpio/export") - self._gpio(program_pin_str, "/sys/class/gpio/export") - self._gpio("out","/sys/class/gpio/gpio"+reset_pin_str+"/direction") - self._gpio("out","/sys/class/gpio/gpio"+program_pin_str+"/direction") - self.uper_reset = "/sys/class/gpio/gpio"+reset_pin_str+"/value" - self.uper_program = "/sys/class/gpio/gpio"+program_pin_str+"/value" +import struct +import types +import glob - def _gpio(self, content, file_name): - try: - file_id = os.open(file_name, os.O_WRONLY) - os.write(file_id, content) - os.close(file_id) - except OSError: - pass +import serial - def _reset_uper(self): - self._gpio("1",self.uper_reset) - self._gpio("0",self.uper_reset) +class detectFW: + def __init__(self): + pass - def detect(self): - uper_flash_pattern = "CRP DISABLD" + def detector(self): + ser = None + ports_list = glob.glob("/dev/ttyACM*") + for my_port in ports_list: + try: + port_to_try = serial.Serial( + port=my_port, + baudrate=230400, #virtual com port on USB is always max speed + parity=serial.PARITY_ODD, + stopbits=serial.STOPBITS_ONE, + bytesize=serial.EIGHTBITS, + timeout=0.1 + ) + port_to_try.write(self.encode_sfp(255, [])) + uper_response = port_to_try.read(1) #read one, blocking + n = port_to_try.inWaiting() #look if there is more + if n: + uper_response = uper_response + port_to_try.read(n) + if self.decode_sfp(uper_response)[0] == -1: # found port with UPER + ser = port_to_try + break + port_to_try.close() + except: + print "Exception" + return False + if not ser: + print "Not found" + return False - # put UPER in to programming mode - self._gpio("1",self.uper_reset) - self._gpio("1",self.uper_program) - self._gpio("0",self.uper_reset) - time.sleep(2) # wait for linux to settle after UPER reboot in to pgm state - self._gpio("0",self.uper_program) + return True - # find UPER block device - list_block_devs = glob.glob("/sys/block/sd*") - block_device_name = '' - header = '' - for try_device_name in list_block_devs: - try_device_name = "/dev/" + try_device_name.split('/')[-1] - try: - block_device = os.open(try_device_name, os.O_RDWR) - os.lseek(block_device, 3 * 512, os.SEEK_SET) - header = os.read(block_device,11) - time.sleep(0.35) # reading can be slowww - os.close(block_device) - except OSError: - pass - if header == uper_flash_pattern: # "CRP DISABLD" - block_device_name = try_device_name # found UPER - break; - if block_device_name == '': - return 0 + def _encode_int(self, intarg): + if intarg < 64: + return chr(intarg) + packedint = struct.pack('>I', intarg).lstrip('\x00') + return chr(0xc0 | (len(packedint) - 1)) + packedint + + def _encode_bytes(self, bytestr): + if len(bytestr) < 64: + return chr(0x40 | len(bytestr)) + bytestr + packedlen = struct.pack('>I', len(bytestr)).lstrip('\x00') + if len(packedlen) == 1: + return '\xc4' + packedlen + bytestr + elif len(packedlen) == 2: + return '\xc5' + packedlen + bytestr + + def encode_sfp(self, command, args): + """ + Construct binary SFP command. + + :param command: SFP command ID. + :type command: int + :param args: A list of SFP arguments, which can be either an integer or a byte collection (string). + :type args: list + :return: Binary SFP command. + :rtype: str + """ + functions = { + types.StringType: self._encode_bytes, + bytearray: self._encode_bytes, + types.IntType: self._encode_int + } + sfp_command = chr(command) + ''.join(str(functions[type(arg)](arg)) for arg in args) + sfp_command = '\xd4' + struct.pack('>H', len(sfp_command)) + sfp_command + return sfp_command + + def decode_sfp(self, buffer): + """ + Decode SFP command from byte buffer. + + :param buffer: A byte buffer which stores SFP command. + :type buffer: str + :return: A list containing decoded SFP function ID and arguments (if any). + """ + result = [] + if buffer[0:1] != '\xd4': + return result + buflen = struct.unpack('>H', buffer[1:3])[0] + 3 + result.append(struct.unpack('b', buffer[3:4])[0]) + pointer = 4 + args = [] + while pointer < buflen: + argtype = ord(buffer[pointer:pointer + 1]) + pointer += 1 + if argtype < 64: # short int + args.append(argtype) + elif argtype < 128: # short str + arglen = argtype & 0x3f + args.append(buffer[pointer:pointer + arglen]) + pointer += arglen + else: + arglen = argtype & 0x0f + if arglen < 4: # decoding integers + if arglen == 0: + args.append(ord(buffer[pointer:pointer + 1])) + elif arglen == 1: + args.append(struct.unpack('>H', buffer[pointer:pointer + 2])[0]) + elif arglen == 2: + args.append(struct.unpack('>I', '\x00' + buffer[pointer:pointer + 3])[0]) + elif arglen == 3: + args.append(struct.unpack('>I', buffer[pointer:pointer + 4])[0]) + pointer += arglen + 1 + else: + if argtype == 0xc4: # decoding strings + arglen = ord(buffer[pointer:pointer + 1]) + elif argtype == 0xc5: + arglen = struct.unpack('>H', buffer[pointer:pointer + 2])[0] + pointer += 1 + pointer += 1 + args.append(buffer[pointer:pointer + arglen]) + pointer += arglen + result.append(args) + return result - # reset UPER - self._reset_uper() - time.sleep(.2) - return 1 - if __name__ == "__main__": ### Detect the LPC - detect = Detector() - res = detect.detect() - time.sleep(3) + fw = detectFW() + res = fw.detector() if not res: print "LPC not found !" import ledBlink as led while True: led.blink(.1) - + else: + print "LPC found with a functionnal firmware" From 15fe4d2a3f150bba081c955bf7fb07b8248520be Mon Sep 17 00:00:00 2001 From: Paul RATHGEB Date: Wed, 4 Feb 2015 11:45:21 +0100 Subject: [PATCH 5/9] Renamed weio_fqc to sanity_check --- openWrt/files/etc/init.d/{weio_fqc => sanity_check} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename openWrt/files/etc/init.d/{weio_fqc => sanity_check} (100%) diff --git a/openWrt/files/etc/init.d/weio_fqc b/openWrt/files/etc/init.d/sanity_check similarity index 100% rename from openWrt/files/etc/init.d/weio_fqc rename to openWrt/files/etc/init.d/sanity_check From 27b4f517e6c91614b91ba7a013787a6b87e05a4f Mon Sep 17 00:00:00 2001 From: Paul RATHGEB Date: Wed, 4 Feb 2015 14:10:17 +0100 Subject: [PATCH 6/9] Subprocess the ledBlink script when the test fails --- openWrt/files/etc/init.d/sanity_check | 6 ++++++ scripts/weioFQC.py | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/openWrt/files/etc/init.d/sanity_check b/openWrt/files/etc/init.d/sanity_check index 9827e92f..3997d5a3 100755 --- a/openWrt/files/etc/init.d/sanity_check +++ b/openWrt/files/etc/init.d/sanity_check @@ -20,6 +20,12 @@ stop() { PID=`ps | grep "[w]eioFQC.py" | awk '{print $1}'` kill -9 $PID fi + if [ -n "$(ps | grep "[l]edBlinkSanity")" ]; then + killall ledBlinkSanity.py + fi + if [ -h /weio/scripts/ledBlinkSanity.py ]; then + rm /weio/scripts/ledBlinkSanity.py + fi } restart() { diff --git a/scripts/weioFQC.py b/scripts/weioFQC.py index 07570f08..deb3b2ef 100755 --- a/scripts/weioFQC.py +++ b/scripts/weioFQC.py @@ -4,6 +4,8 @@ import struct import types import glob +import subprocess +import os import serial @@ -34,10 +36,8 @@ def detector(self): break port_to_try.close() except: - print "Exception" return False if not ser: - print "Not found" return False return True @@ -131,9 +131,14 @@ def decode_sfp(self, buffer): res = fw.detector() if not res: + ''' + weioRunner.py, just before ioloop.start(), send a command to stop the led_blink init script. + The command will 'killall ledBlink.py'. + To avoid weioRunner to kill this process, ledBlink.py is symlinked with a different name + ''' + if not os.path.islink("/weio/scripts/ledBlinkSanity.py"): + os.symlink("/weio/scripts/ledBlink.py", "/weio/scripts/ledBlinkSanity.py") print "LPC not found !" - import ledBlink as led - while True: - led.blink(.1) + subprocess.call(["/weio/scripts/ledBlinkSanity.py", '0.1']) else: print "LPC found with a functionnal firmware" From 17a566cd90ee05df1e9f55432711427c60f116a2 Mon Sep 17 00:00:00 2001 From: Paul RATHGEB Date: Wed, 4 Feb 2015 15:06:20 +0100 Subject: [PATCH 7/9] Use subprocess.Popen instead of subprocess.call. --- openWrt/files/etc/init.d/sanity_check | 2 +- scripts/weioFQC.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openWrt/files/etc/init.d/sanity_check b/openWrt/files/etc/init.d/sanity_check index 3997d5a3..01d0e7df 100755 --- a/openWrt/files/etc/init.d/sanity_check +++ b/openWrt/files/etc/init.d/sanity_check @@ -7,7 +7,7 @@ STOP=91 start() { echo "Launching WeIO FQC" cd /weio - python scripts/weioFQC.py& + python scripts/weioFQC.py } stop() { diff --git a/scripts/weioFQC.py b/scripts/weioFQC.py index deb3b2ef..70b1b15c 100755 --- a/scripts/weioFQC.py +++ b/scripts/weioFQC.py @@ -139,6 +139,6 @@ def decode_sfp(self, buffer): if not os.path.islink("/weio/scripts/ledBlinkSanity.py"): os.symlink("/weio/scripts/ledBlink.py", "/weio/scripts/ledBlinkSanity.py") print "LPC not found !" - subprocess.call(["/weio/scripts/ledBlinkSanity.py", '0.1']) + subprocess.Popen(["/weio/scripts/ledBlinkSanity.py", '0.1']) else: print "LPC found with a functionnal firmware" From ca07a15397f120b1374418439d93960afe98fef1 Mon Sep 17 00:00:00 2001 From: Drasko DRASKOVIC Date: Wed, 4 Feb 2015 19:46:11 +0100 Subject: [PATCH 8/9] Adding correct path for USB key --- config.weio | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.weio b/config.weio index e242dd57..d2d8277f 100755 --- a/config.weio +++ b/config.weio @@ -6,7 +6,7 @@ "editor_html_path": "www/dashboard.html", "extern_projects_path_flash": "/weioUser/flash", "extern_projects_path_sd": "/weioUser/sd", - "extern_projects_path_usbFlash": "", + "extern_projects_path_usbFlash": "/weioUser/usbFlash", "first_time_run": "YES", "https": "NO", "ip": "0.0.0.0", @@ -31,4 +31,4 @@ "weio_update_official_repository": "https://api.github.com/repos/nodesign/weio/releases", "weio_update_use_official_repository": "YES", "weio_version": "1.0" -} \ No newline at end of file +} From e76a579c63bebe5e374a258066be9bf780b7442f Mon Sep 17 00:00:00 2001 From: Nikola Date: Wed, 4 Feb 2015 20:51:46 +0100 Subject: [PATCH 9/9] -- New pip added to openWrt files. --- openWrt/files/usr/bin/pip | 8 ++++---- openWrt/files/usr/bin/pip-2.7 | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openWrt/files/usr/bin/pip b/openWrt/files/usr/bin/pip index 59ed8be4..6d794599 100755 --- a/openWrt/files/usr/bin/pip +++ b/openWrt/files/usr/bin/pip @@ -1,9 +1,9 @@ -#!/usr/bin/python -# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.4','console_scripts','pip' -__requires__ = 'pip==1.4' +#!/usr/bin/python2.7 +# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.4.1','console_scripts','pip' +__requires__ = 'pip==1.4.1' import sys from pkg_resources import load_entry_point sys.exit( - load_entry_point('pip==1.4', 'console_scripts', 'pip')() + load_entry_point('pip==1.4.1', 'console_scripts', 'pip')() ) diff --git a/openWrt/files/usr/bin/pip-2.7 b/openWrt/files/usr/bin/pip-2.7 index ff447253..a5533db3 100755 --- a/openWrt/files/usr/bin/pip-2.7 +++ b/openWrt/files/usr/bin/pip-2.7 @@ -1,9 +1,9 @@ -#!/usr/bin/python -# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.4','console_scripts','pip-2.7' -__requires__ = 'pip==1.4' +#!/usr/bin/python2.7 +# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.4.1','console_scripts','pip-2.7' +__requires__ = 'pip==1.4.1' import sys from pkg_resources import load_entry_point sys.exit( - load_entry_point('pip==1.4', 'console_scripts', 'pip-2.7')() + load_entry_point('pip==1.4.1', 'console_scripts', 'pip-2.7')() )