timesync.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2019 Koen Zandberg <koen@bergzand.net>
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser
  5. * General Public License v2.1. See the file LICENSE in the top level
  6. * directory for more details.
  7. */
  8. #ifndef APP_BLEMAN_TIMESYNC_H
  9. #define APP_BLEMAN_TIMESYNC_H
  10. #include <stdint.h>
  11. #include "event.h"
  12. #include "event/timeout.h"
  13. #include "ts_event.h"
  14. #include "bleman.h"
  15. #include "host/ble_gatt.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. typedef struct __attribute__((packed)) {
  20. uint16_t year;
  21. uint8_t month;
  22. uint8_t dayofmonth;
  23. uint8_t hour;
  24. uint8_t minute;
  25. uint8_t second;
  26. uint8_t millis;
  27. uint8_t reason;
  28. } bleman_timesync_ble_cts_t;
  29. typedef struct {
  30. event_t ev;
  31. event_t start_chrs_ev;
  32. event_t start_read_ev;
  33. bleman_event_handler_t handler;
  34. event_timeout_t timeout_ev;
  35. bleman_t *bleman;
  36. struct ble_gatt_svc time_svc;
  37. struct ble_gatt_chr time_chr;
  38. } bleman_timesync_t;
  39. void bleman_timesync_init(bleman_t *bleman, bleman_timesync_t *sync);
  40. void bleman_timesync_start_events(bleman_timesync_t *sync);
  41. void bleman_timesync_stop_events(bleman_timesync_t *sync);
  42. #ifdef __cplusplus
  43. }
  44. #endif
  45. #endif /* APP_BLEMAN_TIMESYNC_H */