Bugfix: Decomposing messages

* Fixed a bug in the CanMessage.decomposeData
This commit is contained in:
Christian Sueltrop 2012-08-08 10:30:00 +02:00
parent 3a693ba35d
commit b45ed50a31
5 changed files with 22 additions and 17 deletions

View file

@ -123,7 +123,7 @@ class CanMessage(object):
This method is basically the reversion of the method composeData.
'''
def decomposeData(self):
for sigKey in self.Signals:
for sigKey in self.Signals:
sig = self.Signals[sigKey]
tgtBegin = 0 # writing the target data (to the signal) always starts at the first byte
srcBegin = sig.Begin # where the target data is in the message is defined in the Begin field of the CanSignal object. Unit: bits
@ -139,8 +139,8 @@ class CanMessage(object):
if srcByteNo >= self.Length:
sys.exit('Signal data not in message (message too short)')
tmp = (self.Data[srcByteNo] & (1<<tgtBitNo))
if tmp != 0: # the bit shall be set
tmp = (self.Data[srcByteNo] & (1<<srcBitNo))
if tmp > 0: # the bit shall be set
sig.Data[tgtByteNo] |= (1<<tgtBitNo)
else: # the bit shall be cleared
sig.Data[tgtByteNo] &= ~(1<<tgtBitNo)
@ -155,7 +155,7 @@ class CanMessage(object):
if tgtBitNo >= 8:
tgtBitNo = 0
tgtByteNo += 1
self.Signals[sigKey] = sig
'''

Binary file not shown.

Binary file not shown.

View file

@ -110,16 +110,21 @@ class PcanAdapter (object):
Tries to receive a CAN message and puts its data into the according CanMessage object's Data field.
This method should be called frequently.
'''
result, msg, timestamp = self.Pcan.Read(self.Channel)
if result == PCANBasic.PCAN_ERROR_OK:
# loop through the messages and look for one that matches the received message:
for msgKey in self.Messages:
if self.Messages[msgKey].Id == msg.ID:
if msg.LEN != self.Messages[msgKey].Length:
# an error message could be posted at this point
pass
else:
for i in range(0, self.Messages[msgKey].Length):
self.Messages[msgKey].Data[i] = msg.DATA[i]
self.Messages[msgKey].decomposeData()
while True: # do this while messages are read from the bus
result, msg, timestamp = self.Pcan.Read(self.Channel)
if result == PCANBasic.PCAN_ERROR_OK:
# loop through the messages and look for one that matches the received message:
for msgKey in self.Messages:
if self.Messages[msgKey].Id == msg.ID:
if msg.LEN != self.Messages[msgKey].Length:
# an error message could be posted at this point
pass
else:
#print msgKey
for i in range(0, self.Messages[msgKey].Length):
self.Messages[msgKey].Data[i] = msg.DATA[i]
self.Messages[msgKey].decomposeData()
elif result == PCANBasic.PCAN_ERROR_QRCVEMPTY:
break

Binary file not shown.