Arduino LMIC 6.0.1
Arduino LoRaWAN(r) MAC in C
Loading...
Searching...
No Matches
lmic.h File Reference

LMIC API. More...

#include "oslmic.h"
#include "lorabase.h"
#include "lmic_compat.h"
Include dependency graph for lmic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  bcninfo_t
 Information about the last and previous beacons. More...
struct  lmic_class_c_flags_u::lmic_class_c_flags_s
 the Class C operating flags More...
union  lmic_class_c_flags_u
 details of lmic_class_c_flags_t. More...
struct  lmic_class_c_requests_u::lmic_class_c_requests_s
 the Class C request flags More...
union  lmic_class_c_requests_u
 details of lmic_class_c_requests_t More...
struct  lmic_class_c_s
 details of class C state More...
struct  lmic_client_data_s
 contents of lmic_client_data_t More...
struct  lmic_radio_data_s
 Details of instance data for LMIC radio driver. More...
struct  lmic_t
 Instance data for the LMIC. More...
struct  lmic_time_reference_s
struct  rxsched_t

Macros

#define ARDUINO_LMIC_VERSION_COMPARE_GE(a, b)
 compare two semantic versions
#define ARDUINO_LMIC_VERSION_COMPARE_GT(a, b)
 compare two semantic versions
#define ARDUINO_LMIC_VERSION_COMPARE_LE(a, b)
 compare two semantic versions
#define ARDUINO_LMIC_VERSION_COMPARE_LT(a, b)
 compare two semantic versions
#define ARDUINO_LMIC_VERSION_TO_ORDINAL(v)
 convert a semantic version to an ordinal integer.
#define DR_RANGE_MAP(drlo, drhi)
 Construct a bit map of allowed datarates from drlo to drhi (both included).
#define LMIC_ERROR_NAME__INIT
 Macro to initalize a normal table of error name strings.
#define LMIC_ERROR_NAME_MULTISZ__INIT
 Macro to initialize a compressed string of error name strings.
#define LMIC_EVENT_NAME_MULTISZ__INIT
 Macro to initialize a compressed string of event strings.
#define LMIC_EVENT_NAME_TABLE__INIT
 Macro to initialize a normal table of event strings.

Typedefs

typedef s1_t lmic_beacon_error_t
 Error codes returned for beacon operations.
typedef struct lmic_client_data_s lmic_client_data_t
 abstract type for collection of client data that survives LMIC_reset().
typedef u4_t lmic_gpstime_t
 how the network represents time.
typedef struct lmic_radio_data_s lmic_radio_data_t
 Instance data for LMIC radio driver.
typedef u1_t lmic_radio_flags_t
 container type for radio request flags
typedef u1_t lmic_radio_state_t
 concrete type for holding the radio state mask.
typedef void LMIC_ABI_STD lmic_request_network_time_cb_t(void *pUserData, int flagSuccess)
 network time request callback function type
typedef int lmic_tx_error_t
 LMIC result codes, as an integer type.
typedef union lmic_class_c_flags_u lmic_class_c_flags_t
 internal state flacs for class C operation
typedef union lmic_class_c_requests_u lmic_class_c_requests_t
 requests from outside the LMIC to inside the LMIC, for class C
typedef struct lmic_class_c_s lmic_class_c_t
 the structure containing class C state

Enumerations

enum  {
}
enum  {
  RADIO_RST =0 , RADIO_TX =1 , RADIO_RX =2 , RADIO_RXON =3 ,
  RADIO_TX_AT =4 , RADIO_RXON_C =5
}
 radio driver request codes More...
enum  
 Only For Antenna Tuning Tests !
enum  { BCN_NONE = 0x00 , BCN_PARTIAL = 0x01 , BCN_FULL = 0x02 , BCN_NODRIFT = 0x04 , BCN_NODDIFF = 0x08 }
 Parsing and tracking states of beacons. More...
enum  {
  TXRX_ACK = 0x80 , TXRX_NACK = 0x40 , TXRX_NOPORT = 0x20 , TXRX_PORT = 0x10 ,
  TXRX_LENERR = 0x08 , TXRX_PING = 0x04 , TXRX_DNW2 = 0x02 , TXRX_DNW1 = 0x01
}
enum  { MAX_CLOCK_ERROR = 65536 , LMIC_kMaxClockError_ppm = 4000 }
enum  _ev_t
 Event codes for event callback.
enum  lmic_beacon_error_e { LMIC_BEACON_ERROR_INVALID = -2 , LMIC_BEACON_ERROR_WRONG_NETWORK = -1 , LMIC_BEACON_ERROR_SUCCESS_PARTIAL = 0 , LMIC_BEACON_ERROR_SUCCESS_FULL = 1 }
 Error codes returned for beacon operations. More...
enum  lmic_engine_update_state_e { lmic_EngineUpdateState_idle = 0 , lmic_EngineUpdateState_busy = 1 , lmic_EngineUpdateState_again = 2 }
enum  lmic_radio_flags_e { LMIC_RADIO_FLAGS_NO_RX_IQ_INVERSION = 1u << 0 }
 radio request flags More...
enum  lmic_radio_state_e {
  LMIC_RADIO_EV_NONE = 0u , LMIC_RADIO_EV_TXSTART = (1u << 0) , LMIC_RADIO_EV_TXDONE = (1u << 1) , LMIC_RADIO_EV_TXDEFER = (1u << 2) ,
  LMIC_RADIO_EV_TXUNKNOWN = (1u << 3) , LMIC_RADIO_EV_RXSTART = (1u << 4) , LMIC_RADIO_EV_RXDONE = (1u << 5) , LMIC_RADIO_EV_RXTIMEOUT = (1u << 6) ,
  LMIC_RADIO_EV_RXUNKNOWN = (1u << 7)
}
 radio driver state mask More...
enum  lmic_request_time_state_e { lmic_RequestTimeState_idle = 0 , lmic_RequestTimeState_tx , lmic_RequestTimeState_rx , lmic_RequestTimeState_success }
enum  lmic_tx_error_e {
  LMIC_ERROR_SUCCESS = 0 , LMIC_ERROR_TX_BUSY = -1 , LMIC_ERROR_TX_TOO_LARGE = -2 , LMIC_ERROR_TX_NOT_FEASIBLE = -3 ,
  LMIC_ERROR_TX_FAILED = -4
}
 LMIC error codes. More...

Functions

u1_t LMIC_getBatteryLevel (void)
 get battery level that is to be returned by DevStatusAns.
u1_t LMIC_queryNumDefaultChannels (void)
 get the number of (fixed) default channels before the programmable channels.
bit_t LMIC_queryTxReady (void)
 check whether the LMIC is ready for a transmit packet
u1_t LMIC_setBatteryLevel (u1_t)
 set battery level to be returned by DevStatusAns.
void LMIC_setSession (u4_t netid, devaddr_t devaddr, xref2u1_t nwkKey, xref2u1_t artKey)
 Set up keys for ABP.
bit_t LMIC_setupChannel (u1_t channel, u4_t freq, u2_t drmap, s1_t band)
 LMIC_setupChannel for EU 868.

Detailed Description

LMIC API.

Macro Definition Documentation

◆ ARDUINO_LMIC_VERSION_COMPARE_GE

#define ARDUINO_LMIC_VERSION_COMPARE_GE ( a,
b )
Value:
#define ARDUINO_LMIC_VERSION_TO_ORDINAL(v)
convert a semantic version to an ordinal integer.
Definition lmic.h:124

compare two semantic versions

Returns
true if a is greater than or equal to b (as a semantic version).

◆ ARDUINO_LMIC_VERSION_COMPARE_GT

#define ARDUINO_LMIC_VERSION_COMPARE_GT ( a,
b )
Value:

compare two semantic versions

Returns
true if a is greater than b (as a semantic version).

◆ ARDUINO_LMIC_VERSION_COMPARE_LE

#define ARDUINO_LMIC_VERSION_COMPARE_LE ( a,
b )
Value:

compare two semantic versions

Returns
true if a is less than or equal to b (as a semantic version).

◆ ARDUINO_LMIC_VERSION_COMPARE_LT

#define ARDUINO_LMIC_VERSION_COMPARE_LT ( a,
b )
Value:

compare two semantic versions

Returns
true if a is less than b (as a semantic version).

◆ LMIC_ERROR_NAME_MULTISZ__INIT

#define LMIC_ERROR_NAME_MULTISZ__INIT
Value:
"LMIC_ERROR_SUCCESS\0" \
"LMIC_ERROR_TX_BUSY\0" \
"LMIC_ERROR_TX_TOO_LARGE\0" \
"LMIC_ERROR_TX_NOT_FEASIBLE\0" \
"LMIC_ERROR_TX_FAILED"

