5 Package to the interface between the Bike-X and the
11 from msp430
import MSP
12 import device
as sensor
13 from signal
import signal, SIGINT, SIGALRM, SIGABRT, SIGQUIT
14 from startx
import SIG1,SIG2,SIG3,ACTIVE_FILE, PASSIVE_FILE
15 from time
import sleep
16 from os
import getpid,kill
17 from mock
import MagicMock
25 """ Care for a safe quit """
31 """ was requisited new data from sensor"""
32 f = open(PASSIVE_FILE,
'w')
33 print "requisited new data from sensor"
35 f.write(msp430[
'passives'])
42 print 'Father not available'
45 """ read file and send to mcu """
46 f = open(ACTIVE_FILE,
'a+r')
53 pid_bikex = sys.argv[1:2]
54 print "Father: %s" % pid_bikex
55 print "Mine: %d " % getpid()
57 msp430.curb = sensor.Break(msp430.serial,0)
58 msp430.passives = sensor.Passives(msp430.serial,0)
60 signal(SIG1, write_file)
61 signal(SIG3, read_file)
62 signal(SIGINT, safe_quit)
63 signal(SIGQUIT, safe_quit)
64 signal(SIGABRT, safe_quit)
68 if __name__ ==
'__main__':
70 PORTS_AVAILABLE = util.available_ports()
72 print 'Available ports:'
73 for i
in PORTS_AVAILABLE:
77 if len(PORTS_AVAILABLE) > 0:
78 msp430 = MSP(PORTS_AVAILABLE[0])
79 except TypeError, error:
80 print "None device connected - test mode"
82 msp430.__getitem__ = MagicMock(return_value=
'Test Message\n')