Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SampleApp / arduino / Reference_Thing / include / bleLib.h
1 /******************************************************************
2 *
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************/
20
21 #ifndef BLELIB_H_
22 #define BLELIB_H_
23
24 #include "Arduino.h"
25
26 #define BLE_NOCHANGE    -1
27 #define BLE_MASTER      1
28 #define BLE_SLAVER      0
29
30 #define BLE_DISCON      200
31 #define BLE_NODATA      100
32
33
34 /***************************************
35  *
36  *  HM-10 BLE Module Control Class.
37  *  Target Board : Arduino-Mega.
38  *
39  **************************************/
40 class Cble
41 {
42     public :
43         /***
44          * BLE Control Function.
45          */
46         // BLE initialization ( COM baud rate , BLE Master , Slave setting. )
47         void init(long baudRate, int ble_mode, char *SelfMaxAddr);
48
49         void StatusRead( void );
50
51         bool IsSelfArduino( void );
52
53         bool IsConnected( void );
54
55         bool pollingConnect( const char *maxAddr );
56
57         void pollingDisconnect( void );
58         // Get RSSI by BLE communication. (polling method.)
59         int pollingGetRSSI( void );
60         // Send Request to BLE Module. And, Get the response. (polling method.)
61         bool pollingRequest(const char *request, char *data, int dataLen);
62
63         int mustHaveRequest(const char *request, char *data, int dataLen);
64
65         void streamDummy( char *data, int dataLen);
66
67         /***
68          * Debug COM port to BLE COM port.
69          * BLE COM port to Debug COM port.
70          */
71         // BLE Module to Debug Serial port.
72         void BLE2Debug( int autoDiscon );
73         // Debug Serial port to BLE Module.
74         char *Debug2BLE( int BLEwrite );
75
76         /***
77          * If you first setting, you need next-function.
78          */
79         // Restore to factory setting data.
80         void FactoryReset( void );
81         // First setting of COM port.
82         void firstUartSetting( void );
83 };
84
85
86
87 #if 0
88 #define debug_printf(...)   {                           \
89     char* __temp__ = (char*)malloc(sizeof(char)*2048);      \
90     sprintf(__temp__, __VA_ARGS__ );                    \
91     Serial.print(__temp__);                                 \
92     free(__temp__);                                                 \
93 }
94 #else
95 #define debug_printf(...)
96 #endif
97
98
99
100 #endif /* BLELIB_H_ */