Added getch the to our TelnetSpy overload. This adds the logic to add a LF if only CR is sent by a terminal package
This commit is contained in:
parent
06d78860ca
commit
3ca3e633ae
|
@ -1,5 +1,5 @@
|
||||||
REM Firmware
|
REM Firmware
|
||||||
esptool.exe --chip esp32 --port COM5 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 boot_app0.bin 0x1000 bootloader_qio_80m.bin 0x10000 ..\releases\AfterburnerV3.1.9.bin 0x8000 Afterburner.partitions.bin
|
esptool.exe --chip esp32 --port COM5 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 boot_app0.bin 0x1000 bootloader_qio_80m.bin 0x10000 AfterburnerV3.1.9.bin 0x8000 Afterburner.partitions.bin
|
||||||
REM SPIFFS
|
REM SPIFFS
|
||||||
esptool.exe --chip esp32 --port COM5 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_size detect 0x3d0000 spiffs.bin
|
esptool.exe --chip esp32 --port COM5 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_size detect 0x3d0000 spiffs.bin
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ upload_protocol = esptool
|
||||||
extra_scripts = post:add_CRC.py
|
extra_scripts = post:add_CRC.py
|
||||||
; replace shitty Arduino millis with a linear time version
|
; replace shitty Arduino millis with a linear time version
|
||||||
build_flags =
|
build_flags =
|
||||||
-Wl,--wrap,millis
|
-Wl,--wrap,millis
|
||||||
debug_tool = esp-prog
|
debug_tool = esp-prog
|
||||||
;upload_protocol = esp-prog
|
;upload_protocol = esp-prog
|
||||||
debug_init_break =
|
debug_init_break =
|
|
@ -126,8 +126,8 @@
|
||||||
|
|
||||||
const int FirmwareRevision = 31;
|
const int FirmwareRevision = 31;
|
||||||
const int FirmwareSubRevision = 9;
|
const int FirmwareSubRevision = 9;
|
||||||
const int FirmwareMinorRevision = 0;
|
const int FirmwareMinorRevision = 1;
|
||||||
const char* FirmwareDate = "14 Jan 2020";
|
const char* FirmwareDate = "15 Jan 2020";
|
||||||
|
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
@ -1370,15 +1370,15 @@ void checkDebugCommands()
|
||||||
static String pw1;
|
static String pw1;
|
||||||
static String pw2;
|
static String pw2;
|
||||||
|
|
||||||
// check for test commands received from PC Over USB
|
// check for test commands received over Debug serial port or telnet
|
||||||
if(DebugPort.available()) {
|
char rxVal;
|
||||||
|
if(DebugPort.getch(rxVal)) {
|
||||||
|
|
||||||
#ifdef PROTOCOL_INVESTIGATION
|
#ifdef PROTOCOL_INVESTIGATION
|
||||||
static int mode = 0;
|
static int mode = 0;6
|
||||||
static int val = 0;
|
static int val = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char rxVal = DebugPort.read();
|
|
||||||
|
|
||||||
if(bTestBTModule) {
|
if(bTestBTModule) {
|
||||||
bTestBTModule = Bluetooth.test(rxVal);
|
bTestBTModule = Bluetooth.test(rxVal);
|
||||||
return;
|
return;
|
||||||
|
@ -2030,3 +2030,5 @@ CTempSense& getTempSensor()
|
||||||
{
|
{
|
||||||
return TempSensor;
|
return TempSensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
ABTelnetSpy::ABTelnetSpy() : TelnetSpy() {
|
ABTelnetSpy::ABTelnetSpy() : TelnetSpy() {
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
|
_CRtimeout = 0;
|
||||||
|
_pending = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
@ -40,4 +42,47 @@ ABTelnetSpy::enable(bool state)
|
||||||
_enabled = state;
|
_enabled = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typical problem we have with terminal software that may or may not send CR/LF
|
||||||
|
// when a user hits ENTER.
|
||||||
|
// This method will inject a LF if none was received within a period of time
|
||||||
|
bool
|
||||||
|
ABTelnetSpy::getch(char& rxVal)
|
||||||
|
{
|
||||||
|
if(_CRtimeout) {
|
||||||
|
// have received a CR, now in wait interval for a LF
|
||||||
|
long diff = millis() - _CRtimeout;
|
||||||
|
if(available()) {
|
||||||
|
// a character is sitting in the debug input
|
||||||
|
// grab it and check if it is a LF, if so do not retain and return a faked LF
|
||||||
|
// otherwise retain for next pass, and return a faked LF now
|
||||||
|
_pending = read(); // read pending character
|
||||||
|
if(_pending == '\n') { // if it's a LF, a normal CR/LF occured
|
||||||
|
_pending = 0; // cancel retention
|
||||||
|
}
|
||||||
|
diff = 1; // force timeout to happen now
|
||||||
|
}
|
||||||
|
if(diff > 0) {
|
||||||
|
// timed out waiting for a LF, inject one now
|
||||||
|
_CRtimeout = 0; // reset timeout
|
||||||
|
rxVal = '\n'; // force a LF response
|
||||||
|
return true; // rxVal is valid
|
||||||
|
}
|
||||||
|
return false; // no character ready
|
||||||
|
}
|
||||||
|
|
||||||
|
// dispose of any character that may have been received during CR/LF timeout
|
||||||
|
if(_pending) {
|
||||||
|
rxVal = _pending;
|
||||||
|
_pending = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(available()) {
|
||||||
|
rxVal = read(); // read incoming character
|
||||||
|
if(rxVal == '\r') { // if it's a CR, start the timeout
|
||||||
|
_CRtimeout = (millis() + _LFPERIOD) | 1; // ensure always non zero
|
||||||
|
}
|
||||||
|
return true; // rxVal is valid
|
||||||
|
}
|
||||||
|
return false; // no character ready
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,19 @@ public:
|
||||||
ABTelnetSpy();
|
ABTelnetSpy();
|
||||||
size_t write(uint8_t) override;
|
size_t write(uint8_t) override;
|
||||||
void enable(bool);
|
void enable(bool);
|
||||||
|
/// getch():
|
||||||
|
// typical problem we have with terminal software that may or may not send CR/LF
|
||||||
|
// when a user hits ENTER.
|
||||||
|
// This getch method will inject a LF if none was received within a period of time
|
||||||
|
bool getch(char& rxVal);
|
||||||
protected:
|
protected:
|
||||||
bool _enabled;
|
bool _enabled;
|
||||||
|
unsigned long _CRtimeout;
|
||||||
|
char _pending;
|
||||||
|
const int _LFPERIOD = 100;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __ABTELNETSPY_H__
|
#endif // __ABTELNETSPY_H__
|
||||||
|
|
|
@ -96,8 +96,8 @@ CMQTTsetup::HandleMQTTsetup(char rxVal)
|
||||||
switch(_mode) {
|
switch(_mode) {
|
||||||
case 1: DebugPort.printf("Enter MQTT broker's IP address (%s)", _MQTTsetup.host); break;
|
case 1: DebugPort.printf("Enter MQTT broker's IP address (%s)", _MQTTsetup.host); break;
|
||||||
case 2: DebugPort.printf("Enter MQTT broker's port (%d)", _MQTTsetup.port); break;
|
case 2: DebugPort.printf("Enter MQTT broker's port (%d)", _MQTTsetup.port); break;
|
||||||
case 3: DebugPort.printf("Enter MQTT broker's username (%s)", _MQTTsetup.username); break;
|
case 3: DebugPort.printf("Enter MQTT broker's username (currently '%s', CTRL-X to erase)", _MQTTsetup.username); break;
|
||||||
case 4: DebugPort.printf("Enter MQTT broker's password (%s)", _MQTTsetup.password); break;
|
case 4: DebugPort.printf("Enter MQTT broker's password (currently '%s', CTRL-X to erase)", _MQTTsetup.password); break;
|
||||||
case 5: DebugPort.printf("Enter root topic name (%s)", _MQTTsetup.topicPrefix); break;
|
case 5: DebugPort.printf("Enter root topic name (%s)", _MQTTsetup.topicPrefix); break;
|
||||||
case 6: DebugPort.printf("Enter QoS level (%d)", _MQTTsetup.qos); break;
|
case 6: DebugPort.printf("Enter QoS level (%d)", _MQTTsetup.qos); break;
|
||||||
case 7: DebugPort.printf("Enable MQTT? (Y)es / (N)o (%s)", _MQTTsetup.enabled ? "YES" : "NO"); break;
|
case 7: DebugPort.printf("Enable MQTT? (Y)es / (N)o (%s)", _MQTTsetup.enabled ? "YES" : "NO"); break;
|
||||||
|
@ -181,14 +181,18 @@ CMQTTsetup::getMQTTstring(char rxVal, int maxidx, char* pTargetString)
|
||||||
{
|
{
|
||||||
if(rxVal < ' ') {
|
if(rxVal < ' ') {
|
||||||
if(_idx == 0) strcpy(_buffer, pTargetString);
|
if(_idx == 0) strcpy(_buffer, pTargetString);
|
||||||
if(rxVal == '\r')
|
if(rxVal == ('x' & 0x1f)) { // CTRL-X - erase string, return done
|
||||||
|
memset(pTargetString, 0, maxidx+1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(rxVal == '\r') // ignore CR
|
||||||
return false;
|
return false;
|
||||||
if(rxVal == '\n') {
|
if(rxVal == '\n') { // accept buffered string upon LF, return done
|
||||||
strncpy(pTargetString, _buffer, maxidx);
|
strncpy(pTargetString, _buffer, maxidx);
|
||||||
pTargetString[maxidx] = 0;
|
pTargetString[maxidx] = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(rxVal == 0x1b) {
|
if(rxVal == 0x1b) { // abort, no change upon ESC, return done
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue