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
bt_network/Socket/Endpoint.cpp@2:30f4a0dab604, 2015-02-14 (annotated)
- Committer:
- ansond
- Date:
- Sat Feb 14 07:36:17 2015 +0000
- Revision:
- 2:30f4a0dab604
- Parent:
- 0:7809547930d9
updates
Who changed what in which revision?
User | Revision | Line number | New 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 | #include "Socket/Socket.h" |
ansond | 0:7809547930d9 | 19 | #include "Socket/Endpoint.h" |
ansond | 0:7809547930d9 | 20 | #include <cstring> |
ansond | 0:7809547930d9 | 21 | #include <cstdio> |
ansond | 0:7809547930d9 | 22 | |
ansond | 2:30f4a0dab604 | 23 | // BLE network_stubs.cpp linkage |
ansond | 2:30f4a0dab604 | 24 | extern "C" void ble_set_remote_ip_address(const char *ipAddress,const int ipAddressLength); |
ansond | 2:30f4a0dab604 | 25 | extern "C" void ble_set_remote_ip_port(const int ipPort); |
ansond | 2:30f4a0dab604 | 26 | |
ansond | 0:7809547930d9 | 27 | Endpoint::Endpoint() { |
ansond | 0:7809547930d9 | 28 | reset_address(); |
ansond | 0:7809547930d9 | 29 | } |
ansond | 0:7809547930d9 | 30 | Endpoint::~Endpoint() {} |
ansond | 0:7809547930d9 | 31 | |
ansond | 0:7809547930d9 | 32 | void Endpoint::reset_address(void) { |
ansond | 2:30f4a0dab604 | 33 | memset(_ipAddress,0,sizeof(_ipAddress)); |
ansond | 2:30f4a0dab604 | 34 | _ipPort = 0; |
ansond | 0:7809547930d9 | 35 | } |
ansond | 0:7809547930d9 | 36 | |
ansond | 0:7809547930d9 | 37 | #include "stdio.h" |
ansond | 0:7809547930d9 | 38 | |
ansond | 0:7809547930d9 | 39 | int Endpoint::set_address(const char* host, const int port) { |
ansond | 2:30f4a0dab604 | 40 | reset_address(); |
ansond | 2:30f4a0dab604 | 41 | |
ansond | 2:30f4a0dab604 | 42 | // XXX do we need to worry about hostname->ipaddress mapping for BLE? |
ansond | 2:30f4a0dab604 | 43 | memcpy(_ipAddress,host,strlen(host)); |
ansond | 2:30f4a0dab604 | 44 | ble_set_remote_ip_address(host,strlen(host)); |
ansond | 2:30f4a0dab604 | 45 | |
ansond | 2:30f4a0dab604 | 46 | // copy port number |
ansond | 2:30f4a0dab604 | 47 | _ipPort = port; |
ansond | 2:30f4a0dab604 | 48 | |
ansond | 2:30f4a0dab604 | 49 | // BLE also needs it for the connection record |
ansond | 2:30f4a0dab604 | 50 | ble_set_remote_ip_port(port); |
ansond | 2:30f4a0dab604 | 51 | |
ansond | 2:30f4a0dab604 | 52 | // return the port number... |
ansond | 2:30f4a0dab604 | 53 | return port; |
ansond | 0:7809547930d9 | 54 | } |
ansond | 0:7809547930d9 | 55 | |
ansond | 0:7809547930d9 | 56 | char* Endpoint::get_address() { |
ansond | 2:30f4a0dab604 | 57 | return _ipAddress; |
ansond | 0:7809547930d9 | 58 | } |
ansond | 0:7809547930d9 | 59 | |
ansond | 0:7809547930d9 | 60 | int Endpoint::get_port() { |
ansond | 2:30f4a0dab604 | 61 | return _ipPort; |
ansond | 0:7809547930d9 | 62 | } |