Offset and scaling are taken into account when calculating signal values.
This commit is contained in:
parent
2aa6eb3da7
commit
b07ff99b4a
4 changed files with 12 additions and 13 deletions
|
|
@ -14,12 +14,8 @@ class CanSignal(object):
|
|||
A Signal has a Begin, a Length and Data. The Label is a textual tag that identifies the Signal to
|
||||
a human.
|
||||
'''
|
||||
Begin = 0;
|
||||
Length = 0;
|
||||
Data = [];
|
||||
Label = ''
|
||||
|
||||
def __init__(self, SignalBegin, SignalLength, SignalData, SignalLabel):
|
||||
def __init__(self, SignalBegin, SignalLength, SignalOffset, SignalScaling, SignalData, SignalLabel):
|
||||
'''
|
||||
Constructor.
|
||||
@param SignalBegin: At which bit does the Signal begin in a CAN message?
|
||||
|
|
@ -28,15 +24,16 @@ class CanSignal(object):
|
|||
'''
|
||||
self.Begin = SignalBegin
|
||||
self.Length = SignalLength
|
||||
self.Offset = SignalOffset
|
||||
self.Scaling = SignalScaling
|
||||
|
||||
self.Label = SignalLabel
|
||||
self.Data = []
|
||||
|
||||
for i in range(0, int(SignalLength/8)+1):
|
||||
self.Data.append ( (SignalData >> 8) & 0xff )
|
||||
|
||||
#self.Data = SignalData
|
||||
self.SetData(SignalData)
|
||||
|
||||
|
||||
|
||||
def SetData(self, Data):
|
||||
def SetData(self, SignalData):
|
||||
'''
|
||||
Updated the data of the Signal.
|
||||
The data is given to the Signal as full bytes, but only the bits up to Length may be used!
|
||||
|
|
@ -44,4 +41,6 @@ class CanSignal(object):
|
|||
'''
|
||||
#if not (len(Data) == self.Length):
|
||||
# sys.exit('Data has invalid length')
|
||||
self.Data = Data
|
||||
tmpData = int((SignalData+self.Offset)*self.Scaling)
|
||||
for i in range(0, int(self.Length/8)+1):
|
||||
self.Data.append ( (tmpData >> 8) & 0xff )
|
||||
Binary file not shown.
|
|
@ -62,4 +62,4 @@ class PcanAdapter (object):
|
|||
msg.DATA[0:len(Message.Data)] = Message.Data
|
||||
|
||||
self.Pcan.Write(self.Channel, msg)
|
||||
#print ('Message ' + Message.Label + ' written.\n')
|
||||
#print ('Message ' + Message.Label + ' written.')
|
||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue