TuyaOS
websocket_client.h
1 /*============================================================================
2 * *
3 * Copyright (C) by Tuya Inc *
4 * All rights reserved *
5 * *
6 * @author : Linch *
7 * @date : 2020-07-07 *
8 * @brief : *
9 * @log : *
10 =============================================================================*/
11
12#ifndef __WEBSOCKET_H__
13#define __WEBSOCKET_H__
14
15#ifdef __cplusplus
16 extern "C" {
17#endif
18
19/*============================ INCLUDES ======================================*/
20#include "tuya_iot_config.h"
21#include "tuya_transporter.h"
22
23/*============================ MACROS ========================================*/
24/*============================ MACROFIED FUNCTIONS ===========================*/
25/*============================ TYPES =========================================*/
26typedef enum {
27 WEBSOCKET_OK,
28 WEBSOCKET_COM_ERROR,
29 WEBSOCKET_MALLOC_FAILED,
30 WEBSOCKET_INVALID_PARM,
31} websocket_error_t;
32
33typedef enum {
34 WEBSOCKET_RECV_DATA_EVENT,
35 WEBSOCKET_CONNECTED_EVENT,
36 WEBSOCKET_DISCONNECT_EVENT,
37} websocket_client_event_t;
38
39typedef struct {
40 websocket_client_event_t event;
41 uint8_t *data;
42 uint32_t len;
44
45
46typedef void (*websocket_client_event_cb_t)(websocket_client_msg_t *msg, void *priv_data);
47
48typedef struct {
49 char *uri;
50 char* scheme;
51 char* host;
52 int port;
53 tuya_tcp_config_t tcpConfig;
54 void *priv_data;
55 websocket_client_event_cb_t event_cb;
57
58
59typedef void *websocket_client_handle_t;
60
61/*============================ PROTOTYPES ====================================*/
62int websocket_client_init (websocket_client_handle_t *handle, websocket_client_cfg_t *cfg);
63int websocket_client_start (websocket_client_handle_t handle, char *name);
64
65
66int websocket_client_set_path(websocket_client_handle_t handle, char *path);
67
68int websocket_client_send_bin (websocket_client_handle_t handle, const uint8_t *data, uint32_t data_len);
69int websocket_client_send_text (websocket_client_handle_t handle, const uint8_t *data, uint32_t data_len);
70
71int websocket_client_disconnect (websocket_client_handle_t handle);
72
73int websocket_client_open(websocket_client_handle_t client, int connect_timeout_ms);
74
75int websocket_client_poll(websocket_client_handle_t client, int timeout_ms);
76int websocket_client_read(websocket_client_handle_t client, uint8_t *buffer, int len);
77void websocket_client_close(websocket_client_handle_t client);
78
79#ifdef __cplusplus
80} // extern "C"
81#endif
82
83#endif
定义了tcp transporter配置选项
Definition: tuya_transporter.h:56
Definition: websocket_client.h:48
char * scheme
<ws/wss>://host[:port]/path
Definition: websocket_client.h:50
Definition: websocket_client.h:39