Skip to content

Commit

Permalink
Fix #270: updated the src to support Sigfox provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
dhineshkumarmcci committed Jan 20, 2021
1 parent 951240e commit ccdce72
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 420 deletions.
6 changes: 6 additions & 0 deletions src/CatenaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Copyright notice:

#include <Arduino_LoRaWAN.h>

#include <MCCI_Sigfox.h>
#include <Catena_Sigfox_wapper.h>

#if ! (defined(ARDUINO_LORAWAN_VERSION) && ARDUINO_LORAWAN_VERSION >= ARDUINO_LORAWAN_VERSION_CALC(0,6,0,20))
# error Arduino_LoRaWAN library is out of date. Check ARDUINO_LORAWAN_VERSION.
#endif
Expand Down Expand Up @@ -284,6 +287,9 @@ class CatenaBase

bool addLoRaWanCommands(void);

bool GetSigfoxConfiguringInfo(MCCI_Catena_Sigfox::SigfoxConfiguringInfo *);
bool addSigfoxCommands(void);

// calibrate the system clock, if possible
virtual uint32_t CalibrateSystemClock(void)
{
Expand Down
42 changes: 42 additions & 0 deletions src/CatenaFeatherM0.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Copyright notice:

#include <Arduino_LoRaWAN_network.h>

#include <MCCI_Sigfox.h>
#include <Catena_Sigfox_wapper.h>

namespace McciCatena {

class CatenaFeatherM0 : public CatenaSamd21
Expand All @@ -37,6 +40,9 @@ class CatenaFeatherM0 : public CatenaSamd21
// forward reference
class LoRaWAN;

// Sigfox binding
class Sigfox /* forward */;

// all FeatherM0s put vbat on A7
enum ANALOG_PINS
{
Expand Down Expand Up @@ -116,6 +122,42 @@ class CatenaFeatherM0::LoRaWAN : public Arduino_LoRaWAN_network,
CatenaFeatherM0 *m_pCatena;
};

class CatenaFeatherM0::Sigfox : public MCCI_Catena_Sigfox,
public cPollableObject
{
public:
using Super = MCCI_Sigfox;

/*
|| the constructor.
*/
Sigfox() {};

/*
|| the begin function loads data from the local
|| platform's stable storage and initializes
|| the connection.
*/
virtual bool begin(CatenaFeatherM0 *pCatena);

virtual void poll() { sigfox_loop(); };

protected:
/*
|| we have to provide these for the lower level
*/
virtual bool GetSigfoxConfiguringInfo(
SigfoxConfiguringInfo *pProvisioningInfo
) override;

//
// TODO([email protected]) -- the following are not used but are always
// hanging around even when we have better ways to do things.
//
private:
CatenaFeatherM0 *m_pCatena;
};

} /* namespace McciCatena */

/**** end of CatenaFeatherM0.h ****/
Expand Down
17 changes: 8 additions & 9 deletions src/CatenaStm32L0.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Copyright notice:
#include <Arduino_LoRaWAN_network.h>

#include <MCCI_Sigfox.h>
#include <Catena_Sigfox_wapper.h>

namespace McciCatena {

Expand All @@ -47,6 +48,9 @@ class CatenaStm32L0 : public CatenaStm32
// forward reference
class LoRaWAN;

// Sigfox binding
class Sigfox /* forward */;

// start the Stm32L0 level
virtual bool begin(void) override;

Expand Down Expand Up @@ -159,11 +163,11 @@ class CatenaStm32L0::LoRaWAN : public Arduino_LoRaWAN_network,
CatenaStm32L0 *m_pCatena;
};

class CatenaStm32L0::Sigfox : public MCCI_Sigfox,
class CatenaStm32L0::Sigfox : public MCCI_Catena_Sigfox,
public McciCatena::cPollableObject
{
public:
using Super = MCCI_Sigfox;
using Super = MCCI_Catena_Sigfox;

/*
|| the constructor.
Expand All @@ -177,20 +181,15 @@ class CatenaStm32L0::Sigfox : public MCCI_Sigfox,
*/
virtual bool begin(CatenaStm32L0 *pCatena);

virtual void poll() { this->Super::loop(); };
virtual void poll() { sigfox_loop(); };

protected:
/*
|| we have to provide these for the lower level
*/
virtual bool GetSigfoxConfiguringInfo(
Arduino_LoRaWAN::OtaaProvisioningInfo *
MCCI_Catena_Sigfox::SigfoxConfiguringInfo *
) override;

//
// TODO([email protected]) -- the following are not used but are always
// hanging around even when we have better ways to do things.
//
private:
CatenaStm32L0 *m_pCatena;
};
Expand Down
12 changes: 6 additions & 6 deletions src/Catena_FramStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class cFramStorage
kBootCount = 14,
kOperatingFlags = 15,
kBme680Cal = 16,
kAppConf = 17,
kDevID = 18,
kPAC = 19,
kKey = 20,
kRegion = 21,
kEncryption = 22,
kDevID = 17,
kPAC = 18,
kKey = 19,
kRegion = 20,
kEncryption = 21,
kAppConf = 22,
// when you add something, also update McciCatena::cFramStorage::vItemDefs[]!
kMAX
};
Expand Down
32 changes: 22 additions & 10 deletions src/lib/CatenaBase_GetSigfoxConfiguringInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Name: CatenaBase::GetSigfoxConfiguringInfo()
Definition:
public: virtual bool
CatenaBase::GetSigfoxConfiguringInfo(
Arduino_LoRaWAN::OtaaProvisioningInfo *pInfo
MCCI_Catena_Sigfox::SigfoxConfiguringInfo *pInfo
) override;
Description:
Expand All @@ -84,7 +84,7 @@ Name: CatenaBase::GetSigfoxConfiguringInfo()