Macro to initialize a compressed string of error name strings.

If compling for an AVR (or worried about it), you can use this multi-zero string and put this in a single const F() string. Index through this counting up from 0, until you get to the entry you want or to an entry that begins with a \0.

See also
LMIC_ERROR_NAME__INIT

◆ LMIC_EVENT_NAME_MULTISZ__INIT

#define LMIC_EVENT_NAME_MULTISZ__INIT
Value:
"<<zero>>\0" \
"EV_SCAN_TIMEOUT\0" "EV_BEACON_FOUND\0" \
"EV_BEACON_MISSED\0" "EV_BEACON_TRACKED\0" "EV_JOINING\0" \
"EV_JOINED\0" "EV_RFU1\0" "EV_JOIN_FAILED\0" "EV_REJOIN_FAILED\0" \
"EV_TXCOMPLETE\0" "EV_LOST_TSYNC\0" "EV_RESET\0" \
"EV_RXCOMPLETE\0" "EV_LINK_DEAD\0" "EV_LINK_ALIVE\0" "EV_SCAN_FOUND\0" \
"EV_TXSTART\0" "EV_TXCANCELED\0" "EV_RXSTART\0" "EV_JOIN_TXCOMPLETE\0"

Macro to initialize a compressed string of event strings.

iIf compiling for an AVR (or worried about it), you can use this multi-zero string and put this in a single const F() string. Index through this counting up from 0, until you get to the entry you want or to an

Typedef Documentation

◆ lmic_beacon_error_t

typedef s1_t lmic_beacon_error_t

Error codes returned for beacon operations.

See also
lmic_beacon_error_e

◆ lmic_class_c_flags_t

internal state flacs for class C operation

See also
lmic_class_c_flags_u

◆ lmic_class_c_requests_t

requests from outside the LMIC to inside the LMIC, for class C

Enabling and disabling Class C operation can happen from outside the LMIC, or as the result of processing a callback. It's very fragile to require users to understand the LMIC state, so (at least for Class C), we provide APIs that are safe to call at any time. The tradeoff is that the operation is asynchronous – it doesn't complete until the LMIC gets scheduled. An object of this type is used to represent these requests.

See also
lmic_class_c_requests_u

◆ lmic_class_c_t

the structure containing class C state

State for class C operations are incapsulated in a single object, so that conditional compiles are easier to read.

See also
lmic_class_c_s

◆ lmic_client_data_t

abstract type for collection of client data that survives LMIC_reset().

There are a variety of client registration linkage items that must live through LMIC_reset(), because LMIC_reset() is called at frame-rollover time. We group them together into a structure to make copies easy.

See also
lmic_client_data_s

◆ lmic_radio_data_t

Instance data for LMIC radio driver.

Eventually this will be used for all portable things for the radio driver, but for now it's where we can start to add things.

◆ lmic_radio_flags_t

typedef u1_t lmic_radio_flags_t

container type for radio request flags

See also
lmic_radio_flags_e

◆ lmic_radio_state_t

typedef u1_t lmic_radio_state_t

concrete type for holding the radio state mask.

container type for radio driver state mask

Must be wide enough to hold values of type lmic_radio_state_e.

See also
lmic_radio_state_e
lmic_radio_state_e

◆ lmic_request_network_time_cb_t

typedef void LMIC_ABI_STD lmic_request_network_time_cb_t(void *pUserData, int flagSuccess)

network time request callback function type

Parameters
pUserData[in] value passed to corresponding network time request.
flagSuccess[in] true if a network time was received, otherwise false.

A function of this type is called when a time-request succeeds or when we get a downlink without time request, "completing" the pending time request.

Note
This function is defined unconditionally (even if network time support is not enabled), because we don't want APIs and types to change based on config.

◆ lmic_tx_error_t

typedef int lmic_tx_error_t

LMIC result codes, as an integer type.

See also
lmic_tx_error_e

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OP_SCAN 

radio scan to find a beacon

OP_TRACK 

track my networks beacon (netid)

OP_JOINING 

device joining in progress (blocks other activities)

OP_TXDATA 

TX user data (buffered in pendTxData).

OP_POLL 

