cvb

Fork of nrf51-sdk by Lancaster University

Committer:
Jonathan Austin
Date:
Wed Apr 06 23:55:04 2016 +0100
Revision:
0:bc2961fa1ef0
Synchronized with git rev 90647e3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jonathan Austin 0:bc2961fa1ef0 1 /*
Jonathan Austin 0:bc2961fa1ef0 2 * Copyright (c) Nordic Semiconductor ASA
Jonathan Austin 0:bc2961fa1ef0 3 * All rights reserved.
Jonathan Austin 0:bc2961fa1ef0 4 *
Jonathan Austin 0:bc2961fa1ef0 5 * Redistribution and use in source and binary forms, with or without modification,
Jonathan Austin 0:bc2961fa1ef0 6 * are permitted provided that the following conditions are met:
Jonathan Austin 0:bc2961fa1ef0 7 *
Jonathan Austin 0:bc2961fa1ef0 8 * 1. Redistributions of source code must retain the above copyright notice, this
Jonathan Austin 0:bc2961fa1ef0 9 * list of conditions and the following disclaimer.
Jonathan Austin 0:bc2961fa1ef0 10 *
Jonathan Austin 0:bc2961fa1ef0 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
Jonathan Austin 0:bc2961fa1ef0 12 * list of conditions and the following disclaimer in the documentation and/or
Jonathan Austin 0:bc2961fa1ef0 13 * other materials provided with the distribution.
Jonathan Austin 0:bc2961fa1ef0 14 *
Jonathan Austin 0:bc2961fa1ef0 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
Jonathan Austin 0:bc2961fa1ef0 16 * contributors to this software may be used to endorse or promote products
Jonathan Austin 0:bc2961fa1ef0 17 * derived from this software without specific prior written permission.
Jonathan Austin 0:bc2961fa1ef0 18 *
Jonathan Austin 0:bc2961fa1ef0 19 *
Jonathan Austin 0:bc2961fa1ef0 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Jonathan Austin 0:bc2961fa1ef0 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Jonathan Austin 0:bc2961fa1ef0 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Jonathan Austin 0:bc2961fa1ef0 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Jonathan Austin 0:bc2961fa1ef0 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Jonathan Austin 0:bc2961fa1ef0 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Jonathan Austin 0:bc2961fa1ef0 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Jonathan Austin 0:bc2961fa1ef0 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Jonathan Austin 0:bc2961fa1ef0 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Jonathan Austin 0:bc2961fa1ef0 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jonathan Austin 0:bc2961fa1ef0 30 *
Jonathan Austin 0:bc2961fa1ef0 31 */
Jonathan Austin 0:bc2961fa1ef0 32
Jonathan Austin 0:bc2961fa1ef0 33 /* Attention!
Jonathan Austin 0:bc2961fa1ef0 34 * To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile
Jonathan Austin 0:bc2961fa1ef0 35 * qualification listings, this section of source code must not be modified.
Jonathan Austin 0:bc2961fa1ef0 36 */
Jonathan Austin 0:bc2961fa1ef0 37
Jonathan Austin 0:bc2961fa1ef0 38 /** @file
Jonathan Austin 0:bc2961fa1ef0 39 * @brief Contains definition of ble_date_time structure.
Jonathan Austin 0:bc2961fa1ef0 40 */
Jonathan Austin 0:bc2961fa1ef0 41
Jonathan Austin 0:bc2961fa1ef0 42 /** @file
Jonathan Austin 0:bc2961fa1ef0 43 *
Jonathan Austin 0:bc2961fa1ef0 44 * @defgroup ble_sdk_srv_date_time BLE Date Time characteristic type
Jonathan Austin 0:bc2961fa1ef0 45 * @{
Jonathan Austin 0:bc2961fa1ef0 46 * @ingroup ble_sdk_lib
Jonathan Austin 0:bc2961fa1ef0 47 * @brief Definition of ble_date_time_t type.
Jonathan Austin 0:bc2961fa1ef0 48 */
Jonathan Austin 0:bc2961fa1ef0 49
Jonathan Austin 0:bc2961fa1ef0 50 #ifndef BLE_DATE_TIME_H__
Jonathan Austin 0:bc2961fa1ef0 51 #define BLE_DATE_TIME_H__
Jonathan Austin 0:bc2961fa1ef0 52
Jonathan Austin 0:bc2961fa1ef0 53 #include <stdint.h>
Jonathan Austin 0:bc2961fa1ef0 54
Jonathan Austin 0:bc2961fa1ef0 55 /**@brief Date and Time structure. */
Jonathan Austin 0:bc2961fa1ef0 56 typedef struct
Jonathan Austin 0:bc2961fa1ef0 57 {
Jonathan Austin 0:bc2961fa1ef0 58 uint16_t year;
Jonathan Austin 0:bc2961fa1ef0 59 uint8_t month;
Jonathan Austin 0:bc2961fa1ef0 60 uint8_t day;
Jonathan Austin 0:bc2961fa1ef0 61 uint8_t hours;
Jonathan Austin 0:bc2961fa1ef0 62 uint8_t minutes;
Jonathan Austin 0:bc2961fa1ef0 63 uint8_t seconds;
Jonathan Austin 0:bc2961fa1ef0 64 } ble_date_time_t;
Jonathan Austin 0:bc2961fa1ef0 65
Jonathan Austin 0:bc2961fa1ef0 66 static __INLINE uint8_t ble_date_time_encode(const ble_date_time_t * p_date_time,
Jonathan Austin 0:bc2961fa1ef0 67 uint8_t * p_encoded_data)
Jonathan Austin 0:bc2961fa1ef0 68 {
Jonathan Austin 0:bc2961fa1ef0 69 uint8_t len = uint16_encode(p_date_time->year, p_encoded_data);
Jonathan Austin 0:bc2961fa1ef0 70
Jonathan Austin 0:bc2961fa1ef0 71 p_encoded_data[len++] = p_date_time->month;
Jonathan Austin 0:bc2961fa1ef0 72 p_encoded_data[len++] = p_date_time->day;
Jonathan Austin 0:bc2961fa1ef0 73 p_encoded_data[len++] = p_date_time->hours;
Jonathan Austin 0:bc2961fa1ef0 74 p_encoded_data[len++] = p_date_time->minutes;
Jonathan Austin 0:bc2961fa1ef0 75 p_encoded_data[len++] = p_date_time->seconds;
Jonathan Austin 0:bc2961fa1ef0 76
Jonathan Austin 0:bc2961fa1ef0 77 return len;
Jonathan Austin 0:bc2961fa1ef0 78 }
Jonathan Austin 0:bc2961fa1ef0 79
Jonathan Austin 0:bc2961fa1ef0 80 static __INLINE uint8_t ble_date_time_decode(ble_date_time_t * p_date_time,
Jonathan Austin 0:bc2961fa1ef0 81 const uint8_t * p_encoded_data)
Jonathan Austin 0:bc2961fa1ef0 82 {
Jonathan Austin 0:bc2961fa1ef0 83 uint8_t len = sizeof(uint16_t);
Jonathan Austin 0:bc2961fa1ef0 84
Jonathan Austin 0:bc2961fa1ef0 85 p_date_time->year = uint16_decode(p_encoded_data);
Jonathan Austin 0:bc2961fa1ef0 86 p_date_time->month = p_encoded_data[len++];
Jonathan Austin 0:bc2961fa1ef0 87 p_date_time->day = p_encoded_data[len++];
Jonathan Austin 0:bc2961fa1ef0 88 p_date_time->hours = p_encoded_data[len++];
Jonathan Austin 0:bc2961fa1ef0 89 p_date_time->minutes = p_encoded_data[len++];
Jonathan Austin 0:bc2961fa1ef0 90 p_date_time->seconds = p_encoded_data[len++];
Jonathan Austin 0:bc2961fa1ef0 91
Jonathan Austin 0:bc2961fa1ef0 92 return len;
Jonathan Austin 0:bc2961fa1ef0 93 }
Jonathan Austin 0:bc2961fa1ef0 94
Jonathan Austin 0:bc2961fa1ef0 95 #endif // BLE_DATE_TIME_H__
Jonathan Austin 0:bc2961fa1ef0 96
Jonathan Austin 0:bc2961fa1ef0 97 /** @} */