テスト用
Fork of nRF51822 by
nordic/nrf-sdk/ble/ble_date_time.h@0:eff01767de02, 2014-03-26 (annotated)
- Committer:
- bogdanm
- Date:
- Wed Mar 26 14:38:17 2014 +0000
- Revision:
- 0:eff01767de02
- Child:
- 37:c29c330d942c
Initial import of the nRF51822 code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:eff01767de02 | 1 | /* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved. |
bogdanm | 0:eff01767de02 | 2 | * |
bogdanm | 0:eff01767de02 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
bogdanm | 0:eff01767de02 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
bogdanm | 0:eff01767de02 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
bogdanm | 0:eff01767de02 | 6 | * |
bogdanm | 0:eff01767de02 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
bogdanm | 0:eff01767de02 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
bogdanm | 0:eff01767de02 | 9 | * the file. |
bogdanm | 0:eff01767de02 | 10 | */ |
bogdanm | 0:eff01767de02 | 11 | |
bogdanm | 0:eff01767de02 | 12 | /* Attention! |
bogdanm | 0:eff01767de02 | 13 | * To maintain compliance with Nordic Semiconductor ASA�s Bluetooth profile |
bogdanm | 0:eff01767de02 | 14 | * qualification listings, this section of source code must not be modified. |
bogdanm | 0:eff01767de02 | 15 | */ |
bogdanm | 0:eff01767de02 | 16 | |
bogdanm | 0:eff01767de02 | 17 | /** @file |
bogdanm | 0:eff01767de02 | 18 | * @brief Contains definition of ble_date_time structure. |
bogdanm | 0:eff01767de02 | 19 | */ |
bogdanm | 0:eff01767de02 | 20 | |
bogdanm | 0:eff01767de02 | 21 | /** @file |
bogdanm | 0:eff01767de02 | 22 | * |
bogdanm | 0:eff01767de02 | 23 | * @defgroup ble_sdk_srv_date_time BLE Date Time characteristic type |
bogdanm | 0:eff01767de02 | 24 | * @{ |
bogdanm | 0:eff01767de02 | 25 | * @ingroup ble_sdk_srv |
bogdanm | 0:eff01767de02 | 26 | * @brief Definition of ble_date_time_t type. |
bogdanm | 0:eff01767de02 | 27 | */ |
bogdanm | 0:eff01767de02 | 28 | |
bogdanm | 0:eff01767de02 | 29 | #ifndef BLE_DATE_TIME_H__ |
bogdanm | 0:eff01767de02 | 30 | #define BLE_DATE_TIME_H__ |
bogdanm | 0:eff01767de02 | 31 | |
bogdanm | 0:eff01767de02 | 32 | #include <stdint.h> |
bogdanm | 0:eff01767de02 | 33 | #include "nordic_global.h" |
bogdanm | 0:eff01767de02 | 34 | |
bogdanm | 0:eff01767de02 | 35 | /**@brief Date and Time structure. */ |
bogdanm | 0:eff01767de02 | 36 | typedef struct |
bogdanm | 0:eff01767de02 | 37 | { |
bogdanm | 0:eff01767de02 | 38 | uint16_t year; |
bogdanm | 0:eff01767de02 | 39 | uint8_t month; |
bogdanm | 0:eff01767de02 | 40 | uint8_t day; |
bogdanm | 0:eff01767de02 | 41 | uint8_t hours; |
bogdanm | 0:eff01767de02 | 42 | uint8_t minutes; |
bogdanm | 0:eff01767de02 | 43 | uint8_t seconds; |
bogdanm | 0:eff01767de02 | 44 | } ble_date_time_t; |
bogdanm | 0:eff01767de02 | 45 | |
bogdanm | 0:eff01767de02 | 46 | static __INLINE uint8_t ble_date_time_encode(const ble_date_time_t * p_date_time, |
bogdanm | 0:eff01767de02 | 47 | uint8_t * p_encoded_data) |
bogdanm | 0:eff01767de02 | 48 | { |
bogdanm | 0:eff01767de02 | 49 | uint8_t len = uint16_encode(p_date_time->year, p_encoded_data); |
bogdanm | 0:eff01767de02 | 50 | |
bogdanm | 0:eff01767de02 | 51 | p_encoded_data[len++] = p_date_time->month; |
bogdanm | 0:eff01767de02 | 52 | p_encoded_data[len++] = p_date_time->day; |
bogdanm | 0:eff01767de02 | 53 | p_encoded_data[len++] = p_date_time->hours; |
bogdanm | 0:eff01767de02 | 54 | p_encoded_data[len++] = p_date_time->minutes; |
bogdanm | 0:eff01767de02 | 55 | p_encoded_data[len++] = p_date_time->seconds; |
bogdanm | 0:eff01767de02 | 56 | |
bogdanm | 0:eff01767de02 | 57 | return len; |
bogdanm | 0:eff01767de02 | 58 | } |
bogdanm | 0:eff01767de02 | 59 | |
bogdanm | 0:eff01767de02 | 60 | static __INLINE uint8_t ble_date_time_decode(ble_date_time_t * p_date_time, |
bogdanm | 0:eff01767de02 | 61 | const uint8_t * p_encoded_data) |
bogdanm | 0:eff01767de02 | 62 | { |
bogdanm | 0:eff01767de02 | 63 | uint8_t len = sizeof(uint16_t); |
bogdanm | 0:eff01767de02 | 64 | |
bogdanm | 0:eff01767de02 | 65 | p_date_time->year = uint16_decode(p_encoded_data); |
bogdanm | 0:eff01767de02 | 66 | p_date_time->month = p_encoded_data[len++]; |
bogdanm | 0:eff01767de02 | 67 | p_date_time->day = p_encoded_data[len++]; |
bogdanm | 0:eff01767de02 | 68 | p_date_time->hours = p_encoded_data[len++]; |
bogdanm | 0:eff01767de02 | 69 | p_date_time->minutes = p_encoded_data[len++]; |
bogdanm | 0:eff01767de02 | 70 | p_date_time->seconds = p_encoded_data[len++]; |
bogdanm | 0:eff01767de02 | 71 | |
bogdanm | 0:eff01767de02 | 72 | return len; |
bogdanm | 0:eff01767de02 | 73 | } |
bogdanm | 0:eff01767de02 | 74 | |
bogdanm | 0:eff01767de02 | 75 | #endif // BLE_DATE_TIME_H__ |
bogdanm | 0:eff01767de02 | 76 | |
bogdanm | 0:eff01767de02 | 77 | /** @} */ |