-
Notifications
You must be signed in to change notification settings - Fork 6
Serial Stream Refactor and Split-Channel Example #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brocci
wants to merge
5
commits into
SvenRosvall:main
Choose a base branch
from
brocci:stream-serial-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
59ca9f5
Use Stream abstraction for serial services
brocci ad582f6
Fix CMake desktop build: add Stream.h mock, remove Serial_T indirection
brocci 7ab0208
Add Serial1 option for the SerialUserInterface to split SerialGC/UI e…
brocci 5309770
Rename VLCB_SerialGC_SerialUI_SoftwareSerial example to VLCB_SerialGC…
brocci fff3c9b
Fix Mockup for Stream. Update copyrights in example.
brocci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #pragma once | ||
|
|
||
| struct ENDL_T; | ||
|
|
||
| class Stream | ||
| { | ||
| public: | ||
| Stream() = default; | ||
| virtual ~Stream() = default; | ||
|
|
||
| virtual void begin(int); | ||
| virtual bool available(); | ||
| virtual char read(); | ||
| virtual void print(const char *); | ||
| virtual void println(const char *); | ||
| virtual void flush(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
examples/VLCB_SerialGC_SerialUI_empty/VLCB_SerialGC_SerialUI_empty.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| // Copyright (C) Bruno Rocci (bruno_rocci@hotmail.com) | ||
| // This file is part of VLCB-Arduino project on https://github.com/SvenRosvall/VLCB-Arduino | ||
| // Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. | ||
| // The full licence can be found at: http://creativecommons.org/licenses/by-nc-sa/4.0 | ||
|
|
||
| /* | ||
| 3rd party libraries needed for compilation: (not for binary-only distributions) | ||
|
|
||
| Streaming -- C++ stream style output, v5, (http://arduiniana.org/libraries/streaming/) | ||
| SoftwareSerial -- Arduino software serial library (not needed when USE_MEGA_SERIAL1 is set) | ||
| */ | ||
|
|
||
| // This example demonstrates split serial usage: | ||
| // | ||
| // - SerialGC uses the default hardware Serial port for GridConnect transport | ||
| // - SerialUserInterface uses SoftwareSerial for user commands and status output | ||
| // - Optionally, hardware Serial1 can be used for the SerialUserInterface on Mega2560 by setting the USE_MEGA_SERIAL1 build flag in platformio.ini | ||
| // | ||
| // This is useful on boards where the USB serial port is already committed to | ||
| // the VLCB/GridConnect transport, but a separate command console is still wanted. | ||
| // | ||
| // Based on VLCB_SerialGC_empty example from Sven Rosvall (MERG 3777) | ||
|
|
||
| // 3rd party libraries | ||
| #include <Streaming.h> | ||
| #ifndef USE_MEGA_SERIAL1 | ||
| #include <SoftwareSerial.h> | ||
| #endif | ||
|
|
||
| // VLCB library header files | ||
| #include <VLCB.h> | ||
| #include <SerialGC.h> | ||
| #include <SerialUserInterface.h> | ||
|
|
||
| // forward function declarations | ||
| void printConfig(); | ||
|
|
||
| // constants | ||
| const byte VER_MAJ = 1; // code major version | ||
| const char VER_MIN = 'a'; // code minor version | ||
| const byte VER_BUILD = 0; // code build number | ||
| const byte MANUFACTURER = MANU_DEV; // for boards in development. | ||
| const byte MODULE_ID = 98; // VLCB module type | ||
|
|
||
| // module name, must be at most 7 characters | ||
| char mname[] = "SPLIT"; | ||
|
|
||
| const byte LED_GRN = 4; // VLCB green Unitialised LED pin | ||
| const byte LED_YLW = 7; // VLCB yellow Normal LED pin | ||
| const byte SWITCH0 = 8; // VLCB push button switch pin | ||
|
|
||
| #ifdef USE_MEGA_SERIAL1 | ||
| // Use hardware Serial1 on pins 18 (TX1) and 19 (RX1) | ||
| #define serialUserPort Serial1 | ||
| #else | ||
| // Use SoftwareSerial on pins 2 (RX) and 3 (TX) | ||
| const byte UI_RX_PIN = 2; | ||
| const byte UI_TX_PIN = 3; | ||
| SoftwareSerial serialUserPort(UI_RX_PIN, UI_TX_PIN); | ||
| #endif | ||
|
|
||
| // module objects | ||
| VLCB::SerialGC serialGC(Serial); // CAN transport object using hardware serial | ||
| VLCB::SerialUserInterface serialUserInterface(serialUserPort); | ||
|
|
||
| // Service objects | ||
| VLCB::LEDUserInterface ledUserInterface(LED_GRN, LED_YLW, SWITCH0); | ||
| VLCB::MinimumNodeServiceWithDiagnostics mnService; | ||
| VLCB::CanService serialCanService(&serialGC); | ||
|
|
||
| // | ||
| /// setup VLCB - runs once at power on from setup() | ||
| // | ||
| void setupVLCB() | ||
| { | ||
| VLCB::checkStartupAction(LED_GRN, LED_YLW, SWITCH0); | ||
|
|
||
| VLCB::setServices({ | ||
| &mnService, &ledUserInterface, &serialUserInterface, &serialCanService}); | ||
|
|
||
| // set module parameters | ||
| VLCB::setVersion(VER_MAJ, VER_MIN, VER_BUILD); | ||
| VLCB::setModuleId(MANUFACTURER, MODULE_ID); | ||
|
|
||
| // set module name | ||
| VLCB::setName(mname); | ||
|
|
||
| // initialise and load configuration | ||
| VLCB::begin(); | ||
|
|
||
| // show code version and copyright notice on the UI console | ||
| serialUserPort << F("> mode = ") << VLCB::Configuration::modeString(VLCB::getCurrentMode()); | ||
| serialUserPort << F(", CANID = ") << VLCB::getCANID(); | ||
| serialUserPort << F(", NN = ") << VLCB::getNodeNum() << endl; | ||
|
|
||
| printConfig(); | ||
| } | ||
|
|
||
| // | ||
| /// setup - runs once at power on | ||
| // | ||
| void setup() | ||
| { | ||
| Serial.begin(115200); | ||
| serialUserPort.begin(9600); | ||
| delay(2000); // Give some time to PIO to open the serial monitor before printing anything | ||
|
|
||
| #ifdef USE_MEGA_SERIAL1 | ||
| serialUserPort << F("> ** VLCB split: SerialGC + Serial1 UI example ** ") << __FILE__ << endl; | ||
| #else | ||
| serialUserPort << F("> ** VLCB split: SerialGC + SoftwareSerial UI example ** ") << __FILE__ << endl; | ||
| #endif | ||
|
|
||
| setupVLCB(); | ||
|
|
||
| serialUserPort << F("> ready") << endl << endl; | ||
| } | ||
|
|
||
| // | ||
| /// loop - runs forever | ||
| // | ||
| void loop() | ||
| { | ||
| // | ||
| /// do VLCB message, switch and LED processing | ||
| // | ||
| VLCB::process(); | ||
|
|
||
| // bottom of loop() | ||
| } | ||
|
|
||
| // | ||
| /// print code version config details and copyright notice | ||
| // | ||
| void printConfig() | ||
| { | ||
| // code version | ||
| serialUserPort << F("> code version = ") << VER_MAJ << VER_MIN << F(" build ") << VER_BUILD << endl; | ||
| serialUserPort << F("> compiled on ") << __DATE__ << F(" at ") << __TIME__ << F(", compiler ver = ") << __cplusplus << endl; | ||
|
|
||
| // copyright | ||
| serialUserPort << F("> Copyright © 2026 Bruno Rocci (MERG 9690)") << endl; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.