Browse Source

Use same buffer size across all terminal-realted classes/methods. Set to 128 chars (#477)

softuart
Xose Pérez 6 years ago
parent
commit
9e8e667578
3 changed files with 30 additions and 24 deletions
  1. +3
    -3
      code/espurna/config/general.h
  2. +13
    -6
      code/espurna/libs/StreamInjector.h
  3. +14
    -15
      code/espurna/settings.ino

+ 3
- 3
code/espurna/config/general.h View File

@ -79,8 +79,6 @@
#define SERIAL_RX_BAUDRATE 115200 // Default baudrate #define SERIAL_RX_BAUDRATE 115200 // Default baudrate
#endif #endif
#define SERIAL_RX_BUFFER_SIZE 32
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// UDP debug log // UDP debug log
@ -124,9 +122,11 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef TERMINAL_SUPPORT #ifndef TERMINAL_SUPPORT
#define TERMINAL_SUPPORT 1 // Enable terminal commands (0.97Kb)
#define TERMINAL_SUPPORT 1 // Enable terminal commands (0.97Kb)
#endif #endif
#define TERMINAL_BUFFER_SIZE 128 // Max size for commands commands
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// SYSTEM CHECK // SYSTEM CHECK
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------


+ 13
- 6
code/espurna/libs/StreamInjector.h View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#define STREAM_INJECTOR_BUFFER_SIZE 32
#include <Stream.h>
class StreamInjector : public Stream { class StreamInjector : public Stream {
@ -12,7 +12,13 @@ class StreamInjector : public Stream {
typedef std::function<void(uint8_t ch)> writeCallback; typedef std::function<void(uint8_t ch)> 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) { virtual void callback(writeCallback c) {
_callback = c; _callback = c;
@ -28,7 +34,7 @@ class StreamInjector : public Stream {
if (ch == -1) { if (ch == -1) {
if (_buffer_read != _buffer_write) { if (_buffer_read != _buffer_write) {
ch = _buffer[_buffer_read]; ch = _buffer[_buffer_read];
_buffer_read = (_buffer_read + 1) % STREAM_INJECTOR_BUFFER_SIZE;
_buffer_read = (_buffer_read + 1) % _buffer_size;
} }
} }
return ch; return ch;
@ -37,7 +43,7 @@ class StreamInjector : public Stream {
virtual int available() { virtual int available() {
unsigned int bytes = _stream.available(); unsigned int bytes = _stream.available();
if (_buffer_read > _buffer_write) { 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) { } else if (_buffer_read < _buffer_write) {
bytes += (_buffer_write - _buffer_read); bytes += (_buffer_write - _buffer_read);
} }
@ -62,14 +68,15 @@ class StreamInjector : public Stream {
virtual void inject(char *data, size_t len) { virtual void inject(char *data, size_t len) {
for (int i=0; i<len; i++) { for (int i=0; i<len; i++) {
_buffer[_buffer_write] = data[i]; _buffer[_buffer_write] = data[i];
_buffer_write = (_buffer_write + 1) % STREAM_INJECTOR_BUFFER_SIZE;
_buffer_write = (_buffer_write + 1) % _buffer_size;
} }
} }
private: private:
Stream& _stream; Stream& _stream;
unsigned char _buffer[STREAM_INJECTOR_BUFFER_SIZE];
char * _buffer;
unsigned char _buffer_size;
unsigned char _buffer_write = 0; unsigned char _buffer_write = 0;
unsigned char _buffer_read = 0; unsigned char _buffer_read = 0;
writeCallback _callback = NULL; writeCallback _callback = NULL;


+ 14
- 15
code/espurna/settings.ino View File

@ -7,30 +7,29 @@ Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
*/ */
#include <EEPROM.h> #include <EEPROM.h>
#include <vector>
#include "spi_flash.h" #include "spi_flash.h"
#include "libs/EmbedisWrap.h" #include "libs/EmbedisWrap.h"
#include <vector>
#include <StreamString.h>
#include <Stream.h>
#ifdef DEBUG_PORT
#define EMBEDIS_PORT DEBUG_PORT
#else
#define EMBEDIS_PORT Serial
#endif
#if TELNET_SUPPORT #if TELNET_SUPPORT
#include "libs/StreamInjector.h" #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 #endif
EmbedisWrap embedis(EMBEDIS_PORT, TERMINAL_BUFFER_SIZE);
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
#ifdef SERIAL_RX_PORT #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; static unsigned char _serial_rx_pointer = 0;
#endif #endif
#endif #endif


Loading…
Cancel
Save