components/websocket/include/websocket_server.h

Sat, 06 Jun 2020 13:28:46 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 06 Jun 2020 13:28:46 +0200
changeset 77
66c77497d86d
parent 30
3cc32f97410c
permissions
-rw-r--r--

Changed the recipe database so that it is expandable, version 2. More mash fields and allow 16 steps. Allow 20 Additions. Removed separate mash steps from the state machine, the steps are moved to the runtime data. There is no fixed step number for mashout anymore. There is no fixed step for mash-in anymore, just use the first step and heat to the infusion temperature. After malt add, switch to the normal step temperature. Implemented decoction steps.

/**
 * @file websocket_server.h
 * @brief Websocket server functions.
 * @author Blake Felt - blake.w.felt@gmail.com`
 */

#ifdef __cplusplus
extern "C" {
#endif

#ifndef WEBSOCKET_SERVER_H
#define WEBSOCKET_SERVER_H

#include "websocket.h"

#define WEBSOCKET_SERVER_MAX_CLIENTS CONFIG_WEBSOCKET_SERVER_MAX_CLIENTS		///< Maximum allowed clients
#define WEBSOCKET_SERVER_QUEUE_SIZE CONFIG_WEBSOCKET_SERVER_QUEUE_SIZE			///< Webserver requests queue size
#define WEBSOCKET_SERVER_QUEUE_TIMEOUT CONFIG_WEBSOCKET_SERVER_QUEUE_TIMEOUT		///< Queue timeout
#define WEBSOCKET_SERVER_TASK_STACK_DEPTH CONFIG_WEBSOCKET_SERVER_TASK_STACK_DEPTH	///< Task stack size
#define WEBSOCKET_SERVER_TASK_PRIORITY CONFIG_WEBSOCKET_SERVER_TASK_PRIORITY		///< Task priority
#define WEBSOCKET_SERVER_PINNED CONFIG_WEBSOCKET_SERVER_PINNED				///< Pinned to a CPU
#if WEBSOCKET_SERVER_PINNED
#define WEBSOCKET_SERVER_PINNED_CORE CONFIG_WEBSOCKET_SERVER_PINNED_CORE		///< If pinned, which CPU
#endif

/**
 * @brief Starts the server.
 * @return 1 if started, 0 if the server was already started.
 */
int ws_server_start();

/**
 * @brief Stops the server.
 * @return 1 if stopped, 0 if the server was not running.
 */
int ws_server_stop();

/**
 * @brief Adds a client, returns the client's number in the server.
 * @param conn The network connection.
 * @param msg The message received from the client.
 * @param len The length of the message.
 * @param url The url of the connection.
 * @param callback The callback function.
 * @return Negative if an error, else the connection number.
 */
int ws_server_add_client(struct netconn* conn,
                         char* msg,
                         uint16_t len,
                         char* url,
                         void (*callback)(uint8_t num, WEBSOCKET_TYPE_t type, char* msg, uint64_t len));

/**
 * @brief Adds a client, returns the client's number in the server.
 * @param conn The network connection.
 * @param msg The message received from the client.
 * @param len The length of the message.
 * @param url The url of the connection.
 * @param protocol The protocol requested by the client.
 * @param callback The callback function.
 * @return Negative if an error, else the connection number.
 */
int ws_server_add_client_protocol(struct netconn* conn,
                                  char* msg,
                                  uint16_t len,
                                  char* url,
                                  char* protocol,
                                  void (*callback)(uint8_t num, WEBSOCKET_TYPE_t type, char* msg, uint64_t len));

/**
 * @brief Returns the number of connected clients to url
 * @param url The url to check.
 * @return The number of connected clients.
 */
int ws_server_len_url(char* url);

/**
 * @brief Returns the total number of connected clients.
 * @return The number of connected clients.
 */
int ws_server_len_all();

/**
 * @brief Removes the client with the set number
 * @param num The client number.
 * @return 1 if success, else 0.
 */
int ws_server_remove_client(int num);

/**
 * @brief Removes all clients connected to the specified url.
 * @param url The connection url.
 * @return The number of clients removed.
 */
int ws_server_remove_clients(char* url);

/**
 * @brief Removes all clients from the server.
 * @return The number of clients removed.
 */
int ws_server_remove_all();

/**
 * @brief Send text to client with the set number.
 * @param num The client connection number.
 * @param msg The message to send.
 * @param len The length of the message to send.
 * @return 1 if message send.
 */
int ws_server_send_text_client(int num,char* msg,uint64_t len);
int ws_server_send_text_client_from_callback(int num,char* msg,uint64_t len);

/**
 * @brief Sends text to all clients with the set url.
 * @param url The clients url.
 * @param msg The message to send.
 * @param len The length of the message to send.
 * @return The number of clients the message was send to.
 */
int ws_server_send_text_clients(char* url,char* msg,uint64_t len);
int ws_server_send_text_clients_from_callback(char* url,char* msg,uint64_t len);

/**
 * @brief Sends text to all clients.
 * @param msg The message to send.
 * @param len The length of the message to send.
 * @return The number of clients the message was send to.
 */
int ws_server_send_text_all(char* msg,uint64_t len);
int ws_server_send_text_all_from_callback(char* msg,uint64_t len);

/**
 * @brief Send binary message to client with the set number.
 * @param num The client connection number.
 * @param msg The message to send.
 * @param len The length of the message to send.
 * @return 1 if message send.
 */
int ws_server_send_bin_client(int num,char* msg,uint64_t len);
int ws_server_send_bin_client_from_callback(int num,char* msg,uint64_t len);

/**
 * @brief Sends binary message to all clients with the set url.
 * @param url The clients url.
 * @param msg The message to send.
 * @param len The length of the message to send.
 * @return The number of clients the message was send to.
 */
int ws_server_send_bin_clients(char* url,char* msg,uint64_t len);

/**
 * @brief Sends binary message to all clients.
 * @param msg The message to send.
 * @param len The length of the message to send.
 * @return The number of clients the message was send to.
 */
int ws_server_send_bin_all(char* msg,uint64_t len);

/**
 * @brief Websocket ping (not working yet)
 * @param num The connection number
 * @return 1 if succeeded.
 */
int ws_server_ping(int num);

#endif

#ifdef __cplusplus
}
#endif

mercurial