mirror of https://github.com/ARMmbed/mbed-os.git
Switch to millisecond resolution gps time
The existing gps time resolution is seconds, while class b beacon and ping slot scheduling requires millisecond resolution. This set of changes switches gps time to millisecond resolution.feature-lorawan-1-1
parent
d7a57fb0f3
commit
42ddb617d9
|
@ -66,20 +66,18 @@ void LoRaWANTimeHandler::stop(timer_event_t &obj)
|
||||||
obj.timer_id = 0;
|
obj.timer_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_time_t LoRaWANTimeHandler::get_gps_time(void)
|
void LoRaWANTimeHandler::set_gps_time(lorawan_gps_time_t gps_time)
|
||||||
{
|
|
||||||
if (_gps_time == 0) {
|
|
||||||
return _gps_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _gps_time + floor((get_current_time() - _monotonic_tick_time) / 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoRaWANTimeHandler::set_gps_time(lorawan_time_t gps_time)
|
|
||||||
{
|
{
|
||||||
// store in seconds
|
// store in seconds
|
||||||
_gps_time = gps_time;
|
_gps_time = gps_time;
|
||||||
// store snapshot of current tick time in (ms)
|
// store snapshot of current tick time in (ms)
|
||||||
_monotonic_tick_time = get_current_time();
|
_monotonic_tick_time = get_current_time();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lorawan_gps_time_t LoRaWANTimeHandler::get_gps_time(void)
|
||||||
|
{
|
||||||
|
if(_gps_time == 0){
|
||||||
|
return _gps_time;
|
||||||
|
}
|
||||||
|
return _gps_time + get_current_time() - _monotonic_tick_time;
|
||||||
|
}
|
|
@ -90,10 +90,10 @@ public:
|
||||||
* tick time and current tick time.
|
* tick time and current tick time.
|
||||||
* If the GPS time was not set by the network yet, the API returns zero.
|
* If the GPS time was not set by the network yet, the API returns zero.
|
||||||
*
|
*
|
||||||
* @return Current GPS time in seconds
|
* @return Current GPS time in millisseconds
|
||||||
* Or 0 if the GPS time is not yet set by the network
|
* Or 0 if the GPS time is not yet set by the network
|
||||||
*/
|
*/
|
||||||
lorawan_time_t get_gps_time(void);
|
lorawan_gps_time_t get_gps_time(void);
|
||||||
|
|
||||||
/** Store GPS time received from the network
|
/** Store GPS time received from the network
|
||||||
*
|
*
|
||||||
|
@ -103,19 +103,20 @@ public:
|
||||||
* GPS time and the forthcoming CPU tick. Please refer to `get_gps_time()` API
|
* GPS time and the forthcoming CPU tick. Please refer to `get_gps_time()` API
|
||||||
* documentation for more information.
|
* documentation for more information.
|
||||||
*
|
*
|
||||||
* It is important that the caller relays the network provided GPS time (in seconds)
|
* It is important that the caller relays the network provided GPS time (in milliseconds)
|
||||||
* as it is without adjustment (for leap seconds or conversions to TAI/UTC etc).
|
* as it is without adjustment (for leap seconds or conversions to TAI/UTC etc).
|
||||||
* The rationale here is that we are not setting system time here. This time base
|
* The rationale here is that we are not setting system time here. This time base
|
||||||
* is used only for device level synchronization with network.
|
* is used only for device level synchronization with network.
|
||||||
*
|
*
|
||||||
* @param gps_time Current GPS time provided by the network (seconds)
|
* @param gps_time Current GPS time provided by the network (milliseconds)
|
||||||
*/
|
*/
|
||||||
void set_gps_time(lorawan_time_t gps_time);
|
void set_gps_time(lorawan_gps_time_t gps_time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
events::EventQueue *_queue;
|
events::EventQueue *_queue;
|
||||||
lorawan_time_t _gps_time; // seconds
|
lorawan_gps_time_t _gps_time; // gps time in milliseconds
|
||||||
lorawan_time_t _monotonic_tick_time; //milliseconds
|
lorawan_time_t _monotonic_tick_time; //milliseconds
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MBED_LORAWAN_SYS_TIMER_H__
|
#endif // MBED_LORAWAN_SYS_TIMER_H__
|
||||||
|
|
|
@ -44,6 +44,14 @@
|
||||||
typedef uint32_t lorawan_time_t;
|
typedef uint32_t lorawan_time_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief GPS time in milliseconds
|
||||||
|
*/
|
||||||
|
#ifndef lorawan_gps_time_t
|
||||||
|
typedef uint64_t lorawan_gps_time_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Sets the length of the LoRaMAC footer field.
|
* Sets the length of the LoRaMAC footer field.
|
||||||
* Mainly indicates the MIC field length.
|
* Mainly indicates the MIC field length.
|
||||||
|
@ -79,6 +87,12 @@ typedef uint32_t lorawan_time_t;
|
||||||
#define MBED_CONF_LORA_TX_MAX_SIZE 255
|
#define MBED_CONF_LORA_TX_MAX_SIZE 255
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Network Beacon Gateway Specific field length
|
||||||
|
*/
|
||||||
|
#define LORAMAC_BEACON_GW_SPECIFIC_LEN 7
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* LoRaMAC band parameters definition.
|
* LoRaMAC band parameters definition.
|
||||||
*/
|
*/
|
||||||
|
@ -148,9 +162,22 @@ typedef enum {
|
||||||
*/
|
*/
|
||||||
RX_SLOT_WIN_CLASS_C,
|
RX_SLOT_WIN_CLASS_C,
|
||||||
/*!
|
/*!
|
||||||
* LoRaMAC class b ping slot window
|
* LoRaMAC class b unicast ping slot window
|
||||||
*/
|
*/
|
||||||
RX_SLOT_WIN_PING_SLOT
|
RX_SLOT_WIN_UNICAST_PING_SLOT,
|
||||||
|
/*!
|
||||||
|
* LoRaMAC class b multicast ping slot window
|
||||||
|
*/
|
||||||
|
RX_SLOT_WIN_MULTICAST_PING_SLOT,
|
||||||
|
/*!
|
||||||
|
* LoRaMAC class b beacon window
|
||||||
|
*/
|
||||||
|
RX_SLOT_BEACON,
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Put new slot types before here
|
||||||
|
*/
|
||||||
|
RX_SLOT_MAX
|
||||||
} rx_slot_t;
|
} rx_slot_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -184,6 +211,31 @@ typedef enum {
|
||||||
FOPTS
|
FOPTS
|
||||||
} payload_type_t;
|
} payload_type_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* LoRaMAC ping slot parameters.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
/*!
|
||||||
|
* Unicast ping slot periodicity
|
||||||
|
*/
|
||||||
|
uint8_t periodicity;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Number of ping slots per beacon period
|
||||||
|
*/
|
||||||
|
uint8_t ping_nb;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Period of the device wake-up expressed in number of slots
|
||||||
|
*/
|
||||||
|
uint16_t ping_period;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Randomized ping slot offset
|
||||||
|
*/
|
||||||
|
uint16_t ping_offset;
|
||||||
|
} ping_slot_params_t;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* The global MAC layer parameters.
|
* The global MAC layer parameters.
|
||||||
*/
|
*/
|
||||||
|
@ -260,6 +312,12 @@ typedef struct {
|
||||||
* LoRaMac ADR control status
|
* LoRaMac ADR control status
|
||||||
*/
|
*/
|
||||||
bool adr_on;
|
bool adr_on;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Class B ping slot configuration
|
||||||
|
*/
|
||||||
|
ping_slot_params_t ping_slot;
|
||||||
|
|
||||||
} lora_mac_system_params_t;
|
} lora_mac_system_params_t;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -337,59 +395,72 @@ typedef enum {
|
||||||
/*!
|
/*!
|
||||||
* ResetInd
|
* ResetInd
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_RESET_IND = 0x01,
|
MOTE_MAC_RESET_IND = 0x01,
|
||||||
/*!
|
/*!
|
||||||
* LinkCheckReq
|
* LinkCheckReq
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_LINK_CHECK_REQ = 0x02,
|
MOTE_MAC_LINK_CHECK_REQ = 0x02,
|
||||||
/*!
|
/*!
|
||||||
* LinkADRAns
|
* LinkADRAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_LINK_ADR_ANS = 0x03,
|
MOTE_MAC_LINK_ADR_ANS = 0x03,
|
||||||
/*!
|
/*!
|
||||||
* DutyCycleAns
|
* DutyCycleAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_DUTY_CYCLE_ANS = 0x04,
|
MOTE_MAC_DUTY_CYCLE_ANS = 0x04,
|
||||||
/*!
|
/*!
|
||||||
* RXParamSetupAns
|
* RXParamSetupAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_RX_PARAM_SETUP_ANS = 0x05,
|
MOTE_MAC_RX_PARAM_SETUP_ANS = 0x05,
|
||||||
/*!
|
/*!
|
||||||
* DevStatusAns
|
* DevStatusAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_DEV_STATUS_ANS = 0x06,
|
MOTE_MAC_DEV_STATUS_ANS = 0x06,
|
||||||
/*!
|
/*!
|
||||||
* NewChannelAns
|
* NewChannelAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_NEW_CHANNEL_ANS = 0x07,
|
MOTE_MAC_NEW_CHANNEL_ANS = 0x07,
|
||||||
/*!
|
/*!
|
||||||
* RXTimingSetupAns
|
* RXTimingSetupAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_RX_TIMING_SETUP_ANS = 0x08,
|
MOTE_MAC_RX_TIMING_SETUP_ANS = 0x08,
|
||||||
/*!
|
/*!
|
||||||
* TXParamSetupAns
|
* TXParamSetupAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_TX_PARAM_SETUP_ANS = 0x09,
|
MOTE_MAC_TX_PARAM_SETUP_ANS = 0x09,
|
||||||
/*!
|
/*!
|
||||||
* DlChannelAns
|
* DlChannelAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_DL_CHANNEL_ANS = 0x0A,
|
MOTE_MAC_DL_CHANNEL_ANS = 0x0A,
|
||||||
/*!
|
/*!
|
||||||
* RekeyInd
|
* RekeyInd
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_REKEY_IND = 0x0B,
|
MOTE_MAC_REKEY_IND = 0x0B,
|
||||||
/*!
|
/*!
|
||||||
* ADRParamSetupAns
|
* ADRParamSetupAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_ADR_PARAM_SETUP_ANS = 0x0C,
|
MOTE_MAC_ADR_PARAM_SETUP_ANS = 0x0C,
|
||||||
/*!
|
/*!
|
||||||
* DeviceTimeReq
|
* DeviceTimeReq
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_DEVICE_TIME_REQ = 0x0D,
|
MOTE_MAC_DEVICE_TIME_REQ = 0x0D,
|
||||||
/*!
|
/*!
|
||||||
* RejoinParamSetupAns
|
* RejoinParamSetupAns
|
||||||
*/
|
*/
|
||||||
MOTE_MAC_REJOIN_PARAM_SETUP_ANS = 0x0F,
|
MOTE_MAC_REJOIN_PARAM_SETUP_ANS = 0x0F,
|
||||||
|
/*!
|
||||||
|
* PingSlotInfoReq
|
||||||
|
*/
|
||||||
|
MOTE_MAC_PING_SLOT_INFO_REQ = 0x10,
|
||||||
|
/*!
|
||||||
|
* PingSlotChannelAns
|
||||||
|
*/
|
||||||
|
MOTE_MAC_PING_SLOT_CHANNEL_ANS = 0x11,
|
||||||
|
/*!
|
||||||
|
* BeaconFreqAns
|
||||||
|
*/
|
||||||
|
MOTE_MAC_BEACON_FREQ_ANS = 0x13,
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* DeviceModeInd
|
* DeviceModeInd
|
||||||
*/
|
*/
|
||||||
|
@ -462,6 +533,18 @@ typedef enum {
|
||||||
* RejoinParamSetupReq
|
* RejoinParamSetupReq
|
||||||
*/
|
*/
|
||||||
SRV_MAC_REJOIN_PARAM_SETUP_REQ = 0x0F,
|
SRV_MAC_REJOIN_PARAM_SETUP_REQ = 0x0F,
|
||||||
|
/*!
|
||||||
|
* PingSlotInfoAns
|
||||||
|
*/
|
||||||
|
SRV_MAC_PING_SLOT_INFO_ANS = 0x10,
|
||||||
|
/*!
|
||||||
|
* PingSlotChannelReq
|
||||||
|
*/
|
||||||
|
SRV_MAC_PING_SLOT_CHANNEL_REQ = 0x11,
|
||||||
|
/*!
|
||||||
|
* BeaconFreqReq
|
||||||
|
*/
|
||||||
|
SRV_MAC_BEACON_FREQ_REQ = 0x13,
|
||||||
/*!
|
/*!
|
||||||
* DeviceModeConf
|
* DeviceModeConf
|
||||||
*/
|
*/
|
||||||
|
@ -538,9 +621,10 @@ typedef union {
|
||||||
*/
|
*/
|
||||||
uint8_t fopts_len : 4;
|
uint8_t fopts_len : 4;
|
||||||
/*!
|
/*!
|
||||||
* Frame pending bit.
|
* RFU (Used for downlink frame pending or uplink class b mode)
|
||||||
*/
|
*/
|
||||||
uint8_t fpending : 1;
|
uint8_t rfu : 1;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Message acknowledge bit.
|
* Message acknowledge bit.
|
||||||
*/
|
*/
|
||||||
|
@ -611,6 +695,11 @@ typedef enum {
|
||||||
* Crypto methods failure
|
* Crypto methods failure
|
||||||
*/
|
*/
|
||||||
LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL,
|
LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL,
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Network Beacon not found
|
||||||
|
*/
|
||||||
|
LORAMAC_EVENT_INFO_STATUS_BEACON_NOT_FOUND,
|
||||||
} loramac_event_info_status_t;
|
} loramac_event_info_status_t;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -776,6 +865,7 @@ typedef struct {
|
||||||
* ---------------------------- | :-----: | :--------: | :------: | :-----:
|
* ---------------------------- | :-----: | :--------: | :------: | :-----:
|
||||||
* \ref MLME_LINK_CHECK | YES | NO | NO | YES
|
* \ref MLME_LINK_CHECK | YES | NO | NO | YES
|
||||||
* \ref MLME_SCHEDULE_UPLINK | NO | YES | NO | NO
|
* \ref MLME_SCHEDULE_UPLINK | NO | YES | NO | NO
|
||||||
|
* \ref MLME_BEACON_ACQUISITION | YES | NO | NO | YES
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -825,7 +915,25 @@ typedef enum {
|
||||||
* Indicates that device has received force rejoin MAC command
|
* Indicates that device has received force rejoin MAC command
|
||||||
* LoRaWAN specification V1.1, chapter 5.13
|
* LoRaWAN specification V1.1, chapter 5.13
|
||||||
*/
|
*/
|
||||||
MLME_FORCE_REJOIN
|
MLME_FORCE_REJOIN,
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Initiates network beacon acquisition
|
||||||
|
*/
|
||||||
|
MLME_BEACON_ACQUISITION,
|
||||||
|
|
||||||
|
MLME_BEACON_LOCK,
|
||||||
|
|
||||||
|
MLME_BEACON_MISS,
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* PingSlotInfoReq - Indicates ping unicast slot periodicity
|
||||||
|
* synchronized with the server
|
||||||
|
*
|
||||||
|
* LoRaWAN Specification V1.1, chapter 14.1
|
||||||
|
*/
|
||||||
|
MLME_PING_SLOT_INFO
|
||||||
|
|
||||||
} mlme_type_t;
|
} mlme_type_t;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1472,7 +1580,38 @@ typedef struct {
|
||||||
* \brief forced_datarate See ForceRejoinReq LW 1.1 spec ch 5.13
|
* \brief forced_datarate See ForceRejoinReq LW 1.1 spec ch 5.13
|
||||||
*/
|
*/
|
||||||
uint8_t forced_datarate;
|
uint8_t forced_datarate;
|
||||||
|
|
||||||
} loramac_protocol_params;
|
} loramac_protocol_params;
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* LoRaMAC beacon status
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
/*!
|
||||||
|
* Network beacon acquisition success
|
||||||
|
*/
|
||||||
|
BEACON_STATUS_ACQUISITION_SUCCESS,
|
||||||
|
/*!
|
||||||
|
* Network beacon acquisition failed
|
||||||
|
*/
|
||||||
|
BEACON_STATUS_ACQUISITION_FAILED,
|
||||||
|
/*!
|
||||||
|
* Network beacon received
|
||||||
|
*/
|
||||||
|
BEACON_STATUS_LOCK,
|
||||||
|
/*!
|
||||||
|
* Network beacon not received (lock -> miss)
|
||||||
|
*/
|
||||||
|
BEACON_STATUS_MISS,
|
||||||
|
} loramac_beacon_status_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* LoRaMAC beacon information
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint32_t time; // beacon time
|
||||||
|
uint32_t time_on_air; // beacon frame time on air
|
||||||
|
uint8_t gw_specific[LORAMAC_BEACON_GW_SPECIFIC_LEN]; // info descriptior + info (15.3)
|
||||||
|
} loramac_beacon_t;
|
||||||
|
|
||||||
#endif /* LORAWAN_SYSTEM_LORAWAN_DATA_STRUCTURES_H_ */
|
#endif /* LORAWAN_SYSTEM_LORAWAN_DATA_STRUCTURES_H_ */
|
||||||
|
|
Loading…
Reference in New Issue