JBBoardに接続したモーター2つをRCBControllerでコントロールするテストです。
Dependencies: FatFileSystem TB6612FNG2 mbed
Fork of BTstackLE by
BTstack/att.h@7:3ed1e36587d4, 2014-05-12 (annotated)
- Committer:
- jksoft
- Date:
- Mon May 12 14:24:35 2014 +0000
- Revision:
- 7:3ed1e36587d4
- Parent:
- 1:6078e430af82
First edition
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
todotani | 1:6078e430af82 | 1 | /* |
todotani | 1:6078e430af82 | 2 | * Copyright (C) 2011-2012 by Matthias Ringwald |
todotani | 1:6078e430af82 | 3 | * |
todotani | 1:6078e430af82 | 4 | * Redistribution and use in source and binary forms, with or without |
todotani | 1:6078e430af82 | 5 | * modification, are permitted provided that the following conditions |
todotani | 1:6078e430af82 | 6 | * are met: |
todotani | 1:6078e430af82 | 7 | * |
todotani | 1:6078e430af82 | 8 | * 1. Redistributions of source code must retain the above copyright |
todotani | 1:6078e430af82 | 9 | * notice, this list of conditions and the following disclaimer. |
todotani | 1:6078e430af82 | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
todotani | 1:6078e430af82 | 11 | * notice, this list of conditions and the following disclaimer in the |
todotani | 1:6078e430af82 | 12 | * documentation and/or other materials provided with the distribution. |
todotani | 1:6078e430af82 | 13 | * 3. Neither the name of the copyright holders nor the names of |
todotani | 1:6078e430af82 | 14 | * contributors may be used to endorse or promote products derived |
todotani | 1:6078e430af82 | 15 | * from this software without specific prior written permission. |
todotani | 1:6078e430af82 | 16 | * 4. Any redistribution, use, or modification is done solely for |
todotani | 1:6078e430af82 | 17 | * personal benefit and not for any commercial purpose or for |
todotani | 1:6078e430af82 | 18 | * monetary gain. |
todotani | 1:6078e430af82 | 19 | * |
todotani | 1:6078e430af82 | 20 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS |
todotani | 1:6078e430af82 | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
todotani | 1:6078e430af82 | 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
todotani | 1:6078e430af82 | 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS |
todotani | 1:6078e430af82 | 24 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
todotani | 1:6078e430af82 | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
todotani | 1:6078e430af82 | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
todotani | 1:6078e430af82 | 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
todotani | 1:6078e430af82 | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
todotani | 1:6078e430af82 | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
todotani | 1:6078e430af82 | 30 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
todotani | 1:6078e430af82 | 31 | * SUCH DAMAGE. |
todotani | 1:6078e430af82 | 32 | * |
todotani | 1:6078e430af82 | 33 | * Please inquire about commercial licensing options at btstack@ringwald.ch |
todotani | 1:6078e430af82 | 34 | * |
todotani | 1:6078e430af82 | 35 | */ |
todotani | 1:6078e430af82 | 36 | |
todotani | 1:6078e430af82 | 37 | #pragma once |
todotani | 1:6078e430af82 | 38 | |
todotani | 1:6078e430af82 | 39 | #include <stdint.h> |
todotani | 1:6078e430af82 | 40 | |
todotani | 1:6078e430af82 | 41 | // MARK: Attribute PDU Opcodes |
todotani | 1:6078e430af82 | 42 | #define ATT_ERROR_RESPONSE 0x01 |
todotani | 1:6078e430af82 | 43 | |
todotani | 1:6078e430af82 | 44 | #define ATT_EXCHANGE_MTU_REQUEST 0x02 |
todotani | 1:6078e430af82 | 45 | #define ATT_EXCHANGE_MTU_RESPONSE 0x03 |
todotani | 1:6078e430af82 | 46 | |
todotani | 1:6078e430af82 | 47 | #define ATT_FIND_INFORMATION_REQUEST 0x04 |
todotani | 1:6078e430af82 | 48 | #define ATT_FIND_INFORMATION_REPLY 0x05 |
todotani | 1:6078e430af82 | 49 | #define ATT_FIND_BY_TYPE_VALUE_REQUEST 0x06 |
todotani | 1:6078e430af82 | 50 | #define ATT_FIND_BY_TYPE_VALUE_RESPONSE 0x07 |
todotani | 1:6078e430af82 | 51 | |
todotani | 1:6078e430af82 | 52 | #define ATT_READ_BY_TYPE_REQUEST 0x08 |
todotani | 1:6078e430af82 | 53 | #define ATT_READ_BY_TYPE_RESPONSE 0x09 |
todotani | 1:6078e430af82 | 54 | #define ATT_READ_REQUEST 0x0a |
todotani | 1:6078e430af82 | 55 | #define ATT_READ_RESPONSE 0x0b |
todotani | 1:6078e430af82 | 56 | #define ATT_READ_BLOB_REQUEST 0x0c |
todotani | 1:6078e430af82 | 57 | #define ATT_READ_BLOB_RESPONSE 0x0d |
todotani | 1:6078e430af82 | 58 | #define ATT_READ_MULTIPLE_REQUEST 0x0e |
todotani | 1:6078e430af82 | 59 | #define ATT_READ_MULTIPLE_RESPONSE 0x0f |
todotani | 1:6078e430af82 | 60 | #define ATT_READ_BY_GROUP_TYPE_REQUEST 0x10 |
todotani | 1:6078e430af82 | 61 | #define ATT_READ_BY_GROUP_TYPE_RESPONSE 0x11 |
todotani | 1:6078e430af82 | 62 | |
todotani | 1:6078e430af82 | 63 | #define ATT_WRITE_REQUEST 0x12 |
todotani | 1:6078e430af82 | 64 | #define ATT_WRITE_RESPONSE 0x13 |
todotani | 1:6078e430af82 | 65 | |
todotani | 1:6078e430af82 | 66 | #define ATT_PREPARE_WRITE_REQUEST 0x16 |
todotani | 1:6078e430af82 | 67 | #define ATT_PREPARE_WRITE_RESPONSE 0x17 |
todotani | 1:6078e430af82 | 68 | #define ATT_EXECUTE_WRITE_REQUEST 0x18 |
todotani | 1:6078e430af82 | 69 | #define ATT_EXECUTE_WRITE_RESPONSE 0x19 |
todotani | 1:6078e430af82 | 70 | |
todotani | 1:6078e430af82 | 71 | #define ATT_HANDLE_VALUE_NOTIFICATION 0x1b |
todotani | 1:6078e430af82 | 72 | #define ATT_HANDLE_VALUE_CONFIRMATION 0x1c |
todotani | 1:6078e430af82 | 73 | #define ATT_HANDLE_VALUE_INDICATION 0x1d |
todotani | 1:6078e430af82 | 74 | |
todotani | 1:6078e430af82 | 75 | |
todotani | 1:6078e430af82 | 76 | #define ATT_WRITE_COMMAND 0x52 |
todotani | 1:6078e430af82 | 77 | #define ATT_SIGNED_WRITE_COMAND 0xD2 |
todotani | 1:6078e430af82 | 78 | |
todotani | 1:6078e430af82 | 79 | // MARK: ATT Error Codes |
todotani | 1:6078e430af82 | 80 | #define ATT_ERROR_ATTRIBUTE_INVALID 0x01 |
todotani | 1:6078e430af82 | 81 | #define ATT_ERROR_INVALID_OFFSET 0x07 |
todotani | 1:6078e430af82 | 82 | #define ATT_ERROR_ATTRIBUTE_NOT_FOUND 0x0a |
todotani | 1:6078e430af82 | 83 | #define ATT_ERROR_UNSUPPORTED_GROUP_TYPE 0x10 |
todotani | 1:6078e430af82 | 84 | |
todotani | 1:6078e430af82 | 85 | // MARK: Attribute Property Flags |
todotani | 1:6078e430af82 | 86 | #define ATT_PROPERTY_BROADCAST 0x01 |
todotani | 1:6078e430af82 | 87 | #define ATT_PROPERTY_READ 0x02 |
todotani | 1:6078e430af82 | 88 | #define ATT_PROPERTY_WRITE_WITHOUT_RESPONSE 0x04 |
todotani | 1:6078e430af82 | 89 | #define ATT_PROPERTY_WRITE 0x08 |
todotani | 1:6078e430af82 | 90 | #define ATT_PROPERTY_NOTIFY 0x10 |
todotani | 1:6078e430af82 | 91 | #define ATT_PROPERTY_INDICATE 0x20 |
todotani | 1:6078e430af82 | 92 | #define ATT_PROPERTY_AUTHENTICATED_SIGNED_WRITE 0x40 |
todotani | 1:6078e430af82 | 93 | #define ATT_PROPERTY_EXTENDED_PROPERTIES 0x80 |
todotani | 1:6078e430af82 | 94 | |
todotani | 1:6078e430af82 | 95 | // MARK: Attribute Property Flag, BTstack extension |
todotani | 1:6078e430af82 | 96 | // value is asked from client |
todotani | 1:6078e430af82 | 97 | #define ATT_PROPERTY_DYNAMIC 0x100 |
todotani | 1:6078e430af82 | 98 | // 128 bit UUID used |
todotani | 1:6078e430af82 | 99 | #define ATT_PROPERTY_UUID128 0x200 |
todotani | 1:6078e430af82 | 100 | |
todotani | 1:6078e430af82 | 101 | // MARK: GATT UUIDs |
todotani | 1:6078e430af82 | 102 | #define GATT_PRIMARY_SERVICE_UUID 0x2800 |
todotani | 1:6078e430af82 | 103 | #define GATT_SECONDARY_SERVICE_UUID 0x2801 |
todotani | 1:6078e430af82 | 104 | #define GATT_CHARACTERISTICS_UUID 0x2803 |
todotani | 1:6078e430af82 | 105 | |
todotani | 1:6078e430af82 | 106 | #define GAP_SERVICE_UUID 0x1800 |
todotani | 1:6078e430af82 | 107 | #define GAP_DEVICE_NAME_UUID 0x2a00 |
todotani | 1:6078e430af82 | 108 | |
todotani | 1:6078e430af82 | 109 | #define ATT_TRANSACTION_MODE_NONE 0x0 |
todotani | 1:6078e430af82 | 110 | #define ATT_TRANSACTION_MODE_ACTIVE 0x1 |
todotani | 1:6078e430af82 | 111 | #define ATT_TRANSACTION_MODE_EXECUTE 0x2 |
todotani | 1:6078e430af82 | 112 | #define ATT_TRANSACTION_MODE_CANCEL 0x3 |
todotani | 1:6078e430af82 | 113 | |
todotani | 1:6078e430af82 | 114 | typedef struct att_connection { |
todotani | 1:6078e430af82 | 115 | uint16_t mtu; |
todotani | 1:6078e430af82 | 116 | } att_connection_t; |
todotani | 1:6078e430af82 | 117 | |
todotani | 1:6078e430af82 | 118 | typedef uint8_t signature_t[12]; |
todotani | 1:6078e430af82 | 119 | |
todotani | 1:6078e430af82 | 120 | // ATT Client Read Callback for Dynamic Data |
todotani | 1:6078e430af82 | 121 | // - if buffer == NULL, don't copy data, just return size of value |
todotani | 1:6078e430af82 | 122 | // - if buffer != NULL, copy data and return number bytes copied |
todotani | 1:6078e430af82 | 123 | // @param offset defines start of attribute value |
todotani | 1:6078e430af82 | 124 | typedef uint16_t (*att_read_callback_t)(uint16_t handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size); |
todotani | 1:6078e430af82 | 125 | |
todotani | 1:6078e430af82 | 126 | // ATT Client Write Callback for Dynamic Data |
todotani | 1:6078e430af82 | 127 | // @param handle to be written |
todotani | 1:6078e430af82 | 128 | // @param transaction - ATT_TRANSACTION_MODE_NONE for regular writes, ATT_TRANSACTION_MODE_ACTIVE for prepared writes and ATT_TRANSACTION_MODE_EXECUTE |
todotani | 1:6078e430af82 | 129 | // @param offset into the value - used for queued writes and long attributes |
todotani | 1:6078e430af82 | 130 | // @param buffer |
todotani | 1:6078e430af82 | 131 | // @param buffer_size |
todotani | 1:6078e430af82 | 132 | // @Param signature used for signed write commmands |
todotani | 1:6078e430af82 | 133 | typedef void (*att_write_callback_t)(uint16_t handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size, signature_t * signature); |
todotani | 1:6078e430af82 | 134 | |
todotani | 1:6078e430af82 | 135 | // MARK: ATT Operations |
todotani | 1:6078e430af82 | 136 | |
todotani | 1:6078e430af82 | 137 | void att_set_db(uint8_t const * db); |
todotani | 1:6078e430af82 | 138 | |
todotani | 1:6078e430af82 | 139 | void att_set_read_callback(att_read_callback_t callback); |
todotani | 1:6078e430af82 | 140 | |
todotani | 1:6078e430af82 | 141 | void att_set_write_callback(att_write_callback_t callback); |
todotani | 1:6078e430af82 | 142 | |
todotani | 1:6078e430af82 | 143 | void att_dump_attributes(void); |
todotani | 1:6078e430af82 | 144 | |
todotani | 1:6078e430af82 | 145 | // response buffer size = att_connection->mtu |
todotani | 1:6078e430af82 | 146 | uint16_t att_handle_request(att_connection_t * att_connection, |
todotani | 1:6078e430af82 | 147 | uint8_t * request_buffer, |
todotani | 1:6078e430af82 | 148 | uint16_t request_len, |
todotani | 1:6078e430af82 | 149 | uint8_t * response_buffer); |
todotani | 1:6078e430af82 | 150 | |
todotani | 1:6078e430af82 | 151 | uint16_t att_prepare_handle_value_notification(att_connection_t * att_connection, |
todotani | 1:6078e430af82 | 152 | uint16_t handle, |
todotani | 1:6078e430af82 | 153 | uint8_t *value, |
todotani | 1:6078e430af82 | 154 | uint16_t value_len, |
todotani | 1:6078e430af82 | 155 | uint8_t * response_buffer); |
todotani | 1:6078e430af82 | 156 | |
todotani | 1:6078e430af82 | 157 | uint16_t att_prepare_handle_value_indication(att_connection_t * att_connection, |
todotani | 1:6078e430af82 | 158 | uint16_t handle, |
todotani | 1:6078e430af82 | 159 | uint8_t *value, |
todotani | 1:6078e430af82 | 160 | uint16_t value_len, |
todotani | 1:6078e430af82 | 161 | uint8_t * response_buffer); |
todotani | 1:6078e430af82 | 162 | |
todotani | 1:6078e430af82 | 163 | |
todotani | 1:6078e430af82 | 164 |