Friday, September 15, 2017

Software in the loop simulation

When developing software that will interact with electronic hardware, it is important to have abstractions for hardware, i.e. software modules that mimic hardware behavior. Electronic components can have many problems that are not related to logic, e.g. loose components, need to reset from time to time, delays and data loss. With software abstraction, you can test 90% of logic without dealing with hardware complexities. Even better, you can easily automate your tests.

Once you establish that you are 90% correct, you can start testing with hardware to tease out the remaining 10% of bugs (real time issues etc.). The cost of software abstraction is that your design gets a little more complex and you need to write a couple of additional classes and interfaces to simulate the hardware logic. But it is well worth the effort because it decouples you from the hardware, saving you lots of work and frustration.

As an example, I am currently developing a desktop software that will be used to configure an electronic card through the serial port. I wrote a CardSimulator class and implemented the response of the electronic card to inputs from desktop in that class. On startup, my software can be configured to run in simulated or real mode, real mode meaning working with the real card. I have unit tests providing me with confidence that the desktop side of the equation is correct and when there is a problem, we only need to focus on the electronic card side.

No comments: