##// END OF EJS Templates
Task #715: API ABS...
Fiorella Quino -
r198:0ad1ab767ee3
parent child
Show More
@@ -18,11 +18,57 module_num = 'xx'
18 module_port = 5500
18 module_port = 5500
19 module_xx = ('192.168.1.xx',5500)
19 module_xx = ('192.168.1.xx',5500)
20
20
21 #This function decode sent characters
22 def fromChar2Binary(char):
23 #To get the real value (-33)
24 number = ord(char) - 33
25 bits = bin(number)[2:]
26 #To ensure we have a string with 6bits
27 if len(bits) < 6:
28 bits = bits.zfill(6)
29 return bits
30
21 @route('/')
31 @route('/')
22 @route('/hello')
32 @route('/hello')
23 def hello():
33 def hello():
24 return "Hello World!"
34 return "Hello World!"
25
35
36 """
37 #---- Send Bits Function ----
38 @route('/write', method='POST')
39 def writebits():
40
41 #This funcion configure ABS sending bits.
42
43 try:
44 #------------Get Values-----------
45 #----------------UP---------------
46 ub2 = request.forms.get('ub2')
47 ub1 = request.forms.get('ub1')
48 ub0 = request.forms.get('ub0')
49 #--------------DOWN---------------
50 db2 = request.forms.get('db2')
51 db1 = request.forms.get('db1')
52 db0 = request.forms.get('db0')
53
54 #-----------Send Values-----------
55 #----------------UP---------------
56 ub2 = abs_write(126,ub2)
57 ub1 = abs_write(124,ub1)
58 ub0 = abs_write(122,ub0)
59 #--------------DOWN---------------
60 db2 = abs_write(120,db2)
61 db1 = abs_write(118,db1)
62 db0 = abs_write(116,db0)
63
64 if (ub2+ub1+ub0+db2+db1+db0) == 6:
65 return {"status": 1, "message": "Bits were successfully adjusted"}
66 else:
67 return {"status": 0, "message": "Couldn't configure ABS"}
68
69 except:
70 return {"status": 0, "message": "Couldn't configure ABS"}
71 """
26
72
27 #---- Get Bits Function ----
73 #---- Get Bits Function ----
28 @route('/read', method='GET')
74 @route('/read', method='GET')
@@ -58,23 +104,31 def writebits():
58 """
104 """
59 This function sends configurations to the module tcp_
105 This function sends configurations to the module tcp_
60 """
106 """
107 header_rx = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
108 module_rx = 'ABS_'+module_num
61 try:
109 try:
62 header_rx = request.forms.get('header')
110 #header_rx = request.forms.get('header')
63 module_rx = request.forms.get('module')
111 #module_rx = request.forms.get('module')
64 beams_rx = request.forms.get('beams')
112 #beams_rx = request.forms.get('beams')
65 beams_rx = json.loads(beams_rx)
113 #beams_rx = json.loads(beams_rx)
114 beams_rx = json.loads(request.body.readline())
115 beams_rx = beams_rx['beams']
66 except:
116 except:
67 return {"status":0, "message": "Could not accept configuration"}
117 return {"status":0, "message": "Could not accept configuration"}
68 #print header_rx, module_rx, beams_rx
118 #print beams_rx
69 message_tx = header_rx+"\n"+module_rx+"\n"
119 message_tx = header_rx+"\n"+module_rx+"\n"
70 for i in range(1,len(beams_rx)+1):
120 for i in range(1,len(beams_rx)): #(1,len(beams_rx)+1)
71 message_tx = message_tx+beams_rx[str(i)]+"\n"
121 try:
122 message_tx = message_tx+fromChar2Binary(beams_rx[i])+"\n"
123 except:
124 return {"status":0, "message": "Error in parameters from Beams List"
72 message_tx = message_tx+"0"
125 message_tx = message_tx+"0"
73
126
127
74 # Create the datagram socket
128 # Create the datagram socket
75 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
129 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
76 print >>sys.stderr, 'sending "%s"' % message_tx
130 print >>sys.stderr, 'sending "%s"' % message_tx
77 sock.connect(module_63)
131 sock.connect(module)
78 sock.send(message_tx)
132 sock.send(message_tx)
79 sock.close()
133 sock.close()
80
134
General Comments 0
You need to be logged in to leave comments. Login now