##// END OF EJS Templates
SIR with docker-compose working
SIR with docker-compose working

File last commit:

r299:d18e81484ac8
r299:d18e81484ac8
Show More
api.py
104 lines | 2.5 KiB | text/x-python | PythonLexer
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@72 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r51 '''
Juan C. Espinoza
Update RC model, RC api for testing...
r185 API to configure new Radar controller
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@72 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r51
Juan C. Espinoza
Update RC model, RC api for testing...
r185 @author: Juan C. Espinoza
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@72 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r51 '''
Juan C. Espinoza
Update RC model, RC api for testing...
r185 import os
import json
import requests
from struct import pack
from base64 import b64encode
class RCApi(object):
def __init__(self, ip, port=80):
self.url = 'http://{}:{}/'.format(ip, port)
self.params = None
def load(self, filename):
self.params = json.load(open(filename))
SIR with docker-compose working
r299 self.pk = self.params['configurations']['allIds'][0]
print 'RC Configuration: {}'.format(self.params['configurations']['byId'][self.pk]['name'])
Juan C. Espinoza
Update RC model, RC api for testing...
r185
def status(self):
url = os.path.join(self.url, 'status')
req = requests.get(url)
return req.json()
def read(self):
url = os.path.join(self.url, 'read')
req = requests.get(url)
return req.json()
def stop(self):
url = os.path.join(self.url, 'stop')
req = requests.post(url)
return req.json()
def reset(self):
url = os.path.join(self.url, 'reset')
req = requests.post(url)
return req.json()
def start(self):
url = os.path.join(self.url, 'start')
req = requests.post(url)
return req.json()
def write(self):
url_write = os.path.join(self.url, 'write')
SIR with docker-compose working
r299 url_divider = os.path.join(self.url, 'divider')
values = zip(self.params['configurations']['byId'][self.pk]['pulses'],
[x-1 for x in self.params['configurations']['byId'][self.pk]['delays']])
Juan C. Espinoza
Update RC model, RC api for testing...
r185 payload = ''
for tup in values:
vals = pack('<HH', *tup)
SIR with docker-compose working
r299 payload += '\x85'+vals[0]+'\x84'+vals[1]+'\x85'+vals[2]+'\x84'+vals[3]
Juan C. Espinoza
Update RC model, RC api for testing...
r185
req = requests.post(url_divider,
SIR with docker-compose working
r299 data={'divider':int(self.params['configurations']['byId'][self.pk]['clock_divider'])-1})
Juan C. Espinoza
Update RC model, RC api for testing...
r185 if 'ok' not in req.text:
print 'Error sending divider'
return False
SIR with docker-compose working
r299
Juan C. Espinoza
Update RC model, RC api for testing...
r185 req = requests.post(url_write,
data=b64encode(payload))
return req.json()
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC model, RC api for testing...
r185 if __name__ == '__main__':
SIR with docker-compose working
r299 import time
Juan C. Espinoza
Update RC model, RC api for testing...
r185 ip = '10.10.10.100'
SIR with docker-compose working
r299
filename = './dia.json'
Juan C. Espinoza
Update RC model, RC api for testing...
r185 rc = RCApi(ip)
rc.load(filename)
SIR with docker-compose working
r299 # print rc.status()
# time.sleep(1)
# print rc.reset()
# time.sleep(1)
# print rc.stop()
# time.sleep(1)
Juan C. Espinoza
Update RC model, RC api for testing...
r185 print rc.write()
SIR with docker-compose working
r299 # time.sleep(1)
# print rc.start()
Juan C. Espinoza
Update RC model, RC api for testing...
r185
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Joaquin Verastegui
Metodo nuevo de envio de pulsos y tiempos....
r61
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172