Example #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.')
Example #2
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")
Example #3
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))
Example #4
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)
   # ...
Example #6
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()