Skip to content
1 change: 1 addition & 0 deletions examples/Catena4430_Sensor/Catena4430_cMeasurementLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ cMeasurementLoop::fsmDispatch(
newState = State::stRebootForUpdate;
else
newState = State::stSleeping;
this->handleSdTTNv3Migrate();
break;

// no SD card....
Expand Down
4 changes: 4 additions & 0 deletions examples/Catena4430_Sensor/Catena4430_cMeasurementLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ class cMeasurementLoop : public McciCatena::cPollableObject
bool handleSdFirmwareUpdate();
bool handleSdFirmwareUpdateCardUp();
bool updateFromSd(const char *sFile, McciCatena::cDownload::DownloadRq_t rq);
void handleSdTTNv3Migrate();
bool handleSdTTNv3MigrateCardUp(const char *sFile);
bool updateFramAppEui();
void reJoinNetwork();
void sdPowerUp(bool fOn);
void sdPrep();

Expand Down
75 changes: 75 additions & 0 deletions examples/Catena4430_Sensor/Catena4430_cMeasurementLoop_SDcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Module: Catena4430_cMeasurementLoop_SDcard.cpp

#include <Catena_Download.h>

#include <Catena_Fram.h>

#include <Arduino_LoRaWAN_lmic.h>

#include <SD.h>
#include <mcciadk_baselib.h>

Expand Down Expand Up @@ -571,4 +575,75 @@ cMeasurementLoop::updateFromSd(
}
}

void
cMeasurementLoop::handleSdTTNv3Migrate(
void
)
{
static const char * const sMigrate = "MIGRATE.V3";
bool fMigrate;
bool fResult = this->checkSdCard();

if (fResult)
{
fMigrate = this->handleSdTTNv3MigrateCardUp(sMigrate);
}

if (fMigrate)
{
bool fFramUpdate = this->updateFramAppEui();

if (fFramUpdate)
{
this->reJoinNetwork();
gSD.remove(sMigrate);
gLog.printf(gLog.kInfo, "cFramStorage::kAppEUI: update: success\n");
}
else
gLog.printf(gLog.kError, "cFramStorage::kAppEUI: not updated\n");
}
}

bool
cMeasurementLoop::handleSdTTNv3MigrateCardUp(
const char *sMigrate
)
{
if (! gSD.exists(sMigrate))
{
if (gLog.isEnabled(gLog.kTrace))
gLog.printf(gLog.kAlways, "%s: not found: %s\n", FUNCTION, sMigrate);

return false;
}
return true;
}

bool
cMeasurementLoop::updateFramAppEui(
void
)
{
auto const pFram = gCatena.getFram();
uint8_t AppEUI[] = { 1, 0, 0, 0, 0, 0, 0, 0 };

if (pFram == nullptr)
return false;

pFram->saveField(cFramStorage::kAppEUI, AppEUI);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check error status.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I have planned to check return value, unfortunately API saveField is of datatype void.

In this case, I believe we can use API getField to read the value written in FRAM, and then compare to check for error.

Please advice on this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous.

return true;
}

void
cMeasurementLoop::reJoinNetwork(
void
)
{
auto const pFram = gCatena.getFram();
pFram->saveField(cFramStorage::kDevAddr, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can return an error. Check return value. As a consequence, rejoinNetwork can return an error.

Copy link
Contributor Author

@dhineshkumarmcci dhineshkumarmcci Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I have planned to check return value, unfortunately API saveField is of datatype void.

In this case, I believe we can use API getField to read the value written in FRAM, and then compare to check for error.

@terrillmoore Please advice on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I filed a bug report but didn't make the change. No, don't use getField(); the saveField() API is going to change to be bool, and we'll deal with it then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a pull-request for changes with McciCatena::cFram::saveField() - Catena-Arduino-Platform PR-317


LMIC_unjoin();
LMIC_startJoining();
}

#undef FUNCTION