bugfix test1

This commit is contained in:
Philipp Rauch 2014-02-21 13:42:50 +01:00
parent 919c1d5122
commit d7fec1cb76
8 changed files with 209 additions and 23 deletions

View file

@ -16,6 +16,8 @@ from profile.database import Database
debug = True
intervall = 100
def CAN_start(conf):
print 'starte CAN mit Baud von', conf['can_baudrate']
can = CANFilter(conf)
@ -25,7 +27,11 @@ class CANFilter(Thread):
### Lookup für CAN --> DB ###
lookup = {
'dc_battery' : 'battery'
'U_IST_WERT' : 'GRIDManager_U_IST',
'I_IST_WERT' : 'GRIDManager_I_IST',
'TEMPEARTUR' : 'GRIDManager_Temperatur',
'STATUS_FPGA' : 'GRIDManager_Status',
'I_PH_WERT' : 'GRIDManager_I_PH'
}
def __init__(self, conf):
@ -60,28 +66,41 @@ class CANFilter(Thread):
def run(self):
while True:
receiveMessageName = self.pcan.receiveMessage()
receiveMessageName = self.pcan.receiveMessage(block = True)##
try:
tablename = self.lookup[receiveMessageName]
except:
tablename = receiveMessageName
if receiveMessageName is None:
continue
#print "%s - %s" % (datetime.now(), tablename)
for sym in self.symList:
if receiveMessageName in sym.keys():
tmp = {}
for sig in list(sym[receiveMessageName].columns):
data = self.pcan.Messages[receiveMessageName].Signals[sig].GetData()
if self.pcan.Messages[receiveMessageName].Signals[sig].enum is not None:
if self.pcan.Messages[receiveMessageName].Signals[sig].Enum is not None:
data = self.pcan.Messages[receiveMessageName].Signals[sig].Enum[data]
tmp[sig] = data
sym[receiveMessageName] = sym[receiveMessageName].append(tmp, ignore_index=True)
if len(sym[receiveMessageName].index) == 100:
res = DataFrame(sym[receiveMessageName].mean(axis=0)).T
if len(sym[receiveMessageName].index) == int(1/(0.001 * intervall)):
#res = DataFrame(sym[receiveMessageName].mean(axis=0)).T
res = sym[receiveMessageName][-1:]
res = res.reset_index(drop = True)
res.drop('isMaster', axis = 1, inplace = True)
res.drop('isCharging', axis = 1, inplace = True)
#res.drop('isMaster', axis = 1, inplace = True)
#res.drop('isCharging', axis = 1, inplace = True)
res['DateTime'] = datetime.now()
self.db.writeDatabase(self.lookup[receiveMessageName], res)
#self.db.writeDatabase(self.lookup[receiveMessageName], res)
self.db.writeDatabase(strTable=tablename, dfData=res, bClear=False)
sym[receiveMessageName] = sym[receiveMessageName].drop(sym[receiveMessageName].index[:])
#print res
print "%s - Write to DB - %s" % (res['DateTime'][0], tablename)
sleep(0.01)
#sleep(0.01)

View file

@ -5,7 +5,13 @@ Created on 26.11.2013
'''
from profile.database import Database
_sort_lookup = { 'EA_Last' : 'DateTime' }
_sort_lookup = { 'EA_Last' : 'DateTime',
'I_IST_WERT' : 'DateTime',
'I_SOLL_WERT' : 'DateTime',
'PAC' : 'date_/_time',
'STATUS_FPGA' : 'DateTime',
'U_IST_WERT': 'DateTime',
'pCharger': 'DateTime'}
def setup(conf):
'''

View file

@ -66,12 +66,12 @@ def _to_float_time(reg):
def _to_long(reg):
tmp = _to_ulong(reg)
s = struct.pack('=i', tmp)
return numpy.float(struct.unpack('=l', s)[0])
return numpy.float32(struct.unpack('=l', s)[0])
def _to_double(reg):
tmp = int(reg[0]) << 3*16 | int(reg[1]) << 2*16 | int(reg[2]) << 16 | int(reg[3])
s = struct.pack('=q', tmp)
return numpy.float(struct.unpack('=d', s)[0])
return numpy.float64(struct.unpack('=d', s)[0])
def _to_time_abs(reg):
timestamp = _to_ulong(reg)
@ -79,15 +79,15 @@ def _to_time_abs(reg):
return date
def _to_ulong(reg):
return numpy.int(reg[0]) << 16 | int(reg[1])
return numpy.int32(reg[0]) << 16 | int(reg[1])
def _to_ushort(reg):
return numpy.int(reg[0])
return numpy.int16(reg[0])
def _to_float(reg):
tmp = _to_ulong(reg)
s = struct.pack('=i', tmp)
return numpy.float(struct.unpack('=f', s)[0])
return numpy.float32(struct.unpack('=f', s)[0])
def _set_time(PAC):
stamp = time.time()

