Support library for the ESP8266 Wireless Terminal. Can also be used for communicating with any VT100-compatible terminal.

Committer:
MightyPork
Date:
Sun Mar 19 17:19:16 2017 +0000
Revision:
4:294e8f53ebcd
Parent:
3:1114012184bf
Child:
5:7379bd37f3e2
Added bunch of new features and a parser

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MightyPork 0:20fb68233f89 1 #include "mbed.h"
MightyPork 0:20fb68233f89 2 #include "espterm.hpp"
MightyPork 0:20fb68233f89 3
MightyPork 1:09dfc9fd55f4 4 #include <cstdarg>
MightyPork 1:09dfc9fd55f4 5
MightyPork 1:09dfc9fd55f4 6
MightyPork 4:294e8f53ebcd 7 void ESPTerm::init(Serial *s)
MightyPork 4:294e8f53ebcd 8 {
MightyPork 4:294e8f53ebcd 9 cs = -1;
MightyPork 4:294e8f53ebcd 10 device_ok = false;
MightyPork 4:294e8f53ebcd 11
MightyPork 4:294e8f53ebcd 12 on_mouse_click = NULL;
MightyPork 4:294e8f53ebcd 13 on_button = NULL;
MightyPork 4:294e8f53ebcd 14 on_esp_reset = NULL;
MightyPork 4:294e8f53ebcd 15 on_char_rx = NULL;
MightyPork 4:294e8f53ebcd 16 on_key_press = NULL;
MightyPork 4:294e8f53ebcd 17 on_osc_rx = NULL;
MightyPork 4:294e8f53ebcd 18
MightyPork 4:294e8f53ebcd 19 ser = s;
MightyPork 4:294e8f53ebcd 20 ser->attach(callback(this, &ESPTerm::ser_rx_char), Serial::RxIrq);
MightyPork 4:294e8f53ebcd 21 }
MightyPork 4:294e8f53ebcd 22
MightyPork 4:294e8f53ebcd 23
MightyPork 1:09dfc9fd55f4 24 ESPTerm::ESPTerm(Serial *s)
MightyPork 1:09dfc9fd55f4 25 {
MightyPork 4:294e8f53ebcd 26 init(s);
MightyPork 0:20fb68233f89 27 }
MightyPork 1:09dfc9fd55f4 28
MightyPork 1:09dfc9fd55f4 29
MightyPork 1:09dfc9fd55f4 30 ESPTerm::ESPTerm(void)
MightyPork 1:09dfc9fd55f4 31 {
MightyPork 4:294e8f53ebcd 32 // Defaults
MightyPork 4:294e8f53ebcd 33 init(new Serial(PA_2, PA_3, 115200));
MightyPork 1:09dfc9fd55f4 34 }
MightyPork 1:09dfc9fd55f4 35
MightyPork 4:294e8f53ebcd 36
MightyPork 4:294e8f53ebcd 37 ESPTerm::ESPTerm(PinName txPin, PinName rxPin, int baud)
MightyPork 4:294e8f53ebcd 38 {
MightyPork 4:294e8f53ebcd 39 init(new Serial(txPin, rxPin, baud));
MightyPork 4:294e8f53ebcd 40 }
MightyPork 4:294e8f53ebcd 41
MightyPork 4:294e8f53ebcd 42
MightyPork 3:1114012184bf 43 // ----- Printing -----
MightyPork 3:1114012184bf 44
MightyPork 1:09dfc9fd55f4 45
MightyPork 1:09dfc9fd55f4 46 int ESPTerm::printf(const char *format, ...)
MightyPork 1:09dfc9fd55f4 47 {
MightyPork 1:09dfc9fd55f4 48 std::va_list arg;
MightyPork 1:09dfc9fd55f4 49 va_start(arg, format);
MightyPork 1:09dfc9fd55f4 50 int r = ser->vprintf(format, arg);
MightyPork 1:09dfc9fd55f4 51 va_end(arg);
MightyPork 1:09dfc9fd55f4 52
MightyPork 1:09dfc9fd55f4 53 return r;
MightyPork 1:09dfc9fd55f4 54 }
MightyPork 1:09dfc9fd55f4 55
MightyPork 4:294e8f53ebcd 56
MightyPork 1:09dfc9fd55f4 57 // alias of printf
MightyPork 1:09dfc9fd55f4 58 int ESPTerm::print(const char *format, ...)
MightyPork 1:09dfc9fd55f4 59 {
MightyPork 1:09dfc9fd55f4 60 std::va_list arg;
MightyPork 1:09dfc9fd55f4 61 va_start(arg, format);
MightyPork 1:09dfc9fd55f4 62 int r = ser->vprintf(format, arg);
MightyPork 1:09dfc9fd55f4 63 va_end(arg);
MightyPork 1:09dfc9fd55f4 64
MightyPork 1:09dfc9fd55f4 65 return r;
MightyPork 1:09dfc9fd55f4 66 }
MightyPork 1:09dfc9fd55f4 67
MightyPork 1:09dfc9fd55f4 68
MightyPork 1:09dfc9fd55f4 69 int ESPTerm::println(const char *format, ...) {
MightyPork 1:09dfc9fd55f4 70 std::va_list arg;
MightyPork 1:09dfc9fd55f4 71 va_start(arg, format);
MightyPork 1:09dfc9fd55f4 72 int r = ser->vprintf(format, arg);
MightyPork 1:09dfc9fd55f4 73 va_end(arg);
MightyPork 1:09dfc9fd55f4 74
MightyPork 1:09dfc9fd55f4 75 r += ser->puts("\r\n");
MightyPork 1:09dfc9fd55f4 76 return r;
MightyPork 1:09dfc9fd55f4 77 }
MightyPork 1:09dfc9fd55f4 78
MightyPork 1:09dfc9fd55f4 79
MightyPork 3:1114012184bf 80 // ----- Colors -----
MightyPork 3:1114012184bf 81
MightyPork 3:1114012184bf 82
MightyPork 3:1114012184bf 83 void ESPTerm::fg(Color c)
MightyPork 1:09dfc9fd55f4 84 {
MightyPork 1:09dfc9fd55f4 85 int ci = c;
MightyPork 1:09dfc9fd55f4 86 if(ci > 7) {
MightyPork 1:09dfc9fd55f4 87 ci += (90-8);
MightyPork 1:09dfc9fd55f4 88 } else {
MightyPork 1:09dfc9fd55f4 89 ci += 30;
MightyPork 1:09dfc9fd55f4 90 }
MightyPork 1:09dfc9fd55f4 91 ser->printf("\033[%dm", ci);
MightyPork 1:09dfc9fd55f4 92 }
MightyPork 1:09dfc9fd55f4 93
MightyPork 1:09dfc9fd55f4 94
MightyPork 3:1114012184bf 95 void ESPTerm::bg(Color c)
MightyPork 1:09dfc9fd55f4 96 {
MightyPork 1:09dfc9fd55f4 97 int ci = c;
MightyPork 1:09dfc9fd55f4 98 if(ci > 7) {
MightyPork 1:09dfc9fd55f4 99 ci += (100-8);
MightyPork 1:09dfc9fd55f4 100 } else {
MightyPork 1:09dfc9fd55f4 101 ci += 40;
MightyPork 1:09dfc9fd55f4 102 }
MightyPork 1:09dfc9fd55f4 103 ser->printf("\033[%dm", ci);
MightyPork 1:09dfc9fd55f4 104 }
MightyPork 1:09dfc9fd55f4 105
MightyPork 1:09dfc9fd55f4 106
MightyPork 1:09dfc9fd55f4 107 void ESPTerm::reset_attribs(void)
MightyPork 1:09dfc9fd55f4 108 {
MightyPork 1:09dfc9fd55f4 109 ser->puts("\033[0m");
MightyPork 1:09dfc9fd55f4 110 }
MightyPork 1:09dfc9fd55f4 111
MightyPork 1:09dfc9fd55f4 112
MightyPork 3:1114012184bf 113 // ----- Cursor control & erasing -----
MightyPork 3:1114012184bf 114
MightyPork 3:1114012184bf 115
MightyPork 1:09dfc9fd55f4 116 void ESPTerm::go_to(int y, int x)
MightyPork 1:09dfc9fd55f4 117 {
MightyPork 1:09dfc9fd55f4 118 ser->printf("\033[%d;%dH", y, x);
MightyPork 1:09dfc9fd55f4 119 }
MightyPork 1:09dfc9fd55f4 120
MightyPork 1:09dfc9fd55f4 121
MightyPork 1:09dfc9fd55f4 122 void ESPTerm::clear_screen(ClearMode mode)
MightyPork 1:09dfc9fd55f4 123 {
MightyPork 1:09dfc9fd55f4 124 ser->printf("\033[%dJ", mode);
MightyPork 1:09dfc9fd55f4 125 }
MightyPork 1:09dfc9fd55f4 126
MightyPork 1:09dfc9fd55f4 127
MightyPork 1:09dfc9fd55f4 128 void ESPTerm::clear_line(ClearMode mode)
MightyPork 1:09dfc9fd55f4 129 {
MightyPork 1:09dfc9fd55f4 130 ser->printf("\033[%dK", mode);
MightyPork 1:09dfc9fd55f4 131 }
MightyPork 1:09dfc9fd55f4 132
MightyPork 1:09dfc9fd55f4 133
MightyPork 1:09dfc9fd55f4 134 void ESPTerm::screen_reset(void)
MightyPork 1:09dfc9fd55f4 135 {
MightyPork 1:09dfc9fd55f4 136 ser->puts("\033c");
MightyPork 1:09dfc9fd55f4 137 }
MightyPork 1:09dfc9fd55f4 138
MightyPork 1:09dfc9fd55f4 139
MightyPork 1:09dfc9fd55f4 140 void ESPTerm::show_cursor(bool yes)
MightyPork 1:09dfc9fd55f4 141 {
MightyPork 1:09dfc9fd55f4 142 if (yes)
MightyPork 1:09dfc9fd55f4 143 ser->puts("\033[?25h");
MightyPork 1:09dfc9fd55f4 144 else
MightyPork 1:09dfc9fd55f4 145 ser->puts("\033[?25l");
MightyPork 1:09dfc9fd55f4 146 }
MightyPork 1:09dfc9fd55f4 147
MightyPork 1:09dfc9fd55f4 148
MightyPork 3:1114012184bf 149 // ----- System commands -----
MightyPork 3:1114012184bf 150
MightyPork 3:1114012184bf 151
MightyPork 1:09dfc9fd55f4 152 void ESPTerm::factory_reset(void)
MightyPork 1:09dfc9fd55f4 153 {
MightyPork 1:09dfc9fd55f4 154 ser->puts("\033]FR\a");
MightyPork 1:09dfc9fd55f4 155 }
MightyPork 1:09dfc9fd55f4 156
MightyPork 1:09dfc9fd55f4 157
MightyPork 1:09dfc9fd55f4 158 void ESPTerm::set_screen_size(int rows, int cols)
MightyPork 1:09dfc9fd55f4 159 {
MightyPork 1:09dfc9fd55f4 160 ser->printf("\033]W%d;%d\a", rows, cols);
MightyPork 1:09dfc9fd55f4 161 }
MightyPork 4:294e8f53ebcd 162
MightyPork 4:294e8f53ebcd 163
MightyPork 4:294e8f53ebcd 164 bool ESPTerm::query_status(void)
MightyPork 4:294e8f53ebcd 165 {
MightyPork 4:294e8f53ebcd 166 if (device_ok) return true;
MightyPork 4:294e8f53ebcd 167
MightyPork 4:294e8f53ebcd 168 ser->puts("\033[5n");
MightyPork 4:294e8f53ebcd 169 return false;
MightyPork 4:294e8f53ebcd 170 }
MightyPork 4:294e8f53ebcd 171
MightyPork 4:294e8f53ebcd 172
MightyPork 4:294e8f53ebcd 173 // ----- Rx command parsing -----
MightyPork 4:294e8f53ebcd 174
MightyPork 4:294e8f53ebcd 175
MightyPork 4:294e8f53ebcd 176 void ESPTerm::ser_rx_char(void)
MightyPork 4:294e8f53ebcd 177 {
MightyPork 4:294e8f53ebcd 178 while (ser->readable()) {
MightyPork 4:294e8f53ebcd 179 char c = ser->getc();
MightyPork 4:294e8f53ebcd 180 ansi_parser(&c, 1); // pretend as if it was a string, this is safe
MightyPork 4:294e8f53ebcd 181 }
MightyPork 4:294e8f53ebcd 182 }
MightyPork 4:294e8f53ebcd 183
MightyPork 4:294e8f53ebcd 184
MightyPork 4:294e8f53ebcd 185 void ESPTerm::apars_handle_plainchar(char c)
MightyPork 4:294e8f53ebcd 186 {
MightyPork 4:294e8f53ebcd 187 if (c == 24) {
MightyPork 4:294e8f53ebcd 188 if (on_esp_reset) on_esp_reset();
MightyPork 4:294e8f53ebcd 189 }
MightyPork 4:294e8f53ebcd 190 else if (c >= 1 && c <= 5) {
MightyPork 4:294e8f53ebcd 191 if (on_button) on_button((int)c);
MightyPork 4:294e8f53ebcd 192 }
MightyPork 4:294e8f53ebcd 193 else {
MightyPork 4:294e8f53ebcd 194 if (on_char_rx) on_char_rx(c);
MightyPork 4:294e8f53ebcd 195 }
MightyPork 4:294e8f53ebcd 196 }
MightyPork 4:294e8f53ebcd 197
MightyPork 4:294e8f53ebcd 198
MightyPork 4:294e8f53ebcd 199 void ESPTerm::apars_handle_csi(char lead, const int* nums, char keychar)
MightyPork 4:294e8f53ebcd 200 {
MightyPork 4:294e8f53ebcd 201 // Keyboard events
MightyPork 4:294e8f53ebcd 202 if (on_key_press) {
MightyPork 4:294e8f53ebcd 203 if (keychar == 'A') on_key_press(KEY_UP);
MightyPork 4:294e8f53ebcd 204 else if (keychar == 'B') on_key_press(KEY_DOWN);
MightyPork 4:294e8f53ebcd 205 else if (keychar == 'C') on_key_press(KEY_RIGHT);
MightyPork 4:294e8f53ebcd 206 else if (keychar == 'D') on_key_press(KEY_LEFT);
MightyPork 4:294e8f53ebcd 207 }
MightyPork 4:294e8f53ebcd 208
MightyPork 4:294e8f53ebcd 209 // Screen tapped / clicked
MightyPork 4:294e8f53ebcd 210 if (on_mouse_click && keychar == 'M') {
MightyPork 4:294e8f53ebcd 211 on_mouse_click(nums[0], nums[1]);
MightyPork 4:294e8f53ebcd 212 }
MightyPork 4:294e8f53ebcd 213
MightyPork 4:294e8f53ebcd 214 // "Device OK" response to "Device Status Query"
MightyPork 4:294e8f53ebcd 215 if (keychar == 'n' && nums[0] == 0) {
MightyPork 4:294e8f53ebcd 216 device_ok = true;
MightyPork 4:294e8f53ebcd 217 }
MightyPork 4:294e8f53ebcd 218
MightyPork 4:294e8f53ebcd 219 // ... other commands when added
MightyPork 4:294e8f53ebcd 220 }
MightyPork 4:294e8f53ebcd 221
MightyPork 4:294e8f53ebcd 222
MightyPork 4:294e8f53ebcd 223 void ESPTerm::apars_handle_osc(const char *str)
MightyPork 4:294e8f53ebcd 224 {
MightyPork 4:294e8f53ebcd 225 // ... additional parsing when needed in later esp term versions
MightyPork 4:294e8f53ebcd 226 if (on_osc_rx) on_osc_rx(str);
MightyPork 4:294e8f53ebcd 227 }
MightyPork 4:294e8f53ebcd 228
MightyPork 4:294e8f53ebcd 229
MightyPork 4:294e8f53ebcd 230 void ESPTerm::apars_handle_badseq(void)
MightyPork 4:294e8f53ebcd 231 {
MightyPork 4:294e8f53ebcd 232 // Do nothing
MightyPork 4:294e8f53ebcd 233 }
MightyPork 4:294e8f53ebcd 234
MightyPork 4:294e8f53ebcd 235
MightyPork 4:294e8f53ebcd 236
MightyPork 4:294e8f53ebcd 237 /* ----- Ragel constants block ------ */
MightyPork 4:294e8f53ebcd 238
MightyPork 4:294e8f53ebcd 239 /* #line 38 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 240 static const int ansi_start = 1;
MightyPork 4:294e8f53ebcd 241 //static const int ansi_first_final = 7;
MightyPork 4:294e8f53ebcd 242 //static const int ansi_error = 0;
MightyPork 4:294e8f53ebcd 243
MightyPork 4:294e8f53ebcd 244 //static const int ansi_en_CSI_body = 3;
MightyPork 4:294e8f53ebcd 245 //static const int ansi_en_OSC_body = 5;
MightyPork 4:294e8f53ebcd 246 //static const int ansi_en_main = 1;
MightyPork 4:294e8f53ebcd 247
MightyPork 4:294e8f53ebcd 248
MightyPork 4:294e8f53ebcd 249
MightyPork 4:294e8f53ebcd 250 /* Ragel generated parser */
MightyPork 4:294e8f53ebcd 251
MightyPork 4:294e8f53ebcd 252 /**
MightyPork 4:294e8f53ebcd 253 * \brief Linear ANSI chars stream parser (Rage generated)
MightyPork 4:294e8f53ebcd 254 *
MightyPork 4:294e8f53ebcd 255 * Parses a stream of bytes using a Ragel parser. The defined
MightyPork 4:294e8f53ebcd 256 * grammar does not use 'unget', so the entire buffer is
MightyPork 4:294e8f53ebcd 257 * always processed in a linear manner.
MightyPork 4:294e8f53ebcd 258 *
MightyPork 4:294e8f53ebcd 259 * \attention -> but always check the Ragel output for 'p--'
MightyPork 4:294e8f53ebcd 260 * or 'p -=', that means trouble.
MightyPork 4:294e8f53ebcd 261 *
MightyPork 4:294e8f53ebcd 262 * \param newdata - array of new chars to process
MightyPork 4:294e8f53ebcd 263 * \param len - length of the newdata buffer
MightyPork 4:294e8f53ebcd 264 */
MightyPork 4:294e8f53ebcd 265 void ESPTerm::ansi_parser(const char *newdata, size_t len)
MightyPork 4:294e8f53ebcd 266 {
MightyPork 4:294e8f53ebcd 267 if (len == 0) len = strlen(newdata);
MightyPork 4:294e8f53ebcd 268
MightyPork 4:294e8f53ebcd 269 // Load new data to Ragel vars
MightyPork 4:294e8f53ebcd 270 const char *p = newdata;
MightyPork 4:294e8f53ebcd 271 const char *eof = NULL;
MightyPork 4:294e8f53ebcd 272 const char *pe = newdata + len;
MightyPork 4:294e8f53ebcd 273
MightyPork 4:294e8f53ebcd 274 // Init Ragel on the first run
MightyPork 4:294e8f53ebcd 275 if (cs == -1) {
MightyPork 4:294e8f53ebcd 276
MightyPork 4:294e8f53ebcd 277 /* #line 77 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 278 {
MightyPork 4:294e8f53ebcd 279 cs = ansi_start;
MightyPork 4:294e8f53ebcd 280 }
MightyPork 4:294e8f53ebcd 281
MightyPork 4:294e8f53ebcd 282 /* #line 65 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 283 }
MightyPork 4:294e8f53ebcd 284
MightyPork 4:294e8f53ebcd 285 // The parser
MightyPork 4:294e8f53ebcd 286
MightyPork 4:294e8f53ebcd 287 /* #line 87 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 288 {
MightyPork 4:294e8f53ebcd 289 if ( p == pe )
MightyPork 4:294e8f53ebcd 290 goto _test_eof;
MightyPork 4:294e8f53ebcd 291 switch ( cs )
MightyPork 4:294e8f53ebcd 292 {
MightyPork 4:294e8f53ebcd 293 tr0:
MightyPork 4:294e8f53ebcd 294 /* #line 75 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 295 {
MightyPork 4:294e8f53ebcd 296 apars_handle_plainchar((*p));
MightyPork 4:294e8f53ebcd 297 }
MightyPork 4:294e8f53ebcd 298 goto st1;
MightyPork 4:294e8f53ebcd 299 st1:
MightyPork 4:294e8f53ebcd 300 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 301 goto _test_eof1;
MightyPork 4:294e8f53ebcd 302 case 1:
MightyPork 4:294e8f53ebcd 303 /* #line 103 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 304 if ( (*p) == 27 )
MightyPork 4:294e8f53ebcd 305 goto st2;
MightyPork 4:294e8f53ebcd 306 goto tr0;
MightyPork 4:294e8f53ebcd 307 st2:
MightyPork 4:294e8f53ebcd 308 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 309 goto _test_eof2;
MightyPork 4:294e8f53ebcd 310 case 2:
MightyPork 4:294e8f53ebcd 311 switch( (*p) ) {
MightyPork 4:294e8f53ebcd 312 case 91: goto tr3;
MightyPork 4:294e8f53ebcd 313 case 93: goto tr4;
MightyPork 4:294e8f53ebcd 314 }
MightyPork 4:294e8f53ebcd 315 goto tr2;
MightyPork 4:294e8f53ebcd 316 tr2:
MightyPork 4:294e8f53ebcd 317 /* #line 116 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 318 {
MightyPork 4:294e8f53ebcd 319 apars_handle_badseq();
MightyPork 4:294e8f53ebcd 320 {goto st1;}
MightyPork 4:294e8f53ebcd 321 }
MightyPork 4:294e8f53ebcd 322 // goto st0;
MightyPork 4:294e8f53ebcd 323 /* #line 123 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 324 //st0:
MightyPork 4:294e8f53ebcd 325 //cs = 0;
MightyPork 4:294e8f53ebcd 326 // goto _out;
MightyPork 4:294e8f53ebcd 327 tr3:
MightyPork 4:294e8f53ebcd 328 /* #line 82 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 329 {
MightyPork 4:294e8f53ebcd 330 /* Reset the CSI builder */
MightyPork 4:294e8f53ebcd 331 csi_leading = csi_char = 0;
MightyPork 4:294e8f53ebcd 332 csi_ni = 0;
MightyPork 4:294e8f53ebcd 333
MightyPork 4:294e8f53ebcd 334 /* Zero out digits */
MightyPork 4:294e8f53ebcd 335 for(int i = 0; i < CSI_N_MAX; i++) {
MightyPork 4:294e8f53ebcd 336 csi_n[i] = 0;
MightyPork 4:294e8f53ebcd 337 }
MightyPork 4:294e8f53ebcd 338
MightyPork 4:294e8f53ebcd 339 {goto st3;}
MightyPork 4:294e8f53ebcd 340 }
MightyPork 4:294e8f53ebcd 341 //goto st7;
MightyPork 4:294e8f53ebcd 342 tr4:
MightyPork 4:294e8f53ebcd 343 /* #line 129 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 344 {
MightyPork 4:294e8f53ebcd 345 /* Reset the OSC buffer */
MightyPork 4:294e8f53ebcd 346 osc_i = 0;
MightyPork 4:294e8f53ebcd 347 {goto st5;}
MightyPork 4:294e8f53ebcd 348 }
MightyPork 4:294e8f53ebcd 349 //goto st7;
MightyPork 4:294e8f53ebcd 350 //st7:
MightyPork 4:294e8f53ebcd 351 // if ( ++p == pe )
MightyPork 4:294e8f53ebcd 352 // goto _test_eof7;
MightyPork 4:294e8f53ebcd 353 case 7:
MightyPork 4:294e8f53ebcd 354 /* #line 154 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 355 if ( (*p) == 27 )
MightyPork 4:294e8f53ebcd 356 goto st2;
MightyPork 4:294e8f53ebcd 357 goto tr0;
MightyPork 4:294e8f53ebcd 358 st3:
MightyPork 4:294e8f53ebcd 359 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 360 goto _test_eof3;
MightyPork 4:294e8f53ebcd 361 case 3:
MightyPork 4:294e8f53ebcd 362 if ( (*p) == 59 )
MightyPork 4:294e8f53ebcd 363 goto tr7;
MightyPork 4:294e8f53ebcd 364 if ( (*p) < 60 ) {
MightyPork 4:294e8f53ebcd 365 if ( (*p) > 47 ) {
MightyPork 4:294e8f53ebcd 366 if ( 48 <= (*p) && (*p) <= 57 )
MightyPork 4:294e8f53ebcd 367 goto tr6;
MightyPork 4:294e8f53ebcd 368 } else if ( (*p) >= 32 )
MightyPork 4:294e8f53ebcd 369 goto tr5;
MightyPork 4:294e8f53ebcd 370 } else if ( (*p) > 64 ) {
MightyPork 4:294e8f53ebcd 371 if ( (*p) > 90 ) {
MightyPork 4:294e8f53ebcd 372 if ( 97 <= (*p) && (*p) <= 122 )
MightyPork 4:294e8f53ebcd 373 goto tr8;
MightyPork 4:294e8f53ebcd 374 } else if ( (*p) >= 65 )
MightyPork 4:294e8f53ebcd 375 goto tr8;
MightyPork 4:294e8f53ebcd 376 } else
MightyPork 4:294e8f53ebcd 377 goto tr5;
MightyPork 4:294e8f53ebcd 378 goto tr2;
MightyPork 4:294e8f53ebcd 379 tr5:
MightyPork 4:294e8f53ebcd 380 /* #line 95 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 381 {
MightyPork 4:294e8f53ebcd 382 csi_leading = (*p);
MightyPork 4:294e8f53ebcd 383 }
MightyPork 4:294e8f53ebcd 384 goto st4;
MightyPork 4:294e8f53ebcd 385 tr6:
MightyPork 4:294e8f53ebcd 386 /* #line 99 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 387 {
MightyPork 4:294e8f53ebcd 388 /* x10 + digit */
MightyPork 4:294e8f53ebcd 389 if (csi_ni < CSI_N_MAX) {
MightyPork 4:294e8f53ebcd 390 csi_n[csi_ni] = csi_n[csi_ni]*10 + ((*p) - '0');
MightyPork 4:294e8f53ebcd 391 }
MightyPork 4:294e8f53ebcd 392 }
MightyPork 4:294e8f53ebcd 393 goto st4;
MightyPork 4:294e8f53ebcd 394 tr7:
MightyPork 4:294e8f53ebcd 395 /* #line 106 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 396 {
MightyPork 4:294e8f53ebcd 397 csi_ni++;
MightyPork 4:294e8f53ebcd 398 }
MightyPork 4:294e8f53ebcd 399 goto st4;
MightyPork 4:294e8f53ebcd 400 st4:
MightyPork 4:294e8f53ebcd 401 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 402 goto _test_eof4;
MightyPork 4:294e8f53ebcd 403 case 4:
MightyPork 4:294e8f53ebcd 404 /* #line 204 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 405 if ( (*p) == 59 )
MightyPork 4:294e8f53ebcd 406 goto tr7;
MightyPork 4:294e8f53ebcd 407 if ( (*p) < 65 ) {
MightyPork 4:294e8f53ebcd 408 if ( 48 <= (*p) && (*p) <= 57 )
MightyPork 4:294e8f53ebcd 409 goto tr6;
MightyPork 4:294e8f53ebcd 410 } else if ( (*p) > 90 ) {
MightyPork 4:294e8f53ebcd 411 if ( 97 <= (*p) && (*p) <= 122 )
MightyPork 4:294e8f53ebcd 412 goto tr8;
MightyPork 4:294e8f53ebcd 413 } else
MightyPork 4:294e8f53ebcd 414 goto tr8;
MightyPork 4:294e8f53ebcd 415 goto tr2;
MightyPork 4:294e8f53ebcd 416 tr8:
MightyPork 4:294e8f53ebcd 417 /* #line 110 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 418 {
MightyPork 4:294e8f53ebcd 419 csi_char = (*p);
MightyPork 4:294e8f53ebcd 420 apars_handle_csi(csi_leading, csi_n, csi_char);
MightyPork 4:294e8f53ebcd 421 {goto st1;}
MightyPork 4:294e8f53ebcd 422 }
MightyPork 4:294e8f53ebcd 423 // goto st8;
MightyPork 4:294e8f53ebcd 424 //st8:
MightyPork 4:294e8f53ebcd 425 // if ( ++p == pe )
MightyPork 4:294e8f53ebcd 426 // goto _test_eof8;
MightyPork 4:294e8f53ebcd 427 case 8:
MightyPork 4:294e8f53ebcd 428 /* #line 228 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 429 goto tr2;
MightyPork 4:294e8f53ebcd 430 tr9:
MightyPork 4:294e8f53ebcd 431 /* #line 135 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 432 {
MightyPork 4:294e8f53ebcd 433 if (osc_i < OSC_BUF_LEN-1) {
MightyPork 4:294e8f53ebcd 434 osc_buff[osc_i++] = (*p);
MightyPork 4:294e8f53ebcd 435 }
MightyPork 4:294e8f53ebcd 436 }
MightyPork 4:294e8f53ebcd 437 goto st5;
MightyPork 4:294e8f53ebcd 438 st5:
MightyPork 4:294e8f53ebcd 439 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 440 goto _test_eof5;
MightyPork 4:294e8f53ebcd 441 case 5:
MightyPork 4:294e8f53ebcd 442 /* #line 242 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 443 switch( (*p) ) {
MightyPork 4:294e8f53ebcd 444 case 7: goto tr10;
MightyPork 4:294e8f53ebcd 445 case 27: goto st6;
MightyPork 4:294e8f53ebcd 446 }
MightyPork 4:294e8f53ebcd 447 goto tr9;
MightyPork 4:294e8f53ebcd 448 tr10:
MightyPork 4:294e8f53ebcd 449 /* #line 141 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 450 {
MightyPork 4:294e8f53ebcd 451 /** Terminate the buffer */
MightyPork 4:294e8f53ebcd 452 osc_buff[osc_i] = '\0';
MightyPork 4:294e8f53ebcd 453 apars_handle_osc(osc_buff);
MightyPork 4:294e8f53ebcd 454
MightyPork 4:294e8f53ebcd 455 {goto st1;}
MightyPork 4:294e8f53ebcd 456 }
MightyPork 4:294e8f53ebcd 457 // goto st9;
MightyPork 4:294e8f53ebcd 458 //st9:
MightyPork 4:294e8f53ebcd 459 // if ( ++p == pe )
MightyPork 4:294e8f53ebcd 460 // goto _test_eof9;
MightyPork 4:294e8f53ebcd 461 case 9:
MightyPork 4:294e8f53ebcd 462 /* #line 262 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 463 goto tr2;
MightyPork 4:294e8f53ebcd 464 st6:
MightyPork 4:294e8f53ebcd 465 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 466 goto _test_eof6;
MightyPork 4:294e8f53ebcd 467 case 6:
MightyPork 4:294e8f53ebcd 468 if ( (*p) == 92 )
MightyPork 4:294e8f53ebcd 469 goto tr10;
MightyPork 4:294e8f53ebcd 470 goto tr2;
MightyPork 4:294e8f53ebcd 471 }
MightyPork 4:294e8f53ebcd 472 _test_eof1: cs = 1; goto _test_eof;
MightyPork 4:294e8f53ebcd 473 _test_eof2: cs = 2; goto _test_eof;
MightyPork 4:294e8f53ebcd 474 //_test_eof7: cs = 7; goto _test_eof;
MightyPork 4:294e8f53ebcd 475 _test_eof3: cs = 3; goto _test_eof;
MightyPork 4:294e8f53ebcd 476 _test_eof4: cs = 4; goto _test_eof;
MightyPork 4:294e8f53ebcd 477 //_test_eof8: cs = 8; goto _test_eof;
MightyPork 4:294e8f53ebcd 478 _test_eof5: cs = 5; goto _test_eof;
MightyPork 4:294e8f53ebcd 479 //_test_eof9: cs = 9; goto _test_eof;
MightyPork 4:294e8f53ebcd 480 _test_eof6: cs = 6; goto _test_eof;
MightyPork 4:294e8f53ebcd 481
MightyPork 4:294e8f53ebcd 482 _test_eof: {}
MightyPork 4:294e8f53ebcd 483 if ( p == eof )
MightyPork 4:294e8f53ebcd 484 {
MightyPork 4:294e8f53ebcd 485 switch ( cs ) {
MightyPork 4:294e8f53ebcd 486 case 1:
MightyPork 4:294e8f53ebcd 487 case 2:
MightyPork 4:294e8f53ebcd 488 case 3:
MightyPork 4:294e8f53ebcd 489 case 4:
MightyPork 4:294e8f53ebcd 490 case 5:
MightyPork 4:294e8f53ebcd 491 case 6:
MightyPork 4:294e8f53ebcd 492 /* #line 116 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 493 {
MightyPork 4:294e8f53ebcd 494 apars_handle_badseq();
MightyPork 4:294e8f53ebcd 495 {goto st1;}
MightyPork 4:294e8f53ebcd 496 }
MightyPork 4:294e8f53ebcd 497 // break;
MightyPork 4:294e8f53ebcd 498 /* #line 298 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 499 }
MightyPork 4:294e8f53ebcd 500 }
MightyPork 4:294e8f53ebcd 501
MightyPork 4:294e8f53ebcd 502 //_out: {}
MightyPork 4:294e8f53ebcd 503 }
MightyPork 4:294e8f53ebcd 504
MightyPork 4:294e8f53ebcd 505 /* #line 162 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 506
MightyPork 4:294e8f53ebcd 507 }
MightyPork 4:294e8f53ebcd 508
MightyPork 4:294e8f53ebcd 509
MightyPork 4:294e8f53ebcd 510
MightyPork 4:294e8f53ebcd 511
MightyPork 4:294e8f53ebcd 512
MightyPork 4:294e8f53ebcd 513
MightyPork 4:294e8f53ebcd 514
MightyPork 4:294e8f53ebcd 515
MightyPork 4:294e8f53ebcd 516
MightyPork 4:294e8f53ebcd 517
MightyPork 4:294e8f53ebcd 518
MightyPork 4:294e8f53ebcd 519
MightyPork 4:294e8f53ebcd 520
MightyPork 4:294e8f53ebcd 521
MightyPork 4:294e8f53ebcd 522
MightyPork 4:294e8f53ebcd 523
MightyPork 4:294e8f53ebcd 524
MightyPork 4:294e8f53ebcd 525
MightyPork 4:294e8f53ebcd 526
MightyPork 4:294e8f53ebcd 527