ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 // Copyright 2017 Baidu Inc. All Rights Reserved.
TMBOY 47:9e361da97763 2 // Author: Su Hao (suhao@baidu.com)
TMBOY 47:9e361da97763 3 //
TMBOY 47:9e361da97763 4 // Description: SocketAdapter
TMBOY 47:9e361da97763 5
TMBOY 47:9e361da97763 6 #ifndef BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_ADAPTER_BAIDU_CA_NETWORK_SOCKET_H
TMBOY 47:9e361da97763 7 #define BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_ADAPTER_BAIDU_CA_NETWORK_SOCKET_H
TMBOY 47:9e361da97763 8
TMBOY 47:9e361da97763 9 #include "mbed.h"
TMBOY 47:9e361da97763 10 #include "baidu_ca.h"
TMBOY 47:9e361da97763 11
TMBOY 47:9e361da97763 12 namespace duer {
TMBOY 47:9e361da97763 13
TMBOY 47:9e361da97763 14 class SocketAdapter {
TMBOY 47:9e361da97763 15 public:
TMBOY 47:9e361da97763 16
TMBOY 47:9e361da97763 17 typedef mbed::Callback<void (const bca_addr_t*)> Callback;
TMBOY 47:9e361da97763 18
TMBOY 47:9e361da97763 19 SocketAdapter();
TMBOY 47:9e361da97763 20
TMBOY 47:9e361da97763 21 virtual ~SocketAdapter();
TMBOY 47:9e361da97763 22
TMBOY 47:9e361da97763 23 int connect(const bca_addr_t* addr);
TMBOY 47:9e361da97763 24
TMBOY 47:9e361da97763 25 int send(const void* data, size_t size);
TMBOY 47:9e361da97763 26
TMBOY 47:9e361da97763 27 int recv(void* data, size_t size);
TMBOY 47:9e361da97763 28
TMBOY 47:9e361da97763 29 int close();
TMBOY 47:9e361da97763 30
TMBOY 47:9e361da97763 31 void attach(Callback callback);
TMBOY 47:9e361da97763 32
TMBOY 47:9e361da97763 33 template <typename T, typename M>
TMBOY 47:9e361da97763 34 void attach(T* obj, M method) {
TMBOY 47:9e361da97763 35 attach(Callback(obj, method));
TMBOY 47:9e361da97763 36 }
TMBOY 47:9e361da97763 37
TMBOY 47:9e361da97763 38 static void set_network_interface(NetworkInterface* ifc);
TMBOY 47:9e361da97763 39
TMBOY 47:9e361da97763 40 static NetworkInterface* get_network_interface();
TMBOY 47:9e361da97763 41
TMBOY 47:9e361da97763 42 // the unit of speed is k/s
TMBOY 47:9e361da97763 43 static void bca_coap_get_statistic(float* upload_speed, float* download_speed);
TMBOY 47:9e361da97763 44 private:
TMBOY 47:9e361da97763 45
TMBOY 47:9e361da97763 46 void on_read();
TMBOY 47:9e361da97763 47
TMBOY 47:9e361da97763 48 Socket* _socket;
TMBOY 47:9e361da97763 49 bca_addr_t _addr;
TMBOY 47:9e361da97763 50 Callback _callback;
TMBOY 47:9e361da97763 51
TMBOY 47:9e361da97763 52 static NetworkInterface* _s_interface;
TMBOY 47:9e361da97763 53 };
TMBOY 47:9e361da97763 54
TMBOY 47:9e361da97763 55 } // namespace duer
TMBOY 47:9e361da97763 56
TMBOY 47:9e361da97763 57 #endif // BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_ADAPTER_BAIDU_CA_NETWORK_SOCKET_H