Assignments

Create a unique output of your EOBD VIN reader

  • Let your function create a unique output (e.g. add a message for the caller), such that the output differentiates from other EOBD scripts.
  • Use this line:
    self.openobd_session.set_context_variable('VIN', vin, ContextVariableType.GLOBAL)
    

Call the EOBD VIN reader from at least one other participant

  • Adjust your composition in such a way that it calls at least one EOBD VIN reader from another participant.
  • In order to do so, you need to create a definitions file remote.py which contains the id of the remote functions that you want to call:
    from openobd import *
    
    
    class FunctionOfKlaas(OpenOBDFunction):
        id = ""
    
    class FunctionOfHenk(OpenOBDFunction):
        id = ""
    
  • In your composition you can now refer to those functions as follows:
    from openobd import *
    
    from myfunctions.remote import FunctionOfHenk, FunctionOfKlaas
    
    
    class MyComposition1(OpenOBDComposition):
    
        id = ""
        signature = ""
        version = "v0.1"
        name = "Gerhards Composition"
        description = "Gerhards Composition"
    
        def run(self):
            self.run_function(FunctionOfKlaas)
            self.run_function(FunctionOfHenk)
    

Argument passing

It is possible in openOBD to pass arguments to other functions that can only be accessed by the intended function. We are still facing problems in correct functioning of these calls. In these assignments we use another construction to pass values between functions. (Global context variables)

Reading out result of another script

  • It is possible to read out the output of another script using the following construction:
    result = self.openobd_session.get_context_variable('VIN', ContextVariableType.GLOBAL)
    logging.info(result.value)
    
  • Create a new script in your composition that reads out the VIN from the EOBD script and outputs it to your shell

The Opel Corsa D speedometer

We will have a ticket available that has access to the Opel Corsa D test setup. We will share the ticket id, this allows you to experiment with the Instrument Panel Cluster.

Feel free to create a fun feature for the speedometer of the Opel Corsa D.

E.g. add user input, randomize the speedometer, accept setting the speed through a context variable, etc.

Again, make sure that you use a unique name ;-)

This script can be ended by ctrl+c. If you want to offer it through function hosting, make sure it ends within reasonable time. Such that others can also run their experiments on the Corsa test setup.

from openobd import *
import logging


class Speedometer(OpenOBDFunction):

    id = ""
    signature = ""
    version = "v0.1"
    name = "Speedometer"
    description = "Speedometer"

    def run(self):
        # Set bus configuration
        self.set_bus_configuration([
            (BusConfiguration(bus_name="bus_1",
                              can_bus=CanBus(pin_plus=1, pin_min=0, can_protocol=CanProtocol.CAN_PROTOCOL_ISOTP,
                                             can_bit_rate=CanBitRate.CAN_BIT_RATE_33_3,
                                             transceiver=TransceiverSpeed.TRANSCEIVER_SPEED_LOW)))
        ])

        # Define the instrument panel cluster, which is present on bus pin 1, with CAN IDs 255-655, and turn on frame padding
        channel = IsotpChannel(bus_name="bus_1", request_id=0x255, response_id=0x655, padding=PADDING_ENABLED)

        # Start a stream to communicate with the engine
        with Socket(IsotpSocket(self.openobd_session, channel)) as ipc:

            logging.info("Driving speedometer...")
            try:
                ipc.request("20")
                ipc.request("1A9A")
                speed = 0

                while True:
                    speed = 0 if speed == 220 else speed + 1
                    self.set_speedometer(ipc, speed)
                    time.sleep(1)

            except NoResponseException as e:
                logging.warning(f"No response to our request: {e}")

    @staticmethod
    def set_speedometer(module, speed):
        speed = 0 if speed < 0 else speed
        speed = 220 if speed > 220 else speed
        needle = "%0.2x" % (speed)
        logging.info(f"Speedometer: {speed}km/h")
        try:
            module.request(f"AE0801{needle}")
            # module.request(f"AE020A{needle}")
        except RequestOutOfRangeException as e:
            logging.warning(f"Out of range: {e}")