BTLE demo for MAXWSNENV.
Dependencies: BLE_API BMP180 Si7020 mbed MaximBLE
Characteristic.h@2:6f76d6160601, 2016-08-18 (annotated)
- Committer:
- enginerd
- Date:
- Thu Aug 18 21:09:13 2016 +0000
- Revision:
- 2:6f76d6160601
- Parent:
- 0:f71931ae3db1
Updated library versions.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kgills | 0:f71931ae3db1 | 1 | /******************************************************************************* |
kgills | 0:f71931ae3db1 | 2 | * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. |
kgills | 0:f71931ae3db1 | 3 | * |
kgills | 0:f71931ae3db1 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
kgills | 0:f71931ae3db1 | 5 | * copy of this software and associated documentation files (the "Software"), |
kgills | 0:f71931ae3db1 | 6 | * to deal in the Software without restriction, including without limitation |
kgills | 0:f71931ae3db1 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
kgills | 0:f71931ae3db1 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
kgills | 0:f71931ae3db1 | 9 | * Software is furnished to do so, subject to the following conditions: |
kgills | 0:f71931ae3db1 | 10 | * |
kgills | 0:f71931ae3db1 | 11 | * The above copyright notice and this permission notice shall be included |
kgills | 0:f71931ae3db1 | 12 | * in all copies or substantial portions of the Software. |
kgills | 0:f71931ae3db1 | 13 | * |
kgills | 0:f71931ae3db1 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
kgills | 0:f71931ae3db1 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
kgills | 0:f71931ae3db1 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
kgills | 0:f71931ae3db1 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
kgills | 0:f71931ae3db1 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
kgills | 0:f71931ae3db1 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
kgills | 0:f71931ae3db1 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
kgills | 0:f71931ae3db1 | 21 | * |
kgills | 0:f71931ae3db1 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
kgills | 0:f71931ae3db1 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
kgills | 0:f71931ae3db1 | 24 | * Products, Inc. Branding Policy. |
kgills | 0:f71931ae3db1 | 25 | * |
kgills | 0:f71931ae3db1 | 26 | * The mere transfer of this software does not imply any licenses |
kgills | 0:f71931ae3db1 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
kgills | 0:f71931ae3db1 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
kgills | 0:f71931ae3db1 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
kgills | 0:f71931ae3db1 | 30 | * ownership rights. |
kgills | 0:f71931ae3db1 | 31 | ******************************************************************************* |
kgills | 0:f71931ae3db1 | 32 | */ |
kgills | 0:f71931ae3db1 | 33 | |
kgills | 0:f71931ae3db1 | 34 | #ifndef __BLE_CHARACTERISTIC_H__ |
kgills | 0:f71931ae3db1 | 35 | #define __BLE_CHARACTERISTIC_H__ |
kgills | 0:f71931ae3db1 | 36 | |
kgills | 0:f71931ae3db1 | 37 | #include "mbed.h" |
kgills | 0:f71931ae3db1 | 38 | #include "BLE.h" |
kgills | 0:f71931ae3db1 | 39 | |
kgills | 0:f71931ae3db1 | 40 | /** |
kgills | 0:f71931ae3db1 | 41 | * @class Characteristic |
kgills | 0:f71931ae3db1 | 42 | * @brief Abstract characteristic class. |
kgills | 0:f71931ae3db1 | 43 | * @details Implement sub class derived from this for custom characteristic. |
kgills | 0:f71931ae3db1 | 44 | */ |
kgills | 0:f71931ae3db1 | 45 | class Characteristic |
kgills | 0:f71931ae3db1 | 46 | { |
kgills | 0:f71931ae3db1 | 47 | public: |
kgills | 0:f71931ae3db1 | 48 | |
kgills | 0:f71931ae3db1 | 49 | static const unsigned TIMESTAMP_BYTES = 7; |
kgills | 0:f71931ae3db1 | 50 | |
kgills | 0:f71931ae3db1 | 51 | virtual GattCharacteristic *getChar(void) = 0; |
kgills | 0:f71931ae3db1 | 52 | virtual uint8_t getNumBytes(void) = 0; |
kgills | 0:f71931ae3db1 | 53 | virtual uint8_t *getBytes(void) = 0; |
kgills | 0:f71931ae3db1 | 54 | |
kgills | 0:f71931ae3db1 | 55 | protected: |
kgills | 0:f71931ae3db1 | 56 | |
kgills | 0:f71931ae3db1 | 57 | // Convert time_t to the timestamp format |
kgills | 0:f71931ae3db1 | 58 | static void date_time(time_t time, uint8_t *buf) { |
kgills | 0:f71931ae3db1 | 59 | // Convert time_t to Year, Month, Day, Hour, Minute, Second |
kgills | 0:f71931ae3db1 | 60 | struct tm ts = *localtime(&time); |
kgills | 0:f71931ae3db1 | 61 | |
kgills | 0:f71931ae3db1 | 62 | buf[1] = ((ts.tm_year+1900) & 0xFF00) >> 8; |
kgills | 0:f71931ae3db1 | 63 | buf[0] = (ts.tm_year+1900) & 0xFF; |
kgills | 0:f71931ae3db1 | 64 | |
kgills | 0:f71931ae3db1 | 65 | buf[2] = (ts.tm_mon + 1) & 0xFF; |
kgills | 0:f71931ae3db1 | 66 | buf[3] = ts.tm_mday & 0xFF; |
kgills | 0:f71931ae3db1 | 67 | buf[4] = ts.tm_hour & 0xFF; |
kgills | 0:f71931ae3db1 | 68 | buf[5] = ts.tm_min & 0xFF; |
kgills | 0:f71931ae3db1 | 69 | buf[6] = ts.tm_sec & 0xFF; |
kgills | 0:f71931ae3db1 | 70 | } |
kgills | 0:f71931ae3db1 | 71 | |
kgills | 0:f71931ae3db1 | 72 | // Convert floating point numbers to IEEE-11073 32-bit float |
kgills | 0:f71931ae3db1 | 73 | static uint32_t float_bytes(float _float, uint8_t exp) { |
kgills | 0:f71931ae3db1 | 74 | // Calculate how much to adjust mantissa |
kgills | 0:f71931ae3db1 | 75 | uint8_t exponent = 0xFF - exp + 1; |
kgills | 0:f71931ae3db1 | 76 | while(exp > 0) { |
kgills | 0:f71931ae3db1 | 77 | _float *=10; |
kgills | 0:f71931ae3db1 | 78 | exp--; |
kgills | 0:f71931ae3db1 | 79 | } |
kgills | 0:f71931ae3db1 | 80 | uint32_t mantissa = (uint32_t)(_float); |
kgills | 0:f71931ae3db1 | 81 | return (((uint32_t)exponent) << 24) | mantissa; |
kgills | 0:f71931ae3db1 | 82 | } |
kgills | 0:f71931ae3db1 | 83 | }; |
kgills | 0:f71931ae3db1 | 84 | |
kgills | 0:f71931ae3db1 | 85 | #endif /* #ifndef __BLE_CHARACTERISTIC_H__*/ |