ESP8266-based WiFi serial modem emulator ROM
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

AT handling: Do DTR processing as advisory, not required

Just remember if we had DTR during the call and if it drops, hangup,
but don't require DTR to talk.

If we get non-ASCII garbage at the start of a connection, assume
it's a new connection (without DTR) sending stuff to us at the wrong
baud rate and perform an autobaud.

Shrink cur/lastcmd buffers to save a bit of memory.

+22 -9
+22 -9
wifippp.ino
··· 29 29 30 30 uint8_t state = STATE_AT; 31 31 32 - static char curcmd[128] = { 0 }; 33 - static char lastcmd[128] = { 0 }; 32 + static char curcmd[64] = { 0 }; 33 + static char lastcmd[64] = { 0 }; 34 34 static unsigned int curcmdlen = 0; 35 35 static unsigned int lastcmdlen = 0; 36 36 static int plusses = 0; 37 37 static unsigned long plus_wait = 0; 38 38 static unsigned long last_dtr = 0; 39 + static unsigned long last_autobaud = 0; 39 40 40 41 void 41 42 loop(void) ··· 47 48 socks_process(); 48 49 49 50 if (serial_dtr()) { 50 - if (!last_dtr) 51 + if (!last_dtr) { 51 52 /* new connection, re-autobaud */ 53 + syslog.logf(LOG_DEBUG, "new connection with DTR, " 54 + "doing auto-baud"); 52 55 serial_autobaud(); 56 + now = millis(); 57 + last_autobaud = now; 58 + } 53 59 last_dtr = now; 54 60 } else if (last_dtr && (now - last_dtr > 1750)) { 55 - /* dropped DTR for 1.75 secs, hangup */ 61 + /* had DTR, dropped it for 1.75 secs, hangup */ 56 62 hangup = true; 57 63 last_dtr = 0; 58 64 syslog.log(LOG_INFO, "dropped DTR, hanging up"); 59 - } else if (!last_dtr) 60 - return; 65 + } 61 66 62 67 switch (state) { 63 68 case STATE_AT: ··· 66 71 67 72 /* USR modem mode, ignore input not starting with at or a/ */ 68 73 if (curcmdlen == 0 && (b != 'A' && b != 'a')) { 74 + if (b > 127 && (now - last_autobaud > 2000)) { 75 + serial_autobaud(); 76 + now = millis(); 77 + last_autobaud = now; 78 + } 69 79 return; 70 - } else if (curcmdlen == 1 && b == '/') { 80 + } 81 + 82 + if (curcmdlen == 1 && b == '/') { 71 83 if (settings->echo) 72 84 output("/\r"); 73 85 curcmd[0] = '\0'; ··· 358 370 359 371 telnet_disconnect(); 360 372 if (ppp_start()) 361 - /* ppp_start outputs CONNECT line, since it has 373 + /* ppp_begin outputs CONNECT line, since it has 362 374 * to do so before calling ppp_listen */ 363 375 state = STATE_PPP; 364 376 else if (!settings->quiet) { ··· 375 387 if (!settings->quiet) { 376 388 if (settings->verbal) 377 389 outputf("CONNECT %d %s:%d\r\n", 378 - settings->baud, host, port); 390 + Serial.baudRate(), host, 391 + port); 379 392 else 380 393 output("18\r"); /* 57600 */ 381 394 }