forked from jcsombria/py-ripserver
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added generic App and configuration examples
- Loading branch information
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
] |