13
src/can.py Normal file
View file

@ -0,0 +1,13 @@
'''
Created on 21.02.2014
@author: rauchp
'''
from Config.parser import config
from CAN.Filter import CAN_start
### LOAD CONFIG ###
c = config()
conf = c.readConf()
CAN_start(conf)

View file

@ -0,0 +1,146 @@
FormatVersion=5.0 // Do not edit!
Title="Symboldatei_multiport"
{ENUMS}
enum CTRL_MODE(1="LSI", 2="HSI", 4="HSU", 8="LSU", 0="OFF")
enum FF_MODE(0="HSU", 1="LSU", 2="HSI", 3="LSI")
enum PH_MODE(0="OFF", 1="REFA", 2="REFB")
enum ERROR_CODE(0="NO ERROR", 1="DCDC_LOCKED",
10="ERR_HSUMAXUL_OUTOF_HWLIMITS", 11="ERR_HSUMINUL_OUTOF_HWLIMITS",
12="ERR_LSUMAXUL_OUTOF_HWLIMITS", 13="ERR_LSUMINUL_OUTOF_HWLIMITS",
14="ERR_LSIMAXUL_OUTOF_HWLIMITS", 15="ERR_LSIMINUL_OUTOF_HWLIMITS",
16="ERR_HSIMAXUL_OUTOF_HWLIMITS", 17="ERR_HSIMINUL_OUTOF_HWLIMITS",
50="ERR_HSUVALUE_OUTOF_ULIMITS", 51="ERR_LSUVALUE_OUTOF_ULIMITS",
52="ERR_LSIVALUE_OUTOF_ULIMITS", 53="ERR_HSIVALUE_OUTOF_ULIMITS",
60="ERR_WRONG_CTRL_MODE", 61="ERR_WRONG_PM", 62="ERR_WRONG_FEED_MODE",
124="ERR_CONTROLMSG_NO_MODE_SELECTED")
{RECEIVE}
[U_IST_WERT]
ID=524h
DLC=8
Var=HSU signed 0,16 /u:V /f:0.1 /d:0
Var=PH1_LSU signed 16,16 /u:V /f:0.1
Var=PH2_LSU signed 32,16 /u:V /f:0.1
[I_IST_WERT]
ID=525h
DLC=8
CycleTime=10
Var=PH1_LSI signed 0,16 /u:A /f:0.01
Var=PH1_HSI signed 16,16 /u:A /f:0.01
Var=PH2_LSI signed 32,16 /u:A /f:0.01
Var=PH2_HSI signed 48,16 /u:A /f:0.01
[I_PH_WERT]
ID=528h
DLC=8
Var=PH1_STROM signed 0,16 /u:A /f:0.001
Var=PH2_STROM signed 16,16 /u:A /f:0.001
Var=PH3_STROM signed 32,16 /u:A /f:0.001
Var=PH4_STROM signed 48,16 /u:A /f:0.001
[TEMPEARTUR]
ID=529h
DLC=8
Var=TEMP1 unsigned 0,8 /u:deg /o:-60
Var=TEMP2 unsigned 8,8 /u:deg /o:-60
Var=TEMP3 unsigned 16,8 /u:deg /o:-60
Var=TEMP4 unsigned 24,8 /u:deg /o:-60
Var=TEMP5 unsigned 32,8 /u:deg /o:-60
[STATUS_FPGA]
ID=526h
DLC=8
Var=PH1_HSU_MAX_LIM unsigned 0,1
Var=PH1_HSU_MIN_LIM unsigned 1,1
Var=PH1_LSU_MAX_LIM unsigned 2,1
Var=PH1_LSU_MIN_LIM unsigned 3,1
Var=PH1_HSI_MAX_LIM unsigned 4,1
Var=PH1_HSI_MIN_LIM unsigned 5,1
Var=PH1_LSI_MAX_LIM unsigned 6,1
Var=PH1_LSI_MIN_LIM unsigned 7,1
Var=PH2_HSU_MAX_LIM unsigned 8,1
Var=PH2_HSU_MIN_LIM unsigned 9,1
Var=PH2_LSU_MAX_LIM unsigned 10,1
Var=PH2_LSU_MIN_LIM unsigned 11,1
Var=PH2_HSI_MAX_LIM unsigned 12,1
Var=PH2_HSI_MIN_LIM unsigned 13,1
Var=PH2_LSI_MAX_LIM unsigned 14,1
Var=PH2_LSI_MIN_LIM unsigned 15,1
Var=G_EN unsigned 16,1
Var=USR_EN unsigned 17,1
Var=INTERLOCK unsigned 18,1
Var=LS_OV unsigned 19,1
Var=HS_OV unsigned 20,1
Var=PH1_OC unsigned 21,1
Var=PH2_OC unsigned 22,1
Var=PH3_OC unsigned 23,1
Var=PH4_OC unsigned 24,1
Var=ERROR unsigned 32,8 /e:ERROR_CODE
{SENDRECEIVE}
[PH1_SOLL]
ID=515h
DLC=8
CycleTime=10
Var=PH1_CTRLMODE CTRL_MODE 0,4
Var=PH1_SOLLWERT signed 8,16
Var=PH1_SOLLGAIN signed 24,16
Var=PH1_SOLLOFFSET signed 40,16
[PH2_SOLL]
ID=516h
DLC=8
CycleTime=10
Var=PH2_CTRLMODE CTRL_MODE 0,4
Var=PH2_SOLLWERT signed 8,16
Var=PH2_SOLLGAIN signed 24,16
Var=PH2_SOLLOFFSET signed 40,16
[STATE]
ID=517h
DLC=8
CycleTime=10
Var=CTRLMODE CTRL_MODE 0,4
Var=ENABLE unsigned 5,1
Var=BOOST bit 6,1
Var=BUCK bit 7,1
Var=FFMODE FF_MODE 8,2
Var=PH1_MODE PH_MODE 16,2
Var=PH2_MODE PH_MODE 18,2
Var=PH3_MODE PH_MODE 20,2
Var=PH4_MODE PH_MODE 22,2
Var=PH_WIRKUNG signed 24,16 /d:5000
Var=PH_MAX signed 40,16 /d:10000
Var=ph_config_apply unsigned 10,1
[HS_LIMIT]
ID=519h
DLC=8
CycleTime=10
Var=HSI_MAX signed 0,16 /u:A /f:0.01 /d:5
Var=HSI_MIN signed 16,16 /u:A /f:0.01 /d:-5
Var=HSU_MAX signed 32,16 /u:V /f:0.1 /d:500
Var=HSU_MIN signed 48,16 /u:V /f:0.1 /d:0
[LS_LIMIT]
ID=51Eh
DLC=8
CycleTime=10
Var=LSI_MAX signed 0,16 /u:A /f:0.01 /d:5
Var=LSI_MIN signed 16,16 /u:A /f:0.01 /d:-5
Var=LSU_MAX signed 32,16 /u:V /f:0.1 /d:500
Var=LSU_MIN signed 48,16 /u:V /f:0.1 /d:0
[PIPARAMETER]
ID=520h
DLC=8
CycleTime=10
Var=UParameterI signed 0,16 /d:5
Var=UParameterP signed 16,16 /d:200
Var=IParameterI signed 32,16 /d:80
Var=IParameterP signed 48,16 /d:200

