##// END OF EJS Templates
Task #715: API del ABS, abs-module scripts...
Fiorella Quino -
r170:3cd43b7dc4dd
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -0,0 +1,87
1 """
2 This script should run in the abs module embedded system
3 It creates a Web Application with API Restful Bottle to connect to SIR server.
4 It needs the following scripts: abs_gpio.py and bottle.py
5 """
6 from bottle import route, run, request
7 from bottle import error
8 from abs_gpio import abs_read
9
10 #Sockets
11 import socket
12 import sys
13
14 import json
15
16 module_ip = '192.168.1.xx'
17 module_num = 'xx'
18 module_port = 5500
19 module_xx = ('192.168.1.xx',5500)
20
21 @route('/')
22 @route('/hello')
23 def hello():
24 return "Hello World!"
25
26
27 #---- Get Bits Function ----
28 @route('/read', method='GET')
29 def readbits():
30
31 """
32 This function reads the real values from the embedded system pins
33 with gpio class
34 """
35
36 #This function reads sent bits.
37
38 #------Get Monitoring Values------
39 #----------------UP---------------
40 um2_value = abs_read(80) #(++)
41 um1_value = abs_read(82)
42 um0_value = abs_read(84) #(--)
43 #--------------DOWN---------------
44 dm2_value = abs_read(94) #(++)
45 dm1_value = abs_read(88)
46 dm0_value = abs_read(86) #(--)
47
48 allbits = [um2_value, um1_value, um0_value, dm2_value, dm1_value, dm0_value]
49 if "" not in allbits:
50 allbits = {"um2":int(um2_value), "um1": int(um1_value), "um0": int(um0_value), "dm2": int(dm2_value), "dm1": int(dm1_value), "dm0": int(dm0_value)}
51 #allbits = {"ub0":0, "ub1":0, "ub2":0, "db0":0, "db1":0, "db2":0}
52 return {"status": 1, "message": "Bits were successfully read", "allbits" : allbits}
53 else:
54 return {"status": 0, "message": "There's a problem reading bits", "allbits" : ""}
55
56 @route('/configure', method='POST')
57 def configurebits():
58 """
59 This function sends configurations to the module tcp_
60 """
61 try:
62 header_rx = request.forms.get('header')
63 module_rx = request.forms.get('module')
64 beams_rx = request.forms.get('beams')
65 beams_rx = json.loads(beams_rx)
66 except:
67 return {"status":0, "message": "Could not accept configuration"}
68 #print header_rx, module_rx, beams_rx
69 message_tx = header_rx+"\n"+module_rx+"\n"
70 for i in range(1,len(beams_rx)+1):
71 message_tx = message_tx+beams_rx[str(i)]+"\n"
72 message_tx = message_tx+"0"
73
74 # Create the datagram socket
75 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
76 print >>sys.stderr, 'sending "%s"' % message_tx
77 sock.connect(module_63)
78 sock.send(message_tx)
79 sock.close()
80
81 return {"status":1, "message": "Configuration has been successfully sent"}
82
83 @error(404)
84 def error404(error):
85 return "^^' Nothing here, try again."
86
87 run(host=module_ip, port=8080, debug=True)
@@ -0,0 +1,137
1 """
2 This script should run in the abs module embedded system.
3 It uses gpio class to write or read the pins values.
4 """
5
6 import sys
7 import time
8
9
10 try:
11 #------------------Write-OUT----------------
12 #----------------DOWN-------------------
13 #GPIO116-PIN37-PC20 (--)
14 pin = open("/sys/class/gpio/export","w")
15 pin.write(str(116))
16 pin.close()
17 #GPIO118-PIN39-PC22
18 pin = open("/sys/class/gpio/export","w")
19 pin.write(str(118))
20 pin.close()
21 #GPIO120-PIN41-PC24 (++)
22 pin = open("/sys/class/gpio/export","w")
23 pin.write(str(120))
24 pin.close()
25
26 #-----------------UP--------------------
27 #GPIO122-PIN43-PC26 (--)
28 pin = open("/sys/class/gpio/export","w")
29 pin.write(str(122))
30 pin.close()
31 #GPIO124-PIN45-PC28
32 pin = open("/sys/class/gpio/export","w")
33 pin.write(str(124))
34 pin.close()
35 #GPIO126-PIN47-PC30 (++)
36 pin = open("/sys/class/gpio/export","w")
37 pin.write(str(126))
38 pin.close()
39 #--------------DIRECTION----------------
40 #----------------DOWN-------------------
41 pin_direct = open("/sys/class/gpio/gpio116/direction","w")
42 pin_direct.write("out")
43 pin_direct.close()
44
45 pin_direct = open("/sys/class/gpio/gpio118/direction","w")
46 pin_direct.write("out")
47 pin_direct.close()
48
49 pin_direct = open("/sys/class/gpio/gpio120/direction","w")
50 pin_direct.write("out")
51 pin_direct.close()
52 #-----------------UP--------------------
53 pin_direct = open("/sys/class/gpio/gpio122/direction","w")
54 pin_direct.write("out")
55 pin_direct.close()
56
57 pin_direct = open("/sys/class/gpio/gpio124/direction","w")
58 pin_direct.write("out")
59 pin_direct.close()
60
61 pin_direct = open("/sys/class/gpio/gpio126/direction","w")
62 pin_direct.write("out")
63 pin_direct.close()
64 #------------------Read-IN------------------
65 #----------------DOWN-------------------
66 #GPIO86-PIN17-PB22 (--)
67 pin = open("/sys/class/gpio/export","w")
68 pin.write(str(86))
69 pin.close()
70 #GPIO88-PIN19-PB24
71 pin = open("/sys/class/gpio/export","w")
72 pin.write(str(88))
73 pin.close()
74 #GPIO94-PIN21-PB30 (++)
75 pin = open("/sys/class/gpio/export","w")
76 pin.write(str(94))
77 pin.close()
78 #-----------------UP--------------------
79 #GPIO84-PIN15-PB20 (--)
80 pin = open("/sys/class/gpio/export","w")
81 pin.write(str(84))
82 pin.close()
83 #GPIO82-PIN13-PB18
84 pin = open("/sys/class/gpio/export","w")
85 pin.write(str(82))
86 pin.close()
87 #GPIO80-PIN11-PB16 (++)
88 pin = open("/sys/class/gpio/export","w")
89 pin.write(str(80))
90 pin.close()
91 #--------------DIRECTION----------------
92 #----------------DOWN-------------------
93 pin_direct = open("/sys/class/gpio/gpio86/direction","w")
94 pin_direct.write("in")
95 pin_direct.close()
96
97 pin_direct = open("/sys/class/gpio/gpio88/direction","w")
98 pin_direct.write("in")
99 pin_direct.close()
100
101 pin_direct = open("/sys/class/gpio/gpio94/direction","w")
102 pin_direct.write("in")
103 pin_direct.close()
104 #-----------------UP--------------------
105 pin_direct = open("/sys/class/gpio/gpio84/direction","w")
106 pin_direct.write("in")
107 pin_direct.close()
108
109 pin_direct = open("/sys/class/gpio/gpio82/direction","w")
110 pin_direct.write("in")
111 pin_direct.close()
112
113 pin_direct = open("/sys/class/gpio/gpio80/direction","w")
114 pin_direct.write("in")
115 pin_direct.close()
116
117 except:
118 pass
119
120 def abs_write(address,value):
121 try:
122 pin_value = open("/sys/class/gpio/gpio"+str(address)+"/value","w")
123 pin_value.write(str(value))
124 pin_value.close()
125 return 1
126 except:
127 return 0
128 #return 1
129
130 def abs_read(address):
131 try:
132 pin_value = open("/sys/class/gpio/gpio"+str(address)+"/value","r")
133 valor = pin_value.read()
134 pin_value.close()
135 return valor
136 except:
137 return ""
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now