示例#1
0
 def connect(self):
     try:
         self.Func_addr = isotp.Address(isotp.AddressingMode.Normal_29bits,
                                        txid=0x18DB33F1,
                                        rxid=0x18DBF133)
         self.Phys_addr = isotp.Address(isotp.AddressingMode.Normal_29bits,
                                        txid=0x18DA87F1,
                                        rxid=0x18DAF187)
         self.Func_stack = isotp.CanStack(
             bus=self.bus, address=self.Func_addr, params=isotp_params_Func
         )  # Network/Transport layer (IsoTP protocol)
         self.Phys_stack = isotp.CanStack(
             bus=self.bus, address=self.Phys_addr, params=isotp_params_Phys
         )  # Network/Transport layer (IsoTP protocol)
         self.Func_conn = PythonIsoTpConnection(
             self.Func_stack
         )  # interface between Application and Transport layer
         self.Phys_conn = PythonIsoTpConnection(
             self.Phys_stack
         )  # interface between Application and Transport layer
     except:
         self.set_statusText(color='red', text='ISOTP Connection fail.')
         if self.Func_conn.is_open():
             self.Func_conn.close()
         if self.Phys_conn.is_open():
             self.Phys_conn.close()
     else:
         self.set_statusText(color='green',
                             text='ISOTP Connection Success.')
示例#2
0
 def __init__(self):
     isotp_params = {
         'stmin':
         0,  # Will request the sender to wait 32ms between consecutive frame. 0-127ms or 100-900ns with values from 0xF1-0xF9
         'blocksize':
         0,  # Request the sender to send 8 consecutives frames before sending a new flow control message
         'wftmax':
         0,  # Number of wait frame allowed before triggering an error
         #'ll_data_length' : 8,                  # Link layer (CAN layer) works with 8 byte payload (CAN 2.0)
         'll_data_length':
         16,  # Link layer (CAN layer) works with 8 byte payload (CAN 2.0)
         'tx_padding':
         0xCC,  # Will pad all transmitted CAN messages with byte 0x00. None means no padding
         'rx_flowcontrol_timeout':
         1000,  # Triggers a timeout if a flow control is awaited for more than 1000 milliseconds
         'rx_consecutive_frame_timeout':
         1000,  # Triggers a timeout if a consecutive frame is awaited for more than 1000 milliseconds
         'squash_stmin_requirement':
         False,  # When sending, respect the stmin requirement of the receiver. If set to True, go as fast as possible.
         'can_fd': True,
         'tx_data_min_length': 8,
         'max_frame_size': 6000
     }
     self.exit_requested = False
     #self.bus = VectorBus(channel='0', bitrate=500000)
     self.bus = VectorBus(channel='0', bitrate=500000, fd=True)
     addr = isotp.Address(isotp.AddressingMode.NormalFixed_29bits,
                          source_address=0x10,
                          target_address=0xF1)
     self.stack = isotp.CanStack(self.bus,
                                 address=addr,
                                 params=isotp_params,
                                 error_handler=self.my_error_handler)
    def get_can_stack(self, **isotp_params_overload):
        # Default configuration
        isotp_params = {
            'stmin':
            10,  # Will request the sender to wait 10ms between consecutive frame. 0-127ms or 100-900ns with values from 0xF1-0xF9
            'blocksize':
            48,  # Request the sender to send 48 consecutives frames before sending a new flow control message
            'wftmax':
            0,  # Number of wait frame allowed before triggering an error
            'tx_data_length':
            8,  # Link layer (CAN layer) works with 8 byte payload (CAN 2.0)
            'tx_padding':
            0,  # Will pad all transmitted CAN messages with byte 0x00. None means no padding
            'rx_flowcontrol_timeout':
            1000,  # Triggers a timeout if a flow control is awaited for more than 1000 milliseconds
            'rx_consecutive_frame_timeout':
            1000,  # Triggers a timeout if a consecutive frame is awaited for more than 1000 milliseconds
            'squash_stmin_requirement':
            False,  # When sending, respect the stmin requirement of the receiver. If set to True, go as fast as possible.
            'can_fd': False
        }

        isotp_params.update(isotp_params_overload)

        return isotp.CanStack(bus=self.bus,
                              address=self.address,
                              params=isotp_params)
 def clientSetUp(self):
     self.bus = can.interface.Bus(tools.get_test_interface(),
                                  bustype='socketcan')
     address = isotp.Address(isotp.AddressingMode.Normal_11bits,
                             txid=self.stack_txid,
                             rxid=self.stack_rxid)
     self.stack = isotp.CanStack(bus=self.bus, address=address)
