diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 1f530cab..c027c6f5 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -79,8 +79,6 @@ #define SERIAL_RX_BAUDRATE 115200 // Default baudrate #endif -#define SERIAL_RX_BUFFER_SIZE 32 - //------------------------------------------------------------------------------ // UDP debug log @@ -124,9 +122,11 @@ //------------------------------------------------------------------------------ #ifndef TERMINAL_SUPPORT -#define TERMINAL_SUPPORT 1 // Enable terminal commands (0.97Kb) +#define TERMINAL_SUPPORT 1 // Enable terminal commands (0.97Kb) #endif +#define TERMINAL_BUFFER_SIZE 128 // Max size for commands commands + //------------------------------------------------------------------------------ // SYSTEM CHECK //------------------------------------------------------------------------------ diff --git a/code/espurna/libs/StreamInjector.h b/code/espurna/libs/StreamInjector.h index 648473c7..56fa8ed4 100644 --- a/code/espurna/libs/StreamInjector.h +++ b/code/espurna/libs/StreamInjector.h @@ -4,7 +4,7 @@ #pragma once -#define STREAM_INJECTOR_BUFFER_SIZE 32 +#include class StreamInjector : public Stream { @@ -12,7 +12,13 @@ class StreamInjector : public Stream { typedef std::function writeCallback; - StreamInjector(Stream& serial) : _stream(serial), _buffer() {} + StreamInjector(Stream& serial, size_t buflen = 128) : _stream(serial), _buffer_size(buflen) { + char * _buffer = new char[buflen]; + } + + ~StreamInjector() { + delete[] _buffer; + } virtual void callback(writeCallback c) { _callback = c; @@ -28,7 +34,7 @@ class StreamInjector : public Stream { if (ch == -1) { if (_buffer_read != _buffer_write) { ch = _buffer[_buffer_read]; - _buffer_read = (_buffer_read + 1) % STREAM_INJECTOR_BUFFER_SIZE; + _buffer_read = (_buffer_read + 1) % _buffer_size; } } return ch; @@ -37,7 +43,7 @@ class StreamInjector : public Stream { virtual int available() { unsigned int bytes = _stream.available(); if (_buffer_read > _buffer_write) { - bytes += (_buffer_write - _buffer_read + STREAM_INJECTOR_BUFFER_SIZE); + bytes += (_buffer_write - _buffer_read + _buffer_size); } else if (_buffer_read < _buffer_write) { bytes += (_buffer_write - _buffer_read); } @@ -62,14 +68,15 @@ class StreamInjector : public Stream { virtual void inject(char *data, size_t len) { for (int i=0; i */ #include +#include #include "spi_flash.h" #include "libs/EmbedisWrap.h" -#include -#include +#include + +#ifdef DEBUG_PORT + #define EMBEDIS_PORT DEBUG_PORT +#else + #define EMBEDIS_PORT Serial +#endif #if TELNET_SUPPORT #include "libs/StreamInjector.h" - #ifdef DEBUG_PORT - StreamInjector _serial = StreamInjector(DEBUG_PORT); - #else - StreamInjector _serial = StreamInjector(Serial); - #endif - EmbedisWrap embedis(_serial); -#else - #ifdef DEBUG_PORT - EmbedisWrap embedis(DEBUG_PORT); - #else - EmbedisWrap embedis(_serial); - #endif + StreamInjector _serial = StreamInjector(EMBEDIS_PORT, TERMINAL_BUFFER_SIZE); + #undef EMBEDIS_PORT + #define EMBEDIS_PORT _serial #endif +EmbedisWrap embedis(EMBEDIS_PORT, TERMINAL_BUFFER_SIZE); + #if TERMINAL_SUPPORT #ifdef SERIAL_RX_PORT - char _serial_rx_buffer[SERIAL_RX_BUFFER_SIZE]; + char _serial_rx_buffer[TERMINAL_BUFFER_SIZE]; static unsigned char _serial_rx_pointer = 0; #endif #endif