ESP8266-based WiFi serial modem emulator ROM
0
fork

Configure Feed

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

Serial: Hangup when DTR drops for 1.75 seconds

Unify on *_start() and *_stop() module names

+52 -30
+15
ppp.cpp
··· 74 74 } 75 75 76 76 void 77 + ppp_stop(bool wait) 78 + { 79 + unsigned long now = millis(); 80 + 81 + ppp_close(_ppp, 0); 82 + 83 + if (wait) { 84 + while (state == STATE_PPP && now - millis() < 1000) { 85 + pppos_input(_ppp, ppp_buf, 0); 86 + yield(); 87 + } 88 + } 89 + } 90 + 91 + void 77 92 ppp_process(void) 78 93 { 79 94 size_t bytes;
+2 -4
serial.cpp
··· 17 17 18 18 #include "wifippp.h" 19 19 20 - bool serial_alive = true; 21 - 22 20 void 23 21 serial_setup(void) 24 22 { 25 23 /* DCE mode, acting as a modem */ 26 24 27 - serial_begin(settings->baud); 25 + serial_start(settings->baud); 28 26 29 27 pinMode(pRI, OUTPUT); 30 28 serial_ri(false); ··· 44 42 } 45 43 46 44 void 47 - serial_begin(int baud) 45 + serial_start(int baud) 48 46 { 49 47 Serial.begin(baud); 50 48 }
+3 -5
util.cpp
··· 162 162 int 163 163 output(char c) 164 164 { 165 - if (serial_alive) { 166 - serial_write(c); 167 - if (c == '\n') 168 - serial_flush(); 169 - } 165 + serial_write(c); 166 + if (c == '\n') 167 + serial_flush(); 170 168 171 169 return 0; 172 170 }
+2 -2
wifippp.h
··· 81 81 /* ppp.cpp */ 82 82 bool ppp_start(void); 83 83 void ppp_process(void); 84 + void ppp_stop(bool wait); 84 85 85 86 /* serial.cpp */ 86 87 void serial_setup(void); 87 - void serial_begin(int baud); 88 + void serial_start(int baud); 88 89 uint8_t serial_read(void); 89 90 bool serial_available(void); 90 91 int16_t serial_peek(void); ··· 125 126 126 127 /* wifippp.ino */ 127 128 void exec_cmd(char *cmd, size_t len); 128 - extern bool serial_alive; 129 129 130 130 #endif
+30 -19
wifippp.ino
··· 35 35 static unsigned int lastcmdlen = 0; 36 36 static int plusses = 0; 37 37 static unsigned long plus_wait = 0; 38 - static bool dtr = false; 38 + static unsigned long last_dtr = 0; 39 39 40 40 void 41 41 loop(void) 42 42 { 43 43 int b = -1, i; 44 44 long now = millis(); 45 + bool hangup = false; 45 46 46 47 socks_process(); 47 48 49 + if (serial_dtr()) { 50 + if (!last_dtr) 51 + /* new connection, re-autobaud */ 52 + serial_autobaud(); 53 + last_dtr = now; 54 + } else if (last_dtr && (now - last_dtr > 1750)) { 55 + /* dropped DTR for 1.75 secs, hangup */ 56 + hangup = true; 57 + last_dtr = 0; 58 + syslog.log(LOG_INFO, "dropped DTR, hanging up"); 59 + } else if (!last_dtr) 60 + return; 61 + 48 62 switch (state) { 49 63 case STATE_AT: 50 - if (!serial_dtr()) { 51 - dtr = false; 52 - return; 53 - } 54 - 55 - if (!dtr) { 56 - serial_autobaud(); 57 - dtr = true; 58 - } 59 - 60 - if (serial_available() && (b = serial_read())) 61 - serial_alive = true; 62 - else 64 + if (!(serial_available() && (b = serial_read()))) 63 65 return; 64 66 65 67 /* USR modem mode, ignore input not starting with at or a/ */ ··· 122 124 case STATE_TELNET: 123 125 b = -1; 124 126 125 - if (serial_available() && (b = serial_read())) 126 - serial_alive = true; 127 + if (hangup) { 128 + telnet_disconnect(); 129 + break; 130 + } 131 + 132 + if (serial_available()) 133 + b = serial_read(); 127 134 128 135 if (b == -1 && plus_wait > 0 && (millis() - plus_wait) >= 500) { 129 136 /* received no input within 500ms of a plus */ ··· 160 167 } 161 168 162 169 if ((b = telnet_read()) != -1) { 163 - if (serial_alive) 164 - serial_write(b); 170 + serial_write(b); 165 171 return; 166 172 } else if (!telnet_connected()) { 167 173 if (!settings->quiet) { ··· 175 181 } 176 182 break; 177 183 case STATE_PPP: 184 + if (hangup) { 185 + ppp_stop(true); 186 + break; 187 + } 188 + 178 189 ppp_process(); 179 190 break; 180 191 } ··· 666 677 output("0\r"); 667 678 } 668 679 serial_flush(); 669 - serial_begin(settings->baud); 680 + serial_start(settings->baud); 670 681 break; 671 682 default: 672 683 output("ERROR unsupported baud rate\r\n");