code reorg and cleanup, no new features

pull/158/head
Hansi, dl9rdz 2021-09-12 16:34:54 +02:00
rodzic d35836366a
commit 3f2947bb0f
46 zmienionych plików z 120 dodań i 1063 usunięć

Wyświetl plik

@ -1,32 +1,32 @@
#include <axp20x.h>
#include "features.h"
#include "version.h"
#include "axp20x.h"
#include <WiFi.h>
#include <WiFiUdp.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFS.h>
//#include <U8x8lib.h>
//#include <U8g2lib.h>
#include <SPI.h>
#include <Update.h>
#include <ESPmDNS.h>
#include <MicroNMEA.h>
#include <Ticker.h>
#include <SX1278FSK.h>
#include <Sonde.h>
#include <Display.h>
#include <Scanner.h>
#include <aprs.h>
#include "version.h"
#include "geteph.h"
#include "rs92gps.h"
#if FEATURE_MQTT
#include "mqtt.h"
#endif
#include "esp_heap_caps.h"
#include "src/SX1278FSK.h"
#include "src/Sonde.h"
#include "src/Display.h"
#include "src/Scanner.h"
#include "src/geteph.h"
#include "src/rs92gps.h"
#include "src/aprs.h"
#if FEATURE_MQTT
#include "src/mqtt.h"
#endif
//#define ESP_MEM_DEBUG 1
int e;
//int e;
enum MainState { ST_DECODER, ST_SPECTRUM, ST_WIFISCAN, ST_UPDATE, ST_TOUCHCALIB };
static MainState mainState = ST_WIFISCAN; // ST_WIFISCAN;
@ -467,7 +467,7 @@ void addSondeStatus(char *ptr, int i)
sprintf(ptr + strlen(ptr), "</td></tr><tr><td>QTH: %.6f,%.6f h=%.0fm</td></tr>\n", s->lat, s->lon, s->alt);
const time_t t = s->time;
ts = *gmtime(&t);
sprintf(ptr + strlen(ptr), "<tr><td>Frame# %d, Sats=%d, %04d-%02d-%02d %02d:%02d:%02d</td></tr>",
sprintf(ptr + strlen(ptr), "<tr><td>Frame# %u, Sats=%d, %04d-%02d-%02d %02d:%02d:%02d</td></tr>",
s->frame, s->sats, ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
if (s->type == STYPE_RS41) {
sprintf(ptr + strlen(ptr), "<tr><td>Burst-KT=%d Launch-KT=%d Countdown=%d (vor %ds)</td></tr>\n",
@ -547,13 +547,6 @@ void setupConfigData() {
}
struct st_configitems {
const char *name;
const char *label;
int type; // 0: numeric; i>0 string of length i; -1: separator; -2: type selector
void *data;
};
struct st_configitems config_list[] = {
/* General config settings */
{"", "Software configuration", -5, NULL},
@ -585,7 +578,7 @@ struct st_configitems config_list[] = {
{"", "Data feed configuration", -5, NULL},
/* APRS settings */
{"call", "Call", 8, sonde.config.call},
{"passcode", "Passcode", 8, sonde.config.passcode},
{"passcode", "Passcode", 0, &sonde.config.passcode},
/* KISS tnc settings */
{"kisstnc.active", "KISS TNC (port 14590) (needs reboot)", 0, &sonde.config.kisstnc.active},
{"kisstnc.idformat", "KISS TNC ID Format", -2, &sonde.config.kisstnc.idformat},
@ -655,7 +648,7 @@ struct st_configitems config_list[] = {
{"sondehub.email", "SondeHub email (optional, only used to contact in case of upload errors)", 63, &sonde.config.sondehub.email},
#endif
};
const static int N_CONFIG = (sizeof(config_list) / sizeof(struct st_configitems));
const int N_CONFIG = (sizeof(config_list) / sizeof(struct st_configitems));
void addConfigStringEntry(char *ptr, int idx, const char *label, int len, char *field) {
sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" value=\"%s\"/></td></tr>\n",
@ -729,7 +722,7 @@ const char *createConfigForm() {
case -6: // List of int8 values
addConfigInt8List(ptr, i, config_list[i].label, (int8_t *)config_list[i].data);
break;
case -3: // in/offt
case -3: // on/off
addConfigOnOffEntry(ptr, i, config_list[i].label, (int *)config_list[i].data);
break;
case -2: // DFM format
@ -2299,7 +2292,7 @@ void loopDecoder() {
#endif
#if FEATURE_MQTT
// send to MQTT if enabled
// send to MQTT if enabledson
if (connected && mqttEnabled) {
Serial.println("Sending sonde info via MQTT");
mqttclient.publishPacket(s);

Wyświetl plik

@ -1,8 +1,6 @@
let stypes=new Map();
stypes.set('4', 'RS41');
stypes.set('R', 'RS92');
stypes.set('9', 'DFM9 (old)');
stypes.set('6', 'DFM6 (old)');
stypes.set('D', 'DFM');
stypes.set('M', 'M10');
stypes.set('2', 'M20');

Wyświetl plik

@ -1,4 +1,4 @@
#include "../../RX_FSK/features.h"
#include "../features.h"
#include <U8x8lib.h>
#include <U8g2lib.h>
#include <SPIFFS.h>
@ -12,13 +12,13 @@ int readLine(Stream &stream, char *buffer, int maxlen);
extern const char *version_name;
extern const char *version_id;
#include <fonts/FreeMono9pt7b.h>
#include <fonts/FreeMono12pt7b.h>
#include <fonts/FreeSans9pt7b.h>
#include <fonts/FreeSans12pt7b.h>
#include <fonts/FreeSans18pt7b.h>
#include <fonts/Picopixel.h>
#include <fonts/Terminal11x16.h>
#include "fonts/FreeMono9pt7b.h"
#include "fonts/FreeMono12pt7b.h"
#include "fonts/FreeSans9pt7b.h"
#include "fonts/FreeSans12pt7b.h"
#include "fonts/FreeSans18pt7b.h"
#include "fonts/Picopixel.h"
#include "fonts/Terminal11x16.h"
extern Sonde sonde;
@ -826,8 +826,9 @@ void Display::parseDispElement(char *text, DispEntry *de)
// IP address / small always uses tiny font on TFT for backward compatibility
// Large font can be used arbitrarily
if(de->fmt==fontsma) de->fmt=0;
de->func = disp.drawIP; break;
de->func = disp.drawIP;
de->extra = strdup(text+1);
break;
case 's':
de->func = disp.drawSite;
de->extra = strdup(text+1);

Wyświetl plik

@ -137,8 +137,8 @@ private:
static const char *trim(char *s) {
char *ret = s;
while(*ret && isspace(*ret)) { ret++; }
int lastidx;
while(1) {
int lastidx;
lastidx = strlen(ret)-1;
if(lastidx>=0 && isspace(ret[lastidx]))
ret[lastidx] = 0;

Wyświetl plik

@ -464,20 +464,6 @@ int M10M20::waitRXcomplete() {
}
#if 0
static bool checkM20crc(uint8_t *msg, int crcpos) {
int i, cs, cs1;
cs = 0;
for (i = 0; i < crcpos; i++) {
cs = update_checkM10(cs, msg[i]); // same for M10 and M20
}
cs = cs & 0xFFFF;
cs1 = (msg[crcpos] << 8) | msg[crcpos+1];
return (cs1 == cs);
}
#endif
// ret: 1=frame ok; 2=frame with errors; 0=ignored frame (m20dop-alternativ)
int M10M20::decodeframeM20(uint8_t *data) {
@ -590,63 +576,5 @@ int M10M20::decodeframeM20(uint8_t *data) {
return crcok?1:2;
}
#if 0
//// same as for M10
// search for
// //101001100110011010011010011001100110100110101010100110101001
// //1010011001100110100110100110 0110.0110 1001.1010 1010.1001 1010.1001 => 0x669AA9A9
void M10M20::processM20data(uint8_t dt)
{
for(int i=0; i<8; i++) {
uint8_t d = (dt&0x80)?1:0;
dt <<= 1;
rxdata = (rxdata<<1) | d;
//uint8_t value = ((rxdata>>1)^rxdata)&0x01;
//if((rxbitc&1)==1) { rxbyte = (rxbyte>>1) + ((value)<<8); } // mancester decoded data
//rxbyte = (rxbyte>>1) | (d<<8);
if( (rxbitc&1)==0 ) {
// "bit1"
rxbyte = (rxbyte<<1) | d;
} else {
// "bit2" ==> 01 or 10 => 1, otherweise => 0
rxbyte = rxbyte ^ d;
}
//
if(rxsearching) {
if( rxdata == 0xcccca64c || rxdata == 0x333359b3 ) {
rxsearching = false;
rxbitc = 0;
rxp = 0;
#if 1
int rssi=sx1278.getRSSI();
int fei=sx1278.getFEI();
int afc=sx1278.getAFC();
Serial.print("Test: RSSI="); Serial.print(rssi);
Serial.print(" FEI="); Serial.print(fei);
Serial.print(" AFC="); Serial.println(afc);
sonde.si()->rssi = rssi;
sonde.si()->afc = afc;
#endif
}
} else {
rxbitc = (rxbitc+1)%16; // 16;
if(rxbitc == 0) { // got 8 data bit
//Serial.printf("%03x ",rxbyte);
dataptr[rxp++] = rxbyte&0xff; // (rxbyte>>1)&0xff;
#if 0
if(rxp==7 && dataptr[6] != 0x65) {
Serial.printf("wrong start: %02x\n",dataptr[6]);
rxsearching = true;
}
#endif
if(rxp>=M20_FRAMELEN) {
rxsearching = true;
haveNewFrame = decodeframeM20(dataptr);
}
}
}
}
}
#endif
M10M20 m10m20 = M10M20();

Wyświetl plik

@ -359,7 +359,7 @@ int MP3H::decodeframeMP3H(uint8_t *data) {
si->id[7] = hex(n/0x10);
si->id[8] = hex(n);
si->id[9] = 0;
snprintf(si->ser, 12, "%d-%d", mp3hstate.id1, mp3hstate.id2);
snprintf(si->ser, 12, "%u-%u", mp3hstate.id1, mp3hstate.id2);
si->validID = true;
}

Wyświetl plik

@ -25,6 +25,7 @@ private:
void bitsToBytes(uint8_t *bits, uint8_t *bytes, int len);
int decode41(byte *data, int maxlen);
#if 0
#define B 8
#define S 4
uint8_t hamming_conf[ 7*B]; // 7*8=56
@ -41,6 +42,7 @@ private:
{ 1, 1, 0, 1, 0, 0, 1, 0},
{ 1, 1, 1, 0, 0, 0, 0, 1}};
uint8_t He[8] = { 0x7, 0xB, 0xD, 0xE, 0x8, 0x4, 0x2, 0x1}; // Spalten von H:
#endif
// 1-bit-error-Syndrome
boolean initialized = false;

Wyświetl plik

@ -11,8 +11,8 @@
#include "SX1278FSK.h"
#include "SPI.h"
#include <Sonde.h>
#include <Display.h>
#include "Sonde.h"
#include "Display.h"
#define SPI_MUTEX_LOCK() \
@ -667,7 +667,7 @@ int8_t SX1278FSK::setMaxCurrent(uint8_t rate)
// Enable Over Current Protection
rate |= B00100000;
state = 1;
//state = 1;
st0 = readRegister(REG_OP_MODE); // Save the previous status
writeRegister(REG_OP_MODE, FSK_STANDBY_MODE); // Set FSK Standby mode to write in registers
writeRegister(REG_OCP, rate); // Modifying maximum current supply

Wyświetl plik

@ -1,7 +1,8 @@
#include "Scanner.h"
#include <SX1278FSK.h>
#include <U8x8lib.h>
#include "SX1278FSK.h"
#include "Sonde.h"
#include "Display.h"

Wyświetl plik

@ -213,12 +213,11 @@ void Sonde::defaultConfig() {
//
config.noisefloor = -125;
strcpy(config.call,"NOCALL");
strcpy(config.passcode, "---");
config.passcode = -1;
strcpy(config.mdnsname, "rdzsonde");
config.maxsonde=15;
config.debug=0;
config.wifi=1;
config.wifiap=1;
config.display[0]=0;
config.display[1]=1;
config.display[2]=-1;
@ -261,6 +260,9 @@ void Sonde::defaultConfig() {
strcpy(config.mqtt.prefix, "rdz_sonde_server/");
}
extern struct st_configitems config_list[];
extern const int N_CONFIG;
void Sonde::setConfig(const char *cfg) {
while(*cfg==' '||*cfg=='\t') cfg++;
if(*cfg=='#') return;
@ -270,180 +272,59 @@ void Sonde::setConfig(const char *cfg) {
*s=0; s--;
while(s>cfg && (*s==' '||*s=='\t')) { *s=0; s--; }
Serial.printf("configuration option '%s'=%s \n", cfg, val);
if(strcmp(cfg,"noisefloor")==0) {
config.noisefloor = atoi(val);
if(config.noisefloor==0) config.noisefloor=-130;
} else if(strcmp(cfg,"call")==0) {
strncpy(config.call, val, 9);
config.call[9]=0;
} else if(strcmp(cfg,"passcode")==0) {
strncpy(config.passcode, val, 9);
} else if(strcmp(cfg,"button_pin")==0) {
config.button_pin = atoi(val);
} else if(strcmp(cfg,"button2_pin")==0) {
config.button2_pin = atoi(val);
} else if(strcmp(cfg,"button2_axp")==0) {
config.button2_axp = atoi(val);
} else if(strcmp(cfg,"touch_thresh")==0) {
config.touch_thresh = atoi(val);
} else if(strcmp(cfg,"led_pout")==0) {
config.led_pout = atoi(val);
} else if(strcmp(cfg,"power_pout")==0) {
config.power_pout = atoi(val);
} else if(strcmp(cfg,"disptype")==0) {
config.disptype = atoi(val);
} else if(strcmp(cfg,"oled_sda")==0) {
config.oled_sda = atoi(val);
} else if(strcmp(cfg,"oled_scl")==0) {
config.oled_scl = atoi(val);
} else if(strcmp(cfg,"oled_rst")==0) {
config.oled_rst = atoi(val);
} else if(strcmp(cfg,"tft_rs")==0) {
config.tft_rs = atoi(val);
} else if(strcmp(cfg,"tft_cs")==0) {
config.tft_cs = atoi(val);
} else if(strcmp(cfg,"tft_orient")==0) {
config.tft_orient = atoi(val);
} else if(strcmp(cfg,"tft_spifreq")==0) {
config.tft_spifreq = atoi(val);
} else if(strcmp(cfg,"gps_rxd")==0) {
config.gps_rxd = atoi(val);
} else if(strcmp(cfg,"gps_txd")==0) {
config.gps_txd = atoi(val);
} else if(strcmp(cfg,"batt_adc")==0) {
config.batt_adc = atoi(val);
} else if(strcmp(cfg,"sx1278_ss")==0) {
config.sx1278_ss = atoi(val);
} else if(strcmp(cfg,"sx1278_miso")==0) {
config.sx1278_miso = atoi(val);
} else if(strcmp(cfg,"sx1278_mosi")==0) {
config.sx1278_mosi = atoi(val);
} else if(strcmp(cfg,"sx1278_sck")==0) {
config.sx1278_sck = atoi(val);
} else if(strcmp(cfg,"maxsonde")==0) {
config.maxsonde = atoi(val);
if(config.maxsonde>MAXSONDE) config.maxsonde=MAXSONDE;
} else if(strcmp(cfg,"debug")==0) {
config.debug = atoi(val);
} else if(strcmp(cfg,"wifi")==0) {
config.wifi = atoi(val);
} else if(strcmp(cfg,"wifiap")==0) {
config.wifiap = atoi(val);
} else if(strcmp(cfg,"mdnsname")==0) {
strncpy(config.mdnsname, val, 14);
} else if(strcmp(cfg,"screenfile")==0) {
config.screenfile = atoi(val);
} else if(strcmp(cfg,"display")==0) {
int i = 0;
char *ptr;
while(val) {
ptr = strchr(val,',');
if(ptr) *ptr = 0;
config.display[i++] = atoi(val);
val = ptr?ptr+1:NULL;
Serial.printf("appending value %d next is %s\n", config.display[i-1], val?val:"");
// new code: use config_list to find config entry...
int i;
for(i=0; i<N_CONFIG; i++) {
if(strcmp(cfg, config_list[i].name)!=0) continue;
if(config_list[i].type>0) { // string with that length
strlcpy((char *)config_list[i].data, val, config_list[i].type+1);
break;
}
switch(config_list[i].type) {
case 0: // integer
case -4: // integer (with "touch button" checkbox in web form)
case -3: // integer (boolean on/off swith in web form)
case -2: // integer (ID type)
*(int *)config_list[i].data = atoi(val);
if(config.maxsonde > MAXSONDE) config.maxsonde = MAXSONDE;
break;
case -7: // double
*(double *)config_list[i].data = *val==0 ? NAN : atof(val);
break;
case -6: // display list
{
int idx = 0;
char *ptr;
while(val) {
ptr = strchr(val,',');
if(ptr) *ptr = 0;
config.display[idx++] = atoi(val);
val = ptr?ptr+1:NULL;
Serial.printf("appending value %d next is %s\n", config.display[idx-1], val?val:"");
}
config.display[idx] = -1;
break;
}
config.display[i] = -1;
} else if (strcmp(cfg, "norx_timeout")==0) {
config.norx_timeout = atoi(val);
} else if(strcmp(cfg,"startfreq")==0) {
config.startfreq = atoi(val);
} else if(strcmp(cfg,"channelbw")==0) {
config.channelbw = atoi(val);
} else if(strcmp(cfg,"spectrum")==0) {
config.spectrum = atoi(val);
} else if(strcmp(cfg,"marker")==0) {
config.marker = atoi(val);
} else if(strcmp(cfg,"freqofs")==0) {
config.freqofs = atoi(val);
} else if(strcmp(cfg,"rs41.agcbw")==0) {
config.rs41.agcbw = atoi(val);
} else if(strcmp(cfg,"rs41.rxbw")==0) {
config.rs41.rxbw = atoi(val);
} else if(strcmp(cfg,"m10m20.agcbw")==0) {
config.m10m20.agcbw = atoi(val);
} else if(strcmp(cfg,"m10m20.rxbw")==0) {
config.m10m20.rxbw = atoi(val);
} else if(strcmp(cfg,"mp3h.agcbw")==0) {
config.mp3h.agcbw = atoi(val);
} else if(strcmp(cfg,"mp3h.rxbw")==0) {
config.mp3h.rxbw = atoi(val);
} else if(strcmp(cfg,"dfm.agcbw")==0) {
config.dfm.agcbw = atoi(val);
} else if(strcmp(cfg,"dfm.rxbw")==0) {
config.dfm.rxbw = atoi(val);
} else if(strcmp(cfg,"rs92.alt2d")==0) {
config.rs92.alt2d= atoi(val);
} else if(strcmp(cfg,"ephftp")==0) {
strncpy(config.ephftp, val, 40);
} else if(strcmp(cfg,"kisstnc.active")==0) {
config.kisstnc.active = atoi(val);
} else if(strcmp(cfg,"kisstnc.idformat")==0) {
config.kisstnc.idformat = atoi(val);
} else if(strcmp(cfg,"rs92.rxbw")==0) {
config.rs92.rxbw = atoi(val);
} else if(strcmp(cfg,"axudp.active")==0) {
config.udpfeed.active = atoi(val)>0;
} else if(strcmp(cfg,"axudp.host")==0) {
strncpy(config.udpfeed.host, val, 63);
} else if(strcmp(cfg,"axudp.port")==0) {
config.udpfeed.port = atoi(val);
} else if(strcmp(cfg,"axudp.symbol")==0) {
strncpy(config.udpfeed.symbol, val, 3);
} else if(strcmp(cfg,"axudp.highrate")==0) {
config.udpfeed.highrate = atoi(val);
} else if(strcmp(cfg,"axudp.idformat")==0) {
config.udpfeed.idformat = atoi(val);
} else if(strcmp(cfg,"tcp.active")==0) {
config.tcpfeed.active = atoi(val)>0;
} else if(strcmp(cfg,"tcp.host")==0) {
strncpy(config.tcpfeed.host, val, 63);
} else if(strcmp(cfg,"tcp.port")==0) {
config.tcpfeed.port = atoi(val);
} else if(strcmp(cfg,"tcp.symbol")==0) {
strncpy(config.tcpfeed.symbol, val, 3);
} else if(strcmp(cfg,"tcp.highrate")==0) {
config.tcpfeed.highrate = atoi(val);
} else if(strcmp(cfg,"tcp.idformat")==0) {
config.tcpfeed.idformat = atoi(val);
} else if(strcmp(cfg,"mqtt.active")==0) {
config.mqtt.active = atoi(val)>0;
} else if(strcmp(cfg,"mqtt.id")==0) {
strncpy(config.mqtt.id, val, 63);
} else if(strcmp(cfg,"mqtt.host")==0) {
strncpy(config.mqtt.host, val, 63);
} else if(strcmp(cfg,"mqtt.port")==0) {
config.mqtt.port = atoi(val);
} else if(strcmp(cfg,"mqtt.username")==0) {
strncpy(config.mqtt.username, val, 63);
} else if(strcmp(cfg,"mqtt.password")==0) {
strncpy(config.mqtt.password, val, 63);
} else if(strcmp(cfg,"mqtt.prefix")==0) {
strncpy(config.mqtt.prefix, val, 63);
} else if(strcmp(cfg, "sondehub.active")==0) {
config.sondehub.active = atoi(val);
} else if(strcmp(cfg,"sondehub.chase")==0) {
config.sondehub.chase = atoi(val);
} else if(strcmp(cfg, "sondehub.host")==0) {
strncpy(config.sondehub.host, val, 63);
} else if(strcmp(cfg, "sondehub.callsign")==0) {
strncpy(config.sondehub.callsign, val, 63);
} else if(strcmp(cfg, "sondehub.lat")==0) {
config.sondehub.lat = *val==0 ? NAN : atof(val);
Serial.printf("lat is %f\n", config.sondehub.lat);
} else if(strcmp(cfg, "sondehub.lon")==0) {
config.sondehub.lon = *val==0 ? NAN : atof(val);
Serial.printf("lon is %f\n", config.sondehub.lon);
} else if(strcmp(cfg, "sondehub.alt")==0) {
strncpy(config.sondehub.alt, val, 19);
} else if(strcmp(cfg, "sondehub.antenna")==0) {
strncpy(config.sondehub.antenna, val, 63);
} else if(strcmp(cfg, "sondehub.email")==0) {
strncpy(config.sondehub.email, val, 63);
} else {
default:
// skipping non-supported types
break;
}
break;
}
if(i==N_CONFIG) {
Serial.printf("Invalid config option '%s'=%s \n", cfg, val);
}
#if 0
// currently not in config_list. Maybe add later.
} else if(strcmp(cfg,"axudp.symbol")==0) {
strncpy(config.udpfeed.symbol, val, 3);
} else if(strcmp(cfg,"tcp.symbol")==0) {
strncpy(config.tcpfeed.symbol, val, 3);
}
#endif
}
void Sonde::setIP(String ip, bool AP) {

Wyświetl plik

@ -224,7 +224,6 @@ typedef struct st_rdzconfig {
// software configuration
int debug; // show port and config options after reboot
int wifi; // connect to known WLAN 0=skip
int wifiap; // enable/disable WiFi AccessPoint mode 0=disable
int screenfile;
int8_t display[30]; // list of display mode (0:scanner, 1:default, 2,... additional modes)
int startfreq; // spectrum display start freq (400, 401, ...)
@ -246,7 +245,7 @@ typedef struct st_rdzconfig {
// data feed configuration
// for now, one feed for each type is enough, but might get extended to more?
char call[10]; // APRS callsign
char passcode[9]; // APRS passcode
int passcode; // APRS passcode
struct st_feedinfo udpfeed; // target for AXUDP messages
struct st_feedinfo tcpfeed; // target for APRS-IS TCP connections
struct st_kisstnc kisstnc; // target for KISS TNC (via TCP, mainly for APRSdroid)
@ -255,6 +254,18 @@ typedef struct st_rdzconfig {
} RDZConfig;
struct st_configitems {
const char *name;
const char *label;
int type; // 0: numeric; i>0 string of length i; -1: separator; -2: type selector
void *data;
};
// defined in RX_FSK.ino
extern struct st_configitems config_list[];
extern const int N_CONFIG;
#define MAXSONDE 99
extern int fingerprintValue[];
@ -288,11 +299,6 @@ public:
void setup();
void receive();
uint16_t waitRXcomplete();
/* old and temp interface */
#if 0
void processRXbyte(uint8_t data);
int receiveFrame();
#endif
SondeInfo *si();

Wyświetl plik

@ -235,28 +235,11 @@ extern int aprsstr_mon2kiss(const char *mon, char raw[], int raw_len)
#define FEET (1.0/0.3048)
#define KNOTS (1.851984)
#define X2C_max_longcard 0xFFFFFFFFUL
static uint32_t X2C_TRUNCC(double x, uint32_t min0, uint32_t max0)
{
uint32_t i;
if (x < (double)min0)
i = (uint32_t)min0;
if (x > (double)max0)
i = (uint32_t)max0;
i = (uint32_t)x;
if ((double)i > x)
--i;
return i;
}
static uint32_t truncc(double r)
{
if (r<=0.0) return 0UL;
else if (r>=2.E+9) return 2000000000UL;
else return (uint32_t)X2C_TRUNCC(r,0UL,X2C_max_longcard);
else return (uint32_t)r;
return 0;
} /* end truncc() */
@ -273,7 +256,7 @@ static uint32_t dao91(double x)
char b[201];
char raw[201];
//char raw[201];
char *aprs_senddata(SondeInfo *s, const char *usercall, const char *sym) {
// float lat, float lon, float alt, float speed, float dir, float climb, const char *type, const char *objname, const char *usercall, const char *sym, const char *comm)
@ -310,11 +293,10 @@ char *aprs_senddata(SondeInfo *s, const char *usercall, const char *sym) {
i=strlen(b);
snprintf(b+i, APRS_MAXLEN-i, "/A=%06d", realcard(s->alt*FEET+0.5));
}
int dao=1;
if(dao) {
i=strlen(b);
snprintf(b+i, APRS_MAXLEN-i, "!w%c%c!", 33+dao91(s->lat), 33+dao91(s->lon));
}
// always use DAO
i=strlen(b);
snprintf(b+i, APRS_MAXLEN-i, "!w%c%c!", 33+dao91(s->lat), 33+dao91(s->lon));
strcat(b, "&");
char comm[100];
snprintf(comm, 100, "Clb=%.1fm/s %.3fMHz Type=%s", s->vs, s->freq, sondeTypeStr[s->type]);

Wyświetl plik

@ -24,13 +24,11 @@ void MQTT::init(const char* host, uint16_t port, const char* id, const char *use
this->password = password;
this->prefix = prefix;
char buffer[20];
snprintf(buffer, 20, "%s%6ld", id, random(0, 1000));
this->id = buffer;
Serial.println("[MQTT] pubsub client");
mqttClient.setServer(ip, port);
mqttClient.setClientId(id);
char buffer[20];
snprintf(buffer, 20, "%s%6ld", id, random(0, 1000));
mqttClient.setClientId(buffer);
if (strlen(password) > 0) {
mqttClient.setCredentials(username, password);
}
@ -73,15 +71,15 @@ void MQTT::publishPacket(SondeInfo *s)
"\"dir\": %.1f,"
"\"sats\": %d,"
"\"validPos\": %d,"
"\"time\": %d,"
"\"frame\": %d,"
"\"time\": %u,"
"\"frame\": %u,"
"\"validTime\": %d,"
"\"rssi\": %d,"
"\"afc\": %d,"
"\"rxStat\": \"%s\","
"\"rxStart\": %d,"
"\"norxStart\": %d,"
"\"viewStart\": %d,"
"\"rxStart\": %u,"
"\"norxStart\": %u,"
"\"viewStart\": %u,"
"\"lastState\": %d,"
"\"launchKT\": %d,"
"\"burstKT\": %d,"

Wyświetl plik

@ -13,7 +13,6 @@ public:
TimerHandle_t mqttReconnectTimer;
IPAddress ip;
uint16_t port;
const char *id;
const char *username;
const char *password;
const char *prefix;

Wyświetl plik

@ -78,174 +78,6 @@ void rotZ(double x1, double y1, double z1, double angle, double *x2, double *y2,
/* ---------------------------------------------------------------------------------------------------- */
#if 0
int read_SEMalmanac(FILE *fp, EPHEM_t *alm) {
int l, j;
char buf[64];
unsigned n, week, toa, ui;
double dbl;
l = fscanf(fp, "%u", &n); if (l != 1) return -1;
l = fscanf(fp, "%s", buf); if (l != 1) return -1;
l = fscanf(fp, "%u", &week); if (l != 1) return -1;
l = fscanf(fp, "%u", &toa); if (l != 1) return -1;
for (j = 1; j <= n; j++) {
//memset(&ephem, 0, sizeof(ephem));
alm[j].week = (uint16_t)week;
alm[j].toa = (uint32_t)toa;
alm[j].toe = (double)toa;
alm[j].toc = alm[j].toe;
l = fscanf(fp, "%u", &ui); if (l != 1) return -1; alm[j].prn = (uint16_t)ui;
l = fscanf(fp, "%u", &ui); if (l != 1) return -2; alm[j].svn = (uint16_t)ui;
l = fscanf(fp, "%u", &ui); if (l != 1) return -3; alm[j].ura = (uint8_t)ui;
l = fscanf(fp, "%lf", &dbl); if (l != 1) return -4; alm[j].e = dbl;
l = fscanf(fp, "%lf", &dbl); if (l != 1) return -5; alm[j].delta_i = dbl;
alm[j].i0 = (0.30 + alm[j].delta_i) * PI;
l = fscanf(fp, "%lf", &dbl); if (l != 1) return -6; alm[j].OmegaDot = dbl * PI;
l = fscanf(fp, "%lf", &dbl); if (l != 1) return -7; alm[j].sqrta = dbl;
l = fscanf(fp, "%lf", &dbl); if (l != 1) return -6; alm[j].Omega0 = dbl * PI;
l = fscanf(fp, "%lf", &dbl); if (l != 1) return -8; alm[j].w = dbl * PI;
l = fscanf(fp, "%lf", &dbl); if (l != 1) return -9; alm[j].M0 = dbl * PI;
l = fscanf(fp, "%lf", &dbl); if (l != 1) return -10; alm[j].af0 = dbl;
l = fscanf(fp, "%lf", &dbl); if (l != 1) return -11; alm[j].af1 = dbl;
alm[j].af2 = 0;
alm[j].crc = 0;
alm[j].crs = 0;
alm[j].cuc = 0;
alm[j].cus = 0;
alm[j].cic = 0;
alm[j].cis = 0;
alm[j].tgd = 0;
alm[j].idot = 0;
alm[j].delta_n = 0;
l = fscanf(fp, "%u", &ui); if (l != 1) return -12; alm[j].health = (uint8_t)ui;
l = fscanf(fp, "%u", &ui); if (l != 1) return -13; alm[j].conf = (uint8_t)ui;
}
return 0;
}
int read_RNXephemeris(FILE *fp, EPHEM_t eph[][24]) {
int l, i;
char buf[64], str[20];
char buf_header[83];
//buf_data[80]; // 3 + 4*19 = 79
char *pbuf;
unsigned ui;
double dbl;
int c;
EPHEM_t ephem = {};
int hr = 0;
do {
//l = fread(buf_header, 81, 1, fp); // Zeilen in Header sind nicht immer mit Leerzeichen aufgefuellt
pbuf = fgets(buf_header, 82, fp); // max 82-1 Zeichen + '\0'
buf_header[82] = '\0'; // doppelt haelt besser
//l = strlen(buf_header);
} while ( pbuf && !strstr(buf_header, "END OF HEADER") );
//l = fread(buf_data, 80, 1, fp);
//buf_data[79] = '\0';
while (hr < 24) { // brdc/hour-rinex sollte nur Daten von einem Tag enthalten
//memset(&ephem, 0, sizeof(ephem));
l = fread(buf, 3, 1, fp); if (l != 1) break; buf[ 3] = 0; sscanf(buf, "%d", &ui);
ephem.prn = ui;
for (i = 0; i < 16; i++) ephem.epoch[i] = '0';
ephem.epoch[16] = '\0';
l = fread(buf, 19, 1, fp); if (l != 1) break; buf[19] = 0;
for (i = 0; i < 6; i++) {
c = buf[3*i ]; if (c == ' ') c = '0'; str[2*i ] = c;
c = buf[3*i+1]; if (c == ' ') c = '0'; str[2*i+1] = c;
}
str[12] = buf[17];
str[13] = buf[18];
str[14] = '\0';
strncpy(ephem.epoch , "20", 2); // vorausgesetzt 21.Jhd; Datum steht auch im Header
strncpy(ephem.epoch+2, str, 15);
ephem.epoch[16] = '\0';
strncpy(str, buf+9, 2); str[2] = '\0';
hr = atoi(str);
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.af0 = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.af1 = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.af2 = dbl;
if ((c=fgetc(fp)) == EOF) break;
l = fread(buf, 3, 1, fp); if (l != 1) break; buf[ 3] = 0;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); //ephem.iode = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.crs = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.delta_n = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.M0 = dbl;
if ((c=fgetc(fp)) == EOF) break;
l = fread(buf, 3, 1, fp); if (l != 1) break; buf[ 3] = 0;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.cuc = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.e = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.cus = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.sqrta = dbl;
if ((c=fgetc(fp)) == EOF) break;
l = fread(buf, 3, 1, fp); if (l != 1) break; buf[ 3] = 0;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.toe = dbl;
ephem.toc = ephem.toe;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.cic = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.Omega0 = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.cis = dbl;
if ((c=fgetc(fp)) == EOF) break;
l = fread(buf, 3, 1, fp); if (l != 1) break; buf[ 3] = 0;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.i0 = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.crc = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.w = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.OmegaDot = dbl;
if ((c=fgetc(fp)) == EOF) break;
l = fread(buf, 3, 1, fp); if (l != 1) break; buf[ 3] = 0;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.idot = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); //ephem.codeL2 = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.gpsweek = (int)dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); //ephem.iodc = dbl;
if ((c=fgetc(fp)) == EOF) break;
l = fread(buf, 3, 1, fp); if (l != 1) break; buf[ 3] = 0;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); //ephem.sva = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.health = (uint8_t)(dbl+0.1);
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); ephem.tgd = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); //ephem.iodc = dbl;
if ((c=fgetc(fp)) == EOF) break;
l = fread(buf, 3, 1, fp); if (l != 1) break; buf[ 3] = 0;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); //ephem.ttom = dbl;
pbuf = fgets(buf_header, 82, fp);
/* // die letzten beiden Felder (spare) sind manchmal leer (statt 0.00); manchmal fehlt sogar das drittletzte Feld
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); //ephem.fit = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); //ephem.spare1 = dbl;
l = fread(buf, 19, 1, fp); if (l != 1) break; if (buf[15] == 'D') buf[15] = 'E'; buf[19] = 0; sscanf(buf, "%lf", &dbl); //ephem.spare2 = dbl;
if ((c=fgetc(fp)) == EOF) break; */
ephem.week = 1; // ephem.gpsweek
eph[ephem.prn][hr] = ephem;
if (pbuf == NULL) break;
}
return 0;
}
#endif
static EPHEM_t *te;
@ -254,17 +86,13 @@ static EPHEM_t *te;
#define fgetc(file) (char)file.read()
//EPHEM_t *read_RNXpephs(FILE *fp) {
EPHEM_t *read_RNXpephs(const char *file) {
int l, i;
//char buffer[86];
char buf[64], str[20];
unsigned ui;
double dbl;
int c;
EPHEM_t ephem = {};
// int count = 0;
//long fpos;
File fp = SPIFFS.open(file, "r");
if(!fp) { Serial.printf("Error opening %s\n", file); }
@ -277,23 +105,7 @@ EPHEM_t *read_RNXpephs(const char *file) {
Serial.printf("Skipping header: %s\n", line.c_str());
} while ( fp.available() && !strstr((const char *)line.c_str(), "END OF HEADER") );
if (!fp.available()) return NULL;
/*
fpos = ftell(fp);
count = 0;
while (count >= 0) { // data-Zeilen: 79 Zeichen
pbuf = fgets(buffer, 84, fp); if (pbuf == 0) break;
strncpy(str, buffer, 3);
str[3] = '\0';
sscanf(str, "%d", &ui);
if (ui < 33) count++;
for (i = 1; i < 8; i++) {
pbuf = fgets(buffer, 84, fp); if (pbuf == 0) break;
}
}
printf("Ephemerides: %d total=%d\n", count, count*sizeof(ephem));
fseek(fp, fpos, SEEK_SET);
*/
if(te) free(te);
te = (EPHEM_t *)calloc( 34, sizeof(ephem) ); // calloc( 1, sizeof(ephem) );
if (te == NULL) return NULL;

Wyświetl plik

@ -41,13 +41,11 @@
*/
#if 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#endif
#include <SPIFFS.h>
#include "nav_gps_vel.h"
@ -83,25 +81,6 @@ int almanac = 0,
int exSat = -1;
#if 0
/* --- RS92-SGP: 8N1 manchester --- */
#define BITS (2*(1+8+1)) // 20
#define HEADOFS 40 // HEADOFS+HEADLEN = 120 (bis 0x10)
#define HEADLEN 80 // (HEADOFS+HEADLEN) mod BITS = 0
/*
#define HEADOFS 0 // HEADOFS muss 0 wegen Wiederholung
#define HEADLEN 60 // HEADLEN < 100, (HEADOFS+HEADLEN) mod BITS = 0
*/
#define FRAMESTART ((HEADOFS+HEADLEN)/BITS)
/* 2A 10*/
char header[] = "10100110011001101001"
"10100110011001101001"
"10100110011001101001"
"10100110011001101001"
"1010011001100110100110101010100110101001";
char buf[HEADLEN+1] = "x";
#endif
int bufpos = -1;
@ -143,225 +122,7 @@ int findstr(char *buff, char *str, int pos) {
return i;
}
#if 0
int read_wav_header(FILE *fp) {
char txt[4+1] = "\0\0\0\0";
unsigned char dat[4];
int byte, p=0;
if (fread(txt, 1, 4, fp) < 4) return -1;
if (strncmp(txt, "RIFF", 4)) return -1;
if (fread(txt, 1, 4, fp) < 4) return -1;
// pos_WAVE = 8L
if (fread(txt, 1, 4, fp) < 4) return -1;
if (strncmp(txt, "WAVE", 4)) return -1;
// pos_fmt = 12L
for ( ; ; ) {
if ( (byte=fgetc(fp)) == EOF ) return -1;
txt[p % 4] = byte;
p++; if (p==4) p=0;
if (findstr(txt, "fmt ", p) == 4) break;
}
if (fread(dat, 1, 4, fp) < 4) return -1;
if (fread(dat, 1, 2, fp) < 2) return -1;
if (fread(dat, 1, 2, fp) < 2) return -1;
channels = dat[0] + (dat[1] << 8);
if (fread(dat, 1, 4, fp) < 4) return -1;
memcpy(&sample_rate, dat, 4); //sample_rate = dat[0]|(dat[1]<<8)|(dat[2]<<16)|(dat[3]<<24);
if (fread(dat, 1, 4, fp) < 4) return -1;
if (fread(dat, 1, 2, fp) < 2) return -1;
//byte = dat[0] + (dat[1] << 8);
if (fread(dat, 1, 2, fp) < 2) return -1;
bits_sample = dat[0] + (dat[1] << 8);
// pos_dat = 36L + info
for ( ; ; ) {
if ( (byte=fgetc(fp)) == EOF ) return -1;
txt[p % 4] = byte;
p++; if (p==4) p=0;
if (findstr(txt, "data", p) == 4) break;
}
if (fread(dat, 1, 4, fp) < 4) return -1;
Serial.printf("sample_rate: %d\n", sample_rate);
Serial.printf("bits : %d\n", bits_sample);
Serial.printf("channels : %d\n", channels);
if ((bits_sample != 8) && (bits_sample != 16)) return -1;
samples_per_bit = sample_rate/(float)BAUD_RATE;
Serial.printf("samples/bit: %.2f\n", samples_per_bit);
return 0;
}
#endif
#if 0
#define EOF_INT 0x1000000
#define LEN_movAvg 3
int movAvg[LEN_movAvg];
unsigned long sample_count = 0;
double bitgrenze = 0;
int read_signed_sample(FILE *fp) { // int = i32_t
int byte, i, sample, s=0; // EOF -> 0x1000000
for (i = 0; i < channels; i++) {
// i = 0: links bzw. mono
byte = fgetc(fp);
if (byte == EOF) return EOF_INT;
if (i == 0) sample = byte;
if (bits_sample == 16) {
byte = fgetc(fp);
if (byte == EOF) return EOF_INT;
if (i == 0) sample += byte << 8;
}
}
if (bits_sample == 8) s = sample-128; // 8bit: 00..FF, centerpoint 0x80=128
if (bits_sample == 16) s = (short)sample;
if (option_avg) {
movAvg[sample_count % LEN_movAvg] = s;
s = 0;
for (i = 0; i < LEN_movAvg; i++) s += movAvg[i];
s = (s+0.5) / LEN_movAvg;
}
sample_count++;
return s;
}
int par=1, par_alt=1;
int read_bits_fsk(FILE *fp, int *bit, int *len) {
static int sample;
int n, y0;
float l, x1;
static float x0;
n = 0;
do{
y0 = sample;
sample = read_signed_sample(fp);
if (sample == EOF_INT) return EOF;
//sample_count++; // in read_signed_sample()
par_alt = par;
par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127)
n++;
} while (par*par_alt > 0);
if (!option_res) l = (float)n / samples_per_bit;
else { // genauere Bitlaengen-Messung
x1 = sample/(float)(sample-y0); // hilft bei niedriger sample rate
l = (n+x0-x1) / samples_per_bit; // meist mehr frames (nicht immer)
x0 = x1;
}
*len = (int)(l+0.5);
if (!option_inv) *bit = (1+par_alt)/2; // oben 1, unten -1
else *bit = (1-par_alt)/2; // sdr#<rev1381?, invers: unten 1, oben -1
/* Y-offset ? */
return 0;
}
int bitstart = 0;
int read_rawbit(FILE *fp, int *bit) {
int sample;
int n, sum;
sum = 0;
n = 0;
if (bitstart) {
n = 1; // d.h. bitgrenze = sample_count-1 (?)
bitgrenze = sample_count-1;
bitstart = 0;
}
bitgrenze += samples_per_bit;
do {
sample = read_signed_sample(fp);
if (sample == EOF_INT) return EOF;
//sample_count++; // in read_signed_sample()
//par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127)
sum += sample;
n++;
} while (sample_count < bitgrenze); // n < samples_per_bit
if (sum >= 0) *bit = 1;
else *bit = 0;
if (option_inv) *bit ^= 1;
return 0;
}
/* ------------------------------------------------------------------------------------ */
// manchester1 1->10,0->01: 1.bit
// manchester2 0->10,1->01: 2.bit
// RS92-SGP: 8N1 manchester2
char manch(char *mbits) {
if ((mbits[0] == 1) && (mbits[1] == 0)) return 0;
else if ((mbits[0] == 0) && (mbits[1] == 1)) return 1;
else return -1;
}
int bits2byte(char bits[]) {
int i, byteval=0, d=1;
int bit8[8];
if (manch(bits+0) != 0) return 0x100;
for (i = 0; i < 8; i++) {
bit8[i] = manch(bits+2*(i+1));
}
if (manch(bits+(2*(8+1))) != 1) return 0x100;
for (i = 0; i < 8; i++) { // little endian
if (bit8[i] == 1) byteval += d;
else if (bit8[i] == 0) byteval += 0;
else return 0x100;
d <<= 1;
}
return byteval;
}
void inc_bufpos() {
bufpos = (bufpos+1) % HEADLEN;
}
int compare() {
int i=0, j = bufpos;
while (i < HEADLEN) {
if (j < 0) j = HEADLEN-1;
if (buf[j] != header[HEADOFS+HEADLEN-1-i]) break;
j--;
i++;
}
return i;
}
#endif
/*
uint8_t xorbyte(int pos) {
return xframe[pos] ^ mask[pos % MASK_LEN];
}
*/
uint8_t framebyte(int pos) {
return frame[pos];
}
@ -698,53 +459,6 @@ void prn12(uint8_t *prn_le, uint8_t prns[12]) {
}
int calc_satpos_alm(EPHEM_t alm[], double t, SAT_t *satp) {
return -1;
#if 0
double X, Y, Z, vX, vY, vZ;
int j;
int week;
double cl_corr, cl_drift;
for (j = 1; j < 33; j++) {
if (alm[j].prn > 0) { // prn==j
// Woche hat 604800 sec
if (t-alm[j].toa > WEEKSEC/2) rollover = +1;
else if (t-alm[j].toa < -WEEKSEC/2) rollover = -1;
else rollover = 0;
week = alm[j].week - rollover;
/*if (j == 1)*/ gpx.week = week + GPS_WEEK1024*1024;
if (option_vel >= 2) {
GPS_SatellitePositionVelocity_Ephem(
week, t, alm[j],
&cl_corr, &cl_drift, &X, &Y, &Z, &vX, &vY, &vZ
);
satp[alm[j].prn].clock_drift = cl_drift;
satp[alm[j].prn].vX = vX;
satp[alm[j].prn].vY = vY;
satp[alm[j].prn].vZ = vZ;
}
else {
GPS_SatellitePosition_Ephem(
week, t, alm[j],
&cl_corr, &X, &Y, &Z
);
}
satp[alm[j].prn].X = X;
satp[alm[j].prn].Y = Y;
satp[alm[j].prn].Z = Z;
satp[alm[j].prn].clock_corr = cl_corr;
}
}
return 0;
#endif
}
int calc_satpos_rnx(EPHEM_t eph[][24], double t, SAT_t *satp) {
double X, Y, Z, vX, vY, vZ;
int j, i, ti;
@ -924,12 +638,10 @@ int get_pseudorange() {
// GPS Sat Pos (& Vel)
//if (almanac) calc_satpos_alm( alm, gpstime/1000.0, sat);
if (ephem) calc_satpos_rnx2(ephs, gpstime/1000.0, sat);
// GPS Sat Pos t -= 1s
if (option_vel == 1) {
//if (almanac) calc_satpos_alm( alm, gpstime/1000.0-1, sat1s);
if (ephem) calc_satpos_rnx2(ephs, gpstime/1000.0-1, sat1s);
}
@ -1477,259 +1189,3 @@ void get_eph(const char *file) {
if (!option_der) d_err = 1000;
}
#if 0
int main(int argc, char *argv[]) {
FILE *fp, *fp_alm = NULL, *fp_eph = NULL;
char *fpname;
char bitbuf[BITS];
int bit_count = 0,
byte_count = FRAMESTART,
header_found = 0,
byte, i;
int bit, len;
char *pbuf = NULL;
#ifdef CYGWIN
_setmode(_fileno(stdin), _O_BINARY);
#endif
setbuf(stdout, NULL);
fpname = argv[0];
++argv;
while ((*argv) && (!fileloaded)) {
if ( (strcmp(*argv, "-h") == 0) || (strcmp(*argv, "--help") == 0) ) {
Serial.printf("%s [options] <file>\n", fpname);
Serial.printf(" file: audio.wav or raw_data\n");
Serial.printf(" options:\n");
Serial.printf(" --vel; --vel1, --vel2 (-g2)\n");
Serial.printf(" -v, -vx, -vv\n");
Serial.printf(" -r, --raw\n");
Serial.printf(" -i, --invert\n");
Serial.printf(" -a, --almanac <almanacSEM>\n");
Serial.printf(" -e, --ephem <ephemperisRinex>\n");
Serial.printf(" -g1 (verbose GPS: 4 sats)\n");
Serial.printf(" -g2 (verbose GPS: all sats)\n");
Serial.printf(" -gg (vverbose GPS)\n");
Serial.printf(" --crc (CRC check GPS)\n");
Serial.printf(" --rawin1,2 (raw_data file)\n");
return 0;
}
else if ( (strcmp(*argv, "--vel") == 0) ) {
option_vel = 4;
}
else if ( (strcmp(*argv, "--vel1") == 0) ) {
option_vel = 1;
if (option_vergps < 1) option_vergps = 2;
}
else if ( (strcmp(*argv, "--vel2") == 0) ) {
option_vel = 2;
if (option_vergps < 1) option_vergps = 2;
}
else if ( (strcmp(*argv, "--iter") == 0) ) {
option_iter = 1;
}
else if ( (strcmp(*argv, "-v") == 0) ) {
option_verbose = 1;
}
else if ( (strcmp(*argv, "-vv") == 0) ) {
option_verbose = 4;
}
else if ( (strcmp(*argv, "-vx") == 0) ) {
option_aux = 1;
}
else if (strcmp(*argv, "--crc") == 0) { option_crc = 1; }
else if ( (strcmp(*argv, "-r") == 0) || (strcmp(*argv, "--raw") == 0) ) {
option_raw = 1;
}
else if ( (strcmp(*argv, "-i") == 0) || (strcmp(*argv, "--invert") == 0) ) {
option_inv = 1;
}
else if ( (strcmp(*argv, "-a") == 0) || (strcmp(*argv, "--almanac") == 0) ) {
++argv;
if (*argv) fp_alm = fopen(*argv, "r"); // txt-mode
else return -1;
if (fp_alm == NULL) Serial.printf("[almanac] %s konnte nicht geoeffnet werden\n", *argv);
}
else if ( (strcmp(*argv, "-e") == 0) || (strncmp(*argv, "--ephem", 7) == 0) ) {
++argv;
if (*argv) fp_eph = fopen(*argv, "rb"); // bin-mode
else return -1;
if (fp_eph == NULL) Serial.printf("[rinex] %s konnte nicht geoeffnet werden\n", *argv);
}
else if ( (strcmp(*argv, "--dop") == 0) ) {
++argv;
if (*argv) {
dop_limit = atof(*argv);
if (dop_limit <= 0 || dop_limit >= 100) dop_limit = 9.9;
}
else return -1;
}
else if ( (strcmp(*argv, "--der") == 0) ) {
++argv;
if (*argv) {
d_err = atof(*argv);
if (d_err <= 0 || d_err >= 100000) d_err = 10000;
else option_der = 1;
}
else return -1;
}
else if ( (strcmp(*argv, "--exsat") == 0) ) {
++argv;
if (*argv) {
exSat = atoi(*argv);
if (exSat < 1 || exSat > 32) exSat = -1;
}
else return -1;
}
else if (strcmp(*argv, "-g1") == 0) { option_vergps = 1; } // verbose1 GPS
else if (strcmp(*argv, "-g2") == 0) { option_vergps = 2; } // verbose2 GPS (bancroft)
else if (strcmp(*argv, "-gg") == 0) { option_vergps = 8; } // vverbose GPS
else if (strcmp(*argv, "--rawin1") == 0) { rawin = 2; } // raw_txt input1
else if (strcmp(*argv, "--rawin2") == 0) { rawin = 3; } // raw_txt input2 (SM)
else if ( (strcmp(*argv, "--avg") == 0) ) {
option_avg = 1;
}
else if (strcmp(*argv, "-b") == 0) { option_b = 1; }
else {
if (!rawin) fp = fopen(*argv, "rb");
else fp = fopen(*argv, "r");
if (fp == NULL) {
Serial.printf("%s konnte nicht geoeffnet werden\n", *argv);
return -1;
}
fileloaded = 1;
}
++argv;
}
if (!fileloaded) fp = stdin;
if (fp_alm) {
i = read_SEMalmanac(fp_alm, alm);
if (i == 0) {
almanac = 1;
}
fclose(fp_alm);
if (!option_der) d_err = 4000;
}
if (fp_eph) {
/* i = read_RNXephemeris(fp_eph, eph);
if (i == 0) {
ephem = 1;
almanac = 0;
}
fclose(fp_eph); */
ephs = read_RNXpephs(fp_eph);
if (ephs) {
ephem = 1;
almanac = 0;
}
fclose(fp_eph);
if (!option_der) d_err = 1000;
}
if (!rawin) {
i = read_wav_header(fp);
if (i) {
fclose(fp);
return -1;
}
while (!read_bits_fsk(fp, &bit, &len)) {
if (len == 0) { // reset_frame();
if (byte_count > pos_SondeID+8) {
if (byte_count < FRAME_LEN-20) err_gps = 1;
print_frame(byte_count);
err_gps = 0;
}
bit_count = 0;
byte_count = FRAMESTART;
header_found = 0;
inc_bufpos();
buf[bufpos] = 'x';
continue; // ...
}
for (i = 0; i < len; i++) {
inc_bufpos();
buf[bufpos] = 0x30 + bit; // Ascii
if (!header_found) {
if (compare() >= HEADLEN) header_found = 1;
}
else {
bitbuf[bit_count] = bit;
bit_count++;
if (bit_count == BITS) {
bit_count = 0;
byte = bits2byte(bitbuf);
frame[byte_count] = byte;
byte_count++;
if (byte_count == FRAME_LEN) {
byte_count = FRAMESTART;
header_found = 0;
//inc_bufpos();
//buf[bufpos] = 'x';
print_frame(FRAME_LEN);
}
}
}
}
if (header_found && option_b) {
bitstart = 1;
while ( byte_count < FRAME_LEN ) {
if (read_rawbit(fp, &bit) == EOF) break;
bitbuf[bit_count] = bit;
bit_count++;
if (bit_count == BITS) {
bit_count = 0;
byte = bits2byte(bitbuf);
frame[byte_count] = byte;
byte_count++;
}
}
header_found = 0;
print_frame(byte_count);
byte_count = FRAMESTART;
}
}
}
else //if (rawin)
{
if (rawin == 3) frameofs = 5;
while (1 > 0) {
pbuf = fgets(buffer_rawin, rawin*FRAME_LEN+4, fp);
if (pbuf == NULL) break;
buffer_rawin[rawin*FRAME_LEN+1] = '\0';
len = strlen(buffer_rawin) / rawin;
if (len > pos_SondeID+8) {
for (i = 0; i < len-frameofs; i++) { //%2x SCNx8=%hhx(inttypes.h)
sscanf(buffer_rawin+rawin*i, "%2hhx", frame+frameofs+i);
// wenn ohne %hhx: sscanf(buffer_rawin+rawin*i, "%2x", &byte); frame[frameofs+i] = (uint8_t)byte;
}
if (len < FRAME_LEN-20) err_gps = 1;
print_frame(len);
err_gps = 0;
}
}
}
free(ephs);
fclose(fp);
return 0;
}
#endif