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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Dispatcher.h Source File

Dispatcher.h

Go to the documentation of this file.
00001 /**
00002  * @file    Dispatcher.h
00003  * @brief   BLE UART RPC dispatcher header
00004  * @author  Doug Anson
00005  * @version 1.0
00006  * @see     
00007  *
00008  * Copyright (c) 2014
00009  *
00010  * Licensed under the Apache License, Version 2.0 (the "License");
00011  * you may not use this file except in compliance with the License.
00012  * You may obtain a copy of the License at
00013  *
00014  *     http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing, software
00017  * distributed under the License is distributed on an "AS IS" BASIS,
00018  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  * See the License for the specific language governing permissions and
00020  * limitations under the License.
00021  */
00022  
00023  #ifndef __RPC_DISPATCH_H__
00024  #define __RPC_DISPATCH_H__
00025  
00026  #include "BLEDevice.h"
00027  #include "UARTService.h"
00028  #include "SplitterAssembler.h"
00029  
00030  // These are aligned with MAX_VALUE_BUFFER_LENGTH in mbedConnectorInterface.h 
00031  #define MAX_PACKET_LENGTH          340            // longest packet we will send (aligns with 15x20 in SplitterAssembler)
00032  #define MAX_ARGUMENT_LENGTH        340            // longest argument sent as parameter list (aligns with 15x20 in SplitterAssembler)
00033  #define MAX_RESULT_LENGTH          340            // longest result received (aligns with 15x20 in SplitterAssembler)
00034  
00035  // This is aligned with the value of DEF_FRAGMENT_LENGTH in SplitterAssembler.h and is also the max UART MTU for BLE
00036  #define UART_SEGMENT_LENGTH        20             // BLE: max UART MTU (will trigger send immediately...)
00037   
00038  class Dispatcher {
00039      public:
00040         /**
00041         Default constructor
00042         @param ble the BLEDevice instance
00043         */
00044         Dispatcher(BLEDevice &ble);
00045         
00046         /**
00047         Dispatch function request with arguments (already serialized and prepared for transport)
00048         @param fn_id the identifier for the target remote function to invoke
00049         @param args the serialized function argument array list
00050         @param args_length the length of the serialized function argument list
00051         @param response the received response buffer
00052         @param response_length the recieved response buffer length
00053         @returns number of bytes sent in dispatch() or -1 if in failure
00054         */
00055         int dispatch(uint8_t fn_id,uint8_t *args,int args_length,uint8_t *response,int response_length);
00056         
00057      private:
00058         void                 onDataWritten(const GattCharacteristicWriteCBParams *params);
00059         
00060         int                  uart_write(bool send_ack = false);
00061         int                  uart_write(uint8_t *data,int data_length);
00062         int                  prepare_send_packet(uint8_t fn_id,uint8_t *args,int args_length);
00063         
00064         uint8_t              m_send_packet[MAX_PACKET_LENGTH+1];
00065         UARTService          m_uart;
00066         SplitterAssembler    m_splitter;
00067         int                  m_splitter_count;
00068         int                  m_splitter_index;
00069  };
00070  
00071  #endif // __RPC_DISPATCH_H__