CAN and SUB correctly abort current sequence, including string. Start of adding PM's

http-comm
Ondřej Hruška 7 years ago
parent 55afcca955
commit 6665b5c183
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 55
      user/ansi_parser.c
  2. 13
      user/ansi_parser.rl
  3. 15
      user/ansi_parser_callbacks.c
  4. 34
      user/apars_pm.c
  5. 10
      user/apars_pm.h
  6. 2
      user/apars_string.c

@ -142,6 +142,13 @@ ansi_parser(char newchar)
history[HISTORY_LEN-1] = newchar; history[HISTORY_LEN-1] = newchar;
#endif #endif
// THose should work always, even inside a string
if (newchar == CAN || newchar == SUB) {
// Cancel the active sequence
cs = ansi_start;
return;
}
// Handle simple characters immediately (bypass parser) // Handle simple characters immediately (bypass parser)
if (newchar < ' ' && !inside_string) { if (newchar < ' ' && !inside_string) {
switch (newchar) { switch (newchar) {
@ -183,12 +190,6 @@ ansi_parser(char newchar)
apars_handle_enq(); apars_handle_enq();
return; return;
// Cancel the active sequence
case CAN:
case SUB:
cs = ansi_start;
return;
default: default:
// Discard all other control codes // Discard all other control codes
return; return;
@ -208,7 +209,7 @@ ansi_parser(char newchar)
// The parser // The parser
/* #line 212 "user/ansi_parser.c" */ /* #line 213 "user/ansi_parser.c" */
{ {
const char *_acts; const char *_acts;
unsigned int _nacts; unsigned int _nacts;
@ -398,7 +399,7 @@ execFuncs:
while ( _nacts-- > 0 ) { while ( _nacts-- > 0 ) {
switch ( *_acts++ ) { switch ( *_acts++ ) {
case 0: case 0:
/* #line 188 "user/ansi_parser.rl" */ /* #line 189 "user/ansi_parser.rl" */
{ {
ansi_warn("Parser error."); ansi_warn("Parser error.");
apars_show_context(); apars_show_context();
@ -407,7 +408,7 @@ execFuncs:
} }
break; break;
case 1: case 1:
/* #line 197 "user/ansi_parser.rl" */ /* #line 198 "user/ansi_parser.rl" */
{ {
if ((*p) != 0) { if ((*p) != 0) {
apars_handle_plainchar((*p)); apars_handle_plainchar((*p));
@ -415,7 +416,7 @@ execFuncs:
} }
break; break;
case 2: case 2:
/* #line 205 "user/ansi_parser.rl" */ /* #line 206 "user/ansi_parser.rl" */
{ {
// Reset the CSI builder // Reset the CSI builder
leadchar = NUL; leadchar = NUL;
@ -432,13 +433,13 @@ execFuncs:
} }
break; break;
case 3: case 3:
/* #line 220 "user/ansi_parser.rl" */ /* #line 221 "user/ansi_parser.rl" */
{ {
leadchar = (*p); leadchar = (*p);
} }
break; break;
case 4: case 4:
/* #line 224 "user/ansi_parser.rl" */ /* #line 225 "user/ansi_parser.rl" */
{ {
if (arg_cnt == 0) arg_cnt = 1; if (arg_cnt == 0) arg_cnt = 1;
// x10 + digit // x10 + digit
@ -448,7 +449,7 @@ execFuncs:
} }
break; break;
case 5: case 5:
/* #line 232 "user/ansi_parser.rl" */ /* #line 233 "user/ansi_parser.rl" */
{ {
if (arg_cnt == 0) arg_cnt = 1; // handle case when first arg is empty if (arg_cnt == 0) arg_cnt = 1; // handle case when first arg is empty
arg_cnt++; arg_cnt++;
@ -456,20 +457,20 @@ execFuncs:
} }
break; break;
case 6: case 6:
/* #line 238 "user/ansi_parser.rl" */ /* #line 239 "user/ansi_parser.rl" */
{ {
interchar = (*p); interchar = (*p);
} }
break; break;
case 7: case 7:
/* #line 242 "user/ansi_parser.rl" */ /* #line 243 "user/ansi_parser.rl" */
{ {
apars_handle_csi(leadchar, arg, arg_cnt, interchar, (*p)); apars_handle_csi(leadchar, arg, arg_cnt, interchar, (*p));
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
case 8: case 8:
/* #line 254 "user/ansi_parser.rl" */ /* #line 255 "user/ansi_parser.rl" */
{ {
leadchar = (*p); leadchar = (*p);
str_ni = 0; str_ni = 0;
@ -479,13 +480,13 @@ execFuncs:
} }
break; break;
case 9: case 9:
/* #line 262 "user/ansi_parser.rl" */ /* #line 263 "user/ansi_parser.rl" */
{ {
string_buffer[str_ni++] = (*p); string_buffer[str_ni++] = (*p);
} }
break; break;
case 10: case 10:
/* #line 266 "user/ansi_parser.rl" */ /* #line 267 "user/ansi_parser.rl" */
{ {
inside_string = false; inside_string = false;
string_buffer[str_ni++] = '\0'; string_buffer[str_ni++] = '\0';
@ -494,41 +495,41 @@ execFuncs:
} }
break; break;
case 11: case 11:
/* #line 279 "user/ansi_parser.rl" */ /* #line 280 "user/ansi_parser.rl" */
{ {
apars_handle_hash_cmd((*p)); apars_handle_hash_cmd((*p));
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
case 12: case 12:
/* #line 284 "user/ansi_parser.rl" */ /* #line 285 "user/ansi_parser.rl" */
{ {
apars_handle_short_cmd((*p)); apars_handle_short_cmd((*p));
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
case 13: case 13:
/* #line 289 "user/ansi_parser.rl" */ /* #line 290 "user/ansi_parser.rl" */
{ {
apars_handle_space_cmd((*p)); apars_handle_space_cmd((*p));
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
case 14: case 14:
/* #line 296 "user/ansi_parser.rl" */ /* #line 297 "user/ansi_parser.rl" */
{ {
leadchar = (*p); leadchar = (*p);
{cs = 10;goto _again;} {cs = 10;goto _again;}
} }
break; break;
case 15: case 15:
/* #line 301 "user/ansi_parser.rl" */ /* #line 302 "user/ansi_parser.rl" */
{ {
apars_handle_chs_designate(leadchar, (*p)); apars_handle_chs_designate(leadchar, (*p));
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
/* #line 532 "user/ansi_parser.c" */ /* #line 533 "user/ansi_parser.c" */
} }
} }
goto _again; goto _again;
@ -546,7 +547,7 @@ _again:
while ( __nacts-- > 0 ) { while ( __nacts-- > 0 ) {
switch ( *__acts++ ) { switch ( *__acts++ ) {
case 0: case 0:
/* #line 188 "user/ansi_parser.rl" */ /* #line 189 "user/ansi_parser.rl" */
{ {
ansi_warn("Parser error."); ansi_warn("Parser error.");
apars_show_context(); apars_show_context();
@ -556,7 +557,7 @@ _again:
goto _again;} goto _again;}
} }
break; break;
/* #line 560 "user/ansi_parser.c" */ /* #line 561 "user/ansi_parser.c" */
} }
} }
} }
@ -564,6 +565,6 @@ goto _again;}
_out: {} _out: {}
} }
/* #line 324 "user/ansi_parser.rl" */ /* #line 325 "user/ansi_parser.rl" */
} }

@ -111,6 +111,13 @@ ansi_parser(char newchar)
history[HISTORY_LEN-1] = newchar; history[HISTORY_LEN-1] = newchar;
#endif #endif
// THose should work always, even inside a string
if (newchar == CAN || newchar == SUB) {
// Cancel the active sequence
cs = ansi_start;
return;
}
// Handle simple characters immediately (bypass parser) // Handle simple characters immediately (bypass parser)
if (newchar < ' ' && !inside_string) { if (newchar < ' ' && !inside_string) {
switch (newchar) { switch (newchar) {
@ -152,12 +159,6 @@ ansi_parser(char newchar)
apars_handle_enq(); apars_handle_enq();
return; return;
// Cancel the active sequence
case CAN:
case SUB:
cs = ansi_start;
return;
default: default:
// Discard all other control codes // Discard all other control codes
return; return;

@ -12,6 +12,13 @@
#include "uart_buffer.h" #include "uart_buffer.h"
#include "screen.h" #include "screen.h"
volatile bool enquiry_suppressed = false;
ETSTimer enqTimer;
void ICACHE_FLASH_ATTR enqTimerCb(void *unused)
{
enquiry_suppressed = false;
}
/** /**
* Send a response to UART0 * Send a response to UART0
* @param str * @param str
@ -37,8 +44,16 @@ apars_handle_bel(void)
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
apars_handle_enq(void) apars_handle_enq(void)
{ {
if (enquiry_suppressed) return;
// version encased in SOS and ST // version encased in SOS and ST
apars_respond("\x1bXESPTerm " FIRMWARE_VERSION "\x1b\\"); apars_respond("\x1bXESPTerm " FIRMWARE_VERSION "\x1b\\");
// Throttle enquiry - this is a single-character-invoked response,
// so it tends to happen randomly when throwing garbage at the ESP.
// We don't want to fill the output buffer with dozens of enquiry responses
enquiry_suppressed = true;
TIMER_START(&enqTimer, enqTimerCb, 500, 0);
} }
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR

@ -0,0 +1,34 @@
//
// Created by MightyPork on 2017/08/20.
//
// Handle privacy messages
// PM Pt ST
// (PM = ESC ^)
//
// Those are used for device-to-device communication.
// They were not used for anything in the original VT100 and are not
// used by Xterm or any other common emulator, but they should be safely discarded.
//
#include <esp8266.h>
#include "apars_pm.h"
#include "ansi_parser_callbacks.h"
#include "screen.h"
#include "apars_logging.h"
/**
* Helper function to parse incoming DCS (Device Control String)
* @param buffer - the DCS body (after DCS and before ST)
*/
void ICACHE_FLASH_ATTR
apars_handle_pm(const char *buffer)
{
size_t len = strlen(buffer);
if (false) {
//
}
else {
ansi_warn("Bad DCS: %s", buffer);
apars_show_context();
}
}

@ -0,0 +1,10 @@
//
// Created by MightyPork on 2017/08/20.
//
#ifndef ESP_VT100_FIRMWARE_APARS_PM_H
#define ESP_VT100_FIRMWARE_APARS_PM_H
void apars_handle_pm(const char *buffer);
#endif //ESP_VT100_FIRMWARE_APARS_PM_H

@ -17,6 +17,7 @@
#include "apars_logging.h" #include "apars_logging.h"
#include "ansi_parser_callbacks.h" #include "ansi_parser_callbacks.h"
#include "screen.h" #include "screen.h"
#include "apars_pm.h"
// ----- Generic String cmd - disambiguation ----- // ----- Generic String cmd - disambiguation -----
@ -37,6 +38,7 @@ apars_handle_string_cmd(char leadchar, char *buffer)
break; break;
case '^': // PM - Privacy Message case '^': // PM - Privacy Message
apars_handle_pm(buffer);
break; break;
case '_': // APC - Application Program Command case '_': // APC - Application Program Command

Loading…
Cancel
Save