Merge branch 'p8' (pull request #8) into devel

This commit is contained in:
Hansi, dl9rdz 2019-05-03 13:34:35 +02:00
commit 7cf4b116a6
4 changed files with 83 additions and 59 deletions

View File

@ -102,10 +102,12 @@ void setupChannelList() {
return;
}
int i = 0;
char launchsite[17];
sonde.clearSonde();
Serial.println("Reading channel config:");
while (file.available()) {
String line = file.readStringUntil('\n');
String sitename;
if (!file.available()) break;
if (line[0] == '#') continue;
char *space = strchr(line.c_str(), ' ');
@ -124,24 +126,37 @@ void setupChannelList() {
}
else continue;
int active = space[3] == '+' ? 1 : 0;
char *launchsite = strchr(line.c_str(), ' ');
Serial.printf("Add %f - type %d (on/off: %d)- Site: \n", freq, type, active, launchsite);
if (space[4] == ' ') {
sitename = line.substring(12) + " "; // Don't change start of substr(12) !!!!
int str_len = sitename.length() + 1;
sitename.toCharArray(launchsite, 17);
if (sonde.config.debug == 1) {
Serial.printf("Add %f - sondetype: %d (on/off: %d) - site #%d - name: %s\n ", freq, type, active, i, launchsite);
//Serial.println(sitename);
}
}
sonde.addSonde(freq, type, active, launchsite);
i++;
}
file.close();
}
const char *createQRGForm() {
char *ptr = message;
strcpy(ptr, "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"></head><body><form action=\"qrg.html\" method=\"post\"><table><tr><th>ID</th><th>Active</th><th>Freq</th><th>Mode</th></tr>");
strcpy(ptr, "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"></head><body><form action=\"qrg.html\" method=\"post\"><table><tr><th>ID</th><th>Active</th><th>Freq</th><th>Launchsite</th><th>Mode</th></tr>");
for (int i = 0; i < sonde.config.maxsonde; i++) {
String s = sondeTypeSelect(i >= sonde.nSonde ? 2 : sonde.sondeList[i].type);
String site = sonde.sondeList[i].launchsite;
sprintf(ptr + strlen(ptr), "<tr><td>%d</td><td><input name=\"A%d\" type=\"checkbox\" %s/></td>"
"<td><input name=\"F%d\" type=\"text\" value=\"%3.3f\"></td>"
"<td><input name=\"S%d\" type=\"text\" value=\"%s\"></td>"
"<td><select name=\"T%d\">%s</select></td>",
i + 1,
i + 1, (i < sonde.nSonde && sonde.sondeList[i].active) ? "checked" : "",
i + 1, i >= sonde.nSonde ? 400.000 : sonde.sondeList[i].freq,
i + 1, i >= sonde.nSonde ? " " : sonde.sondeList[i].launchsite,
i + 1, s.c_str());
}
strcat(ptr, "</table><input type=\"submit\" value=\"Update\"/></form></body></html>");
@ -152,8 +167,8 @@ const char *handleQRGPost(AsyncWebServerRequest *request) {
char label[10];
// parameters: a_i, f_1, t_i (active/frequency/type)
#if 1
File f = SPIFFS.open("/qrg.txt", "w");
if (!f) {
File file = SPIFFS.open("/qrg.txt", "w");
if (!file) {
Serial.println("Error while opening '/qrg.txt' for writing");
return "Error while opening '/qrg.txt' for writing";
}
@ -171,22 +186,27 @@ const char *handleQRGPost(AsyncWebServerRequest *request) {
AsyncWebParameter *active = request->getParam(label, true);
snprintf(label, 10, "F%d", i);
AsyncWebParameter *freq = request->getParam(label, true);
snprintf(label, 10, "S%d", i);
AsyncWebParameter *launchsite = request->getParam(label, true);
if (!freq) continue;
snprintf(label, 10, "T%d", i);
AsyncWebParameter *type = request->getParam(label, true);
if (!type) continue;
String fstring = freq->value();
String tstring = type->value();
String sstring = launchsite->value();
const char *fstr = fstring.c_str();
const char *tstr = tstring.c_str();
Serial.printf("Processing a=%s, f=%s, t=%s\n", active ? "YES" : "NO", fstr, tstr);
const char *sstr = sstring.c_str();
Serial.printf("Processing a=%s, f=%s, t=%s, site=%s\n", active ? "YES" : "NO", fstr, tstr, sstr);
char typech = (tstr[2] == '4' ? '4' : tstr[3]); // Ugly TODO
f.printf("%3.3f %c %c\n", atof(fstr), typech, active ? '+' : '-');
file.printf("%3.3f %c %c %s\n", atof(fstr), typech, active ? '+' : '-', sstr);
}
f.close();
file.close();
Serial.println("Channel setup finished");
Serial.println();
delay(500);
setupChannelList();
}
@ -562,9 +582,13 @@ int fetchWifiIndex(const char *id) {
int len = strlen(cfgid);
if (strlen(id) > len) len = strlen(id);
Serial.print("SSID: ");
for(int i = 0; i < len; i++) { Serial.printf("%02x ", id[i]); } Serial.println("");
for (int i = 0; i < len; i++) {
Serial.printf("%02x ", id[i]);
} Serial.println("");
Serial.print("Conf: ");
for(int i = 0; i < len; i++) { Serial.printf("%02x ", cfgid[i]); } Serial.println("");
for (int i = 0; i < len; i++) {
Serial.printf("%02x ", cfgid[i]);
} Serial.println("");
}
return -1;
}
@ -719,7 +743,6 @@ void setup()
}
// == show initial values from config.txt ========================= //
#if 0
// == check the radio chip by setting default frequency =========== //
if (rs41.setFrequency(402700000) == 0) {
@ -1420,6 +1443,7 @@ void execOTA() {
enterMode(ST_DECODER);
}
void loop() {
Serial.print("Running main loop. free heap:");
Serial.println(ESP.getFreeHeap());

View File

@ -15,7 +15,7 @@ oled_rst=16
# General config settings
#-------------------------------#
maxsonde=20
debug=0
debug=1
# wifi mode: 1=client in background; 2=AP in background; 3=client on startup, ap if failure
wifi=3
#-------------------------------#

View File

@ -197,7 +197,7 @@ void Sonde::addSonde(float frequency, SondeType type, int active, char *launchsi
sondeList[nSonde].type = type;
sondeList[nSonde].freq = frequency;
sondeList[nSonde].active = active;
sondeList[nSonde].launchsite = launchsite;
strncpy(sondeList[nSonde].launchsite, launchsite, 17);
memcpy(sondeList[nSonde].rxStat, "\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3", 18); // unknown/undefined
nSonde++;
}
@ -334,8 +334,8 @@ void Sonde::updateDisplayScanner() {
u8x8->drawString(8, 0, sondeTypeStr[si()->type]);
snprintf(buf, 16, "%3.3f MHz", si()->freq);
u8x8->drawString(0,3, buf);
//snprintf(buf, 8, "%s", si()->launchsite);
//u8x8->drawString(0,5, buf);
snprintf(buf, 16, "%s", si()->launchsite);
u8x8->drawString(0,5, buf);
updateDisplayIP();
}

View File

@ -43,7 +43,7 @@ typedef struct st_sondeinfo {
// decoded ID
char id[10];
bool validID;
char *launchsite;
char launchsite[18];
// decoded position
float lat; // latitude
float lon; // longitude