Merge pull request #565 from cyberman54/development

timesync.cpp: minor sanitizations
This commit is contained in:
Verkehrsrot 2020-03-04 23:40:24 +01:00 committed by GitHub
commit b2eafa0b17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -241,11 +241,9 @@ void timesync_init() {
#if (TIME_SYNC_LORAWAN) && (HAS_LORA) #if (TIME_SYNC_LORAWAN) && (HAS_LORA)
static time_t networkUTCTime;
// send time request message // send time request message
void send_timesync_req(void) { void send_timesync_req(void) {
LMIC_requestNetworkTime(process_timesync_req, &networkUTCTime); LMIC_requestNetworkTime(process_timesync_req, NULL);
} }
void IRAM_ATTR process_timesync_req(void *pVoidUserUTCTime, int flagSuccess) { void IRAM_ATTR process_timesync_req(void *pVoidUserUTCTime, int flagSuccess) {
@ -258,7 +256,7 @@ void IRAM_ATTR process_timesync_req(void *pVoidUserUTCTime, int flagSuccess) {
// request was sent to the gateway, and // request was sent to the gateway, and
// - tNetwork: the seconds between the GPS epoch and the time // - tNetwork: the seconds between the GPS epoch and the time
// the gateway received the time request // the gateway received the time request
lmic_time_reference_t lmicTimeReference; lmic_time_reference_t lmicTime;
if (flagSuccess != 1) { if (flagSuccess != 1) {
ESP_LOGW(TAG, "LoRaWAN network did not answer time request"); ESP_LOGW(TAG, "LoRaWAN network did not answer time request");
@ -266,7 +264,7 @@ void IRAM_ATTR process_timesync_req(void *pVoidUserUTCTime, int flagSuccess) {
} }
// Populate lmic_time_reference // Populate lmic_time_reference
flagSuccess = LMIC_getNetworkTimeReference(&lmicTimeReference); flagSuccess = LMIC_getNetworkTimeReference(&lmicTime);
if (flagSuccess != 1) { if (flagSuccess != 1) {
ESP_LOGW(TAG, "LoRaWAN time request failed"); ESP_LOGW(TAG, "LoRaWAN time request failed");
return; return;
@ -276,13 +274,13 @@ void IRAM_ATTR process_timesync_req(void *pVoidUserUTCTime, int flagSuccess) {
mask_user_IRQ(); mask_user_IRQ();
// Update networkUTCTime, considering the difference between GPS and UTC time // Update networkUTCTime, considering the difference between GPS and UTC time
*pUserUTCTime = lmicTimeReference.tNetwork + GPS_UTC_DIFF; uint32_t networkTimeSec = lmicTime.tNetwork + GPS_UTC_DIFF;
// Add delay between the instant the time was transmitted and the current time // Add delay between the instant the time was transmitted and the current time
uint16_t requestDelaymSec = uint16_t requestDelaymSec =
osticks2ms(os_getTime() - lmicTimeReference.tLocal); osticks2ms(os_getTime() - lmicTime.tLocal);
// Update system time with time read from the network // Update system time with time read from the network
setMyTime(*pUserUTCTime, requestDelaymSec, _lora); setMyTime(networkTimeSec, requestDelaymSec, _lora);
// end of time critical section: release app irq lock // end of time critical section: release app irq lock
unmask_user_IRQ(); unmask_user_IRQ();