Page 1 of 1

Terminal refactoring

Posted: Mon Feb 08, 2021 9:59 am
by johu
if you check out stm32-sine or libopeninv you will find quite a few changes.

I have refactored the terminal to be an object. It is simply instantiated by writing

Code: Select all

Terminal t(USART3, commandList);
A third optional parameter can be set true, then remapped pins are used (but you have to do the remapping yourself!).

All the code from usart_setup() in hwinit.cpp has now gone into terminal.cpp. All commands are now passed a Terminal object which in turn can be passed to fprintf to output something on a specific terminal should there be multiple. Might use that on the Tesla charger to have both the USB and the Wifi terminal.
If there is only one terminal, printf just prints to that. More specifically it prints to the terminal last instantiated.

Moreover the "fastuart" command is now built into the terminal and so is the new "enableuart" command. The latter will enable or disable the USART TX pin depending on nodeid. That will be used to share one ESP8266 module between multiple STM32 processors.

What that means: your project can have a parameter for nodeid and pass that to the terminal. t.SetNodeId(). So if you have nodes 1, 2, 3 and type

Code: Select all

enableuart 2
Nodes 1 and 3 will disable all output and custom command reception and node 2 will enable it.
A disabled node will still listen for the "enableuart" command, obviously, but also to the "fastuart" command so that baudrates are kept equal.

Lastly, the Run() function is now non-blocking, i.e. in your main() you will need and endless loop that calls Run(). That is in case you need to serve more than one terminal.

Will do some testing of this on Damiens Dual Motor Prius board.

Re: Terminal refactoring

Posted: Mon Feb 08, 2021 1:05 pm
by johu
Multi-terminaling confirmed, can now communicate with the Tesla charger via USB and Wifi simultaneously :)

Re: Terminal refactoring

Posted: Mon Feb 08, 2021 2:04 pm
by johu
And this also works :)

Re: Terminal refactoring

Posted: Mon Feb 08, 2021 5:50 pm
by mdrobnak
Nice!
My OO theory has gotten to a much better level of understanding in working with this stuff vs the templating stuff they harped on about in school. I still think that at times OO (Object Oriented) programming is a bit overkill, but then when you're dealing with multiple instances of the same thing, it totally makes sense.

-Matt

Re: Terminal refactoring

Posted: Mon Feb 08, 2021 6:17 pm
by johu
Yes I introduced it kindof gently. stm32-sine started out in pure C. Then I just used static classes (well classes with only static functions) to have a bit nicer syntax. And then I found it made sense to make some classes actually instantiateable.

Always wanted to split up inc_encoder.cpp in separate classes like Resolver, Quadrature etc. and have them inherit from a common base class.

Anyway, nice to hear you learned something :)