Пример #1
0
    def uds_request(self, ecu_id, service, payload, timeout=2):
        msg = IsoTpMessage(ecu_id)

        # first byte is service ID, rest of message is payload
        msg.data = [service] + payload

        # length is payload length plus 1 for service ID byte
        msg.length = len(payload) + 1

        # generate a request
        request = self.generate_frames(msg)

        # send the request
        for f in request:
            self.cq.send(f)

        # get a response message with the request ID + 20
        start_ts = time.time()
        result = None

        while result == None:
            if time.time() - start_ts > timeout:
                return None

            response = self.cq.recv()

            if response and response.id == ecu_id + 0x20:
                result = self.parse_frame(response)

        return result
Пример #2
0
Файл: uds.py Проект: 0067/CANard
    def uds_request(self, ecu_id, service, payload, timeout=2):
        msg = IsoTpMessage(ecu_id)
        
        # first byte is service ID, rest of message is payload
        msg.data = [service] + payload
        
        # length is payload length plus 1 for service ID byte
        msg.length = len(payload) + 1

        # generate a request
        request = self.generate_frames(msg)

        # send the request
        for f in request:
            self.cq.send(f)

        # get a response message with the request ID + 20
        start_ts = time.time()
        result = None

        while result == None:
            if time.time() - start_ts > timeout:
                return None

            response = self.cq.recv()

            if response and response.id == ecu_id + 0x20:
                result = self.parse_frame(response)

        return result
Пример #3
0
    def obd_request(self, ecu_id, mode, pid_code, timeout=2):
        msg = IsoTpMessage(ecu_id)

        # pack data according to OBD-II standard
        msg.data = [mode, pid_code]

        # standard OBD-II request messages have length of 2
        msg.length = 2

        # this will always generate a single frame
        request = self.generate_frames(msg)[0]

        # send the request
        self.can_dev.send(request)

        # get a response message with the same ID
        response = self.can_dev.recv()
        start_ts = time.time()
        while response.id != ecu_id + 0x20:
            response = self.can_dev.recv()
            if time.time() - start_ts > timeout:
                return None

        return self.parse_frame(response)
Пример #4
0
    def obd_request(self, ecu_id, mode, pid_code, timeout=2):
        msg = IsoTpMessage(ecu_id)
        
        # pack data according to OBD-II standard
        msg.data = [mode, pid_code]
        
        # standard OBD-II request messages have length of 2
        msg.length = 2

        # this will always generate a single frame
        request = self.generate_frames(msg)[0]
        
        # send the request
        self.can_dev.send(request)
        
        # get a response message with the same ID
        response = self.can_dev.recv()
        start_ts = time.time()
        while response.id != ecu_id + 0x20:
            response = self.can_dev.recv()
            if time.time() - start_ts > timeout:
                return None
                
        return self.parse_frame(response)
Пример #5
0
from canard.proto.isotp import IsoTpProtocol, IsoTpMessage
from canard import can 

p = IsoTpProtocol()


f = can.Frame(0x100)
f.data = [3,1,2,3]
f.dlc = 4

#print(p.parse_frame(f))

f.data = [0x10, 20, 1, 2, 3, 4, 5, 6]
f.dlc = 8
print(p.parse_frame(f))
f.data = [0x21, 7, 8, 9, 10, 11, 12, 13]
#print(p.parse_frame(f))
f.data = [0x22, 7, 8, 9, 10, 11, 12, 13]
#print(p.parse_frame(f))

m = IsoTpMessage(0x100)
m.data = range(1,0xFF)
m.length = 0x1FF
for fr in p.generate_frames(m):
    print fr