Fixed a bug in CanMessage.py that prohibited clearing bits that where once set.
This commit is contained in:
parent
b07ff99b4a
commit
9ff6ce1301
6 changed files with 21 additions and 14 deletions
|
|
@ -65,10 +65,10 @@ class CanMessage(object):
|
|||
of the CanMessage object. The position where to copy the data is defined in the Begin and Length fields of the CanSignal objects.
|
||||
'''
|
||||
|
||||
for symKey in self.Signals:
|
||||
sym = self.Signals[symKey]
|
||||
for sigKey in self.Signals:
|
||||
sig = self.Signals[sigKey]
|
||||
srcBegin = 0 # reading the source data (from the Signal definition) always starts at the first bit
|
||||
tgtBegin = sym.Begin # where the source data goes is defined in the Begin field of the CanSignal object
|
||||
tgtBegin = sig.Begin # where the source data goes is defined in the Begin field of the CanSignal object
|
||||
|
||||
srcByteNo = (srcBegin/8) # will be 0 if srcBegin == 0
|
||||
srcBitNo = (srcBegin%8) # will be 0 if srcBegin == 0
|
||||
|
|
@ -76,15 +76,24 @@ class CanMessage(object):
|
|||
tgtByteNo = (tgtBegin/8) # get the byte and bit numbers
|
||||
tgtBitNo = (tgtBegin%8) # for the target (the CanMessage object) array
|
||||
|
||||
for i in range(0, sym.Length):
|
||||
for i in range(0, sig.Length):
|
||||
|
||||
#print tgtByteNo
|
||||
#print tgtBitNo
|
||||
#print ''
|
||||
# copy the source data bits to the target
|
||||
# OR # get srcBitNo from srcByteNo and shift it to tgtBitNo
|
||||
if tgtByteNo >= self.Length:
|
||||
sys.exit('Signal does not fit into message!')
|
||||
|
||||
tmp = (sym.Data[srcByteNo] >> srcBitNo) & 0x01
|
||||
tmp = tmp << tgtBitNo
|
||||
self.Data[tgtByteNo] |= tmp
|
||||
|
||||
#print srcBitNo
|
||||
tmp = sig.Data[srcByteNo]
|
||||
tmp = tmp >> srcBitNo
|
||||
tmp = tmp & 0x01
|
||||
if tmp == 1: # the bit shall be set
|
||||
self.Data[tgtByteNo] |= (1 << tgtBitNo)
|
||||
else: # the bit shall be cleared
|
||||
self.Data[tgtByteNo] &= ~(1 << tgtBitNo)
|
||||
|
||||
# increment the counters
|
||||
srcBitNo += 1
|
||||
|
|
@ -96,6 +105,3 @@ class CanMessage(object):
|
|||
if tgtBitNo >= 8:
|
||||
tgtBitNo = 0
|
||||
tgtByteNo += 1
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -41,6 +41,7 @@ class CanSignal(object):
|
|||
'''
|
||||
#if not (len(Data) == self.Length):
|
||||
# sys.exit('Data has invalid length')
|
||||
tmpData = int((SignalData+self.Offset)*self.Scaling)
|
||||
tmpData = int((SignalData+self.Offset) / self.Scaling)
|
||||
self.Data = []
|
||||
for i in range(0, int(self.Length/8)+1):
|
||||
self.Data.append ( (tmpData >> 8) & 0xff )
|
||||
self.Data.append ( (tmpData >> (8*i) ) & 0xff )
|
||||
Binary file not shown.
|
|
@ -59,7 +59,7 @@ class PcanAdapter (object):
|
|||
msg.ID = Message.Id
|
||||
msg.MSGTYPE = PCANBasic.PCAN_MESSAGE_STANDARD
|
||||
msg.LEN = Message.Length
|
||||
msg.DATA[0:len(Message.Data)] = Message.Data
|
||||
msg.DATA[0:Message.Length] = Message.Data
|
||||
|
||||
self.Pcan.Write(self.Channel, msg)
|
||||
#print ('Message ' + Message.Label + ' written.')
|
||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue