Skip to content

Commit

Permalink
Added generic App and configuration examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jcsombria committed Nov 21, 2018
1 parent 0b9f95b commit 7f4528a
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
26 changes: 26 additions & 0 deletions App.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions AppConfig.py
Original file line number Diff line number Diff line change
@@ -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',
}
}
}
23 changes: 23 additions & 0 deletions config-examples/AppConfig-Octave.py
Original file line number Diff line number Diff line change
@@ -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',
}
}
}
21 changes: 21 additions & 0 deletions config-examples/AppConfig-RedPitaya.py
Original file line number Diff line number Diff line change
@@ -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',
}
}
}
53 changes: 53 additions & 0 deletions rip/RIPRedPitaya.py
Original file line number Diff line number Diff line change
@@ -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]
]

0 comments on commit 7f4528a

Please sign in to comment.