def SendChangeListItemCommand(self, vtsa, ecusa, objectid, index, newid): candata = ([0xB1] + NumericValue(objectid).AsLEBytes(2) + [index & 0xFF] + NumericValue(newid).AsLEBytes(2) + [RESERVED] * 2) self._SendIBSMessage(PGN_ECU2VT, vtsa, ecusa, candata)
def SendChangeAttribute(self, objid, attrid, value, vtsa, ecusa): candata = ([0xAF] + NumericValue(objid).AsLEBytes(2) + NumericValue(attrid).AsLEBytes(1) + NumericValue(value).AsLEBytes(4)) self._SendIBSMessage(PGN_ECU2VT, vtsa, ecusa, candata)
def SendChangeActiveMask(self, wsid, maskid, sa, da): candata = ([0xAD] + NumericValue(wsid).AsLEBytes(2) + NumericValue(maskid).AsLEBytes(2) + [0xFF, 0xFF, 0xFF]) self._SendIBSMessage(PGN_ECU2VT, da, sa, candata)
def SendChangeStringValue(self, objid, value, vtsa, ecusa): # TODO: Check for too large strings! stringData = [ord(x) for x in value] if len(stringData) < 3: stringData = stringData + list([RESERVED] * (3 - len(stringData))) candata =([0xB3] + NumericValue(objid).AsLEBytes(2) + NumericValue(len(value)).AsLEBytes(2) + stringData) self._SendIBSMessage(PGN_ECU2VT, vtsa, ecusa, candata)
def WaitForESCResponse(self, vtsa, ecusa): """ Wait for ESC response @return True for received, error code and aborted input object ID """ [received, data] = self._WaitForIBSMessage(PGN_VT2ECU, vtsa, ecusa, 0x92) return received, data[3], NumericValue.FromLEBytes(data[1:3]).Value()
def SendChangeSKMask(self, maskid, skmaskid, alarm, vtsa, ecusa): candata = [0xFF] * 8 if alarm: candata = ([0xAE] + [0x02] + NumericValue(maskid).AsLEBytes(2) + NumericValue(skmaskid).AsLEBytes(2) + [0xFF, 0xFF]) else: candata = ([0xAE] + [0x01] + NumericValue(maskid).AsLEBytes(2) + NumericValue(skmaskid).AsLEBytes(2) + [0xFF, 0xFF]) self._SendIBSMessage(PGN_ECU2VT, vtsa, ecusa, candata)
def _SendTPMessage(self, pgn, da, sa, data): log.debug('(TP) Request starting TP for {n} bytes'.format(n=len(data))) tpcm_id = IBSID(da, sa, pgn=PGN_TP_CM, prio=6) tpdt_id = IBSID(da, sa, pgn=PGN_TP_DT, prio=7) # Send RTS rts_control = 0x10 nr_of_packets = int(math.ceil(len(data) / 7.0)) rts_data = ([rts_control] + NumericValue(len(data)).AsLEBytes(2) + [nr_of_packets, RESERVED] + NumericValue(pgn).AsLEBytes(3)) log.debug( '(TP) Sending RTS for PGN {0} : {1} bytes in {2} packets'.format( pgn, len(data), nr_of_packets)) self._SendCANMessage(tpcm_id.GetCANID(), rts_data) # Check the CTS #FIXME: Only send min(nrOfPackets,maxPackets), what to do if less? [received, ctsdata] = self._WaitForIBSMessage(0xEC00, da, sa, 0x11) if received: log.debug('(TP) Received CTS for max {0} packets, next packet {1}'. format(ctsdata[1], ctsdata[2])) else: return False # Pack with 0xFF if len(data) % 7 > 0: data = data + list([RESERVED] * (7 - (len(data) % 7))) # Send bytes for seqN in range(nr_of_packets): log.debug('(TP) Send package {n}'.format(n=seqN + 1)) startByte = seqN * 7 self._SendCANMessage(tpdt_id.GetCANID(), [seqN + 1] + data[startByte:startByte + 7]) # sleep 1 msec, otherwise hardware buffer gets full! time.sleep(0.001)
def SendAddressClaim(self, ibsName, sa): log.debug('Sending Address claim for name {:016X}'.format(ibsName)) candata = NumericValue(ibsName).AsLEBytes(8) self._SendIBSMessage(PGN_ADDRCLAIM, SA_GLOBAL, sa, candata)
def _SendETPMessage(self, pgn, da, sa, data): log.debug( '(ETP) Request starting ETP for {n} bytes'.format(n=len(data))) etpcm_id = IBSID(da, sa, PGN_ETP_CM, prio=6) etpdt_id = IBSID(da, sa, PGN_ETP_DT, prio=7) mesg_size = len(data) # Send RTS rts_control = 0x14 totalPackets = int(math.ceil(len(data) / 7.0)) log.debug("(ETP) Sending {0} bytes in {1} packets".format( len(data), totalPackets)) rts_data = ([rts_control] + NumericValue(mesg_size).AsLEBytes(4) + NumericValue(pgn).AsLEBytes(3)) self._SendCANMessage(etpcm_id.GetCANID(), rts_data) # Pack data with 0xFF to multiple of 7 if len(data) % 7 > 0: data = data + list([RESERVED] * (7 - (len(data) % 7))) # Setup for the data transfer nextPacket = 1 maxSentPackets = 0 done = False while not (done): # TODO: What is the time out for this one? [received, ctsdata] = self._WaitForIBSMessage(0xC800, da, sa, 0x15) if received: nextPacket = NumericValue.FromLEBytes(ctsdata[2:5]).Value() maxSentPackets = ctsdata[1] log.debug( "(ETP) Received CTS for max {0} packets, next packet {1}". format(maxSentPackets, nextPacket)) else: log.warning('(ETP) Wait for CTS timed out') break packetOffset = nextPacket - 1 nPackets = min(maxSentPackets, totalPackets - packetOffset) log.debug( '(ETP) Sending {0} packets with packet offset {1}'.format( nPackets, packetOffset)) log.debug('(ETP) bytes[{0} - {1}]'.format( packetOffset * 7, packetOffset * 7 + nPackets * 7 - 1)) dpoData = ([0x16] + [nPackets] + NumericValue(packetOffset).AsLEBytes(3) + NumericValue(pgn).AsLEBytes(3)) self._SendCANMessage(etpcm_id.GetCANID(), dpoData) for n in range(nPackets): startByte = (n * 7) + (packetOffset * 7) # Send send data[n * 7 + dataoffset: n* 7 +7 + dataoffset] self._SendCANMessage(etpdt_id.GetCANID(), [n + 1] + data[startByte:startByte + 7]) # If it is the last packet, quit the loop if (n + nextPacket) >= totalPackets: done = True break time.sleep(0.001)
def SendRequest(self, sa, da, reqPGN): self._SendIBSMessage(PGN_REQUEST, sa, da, NumericValue(reqPGN).AsLEBytes(3))
def WaitForChangeSKMaskResponse(self, vtsa, ecusa): """ Wait for the Change Soft Key Mask response message Return True for received, error code, and new SK mask ID """ [received, data] = self._WaitForIBSMessage(PGN_VT2ECU, vtsa, ecusa, 0xAE) return received, data[5], NumericValue.FromLEBytes(data[3:5]).Value()
def WaitForChangeActiveMaskResponse(self, vtsa, ecusa): [received, data] = self._WaitForIBSMessage(PGN_VT2ECU, vtsa, ecusa, 0xAD) return received, NumericValue.FromLEBytes(data[1:3]).Value(), data[3]
def SendChangeNumericValue(self, objid, value, vtsa, ecusa): candata =([0xA8] + NumericValue(objid).AsLEBytes(2) + [0xFF] + NumericValue(value).AsLEBytes(4)) self._SendIBSMessage(PGN_ECU2VT, vtsa, ecusa, candata)
def SendGetMemory(self, memRequired, vtsa, ecusa): candata = ( [0xC0, 0xFF] + NumericValue(memRequired).AsLEBytes(4) + [0xFF, 0xFF]) self._SendIBSMessage(PGN_ECU2VT, vtsa, ecusa, candata)