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
234 changes: 121 additions & 113 deletions lib/application/maincontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,118 +459,120 @@ void mainController::runCli() {
break;

default:
if (power::hasUsbPower()) {
if (cli::hasCommand()) {
cliCommand theCommand;
cli::getCommand(theCommand);
switch (theCommand.commandHash) {
case cliCommand::prompt:
showPrompt();
break;

case cliCommand::help:
showHelp();
break;

case cliCommand::enableLogging:
cli::sendResponse("logging enabled\n");
logging::enable(logging::destination::uart2);
break;

case cliCommand::disableLogging:
cli::sendResponse("logging disabled\n");
logging::disable(logging::destination::uart2);
break;

case cliCommand::enableRadio:
LoRaWAN::setEnableRadio(true);
cli::sendResponse("radio enabled\n");
break;

case cliCommand::disableRadio:
LoRaWAN::setEnableRadio(false);
cli::sendResponse("radio disabled\n");
break;

case cliCommand::getDeviceStatus:
showDeviceStatus();
break;

case cliCommand::getMeasurementsStatus:
showMeasurementsStatus();
break;

case cliCommand::getMeasurements:
if (theCommand.nmbrOfArguments == 0) {
showMeasurements();
}
if (theCommand.nmbrOfArguments == 1) {
if (strncmp(theCommand.arguments[0], "csv", 3) == 0) {
showMeasurementsCsv();
break;
} else {
cli::sendResponse("invalid argument\n");
break;
}
} else {
cli::sendResponse("invalid number of arguments\n");
}
break;

case cliCommand::getLoRaWANStatus:
showNetworkStatus();
break;

case cliCommand::resetMacLayer:
LoRaWAN::resetMacLayer();
cli::sendResponse("mac layer reset\n");
break;

case cliCommand::setDeviceAddress:
setDeviceAddress(theCommand);
break;

case cliCommand::setNetworkKey:
setNetworkKey(theCommand);
break;

case cliCommand::setApplicationKey:
setApplicationKey(theCommand);
break;

case cliCommand::setName:
setName(theCommand);
break;

case cliCommand::setBattery:
setBatteryType(theCommand);
break;

case cliCommand::setRadio:
setRadioType(theCommand);
break;

case cliCommand::setSensor:
setSensor(theCommand);
break;

case cliCommand::setDisplay:
setDisplay(theCommand);
break;

case cliCommand::softwareReset:
initialize();
break;

default:
cli::sendResponse("unknown command : ");
cli::sendResponse(theCommand.commandAsString);
cli::sendResponse("\n");
break;
}
if (power::hasUsbPower() && cli::hasCommand()) {
cliCommand theCommand;
cli::getCommand(theCommand);
runCli(theCommand);
}
break;
}
}

void mainController::runCli(const cliCommand& theCommand) {
switch (theCommand.commandHash) {
case cliCommand::prompt:
showPrompt();
break;

case cliCommand::help:
showHelp();
break;

case cliCommand::enableLogging:
cli::sendResponse("logging enabled\n");
logging::enable(logging::destination::uart2);
break;

case cliCommand::disableLogging:
cli::sendResponse("logging disabled\n");
logging::disable(logging::destination::uart2);
break;

case cliCommand::enableRadio:
LoRaWAN::setEnableRadio(true);
cli::sendResponse("radio enabled\n");
break;

case cliCommand::disableRadio:
LoRaWAN::setEnableRadio(false);
cli::sendResponse("radio disabled\n");
break;

case cliCommand::getDeviceStatus:
showDeviceStatus();
break;

case cliCommand::getMeasurementsStatus:
showMeasurementsStatus();
break;

case cliCommand::getMeasurements:
if (theCommand.nmbrOfArguments == 0) {
showMeasurements();
}
if (theCommand.nmbrOfArguments == 1) {
if (strncmp(theCommand.arguments[0], "csv", 3) == 0) {
showMeasurementsCsv();
break;
} else {
cli::sendResponse("invalid argument\n");
break;
}
} else {
cli::sendResponse("invalid number of arguments\n");
}
break;

case cliCommand::getLoRaWANStatus:
showNetworkStatus();
break;

case cliCommand::resetMacLayer:
LoRaWAN::resetMacLayer();
cli::sendResponse("mac layer reset\n");
break;

case cliCommand::setDeviceAddress:
setDeviceAddress(theCommand);
break;

case cliCommand::setNetworkKey:
setNetworkKey(theCommand);
break;

case cliCommand::setApplicationKey:
setApplicationKey(theCommand);
break;

case cliCommand::setName:
setName(theCommand);
break;

case cliCommand::setBattery:
setBatteryType(theCommand);
break;

case cliCommand::setRadio:
setRadioType(theCommand);
break;

case cliCommand::setSensor:
setSensor(theCommand);
break;

case cliCommand::setDisplay:
setDisplay(theCommand);
break;

case cliCommand::softwareReset:
initialize();
break;

default:
cli::sendResponse("unknown command : ");
cli::sendResponse(theCommand.commandAsString);
cli::sendResponse("\n");
break;
}
}

Expand Down Expand Up @@ -984,9 +986,8 @@ void mainController::setSensor(const uint8_t* payload, const uint32_t payloadLen
return;
}
uint32_t tmpOversamplingIndex = payload[2];
;
uint32_t tmpPrescalerIndex = payload[3];
;

if (tmpPrescalerIndex > sensorChannel::maxPrescalerIndex) {
tmpPrescalerIndex = sensorChannel::maxPrescalerIndex;
}
Expand All @@ -1003,12 +1004,19 @@ void mainController::setSensor(const uint8_t* payload, const uint32_t payloadLen
}

void mainController::handleDownLink(const uint8_t port, const uint8_t* payload, const uint32_t payloadLength) {
if (payload == nullptr || payloadLength == 0) {
return;
}
switch (port) {
case 1:
setDisplay(payload, payloadLength);
for (uint32_t offset = 0; offset < payloadLength; offset += 3) {
setDisplay(payload + offset, 3);
}
break;
case 2:
setSensor(payload, payloadLength);
for (uint32_t offset = 0; offset < payloadLength; offset += 4) {
setSensor(payload + offset, 4);
}
break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions lib/application/maincontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class mainController {
static void runStateMachine();
static void handleEvents();
static void runCli();
static void runCli(const cliCommand& aCommand);
static void runDisplayUpdate();
static void runSleep();

Expand Down
7 changes: 2 additions & 5 deletions lib/lorawan/lorawan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,6 @@ void LoRaWAN::removeNonStickyMacStuff() {

macOut.initialize();
macOut.append(tmpMacOut.asUint8Ptr(), tmpMacOut.getLevel());
// TODO : if we have sticky MACstuff, we could append a linkcheckrequest and thus force the LNS to send us a downlink, which confirms the sticky MAC stuff...
}

void LoRaWAN::processLinkCheckAnswer() {
Expand All @@ -901,7 +900,7 @@ void LoRaWAN::processLinkCheckAnswer() {
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); // TODO : For the time being, we just show this info in the logging. Later we could use it to show the quality of the link on the display
logging::snprintf(logging::source::lorawanMac, "LinkCheckAnswer : margin = %d, gatewayCount = %d \n", margin, gatewayCount);
}

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

// TODO : currently I don't understand the purpose of this mac command, so I just ignore it. Maybe it's more useful in US-915 than EU-868

constexpr uint32_t linkAdaptiveDataRateAnswerLength{2}; // commandId, status
uint8_t answer[linkAdaptiveDataRateAnswerLength];
answer[0] = static_cast<uint8_t>(macCommand::linkAdaptiveDataRateAnswer);
answer[1] = static_cast<uint8_t>(0); // TODO : For the time being we just reject this stupid mac command
answer[1] = static_cast<uint8_t>(0);
macOut.append(answer, linkAdaptiveDataRateAnswerLength);
logging::snprintf(logging::source::lorawanMac, "linkAdaptiveDataRateAnswer : 0x%02X \n", answer[1]);
}
Expand All @@ -928,7 +926,6 @@ void LoRaWAN::processDutyCycleRequest() {
macIn.consume(dutyCycleRequestLength);
logging::snprintf(logging::source::lorawanMac, "DutyCycleRequest : 0x%02X \n", dutyCycle);

// TODO : until we implement dutyCycle management, we ignore this command

constexpr uint32_t dutyCycleAnswerLength{1};
uint8_t answer[dutyCycleAnswerLength];
Expand Down
7 changes: 7 additions & 0 deletions lib/lorawan/lorawan.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ If the application wants to send certain MAC commands, or needs to respond to re
When a received LoRaWAN message contains MAC commands, they are stored in **macIn**, and processed afterwards.

Some MAC commands are 'sticky', ie. they need to be repeated on every transmission until confirmed by a received message.


# Could Do
// TODO : if we have sticky MACstuff, we could append a linkcheckrequest and thus force the LNS to send us a downlink, which confirms the sticky MAC stuff...
processLinkAdaptiveDataRateRequest // TODO : currently I don't understand the purpose of this mac command, so I just ignore it. Maybe it's more useful in US-915 than EU-868
processDutyCycleRequest // TODO : until we implement dutyCycle management, we ignore this command
processLinkCheckAnswer// TODO : For the time being, we just show this info in the logging. Later we could use it to show the quality of the link on the display
Loading
Loading