ble_date_time.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. */
  11. /* Attention!
  12. * To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile
  13. * qualification listings, this section of source code must not be modified.
  14. */
  15. /** @file
  16. * @brief Contains definition of ble_date_time structure.
  17. */
  18. /** @file
  19. *
  20. * @defgroup ble_sdk_srv_date_time BLE Date Time characteristic type
  21. * @{
  22. * @ingroup ble_sdk_lib
  23. * @brief Definition of ble_date_time_t type.
  24. */
  25. #ifndef BLE_DATE_TIME_H__
  26. #define BLE_DATE_TIME_H__
  27. #include <stdint.h>
  28. /**@brief Date and Time structure. */
  29. typedef struct
  30. {
  31. uint16_t year;
  32. uint8_t month;
  33. uint8_t day;
  34. uint8_t hours;
  35. uint8_t minutes;
  36. uint8_t seconds;
  37. } ble_date_time_t;
  38. static __INLINE uint8_t ble_date_time_encode(const ble_date_time_t * p_date_time,
  39. uint8_t * p_encoded_data)
  40. {
  41. uint8_t len = uint16_encode(p_date_time->year, p_encoded_data);
  42. p_encoded_data[len++] = p_date_time->month;
  43. p_encoded_data[len++] = p_date_time->day;
  44. p_encoded_data[len++] = p_date_time->hours;
  45. p_encoded_data[len++] = p_date_time->minutes;
  46. p_encoded_data[len++] = p_date_time->seconds;
  47. return len;
  48. }
  49. static __INLINE uint8_t ble_date_time_decode(ble_date_time_t * p_date_time,
  50. const uint8_t * p_encoded_data)
  51. {
  52. uint8_t len = sizeof(uint16_t);
  53. p_date_time->year = uint16_decode(p_encoded_data);
  54. p_date_time->month = p_encoded_data[len++];
  55. p_date_time->day = p_encoded_data[len++];
  56. p_date_time->hours = p_encoded_data[len++];
  57. p_date_time->minutes = p_encoded_data[len++];
  58. p_date_time->seconds = p_encoded_data[len++];
  59. return len;
  60. }
  61. #endif // BLE_DATE_TIME_H__
  62. /** @} */