umstellung auf sym files und datenbank im fraunhofer
This commit is contained in:
parent
0c9a1d2f2c
commit
580a93d620
7 changed files with 89 additions and 52 deletions
|
|
@ -7,6 +7,7 @@ Created on 13.11.2013
|
|||
from CanMessage import CanMessage
|
||||
from CanSignal import CanSignal
|
||||
from PCan import PcanAdapter
|
||||
from Sym2Lib import Add2Adapter, Sym2Code
|
||||
from datetime import datetime
|
||||
from time import sleep
|
||||
from threading import Thread
|
||||
|
|
@ -14,7 +15,7 @@ from Queue import Queue
|
|||
from config import Config
|
||||
import database
|
||||
|
||||
debug = False
|
||||
debug = True
|
||||
|
||||
class CANFilter(Thread):
|
||||
|
||||
|
|
@ -33,24 +34,18 @@ class CANFilter(Thread):
|
|||
self.queue = Queue()
|
||||
|
||||
self.pcan = PcanAdapter(PcanAdapter.Baudrate[self.conf['can_baudrate']],
|
||||
debug = self.conf['config_debug'])
|
||||
debug = self.conf['config_debug'])
|
||||
self.pcan.initialize()
|
||||
|
||||
for message in self.conf['can_messages']:
|
||||
self.pcan.addMessage(CanMessage(int(self.conf[message]['id'], 0), #hex-string to int
|
||||
int(self.conf[message]['length']),
|
||||
int(self.conf[message]['time']),
|
||||
message))
|
||||
print "Message: %s" % message
|
||||
for signal in self.conf["sig_%s" % message]:
|
||||
self.pcan.Messages[message].addSignal(CanSignal(int(self.conf[signal]['begin']),
|
||||
int(self.conf[signal]['length']),
|
||||
int(self.conf[signal]['offset']),
|
||||
float(self.conf[signal]['scaling']),
|
||||
int(self.conf[signal]['data']),
|
||||
signal))
|
||||
print " - %s" % signal
|
||||
|
||||
if isinstance(self.conf["symfile"], str):
|
||||
sym = "%s/%s" % (self.conf["config_dictionary"], self.conf["symfile"])
|
||||
#Sym2Code(sym)
|
||||
Add2Adapter(self.pcan, sym)
|
||||
elif isinstance(self.conf["symfile"], list):
|
||||
for element in self.conf["symfile"]:
|
||||
sym = "%s/%s" % (self.conf["config_dictionary"], element)
|
||||
#Sym2Code(sym)
|
||||
Add2Adapter(self.pcan, sym)
|
||||
|
||||
def mean(self, l):
|
||||
return float(sum(l))/len(l) if len(l) > 0 else 0
|
||||
|
|
@ -58,6 +53,7 @@ class CANFilter(Thread):
|
|||
def run(self):
|
||||
while True:
|
||||
receiveMessageId = self.pcan.receiveMessage()
|
||||
|
||||
if receiveMessageId == self.pcan.Messages['dc_battery'].Id:
|
||||
|
||||
self.battery_current.append(
|
||||
|
|
@ -73,18 +69,18 @@ class CANFilter(Thread):
|
|||
print 'current: ', self.mean(self.battery_current)
|
||||
print 'voltage: ', self.mean(self.battery_voltage)
|
||||
print 'SoC: ', self.mean(self.battery_soc)
|
||||
print 'time: ', self.mean(self.battery_timestamp)
|
||||
print 'time: ', self.battery_timestamp[50]
|
||||
|
||||
tabelle = 'battery'
|
||||
|
||||
list_daten = [(tabelle, str(self.battery_timestamp[i]),
|
||||
str(self.battery_current[i]),
|
||||
str(self.battery_voltage[i]),
|
||||
str(self.battery_current[i]),
|
||||
str(self.battery_soc[i])) for i in range(100)]
|
||||
|
||||
mean_daten = (tabelle, str(self.battery_timestamp[50]),
|
||||
str(self.mean(self.battery_current)),
|
||||
str(self.mean(self.battery_voltage)),
|
||||
str(self.mean(self.battery_current)),
|
||||
str(self.mean(self.battery_soc)))
|
||||
|
||||
sql = "INSERT INTO %s VALUES (\'%s\',%s,%s,%s)"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue