BLE mbed Endpoint network stack for mbedConnectorInterface. The stack makes use of a special BLE Socket abstraction to create socket() semantics over BLE.

Dependencies:   libnsdl_m0 BLE_API Base64 nRF51822 SplitterAssembler

Committer:
ansond
Date:
Tue Nov 03 17:03:51 2015 +0000
Revision:
38:30e71f1206b1
Parent:
9:bf0cf5828378
merged with IoS and android tweaks

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:7809547930d9 1 /* Copyright (C) 2012 mbed.org, MIT License
ansond 0:7809547930d9 2 *
ansond 0:7809547930d9 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:7809547930d9 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
ansond 0:7809547930d9 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:7809547930d9 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:7809547930d9 7 * furnished to do so, subject to the following conditions:
ansond 0:7809547930d9 8 *
ansond 0:7809547930d9 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:7809547930d9 10 * substantial portions of the Software.
ansond 0:7809547930d9 11 *
ansond 0:7809547930d9 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:7809547930d9 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:7809547930d9 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:7809547930d9 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:7809547930d9 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:7809547930d9 17 */
ansond 0:7809547930d9 18
ansond 0:7809547930d9 19 #include "Socket/UDPSocket.h"
ansond 0:7809547930d9 20
ansond 0:7809547930d9 21 #include <cstring>
ansond 0:7809547930d9 22
ansond 6:98af441fd960 23 #include "UartRPCFunctions.h"
ansond 6:98af441fd960 24
ansond 2:30f4a0dab604 25 // BLE network_stubs.cpp linkage
ansond 2:30f4a0dab604 26 extern "C" void ble_set_remote_ip_port(const int ipPort);
ansond 2:30f4a0dab604 27
ansond 0:7809547930d9 28 using std::memset;
ansond 0:7809547930d9 29
ansond 0:7809547930d9 30 UDPSocket::UDPSocket() {
ansond 0:7809547930d9 31 }
ansond 0:7809547930d9 32
ansond 0:7809547930d9 33 int UDPSocket::init(void) {
ansond 0:7809547930d9 34 return 0;
ansond 0:7809547930d9 35 }
ansond 0:7809547930d9 36
ansond 0:7809547930d9 37 // Server initialization
ansond 0:7809547930d9 38 int UDPSocket::bind(int port) {
ansond 2:30f4a0dab604 39 ble_set_remote_ip_port(port);
ansond 0:7809547930d9 40 return 0;
ansond 0:7809547930d9 41 }
ansond 0:7809547930d9 42
ansond 0:7809547930d9 43 // -1 if unsuccessful, else number of bytes written
ansond 0:7809547930d9 44 int UDPSocket::sendTo(Endpoint &remote, char *packet, int length) {
ansond 6:98af441fd960 45 return ble_rpc_send_data((uint8_t *)packet,length);
ansond 0:7809547930d9 46 }
ansond 0:7809547930d9 47
ansond 9:bf0cf5828378 48 // 0 if nothing to receive, else number of bytes received
ansond 0:7809547930d9 49 int UDPSocket::receiveFrom(Endpoint &remote, char *buffer, int length) {
ansond 9:bf0cf5828378 50 return ble_rpc_recv_packet((uint8_t *)buffer,length);
ansond 0:7809547930d9 51 }