Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
drasko committed Feb 4, 2015
2 parents c373edf + 763ed81 commit ede95be
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 82 deletions.
4 changes: 2 additions & 2 deletions config.weio
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=99
START=80
STOP=91

start() {
echo "Launching WeIO FQC"
cd /weio
python scripts/weioFQC.py&
python scripts/weioFQC.py
}

stop() {
Expand All @@ -19,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() {
Expand Down
8 changes: 4 additions & 4 deletions openWrt/files/usr/bin/pip
Original file line number Diff line number Diff line change
@@ -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')()
)
8 changes: 4 additions & 4 deletions openWrt/files/usr/bin/pip-2.7
Original file line number Diff line number Diff line change
@@ -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')()
)
196 changes: 132 additions & 64 deletions scripts/weioFQC.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,144 @@
#!/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
import subprocess
import os

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:
return False
if not ser:
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:
'''
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.Popen(["/weio/scripts/ledBlinkSanity.py", '0.1'])
else:
print "LPC found with a functionnal firmware"
2 changes: 1 addition & 1 deletion weioLib/weioParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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
Expand Down
9 changes: 4 additions & 5 deletions www/libs/weio/weioApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,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
Expand Down Expand Up @@ -362,11 +362,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) {
Expand Down

0 comments on commit ede95be

Please sign in to comment.