modbus modul hinzugefügt
CAN Nachrichten in config eingefügt Logik in CANFilter integriert
This commit is contained in:
parent
053dff064e
commit
149b702e05
9 changed files with 145 additions and 97 deletions
61
src/API.py
61
src/API.py
|
|
@ -4,7 +4,7 @@ Created on 24.10.2013
|
|||
@author: Philipp Rauch
|
||||
@version: 0.6
|
||||
'''
|
||||
|
||||
from sys import stderr
|
||||
from datetime import datetime
|
||||
from flask import Flask, jsonify, abort, make_response, request
|
||||
from socket import gethostname
|
||||
|
|
@ -65,7 +65,7 @@ class Buffer(object):
|
|||
'dc_labor' : dc_labor,
|
||||
'dc_grid' : dc_grid,
|
||||
'ac_grid' : ac_grid,
|
||||
'request' : None
|
||||
'request' : {}
|
||||
}
|
||||
|
||||
_instance = None
|
||||
|
|
@ -111,6 +111,8 @@ class Buffer(object):
|
|||
@param postfix: appendix to the given url
|
||||
'''
|
||||
if isinstance(dic, dict):
|
||||
if '00_config' in url.split('/'):
|
||||
return
|
||||
url = '%s/%s' % (url, postfix)
|
||||
self.set_href(dic, url)
|
||||
else:
|
||||
|
|
@ -142,9 +144,41 @@ class Buffer(object):
|
|||
abort(404)
|
||||
return { l[-1] : message, 'args' : args.to_dict(flat=False)}
|
||||
|
||||
def update_buffer(self):
|
||||
#ToDo
|
||||
pass
|
||||
def update_buffer(self, push):
|
||||
'''
|
||||
Method to update the Buffer on the given path
|
||||
@param push: message to push in the buffer
|
||||
construction: key is the path
|
||||
value is the dict
|
||||
'''
|
||||
|
||||
## Test of valid push message ##
|
||||
if not isinstance(push, dict):
|
||||
stderr.write('error wrong parameter: Type is %s expect dict' %
|
||||
push.__class__.__name__)
|
||||
return
|
||||
if len(push.keys()) not in [1]:
|
||||
stderr.write('error wrong number of arguments: %s expect 1' %
|
||||
len(push.keys()))
|
||||
return
|
||||
if not isinstance(push.get(push.keys()[0]) ,dict):
|
||||
stderr.write('error value is not dict')
|
||||
return
|
||||
|
||||
key = push.keys()[0]
|
||||
value = push[key]
|
||||
path = key.split('/')
|
||||
if path[0] == '':
|
||||
path.remove('')
|
||||
|
||||
sys = self.system
|
||||
for key in path:
|
||||
try:
|
||||
sys = sys[key]
|
||||
except KeyError:
|
||||
stderr.write('error wrong path: %s' % key)
|
||||
return
|
||||
sys.update(value)
|
||||
|
||||
def init_buffer(self):
|
||||
#ToDo
|
||||
|
|
@ -155,6 +189,14 @@ class API(object):
|
|||
def __init__(self):
|
||||
self.app = Flask(__name__)
|
||||
|
||||
### Start EMS thread ###
|
||||
self.EMS = ems.ems(buf)
|
||||
self.emsthread = self.EMS.start()
|
||||
|
||||
if conf['config_debug']:
|
||||
print 'EMS-Thread:\t', self.EMS
|
||||
print '\tAPI-BUFFER:\t', buf
|
||||
|
||||
### ADD URL RULES ###
|
||||
self.app.error_handler_spec[None][400] = bad_reqest
|
||||
self.app.error_handler_spec[None][404] = not_found
|
||||
|
|
@ -196,15 +238,10 @@ def get_catch_all(path):
|
|||
out = buf.get_level(l)
|
||||
return jsonify( out )
|
||||
|
||||
def start():
|
||||
def API_start():
|
||||
api = API()
|
||||
api.app.run(host = conf['flask_server'],
|
||||
port = int(conf['flask_port']),
|
||||
debug = conf['flask_debug'])
|
||||
|
||||
EMS = ems.ems(buf)
|
||||
emsthread = EMS.start()
|
||||
if conf['config_debug']:
|
||||
print 'EMS-Thread:\t', EMS
|
||||
print '\tAPI-BUFFER:\t', buf
|
||||
start()
|
||||
API_start()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue