Browse Source

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

softuart
Xose Pérez 7 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
#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
//------------------------------------------------------------------------------


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

@ -4,7 +4,7 @@
#pragma once
#define STREAM_INJECTOR_BUFFER_SIZE 32
#include <Stream.h>
class StreamInjector : public Stream {
@ -12,7 +12,13 @@ class StreamInjector : public Stream {
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) {
_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<len; i++) {
_buffer[_buffer_write] = data[i];
_buffer_write = (_buffer_write + 1) % STREAM_INJECTOR_BUFFER_SIZE;
_buffer_write = (_buffer_write + 1) % _buffer_size;
}
}
private:
Stream& _stream;
unsigned char _buffer[STREAM_INJECTOR_BUFFER_SIZE];
char * _buffer;
unsigned char _buffer_size;
unsigned char _buffer_write = 0;
unsigned char _buffer_read = 0;
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 <vector>
#include "spi_flash.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
#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


Loading…
Cancel
Save