mbedからGluinサーバへ接続するライブラリです
Embed:
(wiki syntax)
Show/hide line numbers
DxClient.h
00001 /** 00002 * @author Satoshi Komorita 00003 * 00004 * @section LICENSE 00005 * 00006 * Copyright (c) 2014 Satoshi Komorita 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy 00009 * of this software and associated documentation files (the "Software"), to deal 00010 * in the Software without restriction, including without limitation the rights 00011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 * copies of the Software, and to permit persons to whom the Software is 00013 * furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included in 00016 * all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 * THE SOFTWARE. 00025 * 00026 * @section DESCRIPTION 00027 * Simple websocket client 00028 * 00029 */ 00030 00031 #ifndef DXCLIENT_H 00032 #define DXCLIENT_H 00033 00034 #include "mbed.h" 00035 #include "EthernetInterface.h" 00036 #include "Websocket.h" 00037 00038 #define MAX_USERNAME 32 00039 #define MAX_PASSWORD 32 00040 #define MAX_DEVICEID 64 00041 00042 #define MAX_PROPLEN 128 00043 #define MAX_PROPNAMELEN 32 00044 #define MAX_PROPSVALLEN 64 00045 00046 #define MAX_MESSAGELEN 512 00047 #define MAX_MESSAGEIDLEN 32 00048 00049 #define MAX_DEV_DESCRIPTION 64 00050 #define MAX_DEV_NAME 32 00051 00052 typedef enum { 00053 DX_STRING, 00054 DX_INTEGER, 00055 DX_FLOAT, 00056 DX_BOOLEAN 00057 } dx_prop_type; 00058 typedef enum { 00059 DX_UPONLY, 00060 DX_DOWNONLY, 00061 DX_UPDOWN 00062 } dx_prop_direction; 00063 typedef enum { 00064 DX_WRITEONLY, 00065 DX_READONLY, 00066 DX_READWRITE 00067 } dx_prop_mode; 00068 typedef struct { 00069 char name[MAX_PROPNAMELEN]; 00070 dx_prop_type type; 00071 dx_prop_mode mode; 00072 dx_prop_direction direction; 00073 char s_val[MAX_PROPSVALLEN]; 00074 float f_val; 00075 bool b_val; 00076 } dx_prop; 00077 00078 typedef struct { 00079 int numofprops; 00080 dx_prop *props; 00081 } dx_props; 00082 00083 typedef bool ( *REQUEST_HANDLER )( dx_props *props); 00084 00085 class DxClient 00086 { 00087 public: 00088 00089 /** 00090 * Constructor 00091 * @param url The DxClient url in the form "ws://ip_domain[:port]/path" (by default: port = 80) 00092 * @param deviceid is uniqued ID identifing this device. 00093 */ 00094 DxClient(char * url, char* deviceid, float seed); 00095 00096 /* 00097 * Set Auth User and Password 00098 * this method should be called before connect(); 00099 */ 00100 void set_user(char* user, char *pass); 00101 00102 void set_device_description(char* desc); 00103 void set_device_name(char* name); 00104 00105 /** 00106 * Connect to the websocket url 00107 *@return true if the connection is established, false otherwise 00108 */ 00109 bool connect(); 00110 00111 /** 00112 * close websocket connection 00113 *@return true if the connection is established, false otherwise 00114 */ 00115 bool close(); 00116 00117 /* 00118 * send device_register_requsest message to server 00119 */ 00120 bool register_device(dx_props* props); 00121 00122 /* 00123 * send device_unregister_requsest message to server 00124 */ 00125 bool deregister_device(); 00126 00127 /* 00128 * send device_update_request to server 00129 */ 00130 bool update_device(dx_props *props); 00131 00132 /* 00133 * send device_keepalive_request to server 00134 */ 00135 bool keepalive_device(void); 00136 00137 /* 00138 * handle device_get_request from server 00139 */ 00140 void set_get_requset_handler(REQUEST_HANDLER handler); 00141 00142 /* 00143 * handle device_get_request from server 00144 */ 00145 void set_set_requset_handler(REQUEST_HANDLER handler); 00146 00147 00148 bool handle_messages(void); 00149 00150 private: 00151 00152 Websocket m_ws; 00153 00154 char m_user[MAX_USERNAME]; 00155 char m_pass[MAX_PASSWORD]; 00156 char m_deviceid[MAX_DEVICEID]; 00157 char m_dev_description[MAX_DEV_DESCRIPTION]; 00158 char m_dev_name[MAX_DEV_NAME]; 00159 00160 REQUEST_HANDLER m_func_get_request; 00161 REQUEST_HANDLER m_func_set_request; 00162 // bool (*m_func_set_handler)(dx_props *props); 00163 00164 bool dx_user_auth_request(); 00165 bool dx_device_set_response( dx_props *props, const char* mesid); 00166 bool dx_device_get_response( dx_props *props, const char* mesid); 00167 bool dx_error_response( const char* mesid); 00168 00169 00170 }; 00171 00172 00173 #endif
Generated on Tue Jul 12 2022 20:06:16 by 1.7.2