示例#5
0
def get_DTC_byStatusMask(candevice='can0',
                         txid=0x7E0,
                         rxid=0x7E8,
                         statusMask=0xae):
    dtcdict = {}
    isotp_params = {
        'stmin': 32,
        # Will request the sender to wait 32ms between consecutive frame. 0-127ms or 100-900ns with values from 0xF1-0xF9
        'blocksize':
        8,  # Request the sender to send 8 consecutives frames before sending a new flow control message
        'wftmax': 0,  # Number of wait frame allowed before triggering an error
        'll_data_length':
        8,  # Link layer (CAN layer) works with 8 byte payload (CAN 2.0)
        'tx_padding':
        0x00,  # Will pad all transmitted CAN messages with byte 0x00. None means no padding # VW-AG need Padding !! M.M.
        'rx_flowcontrol_timeout': 1000,
        # Triggers a timeout if a flow control is awaited for more than 1000 milliseconds
        'rx_consecutive_frame_timeout': 1000,
        # Triggers a timeout if a consecutive frame is awaited for more than 1000 milliseconds
        'squash_stmin_requirement': True
        # When sending, respect the stmin requirement of the receiver. If set to True, go as fast as possible.
    }

    config = dict(udsoncan.configs.default_client_config)

    bus = can.interface.Bus(candevice, bustype='socketcan')
    tp_addr = isotp.Address(isotp.AddressingMode.Normal_11bits,
                            txid=txid,
                            rxid=rxid)
    stack = isotp.CanStack(bus=bus, address=tp_addr, params=isotp_params)

    conn = PythonIsoTpConnection(stack)
    try:
        with Client(
                conn, request_timeout=2,
                config=config) as client:  # Application layer (UDS protocol)

            #DiagnosticSessionControl.Session.extendedDiagnosticSession  ->überschneidung mit pyvituds
            client.change_session(3)
            response = client.get_dtc_by_status_mask(statusMask)
            print(
                response.service_data.dtc_count, response.service_data.dtcs
            )  # [<DTC ID=0x001ca4, Status=0x20, Severity=0x00 at 0xb3dceed0>]
            if response.service_data.dtc_count > 0:
                dtclist_str = []
                for el in response.service_data.dtcs:
                    dtclist_str.append("{}".format(el))
                dtcdict["DTC"] = dtclist_str
            else:
                dtcdict["DTC"] = [""]
        return dtcdict
    except NegativeResponseException as e:
        print(
            "NegativeResponseException"
        )  # print('Server refused our request for service %s with code "%s" (0x%02x)' % (e.response.service.get_name(), e.response.code_name, e.response.code))
    except (InvalidResponseException, UnexpectedResponseException) as e:
        print('Server sent an invalid payload : %s' %
              e.response.original_payload)
    except TimeoutException as e:
        print("Timeout")
    def set_isotp(self,
                  source,
                  destination,
                  addr_mode='Normal_29bits',
                  test_name=None):
        """ Set ISO-TP protocol
        Keyword Argument:
        source -- Sender address
        destination -- Receiver address
        addr_mode -- Adressing mode (default Normal_29bits)
        """
        if addr_mode == 'Normal_29bits':
            self.isotp_addr = isotp.Address(isotp.AddressingMode.Normal_29bits,
                                            rxid=int(destination, 16),
                                            txid=int(source, 16))
        elif addr_mode == 'Normal_11bits':
            self.isotp_addr = isotp.Address(isotp.AddressingMode.Normal_11bits,
                                            rxid=int(destination, 16),
                                            txid=int(source, 16))
        elif addr_mode == 'Mixed_11bits':
            self.isotp_addr = isotp.Address(isotp.AddressingMode.Mixed_11bits,
                                            rxid=int(destination, 16),
                                            txid=int(source, 16),
                                            address_extension=0x99)
        elif addr_mode == 'Mixed_29bits':
            self.isotp_addr = isotp.Address(isotp.AddressingMode.Mixed_29bits,
                                            source_address=int(source, 16),
                                            target_address=int(
                                                destination, 16),
                                            address_extension=0x99)
        elif addr_mode == 'NormalFixed_29bits':
            self.isotp_addr = isotp.Address(
                isotp.AddressingMode.NormalFixed_29bits,
                target_address=int(destination, 16),
                source_address=int(source, 16))
        elif addr_mode == 'Extended_11bits':
            self.isotp_addr = isotp.Address(
                isotp.AddressingMode.Extended_11bits,
                rxid=int(destination, 16),
                txid=int(source, 16),
                source_address=0x55,
                target_address=0xAA)
        elif addr_mode == 'Extended_29bits':
            self.isotp_addr = isotp.Address(
                isotp.AddressingMode.Extended_29bits,
                rxid=int(destination, 16),
                txid=int(source, 16),
                source_address=0x55,
                target_address=0xAA)
        else:
            raise AssertionError("""Uncompatible addressing\nSee
                https://can-isotp.readthedocs.io/en/latest/isotp/
                examples.html#different-type-of-addresses""")

        self.isotp_stack = isotp.CanStack(
            bus=self.bus,
            address=self.isotp_addr,
            error_handler=self.curf_error_handler)
        self.is_isotp = True
 def setUp(self):
     self.vcan0_bus = self.make_bus()
     addr = isotp.Address(isotp.AddressingMode.Normal_11bits,
                          rxid=self.stack_rxid,
                          txid=self.stack_txid)
     self.conn = PythonIsoTpConnection(isotp.CanStack(bus=self.vcan0_bus,
                                                      address=addr),
                                       name='unittest')
     self.conn.open()
