Skip to content

[comunication] Traits and classes to mask which communication is used

Since the project, from a tini tiny program has increasing complexity, a refactoring of the communication input and output should be considered.

As for now the possible communications (or future ones) includes

  • Serial UART communication
  • Test dummy communication (no serial port)
  • PTY serial port, using a PTS pseudo-terminal /dev/pts file
  • Ethernet (incoming)

A possible improvement could be to create a class and some traits to have a "transparent" communication, which is setup at initialization and then for the main loop it is transparent if a /dev/ttyUSBx, /dev/pts serial ports or rather a dummy loopback or UDP Ethernet communication is used.

The needed traits would include the read, write methods and maybe all should be masked by some Ethernet, Serial, Dummy classes implementing such traits.

NOTE: The feasibility should be studied since serial-port object might not be copyable from what I have seen and that could be an issue depending on the implementation...