Tizen, Android BT , BLE optimization - making similar to wifi, eth adapters
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / arduino / cableserver.cpp
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
22 //logger.h included first to avoid conflict with RBL library PROGMEM attribute
23 #include "logger.h"
24
25 #include "cableserver.h"
26
27 #include <Arduino.h>
28 #include <SPI.h>
29 #include <boards.h>
30 #include <RBL_nRF8001.h>
31
32 #include "caleinterface_singlethread.h"
33 #include "oic_malloc.h"
34 #include "caadapterutils.h"
35
36 #define TAG "LES"
37
38 CAResult_t CAInitializeBle()
39 {
40     OIC_LOG(DEBUG, TAG, "IN");
41
42     // Set your BLE Shield name here, max. length 10
43     ble_set_name(__OIC_DEVICE_NAME__);
44
45     OIC_LOG(DEBUG, TAG, "LEName Set");
46
47     ble_begin();
48
49     OIC_LOG(DEBUG, TAG, "OUT");
50     return CA_STATUS_OK;
51 }
52
53 CAResult_t CATerminateBle()
54 {
55     OIC_LOG(DEBUG, TAG, "IN");
56     ble_disconnect();
57     OIC_LOG(DEBUG, TAG, "OUT");
58     return CA_STATUS_OK;
59
60 }
61
62 CAResult_t CAAddNewBleServiceInGattServer(const char *service_uuid)
63 {
64     // Not Supported - Done at compile time
65     return CA_STATUS_OK;
66 }
67
68 CAResult_t CARemoveBleServiceFromGattServer(const char *svc_path)
69 {
70     // Not Supported - Done at compile time
71     return CA_STATUS_OK;
72 }
73
74 CAResult_t CARemoveAllBleServicesFromGattServer()
75 {
76     // Not Supported
77     return CA_STATUS_OK;
78 }
79
80 CAResult_t CARegisterBleServicewithGattServer(const char *svc_path)
81 {
82     // Not Supported - Done at compile time
83     return CA_STATUS_OK;
84 }
85
86 CAResult_t CAAddNewCharacteristicsToGattServer(const char *svc_path,
87         const char *char_uuid,
88         const char *char_value,
89         int char_value_len,
90         int read)
91 {
92     // Not Supported - Done at compile time
93     return CA_STATUS_OK;
94 }
95
96 CAResult_t CARemoveCharacteristicsFromGattServer(const char *char_path)
97 {
98     // Not Supported
99     return CA_STATUS_OK;
100 }
101
102 unsigned char CAIsBleDataAvailable()
103 {
104     return ble_available();
105 }
106
107 unsigned char CAIsBleConnected()
108 {
109     return ble_connected();
110 }
111 char CAReadBleData()
112 {
113     return (char)ble_read();
114 }
115
116 CAResult_t CABleDoEvents()
117 {
118     ble_do_events();
119     return CA_STATUS_OK;
120 }
121
122 CAResult_t CAUpdateCharacteristicsInGattServer(const char *char_value,
123                                                             const uint32_t value_length)
124 {
125     // Currently ble_write_bytes api returns void.
126     ble_write_bytes((unsigned char *)char_value, (unsigned char)value_length);
127     return CA_STATUS_OK;
128 }
129