Skip to content

Commit 4d91261

Browse files
committed
refactoring
getting rid of a few default methods to avoid confusion
1 parent c1ee107 commit 4d91261

9 files changed

Lines changed: 96 additions & 79 deletions

File tree

‎lib/application/maincontroller.cpp‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ void mainController::showPrompt() {
590590
}
591591

592592
void mainController::showHelp() {
593-
cli::sendResponse("<enter> :show build info and license\n");
593+
cli::sendResponse("<enter> : show build info and license\n");
594594
cli::sendResponse("? : show help\n");
595595
cli::sendResponse("gds : show device status\n");
596596
cli::sendResponse("gms : show recorded measurements status\n");
@@ -941,4 +941,65 @@ void mainController::showMeasurementsCsv() {
941941
nmbrOfGroups++;
942942
offset += measurementGroup::lengthInBytes(tmpGroup.getNumberOfMeasurements());
943943
}
944+
}
945+
946+
void mainController::setDisplay(const uint8_t* payload, const uint32_t payloadLength) {
947+
if (payloadLength != 3) {
948+
return;
949+
}
950+
uint32_t tmpLineIndex = payload[0];
951+
if (tmpLineIndex >= screen::nmbrOfMeasurementTextLines) {
952+
return;
953+
}
954+
uint32_t tmpDeviceIndex = payload[1];
955+
uint32_t tmpChannelIndex = payload[2];
956+
if (!sensorDeviceCollection::isValid(tmpDeviceIndex, tmpChannelIndex)) {
957+
return;
958+
}
959+
uint8_t tmpDeviceAndChannel = sensorChannel::compressDeviceAndChannelIndex(static_cast<uint8_t>(tmpDeviceIndex), static_cast<uint8_t>(tmpChannelIndex));
960+
settingsCollection::save(tmpDeviceAndChannel, settingsCollection::settingIndex::displaySettings, tmpLineIndex);
961+
displayDeviceIndex[tmpLineIndex] = tmpDeviceIndex;
962+
displayChannelIndex[tmpLineIndex] = tmpChannelIndex;
963+
// showMain();
964+
}
965+
966+
void mainController::setSensor(const uint8_t* payload, const uint32_t payloadLength) {
967+
if (payloadLength != 4) {
968+
return;
969+
}
970+
uint32_t tmpDeviceIndex = payload[0];
971+
uint32_t tmpChannelIndex = payload[1];
972+
if (!sensorDeviceCollection::isValid(tmpDeviceIndex, tmpChannelIndex)) {
973+
return;
974+
}
975+
uint32_t tmpOversamplingIndex = payload[2];
976+
;
977+
uint32_t tmpPrescalerIndex = payload[3];
978+
;
979+
if (tmpPrescalerIndex > sensorChannel::maxPrescalerIndex) {
980+
tmpPrescalerIndex = sensorChannel::maxPrescalerIndex;
981+
}
982+
if (tmpOversamplingIndex > sensorChannel::maxOversamplingIndex) {
983+
tmpOversamplingIndex = sensorChannel::maxOversamplingIndex;
984+
}
985+
if (tmpOversamplingIndex > tmpPrescalerIndex) {
986+
tmpOversamplingIndex = tmpPrescalerIndex;
987+
}
988+
uint8_t tmpCombined = sensorChannel::compressOversamplingAndPrescalerIndex(tmpOversamplingIndex, tmpPrescalerIndex);
989+
uint8_t tmpDeviceAndChannel = sensorChannel::compressDeviceAndChannelIndex(static_cast<uint8_t>(tmpDeviceIndex), static_cast<uint8_t>(tmpChannelIndex));
990+
settingsCollection::save(tmpCombined, settingsCollection::settingIndex::sensorSettings, tmpDeviceAndChannel);
991+
sensorDeviceCollection::channel(tmpDeviceIndex, tmpChannelIndex).setIndex(tmpOversamplingIndex, tmpPrescalerIndex);
992+
}
993+
994+
void mainController::handleDownLink(const uint8_t port, const uint8_t* payload, const uint32_t payloadLength) {
995+
switch (port) {
996+
case 1:
997+
setDisplay(payload, payloadLength);
998+
break;
999+
case 2:
1000+
setSensor(payload, payloadLength);
1001+
break;
1002+
default:
1003+
break;
1004+
}
9441005
}