示例#8
0
 def __init__(self, nodeId):
     self.nodeId = nodeId
     self.bus = SocketcanBus(channel='can0')
     addr = isotp.Address(isotp.AddressingMode.Normal_11bits,
                          rxid=self.nodeId + 100,
                          txid=self.nodeId)
     self.stack = isotp.CanStack(self.bus,
                                 address=addr,
                                 error_handler=self.my_error_handler)
     self.inData = {}
     self.isNewInputData = False
     self.outData = {}
     self.newOutData = False
示例#9
0
 def __init__(self):
    isotp_params = {
       'stmin' : 0, 
       'blocksize' : 4,
       'wftmax' : 0,
       'll_data_length' : 8,
       'tx_padding' : 0xCC,
       'rx_flowcontrol_timeout' : 1000,
       'rx_consecutive_frame_timeout' : 1000,
       'squash_stmin_requirement' : False,
       'can_fd' : False,
       'tx_data_min_length' : 8
    }
    self.exit_requested = False
    #self.bus = VectorBus(channel='0', bitrate=500000)
    self.bus = VectorBus(channel='0', bitrate=500000, fd=True)
    addr = isotp.Address(isotp.AddressingMode.NormalFixed_29bits, source_address=0xF1, target_address=0x10) 
    self.stack = isotp.CanStack(self.bus, address=addr, params=isotp_params, error_handler=self.my_error_handler)
示例#10
0
 def configComm(self):
     if not self.commStatus:
         if self.sensor.get() != 'BEG':
             messagebox.showinfo('Error', 'Device not supported.')
         else:
             try:
                 tp_addr = isotp.Address(
                     isotp.AddressingMode.Normal_29bits,  # noqa: E501
                     txid=0x18DA2AF1,
                     rxid=0x18DAFA2A)
                 bus = Bus(bustype='pcan',
                           channel='PCAN_USBBUS1',
                           bitrate=500000)
                 stack = isotp.CanStack(bus=bus, address=tp_addr)
                 self.conn = PythonIsoTpConnection(stack)
                 self.requestTitleMenu.grid(row=3, column=0, pady=5)
                 self.begRequestMenu.grid(row=4, column=0, pady=5)
                 self.sendBtn.grid(row=5, column=0, pady=5)
                 self.commStatus = True
                 self.commButton.config(text='Disconnect')
                 self.terminalMenu.grid(row=6, column=0)
                 self.termPrint('Info - connected')
                 self.sensorOptions.config(state='disabled')
             except Exception:
                 messagebox.showinfo('Error', 'There is no connection')
                 self.commStatus = False
     else:
         try:
             self.commButton.config(text='Connect')
             self.requestTitleMenu.grid_forget()
             self.begRequestMenu.grid_forget()
             self.terminalMenu.grid_forget()
             self.sendBtn.grid_forget()
             self.commStatus = False
         except Exception:
             messagebox.showinfo('Error', 'Unable to disconnect')
     self.commStatuss.config(text=str(self.commStatus))
示例#11
0
from can.interface import Bus
from udsoncan.connections import PythonIsoTpConnection
from udsoncan.client import Client
import isotp
from udsoncan import Response
import securityAlgo as sec
from time import sleep

tp_addr = isotp.Address(isotp.AddressingMode.Normal_29bits,
                        txid=0x18DA2AF1,
                        rxid=0x18DAFA2A)
