[elektro] localtime gond
zulu
zulu at gmail.hu
Thu Sep 15 09:53:15 CEST 2016
2016-09-15 09:28 keltezéssel, SZIGETI Szabolcs írta:
> Ezeket mondjuk mondhattad volna előbb is :-)
copy - paste:
#define NTP_PACKET_SIZE 48
char packetBuffer[ NTP_PACKET_SIZE ];
// ntp packetben 0x20...0x23 címen van a receive timestamp sec. pontossággal (by wireshark)
struct tm ts;
uint32_t secsSince1900
=((uint32_t)packetBuffer[0x20]<<24)|((uint32_t)packetBuffer[0x21]<<16)|((uint32_t)packetBuffer[0x22]<<8)|((uint32_t)packetBuffer[0x23]);
/*
Ellenörzés végett az alábbi sorokban visszaszámoltam a pontos idöt, ami tökéletes.
hour = ( ( epoch % 86400L ) / 3600 )+2;
minute = ( epoch % 3600 ) / 60;
second = epoch % 60;
*/
const uint32_t seventyYears = 2208988800UL;
unsigned long epoch = secsSince1900 - seventyYears;
ts = *localtime( &epoch );
printf( "%04i-%02i-%02i, %1i", ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday, ts.tm_wday );
-zulu
More information about the Elektro
mailing list