‎lib/application/maincontroller.hpp‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class mainController {
3737

3838
static constexpr uint32_t minNmbrAnswers{2};
3939
static constexpr uint32_t maxNmbrRequests{12};
40-
41-
#ifndef unitTesting
42-
43-
// private:
44-
#endif
40+
41+
#ifndef unitTesting
42+
43+
// private:
44+
#endif
4545
static char name[maxNameLength + 1];
4646
static uint32_t displayDeviceIndex[screen::nmbrOfMeasurementTextLines];
4747
static uint32_t displayChannelIndex[screen::nmbrOfMeasurementTextLines];
@@ -80,4 +80,8 @@ class mainController {
8080
static void setRadioType(const cliCommand& aCommand);
8181
static void setDisplay(const cliCommand& aCommand);
8282
static void setSensor(const cliCommand& aCommand);
83+
84+
static void setSensor(const uint8_t* payload, const uint32_t payloadLength);
85+
static void setDisplay(const uint8_t* payload, const uint32_t payloadLength);
86+
static void handleDownLink(const uint8_t port, const uint8_t* payload, const uint32_t payloadLength);
8387
};

‎lib/lorawan/deviceaddress.hpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
class deviceAddress {
1212
public:
13+
deviceAddress() = default;
14+
deviceAddress(const deviceAddress&) = delete;
15+
deviceAddress& operator=(const deviceAddress&) = delete;
16+
deviceAddress(deviceAddress&&) = delete;
17+
deviceAddress& operator=(deviceAddress&&) = delete;
18+
1319
static constexpr uint32_t lengthInBytes{4};
1420
static constexpr uint32_t lengthAsHexAscii{8};
1521

‎lib/lorawan/framecount.hpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
class frameCount {
1111
public:
12+
frameCount() = default;
13+
frameCount(const frameCount&) = delete;
14+
frameCount& operator=(const frameCount&) = delete;
15+
frameCount& operator=(frameCount&&) = delete;
16+
1217
static constexpr uint32_t lengthInBytes{4};
1318
static constexpr uint32_t lengthInWords{1};
1419
void guessFromUint16(uint16_t frameCount16Lsb);

‎lib/lorawan/lorawan.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ messageType LoRaWAN::decodeMessage() {
11131113
// 2. Extract & guess the downLinkFrameCount, as we need this to check the MIC
11141114
uint16_t receivedDownlinkFramecount = receivedFramecount();
11151115
frameCount guessedDownlinkFramecount;
1116-
guessedDownlinkFramecount = downlinkFrameCount;
1116+
guessedDownlinkFramecount.setFromWord(downlinkFrameCount.getAsWord());
11171117
guessedDownlinkFramecount.guessFromUint16(receivedDownlinkFramecount);
11181118
logging::snprintf(logging::source::lorawanMac, "receivedFramecount = %u, lastFramecount = %u, guessedFramecount = %u\n", receivedDownlinkFramecount, downlinkFrameCount.getAsWord(), guessedDownlinkFramecount.getAsWord());
11191119

@@ -1141,13 +1141,13 @@ messageType LoRaWAN::decodeMessage() {
11411141
}
11421142

11431143
// 5. check if the frameCount is valid
1144-
if (!isValidDownlinkFrameCount(guessedDownlinkFramecount)) {
1144+
if (!isValidDownlinkFrameCount(guessedDownlinkFramecount.getAsWord())) {
11451145
logging::snprintf(logging::source::error, "Error : invalid downlinkFrameCount : received %u, current %u\n", guessedDownlinkFramecount.getAsWord(), downlinkFrameCount.getAsWord());
11461146
return messageType::invalid;
11471147
}
11481148

11491149
// 6. Seems a valid message, so update the downlinkFrameCount to what we've received (not just incrementing it, as there could be gaps in the sequence due to lost packets)
1150-
downlinkFrameCount = guessedDownlinkFramecount;
1150+
downlinkFrameCount.setFromWord(guessedDownlinkFramecount.getAsWord());
11511151
settingsCollection::save(downlinkFrameCount.getAsWord(), settingsCollection::settingIndex::downlinkFrameCounter);
11521152

11531153
// 6.5 If we had sticky macOut stuff, we can clear that now, as we did receive a valid downlink
@@ -1195,11 +1195,11 @@ uint32_t LoRaWAN::getReceiveTimeout(spreadingFactor aSpreadingFactor) {
11951195
}
11961196
}
11971197

1198-
bool LoRaWAN::isValidDownlinkFrameCount(frameCount testFrameCount) {
1198+
bool LoRaWAN::isValidDownlinkFrameCount(uint32_t testValue) {
11991199
if (downlinkFrameCount.getAsWord() == 0) {
12001200
return true; // no downlink received yet, so any frameCount is valid
12011201
} else {
1202-
return (testFrameCount.getAsWord() > downlinkFrameCount.getAsWord());
1202+
return (testValue > downlinkFrameCount.getAsWord());
12031203
}
12041204
}
12051205

‎lib/lorawan/lorawan.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class LoRaWAN {
186186
static uint16_t receivedFramecount();
187187
static uint32_t receivedDeviceAddress();
188188
static uint32_t receivedMic();
189-
static bool isValidDownlinkFrameCount(frameCount testFrameCount);
189+
static bool isValidDownlinkFrameCount(uint32_t testFrameCount);
190190
static messageType decodeMessage();
191191

192192
// #############################################################

‎platformio.ini‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ test_filter =
120120
;generic/test_logging
121121
;generic/test_gpio
122122
;generic/test_power
123-
generic/test_display
123+
;generic/test_display
124124
;generic/test_battery
125125
;generic/test_bme68x
126126
;generic/test_tsl2591
@@ -131,8 +131,8 @@ test_filter =
131131
;generic/test_applicationevent
132132
;generic/test_graphics
133133
;generic/test_lorawan_deviceaddress
134-
;generic/test_framecount
135-
;generic/test_lorawan_0_general
134+
generic/test_framecount
135+
generic/test_lorawan_0_general
136136
;generic/test_lorawan_1_rawmessage
137137
;generic/test_lorawan_2_crypto
138138
;generic/test_lorawan_3_txrxcycle

‎test/generic/test_framecount/test.cpp‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@ void test_initialize() {
2121
}
2222
}
2323

24-
void test_operatorAssign() {
25-
frameCount testFrameCount1;
26-
frameCount testFrameCount2;
27-
TEST_ASSERT_EQUAL(0, testFrameCount1.getAsWord());
28-
TEST_ASSERT_EQUAL(0, testFrameCount2.getAsWord());
29-
testFrameCount1.setFromWord(0x12345678);
30-
TEST_ASSERT_EQUAL(0x12345678, testFrameCount1.getAsWord());
31-
uint8_t expectedBytes1[frameCount::lengthInBytes]{0x78, 0x56, 0x34, 0x12};
32-
for (uint32_t index = 0; index < frameCount::lengthInBytes; index++) {
33-
TEST_ASSERT_EQUAL(expectedBytes1[index], testFrameCount1.getAsByte(index));
34-
}
35-
testFrameCount2 = testFrameCount1;
36-
TEST_ASSERT_EQUAL(0x12345678, testFrameCount2.getAsWord());
37-
uint8_t expectedBytes2[frameCount::lengthInBytes]{0x78, 0x56, 0x34, 0x12};
38-
for (uint32_t index = 0; index < frameCount::lengthInBytes; index++) {
39-
TEST_ASSERT_EQUAL(expectedBytes2[index], testFrameCount2.getAsByte(index));
40-
}
41-
}
42-
4324
void test_setFromByteArray() {
4425
frameCount testFrameCount;
4526
uint8_t testBytes[frameCount::lengthInBytes]{0x78, 0x56, 0x34, 0x12};
@@ -106,8 +87,7 @@ int main(int argc, char **argv) {
10687
#endif
10788
UNITY_BEGIN();
10889
RUN_TEST(test_initialize);
109-
RUN_TEST(test_operatorAssign);
110-
RUN_TEST(test_setFromByteArray);
90+
RUN_TEST(test_setFromByteArray);
11191
RUN_TEST(test_SetFromWord);
11292
RUN_TEST(test_operatorIncrement);
11393
RUN_TEST(test_guessFromUint16);

‎test/generic/test_lorawan_0_general/test.cpp‎

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ void test_isValidDownlinkFrameCount() {
112112
LoRaWAN::downlinkFrameCount.setFromWord(0);
113113
frameCount testFrameCount;
114114
testFrameCount.setFromWord(10);
115-
TEST_ASSERT_TRUE(LoRaWAN::isValidDownlinkFrameCount(testFrameCount));
115+
TEST_ASSERT_TRUE(LoRaWAN::isValidDownlinkFrameCount(testFrameCount.getAsWord()));
116116
LoRaWAN::downlinkFrameCount.setFromWord(9);
117-
TEST_ASSERT_TRUE(LoRaWAN::isValidDownlinkFrameCount(testFrameCount));
117+
TEST_ASSERT_TRUE(LoRaWAN::isValidDownlinkFrameCount(testFrameCount.getAsWord()));
118118
LoRaWAN::downlinkFrameCount.setFromWord(10);
119-
TEST_ASSERT_FALSE(LoRaWAN::isValidDownlinkFrameCount(testFrameCount));
119+
TEST_ASSERT_FALSE(LoRaWAN::isValidDownlinkFrameCount(testFrameCount.getAsWord()));
120120
LoRaWAN::downlinkFrameCount.setFromWord(11);
121-
TEST_ASSERT_FALSE(LoRaWAN::isValidDownlinkFrameCount(testFrameCount));
121+
TEST_ASSERT_FALSE(LoRaWAN::isValidDownlinkFrameCount(testFrameCount.getAsWord()));
122122
}
123123

124124
void test_dump() {
@@ -136,44 +136,6 @@ void test_dump() {
136136
TEST_MESSAGE("For Coverage only");
137137
}
138138

139-
// void test_saveContext() {
140-
// memset(mockEepromMemory, 0x00, 512);
141-
142-
// LoRaWAN::DevAddr = 0x44657641; // reads as DevA in memory
143-
// LoRaWAN::uplinkFrameCount = 0x554C4643; // reads as ULFC in memory
144-
// LoRaWAN::downlinkFrameCount = 0x444C4643; // reads as DLFC in memory
145-
// LoRaWAN::rx1DelayInSeconds = 7;
146-
// LoRaWAN::currentDataRateIndex = 3;
147-
// LoRaWAN::applicationKey.setFromHexString("000102030405060708090A0B0C0D0E0F");
148-
// LoRaWAN::networkKey.setFromHexString("101112131415161718191A1B1C1D1E1F");
149-
150-
// LoRaWAN::saveConfig();
151-
// LoRaWAN::saveState();
152-
// LoRaWAN::saveChannels();
153-
154-
// LoRaWAN::DevAddr = 0;
155-
// LoRaWAN::uplinkFrameCount = 0;
156-
// LoRaWAN::downlinkFrameCount = 0;
157-
// LoRaWAN::rx1DelayInSeconds = 0;
158-
// LoRaWAN::currentDataRateIndex = 0;
159-
// LoRaWAN::applicationKey.setFromHexString("00000000000000000000000000000000");
160-
// LoRaWAN::networkKey.setFromHexString("00000000000000000000000000000000");
161-
162-
// LoRaWAN::restoreConfig();
163-
// LoRaWAN::restoreState();
164-
// LoRaWAN::restoreChannels();
165-
166-
// TEST_ASSERT_EQUAL_UINT32(0x44657641, LoRaWAN::DevAddr.asUint32);
167-
// TEST_ASSERT_EQUAL_UINT32(0x554C4643, LoRaWAN::uplinkFrameCount.toUint32());
168-
// TEST_ASSERT_EQUAL_UINT32(0x444C4643, LoRaWAN::downlinkFrameCount.toUint32());
169-
// TEST_ASSERT_EQUAL_UINT32(7, LoRaWAN::rx1DelayInSeconds);
170-
// TEST_ASSERT_EQUAL_UINT32(3, LoRaWAN::currentDataRateIndex);
171-
// char tmpKeyAsHexString[33];
172-
// hexAscii::byteArrayToHexString(tmpKeyAsHexString, LoRaWAN::applicationKey.asBytes(), 16);
173-
// TEST_ASSERT_EQUAL_STRING("000102030405060708090A0B0C0D0E0F", tmpKeyAsHexString);
174-
// hexAscii::byteArrayToHexString(tmpKeyAsHexString, LoRaWAN::networkKey.asBytes(), 16);
175-
// TEST_ASSERT_EQUAL_STRING("101112131415161718191A1B1C1D1E1F", tmpKeyAsHexString);
176-
// }
177139

178140
int main(int argc, char **argv) {
179141
UNITY_BEGIN();
@@ -187,7 +149,6 @@ int main(int argc, char **argv) {
187149
RUN_TEST(test_save_restore_channels);
188150
RUN_TEST(test_isValidDownlinkFrameCount);
189151
RUN_TEST(test_dump);
190-
// RUN_TEST(test_saveContext);
191152

192153
UNITY_END();
193154
}

0 commit comments

Comments
 (0)