as a developer…

Developer How-To’s for PILOT Drive

create a new service

Making a new service has some basic prerequisites to allow for modularity:

  1. It has it’s own module within the backend/pilot-drive/services/ directory (requiring an __init__.py).

  2. Within the module, it has a “main” file, with the same name as the module directory.
    • ie. if the service is named “bluetooth” located at backend/pilot-drive/services/bluetooth/, it has a bluetooth.py main file

  3. The service name needs to be added to the EventType Enum in backend/pilot-drive/master_event_queue.py

  4. In the main file, the service inherents the AbstractService class, located at backend/pilot-drive/services/abstract_service.py.

  5. With the AbstractService as a parent class, the service is required to accept and implement the follow parameters:
    • master_event_queue - a MasterEventQueue instance to push new events to

    • service_type - the EventType enum value created in step #3, used to identify the service when it pushes to Queue

    • logger - a MasterLogger instance to handle logging events

  6. The service needs to contain a main method, that will run as a process upon PILOT Drive’s start.
    • The service can either utilize a loop to run until SIGINT, or it can terminate after some work on startup.

  7. Each service also needs a refresh method, which runs on the UI’s initial connection, along with refreshes.
    • This might not last long, and most services do not have any logic contained in the refresh. Doesn’t work well with multiprocessing.

  8. The PilotDrive located at backend/pilot-drive/pd_manager.py manager initializes the service
    • This should happen in the __init__ method, using the service_factory method.

    • (Optional) Add a callback for commands sent from the UI by adding a method to PilotManager.service_msg_handlers

  9. Get Creative!
    • This is where the fun happens! Build your services’ logic, and make sure it can be leveraged by the frontend.

NOTE: Do not use the Python logging module in services, only the provided PILOT Drive Logger!

run an OBD/ELM327 emmulator

It’s pretty inconvenient as a developer to walk out to your car every time you want to test a feature. Thankfully, ELM327-emulator makes this easy!

  1. Confirm ELM327-emulator is installed:

    python3.11 -m pip install ELM327-emulator
    
  2. Run the ELM327 emulator:

    python3 -m elm
    
  3. Note the port provided and configure PILOT Drive with specified port

  4. Restart PILOT Drive

  5. You should now see emulated vehicle data under the vehicle tab.