diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 0cbe379..542fe65 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -1,56 +1,22 @@ -name: push pull checks +name: Integreation Tests on: [push, pull_request] jobs: - #check: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v2 - # - name: Cache pip - # uses: actions/cache@v2 - # with: - # path: ~/.cache/pip - # key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - # restore-keys: ${{ runner.os }}-pip- - # - name: Cache PlatformIO - # uses: actions/cache@v2 - # with: - # path: ~/.platformio - # key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - # - name: Set up Python - # uses: actions/setup-python@v2 - # - name: Install PlatformIO - # run: | - # python -m pip install --upgrade pip - # pip install --upgrade platformio - # - name: Run PlatformIO Check - # run: platformio check --fail-on-defect low --fail-on-defect medium --fail-on-defect high - build: + name: Compile Firmware runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Cache pip - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: ${{ runner.os }}-pip- - - name: Cache PlatformIO - uses: actions/cache@v2 - with: - path: ~/.platformio - key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + - name: Checkout code + uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 - name: Install PlatformIO - run: | - python -m pip install --upgrade pip - pip install --upgrade platformio + run: python -m pip install --upgrade pip platformio - name: Run PlatformIO CI run: platformio run - - uses: actions/upload-artifact@v2 + - name: Upload artifacts + uses: actions/upload-artifact@v2 with: name: firmware path: .pio/build/lora_board/firmware.bin @@ -72,10 +38,29 @@ jobs: - 'lib/System' #- 'lib/TimeLib' steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 - name: Run clang-format style check for C/C++ programs. uses: jidicula/clang-format-action@v3.2.0 with: clang-format-version: '11' check-path: ${{ matrix.path }} + cppcheck: + name: Run cppcheck + runs-on: ubuntu-latest + env: + CPPCHECK_ARGS: --enable=all --std=c++14 --inline-suppr -I lib/BoardFinder -I lib/ConfigurationManagement -I lib/Display -I lib/LoRa -I lib/LoRa_APRS -I lib/NTPClient -I lib/PowerManagement -I lib/System -I lib/TimeLib -i lib/Display -i lib/LoRa -i lib/NTPClient -i lib/TimeLib src lib + steps: + - name: checkout code + uses: actions/checkout@v2 + - run: docker pull facthunder/cppcheck:latest + - name: Run cppcheck and print result + run: docker run --rm -v ${PWD}:/src facthunder/cppcheck:latest /bin/bash -c "cppcheck $CPPCHECK_ARGS" + - name: Run cppcheck and create html + run: docker run --rm -v ${PWD}:/src facthunder/cppcheck:latest /bin/bash -c "cppcheck --xml $CPPCHECK_ARGS 2> report.xml && cppcheck-htmlreport --file=report.xml --report-dir=output" + - name: Upload report + uses: actions/upload-artifact@v1 + with: + name: Cppcheck Report + path: output diff --git a/.gitignore b/.gitignore index 89cc49c..9f19284 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +report.xml +output diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index fe70d13..ec9de89 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -15,6 +15,7 @@ #include "TaskModem.h" #include "TaskNTP.h" #include "TaskOTA.h" +#include "TaskRouter.h" #include "TaskWifi.h" #include "project_configuration.h" @@ -25,6 +26,9 @@ String create_long_aprs(double lng); std::shared_ptr LoRaSystem; +TaskQueue> toAprsIs; +TaskQueue> fromModem; + // cppcheck-suppress unusedFunction void setup() { Serial.begin(115200); @@ -78,7 +82,7 @@ void setup() { LoRaSystem = std::shared_ptr(new System(boardConfig, userConfig)); LoRaSystem->getTaskManager().addTask(std::shared_ptr(new DisplayTask())); - LoRaSystem->getTaskManager().addTask(std::shared_ptr(new ModemTask())); + LoRaSystem->getTaskManager().addTask(std::shared_ptr(new ModemTask(fromModem))); if (boardConfig->Type == eETH_BOARD) { LoRaSystem->getTaskManager().addAlwaysRunTask(std::shared_ptr(new EthTask())); } else { @@ -89,7 +93,8 @@ void setup() { if (userConfig->ftp.active) { LoRaSystem->getTaskManager().addTask(std::shared_ptr(new FTPTask())); } - LoRaSystem->getTaskManager().addTask(std::shared_ptr(new AprsIsTask())); + LoRaSystem->getTaskManager().addTask(std::shared_ptr(new AprsIsTask(toAprsIs))); + LoRaSystem->getTaskManager().addTask(std::shared_ptr(new RouterTask(fromModem, toAprsIs))); LoRaSystem->getTaskManager().setup(LoRaSystem); diff --git a/src/Task.h b/src/Task.h index 4c881a4..b9a1f12 100644 --- a/src/Task.h +++ b/src/Task.h @@ -6,10 +6,11 @@ enum TaskNames TaskAprsIs = 1, TaskEth, TaskFtp, - TaskLora, + TaskModem, TaskNtp, TaskOta, TaskWifi, + TaskRouter, TaskSize, }; @@ -18,9 +19,10 @@ enum TaskNames #define TASK_APRS_IS "AprsIsTask" #define TASK_ETH "EthTask" #define TASK_FTP "FTPTask" -#define TASK_LORA "LoraTask" +#define TASK_MODEM "ModemTask" #define TASK_NTP "NTPTask" #define TASK_OTA "OTATask" #define TASK_WIFI "WifiTask" +#define TASK_ROUTER "RouterTask" #endif diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index d060043..b03c2e0 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -5,26 +5,15 @@ #include "TaskAprsIs.h" #include "project_configuration.h" -String create_lat_aprs(double lat); -String create_long_aprs(double lng); - -AprsIsTask::AprsIsTask() : Task(TASK_APRS_IS, TaskAprsIs) { +AprsIsTask::AprsIsTask(TaskQueue> &toAprsIs) : Task(TASK_APRS_IS, TaskAprsIs), _toAprsIs(toAprsIs) { } AprsIsTask::~AprsIsTask() { } bool AprsIsTask::setup(std::shared_ptr system) { - _beacon_timer.setTimeout(system->getUserConfig()->beacon.timeout * 60 * 1000); _aprs_is = std::shared_ptr(new APRS_IS(system->getUserConfig()->callsign, system->getUserConfig()->aprs_is.passcode, "ESP32-APRS-IS", "0.2")); - _beaconMsg = std::shared_ptr(new APRSMessage()); - _beaconMsg->setSource(system->getUserConfig()->callsign); - _beaconMsg->setDestination("APLG01"); - String lat = create_lat_aprs(system->getUserConfig()->beacon.positionLatitude); - String lng = create_long_aprs(system->getUserConfig()->beacon.positionLongitude); - _beaconMsg->getBody()->setData(String("=") + lat + "L" + lng + "&" + system->getUserConfig()->beacon.message); - return true; } @@ -45,21 +34,11 @@ bool AprsIsTask::loop(std::shared_ptr system) { _aprs_is->getAPRSMessage(); - if (!inputQueue.empty()) { - std::shared_ptr msg = inputQueue.getElement(); + if (!_toAprsIs.empty()) { + std::shared_ptr msg = _toAprsIs.getElement(); _aprs_is->sendMessage(msg); } - if (_beacon_timer.check()) { - logPrintD("[" + timeString() + "] "); - logPrintlnD(_beaconMsg->encode()); - _aprs_is->sendMessage(_beaconMsg); - system->getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); - _beacon_timer.start(); - } - time_t diff = _beacon_timer.getTriggerTimeInSec(); - _stateInfo = "beacon " + String(diff / 60) + ":" + String(diff % 60); - _state = Okay; return true; } diff --git a/src/TaskAprsIs.h b/src/TaskAprsIs.h index 67b1d31..69fd66d 100644 --- a/src/TaskAprsIs.h +++ b/src/TaskAprsIs.h @@ -8,18 +8,16 @@ class AprsIsTask : public Task { public: - AprsIsTask(); + explicit AprsIsTask(TaskQueue> &toAprsIs); virtual ~AprsIsTask(); virtual bool setup(std::shared_ptr system) override; virtual bool loop(std::shared_ptr system) override; - TaskQueue> inputQueue; - private: - std::shared_ptr _aprs_is; - std::shared_ptr _beaconMsg; - Timer _beacon_timer; + std::shared_ptr _aprs_is; + + TaskQueue> &_toAprsIs; bool connect(std::shared_ptr system); }; diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index 6f9a8ba..a7590a2 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -6,7 +6,7 @@ #include "TaskModem.h" #include "project_configuration.h" -ModemTask::ModemTask() : Task(TASK_LORA, TaskLora) { +ModemTask::ModemTask(TaskQueue> &fromModem) : Task(TASK_MODEM, TaskModem), _fromModem(fromModem) { } ModemTask::~ModemTask() { @@ -55,15 +55,9 @@ bool ModemTask::loop(std::shared_ptr system) { } msg->setPath(path + "qAR," + system->getUserConfig()->callsign); - std::shared_ptr is_thread = std::static_pointer_cast(system->getTaskManager().getTask(TASK_APRS_IS)); - is_thread->inputQueue.addElement(msg); + _fromModem.addElement(msg); system->getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString()))); } - if (!inputQueue.empty()) { - std::shared_ptr msg = inputQueue.getElement(); - _lora_aprs->sendMessage(msg); - } - return true; } diff --git a/src/TaskModem.h b/src/TaskModem.h index 84e125c..7d324fd 100644 --- a/src/TaskModem.h +++ b/src/TaskModem.h @@ -7,16 +7,15 @@ class ModemTask : public Task { public: - ModemTask(); + explicit ModemTask(TaskQueue> &fromModem); virtual ~ModemTask(); virtual bool setup(std::shared_ptr system) override; virtual bool loop(std::shared_ptr system) override; - TaskQueue> inputQueue; - private: - std::shared_ptr _lora_aprs; + std::shared_ptr _lora_aprs; + TaskQueue> &_fromModem; }; #endif diff --git a/src/TaskRouter.cpp b/src/TaskRouter.cpp new file mode 100644 index 0000000..1bcf7b8 --- /dev/null +++ b/src/TaskRouter.cpp @@ -0,0 +1,46 @@ +#include + +#include "Task.h" +#include "TaskRouter.h" +#include "project_configuration.h" + +String create_lat_aprs(double lat); +String create_long_aprs(double lng); + +RouterTask::RouterTask(TaskQueue> &fromModem, TaskQueue> &toAprsIs) : Task(TASK_ROUTER, TaskRouter), _fromModem(fromModem), _toAprsIs(toAprsIs) { +} + +RouterTask::~RouterTask() { +} + +bool RouterTask::setup(std::shared_ptr system) { + // setup beacon + _beacon_timer.setTimeout(system->getUserConfig()->beacon.timeout * 60 * 1000); + _beaconMsg = std::shared_ptr(new APRSMessage()); + _beaconMsg->setSource(system->getUserConfig()->callsign); + _beaconMsg->setDestination("APLG01"); + String lat = create_lat_aprs(system->getUserConfig()->beacon.positionLatitude); + String lng = create_long_aprs(system->getUserConfig()->beacon.positionLongitude); + _beaconMsg->getBody()->setData(String("=") + lat + "L" + lng + "&" + system->getUserConfig()->beacon.message); + + return true; +} + +bool RouterTask::loop(std::shared_ptr system) { + // do routing + if (!_fromModem.empty()) { + _toAprsIs.addElement(_fromModem.getElement()); + } + + // check for beacon + if (_beacon_timer.check()) { + logPrintD("[" + timeString() + "] "); + logPrintlnD(_beaconMsg->encode()); + _toAprsIs.addElement(_beaconMsg); + system->getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); + _beacon_timer.start(); + } + time_t diff = _beacon_timer.getTriggerTimeInSec(); + _stateInfo = "beacon " + String(diff / 60) + ":" + String(diff % 60); + return true; +} diff --git a/src/TaskRouter.h b/src/TaskRouter.h new file mode 100644 index 0000000..0ed8092 --- /dev/null +++ b/src/TaskRouter.h @@ -0,0 +1,23 @@ +#ifndef TASK_ROUTER_H_ +#define TASK_ROUTER_H_ + +#include +#include + +class RouterTask : public Task { +public: + RouterTask(TaskQueue> &fromModem, TaskQueue> &toAprsIs); + virtual ~RouterTask(); + + virtual bool setup(std::shared_ptr system) override; + virtual bool loop(std::shared_ptr system) override; + +private: + TaskQueue> &_fromModem; + TaskQueue> &_toAprsIs; + + std::shared_ptr _beaconMsg; + Timer _beacon_timer; +}; + +#endif