|
ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts
1.0
ESP8266ILI9341DisplayProject
|
Small web server for esp8266. More...
#include "user_config.h"#include <stdint.h>#include <stdarg.h>#include <string.h>#include <math.h>#include "display/ili9341.h"#include "web/web.h"Go to the source code of this file.
Macros | |
| #define | MAX_MSG 1024 |
| max size of ERROR/REDIRECT/STATUS Message buffer More... | |
| #define | CGI_TOKEN_SIZE 128 |
| max size of CGI token More... | |
| #define | BUFFER_SIZE 1000 |
| max size of read/write socket buffers Note: reducing this size below 1500 will slow down transfer a great deal More... | |
Functions | |
| MEMSPACE void | web_sep (void) |
| printer seperator More... | |
| MEMSPACE int | wait_send (rwbuf_t *p) |
| Wait for buffer to send for this connection If write_buffer sending flag is set then wait for it to clear. More... | |
| MEMSPACE int | write_buffer (rwbuf_t *p) |
| Socket write buffer for this connection We wait for previous send to complete - then send any new data We do not wait for new data to finish sending - you use flush for that. More... | |
| MEMSPACE int | write_flush (rwbuf_t *p) |
| Write all outstanding data and wait for it to send. More... | |
| MEMSPACE int | write_byte (rwbuf_t *p, int c) |
| Write a byte (buffered) using the rwbuf_t socket buffers for this connection If the buffers are full the socket is written using write_flush. More... | |
| MEMSPACE void | led_on (int led) |
| MEMSPACE void | led_off (int led) |
| Turn off virtual LED. More... | |
| static MEMSPACE void | tcp_accept (espconn_t *esp_config, esp_tcp *esp_tcp_config, uint16_t port, void(*connect_callback)(struct espconn *)) |
| Accept an incomming connection, setup connect_callback. More... | |
| MEMSPACE void | rwbuf_rinit (rwbuf_t *p) |
| Initialize socket read status and read index. More... | |
| MEMSPACE void | rwbuf_winit (rwbuf_t *p) |
| Initialize socket send status and write index. More... | |
| MEMSPACE void | display_ipv4 (char *msg, uint8_t *ip, int port) |
| Display IPV4 address. More... | |
| MEMSPACE void | rwbuf_delete (rwbuf_t *p) |
| Delete socket read/write buffers. More... | |
| MEMSPACE rwbuf_t * | rwbuf_create () |
| Create socket read/write buffer for a connection. More... | |
| MEMSPACE rwbuf_t * | find_connection (espconn_t *conn, int *index, char *msg) |
| Find a read/write socket buffer for an espconn connection. More... | |
| MEMSPACE rwbuf_t * | create_connection (espconn_t *conn) |
| Allocate read/write socket buffers and add it to the working pool. More... | |
| MEMSPACE int | delete_connection (rwbuf_t *p) |
| Delete our main connection structure and connection buffers. More... | |
| MEMSPACE void | write_len (rwbuf_t *p, char *str, int len) |
| Write data using buffered write_byte function. More... | |
| MEMSPACE void | write_str (rwbuf_t *p, char *str) |
| Write string using buffered write_byte function. More... | |
| static MEMSPACE void | _write_byte_fn (struct _printf_t *pr, char c) |
| low level vsock_printf function that calls socket write_byte More... | |
| MEMSPACE int | vsock_printf (rwbuf_t *p, const char *fmt, va_list va) |
| vsock_printf function More... | |
| MEMSPACE int | sock_printf (rwbuf_t *p, const char *fmt,...) |
| sock_printf function More... | |
| MEMSPACE int | html_msg (rwbuf_t *p, int status, char type, char *fmt,...) |
| Send an HTML status message to socket. More... | |
| MEMSPACE char * | meminit (mem_t *p, char *ptr, int size) |
| in memory memory gets function More... | |
| MEMSPACE char * | memgets (mem_t *p) |
| Memory gets function We ASSUME we can replace any with a \0. More... | |
| MEMSPACE char * | mime_type (int type) |
| return strung pointer for mime type index More... | |
| MEMSPACE int | file_type (char *name) |
| Determin mimetype using file name extension. More... | |
| MEMSPACE char * | html_status (int status) |
| Convert html status into string using http_status table. More... | |
| MEMSPACE void | init_hinfo (hinfo_t *hi) |
| MEMSPACE int | match_headers (char *str, char **p) |
| Match GET/POST message headers. More... | |
| MEMSPACE char * | process_args (hinfo_t *hi, char *ptr) |
| Process GET argments or POST message name/value data. HTML encoding is done in place often reducting the size of the result. Convert name=value pairs into null terminated strings. Names and values are each terminated with an EOS by replaceing '?', '&', '=' characters seen while scaning. More... | |
| MEMSPACE char * | first_arg (hinfo_t *hi) |
| Find first POST/GET argument. More... | |
| MEMSPACE char * | next_arg (hinfo_t *hi) |
| Find next POST/GET argument We have to skip a name and a value. More... | |
| MEMSPACE char * | arg_name (hinfo_t *hi) |
| Return the argument name for current argument. More... | |
| MEMSPACE char * | arg_value (hinfo_t *hi) |
| Return the argument value for current argument. More... | |
| MEMSPACE char * | http_value (hinfo_t *hi, char *str) |
| Lookup and argument name and return its value. More... | |
| MEMSPACE int | is_header (char *str, char **p) |
| Does the string look like a header token with a ':' ? More... | |
| MEMSPACE char * | nextbreak (char *ptr) |
| Find next space or ? character. More... | |
| MEMSPACE void | u5toa (char *ptr, uint16_t num) |
| Print a decimal number into a string without an EOS. More... | |
| MEMSPACE void | html_head (rwbuf_t *p, int status, char type, int len) |
| Write HTTP Contenet-Type/Content-Length header. More... | |
| MEMSPACE int | parse_http_request (rwbuf_t *p, hinfo_t *hi) |
| Get arguments for a GET or POST request. More... | |
| static MEMSPACE void | web_data_receive_callback (void *arg, char *data, unsigned short length) |
| Network receive callback function. More... | |
| static MEMSPACE void | web_data_sent_callback (void *arg) |
| Network sent callback function. More... | |
| static MEMSPACE void | web_data_disconnect_callback (void *arg) |
| Network disconnect callback function. More... | |
| static MEMSPACE void | web_data_error_callback (void *arg, int8_t err) |
| Network Error callback function. More... | |
| static MEMSPACE void | web_data_connect_callback (espconn_t *conn) |
| incomming connection setup callbacks More... | |
| MEMSPACE int | is_cgitoken_char (int c) |
| test to see if a character is a valid member of the CGI token character set CGI tokens have the following syntax @ They start with "@_" and end with "_@" "@_" must be first two characters of string May have upper and lower case letters, numbers and '-' More... | |
| MEMSPACE int | find_cgitoken_start (char *str) |
| Find start of CGI token in a string CGI tokens have the following syntax @ They start with "@_" and end with "_@" "@_" must be first two characters of string May have upper and lower case letters, numbers and '-' param[in] *str: string to search. More... | |
| MEMSPACE int | is_cgitoken (char *str) |
| Does the string have a CGI TOKEN at the beginning ? CGI tokens have the following syntax @ They start with "@_" and end with "_@" "@_" must be first two characters of string May have upper and lower case letters, numbers and '-'. More... | |
| MEMSPACE int | rewrite_cgi_token (rwbuf_t *p, char *src) |
| Replace CGI token with CGI result CGI tokens have the following syntax @ They start with "@_" and end with "_@" "@_" must be first two characters of string May have upper and lower case letters, numbers and '-'. More... | |
| static MEMSPACE void | process_requests (rwbuf_t *p) |
| Process an incoming HTTP request. More... | |
| MEMSPACE void | web_task () |
| Process ALL incoming HTTP requests. More... | |
| MEMSPACE void | web_init_connections () |
| MEMSPACE void | web_init (int port) |
| Setup WEB server and accept connections. More... | |
Variables | |
| int | connections |
| window * | winmsg |
| window * | wintop |
| rwbuf_t * | web_connections [MAX_CONNECTIONS] |
| socket buffers for this connection More... | |
| espconn_t | WebConn |
| Master espconn structure of the web server. More... | |
| static esp_tcp | WebTcp |
| Master network configuration for the web server. More... | |
| header_t | msg_headers [] |
| HTTP headers we understand. More... | |
| char * | http_status [] |
| HTTP status code messages. More... | |
| mime_t | mimes [] |
| MIME types. More... | |
| static MEMSPACE | _led = 0 |
| Turn on virtual LED. More... | |
Small web server for esp8266.
This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file web.c.
| #define BUFFER_SIZE 1000 |
max size of read/write socket buffers Note: reducing this size below 1500 will slow down transfer a great deal
Definition at line 43 of file web.c.
Referenced by rwbuf_create().
| #define MAX_MSG 1024 |
max size of ERROR/REDIRECT/STATUS Message buffer
Definition at line 38 of file web.c.
Referenced by html_msg().
low level vsock_printf function that calls socket write_byte
| [in] | *pr | printf structure and user buffer for this socket |
| [in] | c | character to write |
Definition at line 790 of file web.c.
Referenced by vsock_printf().
Return the argument name for current argument.
| [in] | *hi | hinfo_t structure with arguments |
Definition at line 1298 of file web.c.
Referenced by http_value(), and parse_http_request().
Return the argument value for current argument.
| [in] | *hi | hinfo_t structure with arguments |
Definition at line 1346 of file web.c.
Referenced by http_value(), and parse_http_request().
Allocate read/write socket buffers and add it to the working pool.
| [in] | conn | espconn pointer for this connection |
Definition at line 669 of file web.c.
Referenced by web_data_connect_callback().
Delete our main connection structure and connection buffers.
| [in] | p | rwbuf_t pointer |
Definition at line 715 of file web.c.
Referenced by web_data_disconnect_callback().
Display IPV4 address.
| [in] | msg | user supplied message |
| [in] | ip | IP address as uint8_t [4] |
| [in] | port | Port number |
Definition at line 470 of file web.c.
Referenced by delete_connection(), find_connection(), web_data_connect_callback(), web_data_disconnect_callback(), web_data_error_callback(), web_data_receive_callback(), and web_data_sent_callback().
| MEMSPACE int file_type | ( | char * | name | ) |
| MEMSPACE int find_cgitoken_start | ( | char * | str | ) |
Find start of CGI token in a string CGI tokens have the following syntax @ They start with "@_" and end with "_@" "@_" must be first two characters of string May have upper and lower case letters, numbers and '-' param[in] *str: string to search.
Find a read/write socket buffer for an espconn connection.
| [in] | conn | espconn pointer for this connection |
| [in] | *index | return index into pool of rwbuf_t connections |
| [in] | *msg | user debug message |
Definition at line 590 of file web.c.
Referenced by web_data_disconnect_callback(), web_data_error_callback(), web_data_receive_callback(), and web_data_sent_callback().
Find first POST/GET argument.
| [in] | *hi | hinfo_t structure with arguments |
Definition at line 1235 of file web.c.
Referenced by http_value(), and parse_http_request().
| MEMSPACE char* html_status | ( | int | status | ) |
Convert html status into string using http_status table.
| [in] | status | html status number |
Definition at line 1030 of file web.c.
Referenced by html_head(), and html_msg().
| MEMSPACE int is_cgitoken | ( | char * | str | ) |
Does the string have a CGI TOKEN at the beginning ? CGI tokens have the following syntax @ They start with "@_" and end with "_@" "@_" must be first two characters of string May have upper and lower case letters, numbers and '-'.
/**
| MEMSPACE int is_cgitoken_char | ( | int | c | ) |
test to see if a character is a valid member of the CGI token character set CGI tokens have the following syntax @ They start with "@_" and end with "_@" "@_" must be first two characters of string May have upper and lower case letters, numbers and '-'
| [in] | c | character to test |
| MEMSPACE int is_header | ( | char * | str, |
| char ** | p | ||
| ) |
Does the string look like a header token with a ':' ?
| [in] | *str | string to test |
| [in] | **p | string pointer to set on match |
Definition at line 1451 of file web.c.
Referenced by parse_http_request().
| MEMSPACE void led_off | ( | int | led | ) |
| MEMSPACE int match_headers | ( | char * | str, |
| char ** | p | ||
| ) |
Match GET/POST message headers.
| [in] | *str | string to patch |
| [in] | **p | points past matched string on sucess |
Definition at line 1077 of file web.c.
Referenced by parse_http_request().
Memory gets function We ASSUME we can replace any
with a \0.
| [in] | p | structure with size and offset used by mem_gets() |
Definition at line 952 of file web.c.
Referenced by parse_http_request().
in memory memory gets function
| [in] | p | structure with size and offset used by mem_gets() |
| [in] | ptr | start of memory area |
| [in] | size | size of memory area |
Definition at line 933 of file web.c.
Referenced by parse_http_request().
| MEMSPACE char* mime_type | ( | int | type | ) |
return strung pointer for mime type index
| [in] | type | index into mim_type table |
Definition at line 983 of file web.c.
Referenced by html_head(), and html_msg().
Find next POST/GET argument We have to skip a name and a value.
| [in] | *hi | hinfo_t structure with arguments |
Definition at line 1247 of file web.c.
Referenced by http_value(), and parse_http_request().
| MEMSPACE char* nextbreak | ( | char * | ptr | ) |
Find next space or ? character.
| [in] | *ptr | string to search |
Definition at line 1476 of file web.c.
Referenced by parse_http_request().
Process GET argments or POST message name/value data. HTML encoding is done in place often reducting the size of the result. Convert name=value pairs into null terminated strings. Names and values are each terminated with an EOS by replaceing '?', '&', '=' characters seen while scaning.
| [in] | *hi | hinfo_t structure to fill |
| [in] | *ptr | GET arguments or PUT message body. |
Definition at line 1116 of file web.c.
Referenced by parse_http_request().
Replace CGI token with CGI result CGI tokens have the following syntax @ They start with "@_" and end with "_@" "@_" must be first two characters of string May have upper and lower case letters, numbers and '-'.
| [in] | *p | socket stream |
| [in] | *str | string with token, example @ |
Create socket read/write buffer for a connection.
Definition at line 526 of file web.c.
Referenced by create_connection().
Delete socket read/write buffers.
| [in] | p | rwbuf_t pointer to buffer to delete |
Definition at line 487 of file web.c.
Referenced by delete_connection(), and rwbuf_create().
Initialize socket read status and read index.
| [in] | p | rwbuf_t pointer |
Definition at line 439 of file web.c.
Referenced by rwbuf_create(), rwbuf_delete(), and web_data_receive_callback().
Initialize socket send status and write index.
| [in] | p | rwbuf_t pointer |
Definition at line 453 of file web.c.
Referenced by rwbuf_create(), rwbuf_delete(), and web_data_sent_callback().
sock_printf function
| [in] | p | socket buffer structure |
| [in] | fmt | printf format string |
| [in] | ... | list of arguments |
Definition at line 830 of file web.c.
Referenced by html_head().
|
static |
Accept an incomming connection, setup connect_callback.
| [in] | *esp_config | ESP8266 network type an mode configuration structure |
| [in] | *esp_tcp_config | network protocol structure |
| [in] | port | network port to listen on |
| [in] | connect_callback | connection callback function pointer |
Print a decimal number into a string without an EOS.
| [in] | *ptr | buffer to write number to |
| [in] | num | number to convet |
Definition at line 1497 of file web.c.
Referenced by html_msg().
vsock_printf function
| [in] | p | socket buffer structure |
| [in] | fmt | printf format string |
| [in] | va | va_list of arguments |
Definition at line 808 of file web.c.
Referenced by sock_printf().
Wait for buffer to send for this connection If write_buffer sending flag is set then wait for it to clear.
| [in] | *p | rwbuf_t pointer for this socket buffer |
Definition at line 195 of file web.c.
Referenced by write_buffer(), and write_flush().
|
static |
Network disconnect callback function.
| [in] | *arg | connection pointer |
Definition at line 1854 of file web.c.
Referenced by web_data_connect_callback().
Network Error callback function.
| [in] | *arg | connection pointer FIXME TODO - we just disconnect on error |
Definition at line 1895 of file web.c.
Referenced by web_data_connect_callback().
|
static |
Network receive callback function.
| [in] | *arg | connection pointer |
| [in] | *data | Data received |
| [in] | length | Length of data received |
Definition at line 1735 of file web.c.
Referenced by web_data_connect_callback().
|
static |
Network sent callback function.
| [in] | *arg | connection pointer |
Definition at line 1810 of file web.c.
Referenced by web_data_connect_callback().
| MEMSPACE void web_init | ( | int | port | ) |
| MEMSPACE void web_sep | ( | void | ) |
| MEMSPACE void web_task | ( | void | ) |
Process ALL incoming HTTP requests.
Definition at line 2441 of file web.c.
Referenced by loop_wrapper().
Socket write buffer for this connection We wait for previous send to complete - then send any new data We do not wait for new data to finish sending - you use flush for that.
| [in] | *p | rwbuf_t pointer for this socket buffer |
Definition at line 266 of file web.c.
Referenced by write_flush().
Write a byte (buffered) using the rwbuf_t socket buffers for this connection If the buffers are full the socket is written using write_flush.
| [in] | *p | rwbuf_t pointer for this socket buffer |
| [in] | 1 | on success 0 on fail |
Definition at line 339 of file web.c.
Referenced by _write_byte_fn(), write_len(), and write_str().
Write all outstanding data and wait for it to send.
| [in] | *p | rwbuf_t pointer for this socket buffer |
Definition at line 323 of file web.c.
Referenced by write_byte().
Write data using buffered write_byte function.
| [in] | *p | rwbuf_t pointer for this socket buffer |
| [in] | *str | data buffer to write |
| [in] | len | number of bytes to write |
Definition at line 758 of file web.c.
Referenced by html_msg().
|
static |
| int connections |
Definition at line 45 of file web.c.
Referenced by tcp_accept(), user_loop(), user_tests(), web_data_connect_callback(), web_data_disconnect_callback(), web_data_error_callback(), web_data_receive_callback(), and web_data_sent_callback().
| char* http_status[] |
| mime_t mimes[] |
| header_t msg_headers[] |
HTTP headers we understand.
| rwbuf_t* web_connections[MAX_CONNECTIONS] |
| espconn_t WebConn |
Master espconn structure of the web server.
Definition at line 53 of file web.c.
Referenced by find_connection(), and rwbuf_delete().
|
static |
| window* winmsg |
| window * wintop |
1.8.11