View file

@ -3,7 +3,7 @@ mySQL_server = iisb-mysql.iisb.fraunhofer.de
mySQL_port = 3306 # default 3306
mySQL_user = stud_EMS
mySQL_pass = sql13
mySQL_database = photodb
mySQL_database = ems_testdb # photodb
mySQL_speed = 0.02 # time between two query's in sec # default 0.02
#sdgsgssth
@ -16,10 +16,10 @@ config_debug = True # default False
#### CAN ####
## possible Baud Rates: 100k, 125k, 250k, 500k, 1000k ##
can_baudrate = 250k # default 500k
can_symfile = ems-test.sym
can_baudrate = 500k # default 500k
can_symfile = Symboldatei_multiport.sym #ems-test.sym
#### PAC ####
pac_ip = 10.2.6.6 # 10.2.6.5, 10.2.6.6, 10.2.6.7, 10.2.6.8
pac_csvfile = pacs.csv # only one file allowed
pac_messages = 797, 1, 3, 5, 13, 15, 17, 25, 27, 29
pac_messages = 797, 1, 3, 5, 13, 15, 17, 25, 27, 29 #, 31, 33, 35

View file

@ -6,6 +6,7 @@ Created on 21.11.2013
from Config.parser import config
from Connector.switch import Switch, MODBUS
from time import sleep
from datetime import datetime
from profile.database import Database
from profile.datasheet import Datasheet
from pandas import DataFrame
@ -21,7 +22,7 @@ db.loadDatabase(strHost = conf['mySQL_server'],
intPort = int(conf['mySQL_port']),
strUser = conf['mySQL_user'],
strPasswd = conf['mySQL_pass'],
strDatabase = 'ems_testdb', #conf['mySQL_database'],
strDatabase = conf['mySQL_database'],
strTable = None)
### READ CSV ###
@ -51,7 +52,8 @@ while True:
for mes in conf['pac_messages']:
modbus.query.put([1, int(mes)])
res.update(modbus.queue.get())
print datetime.now() + " " + res.keys()
res_data = tab.append(res, ignore_index=True)
res_data[col[1::]] = res_data[col[1::]].astype(numpy.float) #till now only float support
db.writeDatabase('PAC', res_data, bClear = False)

View file

@ -5,7 +5,7 @@ Created on 29.01.2014
'''
from Config.parser import config
from API.service import REST_start
from CAN.Filter import CAN_start
#from CAN.Filter import CAN_start
### LOAD CONFIG ###
c = config()