Arduino LMIC 6.0.1
Arduino LoRaWAN(r) MAC in C
Loading...
Searching...
No Matches
lmic_us_like.h
1/*
2* Copyright (c) 2014-2016 IBM Corporation.
3* Copyright (c) 2017, 2019 MCCI Corporation.
4* All rights reserved.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* * Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of the <organization> nor the
14* names of its contributors may be used to endorse or promote products
15* derived from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#ifndef _lmic_us_like_h_
30# define _lmic_us_like_h_
31
32#ifndef _lmic_env_h_
33# include "lmic_env.h"
34#endif
35
36LMIC_BEGIN_DECLS
37
38// make sure we want US-like code
39#if !CFG_LMIC_US_like
40# error "lmic not configured for us-like bandplan"
41#endif
42
43// TODO(tmm@mcci.com): this should come from the lmic.h or lorabase.h file; and
44// it's probably affected by the fix to this issue:
45// https://github.com/mcci-catena/arduino-lmic/issues/2
46#define DNW2_SAFETY_ZONE ms2osticks(750)
47
48#define IS_CHANNEL_125khz(c) (c<64)
49#define IS_CHANNEL_500khz(c) (c>=64 && c<72)
50#define ENABLED_CHANNEL(chnl) ((LMIC.channelMap[(chnl >> 4)] & (1<<(chnl & 0x0F))) != 0)
51
52// library functions: called from bandplan
53void LMICuslike_initJoinLoop(void);
54
55// provide the isValidBeacon1 function -- int for bool.
56static inline int
57LMICuslike_isValidBeacon1(const uint8_t *d) {
58 return os_rlsbf2(&d[OFF_BCN_CRC1]) != os_crc16(d, OFF_BCN_CRC1);
59}
60
61#define LMICbandplan_isValidBeacon1(pFrame) LMICuslike_isValidBeacon1(pFrame)
62
63// provide a default for LMICbandplan_isFSK()
64#define LMICbandplan_isFSK() (0)
65
66// provide a default LMICbandplan_txDoneFSK()
67#define LMICbandplan_txDoneFSK(delay, func) do { } while (0)
68
69// provide a default LMICbandplan_joinAcceptChannelClear()
70#define LMICbandplan_joinAcceptChannelClear() do { } while (0)
71
73#define LMICbandplan_hasJoinCFlist() (1)
74
76void LMICuslike_processJoinAcceptCFList(void);
78#define LMICbandplan_processJoinAcceptCFList LMICuslike_processJoinAcceptCFList
79
80
81#define LMICbandplan_advanceBeaconChannel() \
82 do { LMIC.bcnChnl = (LMIC.bcnChnl+1) & 7; } while (0)
83
84// TODO(tmm@mcci.com): decide whether we want to do this on every
85// reset or just restore the last sub-band selected by the user.
86#define LMICbandplan_resetDefaultChannels() \
87 LMICbandplan_initDefaultChannels(/* normal */ 0)
88
89void LMICuslike_initDefaultChannels(bit_t fJoin);
90#define LMICbandplan_initDefaultChannels(fJoin) LMICuslike_initDefaultChannels(fJoin)
91
92#define LMICbandplan_setSessionInitDefaultChannels() \
93 do { /* nothing */} while (0)
94
95bit_t LMICuslike_canMapChannels(u1_t chpage, u2_t chmap);
96#define LMICbandplan_canMapChannels(chpage, chmap) LMICuslike_canMapChannels(chpage, chmap)
97
98bit_t LMICuslike_mapChannels(u1_t chpage, u2_t chmap);
99#define LMICbandplan_mapChannels(chpage, chmap) LMICuslike_mapChannels(chpage, chmap)
100
101ostime_t LMICuslike_nextTx(ostime_t now);
102#define LMICbandplan_nextTx(now) LMICuslike_nextTx(now)
103
104ostime_t LMICuslike_nextJoinState(void);
105#define LMICbandplan_nextJoinState() LMICuslike_nextJoinState();
106
107static inline ostime_t LMICuslike_nextJoinTime(ostime_t now) {
108 return now;
109}
110#define LMICbandplan_nextJoinTime(now) LMICuslike_nextJoinTime(now)
111
112#define LMICbandplan_init() \
113 do { /* nothing */ } while (0)
114
115void LMICuslike_saveAdrState(lmic_saved_adr_state_t *pStateBuffer);
116#define LMICbandplan_saveAdrState(pState) LMICuslike_saveAdrState(pState)
117
118bit_t LMICuslike_compareAdrState(const lmic_saved_adr_state_t *pStateBuffer);
119#define LMICbandplan_compareAdrState(pState) LMICuslike_compareAdrState(pState)
120
121void LMICuslike_restoreAdrState(const lmic_saved_adr_state_t *pStateBuffer);
122#define LMICbandplan_restoreAdrState(pState) LMICuslike_restoreAdrState(pState)
123
124bit_t LMICuslike_isDataRateFeasible(dr_t dr);
125#define LMICbandplan_isDataRateFeasible(dr) LMICuslike_isDataRateFeasible(dr)
126
131void LMICuslike_saveChannelState(u1_t *pVariant, ostime_t now);
132#define LMICbandplan_saveChannelState(p, now) LMICuslike_saveChannelState(p, now)
133
137bit_t LMICuslike_restoreChannelState(const u1_t *pVariant, ostime_t now, u1_t version);
138#define LMICbandplan_restoreChannelState(p, now, v) LMICuslike_restoreChannelState(p, now, v)
139
140LMIC_END_DECLS
141
142#endif // _lmic_us_like_h_
u2_t os_rlsbf2(xref2cu1_t buf)
Read 16-bit quantity from given pointer in little endian byte order.
Definition lmic.c:80