Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: libnsdl_m0 BLE_API Base64 nRF51822 SplitterAssembler
Diff: bt_network/BleUartRPC/UartRPCFunctions.cpp
- Revision:
- 6:98af441fd960
- Parent:
- 5:9233e88b9c83
- Child:
- 9:bf0cf5828378
--- a/bt_network/BleUartRPC/UartRPCFunctions.cpp Mon Feb 16 06:37:35 2015 +0000 +++ b/bt_network/BleUartRPC/UartRPCFunctions.cpp Tue Feb 17 02:56:36 2015 +0000 @@ -48,67 +48,56 @@ bool ble_rpc_open_udp_socket(char *ip_address,int port) { - bool success = false; uint8_t response[2]; - memset(response,0,sizeof(response)); - if (__rpc->dispatch(SOCKET_OPEN_FN,response,sizeof((char *)response),"%s %d",ip_address,port)) { - // success - int reply = 0; - scanf((char *)response,"%d",&reply); - if (reply == 1) success = true; + memset(response,0,2); + if (__rpc->dispatch(SOCKET_OPEN_FN,response,2,"%s %d",ip_address,port) > 0) { + DBG("ble_rpc_open_udp_socket: success...\r\n"); + return true; } - else { - // failure - DBG("ble_rpc_open_udp_socket: dispatch() failed\r\n"); - } - return success; + + // failure + DBG("ble_rpc_open_udp_socket: dispatch() failed\r\n"); + return false; } bool ble_rpc_close_udp_socket(void) { - bool success = false; uint8_t response[2]; - memset(response,0,sizeof(response)); - if (__rpc->dispatch(SOCKET_CLOSE_FN,response,sizeof((char *)response),"%s","")) { - // success - int reply = 0; - scanf((char *)response,"%d",&reply); - if (reply == 1) success = true; + memset(response,0,2); + if (__rpc->dispatch(SOCKET_CLOSE_FN,response,2,"%s","") > 0) { + DBG("ble_rpc_close_udp_socket: success...\r\n"); + return true; } - else { - // failure - DBG("ble_rpc_close_udp_socket: dispatch() failed\r\n"); - } - return success; + + // failure + DBG("ble_rpc_close_udp_socket: dispatch() failed\r\n"); + return false; } - bool ble_rpc_send_data(uint8_t *data,int data_length) + int ble_rpc_send_data(uint8_t *data,int data_length) { - bool success = false; + Base64 b64; uint8_t response[2]; - memset(response,0,sizeof(response)); - Base64 b64; + memset(response,0,2); int base64_data_length = MAX_ARGUMENT_LENGTH; + DBG("ble_rpc_send_data: base64 encoding data...\r\n"); char *base64_data = b64.Encode((char *)data,data_length,(std::size_t *)&base64_data_length); - if (__rpc->dispatch(SEND_DATA_FN,response,sizeof((char *)response),"%s",base64_data)) { - // success - int reply = 0; - scanf((char *)response,"%d",&reply); - if (reply == 1) success = true; - } - else { - // failure - DBG("ble_rpc_send_data: dispatch() failed\r\n"); - } + DBG("ble_rpc_send_data: sending data=[%s] length=%d...\r\n",base64_data,strlen((char *)base64_data)); + int sent_length = __rpc->dispatch(SEND_DATA_FN,response,2,"%s",base64_data); + DBG("ble_rpc_send_data: dispatched %d bytes\r\n",sent_length); if (base64_data != NULL) free(base64_data); - return success; + return sent_length; } int ble_rpc_recv_data(uint8_t *buffer,int buffer_length) { + /* uint8_t base64_buffer[MAX_RESULT_LENGTH+1]; - memset(base64_buffer,0,sizeof(base64_buffer)); - if (__rpc->dispatch(RECV_DATA_FN,base64_buffer,MAX_RESULT_LENGTH,"%s","")) { + memset(base64_buffer,0,MAX_RESULT_LENGTH+1); + DBG("ble_rpc_recv_data: seeing if any data is available...\r\n"); + int recv_length =__rpc->dispatch(RECV_DATA_FN,base64_buffer,MAX_RESULT_LENGTH,"%s",""); + DBG("ble_rpc_recv_data: received %d bytes of data...\r\n",recv_length); + if (recv_length > 0) { // success Base64 b64; int base64_length = buffer_length; @@ -121,6 +110,7 @@ // failure DBG("ble_rpc_recv_data: dispatch() failed\r\n"); } + */ return -1; } \ No newline at end of file