Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/testbuildrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
--define sonar.projectKey=Strooom_MuMo-v2-Node-SW \
--define sonar.organization=strooom-1 \
--define sonar.projectKey=strooom_mumo-sw \
--define sonar.organization=strooom \
--define sonar.coverageReportPaths=coverage.xml

- name: Attach Binary to Workflow run
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
![workflow](https://github.com/strooom/MuMo-v2-Node-SW/actions/workflows/testbuildrelease.yml/badge.svg)
[![codecov](https://codecov.io/gh/Strooom/MuMo-v2-Node-SW/graph/badge.svg?token=7KF1NA1ACQ)](https://codecov.io/gh/Strooom/MuMo-v2-Node-SW)
[![License: CC BY-NC-SA 4.0](https://img.shields.io/badge/License-CC_BY--NC--SA_4.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Strooom_MuMo-v2-Node-SW&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Strooom_MuMo-v2-Node-SW)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=strooom_mumo-sw&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=strooom_mumo-sw)

# LoRaWAN development for STM32WLE using PlatformIO and STM32CubeIDE

Expand Down
2 changes: 1 addition & 1 deletion lib/application/maincontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void mainController::showLoRaWanStatus() {
screen::setText(2, tmpString);
snprintf(tmpString, screen::maxConsoleTextLength, "rx1Delay : %u", static_cast<uint8_t>(LoRaWAN::rx1DelayInSeconds));
screen::setText(3, tmpString);
snprintf(tmpString, screen::maxConsoleTextLength, "Margin : %u", static_cast<uint8_t>(LoRaWAN::margin));
snprintf(tmpString, screen::maxConsoleTextLength, "Margin : %u", static_cast<uint8_t>(LoRaWAN::uplinkMargin));
screen::setText(4, tmpString);
snprintf(tmpString, screen::maxConsoleTextLength, "Gateways : %u", static_cast<uint8_t>(LoRaWAN::gatewayCount));
screen::setText(5, tmpString);
Expand Down
4 changes: 2 additions & 2 deletions lib/float/float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <float.hpp>

int32_t integerPart(const float value, const uint32_t decimals) {
return (static_cast<int>(round(value * factorFloat(decimals))) / factorInt(decimals));
return static_cast<int32_t>(roundf(value * factorFloat(decimals))) / static_cast<int32_t>(factorInt(decimals));
}

uint32_t fractionalPart(const float value, const uint32_t decimals) {
return static_cast<int>(round(value * factorFloat(decimals))) - (integerPart(value, decimals) * factorInt(decimals));
return abs(static_cast<int32_t>(roundf(value * factorFloat(decimals))) - (integerPart(value, decimals) * factorInt(decimals)));
}

float factorFloat(const uint32_t decimals) {
Expand Down
3 changes: 0 additions & 3 deletions lib/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ char logging::buffer[bufferLength]{};

void logging::initialize() {
enable(logging::destination::uart1);

enable(logging::source::lorawanData);

enable(logging::source::error);
enable(logging::source::criticalError);
}
Expand Down
23 changes: 14 additions & 9 deletions lib/lorawan/lorawan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <ctime>
#include <realtimeclock.hpp>
#include <lptim.hpp>
#include <battery.hpp>

#ifndef generic
#include "main.h"
Expand Down Expand Up @@ -54,7 +55,7 @@ txRxCycleState LoRaWAN::state{txRxCycleState::idle};
linearBuffer<LoRaWAN::macInOutLength> LoRaWAN::macIn;
linearBuffer<LoRaWAN::macInOutLength> LoRaWAN::macOut;

uint32_t LoRaWAN::margin{0};
uint32_t LoRaWAN::uplinkMargin{0};
uint32_t LoRaWAN::gatewayCount{0};

#pragma endregion
Expand Down Expand Up @@ -896,11 +897,11 @@ void LoRaWAN::removeNonStickyMacStuff() {

void LoRaWAN::processLinkCheckAnswer() {
constexpr uint32_t linkCheckAnswerLength{3}; // commandId, margin, GwCnt
margin = macIn[1]; // margin : [0..254] = value in dB above the demodulation floor -> the higher the better, margin [255] = reserved
uplinkMargin = macIn[1]; // margin : [0..254] = value in dB above the demodulation floor -> the higher the better, margin [255] = reserved
gatewayCount = macIn[2]; // GwCnt : number of gateways that successfully received the last uplink
macIn.consume(linkCheckAnswerLength); // consume all bytes

logging::snprintf(logging::source::lorawanMac, "LinkCheckAnswer : margin = %d, gatewayCount = %d \n", margin, gatewayCount);
logging::snprintf(logging::source::lorawanMac, "LinkCheckAnswer : margin = %d, gatewayCount = %d \n", uplinkMargin, gatewayCount);
}

void LoRaWAN::processLinkAdaptiveDataRateRequest() {
Expand All @@ -911,7 +912,6 @@ void LoRaWAN::processLinkAdaptiveDataRateRequest() {
macIn.consume(linkAdaptiveDataRateRequestLength);
logging::snprintf(logging::source::lorawanMac, "LinkAdaptiveDataRateRequest : 0x%02X, 0x%04X, 0x%02X \n", dataRateTxPower, chMask, redundancy);


constexpr uint32_t linkAdaptiveDataRateAnswerLength{2}; // commandId, status
uint8_t answer[linkAdaptiveDataRateAnswerLength];
answer[0] = static_cast<uint8_t>(macCommand::linkAdaptiveDataRateAnswer);
Expand All @@ -926,7 +926,6 @@ void LoRaWAN::processDutyCycleRequest() {
macIn.consume(dutyCycleRequestLength);
logging::snprintf(logging::source::lorawanMac, "DutyCycleRequest : 0x%02X \n", dutyCycle);


constexpr uint32_t dutyCycleAnswerLength{1};
uint8_t answer[dutyCycleAnswerLength];
answer[0] = static_cast<uint8_t>(macCommand::dutyCycleAnswer);
Expand Down Expand Up @@ -958,8 +957,14 @@ void LoRaWAN::processDeviceStatusRequest() {
constexpr uint32_t deviceStatusAnswerLength{3}; // commandId, batteryLevel, margin
uint8_t answer[deviceStatusAnswerLength];
answer[0] = static_cast<uint8_t>(macCommand::deviceStatusAnswer);
answer[1] = static_cast<uint8_t>(255); // The end-device was not able to measure the battery level
answer[2] = static_cast<uint8_t>(10); // TODO : implement real value here
answer[1] = battery::stateOfChargeLoRaWAN();
answer[2] = static_cast<uint8_t>(10); // TODO : implement real value here

// int8_t snr_db = snr_raw / 4; // SNR in full dB
// if (snr_db < -32) snr_db = -32;
// if (snr_db > 31) snr_db = 31;
// uint8_t margin = ((uint8_t)snr_db) & 0x3F; // zero out bits 7 and 6

macOut.append(answer, deviceStatusAnswerLength);
logging::snprintf(logging::source::lorawanMac, "DeviceStatusAnswer : 0x%02X, 0x%02X \n", answer[1], answer[2]);
}
Expand Down Expand Up @@ -1096,13 +1101,13 @@ void LoRaWAN::sendUplink(uint8_t theFramePort, const uint8_t applicationData[],
}

void LoRaWAN::getReceivedDownlinkMessage() {
// sx126x::getReceivedMessage();
// downlinkMessage.processDownlinkMessage(applicationPayloadReceived);
goTo(txRxCycleState::idle);
}

messageType LoRaWAN::decodeMessage() {
// sx126x::getPacketSnr();
// 1. read the raw message from the radio receiveBuffer

uint8_t response[2];
sx126x::executeGetCommand(sx126x::command::getRxBufferStatus, response, 2);
loRaPayloadLength = response[0];
Expand Down
5 changes: 4 additions & 1 deletion lib/lorawan/lorawan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ class LoRaWAN {
static void dumpRawMessagePayload();
static void dumpTransmitSettings();

static uint32_t margin;
static uint32_t uplinkMargin;
static uint32_t downlinkMargin;
static uint32_t gatewayCount;


static uint32_t currentDataRateIndex;
static deviceAddress DevAddr;
static aesKey applicationKey;
Expand Down
19 changes: 18 additions & 1 deletion lib/sensors/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <sensordevicetype.hpp>
#include <battery.hpp>
#include <chargefromvoltage.hpp>
#include <logging.hpp>
#include <float.hpp>
#include <power.hpp>

#ifndef generic
#include <main.h>
Expand Down Expand Up @@ -94,3 +94,20 @@ float battery::voltageFromRaw(const uint32_t rawADC) {
return mockBatteryVoltage;
#endif
}

uint8_t battery::stateOfChargeLoRaWAN() {
if (power::hasUsbPower()) {
return 0x00; // LoRaWAN® L2 1.0.4 Specification - line 1106 : The end-device is connected to an external power source.
}
if (!channels[stateOfCharge].isActive()) {
return 0xFF; // LoRaWAN® L2 1.0.4 Specification - line 1106 : The end-device was not able to measure the battery level. (because this sensorC channel is not active)
}
int32_t result = static_cast<int32_t>(channels[stateOfCharge].value() * 254.0F);
if (result > 254) {
result = 254;
}
if (result < 1) {
result = 1;
}
return static_cast<uint8_t>(result);
}
1 change: 1 addition & 0 deletions lib/sensors/battery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class battery {
static bool samplingIsReady();
static uint32_t readSample();
static float voltageFromRaw(const uint32_t rawADC);
static uint8_t stateOfChargeLoRaWAN();
#ifndef unitTesting

private:
Expand Down
13 changes: 4 additions & 9 deletions lib/sx126x/sx126x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,12 @@ uint8_t sx126x::getStatus() {
}

float sx126x::getPacketSnr() {
// RssiPkt = (-1 * response[0])/2;
// SnrPkt = response[1] / 4;
// SignalRssiPkt = -response[2]/2;

uint8_t response[3];
sx126x::executeGetCommand(sx126x::command::getPacketStatus, response, 3);

int8_t snr;
std::memcpy(&snr, &response[1], 1);

return (static_cast<float>(snr) / 4.0f);
int8_t snrAsByte;
std::memcpy(&snrAsByte, &response[1], 1);
float result = static_cast<float>(snrAsByte) / 4.0F;
return result;
}

void sx126x::configForTransmit(spreadingFactor theSpreadingFactor, uint32_t frequency, uint8_t* payload, uint32_t payloadLength) {
Expand Down
8 changes: 4 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ test_filter =
;generic/test_applicationevent
;generic/test_graphics
;generic/test_lorawan_deviceaddress
generic/test_framecount
generic/test_lorawan_0_general
;generic/test_framecount
;generic/test_lorawan_0_general
;generic/test_lorawan_1_rawmessage
;generic/test_lorawan_2_crypto
;generic/test_lorawan_3_txrxcycle
;generic/test_lorawan_4_mac
;generic/test_sx126x
;generic/test_float
generic/test_float
;generic/test_aeskey
;generic/test_aesblock
;generic/test_hexascii
Expand All @@ -165,7 +165,7 @@ test_filter =



debug_test = generic/test_lorawan_2_crypto
debug_test = generic/test_float


; #############################################################################
Expand Down
5 changes: 3 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sonar.projectKey=MuMo-v2-Node-SW
sonar.projectName=MuMo-v2-Node-SW
sonar.projectKey=strooom_mumo-sw
sonar.organization=strooom
sonar.projectName=strooom_mumo-sw
sonar.projectVersion=1.0
sonar.sources=src, lib
sonar.tests=test
Expand Down
43 changes: 28 additions & 15 deletions test/generic/test_float/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,39 @@
extern uint8_t mockBME680Registers[256];
extern uint8_t mockTSL2591Registers[256];

void setUp(void) { // before each test
}
void tearDown(void) { // after each test
}
void setUp(void) {}
void tearDown(void) {}


void test_integerPart() {
TEST_ASSERT_EQUAL_INT(10, integerPart(10.4, 0));
TEST_ASSERT_EQUAL_INT(11, integerPart(10.5, 0));
TEST_ASSERT_EQUAL_INT(10, integerPart(10.4, 1));
TEST_ASSERT_EQUAL_INT(10, integerPart(10.5, 1));
TEST_ASSERT_EQUAL_INT(11, integerPart(10.95, 1));
TEST_ASSERT_EQUAL_INT(10, integerPart(10.4F, 0));
TEST_ASSERT_EQUAL_INT(11, integerPart(10.5F, 0));
TEST_ASSERT_EQUAL_INT(10, integerPart(10.4F, 1));
TEST_ASSERT_EQUAL_INT(10, integerPart(10.5F, 1));
TEST_ASSERT_EQUAL_INT(11, integerPart(10.95F, 1));


TEST_ASSERT_EQUAL_INT(-10, integerPart(-10.4F, 0));
TEST_ASSERT_EQUAL_INT(-11, integerPart(-10.5F, 0));
TEST_ASSERT_EQUAL_INT(-10, integerPart(-10.4F, 1));
TEST_ASSERT_EQUAL_INT(-10, integerPart(-10.5F, 1));
TEST_ASSERT_EQUAL_INT(-11, integerPart(-10.95F, 1));
}

void test_fractionalPart() {
TEST_ASSERT_EQUAL_INT(0, fractionalPart(10.49, 0));
TEST_ASSERT_EQUAL_INT(0, fractionalPart(10.51, 0));
TEST_ASSERT_EQUAL_INT(4, fractionalPart(10.44, 1));
TEST_ASSERT_EQUAL_INT(5, fractionalPart(10.45, 1));
TEST_ASSERT_EQUAL_INT(44, fractionalPart(10.44, 2));
TEST_ASSERT_EQUAL_INT(45, fractionalPart(10.45, 2));
TEST_ASSERT_EQUAL_INT(0, fractionalPart(10.49F, 0));
TEST_ASSERT_EQUAL_INT(0, fractionalPart(10.51F, 0));
TEST_ASSERT_EQUAL_INT(4, fractionalPart(10.44F, 1));
TEST_ASSERT_EQUAL_INT(5, fractionalPart(10.45F, 1));
TEST_ASSERT_EQUAL_INT(44, fractionalPart(10.44F, 2));
TEST_ASSERT_EQUAL_INT(45, fractionalPart(10.45F, 2));

TEST_ASSERT_EQUAL_INT(0, fractionalPart(-10.49F, 0));
TEST_ASSERT_EQUAL_INT(0, fractionalPart(-10.51F, 0));
TEST_ASSERT_EQUAL_INT(4, fractionalPart(-10.44F, 1));
TEST_ASSERT_EQUAL_INT(5, fractionalPart(-10.45F, 1));
TEST_ASSERT_EQUAL_INT(44, fractionalPart(-10.44F, 2));
TEST_ASSERT_EQUAL_INT(45, fractionalPart(-10.45F, 2));
}

void test_factorFloat() {
Expand Down
Loading