-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
156 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters