Rückgabequeue arbeitet mit dictionarys
*die Rückgabequeue des swiches gibt nun dic zurück *die config wurde erweitert *der CANFilter wird als eigenständiges Programm verwändet
This commit is contained in:
parent
cda58b0f2e
commit
8d56806c03
7 changed files with 53 additions and 28 deletions
|
|
@ -5,14 +5,13 @@ Created on 24.10.2013
|
|||
@version: 0.6
|
||||
'''
|
||||
|
||||
from time import time
|
||||
from datetime import datetime
|
||||
from flask import Flask, jsonify, abort, make_response, request
|
||||
from socket import gethostname
|
||||
from threading import Thread
|
||||
from config import Config
|
||||
import ems
|
||||
|
||||
### LOAD CONFIG ###
|
||||
c = Config()
|
||||
conf = c.readConf()
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class CANFilter(Thread):
|
|||
|
||||
battery_current, battery_voltage, battery_capacity, battery_timestamp, test = [], [], [], [], [] #create tmp lists
|
||||
|
||||
### LOAD CONFIG ###
|
||||
c = Config()
|
||||
conf = c.readConf()
|
||||
|
||||
|
|
@ -108,4 +109,4 @@ class CANFilter(Thread):
|
|||
#self.cursor.executemany(sql, daten)
|
||||
|
||||
del self.battery_current[:], self.battery_voltage[:], self.battery_capacity[:], self.battery_timestamp[:] #clear tmp lists
|
||||
sleep(0.01)
|
||||
sleep(0.01)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class Config():
|
|||
'mySQL_pass': 'KiWujcafAlor',
|
||||
'mySQL_database': 'smoke_test',
|
||||
'mySQL_table': 'battery',
|
||||
'mySQL_speed' : '0.1',
|
||||
'flask_server': '0.0.0.0',
|
||||
'flask_port': '5000',
|
||||
'flask_debug': False,
|
||||
|
|
@ -56,4 +57,4 @@ class Config():
|
|||
self._confDic['config_read'] = True
|
||||
if self._confDic['config_debug']:
|
||||
print ('config:\t', self._confDic)
|
||||
return self._confDic
|
||||
return self._confDic
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ mySQL_port = 3306 # default 3306
|
|||
mySQL_user = smoke
|
||||
mySQL_pass = KiWujcafAlor
|
||||
mySQL_database = smoke_test
|
||||
mySQL_table = battery
|
||||
mySQL_table = battery # only for debugging
|
||||
mySQL_speed = 0.1 # time between two query's in sec
|
||||
|
||||
#### FLASK ####
|
||||
|
||||
|
|
@ -15,4 +16,4 @@ flask_debug = True
|
|||
|
||||
#### CONFIG ####
|
||||
|
||||
config_debug = False
|
||||
config_debug = False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ Created on 15.11.2013
|
|||
from threading import Thread
|
||||
#from Queue import Queue
|
||||
from swich import Swich, MYSQL
|
||||
#from API import Buffer, start
|
||||
#from CANFilter import CANFilter
|
||||
|
||||
#def startCANFilter():
|
||||
|
|
@ -18,7 +17,7 @@ from swich import Swich, MYSQL
|
|||
|
||||
def startSwich():
|
||||
swich = Swich(MYSQL)
|
||||
queue, can = swich.initialisiere()
|
||||
queue = swich.initialisiere()
|
||||
print 'swich-Thread:\t', swich
|
||||
print '\tEMS:\t', queue
|
||||
swich.start()
|
||||
|
|
@ -40,7 +39,5 @@ class ems(Thread):
|
|||
while True:
|
||||
neu = self.queue.get()
|
||||
if not alt == neu or True:
|
||||
# self.buffer.update({'Voltage' : neu[2]})
|
||||
self.buffer.device.get('battery').update({'voltage' : neu[2]})
|
||||
# print self.buffer.device.get('battery').get('voltage'), neu[2]
|
||||
alt = neu
|
||||
self.buffer.device.get('battery').update(neu)
|
||||
alt = neu
|
||||
|
|
|
|||
41
scr/swich.py
41
scr/swich.py
|
|
@ -7,7 +7,6 @@ Created on 15.11.2013
|
|||
|
||||
from threading import Thread
|
||||
from Queue import Queue
|
||||
#from CANFilter import CANFilter
|
||||
from time import sleep
|
||||
from config import Config
|
||||
from MySQLdb import connect
|
||||
|
|
@ -16,6 +15,8 @@ MYSQL = 0
|
|||
CSV = 1
|
||||
XML = 2
|
||||
JSON = 3
|
||||
|
||||
### LOAD CONFIG ###
|
||||
c = Config()
|
||||
conf = c.readConf()
|
||||
|
||||
|
|
@ -36,11 +37,6 @@ class Swich(Thread):
|
|||
if self.source == MYSQL:
|
||||
_isInit = True
|
||||
|
||||
### start CAN ###
|
||||
# self.CAN = CANFilter()
|
||||
# self.CAN.start()
|
||||
self.CAN = None
|
||||
|
||||
### connect to DB ###
|
||||
self.connection = connect(host = conf['mySQL_server'],
|
||||
user = conf['mySQL_user'],
|
||||
|
|
@ -52,7 +48,7 @@ class Swich(Thread):
|
|||
### init Queue ###
|
||||
self.queue = Queue()
|
||||
print '\tSWICH:\t', self.queue
|
||||
return self.queue, self.CAN
|
||||
return self.queue
|
||||
|
||||
elif self.source == CSV:
|
||||
pass
|
||||
|
|
@ -67,15 +63,36 @@ class Swich(Thread):
|
|||
return
|
||||
|
||||
def run(self):
|
||||
###########################
|
||||
# Imlementation for MYSQL #
|
||||
###########################
|
||||
while True:
|
||||
sql = 'SELECT * FROM %s ORDER BY timestamp DESC LIMIT 1'
|
||||
# item = Swich.queue.get(block = True)
|
||||
sql_values = 'SELECT * FROM %s ORDER BY timestamp DESC LIMIT 1'
|
||||
sql_collums = 'SHOW COLUMNS FROM %s'
|
||||
item = conf['mySQL_table']
|
||||
|
||||
self.cursor.execute(sql % item)
|
||||
# Queue implementaion
|
||||
# Queue contains the tablename for query
|
||||
# item = query.get() #block = True
|
||||
# query should be included in the result
|
||||
|
||||
collums = []
|
||||
self.cursor.execute(sql_collums % item)
|
||||
for cul in self.cursor:
|
||||
collums.append(cul[0])
|
||||
|
||||
self.cursor.execute(sql_values % item)
|
||||
for row in self.cursor:
|
||||
self.setQueue(row)
|
||||
sleep(0.1)
|
||||
values = row
|
||||
|
||||
result = {}
|
||||
for i in range(len(collums)):
|
||||
result[collums[i]] = values[i]
|
||||
|
||||
print 'PUT:\t%s' % result
|
||||
|
||||
self.setQueue(result)
|
||||
sleep(float('mySQL_speed'))
|
||||
|
||||
def setQueue(self, item):
|
||||
self.queue.put(item)
|
||||
|
|
|
|||
17
scr/test.py
17
scr/test.py
|
|
@ -3,9 +3,10 @@ Created on 21.11.2013
|
|||
|
||||
@author: rauchp
|
||||
'''
|
||||
import CANFilter
|
||||
#import CANFilter
|
||||
# import ems
|
||||
# import time
|
||||
import swich
|
||||
# from config import Config
|
||||
#
|
||||
# c = Config()
|
||||
|
|
@ -14,8 +15,8 @@ import CANFilter
|
|||
# buffer={}
|
||||
# if conf['config_debug']:
|
||||
# print 'starte CAN'
|
||||
can = CANFilter.CANFilter()
|
||||
can.start()
|
||||
#can = CANFilter.CANFilter()
|
||||
#can.start()
|
||||
# if conf['config_debug']:
|
||||
# print 'starte EMS'
|
||||
# th = ems.ems(buffer)
|
||||
|
|
@ -24,4 +25,12 @@ can.start()
|
|||
# print 'alles gestartet'
|
||||
# while True:
|
||||
# print buffer
|
||||
# time.sleep(1)
|
||||
# time.sleep(1)
|
||||
|
||||
sw = swich.Swich(swich.MYSQL)
|
||||
queue = sw.initialisiere()
|
||||
sw.start()
|
||||
print '\tTEST:\t', queue
|
||||
|
||||
while True:
|
||||
print 'GET:\t%s' % queue.get()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue