This commit is contained in:
pvvx 2017-12-12 23:34:32 +03:00
parent b3dc0dda87
commit 0830a1244a
29 changed files with 240 additions and 152 deletions

View file

@ -12,11 +12,6 @@
#include "lwip/err.h"
#undef mMIN
#define mMIN(a, b) ((a < b)? a : b)
#define mMAX(a, b) ((a>b)?a:b)
enum srvconn_state {
SRVCONN_NONE =0,
SRVCONN_CLOSEWAIT, // ожидает закрытия
@ -35,9 +30,11 @@ enum srvconn_state {
#define MAX_TIME_WAIT_PCB 10
#endif
#define _mMIN(a, b) ((a < b)? a : b)
// кол-во одновременно открытых соединений по умолчанию
#ifndef TCP_SRV_MAX_CONNECTIONS
#define TCP_SRV_MAX_CONNECTIONS mMIN(MEMP_NUM_TCP_PCB, 10)
#define TCP_SRV_MAX_CONNECTIONS _mMIN(MEMP_NUM_TCP_PCB, 10)
#endif
// порт сервера по умолчанию

View file

@ -320,6 +320,9 @@ LOCAL void fATDS(int argc, char *argv[])
uint32 sleep_ms = 10000;
if(argc > 1) sleep_ms = atoi(argv[1]);
#if 0 // WakeUp PB_1
#include "gpio_api.h"
extern void HalInitLogUart(void);
extern void HalDeinitLogUart(void);
if(argc > 2) {
printf("%u ms waiting low level on PB_1 before launching Deep-Sleep...\n", sleep_ms);
// turn off log uart

View file

@ -26,6 +26,11 @@
#include "hal_com_reg.h"
#undef mMIN
#define mMIN(a, b) ((a < b)? a : b)
#undef mMAX
#define mMAX(a, b) ((a > b)? a : b)
//#define ReadTSF_Lo32() (*((volatile unsigned int *)(WIFI_REG_BASE + REG_TSFTR)))
//#define ReadTSF_Hi32() (*((volatile unsigned int *)(WIFI_REG_BASE + REG_TSFTR1)))
@ -44,7 +49,7 @@ INA219DRV ina219drv = {
.i2c.status = DRV_I2C_OFF,
.i2c.idx = 1, // I2C1
.i2c.io_sel = S0, // PC_4, PC_5
.i2c.mode = DRV_I2C_FS_MODE // DRV_I2C_HS_MODE
.i2c.mode = DRV_I2C_FS_MODE // DRV_I2C_FS_MODE
};
/*
void ina219_write(unsigned char reg, unsigned short data)
@ -186,9 +191,6 @@ size_t ina219_getdata(void *pd, uint16 cnt)
return cnt * sizeof(INA219DATA) + 4;
}
//#define mMIN(a, b) ((a<b)?a:b)
#define mMAX(a, b) ((a>b)?a:b)
#include "web_srv.h"
#include "websock.h"

View file

@ -62,6 +62,9 @@ extern void console_init(void);
void user_init_thrd(void) {
/* Read system config*/
if(syscfg.cfg.b.pin_clear_cfg_enable
&& 0) { // user_test_clear_pin()
wifi_cfg.load_flg = 0;

View file

@ -4,7 +4,9 @@
* Created on: 23/04/2017.
* Author: pvvx
*/
#ifndef COMPILE_SCI // Use Single Compilation Unit "web"
#include "autoconf.h"
#ifdef USE_WEB
#include "FreeRTOS.h"
#include "diag.h"
#include "web_utils.h"
@ -12,8 +14,10 @@
#include "web_srv.h"
#include "rtl8195a/rtl_libc.h"
#include "esp_comp.h"
#endif // USE_WEB
#endif // COMPILE_SCI
#ifdef USE_WEB
/* ----------------------------------------------------------------------------------
* pbuf[77] = Username and password are combined into a string "username:password"
* Return: Authorization Level
@ -46,3 +50,4 @@ uint8 UserAuthorization(uint8 *pbuf, size_t declen)
}
return 0;
}
#endif // USE_WEB

View file

@ -3,6 +3,7 @@
* Description: The web server inernal callbacks.
*******************************************************************************/
#ifndef COMPILE_SCI // Use Single Compilation Unit "web"
#include "user_config.h"
#ifdef USE_WEB
#include "autoconf.h"
@ -53,16 +54,22 @@
#undef atoi
#define atoi rom_atoi
//#define mMIN(a, b) ((a<b)?a:b)
#undef mMIN
#define mMIN(a, b) ((a < b)? a : b)
//#undef mMAX
//#define mMAX(a, b) ((a > b)? a : b)
#define ifcmp(a) if(rom_xstrcmp(cstr, a))
extern struct netif xnetif[NET_IF_NUM]; /* network interface structure */
#endif // USE_WEB
#endif // COMPILE_SCI
#ifdef USE_WEB
#define OpenFlash() { device_mutex_lock(RT_DEV_LOCK_FLASH); flash_turnon(); }
#define CloseFlash() { SpicDisableRtl8195A(); device_mutex_unlock(RT_DEV_LOCK_FLASH); }
extern struct netif xnetif[NET_IF_NUM]; /* network interface structure */
#if WEB_DEBUG_FUNCTIONS
//#define TEST_SEND_WAVE
#endif // #if WEB_DEBUG_FUNCTIONS

View file

@ -2,7 +2,7 @@
* FileName: webserver.c
* Description: The web server mode configuration.
*******************************************************************************/
#ifndef COMPILE_SCI // Use Single Compilation Unit "web"
#include "user_config.h"
#ifdef USE_WEB
#include "autoconf.h"
@ -23,6 +23,7 @@
#include "rtl8195a/rtl_libc.h"
#include "user/sys_cfg.h"
#include "wifi_api.h"
#include "sleep_ex_api.h"
#include "sys_api.h"
#include "esp_comp.h"
@ -67,6 +68,11 @@ extern int rom_atoi(const char *);
#undef atoi
#define atoi rom_atoi
#endif // USE_WEB
#endif // COMPILE_SCI
#ifdef USE_WEB
typedef uint32 (* call_func)(uint32 a, uint32 b, uint32 c);
extern QueueHandle_t xQueueWebSrv;

View file

@ -6,6 +6,7 @@
* ver1.1 02/04/2015 SDK 1.0.0
* ver2.0 14/14/2017 RTL871x
*******************************************************************************/
#ifndef COMPILE_SCI // Use Single Compilation Unit "web"
#include "user_config.h"
#ifdef USE_WEB
#include "autoconf.h"
@ -36,17 +37,23 @@
#include "overlay.h"
#endif
//#define mMIN(a, b) ((a<b)?a:b)
//#define mMAX(a, b) ((a>b)?a:b)
extern int rom_atoi(const char *);
#undef atoi
#define atoi(s) rom_atoi(s)
#endif // USE_WEB
#endif // COMPILE_SCI
#ifdef USE_WEB
#define USE_WEB_NAGLE // https://en.wikipedia.org/wiki/Nagle%27s_algorithm
#define MIN_REQ_LEN 7 // Minimum length for a valid HTTP/0.9 request: "GET /\r\n" -> 7 bytes
#define CRLF "\r\n"
#define max_len_buf_write_flash 2048 // размер буфера при записи flash. Увеличение/уменньшение размера (до сектора 4096) ускорения не дает (1..2%)
//#define mMIN(a, b) ((a<b)?a:b)
//#define mMAX(a, b) ((a>b)?a:b)
#undef atoi
#define atoi(s) rom_atoi(s)
LOCAL void web_print_headers(HTTP_CONN *CurHTTP, TCP_SERV_CONN *ts_conn) ICACHE_FLASH_ATTR ;
//LOCAL void webserver_discon(void *arg) ICACHE_FLASH_ATTR;

View file

@ -4,6 +4,7 @@
* Created on: 25 дек. 2014 г.
* Author: PV`
*/
#ifndef COMPILE_SCI // Use Single Compilation Unit "web"
#include "user_config.h"
#include "autoconf.h"
#include "FreeRTOS.h"
@ -18,7 +19,10 @@
#include "web_utils.h"
#include "esp_comp.h"
#define mMIN(a, b) ((a<b)?a:b)
//#define mMIN(a, b) ((a<b)?a:b)
//#define mMAX(a, b) ((a>b)?a:b)
#endif // COMPILE_SCI
/******************************************************************************
* xstrcpy() из сегментов flash и IRAM с возвратом размера строки:

View file

@ -4,6 +4,7 @@
* Author: pvvx
* 2016
*******************************************************************************/
#ifndef COMPILE_SCI // Use Single Compilation Unit "web"
#include "user_config.h"
#ifdef WEBSOCKET_ENA
#include "autoconf.h"
@ -21,6 +22,14 @@
#include "rtl8195a/rtl_libc.h"
#include "esp_comp.h"
//#define mMIN(a, b) ((a<b)?a:b)
#endif // WEBSOCKET_ENA
#endif // COMPILE_SCI
#ifdef WEBSOCKET_ENA
#if 0
#undef DEBUGSOO
#define DEBUGSOO 4
@ -28,8 +37,6 @@
#define copy_s4d1 rtl_memcpy
//#define mMIN(a, b) ((a<b)?a:b)
#define MAX_RX_BUF_SIZE 8192
const char txt_wsping[] ICACHE_RODATA_ATTR = "ws:ping";

View file

@ -4,6 +4,7 @@
* Author: PV`
* (c) PV` 2016
*******************************************************************************/
#ifndef COMPILE_SCI // Use Single Compilation Unit "web"
#include "user_config.h"
#ifdef WEBSOCKET_ENA
#include "autoconf.h"
@ -20,6 +21,10 @@
#include "rtl8195a/rtl_libc.h"
#include "esp_comp.h"
#include "hal_crypto.h"
#endif // WEBSOCKET_ENA
#endif // COMPILE_SCI
#ifdef WEBSOCKET_ENA
// HTTP/1.1 101 Web Socket Protocol Handshake\r\n
const uint8 WebSocketHTTPOkKey[] ICACHE_RODATA_ATTR = "HTTP/1.1 101 Switching Protocols\r\nAccess-Control-Allow-Origin: *\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: %s\r\n\r\n";