diff --git a/App.py b/App.py new file mode 100644 index 00000000..55b83b01 --- /dev/null +++ b/App.py @@ -0,0 +1,26 @@ +import importlib +from HttpServer import HttpServer +from AppConfig import config + +def load_control(control): + module_name = 'rip.%s' % control['impl_module'] + module = importlib.import_module(module_name) + control_name = control.get('impl_name', control['impl_module']) + RIPControl = getattr(module, control_name) + + info = config['control']['info'] + return RIPControl( + info['name'], + info['description'], + info['authors'], + info['keywords'], + ) + +if __name__ == "__main__": + control = load_control(config['control']) + + HttpServer( + host=config['server']['host'], + port=config['server']['port'], + control=control + ).start(enable_ssl=False) diff --git a/AppConfig.py b/AppConfig.py new file mode 100644 index 00000000..ab3e915a --- /dev/null +++ b/AppConfig.py @@ -0,0 +1,23 @@ +# This file contains the configuration of the RIP server applicationself. +config = { + # TO DO: The server will listen to host:port + 'server': { + 'host': '127.0.0.1', + 'port': 8080, + }, + # The 'control' section configures the mapping between the RIP protocol + # and the actual implementation of the functionality. + # The 'impl' field should contain the name of the module (.py) and the + # class that implement the control interface + 'control': { + 'impl_module': 'RIPOctave', + # Also, if the class name is not the same as the module name: + #'impl_name': 'RIPOctave', + 'info': { + 'name': 'Octave', + 'description': 'An implementation of RIP to control Octave', + 'authors': 'D. Garcia, J. Chacon', + 'keywords': 'Octave, Raspberry PI, Robot', + } + } +} diff --git a/config-examples/AppConfig-Octave.py b/config-examples/AppConfig-Octave.py new file mode 100644 index 00000000..ab3e915a --- /dev/null +++ b/config-examples/AppConfig-Octave.py @@ -0,0 +1,23 @@ +# This file contains the configuration of the RIP server applicationself. +config = { + # TO DO: The server will listen to host:port + 'server': { + 'host': '127.0.0.1', + 'port': 8080, + }, + # The 'control' section configures the mapping between the RIP protocol + # and the actual implementation of the functionality. + # The 'impl' field should contain the name of the module (.py) and the + # class that implement the control interface + 'control': { + 'impl_module': 'RIPOctave', + # Also, if the class name is not the same as the module name: + #'impl_name': 'RIPOctave', + 'info': { + 'name': 'Octave', + 'description': 'An implementation of RIP to control Octave', + 'authors': 'D. Garcia, J. Chacon', + 'keywords': 'Octave, Raspberry PI, Robot', + } + } +} diff --git a/config-examples/AppConfig-RedPitaya.py b/config-examples/AppConfig-RedPitaya.py new file mode 100644 index 00000000..05e2ed81 --- /dev/null +++ b/config-examples/AppConfig-RedPitaya.py @@ -0,0 +1,21 @@ +# This file contains the configuration of the RIP server applicationself. +config = { + # TO DO: The server will listen to host:port + 'server': { + 'host': '127.0.0.1', + 'port': 8080, + }, + # The 'control' section configures the mapping between the RIP protocol + # and the actual implementation of the functionality. + # The 'impl' field should contain the name of the module (.py) and the + # class that implement the control interface + 'control': { + 'impl_module': 'RIPRedPitaya', + 'info': { + 'name': 'Octave', + 'description': 'An implementation of RIP to control Red Pitaya', + 'authors': 'Amine my-taj', + 'keywords': 'Red Pitaya, Raspberry PI', + } + } +} diff --git a/rip/RIPRedPitaya.py b/rip/RIPRedPitaya.py new file mode 100644 index 00000000..d83ded76 --- /dev/null +++ b/rip/RIPRedPitaya.py @@ -0,0 +1,53 @@ +''' +@author: Amine +''' +from rip.RIPGeneric import RIPGeneric + +class RIPRedPitaya(RIPGeneric): + ''' + RIP Implementation for Red Pitaya + ''' + + def __init__(self, name='RedPitaya', description='An implementation of RIP to control Red Pitaya', authors='Amine', keywords='Red Pitaya'): + ''' + Constructor + ''' + super().__init__(name, description, authors, keywords) + + self.readables.append({ + 'name':'x', + 'description':'Testing readable variable', + 'type':'float', + 'min':'-Inf', + 'max':'Inf', + 'precision':'0' + }) + self.writables.append({ + 'name':'x', + 'description':'Testing writable variable', + 'type':'float', + 'min':'-Inf', + 'max':'Inf', + 'precision':'0' + }) + + def set(self, expid, variables, values): + ''' + Writes one or more variables to the workspace of the current session + ''' + # TO DO: do something with variables and values + pass + + def get(self, expid, variables): + ''' + Retrieve one or more variables from the workspace of the current session + ''' + # TO DO: do something with variables and values + toReturn = {} + return toReturn + + def getValuesToNotify(self): + return [ + ['time', 'x'], + [self.sampler.lastTime(), 1] + ]