Add codename

http-comm
Ondřej Hruška 7 years ago
parent dca02976a7
commit 9a5bc0a274
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      Makefile
  2. 1
      esphttpdconfig.mk.example
  3. 2
      libesphttpd
  4. 35
      user/cgi_d2d.c
  5. 10
      user/cgi_d2d.h
  6. 10
      user/cgi_sockets.c
  7. 1
      user/serial.c
  8. 25
      user/uart_buffer.c
  9. 4
      user/uart_buffer.h
  10. 4
      user/uart_handler.c
  11. 18
      user/user_main.c
  12. 3
      user/version.h

@ -216,7 +216,7 @@ libesphttpd/Makefile:
$(Q) [[ -e "libesphttpd/Makefile" ]] || echo -e "\e[31mlibesphttpd submodule missing.\nIf build fails, run \"git submodule init\" and \"git submodule update\".\e[0m"
libesphttpd: libesphttpd/Makefile
$(Q) make -C libesphttpd USE_OPENSDK=$(USE_OPENSDK) SERVERNAME_PREFIX="ESPTerm " -j4
$(Q) make -C libesphttpd USE_OPENSDK=$(USE_OPENSDK) -j4
$(APP_AR): libesphttpd $(OBJ)
$(vecho) "AR $@"

@ -39,6 +39,7 @@ OUTPUT_TYPE = combined
ESP_SPI_FLASH_SIZE_K = 1024
GLOBAL_CFLAGS = \
-DDEBUG_D2D=0 \
-DDEBUG_ROUTER=0 \
-DDEBUG_CAPTDNS=0 \
-DDEBUG_HTTP=0 \

@ -1 +1 @@
Subproject commit a2fe09bb4d610d08806afcc4cc008fc01c0dcee0
Subproject commit 8f4db520bce2ecdc147dd6625e05d8dda45c813a

@ -13,7 +13,7 @@
#define D2D_TIMEOUT_MS 2000
#define D2D_HEADERS \
"User-Agent: ESPTerm/"FIRMWARE_VERSION"\r\n" \
"User-Agent: ESPTerm "FIRMWARE_VERSION"\r\n" \
"Content-Type: text/plain; charset=utf-8\r\n" \
"Cache-Control: max-age=0\r\n"
@ -62,14 +62,13 @@ requestCb(int http_status,
}
// semicolon only if more data is to be sent
if (opts->want_head || opts->want_body)
sprintf(bb, ";");
if (opts->want_head || opts->want_body) sprintf(bb, ";");
apars_respond(buff100);
dbg("Response %d, nonce %s", http_status, opts->nonce);
dbg("Headers %s", response_headers);
dbg("Body %s", response_body);
d2d_dbg("Response %d, nonce \"%s\"", http_status, opts->nonce?opts->nonce:"");
d2d_dbg("Headers %s", response_headers);
d2d_dbg("Body %s", response_body);
// head and payload separated by \r\n\r\n (one \r\n is at the end of head - maybe)
if (opts->want_head) {
@ -108,7 +107,7 @@ d2d_parse_command(char *msg)
FIND_NEXT(ip, ';');
const char *payload = msg;
ansi_dbg("D2D Tx,dest=%s,msg=%s", ip, payload);
d2d_dbg("D2D Tx,dest=%s,msg=%s", ip, payload);
sprintf(buff40, "http://%s" D2D_MSG_ENDPOINT, ip);
httpclient_args args;
@ -141,16 +140,16 @@ d2d_parse_command(char *msg)
else if (streq(method, "PATCH")) methodNum = HTTPD_METHOD_PATCH;
else if (streq(method, "HEAD")) methodNum = HTTPD_METHOD_HEAD;
else {
warn("BAD METHOD: %s, using GET", method);
d2d_warn("BAD METHOD: %s, using GET", method);
}
FIND_NEXT(params, ';');
dbg("Method %s", method);
dbg("Params %s", params);
d2d_dbg("Method %s", method);
d2d_dbg("Params %s", params);
size_t max_len = HTTPCLIENT_DEF_MAX_LEN;
int timeout = HTTPCLIENT_DEF_TIMEOUT_MS;
uint timeout = HTTPCLIENT_DEF_TIMEOUT_MS;
bool want_body = 0;
bool want_head = 0;
bool no_resp = 0;
@ -165,17 +164,17 @@ d2d_parse_command(char *msg)
else if(streq(param, "B")) want_body = 1; // Return body
else if(streq(param, "X")) no_resp = 1; // X - no response, no callback
else if(strstarts(param, "L=")) { // max length
max_len = atoi(param+2);
max_len = (size_t) atoi(param + 2);
} else if(strstarts(param, "T=")) { // timeout
timeout = atoi(param+2);
timeout = (uint) atoi(param + 2);
} else if(strstarts(param, "N=")) { // Nonce
nonce = param+2;
} else {
warn("BAD PARAM: %s", param);
d2d_warn("BAD PARAM: %s", param);
return false;
}
dbg("- param %s", params);
d2d_dbg("- param %s", params);
if (p == NULL) break;
params = p + 1;
@ -184,11 +183,11 @@ d2d_parse_command(char *msg)
p = strchr(msg, '\n');
if (p != NULL) *p = '\0';
url = msg;
dbg("URL: %s", url);
d2d_dbg("URL: %s", url);
if (p != NULL) {
payload = p + 1;
dbg("Payload: %s", payload);
d2d_dbg("Payload: %s", payload);
} else {
payload = NULL;
}
@ -212,7 +211,7 @@ d2d_parse_command(char *msg)
http_request(&args, no_resp ? NULL : requestCb);
dbg("Done");
d2d_dbg("Done");
return true;
}