send empty UP frame to ACK confirmed DN/fetch more DN data

OP_REJOIN 

occasionally send JOIN REQUEST

OP_SHUTDOWN 

prevent MAC from doing anything

OP_TXRXPEND 

TX/RX transaction pending.

OP_RNDTX 

prevent TX lining up after a beacon

OP_PINGINI 

pingable is initialized and scheduling active

OP_PINGABLE 

we're pingable

OP_NEXTCHNL 

find a new channel

OP_LINKDEAD 

link was reported as dead

OP_TESTMODE 

developer test mode

OP_UNJOIN 

unjoin and rejoin on next engineUpdate().

◆ anonymous enum

anonymous enum

radio driver request codes

Enumerator
RADIO_RST 

reset, canceling any pending operations.

RADIO_TX 

transmit.

RADIO_RX 

receive single with time window

RADIO_RXON 

receive without time window

RADIO_TX_AT 

transmit at a specific time

RADIO_RXON_C 

open the class C window if possible.

◆ anonymous enum

anonymous enum

Parsing and tracking states of beacons.

Enumerator
BCN_NONE 

No beacon received.

BCN_PARTIAL 

Only first (common) part could be decoded (info,lat,lon invalid/previous).

BCN_FULL 

Full beacon decoded.

BCN_NODRIFT 

No drift value measured yet.

◆ anonymous enum

anonymous enum
Enumerator
TXRX_ACK 

confirmed UP frame was acked

TXRX_NACK 

confirmed UP frame was not acked

TXRX_NOPORT 

set if a frame with a port was RXed, clr if no frame/no port

TXRX_PORT 

set if a frame with a port was RXed, LMIC.frame[LMIC.dataBeg-1] => port

TXRX_LENERR 

set if frame was discarded due to length error.

TXRX_PING 

received in a scheduled RX slot or class C

TXRX_DNW2 

received in 2dn DN slot or class C

TXRX_DNW1 

received in 1st DN slot

◆ anonymous enum

anonymous enum
Enumerator
MAX_CLOCK_ERROR 

This value represents 100% error in LMIC.clockError.

LMIC_kMaxClockError_ppm 

maximum clock error that users can specify: 4000 ppm (0.4%).

This is the limit for clock error, unless LMIC_ENABLE_arbitrary_clock_error is set. The default is 4,000 ppm, which is .004, or 0.4%; this is what you get on an STM32L0 running with the HSI oscillator after cal. If your clock error is bigger, usually you want to calibrate it so that millis() and micros() are reasonably accurate. Important: do not use clock error to compensate for late serving of the LMIC. If you see that LMIC.radio.rxlate_count is increasing, you need to adjust your application logic so the LMIC gets serviced promptly when a Class A downlink (or beacon) is pending.

◆ lmic_beacon_error_e

Error codes returned for beacon operations.

Enumerator
LMIC_BEACON_ERROR_INVALID 

Invalid beacon received.

LMIC_BEACON_ERROR_WRONG_NETWORK 

Beacon received for wrong network.

LMIC_BEACON_ERROR_SUCCESS_PARTIAL 

Partial success; first set of fields are OK.

LMIC_BEACON_ERROR_SUCCESS_FULL 

Full beacon successfuly received.

◆ lmic_engine_update_state_e

Enumerator
lmic_EngineUpdateState_idle 

engineUpdate is idle.

lmic_EngineUpdateState_busy 

engineUpdate is busy, but has not been reentered.

lmic_EngineUpdateState_again 

engineUpdate is busy, and has to be evaluated again.

◆ lmic_radio_flags_e

radio request flags

Enumerator
LMIC_RADIO_FLAGS_NO_RX_IQ_INVERSION 

if set, don't invert IQ on receive

◆ lmic_radio_state_e

radio driver state mask

Enumerator
LMIC_RADIO_EV_NONE 

no events reported

LMIC_RADIO_EV_TXSTART 

transmit started

LMIC_RADIO_EV_TXDONE 

transmit complete, TXSTART will still be set

LMIC_RADIO_EV_TXDEFER 

transmit deferred (LBT)

LMIC_RADIO_EV_TXUNKNOWN 

transmit unknown event.

LMIC_RADIO_EV_RXSTART 

receive started

LMIC_RADIO_EV_RXDONE 

rx complete

LMIC_RADIO_EV_RXTIMEOUT 

