Skip to content

Commit a540048

Browse files
authored
fix timestamp check
1 parent cf74d6b commit a540048

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/driver/drv_bl0937.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -949,17 +949,17 @@ void BL0937_RunEverySecond(void)
949949

950950
// g_ntpTime = (time_t)NTP_GetCurrentTime();
951951
ltm = gmtime(&g_ntpTime);
952-
static int offs_ntp_diff;
952+
static int offs_ntp_diff=0;
953953
static int diff_ntp_secelap;
954954
static int diff_ntp_stamp;
955-
diff_ntp_secelap = (int)(g_ntpTime - g_secondsElapsed);
956-
if ( g_secondsElapsed < 300 && diff_ntp_secelap > 1764000000 ) { //init once
955+
diff_ntp_secelap = (int)(g_ntpTime - g_secondsElapsed- offs_ntp_diff);
956+
if ( diff_ntp_secelap > 1764000000 && offs_ntp_diff < 86400 ) { //init once
957957
offs_ntp_diff = (g_ntpTime - g_secondsElapsed);
958-
diff_ntp_secelap -= offs_ntp_diff;
958+
// diff_ntp_secelap -= offs_ntp_diff;
959959
} else {
960-
offs_ntp_diff = 0;
960+
// offs_ntp_diff = 0;
961961
}
962-
diff_ntp_stamp = (int)(g_ntpTime - ( (pulseStampNow * portTICK_PERIOD_MS) / 1000 )) - diff_ntp_secelap;
962+
diff_ntp_stamp = (int)(g_ntpTime - ( (pulseStampNow * portTICK_PERIOD_MS) / 1000 )) - offs_ntp_diff;
963963
if (g_ntp_hourlast != ltm->tm_hour ) {
964964
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "ts %5d ntpts %d cur diff secelap %d pulsestamp %d\n", g_secondsElapsed
965965
, g_ntpTime, diff_ntp_secelap, diff_ntp_stamp);
@@ -992,7 +992,13 @@ void BL0937_RunEverySecond(void)
992992
#endif
993993
} else {
994994
}
995-
}
995+
/* if ( g_secondsElapsed % 30 == 0 ) {
996+
addLogAdv(LOG_DEBUG, LOG_FEATURE_ENERGYMETER, "ts %5d ntpts %d offs %d cur diff secelap %d pulsestamp %d enbl %d lasthour %d ntphour %d\n", g_secondsElapsed
997+
,g_ntpTime, offs_ntp_diff, diff_ntp_secelap, diff_ntp_stamp, g_enable_sendtimestamps, g_ntp_hourlast, ltm->tm_hour);
998+
999+
}
1000+
*/
1001+
}
9961002
#endif
9971003
}
9981004
// close ENABLE_DRIVER_BL0937

0 commit comments

Comments
 (0)