@@ -260,6 +260,11 @@ void mainController::handleEventsStateNetworking(applicationEvent theEvent) {
260260 LoRaWAN::handleEvents (theEvent);
261261 break ;
262262
263+ case applicationEvent::downlinkApplicationPayloadReceived:
264+ handleDownLink (LoRaWAN::getPort (), LoRaWAN::getPayloadPtr (), LoRaWAN::getPayloadLength ());
265+ LoRaWAN::getReceivedDownlinkMessage ();
266+ break ;
267+
263268 default :
264269 break ;
265270 }
@@ -389,7 +394,7 @@ void mainController::showLoRaWanStatus() {
389394 snprintf (tmpString, screen::maxConsoleTextLength, " Gateways : %u" , static_cast <uint8_t >(LoRaWAN::gatewayCount));
390395 screen::setText (5 , tmpString);
391396 time_t rtcTime = realTimeClock::get ();
392- const struct tm * rtcTime2 = localtime (&rtcTime);
397+ const struct tm * rtcTime2 = gmtime (&rtcTime);
393398 strftime (tmpString, screen::maxConsoleTextLength, " Date : %Y-%b-%d" , rtcTime2);
394399 screen::setText (6 , tmpString);
395400 strftime (tmpString, screen::maxConsoleTextLength, " Time : %H:%M:%S" , rtcTime2);
@@ -590,7 +595,7 @@ void mainController::showPrompt() {
590595}
591596
592597void mainController::showHelp () {
593- cli::sendResponse (" <enter> :show build info and license\n " );
598+ cli::sendResponse (" <enter> : show build info and license\n " );
594599 cli::sendResponse (" ? : show help\n " );
595600 cli::sendResponse (" gds : show device status\n " );
596601 cli::sendResponse (" gms : show recorded measurements status\n " );
@@ -613,12 +618,14 @@ void mainController::showHelp() {
613618}
614619
615620void mainController::showDeviceStatus () {
616- cli::sendResponse (" UID : %s\n " , uniqueId::asHexString ());
617- cli::sendResponse (" name : %s\n " , name);
618- cli::sendResponse (" display : %s\n " , display::isPresent () ? " present" : " not present" );
619- cli::sendResponse (" EEPROM : %d * 64K present\n " , nonVolatileStorage::getNmbr64KBanks ());
620- cli::sendResponse (" battery : %s (%d)\n " , toString (battery::getType ()), static_cast <uint8_t >(battery::getType ()));
621- cli::sendResponse (" radioType: %s (%d)\n " , toString (sx126x::getType ()), static_cast <uint8_t >(sx126x::getType ()));
621+ cli::sendResponse (" UID : %s\n " , uniqueId::asHexString ());
622+ cli::sendResponse (" name : %s\n " , name);
623+ cli::sendResponse (" display : %s\n " , display::isPresent () ? " present" : " not present" );
624+ cli::sendResponse (" EEPROM : %d * 64K present\n " , nonVolatileStorage::getNmbr64KBanks ());
625+ cli::sendResponse (" battery : %s (%d)\n " , toString (battery::getType ()), static_cast <uint8_t >(battery::getType ()));
626+ cli::sendResponse (" radio : %s (%d)\n " , toString (sx126x::getType ()), static_cast <uint8_t >(sx126x::getType ()));
627+ time_t rtcTime = realTimeClock::get ();
628+ cli::sendResponse (" RTC : %s" , ctime (&rtcTime));
622629
623630 for (uint32_t sensorDeviceIndex = 0 ; sensorDeviceIndex < static_cast <uint32_t >(sensorDeviceType::nmbrOfKnownDevices); sensorDeviceIndex++) {
624631 if (sensorDeviceCollection::isPresent (sensorDeviceIndex)) {
@@ -780,6 +787,7 @@ void mainController::setDisplay(const cliCommand& theCommand) {
780787 displayChannelIndex[tmpLineIndex] = tmpChannelIndex;
781788
782789 cli::sendResponse (" display line %u set to %s - %s\n " , tmpLineIndex, sensorDeviceCollection::name (tmpDeviceIndex), sensorDeviceCollection::name (tmpDeviceIndex, tmpChannelIndex));
790+ showMain ();
783791}
784792
785793void mainController::setSensor (const cliCommand& theCommand) {
@@ -938,4 +946,71 @@ void mainController::showMeasurementsCsv() {
938946 nmbrOfGroups++;
939947 offset += measurementGroup::lengthInBytes (tmpGroup.getNumberOfMeasurements ());
940948 }
949+ }
950+
951+ void mainController::setDisplay (const uint8_t * payload, const uint32_t payloadLength) {
952+ if (payload == nullptr ) {
953+ return ;
954+ }
955+ if (payloadLength != 3 ) {
956+ return ;
957+ }
958+ uint32_t tmpLineIndex = payload[0 ];
959+ if (tmpLineIndex >= screen::nmbrOfMeasurementTextLines) {
960+ return ;
961+ }
962+ uint32_t tmpDeviceIndex = payload[1 ];
963+ uint32_t tmpChannelIndex = payload[2 ];
964+ if (!sensorDeviceCollection::isValid (tmpDeviceIndex, tmpChannelIndex)) {
965+ return ;
966+ }
967+ uint8_t tmpDeviceAndChannel = sensorChannel::compressDeviceAndChannelIndex (static_cast <uint8_t >(tmpDeviceIndex), static_cast <uint8_t >(tmpChannelIndex));
968+ settingsCollection::save (tmpDeviceAndChannel, settingsCollection::settingIndex::displaySettings, tmpLineIndex);
969+ displayDeviceIndex[tmpLineIndex] = tmpDeviceIndex;
970+ displayChannelIndex[tmpLineIndex] = tmpChannelIndex;
971+ showMain ();
972+ }
973+
974+ void mainController::setSensor (const uint8_t * payload, const uint32_t payloadLength) {
975+ if (payload == nullptr ) {
976+ return ;
977+ }
978+ if (payloadLength != 4 ) {
979+ return ;
980+ }
981+ uint32_t tmpDeviceIndex = payload[0 ];
982+ uint32_t tmpChannelIndex = payload[1 ];
983+ if (!sensorDeviceCollection::isValid (tmpDeviceIndex, tmpChannelIndex)) {
984+ return ;
985+ }
986+ uint32_t tmpOversamplingIndex = payload[2 ];
987+ ;
988+ uint32_t tmpPrescalerIndex = payload[3 ];
989+ ;
990+ if (tmpPrescalerIndex > sensorChannel::maxPrescalerIndex) {
991+ tmpPrescalerIndex = sensorChannel::maxPrescalerIndex;
992+ }
993+ if (tmpOversamplingIndex > sensorChannel::maxOversamplingIndex) {
994+ tmpOversamplingIndex = sensorChannel::maxOversamplingIndex;
995+ }
996+ if (tmpOversamplingIndex > tmpPrescalerIndex) {
997+ tmpOversamplingIndex = tmpPrescalerIndex;
998+ }
999+ uint8_t tmpCombined = sensorChannel::compressOversamplingAndPrescalerIndex (tmpOversamplingIndex, tmpPrescalerIndex);
1000+ uint8_t tmpDeviceAndChannel = sensorChannel::compressDeviceAndChannelIndex (static_cast <uint8_t >(tmpDeviceIndex), static_cast <uint8_t >(tmpChannelIndex));
1001+ settingsCollection::save (tmpCombined, settingsCollection::settingIndex::sensorSettings, tmpDeviceAndChannel);
1002+ sensorDeviceCollection::channel (tmpDeviceIndex, tmpChannelIndex).setIndex (tmpOversamplingIndex, tmpPrescalerIndex);
1003+ }
1004+
1005+ void mainController::handleDownLink (const uint8_t port, const uint8_t * payload, const uint32_t payloadLength) {
1006+ switch (port) {
1007+ case 1 :
1008+ setDisplay (payload, payloadLength);
1009+ break ;
1010+ case 2 :
1011+ setSensor (payload, payloadLength);
1012+ break ;
1013+ default :
1014+ break ;
1015+ }
9411016}
0 commit comments