bus = Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=500000)
stack = isotp.CanStack(bus=bus, address=tp_addr)
conn = PythonIsoTpConnection(stack)
with Client(conn,
            request_timeout=1,
            config={'exception_on_unexpected_response': False}) as client:
    try:
        conn.send(b'\x10\x03')
        payload = conn.wait_frame(timeout=1)
        response = Response.from_payload(payload)
        print(response)
        conn.send(b'\x27\x63')
        payload = conn.wait_frame(timeout=1)
        response = Response.from_payload(payload)
        print('key: ' + response.data.hex()[2:])
        seed = (response.data.hex()[2:])
        sA = sec.securityAlgo(seed, 'series')
        sleep(.1)
        print('calculated key: ' + (sA.calculatedKey).hex())
        conn.send(b'\x27\x64' + sA.calculatedKey)
from can.interfaces.vector import VectorBus
from udsoncan.connections import PythonIsoTpConnection
from udsoncan.client import Client
import isotp

# Refer to isotp documentation for full details about parameters
isotp_params = {
   'stmin' : 32,                          # Will request the sender to wait 32ms between consecutive frame. 0-127ms or 100-900ns with values from 0xF1-0xF9
   'blocksize' : 8,                       # Request the sender to send 8 consecutives frames before sending a new flow control message
   'wftmax' : 0,                          # Number of wait frame allowed before triggering an error
   'll_data_length' : 8,                  # Link layer (CAN layer) works with 8 byte payload (CAN 2.0)
   'tx_padding' : 0,                      # Will pad all transmitted CAN messages with byte 0x00. None means no padding
   'rx_flowcontrol_timeout' : 1000,        # Triggers a timeout if a flow control is awaited for more than 1000 milliseconds
   'rx_consecutive_frame_timeout' : 1000, # Triggers a timeout if a consecutive frame is awaited for more than 1000 milliseconds
   'squash_stmin_requirement' : False     # When sending, respect the stmin requirement of the receiver. If set to True, go as fast as possible.
}

bus = VectorBus(channel=0, bitrate=9600)                                          # Link Layer (CAN protocol)
tp_addr = isotp.Address(isotp.AddressingMode.Normal_11bits, txid=0x123, rxid=0x79D) # Network layer addressing scheme
stack = isotp.CanStack(bus=bus, address=tp_addr, params=isotp_params)               # Network/Transport layer (IsoTP protocol)
conn = PythonIsoTpConnection(stack)                                                 # interface between Application and Transport layer
with Client(conn, request_timeout=1) as client:                                     # Application layer (UDS protocol)
   client.change_session(1)
   # ...
示例#13
0
import can
import isotp
import udsoncan
from udsoncan.connections import PythonIsoTpConnection
from udsoncan.client import Client
from udsoncan.exceptions import *
from udsoncan.services import *

udsoncan.setup_logging()

bus = can.interface.Bus(bustype="cantact", channel="0", bitrate=500000)
addr = isotp.Address(addressing_mode=isotp.AddressingMode.Normal_11bits,
                     txid=0x123,
                     rxid=0x456)
tp = isotp.CanStack(bus, address=addr)
conn = PythonIsoTpConnection(tp)
client = Client(conn)

conn.open()
client.ecu_reset(ECUReset.ResetType.hardReset)
print("done")
conn.close()
示例#14
0
isotp_params = {
    #'stmin' : 0,                          # Will request the sender to wait 32ms between consecutive frame. 0-127ms or 100-900ns with values from 0xF1-0xF9
    #'blocksize' : 0,                       # Request the sender to send 8 consecutives frames before sending a new flow control message
    #'wftmax' : 0,                          # Number of wait frame allowed before triggering an error
    #'ll_data_length' : 8,                  # Link layer (CAN layer) works with 8 byte payload (CAN 2.0)
    #'ll_data_length' : 64,                  # Link layer (CAN layer) works with 8 byte payload (CAN 2.0)
    #'tx_padding' : 0xCC,                      # Will pad all transmitted CAN messages with byte 0x00. None means no padding
    #'rx_flowcontrol_timeout' : 1000,        # Triggers a timeout if a flow control is awaited for more than 1000 milliseconds
    #'rx_consecutive_frame_timeout' : 1000, # Triggers a timeout if a consecutive frame is awaited for more than 1000 milliseconds
    #'squash_stmin_requirement' : False,     # When sending, respect the stmin requirement of the receiver. If set to True, go as fast as possible.
    #'can_fd' : True,
    #'tx_data_min_length' : 8
}

bus = VectorBus(channel=0, bitrate=500000)
addr = isotp.Address(isotp.AddressingMode.NormalFixed_29bits,
                     source_address=0xF1,
                     target_address=0x10)
stack = isotp.CanStack(bus, address=addr, params=isotp_params)

#stack.send(b'\x01\x02\x03\x04\x05\x06\x07')
stack.send(
    b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10'
)

while stack.transmitting():
    stack.process()
    time.sleep(0.0001)

bus.shutdown()