macformula / racecar

Monorepo for all firmware running on our custom ECU's
8 stars 1 forks source link

Use polymorphism for sil registrations #137

Open BlakeFreer opened 3 months ago

BlakeFreer commented 3 months ago

SIL Polymorphism

Description

The implementation of SilClient in firmware/validation/sil/sil_client.cc is very repetitive. The Register___ and Read___ and Set___ methods are all almost identical with a few small differences.

This task is to abstract out the commonalities.

Tasks

  1. Abstract out common logic. Look at the functions listed above. Move any repeated code into a new private function. For example, you might have RegisterDigitalOutput and RegisterAnalogInput call the same private function RegisterIO to handle the common logic.

    IMPORTANT the public interface of SilClient must not change! We should not need to rewrite the projects which use SilClient.

  2. Make PR with your changes.

We may take this effort further after you complete this task. I could see us defining peripheral classes which all implement Register() and Read() or Set(), allowing us to use polymorphism instead of defining multiple handler functions.