cyclic.cpp, lorawan.cpp: code sanitization
This commit is contained in:
parent
3e5a0e4058
commit
889ffe3a51
@ -21,12 +21,13 @@ void doHousekeeping() {
|
|||||||
do_reset();
|
do_reset();
|
||||||
|
|
||||||
spi_housekeeping();
|
spi_housekeeping();
|
||||||
|
lora_housekeeping();
|
||||||
|
|
||||||
// time sync once per TIME_SYNC_INTERVAL_MIN
|
// time sync once per TIME_SYNC_INTERVAL_MIN
|
||||||
#ifdef TIME_SYNC
|
#ifdef TIME_SYNC
|
||||||
if (millis() >= nextTimeSync) {
|
if (millis() >= nextTimeSync) {
|
||||||
nextTimeSync = millis() + TIME_SYNC_INTERVAL_MIN *
|
nextTimeSync = millis() + TIME_SYNC_INTERVAL_MIN *
|
||||||
60000; // set up next time sync period
|
60000; // set up next time sync period
|
||||||
do_timesync();
|
do_timesync();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -419,13 +419,6 @@ void user_request_network_time_callback(void *pVoidUserUTCTime,
|
|||||||
int flagSuccess) {
|
int flagSuccess) {
|
||||||
// Explicit conversion from void* to uint32_t* to avoid compiler errors
|
// Explicit conversion from void* to uint32_t* to avoid compiler errors
|
||||||
uint32_t *pUserUTCTime = (uint32_t *)pVoidUserUTCTime;
|
uint32_t *pUserUTCTime = (uint32_t *)pVoidUserUTCTime;
|
||||||
|
|
||||||
// A struct that will be populated by LMIC_getNetworkTimeReference.
|
|
||||||
// It contains the following fields:
|
|
||||||
// - tLocal: the value returned by os_GetTime() when the time
|
|
||||||
// request was sent to the gateway, and
|
|
||||||
// - tNetwork: the seconds between the GPS epoch and the time
|
|
||||||
// the gateway received the time request
|
|
||||||
lmic_time_reference_t lmicTimeReference;
|
lmic_time_reference_t lmicTimeReference;
|
||||||
|
|
||||||
if (flagSuccess != 1) {
|
if (flagSuccess != 1) {
|
||||||
@ -433,7 +426,7 @@ void user_request_network_time_callback(void *pVoidUserUTCTime,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate "lmic_time_reference"
|
// Populate lmic_time_reference
|
||||||
flagSuccess = LMIC_getNetworkTimeReference(&lmicTimeReference);
|
flagSuccess = LMIC_getNetworkTimeReference(&lmicTimeReference);
|
||||||
if (flagSuccess != 1) {
|
if (flagSuccess != 1) {
|
||||||
ESP_LOGW(TAG, "Network time request failed");
|
ESP_LOGW(TAG, "Network time request failed");
|
||||||
@ -443,18 +436,16 @@ void user_request_network_time_callback(void *pVoidUserUTCTime,
|
|||||||
// Update userUTCTime, considering the difference between the GPS and UTC
|
// Update userUTCTime, considering the difference between the GPS and UTC
|
||||||
// epoch, and the leap seconds
|
// epoch, and the leap seconds
|
||||||
*pUserUTCTime = lmicTimeReference.tNetwork + 315964800;
|
*pUserUTCTime = lmicTimeReference.tNetwork + 315964800;
|
||||||
|
|
||||||
// Add the delay between the instant the time was transmitted and
|
|
||||||
// the current time
|
|
||||||
|
|
||||||
// Current time, in ticks
|
// Current time, in ticks
|
||||||
ostime_t ticksNow = os_getTime();
|
ostime_t ticksNow = os_getTime();
|
||||||
// Time when the request was sent, in ticks
|
// Time when the request was sent, in ticks
|
||||||
ostime_t ticksRequestSent = lmicTimeReference.tLocal;
|
ostime_t ticksRequestSent = lmicTimeReference.tLocal;
|
||||||
|
// Add the delay between the instant the time was transmitted and
|
||||||
|
// the current time
|
||||||
uint32_t requestDelaySec = osticks2ms(ticksNow - ticksRequestSent) / 1000;
|
uint32_t requestDelaySec = osticks2ms(ticksNow - ticksRequestSent) / 1000;
|
||||||
*pUserUTCTime += requestDelaySec;
|
*pUserUTCTime += requestDelaySec;
|
||||||
|
|
||||||
// Update the system time with the time read from the network
|
// Update system time with time read from the network
|
||||||
setTime(*pUserUTCTime);
|
setTime(*pUserUTCTime);
|
||||||
ESP_LOGI(TAG, "Time synced by LoRa network to %02d:%02d:%02d", hour(),
|
ESP_LOGI(TAG, "Time synced by LoRa network to %02d:%02d:%02d", hour(),
|
||||||
minute(), second());
|
minute(), second());
|
||||||
|
Loading…
Reference in New Issue
Block a user