From a9ba035474ad51852988582ff1d989b8c24dcb3f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 17 Oct 2022 17:59:18 +0200 Subject: [PATCH] refactor NTP fraction --- tasmota/tasmota_support/support_wifi.ino | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tasmota/tasmota_support/support_wifi.ino b/tasmota/tasmota_support/support_wifi.ino index f202ff602..d06a35569 100644 --- a/tasmota/tasmota_support/support_wifi.ino +++ b/tasmota/tasmota_support/support_wifi.ino @@ -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); }