mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-07-31 22:02:01 +08:00
79 lines
2.4 KiB
C++
79 lines
2.4 KiB
C++
/*
|
|
serial2socket.h - serial 2 socket functions class
|
|
|
|
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
|
|
|
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 _SERIAL_2_SOCKET_H_
|
|
#define _SERIAL_2_SOCKET_H_
|
|
|
|
#include <Print.h>
|
|
|
|
#include "../authentication/authentication_level_types.h"
|
|
#define S2S_TXBUFFERSIZE 512
|
|
#define S2S_RXBUFFERSIZE 256
|
|
#define S2S_FLUSHTIMEOUT 500
|
|
|
|
class ESP3DMessage; // forward declaration
|
|
|
|
class Serial_2_Socket : public Stream {
|
|
public:
|
|
Serial_2_Socket();
|
|
~Serial_2_Socket();
|
|
size_t write(uint8_t c);
|
|
size_t write(const uint8_t *buffer, size_t size);
|
|
bool dispatch(ESP3DMessage *message);
|
|
|
|
inline size_t write(const char *s) { return write((uint8_t *)s, strlen(s)); }
|
|
inline size_t write(unsigned long n) { return write((uint8_t)n); }
|
|
inline size_t write(long n) { return write((uint8_t)n); }
|
|
inline size_t write(unsigned int n) { return write((uint8_t)n); }
|
|
inline size_t write(int n) { return write((uint8_t)n); }
|
|
long baudRate();
|
|
void begin(long speed);
|
|
void end();
|
|
void enable(bool enable = true);
|
|
bool started();
|
|
int available();
|
|
int peek(void);
|
|
int read(void);
|
|
bool push2RX(const uint8_t *buffer, size_t size);
|
|
void flush(bool useMutex = true);
|
|
void handle_flush();
|
|
void handle();
|
|
operator bool() const;
|
|
void pause(bool state = true);
|
|
bool isPaused();
|
|
|
|
private:
|
|
bool _started;
|
|
bool _paused;
|
|
ESP3DAuthenticationLevel _auth;
|
|
void* _rxBufferMutex; // Opaque pointer for RX buffer mutex
|
|
void* _txBufferMutex; // Opaque pointer for TX buffer mutex
|
|
uint32_t _lastflush;
|
|
uint8_t _TXbuffer[S2S_TXBUFFERSIZE+1];
|
|
uint16_t _TXbufferSize;
|
|
uint8_t _RXbuffer[S2S_RXBUFFERSIZE+1];
|
|
uint16_t _RXbufferSize;
|
|
uint16_t _RXbufferpos;
|
|
};
|
|
|
|
extern Serial_2_Socket Serial2Socket;
|
|
|
|
#endif
|