source: azure_iot_hub_riscv/trunk/asp_baseplatform/gdic/ble_shield2.1/BLEPeripheral.h@ 453

Last change on this file since 453 was 453, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 8.4 KB
Line 
1/*
2 * TOPPERS BASE PLATFORM MIDDLEWARE
3 *
4 * Copyright (C) 2017-2018 by TOPPERS PROJECT
5 * Educational Working Group.
6 *
7 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
8 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
9 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
10 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
11 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
12 * スコード中に含まれていること.
13 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
14 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
15 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
16 * の無保証規定を掲載すること.
17 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
18 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
19 * と.
20 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
21 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
22 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
23 * 報告すること.
24 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
25 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
26 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
27 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
28 * 免責すること.
29 *
30 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
31 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
32 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
33 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
34 * の責任を負わない.
35 *
36 * @(#) $Id$
37 */
38
39/*
40The MIT License (MIT)
41
42Copyright (c) 2014 Sandeep Mistry
43
44Permission is hereby granted, free of charge, to any person obtaining a copy
45of this software and associated documentation files (the "Software"), to deal
46in the Software without restriction, including without limitation the rights
47to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48copies of the Software, and to permit persons to whom the Software is
49furnished to do so, subject to the following conditions:
50
51The above copyright notice and this permission notice shall be included in all
52copies or substantial portions of the Software.
53
54THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60SOFTWARE.
61*/
62
63#ifndef _BLEPERIPHERAL_H_
64#define _BLEPERIPHERAL_H_
65
66#ifdef __cplusplus
67 extern "C" {
68#endif
69
70#define MAX_ATTRIBUTE 32
71#define NB_BASE_SETUP_MESSAGES 7
72#define NUM_DEVICE_NAME 20
73#define NUM_APPEAR_VALUE 4
74#define NUM_SERVICE_VALUE 4
75
76#ifndef _BLE_ATTRIBUTE_H_
77typedef struct _nRF8001 nRF8001;
78#endif
79
80enum BLEPeripheralEvent {
81 BLEConnected = 0,
82 BLEDisconnected = 1
83};
84
85struct pipeInfo {
86 BLECharacteristic *pcharc;
87
88 uint16_t valueHandle;
89 uint16_t configHandle;
90
91 uint8_t startPipe;
92 uint8_t txPipe;
93 uint8_t txAckPipe;
94 uint8_t rxPipe;
95 uint8_t rxAckPipe;
96 uint8_t setPipe;
97
98 bool_t txPipeOpen;
99 bool_t txAckPipeOpen;
100};
101
102struct _nRF8001 {
103 struct aci_state_t _aciState;
104 hal_aci_evt_t _aciData;
105
106 void* _pblePeripheral;
107 struct pipeInfo* _pipeInfo;
108 uint8_t _numPipeInfo;
109 uint16_t _crcSeed;
110
111 void (*nRF8001Connected)(nRF8001* nRF8001, const unsigned char* address);
112 void (*nRF8001Disconnected)(nRF8001* nRF8001);
113 void (*nRF8001CharacteristicValueChanged)(nRF8001* nRF8001, BLECharacteristic *pcharc, const unsigned char* value, unsigned char valueLength);
114 void (*nRF8001CharacteristicSubscribedChanged)(nRF8001* nRF8001, BLECharacteristic *pcharc, bool_t subscribed);
115 void (*nRF8001AddressReceived)(nRF8001* nRF8001, const unsigned char* address);
116 void (*nRF8001TemperatureReceived)(nRF8001* nRF8001, float temperature);
117 void (*nRF8001BatteryLevelReceived)(nRF8001* nRF8001, float batteryLevel);
118};
119
120
121typedef void (*BLEPeripheralEventHandler)(BLECentral* central);
122
123typedef struct _BLEPeripheral {
124 nRF8001 _nRF8001;
125
126 const char *_advertisedServiceUuid;
127 const uint8_t *_manufacturerData;
128 uint8_t _manufacturerDataLength;
129 const char* _localName;
130
131 BLEAttribute* _attributes[MAX_ATTRIBUTE];
132 uint8_t _numAttributes;
133
134 BLECentral _central;
135 BLEPeripheralEventHandler _eventHandlers[2];
136} BLEPeripheral;
137
138
139extern void nRF8001_begin(nRF8001* pnRF8001, const uint8_t *advertisementData, uint8_t advertisementDataLength, const uint8_t *scanData,
140 uint8_t scanDataLength, BLEAttribute** attributes, uint8_t numAttributes);
141extern bool_t nRF8001_poll(nRF8001* pnRF8001);
142extern bool_t nRF8001_updateCharacteristicValue(nRF8001* pnRF8001, BLECharacteristic *pcharc);
143extern bool_t nRF8001_canNotifyCharacteristic(nRF8001* pnRF8001, BLECharacteristic* pcharc);
144extern bool_t nRF8001_canIndicateCharacteristic(nRF8001* pnRF8001, BLECharacteristic* pcharc);
145extern void nRF8001_disconnect(nRF8001* pnRF8001);
146extern void nRF8001_requestAddress(void);
147extern void nRF8001_requestTemperature(void);
148extern void nRF8001_requestBatteryLevel(void);
149extern void nRF8001_waitForSetupMode(nRF8001* pnRF8001);
150extern ER nRF8001_sendSetupMessage(nRF8001* pnRF8001, hal_aci_data_t* data);
151extern void nRF8001_sendCrc(nRF8001* pnRF8001);
152
153extern void BLEPeripheral_setup(BLEPeripheral *pblep, unsigned char req, unsigned char rdy, unsigned char rst);
154extern void BLEPeripheral_begin(BLEPeripheral *pblep);
155extern void BLEPeripheral_poll(BLEPeripheral *pblep);
156extern void BLEPeripheral_setAdvertisedServiceUuid(BLEPeripheral *pblep, const char* advertisedServiceUuid);
157extern void BLEPeripheral_setManufacturerData(BLEPeripheral *pblep, const unsigned char manufacturerData[], unsigned char manufacturerDataLength);
158extern void BLEPeripheral_setLocalName(BLEPeripheral *pblep, const char* localName);
159extern void BLEPeripheral_addAttribute(BLEPeripheral *pblep, BLEAttribute* attribute);
160extern void BLEPeripheral_setDeviceName(BLEPeripheral *pblep, const char* deviceName);
161extern void BLEPeripheral_setAppearance(BLEPeripheral *pblep, unsigned short appearance);
162extern void BLEPeripheral_disconnect(BLEPeripheral *pblep);
163extern BLECentral *BLEPeripheral_central(BLEPeripheral *pblep);
164extern bool_t BLEPeripheral_connected(BLEPeripheral *pblep);
165extern void BLEPeripheral_setEventHandler(BLEPeripheral *pblep, uint8_t event, BLEPeripheralEventHandler eventHandler);
166extern bool_t BLEPeripheral_version(BLEPeripheral *pblep);
167extern void BLEPeripheral_nRF8001Connected(nRF8001* nRF8001, const unsigned char* address);
168extern void BLEPeripheral_nRF8001Disconnected(nRF8001* nRF8001);
169extern void BLEPeripheral_nRF8001CharacteristicValueChanged(nRF8001* nRF8001, BLECharacteristic* pcharc, const unsigned char* value, unsigned char valueLength);
170extern void BLEPeripheral_nRF8001CharacteristicSubscribedChanged(nRF8001* nRF8001, BLECharacteristic* pcharc, bool_t subscribed);
171extern void BLEPeripheral_nRF8001AddressReceived(nRF8001* nRF8001, const unsigned char* address);
172extern void BLEPeripheral_nRF8001TemperatureReceived(nRF8001* nRF8001, float temperature);
173extern void BLEPeripheral_nRF8001BatteryLevelReceived(nRF8001* nRF8001, float batteryLevel);
174
175#ifdef __cplusplus
176}
177#endif
178
179#endif /* _BLEPERIPHERAL_H_ */
Note: See TracBrowser for help on using the repository browser.