@ -7,6 +7,16 @@
#include <esp8266.h>
#if DEBUG_D2D
#define d2d_warn warn
#define d2d_dbg dbg
#define d2d_info info
#else
#define d2d_warn(fmt, ...)
#define d2d_dbg(fmt, ...)
#define d2d_info(fmt, ...)
#endif
#define D2D_MSG_ENDPOINT "/api/v1/msg"
bool d2d_parse_command(char *msg);

@ -69,7 +69,7 @@ updateNotify_do(Websock *ws, ScreenNotifyTopics topics)
}
httpd_cgi_state cont = screenSerializeToBuffer(sock_buff, SOCK_BUF_LEN, topics, &data);
int flg = WEBSOCK_FLAG_BIN;
int flg = 0; //WEBSOCK_FLAG_BIN
if (cont == HTTPD_CGI_MORE) flg |= WEBSOCK_FLAG_MORE;
if (i > 0) flg |= WEBSOCK_FLAG_CONT;
if (ws) {
@ -304,13 +304,17 @@ static void ICACHE_FLASH_ATTR updateSockRx(Websock *ws, char *data, int len, int
/** Send a heartbeat msg */
static void ICACHE_FLASH_ATTR heartbeatTimCb(void *unused)
{
static u32 hbcnt=0;
if (term_active_clients > 0) {
if (notify_available) {
inp_dbg(".");
// Heartbeat packet - indicate we're still connected
// JS reloads the page if heartbeat is lost for a couple seconds
cgiWebsockBroadcast(URL_WS_UPDATE, ".", 1, 0);
char buf[10];
sprintf(buf, ".%d", hbcnt++);
cgiWebsockBroadcast(URL_WS_UPDATE, buf, (int) strlen(buf), 0);
// schedule next tick
TIMER_START(&heartbeatTim, heartbeatTimCb, HB_TIME, 0);
@ -331,6 +335,7 @@ static void ICACHE_FLASH_ATTR resetHeartbeatTimer(void)
static void ICACHE_FLASH_ATTR closeSockCb(Websock *ws)
{
term_active_clients--;
inp_dbg("Close socket CB, remain %d clients", term_active_clients);
if (term_active_clients <= 0) {
term_active_clients = 0;
@ -340,6 +345,7 @@ static void ICACHE_FLASH_ATTR closeSockCb(Websock *ws)
// stop the timer
os_timer_disarm(&heartbeatTim);
inp_dbg("Stop HB timer");
}
}

@ -92,4 +92,5 @@ void ICACHE_FLASH_ATTR serialInit(void)
void ICACHE_FLASH_ATTR UART_HandleRxByte(char c)
{
ansi_parser(c);
system_soft_wdt_feed(); // so we survive long torrents
}

@ -11,9 +11,6 @@
//#define buf_dbg(format, ...) printf(format "\r\n", ##__VA_ARGS__)
#define buf_dbg(format, ...) (void)format
#define UART_TX_BUFFER_SIZE 1024 //Ring buffer length of tx buffer
#define UART_RX_BUFFER_SIZE 1024 //Ring buffer length of rx buffer
struct UartBuffer {
uint32 UartBuffSize;
uint8 *pUartBuff;
@ -25,12 +22,15 @@ struct UartBuffer {
static struct UartBuffer *pTxBuffer = NULL;
static struct UartBuffer *pRxBuffer = NULL;
static struct UartBuffer *UART_AsyncBufferInit(uint32 buf_size);
static u8 rxArray[UART_RX_BUFFER_SIZE];
static u8 txArray[UART_TX_BUFFER_SIZE];
static struct UartBuffer *UART_AsyncBufferInit(uint32 buf_size, u8 *buffer);
void ICACHE_FLASH_ATTR UART_AllocBuffers(void)
{
pTxBuffer = UART_AsyncBufferInit(UART_TX_BUFFER_SIZE);
pRxBuffer = UART_AsyncBufferInit(UART_RX_BUFFER_SIZE);
pTxBuffer = UART_AsyncBufferInit(UART_TX_BUFFER_SIZE, txArray);
pRxBuffer = UART_AsyncBufferInit(UART_RX_BUFFER_SIZE, rxArray);
}
/******************************************************************************
@ -40,7 +40,7 @@ void ICACHE_FLASH_ATTR UART_AllocBuffers(void)
* Returns : NONE
*******************************************************************************/
static struct UartBuffer *ICACHE_FLASH_ATTR
UART_AsyncBufferInit(uint32 buf_size)
UART_AsyncBufferInit(uint32 buf_size, u8 *buffer)
{
uint32 heap_size = system_get_free_heap_size();
if (heap_size <= buf_size) {
@ -50,7 +50,7 @@ UART_AsyncBufferInit(uint32 buf_size)
else {
struct UartBuffer *pBuff = (struct UartBuffer *) malloc(sizeof(struct UartBuffer));
pBuff->UartBuffSize = buf_size;
pBuff->pUartBuff = (uint8 *) malloc(pBuff->UartBuffSize);
pBuff->pUartBuff = buffer != NULL ? buffer : (uint8 *) malloc(pBuff->UartBuffSize);
pBuff->pInPos = pBuff->pUartBuff;
pBuff->pOutPos = pBuff->pUartBuff;
pBuff->Space = (uint16) pBuff->UartBuffSize;
@ -176,7 +176,7 @@ void UART_RxFifoCollect(void)
fifo_len = (uint8) ((READ_PERI_REG(UART_STATUS(UART0)) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT);
if (fifo_len >= pRxBuffer->Space) {
fifo_len = (uint8) (pRxBuffer->Space - 1);
UART_WriteString(UART1, "\r\nRX BUF OVERRUN!!\r\n", 100);
UART_WriteChar(UART1, '#', 10);
// discard contents of the FIFO - would loop forever
buf_idx = 0;
while (buf_idx < fifo_len) {
@ -209,6 +209,11 @@ u16 ICACHE_FLASH_ATTR UART_AsyncTxGetEmptySpace(void)
return pTxBuffer->Space;
}
u16 ICACHE_FLASH_ATTR UART_AsyncTxCount(void)
{
return (u16) (pTxBuffer->UartBuffSize - pTxBuffer->Space);
}
/**
* Schedule data to be sent
* @param pdata
@ -226,7 +231,7 @@ UART_SendAsync(const char *pdata, int data_len)
}
else {
buf_dbg("FULL!");
UART_WriteString(UART1, "\r\nTX BUF OVERRUN!!\r\n", 100);
UART_WriteChar(UART1, '=', 10);
}
// Here we enable TX empty interrupt that will take care of sending the content

@ -7,6 +7,9 @@
#include <esp8266.h>
#define UART_TX_BUFFER_SIZE 1000 //Ring buffer length of tx buffer
#define UART_RX_BUFFER_SIZE 600 //Ring buffer length of rx buffer
// the init func
void UART_AllocBuffers(void);
@ -22,6 +25,7 @@ void UART_RxFifoCollect(void);
void UART_DispatchFromTxBuffer(uint8 uart_no);
u16 UART_AsyncRxCount(void);
u16 UART_AsyncTxCount(void);
u16 UART_AsyncTxGetEmptySpace(void);

@ -24,8 +24,8 @@ static void uart_recvTask(os_event_t *events);
static void uart_processTask(os_event_t *events);
// Those heavily affect the byte loss ratio
#define PROCESS_CHUNK_LEN 1
#define RX_FIFO_FULL_THRES 16
#define PROCESS_CHUNK_LEN 10
#define RX_FIFO_FULL_THRES 40
#define uart_recvTaskPrio 1
#define uart_recvTaskQueueLen 25

@ -30,6 +30,7 @@
#include "persist.h"
#include "ansi_parser.h"
#include "ascii.h"
#include "uart_buffer.h"
#ifdef ESPFS_POS
CgiUploadFlashDef uploadParams={
@ -51,6 +52,7 @@ CgiUploadFlashDef uploadParams={
#define INCLUDE_FLASH_FNS
#endif
#define HEAP_TIMER_MS 1000
/** Periodically show heap usage */
static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg)
{
@ -60,18 +62,24 @@ static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg)
int heap = system_get_free_heap_size();
int diff = (heap-last);
int rxc = UART_AsyncRxCount();
int txc = UART_AsyncTxCount();
int rxp = ((rxc*10000) / UART_RX_BUFFER_SIZE)/100;
int txp = ((txc*10000) / UART_TX_BUFFER_SIZE)/100;
const char *cc = "+";
if (diff<0) cc = "";
if (diff == 0) {
if (cnt == 5) {
// only every 5 secs if no change
dbg("FH: %d", heap);
dbg("Rx: %2d%c, Tx: %2d%c, Hp: %d", rxp, '%', txp, '%', heap);
cnt = 0;
}
} else {
// report change
dbg("FH: %d (%s%d)", heap, cc, diff);
dbg("Rx: %2d%c, Tx: %2d%c, Hp: %d (%s%d)", rxp, '%', txp, '%', heap, cc, diff);
cnt = 0;
}
@ -101,7 +109,8 @@ void ICACHE_FLASH_ATTR user_init(void)
banner_info("Firmware (c) Ondrej Hruska, 2017");
banner_info(TERMINAL_GITHUB_REPO);
banner_info("");
banner_info("Version "FIRMWARE_VERSION", built " __DATE__ " at " __TIME__ " " __TIMEZONE__);
banner_info("Version "FIRMWARE_VERSION",");
banner_info("built " __DATE__ " at " __TIME__ " " __TIMEZONE__);
printf("\r\n");
ioInit();
@ -116,7 +125,7 @@ void ICACHE_FLASH_ATTR user_init(void)
#if DEBUG_HEAP
// Heap use timer & blink
TIMER_START(&prHeapTimer, prHeapTimerCb, 1000, 1);
TIMER_START(&prHeapTimer, prHeapTimerCb, HEAP_TIMER_MS, 1);
#endif
// do later (some functions do not work if called from user_init)
@ -130,6 +139,7 @@ static void ICACHE_FLASH_ATTR user_start(void *unused)
captdnsInit();
httpdInit(routes, 80);
httpdSetName("ESPTerm " FIRMWARE_VERSION);
ansi_parser_inhibit = false;

@ -10,8 +10,9 @@
#define FW_V_MAJOR 2
#define FW_V_MINOR 1
#define FW_V_PATCH 0
#define FW_CODENAME "Anthill" // 2.1.0
#define FIRMWARE_VERSION STR(FW_V_MAJOR) "." STR(FW_V_MINOR) "." STR(FW_V_PATCH)
#define FIRMWARE_VERSION STR(FW_V_MAJOR) "." STR(FW_V_MINOR) "." STR(FW_V_PATCH) " \"" FW_CODENAME "\""
#define FIRMWARE_VERSION_NUM (FW_V_MAJOR*1000 + FW_V_MINOR*10 + FW_V_PATCH) // this is used in ID queries
#define TERMINAL_GITHUB_REPO "https://github.com/espterm/espterm-firmware"
#define TERMINAL_GITHUB_REPO_FRONT "https://github.com/espterm/espterm-front-end"

Loading…
Cancel
Save