Terminal refactoring

Post Reply
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Terminal refactoring

Post 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.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Terminal refactoring

Post by johu »

Multi-terminaling confirmed, can now communicate with the Tesla charger via USB and Wifi simultaneously :)
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Terminal refactoring

Post by johu »

And this also works :)
Attachments
IMG_20210208_150259.jpg
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
mdrobnak
Posts: 692
Joined: Thu Mar 05, 2020 5:08 pm
Location: Colorado, United States
Has thanked: 1 time
Been thanked: 5 times

Re: Terminal refactoring

Post 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
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Terminal refactoring

Post 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 :)
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Post Reply