refactor NTP fraction

This commit is contained in:
Theo Arends 2022-10-17 17:59:18 +02:00
parent 0be740850a
commit a9ba035474
1 changed files with 6 additions and 7 deletions

View File

@ -985,13 +985,12 @@ uint64_t WifiGetNtp(void) {
ntp_server_id++; // Next server next time
return 0;
}
uint32_t highWord = word(packet_buffer[44], packet_buffer[45]);
uint32_t lowWord = word(packet_buffer[46], packet_buffer[47]);
uint32_t currentNano = (((uint64_t)(highWord << 16 | lowWord)) * 1000000000) >> 32;
return (((uint64_t) secs_since_1900) - 2208988800UL) * 1000000000 + currentNano;
uint32_t tmp_fraction = (uint32_t)packet_buffer[44] << 24;
tmp_fraction |= (uint32_t)packet_buffer[45] << 16;
tmp_fraction |= (uint32_t)packet_buffer[46] << 8;
tmp_fraction |= (uint32_t)packet_buffer[47];
uint32_t fraction = (((uint64_t)tmp_fraction) * 1000000000) >> 32;
return (((uint64_t)secs_since_1900) - 2208988800UL) * 1000000000 + fraction;
}
delay(10);
}