Bugfixes:
* Fixed a bug in method CanMessage.decomposeData * Fixed a bug in method CanSignal.getData
This commit is contained in:
parent
3a693ba35d
commit
e3d78cc68a
6 changed files with 24 additions and 22 deletions
|
|
@ -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.
|
|
@ -52,12 +52,9 @@ class CanSignal(object):
|
|||
'''
|
||||
'''
|
||||
tmpData = 0
|
||||
for i in range(0, int(self.Length/8)):
|
||||
#print 'Data[i]', self.Data[i]
|
||||
for i in range(0, int(self.Length/8)+1):
|
||||
tmpData += ( self.Data[i] << (8*i) )
|
||||
|
||||
tmpData = int( (tmpData * self.Scaling) + self.Offset )
|
||||
#tmpData = int( (tmpData - self.Offset ) / self.Scaling )
|
||||
#print tmpData
|
||||
tmpData = int( (tmpData * self.Scaling) + self.Offset )
|
||||
|
||||
return tmpData
|
||||
Binary file not shown.
|
|
@ -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.
Loading…
Add table
Add a link
Reference in a new issue