Imported Upstream version 0.9.1
[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_radio_reset();
57     OIC_LOG(DEBUG, TAG, "OUT");
58     return CA_STATUS_OK;
59
60 }
61
62 unsigned char CAIsBleDataAvailable()
63 {
64     return ble_available();
65 }
66
67 unsigned char CAIsBleConnected()
68 {
69     return ble_connected();
70 }
71 char CAReadBleData()
72 {
73     return (char)ble_read();
74 }
75
76 CAResult_t CABleDoEvents()
77 {
78     ble_do_events();
79     return CA_STATUS_OK;
80 }
81
82 CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *char_value,
83                                                    uint8_t valueLength)
84 {
85     // ble_write_bytes() api can send only max of 255 bytes at a time
86     // This function shall never be called to send more than 255 bytes by the fragmentation logic.
87     // Currently ble_write_bytes api returns void.
88     ble_write_bytes((unsigned char *)char_value, (unsigned char)valueLength);
89     return CA_STATUS_OK;
90 }
91
92