!!!Testimplementierung!!!
*API wird ausgeführt *sie starten das ems *ems startet swich
This commit is contained in:
parent
e70ef4de38
commit
59340b5fee
3 changed files with 40 additions and 24 deletions
13
scr/API.py
13
scr/API.py
|
|
@ -149,10 +149,10 @@ class Buffer(object):
|
|||
#ToDo
|
||||
None
|
||||
|
||||
class API(Thread):
|
||||
class API(object):
|
||||
|
||||
def __init__(self):
|
||||
Thread.__init__(self)
|
||||
# Thread.__init__(self)
|
||||
self.app = Flask(__name__)
|
||||
|
||||
### ADD URL RULES ###
|
||||
|
|
@ -197,3 +197,12 @@ def get_catch_all(path):
|
|||
else:
|
||||
out = buf.get_level(l)
|
||||
return jsonify( out )
|
||||
|
||||
def start():
|
||||
api = API()
|
||||
api.app.run(host = conf['flask_server'], port = int(conf['flask_port']), debug = conf['flask_debug'])
|
||||
|
||||
emsthread = ems.ems(buf)
|
||||
print 'EMS-Thread:\t', emsthread
|
||||
print '\tAPI:\t', buf
|
||||
start()
|
||||
|
|
|
|||
42
scr/ems.py
42
scr/ems.py
|
|
@ -5,35 +5,41 @@ Created on 15.11.2013
|
|||
@version: 0.02
|
||||
'''
|
||||
|
||||
#from threading import Thread
|
||||
from threading import Thread
|
||||
#from Queue import Queue
|
||||
from swich import Swich, MYSQL
|
||||
from API import Buffer, API
|
||||
from CANFilter import CANFilter
|
||||
#from API import Buffer, start
|
||||
#from CANFilter import CANFilter
|
||||
|
||||
def startAPI(): #does not work currently
|
||||
app = API()
|
||||
app.start()
|
||||
pass
|
||||
|
||||
def startCANFilter():
|
||||
can = CANFilter()
|
||||
can.start()
|
||||
pass
|
||||
#def startCANFilter():
|
||||
# can = CANFilter()
|
||||
# can.start()
|
||||
# pass
|
||||
|
||||
def startSwich():
|
||||
swich = Swich(MYSQL)
|
||||
queue, can = swich.initialisiere()
|
||||
print 'EMS:\t', queue
|
||||
print 'swich-Thread:\t', swich
|
||||
print '\tEMS:\t', queue
|
||||
swich.start()
|
||||
pass
|
||||
return queue
|
||||
|
||||
def writeToBuffer():
|
||||
#TODO
|
||||
pass
|
||||
|
||||
startSwich()
|
||||
class ems(Thread):
|
||||
def __init__(self, buf):
|
||||
Thread.__init__(self)
|
||||
self.buffer = buf
|
||||
self.queue = startSwich()
|
||||
print '\tEMS:\t', buf
|
||||
|
||||
#buf = Buffer()
|
||||
#print 'ems ', buf
|
||||
#startAPI()
|
||||
def run(self):
|
||||
alt = None
|
||||
while True:
|
||||
neu = self.queue.get()
|
||||
if not alt == neu:
|
||||
self.buffer.device.get['battery'].update({'Voltage' : neu[2]})
|
||||
print neu
|
||||
alt = neu
|
||||
|
|
@ -68,11 +68,12 @@ class Swich(Thread):
|
|||
while True:
|
||||
sql = 'SELECT * FROM %s ORDER BY timestamp DESC LIMIT 1'
|
||||
# item = Swich.queue.get(block = True)
|
||||
item = 'EMS-TEST'
|
||||
item = conf['mySQL_table']
|
||||
|
||||
# data = self.cursor.execute(sql % item)
|
||||
self.setQueue(item)
|
||||
sleep(0.5)
|
||||
self.cursor.execute(sql % item)
|
||||
for row in self.cursor:
|
||||
self.setQueue(row)
|
||||
sleep(0.1)
|
||||
|
||||
def setQueue(self, item):
|
||||
self.queue.put(item)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue