ESP8266-based WiFi serial modem emulator ROM

Shrink some code

+36 -77
+1 -1
pixel.cpp
··· 20 20 21 21 Adafruit_NeoPixel pixel(1, pPixel, NEO_GRB + NEO_KHZ800); 22 22 static uint32_t cur_color = 0; 23 - static int wifi_status = WL_DISCONNECTED; 23 + static char wifi_status = WL_DISCONNECTED; 24 24 25 25 void 26 26 pixel_setup(void)
+21 -65
ppp.cpp
··· 76 76 77 77 #ifdef PPP_TRACE 78 78 long elap = millis(); 79 - syslog.logf(LOG_DEBUG, "forwarded %ld PPP bytes in %ldms", len, 79 + syslog.logf(LOG_DEBUG, "forwarded %ld PPP bytes out in %ldms", len, 80 80 elap - now); 81 81 #endif 82 82 ··· 105 105 ppp_process(void) 106 106 { 107 107 size_t bytes; 108 + #ifdef PPP_TRACE 109 + long now = millis(); 110 + #endif 108 111 109 112 if (state != STATE_PPP) { 110 113 syslog.logf(LOG_ERR, "%s but state is %d!", __func__, state); ··· 120 123 121 124 bytes = Serial.readBytes(ppp_buf, bytes); 122 125 pppos_input(_ppp, ppp_buf, bytes); 126 + 127 + #ifdef PPP_TRACE 128 + long elap = millis(); 129 + syslog.logf(LOG_DEBUG, "processed %zu PPP bytes in %ldms", bytes, 130 + elap - now); 131 + #endif 123 132 } 124 133 125 134 void ··· 130 139 switch (err) { 131 140 case PPPERR_NONE: 132 141 ppp_setup_nat(nif); 133 - #ifdef PPP_TRACE 134 142 syslog.logf(LOG_DEBUG, "PPP session established, free mem %d", 135 143 ESP.getFreeHeap()); 136 - #endif 137 - break; 138 - case PPPERR_PARAM: 139 - /* Invalid parameter. */ 140 - syslog.logf(LOG_ERR, "%s: PPPERR_PARAM", __func__); 141 - break; 142 - case PPPERR_OPEN: 143 - /* Unable to open PPP session. */ 144 - syslog.logf(LOG_ERR, "%s: PPPERR_OPEN", __func__); 145 - break; 146 - case PPPERR_DEVICE: 147 - /* Invalid I/O device for PPP. */ 148 - syslog.logf(LOG_ERR, "%s: PPPERR_DEVICE", __func__); 149 - break; 150 - case PPPERR_ALLOC: 151 - /* Unable to allocate resources. */ 152 - syslog.logf(LOG_ERR, "%s: PPPERR_ALLOC", __func__); 153 - break; 154 - case PPPERR_USER: 155 - /* User interrupt. */ 156 - #ifdef PPP_TRACE 157 - syslog.logf(LOG_ERR, "%s: PPPERR_USER", __func__); 158 - #endif 159 - break; 160 - case PPPERR_CONNECT: 161 - /* Connection lost. */ 162 - syslog.logf(LOG_ERR, "%s: PPPERR_CONNECT", __func__); 163 - break; 164 - case PPPERR_AUTHFAIL: 165 - /* Failed authentication challenge. */ 166 - syslog.logf(LOG_ERR, "%s: PPPERR_AUTHFAIL", __func__); 167 - break; 168 - case PPPERR_PROTOCOL: 169 - /* Failed to meet protocol. */ 170 - syslog.logf(LOG_ERR, "%s: PPPERR_PROTOCOL", __func__); 171 - break; 172 - case PPPERR_PEERDEAD: 173 - /* Connection timeout. */ 174 - syslog.logf(LOG_ERR, "%s: PPPERR_PEERDEAD", __func__); 175 - break; 176 - case PPPERR_IDLETIMEOUT: 177 - /* Idle Timeout. */ 178 - syslog.logf(LOG_ERR, "%s: PPPERR_IDLETIMEOUT", __func__); 179 - break; 180 - case PPPERR_CONNECTTIME: 181 - /* Max connect time reached. */ 182 - syslog.logf(LOG_ERR, "%s: PPPERR_CONNECTTIME", __func__); 183 - break; 184 - case PPPERR_LOOPBACK: 185 - /* Connection timeout. */ 186 - syslog.logf(LOG_ERR, "%s: PPPERR_LOOPBACK", __func__); 187 - break; 188 - default: 189 - syslog.logf(LOG_ERR, "%s: unknown error %d", __func__, err); 190 - break; 191 - } 192 - 193 - if (err == PPPERR_NONE) 194 144 return; 195 - 196 - if (err == PPPERR_USER) { 145 + case PPPERR_USER: 197 146 #ifdef PPP_TRACE 198 147 syslog.log(LOG_DEBUG, "ending PPP session, " 199 148 "returning to AT mode"); ··· 204 153 serial_dcd(false); 205 154 outputf("\r\nNO CARRIER\r\n"); 206 155 return; 207 - } 156 + default: 157 + #ifndef PPP_TRACE 158 + if (err == PPPERR_USER) 159 + break; 160 + #endif 161 + syslog.logf(LOG_ERR, "%s: err %d", __func__, err); 208 162 209 163 #ifdef PPP_TRACE 210 - syslog.log(LOG_DEBUG, "closing PPP session"); 164 + syslog.log(LOG_DEBUG, "closing PPP session"); 211 165 #endif 212 - ppp_close(_ppp, 0); 166 + ppp_close(_ppp, 0); 167 + break; 168 + } 213 169 } 214 170 215 171 void
+1 -1
socks.cpp
··· 25 25 WiFiServer socks_server(SOCKS_PORT); 26 26 27 27 #define MAX_SOCKS_CLIENTS 5 28 - SocksClient *socks_clients[MAX_SOCKS_CLIENTS] = { nullptr }; 28 + static SocksClient *socks_clients[MAX_SOCKS_CLIENTS] = { nullptr }; 29 29 30 30 void 31 31 socks_setup(void)
+1 -1
telnet.cpp
··· 20 20 WiFiClient telnet; 21 21 22 22 enum { 23 - TELNET_STATE_DISCONNECTED, 23 + TELNET_STATE_DISCONNECTED = 1, 24 24 TELNET_STATE_CONNECTED, 25 25 TELNET_STATE_IAC, 26 26 TELNET_STATE_IAC_SB,
+3 -2
update.cpp
··· 263 263 * Just force serial output here rather than using outputf, 264 264 * don't let it block us. 265 265 */ 266 - Serial.printf("\rFlash update progress:% 7d of %d", progress, 267 - total); 266 + if (progress == 1 || progress % 1024 == 0 || progress == total) 267 + Serial.printf("\rFlash update progress:% 7d of %d", 268 + progress, total); 268 269 }); 269 270 270 271 if ((int)Update.writeStream((tls ? client_tls : client)) != bytesize) {
+1 -1
util.cpp
··· 26 26 setup(void) 27 27 { 28 28 static_assert(sizeof(struct eeprom_data) < EEPROM_SIZE, 29 - "EEPROM_SIZE is not large enough to hold struct eeprom_data"); 29 + "EEPROM_SIZE < sizeof(struct eeprom_data)"); 30 30 31 31 EEPROM.begin(EEPROM_SIZE); 32 32 settings = (struct eeprom_data *)EEPROM.getDataPtr();
-2
wifippp.h
··· 86 86 const int pDTR = 14; 87 87 const int pDCD = 16; 88 88 89 - 90 89 /* still need to map out */ 91 90 const int pCTS = 0; //15, but responds weirdly when used 92 91 const int pRTS = 0; 93 92 const int pRI = 0; 94 - 95 93 96 94 /* pixel.cpp */ 97 95 void pixel_setup(void);
+8 -4
wifippp.ino
··· 27 27 28 28 #include "wifippp.h" 29 29 30 + #define AUTOBAUD 31 + 30 32 uint8_t state = STATE_AT; 31 33 32 34 static char curcmd[64] = { 0 }; 33 35 static char lastcmd[64] = { 0 }; 34 - static unsigned int curcmdlen = 0; 35 - static unsigned int lastcmdlen = 0; 36 - static int plusses = 0; 36 + static unsigned char curcmdlen = 0; 37 + static unsigned char lastcmdlen = 0; 38 + static unsigned char plusses = 0; 37 39 static unsigned long plus_wait = 0; 38 40 static unsigned long last_dtr = 0; 39 41 static unsigned long last_autobaud = 0; ··· 463 465 did_nl = true; 464 466 break; 465 467 case 2: 466 - /* ATI2: test RAM (not used) */ 468 + /* ATI2: test RAM (show ram info) */ 469 + outputf("\nFree heap: %d\r\n", ESP.getFreeHeap()); 470 + did_nl = true; 467 471 break; 468 472 case 4: { 469 473 /* ATI4: show settings */