# Creates a new signal calculated from an existing signal # The new signal can be used in Trace, Data and Graph view # Script takes incoming message from desired channel # Creates a new message, copies original message data to it # Calculates FIR filtered data and adds it to the new message # Sends new message to virtual channel and original message goes through as normal meanValue = 0 # Function that handles all incoming messages def recvFunc(canmsg): if (canmsg.Channel == 1 and canmsg.Id == 385): global meanValue newmsg = CanMsg() # New message to be modified # Change to 16 bit for data calculations currentValue = (canmsg.Data[1]<<8)|canmsg.Data[0] # Support negative values if currentValue >= 32768: currentValue = -65536 + currentValue # Calculates FIR filtered value meanValue = (5 * meanValue + currentValue)/6 # Copy information from original message to new message newmsg.Id = canmsg.Id newmsg.Channel = canmsg.Channel newmsg.Dlc = canmsg.Dlc newmsg.TimeStamp = canmsg.TimeStamp newmsg.IsTxAck = canmsg.IsTxAck newmsg.IsExtendedId = canmsg.IsExtendedId newmsg.IsRtr = canmsg.IsRtr newmsg.IsErrorFrame = canmsg.IsErrorFrame # Insert filtered data to new message newmsg.Data[1] = (meanValue >> 8) & 0xff newmsg.Data[0] = meanValue & 0xff ctapi.Send(2, newmsg) # Send new message to desired channel return True # Return True = original canmsg goes through also