sntp.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * sntp.h
  3. *
  4. * Created on: 2014. 12. 15.
  5. * Author: Administrator
  6. */
  7. #ifndef SNTP_H_
  8. #define SNTP_H_
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include <stdint.h>
  13. /*
  14. * @brief Define it for Debug & Monitor DNS processing.
  15. * @note If defined, it dependens on <stdio.h>
  16. */
  17. //#define _SNTP_DEBUG_
  18. #define MAX_SNTP_BUF_SIZE sizeof(ntpformat) ///< maximum size of DNS buffer. */
  19. /* for ntpclient */
  20. typedef signed char s_char;
  21. typedef unsigned long long tstamp;
  22. typedef unsigned int tdist;
  23. typedef struct _ntpformat
  24. {
  25. uint8_t dstaddr[4]; /* destination (local) address */
  26. char version; /* version number */
  27. char leap; /* leap indicator */
  28. char mode; /* mode */
  29. char stratum; /* stratum */
  30. char poll; /* poll interval */
  31. s_char precision; /* precision */
  32. tdist rootdelay; /* root delay */
  33. tdist rootdisp; /* root dispersion */
  34. char refid; /* reference ID */
  35. tstamp reftime; /* reference time */
  36. tstamp org; /* origin timestamp */
  37. tstamp rec; /* receive timestamp */
  38. tstamp xmt; /* transmit timestamp */
  39. } ntpformat;
  40. typedef struct _datetime
  41. {
  42. uint16_t yy;
  43. uint8_t mo;
  44. uint8_t dd;
  45. uint8_t hh;
  46. uint8_t mm;
  47. uint8_t ss;
  48. } datetime;
  49. #define ntp_port 123 //ntp server port number
  50. #define SECS_PERDAY 86400UL // seconds in a day = 60*60*24
  51. #define UTC_ADJ_HRS 9 // SEOUL : GMT+9
  52. #define EPOCH 1900 // NTP start year
  53. void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx);
  54. void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf);
  55. int8_t SNTP_run(datetime *time);
  56. tstamp changedatetime_to_seconds(void);
  57. void calcdatetime(tstamp seconds);
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* SNTP_H_ */