bool
CatenaBase::GetSigfoxConfiguringInfo(
Arduino_LoRaWAN::OtaaProvisioningInfo *pInfo
MCCI_Catena_Sigfox::SigfoxConfiguringInfo *pInfo
)
{
auto const pFram = this->getFram();
Expand All @@ -93,7 +93,7 @@ CatenaBase::GetSigfoxConfiguringInfo(
{
gLog.printf(
gLog.kError,
"?CatenaBase::GetOtaaProvisioningInfo: no FRAM\n"
"?CatenaBase::GetSigfoxConfiguringInfo: no FRAM\n"
);

if (pInfo != nullptr)
Expand All @@ -102,6 +102,8 @@ CatenaBase::GetSigfoxConfiguringInfo(
return false;
}

/* cFram::Cursor framSigfoxCredentials(pFram); */

cFram::Cursor framDevID(pFram),
framPAC(pFram),
framKey(pFram),
Expand All @@ -118,11 +120,14 @@ CatenaBase::GetSigfoxConfiguringInfo(
framEncryption.locate(cFramStorage::vItemDefs[cFramStorage::kEncryption]))
fResult = true;

/* if (framSigfoxCredentials.locate(cFramStorage::vItemDefs[cFramStorage::kSigfoxCredentials]))
fResult = true; */

if (! fResult)
{
gLog.printf(
gLog.kError,
"?CatenaBase::GetOtaaProvisioningInfo: failing\n"
"?CatenaBase::GetSigfoxConfiguringInfo: failing\n"
);

if (pInfo != nullptr)
Expand All @@ -135,13 +140,20 @@ CatenaBase::GetSigfoxConfiguringInfo(
return true;

/* copy the data */
framDevID.get(pInfo->AppKey, sizeof(pInfo->AppKey));
framPAC.get(pInfo->DevEUI, sizeof(pInfo->DevEUI));
framKey.get(pInfo->AppEUI, sizeof(pInfo->AppEUI));
framRegion.get(pInfo->DevEUI, sizeof(pInfo->DevEUI));
framEncryption.get(pInfo->AppEUI, sizeof(pInfo->AppEUI));
framDevID.get(pInfo->DevID, sizeof(pInfo->DevID));
framPAC.get(pInfo->PAC, sizeof(pInfo->PAC));
framKey.get(pInfo->Key, sizeof(pInfo->Key));
framRegion.get(pInfo->Region, sizeof(pInfo->Region));
framEncryption.get(pInfo->Encryption, sizeof(pInfo->Encryption));

/* copy the data */
/* framSigfoxCredentials.get(pInfo->AppKey, sizeof(pInfo->AppKey));
framSigfoxCredentials.get(pInfo->DevEUI, sizeof(pInfo->DevEUI));
framSigfoxCredentials.get(pInfo->AppEUI, sizeof(pInfo->AppEUI));
framSigfoxCredentials.get(pInfo->DevEUI, sizeof(pInfo->DevEUI));
framSigfoxCredentials.get(pInfo->AppEUI, sizeof(pInfo->AppEUI)); */

return true;
}

/**** end of CatenaBase_GetOtaaProvisioningInfo.cpp ****/
/**** end of CatenaBase_GetSigfoxConfiguringInfo.cpp ****/
1 change: 1 addition & 0 deletions src/lib/CatenaBase_addSigfoxCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Copyright notice:
#include "CatenaBase.h"

#include <MCCI_Sigfox.h>
#include <Catena_Sigfox_wapper.h>

#include "Catena_Log.h"

Expand Down
4 changes: 2 additions & 2 deletions src/lib/Catena_Fram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@ McciCatena::cFram::writeItemData(
{
gLog.printf(
gLog.kBug,
"%s: offset for uKey(%u) invalid!\n",
"%s: offset for uKey(%u) invalid!, offset:(%u)\n",
__FUNCTION__,
uKey
uKey, offset
);

return false;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Catena_FramStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ McciCatena::cFramStorage::vItemDefs[cFramStorage::kMAX] =
cFramStorage::StandardItem(kAppKey, sizeof(uint8_t[16]), /* number */ false),
cFramStorage::StandardItem(kBootCount, sizeof(uint32_t), /* number */ true),
cFramStorage::StandardItem(kOperatingFlags, sizeof(uint32_t), /* number */ true),
cFramStorage::StandardItem(kDevID, sizeof(uint32_t), /* number */ true),
cFramStorage::StandardItem(kPAC, sizeof(uint32_t), /* number */ true),
cFramStorage::StandardItem(kKey, sizeof(uint8_t[16]), /* number */ false),
cFramStorage::StandardItem(kRegion, sizeof(uint32_t), /* number */ true),
cFramStorage::StandardItem(kEncryption, sizeof(uint32_t), /* number */ true),

/* the size field should match BSEC_MAX_STATE_BLOB_SIZE, which is 139 */
cFramStorage::StandardItem(kBme680Cal, 139, /* number */ false),
cFramStorage::StandardItem(kDevID, sizeof(uint8_t[4]), /* number */ true),
cFramStorage::StandardItem(kPAC, sizeof(uint8_t[8]), /* number */ true),
cFramStorage::StandardItem(kKey, sizeof(uint8_t[16]), /* number */ false),
cFramStorage::StandardItem(kRegion, sizeof(uint8_t), /* number */ true),
cFramStorage::StandardItem(kEncryption, sizeof(uint8_t), /* number */ true),
cFramStorage::StandardItem(kAppConf, cFramStorage::MaxAppConfSize, false)
};

Expand Down
52 changes: 14 additions & 38 deletions src/lib/samd/catenawingfram2k/CatenaWingFram2k_Sigfox_begin.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
/* CatenaWingFram2k_LoRaWAN_begin.cpp Wed Jan 09 2019 14:24:20 chwon */

/*
Module: CatenaWingFram2k_LoRaWAN_begin.cpp
Module: CatenaWingFram2k_Sigfox_begin.cpp
Function:
CatenaWingFram2k::LoRaWAN::begin()
Version:
V0.13.0 Wed Jan 09 2019 14:24:20 chwon Edit level 3
CatenaWingFram2k::Sigfox::begin()
Copyright notice:
This file copyright (C) 2017-2019 by
MCCI Corporation
3520 Krums Corners Road
Ithaca, NY 14850
An unpublished work. All rights reserved.
This file is proprietary information, and may not be disclosed or
copied without the prior permission of MCCI Corporation.
See accompanying LICENSE file.
Author:
Terry Moore, MCCI Corporation March 2017
Revision history:
0.5.0 Sun Mar 12 2017 19:31:15 tmm
Module created.
0.12.0 Wed Dec 05 2018 14:27:52 chwon
Call Arduino_LoRaWAN::begin() and use Catena addLoRaWanCommands().
0.13.0 Wed Jan 09 2019 14:24:20 chwon
Need to set up LoRaWan command before call Arduino_LoRaWAN::begin().
Dhinesh Kumar Pitchai, MCCI Corporation December 2020
*/

Expand All @@ -48,13 +24,13 @@ using namespace McciCatena;

/*
Name: CatenaWingFram2k::LoRaWAN::begin()
Name: CatenaWingFram2k::Sigfox::begin()
Function:
Record linkage to main Catena object and set up LoRaWAN.
Record linkage to main Catena object and set up Sigfox.
Definition:
bool CatenaWingFram2k::LoRaWAN::begin(
bool CatenaWingFram2k::Sigfox::begin(
CatenaWingFram2k *pParent
);
Expand All @@ -67,25 +43,25 @@ Name: CatenaWingFram2k::LoRaWAN::begin()
*/

bool
CatenaWingFram2k::LoRaWAN::begin(
CatenaWingFram2k::Sigfox::begin(
CatenaWingFram2k *pParent
)
{
gLog.printf(gLog.kTrace, "+CatenaWingFram2k::LoRaWAN::begin()\n");
gLog.printf(gLog.kTrace, "+CatenaWingFram2k::Sigfox::begin()\n");
MCCI_Sigfox m_Sigfox;

this->m_pCatena = pParent;
this->m_ulDebugMask |= LOG_VERBOSE | LOG_ERRORS | LOG_BASIC;

/* first set up command processor -- just in case begin() failed */
pParent->addLoRaWanCommands();
pParent->addSigfoxCommands();

/* call the base begin */
if (! this->Arduino_LoRaWAN::begin())
if (! m_Sigfox.isReady())
{
gLog.printf(
gLog.kError,
"?CatenaWingFram2k::LoRaWAN::begin:"
" Arduino_LoRaWAN:begin failed\n"
"?CatenaWingFram2k::Sigfox::begin:"
" MCCI_Catena_Sigfox:begin failed\n"
);
return false;
}
Expand Down
Loading

0 comments on commit ccdce72

Please sign in to comment.