Skip to content

Commit 7f4528a

Browse files
committed
Added generic App and configuration examples
1 parent 0b9f95b commit 7f4528a

5 files changed

Lines changed: 146 additions & 0 deletions

File tree

App.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import importlib
2+
from HttpServer import HttpServer
3+
from AppConfig import config
4+
5+
def load_control(control):
6+
module_name = 'rip.%s' % control['impl_module']
7+
module = importlib.import_module(module_name)
8+
control_name = control.get('impl_name', control['impl_module'])
9+
RIPControl = getattr(module, control_name)
10+
11+
info = config['control']['info']
12+
return RIPControl(
13+
info['name'],
14+
info['description'],
15+
info['authors'],
16+
info['keywords'],
17+
)
18+
19+
if __name__ == "__main__":
20+
control = load_control(config['control'])
21+
22+
HttpServer(
23+
host=config['server']['host'],
24+
port=config['server']['port'],
25+
control=control
26+
).start(enable_ssl=False)

AppConfig.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file contains the configuration of the RIP server applicationself.
2+
config = {
3+
# TO DO: The server will listen to host:port
4+
'server': {
5+
'host': '127.0.0.1',
6+
'port': 8080,
7+
},
8+
# The 'control' section configures the mapping between the RIP protocol
9+
# and the actual implementation of the functionality.
10+
# The 'impl' field should contain the name of the module (.py) and the
11+
# class that implement the control interface
12+
'control': {
13+
'impl_module': 'RIPOctave',
14+
# Also, if the class name is not the same as the module name:
15+
#'impl_name': 'RIPOctave',
16+
'info': {
17+
'name': 'Octave',
18+
'description': 'An implementation of RIP to control Octave',
19+
'authors': 'D. Garcia, J. Chacon',
20+
'keywords': 'Octave, Raspberry PI, Robot',
21+
}
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file contains the configuration of the RIP server applicationself.
2+
config = {
3+
# TO DO: The server will listen to host:port
4+
'server': {
5+
'host': '127.0.0.1',
6+
'port': 8080,
7+
},
8+
# The 'control' section configures the mapping between the RIP protocol
9+
# and the actual implementation of the functionality.
10+
# The 'impl' field should contain the name of the module (.py) and the
11+
# class that implement the control interface
12+
'control': {
13+
'impl_module': 'RIPOctave',
14+
# Also, if the class name is not the same as the module name:
15+
#'impl_name': 'RIPOctave',
16+
'info': {
17+
'name': 'Octave',
18+
'description': 'An implementation of RIP to control Octave',
19+
'authors': 'D. Garcia, J. Chacon',
20+
'keywords': 'Octave, Raspberry PI, Robot',
21+
}
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file contains the configuration of the RIP server applicationself.
2+
config = {
3+
# TO DO: The server will listen to host:port
4+
'server': {
5+
'host': '127.0.0.1',
6+
'port': 8080,
7+
},
8+
# The 'control' section configures the mapping between the RIP protocol
9+
# and the actual implementation of the functionality.
10+
# The 'impl' field should contain the name of the module (.py) and the
11+
# class that implement the control interface
12+
'control': {
13+
'impl_module': 'RIPRedPitaya',
14+
'info': {
15+
'name': 'Octave',
16+
'description': 'An implementation of RIP to control Red Pitaya',
17+
'authors': 'Amine my-taj',
18+
'keywords': 'Red Pitaya, Raspberry PI',
19+
}
20+
}
21+
}

rip/RIPRedPitaya.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'''
2+
@author: Amine
3+
'''
4+
from rip.RIPGeneric import RIPGeneric
5+
6+
class RIPRedPitaya(RIPGeneric):
7+
'''
8+
RIP Implementation for Red Pitaya
9+
'''
10+
11+
def __init__(self, name='RedPitaya', description='An implementation of RIP to control Red Pitaya', authors='Amine', keywords='Red Pitaya'):
12+
'''
13+
Constructor
14+
'''
15+
super().__init__(name, description, authors, keywords)
16+
17+
self.readables.append({
18+
'name':'x',
19+
'description':'Testing readable variable',
20+
'type':'float',
21+
'min':'-Inf',
22+
'max':'Inf',
23+
'precision':'0'
24+
})
25+
self.writables.append({
26+
'name':'x',
27+
'description':'Testing writable variable',
28+
'type':'float',
29+
'min':'-Inf',
30+
'max':'Inf',
31+
'precision':'0'
32+
})
33+
34+
def set(self, expid, variables, values):
35+
'''
36+
Writes one or more variables to the workspace of the current session
37+
'''
38+
# TO DO: do something with variables and values
39+
pass
40+
41+
def get(self, expid, variables):
42+
'''
43+
Retrieve one or more variables from the workspace of the current session
44+
'''
45+
# TO DO: do something with variables and values
46+
toReturn = {}
47+
return toReturn
48+
49+
def getValuesToNotify(self):
50+
return [
51+
['time', 'x'],
52+
[self.sampler.lastTime(), 1]
53+
]

0 commit comments

Comments
 (0)