CGI request function handlers.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <string.h>
#include <FreeRTOS.h>
#include <task.h>
#include "lwip/debug.h"
#include "lwip/tcp.h"
#include "afec.h"
#include "httpd.h"
#include "cgi.h"
#include "led.h"
#include "sysclk.h"
Data Structures | |
struct | archnames |
Macros | |
#define | CGI_LED_CMD_KEY "set" |
#define | CGI_LED_ID_KEY "n" |
#define | CGI_MATCH_EXT 2 |
Select item in table if the extention match. More... | |
#define | CGI_MATCH_NAME 3 |
Select item in table if the string is content. More... | |
#define | CGI_MATCH_NONE 0 |
#define | CGI_MATCH_WORD 1 |
Select item in table only if string match. More... | |
#define | CGI_MSG_CMD_KEY "msg" |
#define | CHIPID_ARCH |
#define | CHIPID_EPRCOC |
#define | CHIPID_NVPSIZ |
#define | CHIPID_NVTYP |
#define | CHIPID_SRAMSIZ |
#define | CLEAR_LED_STATUS(status, led_id) ((status) &= ~(1 << (led_id))) |
#define | CONFIG_AFSK_TX_BUFLEN 1024 |
FIFO tx buffer. More... | |
#define | GET_LED_STATUS(status, led_id) (((status) & (1 << (led_id))) >> (led_id)) |
#define | IP_ADDR_TO_INT_TUPLE(addr) |
Macro to unpack the ip address from LwIP format into 4 integers. More... | |
#define | SET_LED_STATUS(status, led_id) ((status) |= (1 << (led_id))) |
Functions | |
static int | cgi_chipInfo (const char *name, char *recv_buf, size_t recv_len) |
Send the chip ID information. More... | |
static int | cgi_displayMsg (const char *name, char *recv_buf, size_t recv_len) |
Read a message. More... | |
static int | cgi_echo (const char *name, char *recv_buf, size_t recv_len) |
Function declarations. More... | |
static int | cgi_error (const char *name, char *recv_buf, size_t recv_len) |
Used to handle unsupported CGI requests. More... | |
static int | cgi_led (const char *name, char *recv_buf, size_t recv_len) |
Set the led status and send back the new status. More... | |
static int | cgi_ledStatus (const char *name, char *recv_buf, size_t recv_len) |
Send the led status. More... | |
static int | cgi_resistor (const char *name, char *recv_buf, size_t recv_len) |
Send the potentiometer voltage. More... | |
http_handler_t | cgi_search (const char *name, HttpCGI *table) |
CGI request search engine. More... | |
static int | cgi_status (const char *name, char *recv_buf, size_t recv_len) |
Send a JSON string representing the board status. More... | |
static int | cgi_temp (const char *name, char *recv_buf, size_t recv_len) |
Send the internal core temperature in string format. More... | |
static int | cgi_uptime (const char *name, char *recv_buf, size_t recv_len) |
Send system uptime. More... | |
static const char * | chipid_archnames (unsigned value) |
Return the chip architecture name. More... | |
static const char * | chipid_eproc_name (int idx) |
Return the chip ID name. More... | |
static const char * | chipid_nvpsize (int idx) |
Return the non volatile programmable memory size. More... | |
static const char * | chipid_nvptype (int idx) |
Return the chip volatile programmable memory type. More... | |
static const char * | chipid_sramsize (int idx) |
Return the chip SRAM size. More... | |
static int | sec_to_strDhms (u32_t sec_time, char *str, size_t len) |
convert seconds to day/hour/minute/sec. More... | |
Variables | |
static const char | _unknown [] = "unknown" |
HttpCGI | cgi_table [] |
CGI table where we associate one callback to one page. More... | |
static struct archnames | chip_id_archnames [] |
static const char *const | chip_id_eproc_names [] |
static const char *const | chip_id_nvpsize [] |
static const char *const | chip_id_nvptype [] |
static const char *const | chip_id_sramsize [] |
static char | key_value [80] |
HTTP buffer to store key value. More... | |
uint32_t | mag_in_buffer_int [] |
Magnitude buffer converted in float. More... | |
u8_t | tx_buf [CONFIG_AFSK_TX_BUFLEN] |
#define CGI_LED_CMD_KEY "set" |
Referenced by cgi_led().
#define CGI_LED_ID_KEY "n" |
Referenced by cgi_led().
#define CGI_MATCH_EXT 2 |
Select item in table if the extention match.
Referenced by cgi_search().
#define CGI_MATCH_NAME 3 |
Select item in table if the string is content.
Referenced by cgi_search().
#define CGI_MATCH_NONE 0 |
#define CGI_MATCH_WORD 1 |
Select item in table only if string match.
#define CGI_MSG_CMD_KEY "msg" |
Referenced by cgi_displayMsg().
#define CHIPID_ARCH |
Referenced by cgi_chipInfo().
#define CHIPID_EPRCOC |
Referenced by cgi_chipInfo().
#define CHIPID_NVPSIZ |
Referenced by cgi_chipInfo().
#define CHIPID_NVTYP |
Referenced by cgi_chipInfo().
#define CHIPID_SRAMSIZ |
Referenced by cgi_chipInfo().
#define CONFIG_AFSK_TX_BUFLEN 1024 |
FIFO tx buffer.
Referenced by cgi_ledStatus(), and cgi_status().
#define IP_ADDR_TO_INT_TUPLE | ( | addr | ) |
Macro to unpack the ip address from LwIP format into 4 integers.
Referenced by cgi_status().
|
static |
Send the chip ID information.
name | Not used. |
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
References CHIPID_ARCH, chipid_archnames(), CHIPID_EPRCOC, chipid_eproc_name(), CHIPID_NVPSIZ, chipid_nvpsize(), chipid_nvptype(), CHIPID_NVTYP, CHIPID_SRAMSIZ, chipid_sramsize(), HTTP_CONTENT_JSON, http_sendOk(), http_write(), and UNUSED.
|
static |
Read a message.
name | Request containing the message. |
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
References CGI_MSG_CMD_KEY, HTTP_CONTENT_JSON, http_getValue(), http_sendInternalErr(), http_sendOk(), http_tokenizeGetRequest(), and UNUSED.
|
static |
Function declarations.
Send back the input string.
name | Not used. |
recv_buf | Receive buffer to send back. |
recv_len | Receive buffer length. |
References HTTP_CONTENT_PLAIN, http_sendOk(), http_write(), and UNUSED.
|
static |
Used to handle unsupported CGI requests.
name | Not used. |
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
References UNUSED.
|
static |
Set the led status and send back the new status.
name | String containing the led status request. |
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
References CGI_LED_CMD_KEY, CGI_LED_ID_KEY, CLEAR_LED_STATUS, HTTP_CONTENT_JSON, http_getValue(), http_sendInternalErr(), http_sendOk(), http_tokenizeGetRequest(), http_write(), ioport_set_pin_level(), LED0_GPIO, LED1_GPIO, LED2_ACTIVE_LEVEL, LED2_GPIO, LED2_INACTIVE_LEVEL, LED3_GPIO, BoardStatus::led_status, SET_LED_STATUS, status, and UNUSED.
|
static |
Send the led status.
name | Not used. |
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
References GET_LED_STATUS, HTTP_CONTENT_JSON, http_sendOk(), http_write(), BoardStatus::led_status, status, and UNUSED.
|
static |
Send the potentiometer voltage.
name | Not used. |
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
References AFEC_CHANNEL_5, afec_channel_get_value(), HTTP_CONTENT_JSON, http_sendOk(), http_write(), and UNUSED.
http_handler_t cgi_search | ( | const char * | name, |
HttpCGI * | table | ||
) |
CGI request search engine.
name | CGI request name. |
table | CGI handler table. |
References CGI_MATCH_EXT, CGI_MATCH_NAME, get_ext(), HttpCGI::handler, and NULL.
Referenced by http_recv().
|
static |
Send a JSON string representing the board status.
name | Not used. |
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
References AFEC_CHANNEL_5, afec_channel_get_value(), g_pcb, GET_LED_STATUS, HTTP_CONTENT_JSON, http_sendOk(), http_write(), BoardStatus::internal_temp, IP_ADDR_TO_INT_TUPLE, BoardStatus::last_connected_ip, BoardStatus::led_status, BoardStatus::local_ip, mag_in_buffer_int, status, BoardStatus::tot_req, UNUSED, BoardStatus::up_time, and xTaskGetTickCount().
|
static |
Send the internal core temperature in string format.
name | Not used. |
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
References HTTP_CONTENT_JSON, http_sendOk(), http_write(), BoardStatus::internal_temp, status, and UNUSED.
|
static |
Send system uptime.
name | Not used. |
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
References HTTP_CONTENT_JSON, http_sendOk(), http_write(), sec_to_strDhms(), status, UNUSED, and BoardStatus::up_time.
|
static |
Return the chip architecture name.
idx | Index in the chip_id_archnames table. |
References _unknown, chip_id_archnames, and archnames::name.
Referenced by cgi_chipInfo().
|
static |
Return the chip ID name.
idx | Index in the chip_id_eproc_names table. |
References _unknown, and chip_id_eproc_names.
Referenced by cgi_chipInfo().
|
static |
Return the non volatile programmable memory size.
idx | Index in the chip_id_nvpsize table. |
References _unknown, and chip_id_nvpsize.
Referenced by cgi_chipInfo().
|
static |
Return the chip volatile programmable memory type.
idx | Index in the chip_id_nvptype table. |
References _unknown.
Referenced by cgi_chipInfo().
|
static |
Return the chip SRAM size.
idx | Index in the chip_id_sramsize table. |
References _unknown, and chip_id_sramsize.
Referenced by cgi_chipInfo().
|
static |
convert seconds to day/hour/minute/sec.
sec_time | Time value. |
str | Buffer to store date. |
len | Buffer length. |
References h.
Referenced by cgi_uptime().
|
static |
Referenced by chipid_archnames(), chipid_eproc_name(), chipid_nvpsize(), chipid_nvptype(), and chipid_sramsize().
HttpCGI cgi_table[] |
CGI table where we associate one callback to one page.
Referenced by http_recv().
|
static |
Referenced by chipid_archnames().
|
static |
Referenced by chipid_eproc_name().
|
static |
|
static |
|
static |
Referenced by chipid_sramsize().
|
static |
HTTP buffer to store key value.
uint32_t mag_in_buffer_int[] |
Magnitude buffer converted in float.
Referenced by cgi_status(), dsp_task(), and gfx_refresh_mag().
u8_t tx_buf[CONFIG_AFSK_TX_BUFLEN] |