2021-10-27 05:43:28 -03:00
|
|
|
/*
|
|
|
|
* This file 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 file 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_HAL/UARTDriver.h>
|
|
|
|
#include <AP_HAL/utility/RingBuffer.h>
|
|
|
|
#include <AP_HAL_ESP32/AP_HAL_ESP32.h>
|
|
|
|
#include <AP_HAL_ESP32/Semaphores.h>
|
|
|
|
#include "lwip/sockets.h"
|
|
|
|
#include "esp_event.h"
|
|
|
|
|
|
|
|
|
|
|
|
class ESP32::WiFiUdpDriver : public AP_HAL::UARTDriver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WiFiUdpDriver();
|
|
|
|
|
|
|
|
void begin(uint32_t b) override;
|
|
|
|
void begin(uint32_t b, uint16_t rxS, uint16_t txS) override;
|
|
|
|
void end() override;
|
|
|
|
void flush() override;
|
|
|
|
bool is_initialized() override;
|
|
|
|
void set_blocking_writes(bool blocking) override;
|
|
|
|
bool tx_pending() override;
|
|
|
|
|
|
|
|
uint32_t available() override;
|
|
|
|
uint32_t txspace() override;
|
2023-02-21 05:35:57 -04:00
|
|
|
bool read(uint8_t &c) override;
|
2021-10-27 05:43:28 -03:00
|
|
|
|
|
|
|
size_t write(uint8_t c) override;
|
|
|
|
size_t write(const uint8_t *buffer, size_t size) override;
|
|
|
|
|
2023-01-18 03:45:42 -04:00
|
|
|
uint32_t bw_in_bytes_per_second() const override
|
2021-10-27 05:43:28 -03:00
|
|
|
{
|
2023-01-18 03:45:42 -04:00
|
|
|
return 1000*1024;
|
2021-10-27 05:43:28 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool discard_input() override;
|
|
|
|
private:
|
|
|
|
enum ConnectionState {
|
|
|
|
NOT_INITIALIZED,
|
|
|
|
INITIALIZED,
|
|
|
|
CONNECTED
|
|
|
|
};
|
|
|
|
const size_t TX_BUF_SIZE = 1024;
|
|
|
|
const size_t RX_BUF_SIZE = 1024;
|
2023-05-01 20:30:39 -03:00
|
|
|
uint8_t _buffer[255]; // 32 means slow param reads as its too small for most mavlink packets, 128 is still a bit small due to packet overheads
|
2021-10-27 05:43:28 -03:00
|
|
|
ByteBuffer _readbuf{0};
|
|
|
|
ByteBuffer _writebuf{0};
|
|
|
|
Semaphore _write_mutex;
|
|
|
|
Semaphore _read_mutex;
|
|
|
|
ConnectionState _state;
|
|
|
|
|
|
|
|
int accept_socket;
|
|
|
|
|
2023-05-13 23:39:46 -03:00
|
|
|
tskTaskControlBlock* _wifi_task_handle;
|
2021-10-27 05:43:28 -03:00
|
|
|
void initialize_wifi();
|
|
|
|
bool read_all();
|
|
|
|
bool write_data();
|
|
|
|
bool start_listen();
|
|
|
|
bool try_accept();
|
2023-05-01 20:30:39 -03:00
|
|
|
static void _wifi_thread2(void* arg);
|
2021-10-27 05:43:28 -03:00
|
|
|
};
|