Skip to content

Commit ec96e4d

Browse files
authored
Merge pull request #3 from mcci-catena/TMM-CATENA4450
Refactor to add EU868 support and prepare for others
2 parents 5395e96 + b39dbd0 commit ec96e4d

File tree

6 files changed

+293
-57
lines changed

6 files changed

+293
-57
lines changed

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=MCCI Arduino LoRaWAN library
2-
version=0.2.2
2+
version=0.2.3
33
author=MCCI Corporation
44
maintainer=Terry Moore <tmm@mcci.com>
55
sentence=High-level library for LoRaWAN-based Arduino end-devices
6-
paragraph=Implements many of the details of network interfacing and deployment, so that you can focus on your application rather than worrying about the network. Requires the arduino-lmic library from The Things Network NY.
6+
paragraph=Implements many of the details of network interfacing and deployment, so that you can focus on your application rather than worrying about the network. Requires the arduino-lmic library from The Things Network NY.
77
category=Communication
88
url=https://github.com/terrillmoore/arduino-lorawan/
99
architectures=*

src/Arduino_LoRaWAN_ttn.h

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Arduino_LoRaWAN_ttn.h Mon Oct 31 2016 15:44:49 tmm */
1+
/* Arduino_LoRaWAN_ttn.h Fri May 19 2017 23:58:34 tmm */
22

33
/*
44
@@ -8,27 +8,30 @@ Module: Arduino_LoRaWAN_ttn.h
88
LoRaWAN-variants for The Things Network.
99
1010
Version:
11-
V0.2.0 Mon Oct 31 2016 15:44:49 tmm Edit level 1
11+
V0.2.3 Fri May 19 2017 23:58:34 tmm Edit level 2
1212
1313
Copyright notice:
14-
This file copyright (C) 2016 by
14+
This file copyright (C) 2016-2017 by
1515
1616
MCCI Corporation
1717
3520 Krums Corners Road
1818
Ithaca, NY 14850
1919
2020
An unpublished work. All rights reserved.
21-
21+
2222
This file is proprietary information, and may not be disclosed or
2323
copied without the prior permission of MCCI Corporation.
24-
24+
2525
Author:
2626
Terry Moore, MCCI Corporation October 2016
2727
2828
Revision history:
2929
0.2.0 Mon Oct 31 2016 15:44:49 tmm
3030
Module created.
3131
32+
0.2.3 Fri May 19 2017 23:58:34 tmm
33+
Support eu868.
34+
3235
*/
3336

3437
#ifndef _ARDUINO_LORAWAN_TTN_H_ /* prevent multiple includes */
@@ -54,10 +57,18 @@ class Arduino_LoRaWAN_ttn_base : public Arduino_LoRaWAN
5457
Arduino_LoRaWAN_ttn_base(const lmic_pinmap & pinmap) : Super(pinmap) {};
5558

5659
protected:
60+
// the NetBegin() function does specific work when starting
61+
// up; this does the common work for all TTN lorawan
62+
// variants
63+
virtual bool NetBegin();
64+
5765
// the netjoin function does any post-join work -- at present
5866
// this can be shared by all networks.
5967
virtual void NetJoin();
6068

69+
// every derivative must have a NetBeginInit.
70+
virtual void NetBeginRegionInit() = 0;
71+
6172
private:
6273
};
6374

@@ -68,8 +79,16 @@ class Arduino_LoRaWAN_ttn_eu868 : public Arduino_LoRaWAN_ttn_base
6879
Arduino_LoRaWAN_ttn_eu868() {};
6980
Arduino_LoRaWAN_ttn_eu868(const lmic_pinmap & pinmap) : Super(pinmap) {};
7081

82+
protected:
83+
// the NetBeginInit() function does specific work for the common code
84+
// when starting up.
85+
virtual void NetBeginRegionInit();
86+
87+
// Implement the NetJoin() operations for eu868
88+
virtual void NetJoin();
89+
7190
private:
72-
};
91+
};
7392

7493
class Arduino_LoRaWAN_ttn_us915 : public Arduino_LoRaWAN_ttn_base
7594
{
@@ -79,10 +98,10 @@ class Arduino_LoRaWAN_ttn_us915 : public Arduino_LoRaWAN_ttn_base
7998
Arduino_LoRaWAN_ttn_us915(const lmic_pinmap & pinmap) : Super(pinmap) {};
8099

81100
protected:
82-
// the NetBegin() function does specific work when starting
83-
// up. For ttn we need to turn off the link check mode, and
101+
// the NetBeginInit() function does specific work when starting
102+
// up. For us915, we need to turn off the link check mode, and
84103
// select the subband.
85-
bool NetBegin();
104+
virtual void NetBeginRegionInit();
86105

87106
// Implement the NetJoin() operations for US915
88107
virtual void NetJoin();
@@ -97,6 +116,15 @@ class Arduino_LoRaWAN_ttn_as923 : public Arduino_LoRaWAN_ttn_base
97116
Arduino_LoRaWAN_ttn_as923() {};
98117
Arduino_LoRaWAN_ttn_as923(const lmic_pinmap & pinmap) : Super(pinmap) {};
99118

119+
protected:
120+
// the NetBeginInit() function does specific work when starting
121+
// up. For us915, we need to turn off the link check mode, and
122+
// select the subband.
123+
virtual void NetBeginRegionInit();
124+
125+
// Implement the NetJoin() operations for as923
126+
virtual void NetJoin();
127+
100128
private:
101129
};
102130

src/lib/ttn_base_netbegin.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* ttn_base_netbegin.cpp Fri May 19 2017 23:58:34 tmm */
2+
3+
/*
4+
5+
Module: ttn_base_netbegin.cpp
6+
7+
Function:
8+
Arduino_LoRaWAN_ttn_base::NetBegin()
9+
10+
Version:
11+
V0.2.3 Fri May 19 2017 23:58:34 tmm Edit level 1
12+
13+
Copyright notice:
14+
This file copyright (C) 2017 by
15+
16+
MCCI Corporation
17+
3520 Krums Corners Road
18+
Ithaca, NY 14850
19+
20+
An unpublished work. All rights reserved.
21+
22+
This file is proprietary information, and may not be disclosed or
23+
copied without the prior permission of MCCI Corporation.
24+
25+
Author:
26+
Terry Moore, MCCI Corporation May 2017
27+
28+
Revision history:
29+
0.2.3 Fri May 19 2017 23:58:34 tmm
30+
Module created.
31+
32+
*/
33+
34+
#include <Arduino_LoRaWAN_ttn.h>
35+
#include <Arduino_LoRaWAN_lmic.h>
36+
37+
/****************************************************************************\
38+
|
39+
| Manifest constants & typedefs.
40+
|
41+
\****************************************************************************/
42+
43+
44+
45+
/****************************************************************************\
46+
|
47+
| Read-only data.
48+
|
49+
\****************************************************************************/
50+
51+
52+
53+
/****************************************************************************\
54+
|
55+
| VARIABLES:
56+
|
57+
\****************************************************************************/
58+
59+
bool Arduino_LoRaWAN_ttn_base::NetBegin()
60+
{
61+
//
62+
// If no provisining info, return false.
63+
//
64+
if (this->GetProvisioningStyle() == ProvisioningStyle::kNone)
65+
return false;
66+
67+
// Set data rate and transmit power, based on regional considerations.
68+
this->NetBeginRegionInit();
69+
70+
//
71+
// this will succeed either if provisioned for Abp, or if Otaa and we
72+
// have successfully joined. Note that ABP is just exactly the same
73+
// as what happends after a join, so we use this for fetching all the
74+
// required information.
75+
//
76+
AbpProvisioningInfo abpInfo;
77+
78+
if (this->GetAbpProvisioningInfo(&abpInfo))
79+
{
80+
LMIC_setSession(/* port */ 1,
81+
abpInfo.DevAddr,
82+
abpInfo.NwkSKey,
83+
abpInfo.AppSKey
84+
);
85+
86+
// set the seqnoUp and seqnoDown
87+
// presumably if non-zero, somebody is stashing these
88+
// in NVR
89+
LMIC.seqnoUp = abpInfo.FCntUp;
90+
LMIC.seqnoDn = abpInfo.FCntDown;
91+
92+
// because it's ABP, we need to set up the parameters we'd set
93+
// after an OTAA join.
94+
this->NetJoin();
95+
}
96+
97+
return true;
98+
}

src/lib/ttn_eu868_netbegin.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* ttn_eu868_netbegin.cpp Sun Mar 12 2017 16:21:31 tmm */
2+
3+
/*
4+
5+
Module: ttn_eu868_netbegin.cpp
6+
7+
Function:
8+
Arduino_LoRaWAN_ttn_eu868::NetBegin()
9+
10+
Version:
11+
V0.2.2 Sun Mar 12 2017 16:21:31 tmm Edit level 2
12+
13+
Copyright notice:
14+
This file copyright (C) 2016-2017 by
15+
16+
MCCI Corporation
17+
3520 Krums Corners Road
18+
Ithaca, NY 14850
19+
20+
An unpublished work. All rights reserved.
21+
22+
This file is proprietary information, and may not be disclosed or
23+
copied without the prior permission of MCCI Corporation.
24+
25+
Author:
26+
Terry Moore, MCCI Corporation November 2016
27+
28+
Revision history:
29+
0.2.0 Tue Nov 1 2016 05:29:19 tmm
30+
Module created.
31+
32+
0.2.2 Sun Mar 12 2017 16:21:31 tmm
33+
Clarify documentation.
34+
35+
*/
36+
37+
#include <Arduino_LoRaWAN_ttn.h>
38+
#include <Arduino_LoRaWAN_lmic.h>
39+
40+
/****************************************************************************\
41+
|
42+
| Manifest constants & typedefs.
43+
|
44+
\****************************************************************************/
45+
46+
47+
48+
/****************************************************************************\
49+
|
50+
| Read-only data.
51+
|
52+
\****************************************************************************/
53+
54+
55+
56+
/****************************************************************************\
57+
|
58+
| VARIABLES:
59+
|
60+
\****************************************************************************/
61+
62+
// protected virtual
63+
void Arduino_LoRaWAN_ttn_eu868::NetBeginRegionInit()
64+
{
65+
//
66+
// for eu868, we don't need to do any special setup.
67+
//
68+
}

src/lib/ttn_eu868_netjoin.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* ttn_eu868_netjoin.cpp Fri May 19 2017 23:58:34 tmm */
2+
3+
/*
4+
5+
Module: ttn_eu868_netjoin.cpp
6+
7+
Function:
8+
Arduino_LoRaWAN_ttn_eu868::NetJoin()
9+
10+
Version:
11+
V0.2.3 Fri May 19 2017 23:58:34 tmm Edit level 1
12+
13+
Copyright notice:
14+
This file copyright (C) 2017 by
15+
16+
MCCI Corporation
17+
3520 Krums Corners Road
18+
Ithaca, NY 14850
19+
20+
An unpublished work. All rights reserved.
21+
22+
This file is proprietary information, and may not be disclosed or
23+
copied without the prior permission of MCCI Corporation.
24+
25+
Author:
26+
Terry Moore, MCCI Corporation May 2017
27+
28+
Revision history:
29+
0.2.3 Fri May 19 2017 23:58:34 tmm
30+
Module created.
31+
32+
*/
33+
34+
#include <Arduino_LoRaWAN_ttn.h>
35+
#include <Arduino_LoRaWAN_lmic.h>
36+
37+
/****************************************************************************\
38+
|
39+
| Manifest constants & typedefs.
40+
|
41+
| This is strictly for private types and constants which will not
42+
| be exported.
43+
|
44+
\****************************************************************************/
45+
46+
47+
48+
/****************************************************************************\
49+
|
50+
| Read-only data.
51+
|
52+
| If program is to be ROM-able, these must all be tagged read-only
53+
| using the ROM storage class; they may be global.
54+
|
55+
\****************************************************************************/
56+
57+
58+
59+
/****************************************************************************\
60+
|
61+
| VARIABLES:
62+
|
63+
| If program is to be ROM-able, these must be initialized
64+
| using the BSS keyword. (This allows for compilers that require
65+
| every variable to have an initializer.) Note that only those
66+
| variables owned by this module should be declared here, using the BSS
67+
| keyword; this allows for linkers that dislike multiple declarations
68+
| of objects.
69+
|
70+
\****************************************************************************/
71+
72+
73+
void Arduino_LoRaWAN_ttn_eu868::NetJoin()
74+
{
75+
// do the common work.
76+
this->Super::NetJoin();
77+
}

0 commit comments

Comments
 (0)