37 lines
888 B
C
37 lines
888 B
C
#ifndef WEBSOCKET_H_
|
|
#define WEBSOCKET_H_
|
|
|
|
#define WS_PORT 8080
|
|
#define WS_TIMEOUT 10
|
|
#define WS_DEBUG LWIP_DBG_ON
|
|
#define WS_MAX_RETRIES 10
|
|
#define WS_POLL_INTERVAL 60 // WS_POLL_INTERVAL/2 seconds
|
|
#define WS_MAX_CONN 4
|
|
#define WS_BUFFER_SIZE 512
|
|
|
|
#define OP_CONT 0x00
|
|
#define OP_TEXT 0x01
|
|
#define OP_BINARY 0x02
|
|
#define OP_CLOSE 0x08
|
|
#define OP_PING 0x09
|
|
#define OP_PONG 0x0A
|
|
|
|
struct ws_state {
|
|
bool active;
|
|
uint8_t retries;
|
|
struct altcp_pcb *pcb;
|
|
struct ws_state *next;
|
|
};
|
|
|
|
#define WS_ALLOC_WS_STATE() (struct ws_state *)mem_malloc(sizeof(struct ws_state))
|
|
|
|
typedef void (* tWSHandler ) (uint8_t *data, uint16_t len);
|
|
typedef void (* tWSOpenHandler ) (struct ws_state * wss);
|
|
|
|
void ws_server_init(void);
|
|
void ws_send_all(uint8_t *data, uint16_t len);
|
|
void ws_set_receive_handler( tWSHandler ws_handler);
|
|
void ws_set_open_handler( tWSOpenHandler ws_handler);
|
|
|
|
#endif
|