rx timed out; RXDONE also set.

LMIC_RADIO_EV_RXUNKNOWN 

rx timed out, not sure whay.

◆ lmic_request_time_state_e

Enumerator
lmic_RequestTimeState_idle 

we're not doing anything

lmic_RequestTimeState_tx 

we want to tx a time request on next uplink

lmic_RequestTimeState_rx 

we have tx'ed, next downlink completes.

lmic_RequestTimeState_success 

we sucessfully got time.

◆ lmic_tx_error_e

LMIC error codes.

Enumerator
LMIC_ERROR_SUCCESS 

No error.

LMIC_ERROR_TX_BUSY 

Transmit path was busy, mesage rejected.

LMIC_ERROR_TX_TOO_LARGE 

Message was too long for configured LMIC buffers.

LMIC_ERROR_TX_NOT_FEASIBLE 

Message was too long given region, spreading factor, and network settings.

LMIC_ERROR_TX_FAILED 

Transmit failed for unspecified reason.

Function Documentation

◆ LMIC_getBatteryLevel()

u1_t LMIC_getBatteryLevel ( void )

get battery level that is to be returned by DevStatusAns.

Returns
This function returns the saved value of the battery level (as used for the DevStatusAns message).
See also
LMIC_setBatteryLevel()

◆ LMIC_queryNumDefaultChannels()

u1_t LMIC_queryNumDefaultChannels ( void )

get the number of (fixed) default channels before the programmable channels.

get the number of (fixed) default channels before the programmable channels.

◆ LMIC_setBatteryLevel()

u1_t LMIC_setBatteryLevel ( u1_t uBattLevel)

set battery level to be returned by DevStatusAns.

Parameters
uBattLevelis the 8-bit value to be returned. Per LoRaWAN 1.0.3 line 769, this is MCMD_DEVS_EXT_POWER (0) if on external power, MCMD_DEVS_NOINFO (255) if not able to measure battery level, or a value in [ MCMD_DEVS_BATT_MIN, MCMD_DEVS_BATT_MAX ], numerically [1, 254], to represent the charge state of the battery. Note that this is not millivolts.
Returns
This function returns the previous value of the battery level.

The LMIC maintains an idea of the current battery state, initially set to MCMD_DEVS_NOINFO after the call to LMIC_init(). The appplication then calls this function from time to time to update the battery level.

It is possible (in non-Arduino environments) to supply a local implementation of os_getBatteryLevel(). In that case, it's up to the implementation to decide whether to use the value supplied by this API.

This implementation was chosen to minimize the risk of a battery measurement introducting breaking delays into the LMIC.

◆ LMIC_setSession()

void LMIC_setSession ( u4_t netid,
devaddr_t devaddr,
xref2u1_t nwkKey,
xref2u1_t artKey )

Set up keys for ABP.

The LMIC stores the given session keys and put thes MAC in a state as if a join request/accept had just negotiated these keys.

Parameters
netida 24-bit number describing the network id this device is using
devaddrthe 32-bit session address of the device. It is strongly recommended to ensure that different devices use different numbers with high probability.
nwkKeythe 16-byte network session key used for message integrity. If NULL the caller has copied the key into LMIC.nwkKey before.
artKeythe 16-byte application router session key used for message confidentiality. If NULL the caller has copied the key into LMIC.artKey before.
Note
On Harvard architectures, if session keys are in flash and not accessible via normal C pointers, caller must fill in LMIC.{nwk,art}Key separately and pass {nwk,art}Key as NULL.
It is crucial that the combinations devaddr/nwkkey and devaddr/artkey are unique within the network identified by netid.

References OP_JOINING, OP_NEXTCHNL, OP_PINGINI, OP_REJOIN, OP_TRACK, OP_TXRXPEND, OP_UNJOIN, and os_copyMem.

◆ LMIC_setupChannel()

bit_t LMIC_setupChannel ( u1_t chidx,
u4_t freq,
u2_t drmap,
s1_t band )

LMIC_setupChannel for EU 868.

Note
according to LoRaWAN 1.0.3 section 5.6, "the acceptable range for **ChIndex** is N to 16", where N is our NUM_DEFAULT_CHANNELS. This routine is used internally for MAC commands, so we enforce this for the extenal API as well.

References DR_RANGE_MAP, and LMIC_setupChannel().

Referenced by LMIC_setupChannel().