mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
Merge pull request #697 from dalathegreat/bugfix/assert-failed-tasksC
Crashfix: Restore Async lib, implement Mutex locking
This commit is contained in:
commit
57cba6f94b
24 changed files with 1726 additions and 2297 deletions
|
@ -85,7 +85,7 @@ This code uses the following excellent libraries:
|
||||||
- [eModbus/eModbus](https://github.com/eModbus/eModbus) MIT-License
|
- [eModbus/eModbus](https://github.com/eModbus/eModbus) MIT-License
|
||||||
- [knolleary/pubsubclient](https://github.com/knolleary/pubsubclient) MIT-License
|
- [knolleary/pubsubclient](https://github.com/knolleary/pubsubclient) MIT-License
|
||||||
- [mackelec/SerialDataLink](https://github.com/mackelec/SerialDataLink)
|
- [mackelec/SerialDataLink](https://github.com/mackelec/SerialDataLink)
|
||||||
- [mathieucarbou/AsyncTCP](https://github.com/mathieucarbou/AsyncTCP) LGPL-3.0 license
|
- [me-no-dev/AsyncTCP](https://github.com/me-no-dev/AsyncTCP) LGPL-3.0 license
|
||||||
- [me-no-dev/ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer)
|
- [me-no-dev/ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||||
- [miwagner/ESP32-Arduino-CAN](https://github.com/miwagner/ESP32-Arduino-CAN/) MIT-License
|
- [miwagner/ESP32-Arduino-CAN](https://github.com/miwagner/ESP32-Arduino-CAN/) MIT-License
|
||||||
- [pierremolinaro/acan2515](https://github.com/pierremolinaro/acan2515) MIT-License
|
- [pierremolinaro/acan2515](https://github.com/pierremolinaro/acan2515) MIT-License
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "../../include.h"
|
#include "../../include.h"
|
||||||
#include "../../lib/YiannisBourkelis-Uptime-Library/src/uptime_formatter.h"
|
#include "../../lib/YiannisBourkelis-Uptime-Library/src/uptime_formatter.h"
|
||||||
#include "../../lib/ayushsharma82-ElegantOTA/src/ElegantOTA.h"
|
#include "../../lib/ayushsharma82-ElegantOTA/src/ElegantOTA.h"
|
||||||
#include "../../lib/mathieucarbou-AsyncTCP/src/AsyncTCP.h"
|
#include "../../lib/me-no-dev-AsyncTCP/src/AsyncTCP.h"
|
||||||
#include "../../lib/me-no-dev-ESPAsyncWebServer/src/ESPAsyncWebServer.h"
|
#include "../../lib/me-no-dev-ESPAsyncWebServer/src/ESPAsyncWebServer.h"
|
||||||
#include "../../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
#include "../../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ _____ _ _ ___ _____ _
|
||||||
#include "Update.h"
|
#include "Update.h"
|
||||||
#include "StreamString.h"
|
#include "StreamString.h"
|
||||||
#if ELEGANTOTA_USE_ASYNC_WEBSERVER == 1
|
#if ELEGANTOTA_USE_ASYNC_WEBSERVER == 1
|
||||||
#include "../../mathieucarbou-AsyncTCP/src/AsyncTCP.h"
|
#include "../../me-no-dev-AsyncTCP/src/AsyncTCP.h"
|
||||||
#include "../../me-no-dev-ESPAsyncWebServer/src/ESPAsyncWebServer.h"
|
#include "../../me-no-dev-ESPAsyncWebServer/src/ESPAsyncWebServer.h"
|
||||||
#define ELEGANTOTA_WEBSERVER AsyncWebServer
|
#define ELEGANTOTA_WEBSERVER AsyncWebServer
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -1,129 +0,0 @@
|
||||||
|
|
||||||
# Contributor Covenant Code of Conduct
|
|
||||||
|
|
||||||
## Our Pledge
|
|
||||||
|
|
||||||
We as members, contributors, and leaders pledge to make participation in our
|
|
||||||
community a harassment-free experience for everyone, regardless of age, body
|
|
||||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
||||||
identity and expression, level of experience, education, socio-economic status,
|
|
||||||
nationality, personal appearance, race, religion, or sexual identity
|
|
||||||
and orientation.
|
|
||||||
|
|
||||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
||||||
diverse, inclusive, and healthy community.
|
|
||||||
|
|
||||||
## Our Standards
|
|
||||||
|
|
||||||
Examples of behavior that contributes to a positive environment for our
|
|
||||||
community include:
|
|
||||||
|
|
||||||
* Demonstrating empathy and kindness toward other people
|
|
||||||
* Being respectful of differing opinions, viewpoints, and experiences
|
|
||||||
* Giving and gracefully accepting constructive feedback
|
|
||||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
||||||
and learning from the experience
|
|
||||||
* Focusing on what is best not just for us as individuals, but for the
|
|
||||||
overall community
|
|
||||||
|
|
||||||
Examples of unacceptable behavior include:
|
|
||||||
|
|
||||||
* The use of sexualized language or imagery, and sexual attention or
|
|
||||||
advances of any kind
|
|
||||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
||||||
* Public or private harassment
|
|
||||||
* Publishing others' private information, such as a physical or email
|
|
||||||
address, without their explicit permission
|
|
||||||
* Other conduct which could reasonably be considered inappropriate in a
|
|
||||||
professional setting
|
|
||||||
|
|
||||||
## Enforcement Responsibilities
|
|
||||||
|
|
||||||
Community leaders are responsible for clarifying and enforcing our standards of
|
|
||||||
acceptable behavior and will take appropriate and fair corrective action in
|
|
||||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
||||||
or harmful.
|
|
||||||
|
|
||||||
Community leaders have the right and responsibility to remove, edit, or reject
|
|
||||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
||||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
||||||
decisions when appropriate.
|
|
||||||
|
|
||||||
## Scope
|
|
||||||
|
|
||||||
This Code of Conduct applies within all community spaces, and also applies when
|
|
||||||
an individual is officially representing the community in public spaces.
|
|
||||||
Examples of representing our community include using an official e-mail address,
|
|
||||||
posting via an official social media account, or acting as an appointed
|
|
||||||
representative at an online or offline event.
|
|
||||||
|
|
||||||
## Enforcement
|
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
||||||
reported to the community leaders responsible for enforcement at
|
|
||||||
https://sidweb.nl/cms3/en/contact.
|
|
||||||
All complaints will be reviewed and investigated promptly and fairly.
|
|
||||||
|
|
||||||
All community leaders are obligated to respect the privacy and security of the
|
|
||||||
reporter of any incident.
|
|
||||||
|
|
||||||
## Enforcement Guidelines
|
|
||||||
|
|
||||||
Community leaders will follow these Community Impact Guidelines in determining
|
|
||||||
the consequences for any action they deem in violation of this Code of Conduct:
|
|
||||||
|
|
||||||
### 1. Correction
|
|
||||||
|
|
||||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
||||||
unprofessional or unwelcome in the community.
|
|
||||||
|
|
||||||
**Consequence**: A private, written warning from community leaders, providing
|
|
||||||
clarity around the nature of the violation and an explanation of why the
|
|
||||||
behavior was inappropriate. A public apology may be requested.
|
|
||||||
|
|
||||||
### 2. Warning
|
|
||||||
|
|
||||||
**Community Impact**: A violation through a single incident or series
|
|
||||||
of actions.
|
|
||||||
|
|
||||||
**Consequence**: A warning with consequences for continued behavior. No
|
|
||||||
interaction with the people involved, including unsolicited interaction with
|
|
||||||
those enforcing the Code of Conduct, for a specified period of time. This
|
|
||||||
includes avoiding interactions in community spaces as well as external channels
|
|
||||||
like social media. Violating these terms may lead to a temporary or
|
|
||||||
permanent ban.
|
|
||||||
|
|
||||||
### 3. Temporary Ban
|
|
||||||
|
|
||||||
**Community Impact**: A serious violation of community standards, including
|
|
||||||
sustained inappropriate behavior.
|
|
||||||
|
|
||||||
**Consequence**: A temporary ban from any sort of interaction or public
|
|
||||||
communication with the community for a specified period of time. No public or
|
|
||||||
private interaction with the people involved, including unsolicited interaction
|
|
||||||
with those enforcing the Code of Conduct, is allowed during this period.
|
|
||||||
Violating these terms may lead to a permanent ban.
|
|
||||||
|
|
||||||
### 4. Permanent Ban
|
|
||||||
|
|
||||||
**Community Impact**: Demonstrating a pattern of violation of community
|
|
||||||
standards, including sustained inappropriate behavior, harassment of an
|
|
||||||
individual, or aggression toward or disparagement of classes of individuals.
|
|
||||||
|
|
||||||
**Consequence**: A permanent ban from any sort of public interaction within
|
|
||||||
the community.
|
|
||||||
|
|
||||||
## Attribution
|
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
||||||
version 2.0, available at
|
|
||||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
||||||
|
|
||||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
||||||
enforcement ladder](https://github.com/mozilla/diversity).
|
|
||||||
|
|
||||||
[homepage]: https://www.contributor-covenant.org
|
|
||||||
|
|
||||||
For answers to common questions about this code of conduct, see the FAQ at
|
|
||||||
https://www.contributor-covenant.org/faq. Translations are available at
|
|
||||||
https://www.contributor-covenant.org/translations.
|
|
|
@ -1,62 +0,0 @@
|
||||||
# AsyncTCP
|
|
||||||
|
|
||||||
[](https://opensource.org/license/lgpl-3-0/)
|
|
||||||
[](https://github.com/mathieucarbou/AsyncTCP/actions/workflows/ci.yml)
|
|
||||||
[](https://registry.platformio.org/libraries/mathieucarbou/AsyncTCP)
|
|
||||||
|
|
||||||
A fork of the [AsyncTCP](https://github.com/me-no-dev/AsyncTCP) library by [@me-no-dev](https://github.com/me-no-dev).
|
|
||||||
|
|
||||||
### Async TCP Library for ESP32 Arduino
|
|
||||||
|
|
||||||
This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for Espressif's ESP32 MCUs.
|
|
||||||
|
|
||||||
This library is the base for [ESPAsyncWebServer](https://github.com/mathieucarbou/ESPAsyncWebServer)
|
|
||||||
|
|
||||||
## AsyncClient and AsyncServer
|
|
||||||
|
|
||||||
The base classes on which everything else is built. They expose all possible scenarios, but are really raw and require more skills to use.
|
|
||||||
|
|
||||||
## Changes in this fork
|
|
||||||
|
|
||||||
- Based on [ESPHome fork](https://github.com/esphome/AsyncTCP)
|
|
||||||
|
|
||||||
- `library.properties` for Arduino IDE users
|
|
||||||
- Add `CONFIG_ASYNC_TCP_MAX_ACK_TIME`
|
|
||||||
- Add `CONFIG_ASYNC_TCP_PRIORITY`
|
|
||||||
- Add `CONFIG_ASYNC_TCP_QUEUE_SIZE`
|
|
||||||
- Add `setKeepAlive()`
|
|
||||||
- Arduino 3 / ESP-IDF 5 compatibility
|
|
||||||
- Better CI
|
|
||||||
- Better example
|
|
||||||
- Customizable macros
|
|
||||||
- Fix for "Required to lock TCPIP core functionality". Ref: https://github.com/mathieucarbou/AsyncTCP/issues/27 and https://github.com/espressif/arduino-esp32/issues/10526
|
|
||||||
- Fix for "ack timeout 4" client disconnects.
|
|
||||||
- Fix from https://github.com/me-no-dev/AsyncTCP/pull/173 (partially applied)
|
|
||||||
- Fix from https://github.com/me-no-dev/AsyncTCP/pull/184
|
|
||||||
- IPv6
|
|
||||||
- LIBRETINY support
|
|
||||||
- LibreTuya
|
|
||||||
- Reduce logging of non critical messages
|
|
||||||
- Use IPADDR6_INIT() macro to set connecting IPv6 address
|
|
||||||
- xTaskCreateUniversal function
|
|
||||||
|
|
||||||
## Coordinates
|
|
||||||
|
|
||||||
```
|
|
||||||
mathieucarbou/AsyncTCP @ ^3.3.1
|
|
||||||
```
|
|
||||||
|
|
||||||
## Important recommendations
|
|
||||||
|
|
||||||
Most of the crashes are caused by improper configuration of the library for the project.
|
|
||||||
Here are some recommendations to avoid them.
|
|
||||||
|
|
||||||
I personally use the following configuration in my projects:
|
|
||||||
|
|
||||||
```c++
|
|
||||||
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=5000 // (keep default)
|
|
||||||
-D CONFIG_ASYNC_TCP_PRIORITY=10 // (keep default)
|
|
||||||
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=64 // (keep default)
|
|
||||||
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1 // force async_tcp task to be on same core as the app (default is core 0)
|
|
||||||
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096 // reduce the stack size (default is 16K)
|
|
||||||
```
|
|
|
@ -1,38 +0,0 @@
|
||||||
{
|
|
||||||
"name": "AsyncTCP",
|
|
||||||
"version": "3.3.1",
|
|
||||||
"description": "Asynchronous TCP Library for ESP32",
|
|
||||||
"keywords": "async,tcp",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/mathieucarbou/AsyncTCP.git"
|
|
||||||
},
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Hristo Gochkov"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Mathieu Carbou",
|
|
||||||
"maintainer": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"license": "LGPL-3.0",
|
|
||||||
"frameworks": "arduino",
|
|
||||||
"platforms": [
|
|
||||||
"espressif32",
|
|
||||||
"libretiny"
|
|
||||||
],
|
|
||||||
"build": {
|
|
||||||
"libCompatMode": 2
|
|
||||||
},
|
|
||||||
"export": {
|
|
||||||
"include": [
|
|
||||||
"examples",
|
|
||||||
"src",
|
|
||||||
"library.json",
|
|
||||||
"library.properties",
|
|
||||||
"LICENSE",
|
|
||||||
"README.md"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
name=Async TCP
|
|
||||||
includes=AsyncTCP.h
|
|
||||||
version=3.3.1
|
|
||||||
author=Me-No-Dev
|
|
||||||
maintainer=Mathieu Carbou <mathieu.carbou@gmail.com>
|
|
||||||
sentence=Async TCP Library for ESP32
|
|
||||||
paragraph=Async TCP Library for ESP32
|
|
||||||
category=Other
|
|
||||||
url=https://github.com/mathieucarbou/AsyncTCP.git
|
|
||||||
architectures=*
|
|
|
@ -1,43 +0,0 @@
|
||||||
[platformio]
|
|
||||||
default_envs = arduino-2, arduino-3, arduino-310
|
|
||||||
lib_dir = .
|
|
||||||
src_dir = examples/Client
|
|
||||||
|
|
||||||
[env]
|
|
||||||
framework = arduino
|
|
||||||
build_flags =
|
|
||||||
-Wall -Wextra
|
|
||||||
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=5000
|
|
||||||
-D CONFIG_ASYNC_TCP_PRIORITY=10
|
|
||||||
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=64
|
|
||||||
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
|
|
||||||
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096
|
|
||||||
-D CONFIG_ARDUHAL_LOG_COLORS
|
|
||||||
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
|
||||||
upload_protocol = esptool
|
|
||||||
monitor_speed = 115200
|
|
||||||
monitor_filters = esp32_exception_decoder, log2file
|
|
||||||
board = esp32dev
|
|
||||||
|
|
||||||
[env:arduino-2]
|
|
||||||
platform = espressif32@6.9.0
|
|
||||||
|
|
||||||
[env:arduino-3]
|
|
||||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.05/platform-espressif32.zip
|
|
||||||
|
|
||||||
[env:arduino-310]
|
|
||||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc3/platform-espressif32.zip
|
|
||||||
|
|
||||||
; CI
|
|
||||||
|
|
||||||
[env:ci-arduino-2]
|
|
||||||
platform = espressif32@6.9.0
|
|
||||||
board = ${sysenv.PIO_BOARD}
|
|
||||||
|
|
||||||
[env:ci-arduino-3]
|
|
||||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.05/platform-espressif32.zip
|
|
||||||
board = ${sysenv.PIO_BOARD}
|
|
||||||
|
|
||||||
[env:ci-arduino-310]
|
|
||||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc3/platform-espressif32.zip
|
|
||||||
board = ${sysenv.PIO_BOARD}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,347 +0,0 @@
|
||||||
/*
|
|
||||||
Asynchronous TCP library for Espressif MCUs
|
|
||||||
|
|
||||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
|
||||||
This file is part of the esp8266 core for Arduino environment.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ASYNCTCP_H_
|
|
||||||
#define ASYNCTCP_H_
|
|
||||||
|
|
||||||
#define ASYNCTCP_VERSION "3.3.1"
|
|
||||||
#define ASYNCTCP_VERSION_MAJOR 3
|
|
||||||
#define ASYNCTCP_VERSION_MINOR 3
|
|
||||||
#define ASYNCTCP_VERSION_REVISION 1
|
|
||||||
#define ASYNCTCP_FORK_mathieucarbou
|
|
||||||
|
|
||||||
#include "../../../devboard/hal/hal.h"
|
|
||||||
#include "../../../system_settings.h"
|
|
||||||
|
|
||||||
#include "IPAddress.h"
|
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
#include "IPv6Address.h"
|
|
||||||
#endif
|
|
||||||
#include "lwip/ip6_addr.h"
|
|
||||||
#include "lwip/ip_addr.h"
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#ifndef LIBRETINY
|
|
||||||
#include "sdkconfig.h"
|
|
||||||
extern "C" {
|
|
||||||
#include "freertos/semphr.h"
|
|
||||||
#include "lwip/pbuf.h"
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
extern "C" {
|
|
||||||
#include <lwip/pbuf.h>
|
|
||||||
#include <semphr.h>
|
|
||||||
}
|
|
||||||
#define CONFIG_ASYNC_TCP_RUNNING_CORE WIFI_CORE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// If core is not defined, then we are running in Arduino or PIO
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_RUNNING_CORE
|
|
||||||
#define CONFIG_ASYNC_TCP_RUNNING_CORE WIFI_CORE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// guard AsyncTCP task with watchdog
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_USE_WDT
|
|
||||||
#define CONFIG_ASYNC_TCP_USE_WDT 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_STACK_SIZE
|
|
||||||
#define CONFIG_ASYNC_TCP_STACK_SIZE 8192 * 2
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_PRIORITY
|
|
||||||
#define CONFIG_ASYNC_TCP_PRIORITY 10
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_QUEUE_SIZE
|
|
||||||
#define CONFIG_ASYNC_TCP_QUEUE_SIZE 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_MAX_ACK_TIME
|
|
||||||
#define CONFIG_ASYNC_TCP_MAX_ACK_TIME 5000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class AsyncClient;
|
|
||||||
|
|
||||||
#define ASYNC_WRITE_FLAG_COPY 0x01 // will allocate new buffer to hold the data while sending (else will hold reference to the data given)
|
|
||||||
#define ASYNC_WRITE_FLAG_MORE 0x02 // will not send PSH flag, meaning that there should be more data to be sent before the application should react.
|
|
||||||
|
|
||||||
typedef std::function<void(void*, AsyncClient*)> AcConnectHandler;
|
|
||||||
typedef std::function<void(void*, AsyncClient*, size_t len, uint32_t time)> AcAckHandler;
|
|
||||||
typedef std::function<void(void*, AsyncClient*, int8_t error)> AcErrorHandler;
|
|
||||||
typedef std::function<void(void*, AsyncClient*, void* data, size_t len)> AcDataHandler;
|
|
||||||
typedef std::function<void(void*, AsyncClient*, struct pbuf* pb)> AcPacketHandler;
|
|
||||||
typedef std::function<void(void*, AsyncClient*, uint32_t time)> AcTimeoutHandler;
|
|
||||||
|
|
||||||
struct tcp_pcb;
|
|
||||||
struct ip_addr;
|
|
||||||
|
|
||||||
class AsyncClient {
|
|
||||||
public:
|
|
||||||
AsyncClient(tcp_pcb* pcb = 0);
|
|
||||||
~AsyncClient();
|
|
||||||
|
|
||||||
AsyncClient& operator=(const AsyncClient& other);
|
|
||||||
AsyncClient& operator+=(const AsyncClient& other);
|
|
||||||
|
|
||||||
bool operator==(const AsyncClient& other);
|
|
||||||
|
|
||||||
bool operator!=(const AsyncClient& other) {
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
bool connect(const IPAddress& ip, uint16_t port);
|
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
bool connect(const IPv6Address& ip, uint16_t port);
|
|
||||||
#endif
|
|
||||||
bool connect(const char* host, uint16_t port);
|
|
||||||
/**
|
|
||||||
* @brief close connection
|
|
||||||
*
|
|
||||||
* @param now - ignored
|
|
||||||
*/
|
|
||||||
void close(bool now = false);
|
|
||||||
// same as close()
|
|
||||||
void stop() { close(false); };
|
|
||||||
int8_t abort();
|
|
||||||
bool free();
|
|
||||||
|
|
||||||
// ack is not pending
|
|
||||||
bool canSend();
|
|
||||||
// TCP buffer space available
|
|
||||||
size_t space();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief add data to be send (but do not send yet)
|
|
||||||
* @note add() would call lwip's tcp_write()
|
|
||||||
By default apiflags=ASYNC_WRITE_FLAG_COPY
|
|
||||||
You could try to use apiflags with this flag unset to pass data by reference and avoid copy to socket buffer,
|
|
||||||
but looks like it does not work for Arduino's lwip in ESP32/IDF at least
|
|
||||||
it is enforced in https://github.com/espressif/esp-lwip/blob/0606eed9d8b98a797514fdf6eabb4daf1c8c8cd9/src/core/tcp_out.c#L422C5-L422C30
|
|
||||||
if LWIP_NETIF_TX_SINGLE_PBUF is set, and it is set indeed in IDF
|
|
||||||
https://github.com/espressif/esp-idf/blob/a0f798cfc4bbd624aab52b2c194d219e242d80c1/components/lwip/port/include/lwipopts.h#L744
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
* @param size
|
|
||||||
* @param apiflags
|
|
||||||
* @return size_t amount of data that has been copied
|
|
||||||
*/
|
|
||||||
size_t add(const char* data, size_t size, uint8_t apiflags = ASYNC_WRITE_FLAG_COPY);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief send data previously add()'ed
|
|
||||||
*
|
|
||||||
* @return true on success
|
|
||||||
* @return false on error
|
|
||||||
*/
|
|
||||||
bool send();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief add and enqueue data for sending
|
|
||||||
* @note it is same as add() + send()
|
|
||||||
* @note only make sense when canSend() == true
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
* @param size
|
|
||||||
* @param apiflags
|
|
||||||
* @return size_t
|
|
||||||
*/
|
|
||||||
size_t write(const char* data, size_t size, uint8_t apiflags = ASYNC_WRITE_FLAG_COPY);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief add and enque data for sending
|
|
||||||
* @note treats data as null-terminated string
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
* @return size_t
|
|
||||||
*/
|
|
||||||
size_t write(const char* data) { return data == NULL ? 0 : write(data, strlen(data)); };
|
|
||||||
|
|
||||||
uint8_t state();
|
|
||||||
bool connecting();
|
|
||||||
bool connected();
|
|
||||||
bool disconnecting();
|
|
||||||
bool disconnected();
|
|
||||||
|
|
||||||
// disconnected or disconnecting
|
|
||||||
bool freeable();
|
|
||||||
|
|
||||||
uint16_t getMss();
|
|
||||||
|
|
||||||
uint32_t getRxTimeout();
|
|
||||||
// no RX data timeout for the connection in seconds
|
|
||||||
void setRxTimeout(uint32_t timeout);
|
|
||||||
|
|
||||||
uint32_t getAckTimeout();
|
|
||||||
// no ACK timeout for the last sent packet in milliseconds
|
|
||||||
void setAckTimeout(uint32_t timeout);
|
|
||||||
|
|
||||||
void setNoDelay(bool nodelay);
|
|
||||||
bool getNoDelay();
|
|
||||||
|
|
||||||
void setKeepAlive(uint32_t ms, uint8_t cnt);
|
|
||||||
|
|
||||||
uint32_t getRemoteAddress();
|
|
||||||
uint16_t getRemotePort();
|
|
||||||
uint32_t getLocalAddress();
|
|
||||||
uint16_t getLocalPort();
|
|
||||||
#if LWIP_IPV6
|
|
||||||
ip6_addr_t getRemoteAddress6();
|
|
||||||
ip6_addr_t getLocalAddress6();
|
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
IPv6Address remoteIP6();
|
|
||||||
IPv6Address localIP6();
|
|
||||||
#else
|
|
||||||
IPAddress remoteIP6();
|
|
||||||
IPAddress localIP6();
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// compatibility
|
|
||||||
IPAddress remoteIP();
|
|
||||||
uint16_t remotePort();
|
|
||||||
IPAddress localIP();
|
|
||||||
uint16_t localPort();
|
|
||||||
|
|
||||||
// set callback - on successful connect
|
|
||||||
void onConnect(AcConnectHandler cb, void* arg = 0);
|
|
||||||
// set callback - disconnected
|
|
||||||
void onDisconnect(AcConnectHandler cb, void* arg = 0);
|
|
||||||
// set callback - ack received
|
|
||||||
void onAck(AcAckHandler cb, void* arg = 0);
|
|
||||||
// set callback - unsuccessful connect or error
|
|
||||||
void onError(AcErrorHandler cb, void* arg = 0);
|
|
||||||
// set callback - data received (called if onPacket is not used)
|
|
||||||
void onData(AcDataHandler cb, void* arg = 0);
|
|
||||||
// set callback - data received
|
|
||||||
void onPacket(AcPacketHandler cb, void* arg = 0);
|
|
||||||
// set callback - ack timeout
|
|
||||||
void onTimeout(AcTimeoutHandler cb, void* arg = 0);
|
|
||||||
// set callback - every 125ms when connected
|
|
||||||
void onPoll(AcConnectHandler cb, void* arg = 0);
|
|
||||||
|
|
||||||
// ack pbuf from onPacket
|
|
||||||
void ackPacket(struct pbuf* pb);
|
|
||||||
// ack data that you have not acked using the method below
|
|
||||||
size_t ack(size_t len);
|
|
||||||
// will not ack the current packet. Call from onData
|
|
||||||
void ackLater() { _ack_pcb = false; }
|
|
||||||
|
|
||||||
static const char* errorToString(int8_t error);
|
|
||||||
const char* stateToString();
|
|
||||||
|
|
||||||
// internal callbacks - Do NOT call any of the functions below in user code!
|
|
||||||
static int8_t _s_poll(void* arg, struct tcp_pcb* tpcb);
|
|
||||||
static int8_t _s_recv(void* arg, struct tcp_pcb* tpcb, struct pbuf* pb, int8_t err);
|
|
||||||
static int8_t _s_fin(void* arg, struct tcp_pcb* tpcb, int8_t err);
|
|
||||||
static int8_t _s_lwip_fin(void* arg, struct tcp_pcb* tpcb, int8_t err);
|
|
||||||
static void _s_error(void* arg, int8_t err);
|
|
||||||
static int8_t _s_sent(void* arg, struct tcp_pcb* tpcb, uint16_t len);
|
|
||||||
static int8_t _s_connected(void* arg, struct tcp_pcb* tpcb, int8_t err);
|
|
||||||
static void _s_dns_found(const char* name, struct ip_addr* ipaddr, void* arg);
|
|
||||||
|
|
||||||
int8_t _recv(tcp_pcb* pcb, pbuf* pb, int8_t err);
|
|
||||||
tcp_pcb* pcb() { return _pcb; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool _connect(ip_addr_t addr, uint16_t port);
|
|
||||||
|
|
||||||
tcp_pcb* _pcb;
|
|
||||||
int8_t _closed_slot;
|
|
||||||
|
|
||||||
AcConnectHandler _connect_cb;
|
|
||||||
void* _connect_cb_arg;
|
|
||||||
AcConnectHandler _discard_cb;
|
|
||||||
void* _discard_cb_arg;
|
|
||||||
AcAckHandler _sent_cb;
|
|
||||||
void* _sent_cb_arg;
|
|
||||||
AcErrorHandler _error_cb;
|
|
||||||
void* _error_cb_arg;
|
|
||||||
AcDataHandler _recv_cb;
|
|
||||||
void* _recv_cb_arg;
|
|
||||||
AcPacketHandler _pb_cb;
|
|
||||||
void* _pb_cb_arg;
|
|
||||||
AcTimeoutHandler _timeout_cb;
|
|
||||||
void* _timeout_cb_arg;
|
|
||||||
AcConnectHandler _poll_cb;
|
|
||||||
void* _poll_cb_arg;
|
|
||||||
|
|
||||||
bool _ack_pcb;
|
|
||||||
uint32_t _tx_last_packet;
|
|
||||||
uint32_t _rx_ack_len;
|
|
||||||
uint32_t _rx_last_packet;
|
|
||||||
uint32_t _rx_timeout;
|
|
||||||
uint32_t _rx_last_ack;
|
|
||||||
uint32_t _ack_timeout;
|
|
||||||
uint16_t _connect_port;
|
|
||||||
|
|
||||||
int8_t _close();
|
|
||||||
void _free_closed_slot();
|
|
||||||
bool _allocate_closed_slot();
|
|
||||||
int8_t _connected(tcp_pcb* pcb, int8_t err);
|
|
||||||
void _error(int8_t err);
|
|
||||||
int8_t _poll(tcp_pcb* pcb);
|
|
||||||
int8_t _sent(tcp_pcb* pcb, uint16_t len);
|
|
||||||
int8_t _fin(tcp_pcb* pcb, int8_t err);
|
|
||||||
int8_t _lwip_fin(tcp_pcb* pcb, int8_t err);
|
|
||||||
void _dns_found(struct ip_addr* ipaddr);
|
|
||||||
|
|
||||||
public:
|
|
||||||
AsyncClient* prev;
|
|
||||||
AsyncClient* next;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AsyncServer {
|
|
||||||
public:
|
|
||||||
AsyncServer(IPAddress addr, uint16_t port);
|
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
AsyncServer(IPv6Address addr, uint16_t port);
|
|
||||||
#endif
|
|
||||||
AsyncServer(uint16_t port);
|
|
||||||
~AsyncServer();
|
|
||||||
void onClient(AcConnectHandler cb, void* arg);
|
|
||||||
void begin();
|
|
||||||
void end();
|
|
||||||
void setNoDelay(bool nodelay);
|
|
||||||
bool getNoDelay();
|
|
||||||
uint8_t status();
|
|
||||||
|
|
||||||
// Do not use any of the functions below!
|
|
||||||
static int8_t _s_accept(void* arg, tcp_pcb* newpcb, int8_t err);
|
|
||||||
static int8_t _s_accepted(void* arg, AsyncClient* client);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
uint16_t _port;
|
|
||||||
bool _bind4 = false;
|
|
||||||
bool _bind6 = false;
|
|
||||||
IPAddress _addr;
|
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
IPv6Address _addr6;
|
|
||||||
#endif
|
|
||||||
bool _noDelay;
|
|
||||||
tcp_pcb* _pcb;
|
|
||||||
AcConnectHandler _connect_cb;
|
|
||||||
void* _connect_cb_arg;
|
|
||||||
|
|
||||||
int8_t _accept(tcp_pcb* newpcb, int8_t err);
|
|
||||||
int8_t _accepted(AsyncClient* client);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* ASYNCTCP_H_ */
|
|
2
Software/src/lib/me-no-dev-AsyncTCP/.gitignore
vendored
Normal file
2
Software/src/lib/me-no-dev-AsyncTCP/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
.DS_Store
|
34
Software/src/lib/me-no-dev-AsyncTCP/.travis.yml
Normal file
34
Software/src/lib/me-no-dev-AsyncTCP/.travis.yml
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
sudo: false
|
||||||
|
language: python
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
|
||||||
|
git:
|
||||||
|
depth: false
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- build
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
include:
|
||||||
|
|
||||||
|
- name: "Arduino Build"
|
||||||
|
if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
|
||||||
|
stage: build
|
||||||
|
script: bash $TRAVIS_BUILD_DIR/.github/scripts/on-push.sh
|
||||||
|
|
||||||
|
- name: "PlatformIO Build"
|
||||||
|
if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
|
||||||
|
stage: build
|
||||||
|
script: bash $TRAVIS_BUILD_DIR/.github/scripts/on-push.sh 1 1
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email:
|
||||||
|
on_success: change
|
||||||
|
on_failure: change
|
||||||
|
webhooks:
|
||||||
|
urls:
|
||||||
|
- https://webhooks.gitter.im/e/60e65d0c78ea0a920347
|
||||||
|
on_success: change # options: [always|never|change] default: always
|
||||||
|
on_failure: always # options: [always|never|change] default: always
|
||||||
|
on_start: false # default: false
|
30
Software/src/lib/me-no-dev-AsyncTCP/Kconfig.projbuild
Normal file
30
Software/src/lib/me-no-dev-AsyncTCP/Kconfig.projbuild
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
menu "AsyncTCP Configuration"
|
||||||
|
|
||||||
|
choice ASYNC_TCP_RUNNING_CORE
|
||||||
|
bool "Core on which AsyncTCP's thread is running"
|
||||||
|
default ASYNC_TCP_RUN_CORE1
|
||||||
|
help
|
||||||
|
Select on which core AsyncTCP is running
|
||||||
|
|
||||||
|
config ASYNC_TCP_RUN_CORE0
|
||||||
|
bool "CORE 0"
|
||||||
|
config ASYNC_TCP_RUN_CORE1
|
||||||
|
bool "CORE 1"
|
||||||
|
config ASYNC_TCP_RUN_NO_AFFINITY
|
||||||
|
bool "BOTH"
|
||||||
|
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
config ASYNC_TCP_RUNNING_CORE
|
||||||
|
int
|
||||||
|
default 0 if ASYNC_TCP_RUN_CORE0
|
||||||
|
default 1 if ASYNC_TCP_RUN_CORE1
|
||||||
|
default -1 if ASYNC_TCP_RUN_NO_AFFINITY
|
||||||
|
|
||||||
|
config ASYNC_TCP_USE_WDT
|
||||||
|
bool "Enable WDT for the AsyncTCP task"
|
||||||
|
default "y"
|
||||||
|
help
|
||||||
|
Enable WDT for the AsyncTCP task, so it will trigger if a handler is locking the thread.
|
||||||
|
|
||||||
|
endmenu
|
15
Software/src/lib/me-no-dev-AsyncTCP/README.md
Normal file
15
Software/src/lib/me-no-dev-AsyncTCP/README.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
This is commit ca8ac5f from https://github.com/me-no-dev/AsyncTCP
|
||||||
|
|
||||||
|
# AsyncTCP
|
||||||
|
[](https://travis-ci.org/me-no-dev/AsyncTCP)  [](https://www.codacy.com/manual/me-no-dev/AsyncTCP?utm_source=github.com&utm_medium=referral&utm_content=me-no-dev/AsyncTCP&utm_campaign=Badge_Grade)
|
||||||
|
|
||||||
|
### Async TCP Library for ESP32 Arduino
|
||||||
|
|
||||||
|
[](https://gitter.im/me-no-dev/ESPAsyncWebServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
|
This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for Espressif's ESP32 MCUs.
|
||||||
|
|
||||||
|
This library is the base for [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||||
|
|
||||||
|
## AsyncClient and AsyncServer
|
||||||
|
The base classes on which everything else is built. They expose all possible scenarios, but are really raw and require more skills to use.
|
22
Software/src/lib/me-no-dev-AsyncTCP/library.json
Normal file
22
Software/src/lib/me-no-dev-AsyncTCP/library.json
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"name":"AsyncTCP",
|
||||||
|
"description":"Asynchronous TCP Library for ESP32",
|
||||||
|
"keywords":"async,tcp",
|
||||||
|
"authors":
|
||||||
|
{
|
||||||
|
"name": "Hristo Gochkov",
|
||||||
|
"maintainer": true
|
||||||
|
},
|
||||||
|
"repository":
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/me-no-dev/AsyncTCP.git"
|
||||||
|
},
|
||||||
|
"version": "1.1.1",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"frameworks": "arduino",
|
||||||
|
"platforms": "espressif32",
|
||||||
|
"build": {
|
||||||
|
"libCompatMode": 2
|
||||||
|
}
|
||||||
|
}
|
9
Software/src/lib/me-no-dev-AsyncTCP/library.properties
Normal file
9
Software/src/lib/me-no-dev-AsyncTCP/library.properties
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
name=AsyncTCP
|
||||||
|
version=1.1.1
|
||||||
|
author=Me-No-Dev
|
||||||
|
maintainer=Me-No-Dev
|
||||||
|
sentence=Async TCP Library for ESP32
|
||||||
|
paragraph=Async TCP Library for ESP32
|
||||||
|
category=Other
|
||||||
|
url=https://github.com/me-no-dev/AsyncTCP
|
||||||
|
architectures=*
|
1387
Software/src/lib/me-no-dev-AsyncTCP/src/AsyncTCP.cpp
Normal file
1387
Software/src/lib/me-no-dev-AsyncTCP/src/AsyncTCP.cpp
Normal file
File diff suppressed because it is too large
Load diff
220
Software/src/lib/me-no-dev-AsyncTCP/src/AsyncTCP.h
Normal file
220
Software/src/lib/me-no-dev-AsyncTCP/src/AsyncTCP.h
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
/*
|
||||||
|
Asynchronous TCP library for Espressif MCUs
|
||||||
|
|
||||||
|
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||||
|
This file is part of the esp8266 core for Arduino environment.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ASYNCTCP_H_
|
||||||
|
#define ASYNCTCP_H_
|
||||||
|
|
||||||
|
#include "IPAddress.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#include <functional>
|
||||||
|
extern "C" {
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
#include "lwip/pbuf.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "../../../system_settings.h"
|
||||||
|
#include "../../../devboard/hal/hal.h"
|
||||||
|
|
||||||
|
//If core is not defined, then we are running in Arduino or PIO
|
||||||
|
#ifndef CONFIG_ASYNC_TCP_RUNNING_CORE
|
||||||
|
#define CONFIG_ASYNC_TCP_RUNNING_CORE WIFI_CORE //any available core
|
||||||
|
#define CONFIG_ASYNC_TCP_USE_WDT 0 //if enabled, adds between 33us and 200us per event
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class AsyncClient;
|
||||||
|
|
||||||
|
#define ASYNC_MAX_ACK_TIME 5000
|
||||||
|
#define ASYNC_WRITE_FLAG_COPY 0x01 //will allocate new buffer to hold the data while sending (else will hold reference to the data given)
|
||||||
|
#define ASYNC_WRITE_FLAG_MORE 0x02 //will not send PSH flag, meaning that there should be more data to be sent before the application should react.
|
||||||
|
|
||||||
|
typedef std::function<void(void*, AsyncClient*)> AcConnectHandler;
|
||||||
|
typedef std::function<void(void*, AsyncClient*, size_t len, uint32_t time)> AcAckHandler;
|
||||||
|
typedef std::function<void(void*, AsyncClient*, int8_t error)> AcErrorHandler;
|
||||||
|
typedef std::function<void(void*, AsyncClient*, void *data, size_t len)> AcDataHandler;
|
||||||
|
typedef std::function<void(void*, AsyncClient*, struct pbuf *pb)> AcPacketHandler;
|
||||||
|
typedef std::function<void(void*, AsyncClient*, uint32_t time)> AcTimeoutHandler;
|
||||||
|
|
||||||
|
struct tcp_pcb;
|
||||||
|
struct ip_addr;
|
||||||
|
|
||||||
|
class AsyncClient {
|
||||||
|
public:
|
||||||
|
AsyncClient(tcp_pcb* pcb = 0);
|
||||||
|
~AsyncClient();
|
||||||
|
|
||||||
|
AsyncClient & operator=(const AsyncClient &other);
|
||||||
|
AsyncClient & operator+=(const AsyncClient &other);
|
||||||
|
|
||||||
|
bool operator==(const AsyncClient &other);
|
||||||
|
|
||||||
|
bool operator!=(const AsyncClient &other) {
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
bool connect(IPAddress ip, uint16_t port);
|
||||||
|
bool connect(const char* host, uint16_t port);
|
||||||
|
void close(bool now = false);
|
||||||
|
void stop();
|
||||||
|
int8_t abort();
|
||||||
|
bool free();
|
||||||
|
|
||||||
|
bool canSend();//ack is not pending
|
||||||
|
size_t space();//space available in the TCP window
|
||||||
|
size_t add(const char* data, size_t size, uint8_t apiflags=ASYNC_WRITE_FLAG_COPY);//add for sending
|
||||||
|
bool send();//send all data added with the method above
|
||||||
|
|
||||||
|
//write equals add()+send()
|
||||||
|
size_t write(const char* data);
|
||||||
|
size_t write(const char* data, size_t size, uint8_t apiflags=ASYNC_WRITE_FLAG_COPY); //only when canSend() == true
|
||||||
|
|
||||||
|
uint8_t state();
|
||||||
|
bool connecting();
|
||||||
|
bool connected();
|
||||||
|
bool disconnecting();
|
||||||
|
bool disconnected();
|
||||||
|
bool freeable();//disconnected or disconnecting
|
||||||
|
|
||||||
|
uint16_t getMss();
|
||||||
|
|
||||||
|
uint32_t getRxTimeout();
|
||||||
|
void setRxTimeout(uint32_t timeout);//no RX data timeout for the connection in seconds
|
||||||
|
|
||||||
|
uint32_t getAckTimeout();
|
||||||
|
void setAckTimeout(uint32_t timeout);//no ACK timeout for the last sent packet in milliseconds
|
||||||
|
|
||||||
|
void setNoDelay(bool nodelay);
|
||||||
|
bool getNoDelay();
|
||||||
|
|
||||||
|
uint32_t getRemoteAddress();
|
||||||
|
uint16_t getRemotePort();
|
||||||
|
uint32_t getLocalAddress();
|
||||||
|
uint16_t getLocalPort();
|
||||||
|
|
||||||
|
//compatibility
|
||||||
|
IPAddress remoteIP();
|
||||||
|
uint16_t remotePort();
|
||||||
|
IPAddress localIP();
|
||||||
|
uint16_t localPort();
|
||||||
|
|
||||||
|
void onConnect(AcConnectHandler cb, void* arg = 0); //on successful connect
|
||||||
|
void onDisconnect(AcConnectHandler cb, void* arg = 0); //disconnected
|
||||||
|
void onAck(AcAckHandler cb, void* arg = 0); //ack received
|
||||||
|
void onError(AcErrorHandler cb, void* arg = 0); //unsuccessful connect or error
|
||||||
|
void onData(AcDataHandler cb, void* arg = 0); //data received (called if onPacket is not used)
|
||||||
|
void onPacket(AcPacketHandler cb, void* arg = 0); //data received
|
||||||
|
void onTimeout(AcTimeoutHandler cb, void* arg = 0); //ack timeout
|
||||||
|
void onPoll(AcConnectHandler cb, void* arg = 0); //every 125ms when connected
|
||||||
|
|
||||||
|
void ackPacket(struct pbuf * pb);//ack pbuf from onPacket
|
||||||
|
size_t ack(size_t len); //ack data that you have not acked using the method below
|
||||||
|
void ackLater(){ _ack_pcb = false; } //will not ack the current packet. Call from onData
|
||||||
|
|
||||||
|
const char * errorToString(int8_t error);
|
||||||
|
const char * stateToString();
|
||||||
|
|
||||||
|
//Do not use any of the functions below!
|
||||||
|
static int8_t _s_poll(void *arg, struct tcp_pcb *tpcb);
|
||||||
|
static int8_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, int8_t err);
|
||||||
|
static int8_t _s_fin(void *arg, struct tcp_pcb *tpcb, int8_t err);
|
||||||
|
static int8_t _s_lwip_fin(void *arg, struct tcp_pcb *tpcb, int8_t err);
|
||||||
|
static void _s_error(void *arg, int8_t err);
|
||||||
|
static int8_t _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len);
|
||||||
|
static int8_t _s_connected(void* arg, void* tpcb, int8_t err);
|
||||||
|
static void _s_dns_found(const char *name, struct ip_addr *ipaddr, void *arg);
|
||||||
|
|
||||||
|
int8_t _recv(tcp_pcb* pcb, pbuf* pb, int8_t err);
|
||||||
|
tcp_pcb * pcb(){ return _pcb; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
tcp_pcb* _pcb;
|
||||||
|
int8_t _closed_slot;
|
||||||
|
|
||||||
|
AcConnectHandler _connect_cb;
|
||||||
|
void* _connect_cb_arg;
|
||||||
|
AcConnectHandler _discard_cb;
|
||||||
|
void* _discard_cb_arg;
|
||||||
|
AcAckHandler _sent_cb;
|
||||||
|
void* _sent_cb_arg;
|
||||||
|
AcErrorHandler _error_cb;
|
||||||
|
void* _error_cb_arg;
|
||||||
|
AcDataHandler _recv_cb;
|
||||||
|
void* _recv_cb_arg;
|
||||||
|
AcPacketHandler _pb_cb;
|
||||||
|
void* _pb_cb_arg;
|
||||||
|
AcTimeoutHandler _timeout_cb;
|
||||||
|
void* _timeout_cb_arg;
|
||||||
|
AcConnectHandler _poll_cb;
|
||||||
|
void* _poll_cb_arg;
|
||||||
|
|
||||||
|
bool _pcb_busy;
|
||||||
|
uint32_t _pcb_sent_at;
|
||||||
|
bool _ack_pcb;
|
||||||
|
uint32_t _rx_ack_len;
|
||||||
|
uint32_t _rx_last_packet;
|
||||||
|
uint32_t _rx_since_timeout;
|
||||||
|
uint32_t _ack_timeout;
|
||||||
|
uint16_t _connect_port;
|
||||||
|
|
||||||
|
int8_t _close();
|
||||||
|
void _free_closed_slot();
|
||||||
|
void _allocate_closed_slot();
|
||||||
|
int8_t _connected(void* pcb, int8_t err);
|
||||||
|
void _error(int8_t err);
|
||||||
|
int8_t _poll(tcp_pcb* pcb);
|
||||||
|
int8_t _sent(tcp_pcb* pcb, uint16_t len);
|
||||||
|
int8_t _fin(tcp_pcb* pcb, int8_t err);
|
||||||
|
int8_t _lwip_fin(tcp_pcb* pcb, int8_t err);
|
||||||
|
void _dns_found(struct ip_addr *ipaddr);
|
||||||
|
|
||||||
|
public:
|
||||||
|
AsyncClient* prev;
|
||||||
|
AsyncClient* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AsyncServer {
|
||||||
|
public:
|
||||||
|
AsyncServer(IPAddress addr, uint16_t port);
|
||||||
|
AsyncServer(uint16_t port);
|
||||||
|
~AsyncServer();
|
||||||
|
void onClient(AcConnectHandler cb, void* arg);
|
||||||
|
void begin();
|
||||||
|
void end();
|
||||||
|
void setNoDelay(bool nodelay);
|
||||||
|
bool getNoDelay();
|
||||||
|
uint8_t status();
|
||||||
|
|
||||||
|
//Do not use any of the functions below!
|
||||||
|
static int8_t _s_accept(void *arg, tcp_pcb* newpcb, int8_t err);
|
||||||
|
static int8_t _s_accepted(void *arg, AsyncClient* client);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint16_t _port;
|
||||||
|
IPAddress _addr;
|
||||||
|
bool _noDelay;
|
||||||
|
tcp_pcb* _pcb;
|
||||||
|
AcConnectHandler _connect_cb;
|
||||||
|
void* _connect_cb_arg;
|
||||||
|
|
||||||
|
int8_t _accept(tcp_pcb* newpcb, int8_t err);
|
||||||
|
int8_t _accepted(AsyncClient* client);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* ASYNCTCP_H_ */
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include "../../mathieucarbou-AsyncTCP/src/AsyncTCP.h"
|
#include "../../me-no-dev-AsyncTCP/src/AsyncTCP.h"
|
||||||
#define SSE_MAX_QUEUED_MESSAGES 32
|
#define SSE_MAX_QUEUED_MESSAGES 32
|
||||||
#else
|
#else
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include "../../mathieucarbou-AsyncTCP/src/AsyncTCP.h"
|
#include "../../me-no-dev-AsyncTCP/src/AsyncTCP.h"
|
||||||
#define WS_MAX_QUEUED_MESSAGES 32
|
#define WS_MAX_QUEUED_MESSAGES 32
|
||||||
#else
|
#else
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
|
|
|
@ -30,10 +30,10 @@
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include "../../mathieucarbou-AsyncTCP/src/AsyncTCP.h"
|
#include "../../me-no-dev-AsyncTCP/src/AsyncTCP.h"
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include "../../mathieucarbou-AsyncTCP/src/AsyncTCP.h"
|
#include "../../me-no-dev-AsyncTCP/src/AsyncTCP.h"
|
||||||
#else
|
#else
|
||||||
#error Platform not supported
|
#error Platform not supported
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue