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.
Definition of Readables/Writables in AppConfig.py
- Loading branch information
Showing
4,328 changed files
with
269 additions
and
1,052,988 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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
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
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,19 @@ | ||
# This file contains the configuration of the RIP server application. | ||
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': 'RIPAdapterTemplate', | ||
'info': { | ||
'name': 'RIPRandom', | ||
'description': 'A random numbers generator', | ||
}, | ||
} | ||
} |
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,34 @@ | ||
# This file contains the configuration of the RIP server application. | ||
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': 'RIPGeneric', | ||
# Also, if the class name is not the same as the module name: | ||
#'impl_name': 'RIPOctave', | ||
'info': { | ||
'name': 'RIP Generic', | ||
'description': 'A generic implementation of RIP', | ||
'authors': 'J. Chacon', | ||
'keywords': 'Raspberry PI, RIP', | ||
# Server readable objects | ||
'readables': [{ | ||
'name':'time', | ||
'description':'Server time in seconds', | ||
'type':'float', | ||
'min':'0', | ||
'max':'Inf', | ||
'precision':'0' | ||
}], | ||
# Server writable objects | ||
'writables': [] | ||
}, | ||
} | ||
} |
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
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
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,102 @@ | ||
''' | ||
@author: jcsombria | ||
''' | ||
import random | ||
from rip.RIPGeneric import RIPGeneric | ||
|
||
class RIPAdapterTemplate(RIPGeneric): | ||
''' | ||
RIP Adapter Template | ||
''' | ||
|
||
def __init__(self, info={}): | ||
''' | ||
Constructor | ||
''' | ||
super().__init__(info) | ||
|
||
def default_info(self): | ||
''' | ||
You can provide default metadata here. AppConfig will override this definition. | ||
''' | ||
return { | ||
'name':'RIPAdapterTemplate', | ||
'description':'A template to extend RIP Generic', | ||
'authors':'J. Chacon', | ||
'keywords':'Adapter Template', | ||
'readables':[{ | ||
'name':'time', | ||
'description':'Server time in seconds', | ||
'type':'float', | ||
'min':'0', | ||
'max':'Inf', | ||
'precision':'0', | ||
}, { | ||
'name':'random', | ||
'description':'Random value generator', | ||
'type':'float', | ||
'min':'0', | ||
'max':'1', | ||
'precision':'0' | ||
}], | ||
'writables': [{ | ||
'name':'seed', | ||
'description':'Random seed', | ||
'type':'float', | ||
'min':'0', | ||
'max':'1', | ||
'precision':'0' | ||
}], | ||
} | ||
|
||
def set(self, expid, variables, values): | ||
''' | ||
Write on or more variables | ||
''' | ||
n = len(variables) | ||
for i in range(n): | ||
try: | ||
n, v = variables[i], values[i] | ||
if v in writables: | ||
self.n = v | ||
except: | ||
pass | ||
|
||
def get(self, expid, variables): | ||
''' | ||
Retrieve one or more variables under request | ||
''' | ||
toReturn = {} | ||
n = len(variables) | ||
for i in range(n): | ||
name = variables[i] | ||
try: | ||
toReturn[name] = random.rand | ||
except: | ||
pass | ||
return toReturn | ||
|
||
def getValuesToNotify(self): | ||
''' | ||
Variables to include in periodic SSE updates | ||
''' | ||
return [ | ||
['time', 'random'], | ||
[self.sampler.lastTime(), self.random] | ||
] | ||
|
||
@property | ||
def seed(self): | ||
return self._seed | ||
|
||
@seed.setter | ||
def seed(self, value): | ||
random.seed(value) | ||
|
||
@property | ||
def random(self): | ||
return random.random() | ||
|
||
@random.setter | ||
def random(self, value): | ||
pass |
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
Oops, something went wrong.