mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-27 22:31:24 +01:00
More PROGMEM tuning
This commit is contained in:
parent
8538aa1624
commit
506f9e4353
4
Config.h
4
Config.h
@ -2,8 +2,8 @@
|
||||
#define Config_h
|
||||
|
||||
const int WIFI_PORT = 99; // OR set to zero for no wifi
|
||||
const char WIFI_SSID[] = "BTHub5-M6PT"; // your network SSID (name)
|
||||
const char WIFI_PASS[] = "49de8d4862"; // your network password
|
||||
const char WIFI_SSID[] PROGMEM = "BTHub5-M6PT"; // your network SSID (name)
|
||||
const char WIFI_PASS[] PROGMEM = "49de8d4862"; // your network password
|
||||
const long WIFI_BAUD_RATE=115200;
|
||||
|
||||
const long SERIAL_BAUD_RATE=115200;
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "EEStore.h"
|
||||
#include "DIAG.h"
|
||||
|
||||
const char VERSION[]="99.666";
|
||||
const char VERSION[] PROGMEM ="99.666";
|
||||
|
||||
int DCCEXParser::stashP[MAX_PARAMS];
|
||||
bool DCCEXParser::stashBusy;
|
||||
@ -178,7 +178,7 @@ void DCCEXParser::parse(Print & stream, const char *com) {
|
||||
|
||||
case 's': // <s>
|
||||
StringFormatter::send(stream,F("<p%d>"),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON );
|
||||
StringFormatter::send(stream,F("<iDCC-Asbelos BASE STATION FOR ARDUINO / %s: V-%s %s/%s>"), BOARD_NAME, VERSION, __DATE__, __TIME__ );
|
||||
StringFormatter::send(stream,F("<iDCC-Asbelos BASE STATION FOR ARDUINO / %S: V-%S %s/%s>"), BOARD_NAME, VERSION, __DATE__, __TIME__ );
|
||||
// TODO Send stats of speed reminders table
|
||||
// TODO send status of turnouts etc etc
|
||||
return;
|
||||
|
@ -31,5 +31,5 @@ struct DCCEXParser
|
||||
|
||||
};
|
||||
|
||||
#define BOARD_NAME "not yet configured"
|
||||
#define BOARD_NAME F("not yet configured")
|
||||
#endif
|
||||
|
@ -87,7 +87,7 @@ void DCCWaveform::checkPowerOverload() {
|
||||
if (lastCurrent < POWER_SAMPLE_MAX) delay = POWER_SAMPLE_ON_WAIT;
|
||||
else {
|
||||
setPowerMode(POWERMODE::OVERLOAD);
|
||||
DIAG(F("\n*** %s TRACK POWER OVERLOAD current=%d max=%d ***\n"), isMainTrack ? "MAIN" : "PROG", lastCurrent, POWER_SAMPLE_MAX);
|
||||
DIAG(F("\n*** %S TRACK POWER OVERLOAD current=%d max=%d ***\n"), isMainTrack ? F("MAIN") : F("PROG"), lastCurrent, POWER_SAMPLE_MAX);
|
||||
delay = POWER_SAMPLE_OVERLOAD_WAIT;
|
||||
}
|
||||
break;
|
||||
|
@ -139,7 +139,7 @@ void Sensor::show(Print & stream){
|
||||
|
||||
void Sensor::status(Print & stream){
|
||||
for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){
|
||||
StringFormatter::send(stream,F("<%s %d>"), tt->active?"Q":"q", tt->data.snum);
|
||||
StringFormatter::send(stream,F("<%c %d>"), tt->active?'Q':'q', tt->data.snum);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ void StringFormatter::send(Print & stream,const __FlashStringHelper* format, va_
|
||||
case '%': stream.print('%'); break;
|
||||
case 'c': stream.print((char) va_arg(args, int)); break;
|
||||
case 's': stream.print(va_arg(args, char*)); break;
|
||||
case 'S': stream.print((const __FlashStringHelper*)va_arg(args, char*)); break;
|
||||
case 'd': stream.print(va_arg(args, int), DEC); break;
|
||||
case 'b': stream.print(va_arg(args, int), BIN); break;
|
||||
case 'o': stream.print(va_arg(args, int), OCT); break;
|
||||
|
@ -4,8 +4,10 @@
|
||||
#include "StringFormatter.h"
|
||||
|
||||
|
||||
const char READY_SEARCH[]="\r\nready\r\n";
|
||||
const char OK_SEARCH[]="\r\nOK\r\n";
|
||||
const char PROGMEM READY_SEARCH[] ="\r\nready\r\n";
|
||||
const char PROGMEM OK_SEARCH[] ="\r\nOK\r\n";
|
||||
const char PROGMEM END_DETAIL_SEARCH[] ="@ 1000";
|
||||
const char PROGMEM PROMPT_SEARCH[] =">";
|
||||
|
||||
bool WifiInterface::connected=false;
|
||||
DCCEXParser WifiInterface::parser;
|
||||
@ -19,7 +21,7 @@ void WifiInterface::setup() {
|
||||
DIAG(F("\n++++++ Wifi Setup In Progress ++++++++\n"));
|
||||
connected=setup2();
|
||||
// TODO calloc the buffer and streamer and parser etc
|
||||
DIAG(F("\n++++++ Wifi Setup %s ++++++++\n"), connected?"OK":"FAILED");
|
||||
DIAG(F("\n++++++ Wifi Setup %S ++++++++\n"), connected?F("OK"):F("FAILED"));
|
||||
}
|
||||
|
||||
bool WifiInterface::setup2()
|
||||
@ -29,38 +31,39 @@ bool WifiInterface::setup2()
|
||||
delay(1000);
|
||||
|
||||
StringFormatter::send(Serial1,F("AT+RST\r\n")); // reset module
|
||||
if (!checkForOK(10000,READY_SEARCH)) return false;
|
||||
checkForOK(5000,END_DETAIL_SEARCH,true); // Show startup but ignore unreadable upto ready
|
||||
if (!checkForOK(5000,READY_SEARCH,false)) return false;
|
||||
|
||||
StringFormatter::send(Serial1,F("AT+CWMODE=1\r\n")); // configure as access point
|
||||
if (!checkForOK(10000,OK_SEARCH)) return false;
|
||||
if (!checkForOK(10000,OK_SEARCH,true)) return false;
|
||||
|
||||
StringFormatter::send(Serial1,F("AT+CWJAP=\"%s\",\"%s\"\r\n"),WIFI_SSID,WIFI_PASS);
|
||||
if (!checkForOK(20000,OK_SEARCH)) return false;
|
||||
StringFormatter::send(Serial1,F("AT+CWJAP=\"%S\",\"%S\"\r\n"),WIFI_SSID,WIFI_PASS);
|
||||
if (!checkForOK(20000,OK_SEARCH,true)) return false;
|
||||
|
||||
StringFormatter::send(Serial1,F("AT+CIFSR\r\n")); // get ip address //192.168.4.1
|
||||
if (!checkForOK(10000,OK_SEARCH)) return false;
|
||||
if (!checkForOK(10000,OK_SEARCH,true)) return false;
|
||||
|
||||
StringFormatter::send(Serial1,F("AT+CIPMUX=1\r\n")); // configure for multiple connections
|
||||
if (!checkForOK(10000,OK_SEARCH)) return false;
|
||||
if (!checkForOK(10000,OK_SEARCH,true)) return false;
|
||||
|
||||
StringFormatter::send(Serial1,F("AT+CIPSERVER=1,%d\r\n"),WIFI_PORT); // turn on server on port 80
|
||||
if (!checkForOK(10000,OK_SEARCH)) return false;
|
||||
if (!checkForOK(10000,OK_SEARCH,true)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WifiInterface::checkForOK( const int timeout,char * search) {
|
||||
bool WifiInterface::checkForOK( const int timeout, const char * waitfor, bool echo) {
|
||||
long int time = millis()+timeout;
|
||||
byte locator=0;
|
||||
DIAG(F("\nWifi setup Check:"),search);
|
||||
char *locator=waitfor;
|
||||
DIAG(F("\nWifi setup Check: %S\n"),waitfor);
|
||||
while( time > millis()) {
|
||||
while(Serial1.available()) {
|
||||
int ch=Serial1.read();
|
||||
Serial.write(ch);
|
||||
if (ch!=search[locator]) locator=0;
|
||||
if (ch==search[locator]){
|
||||
if (echo) Serial.write(ch);
|
||||
if (ch!=pgm_read_byte_near(locator)) locator=waitfor;
|
||||
if (ch==pgm_read_byte_near(locator)) {
|
||||
locator++;
|
||||
if (!search[locator]) {
|
||||
if (!pgm_read_byte_near(locator)) {
|
||||
DIAG(F("\nOK after %dms\n"),millis()-time+timeout);
|
||||
return true;
|
||||
}
|
||||
@ -127,7 +130,7 @@ void WifiInterface::loop() {
|
||||
if (streamer.available()) { // there is a reply to send
|
||||
StringFormatter::send(Serial1,F("AT+CIPSEND=%d,%d\r\n"),connectionId,streamer.available());
|
||||
streamer.write('\0');
|
||||
if (checkForOK(1000,">")) Serial1.print((char *) buffer);
|
||||
if (checkForOK(1000,PROMPT_SEARCH,true)) Serial1.print((char *) buffer);
|
||||
}
|
||||
loopstate=0; // go back to looking for +IPD
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#define WifiInterface_h
|
||||
#include "DCCEXParser.h"
|
||||
#include "MemStream.h"
|
||||
#include <Arduino.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
class WifiInterface {
|
||||
|
||||
@ -13,7 +15,7 @@ class WifiInterface {
|
||||
private:
|
||||
static DCCEXParser parser;
|
||||
static bool setup2();
|
||||
static bool checkForOK(const int timeout, char * search);
|
||||
static bool checkForOK( const int timeout, const char* waitfor, bool echo);
|
||||
static bool connected;
|
||||
static byte loopstate;
|
||||
static int datalength;
|
||||
|
Loading…
Reference in New Issue
Block a user