ntp_clock.h 955 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include "esp_err.h"
  5. /**
  6. * NTP-like timing for AirPlay 1 synchronization.
  7. * Sends timing requests to the sender and calculates clock offset from
  8. * responses. Based on shairport-sync's timing implementation.
  9. */
  10. /**
  11. * Start NTP timing client.
  12. * Sends periodic timing requests to the remote client and calculates offset.
  13. * @param remote_ip Remote IP address (network byte order)
  14. * @param remote_port Remote timing port
  15. * @return ESP_OK on success
  16. */
  17. esp_err_t ntp_clock_start_client(uint32_t remote_ip, uint16_t remote_port);
  18. /**
  19. * Stop NTP timing and free resources.
  20. */
  21. void ntp_clock_stop(void);
  22. /**
  23. * Check if NTP timing is synchronized.
  24. * @return true if we have valid offset measurements
  25. */
  26. bool ntp_clock_is_locked(void);
  27. /**
  28. * Get current offset from local clock to remote time in nanoseconds.
  29. * remote_time = local_time + offset
  30. */
  31. int64_t ntp_clock_get_offset_ns(void);