Add support for WxR-301 PN9 variant

pull/882/head
Mark Jessop 2024-05-31 19:43:49 +09:30
rodzic 111f03f6e6
commit bbb432274e
9 zmienionych plików z 188 dodań i 68 usunięć

Wyświetl plik

@ -12,7 +12,7 @@ from queue import Queue
# MINOR - New sonde type support, other fairly big changes that may result in telemetry or config file incompatability issus. # MINOR - New sonde type support, other fairly big changes that may result in telemetry or config file incompatability issus.
# PATCH - Small changes, or minor feature additions. # PATCH - Small changes, or minor feature additions.
__version__ = "1.7.3-beta11" __version__ = "1.7.3-beta12"
# Global Variables # Global Variables

Wyświetl plik

@ -428,7 +428,8 @@ def read_auto_rx_config(filename, no_sdr_test=False):
"MEISEI": True, "MEISEI": True,
"MTS01": False, # Until we test it "MTS01": False, # Until we test it
"MRZ": False, # .... except for the MRZ, until we know it works. "MRZ": False, # .... except for the MRZ, until we know it works.
"WXR301": True, # No fsk_demod chain for this yet. "WXR301": True,
"WXRPN9": True,
"UDP": False, "UDP": False,
} }

Wyświetl plik

@ -40,7 +40,8 @@ VALID_SONDE_TYPES = [
"MRZ", "MRZ",
"MTS01", "MTS01",
"UDP", "UDP",
"WXR301" "WXR301",
"WXRPN9"
] ]
# Known 'Drifty' Radiosonde types # Known 'Drifty' Radiosonde types
@ -120,7 +121,8 @@ class SondeDecoder(object):
"MRZ", "MRZ",
"MTS01", "MTS01",
"UDP", "UDP",
"WXR301" "WXR301",
"WXRPN9"
] ]
def __init__( def __init__(
@ -762,7 +764,31 @@ class SondeDecoder(object):
# WXR301, via iq_dec as a FM Demod. # WXR301, via iq_dec as a FM Demod.
decode_cmd += f"./iq_dec --FM --IFbw {_if_bw} --lpFM --wav --iq 0.0 - {_sample_rate} 16 2>/dev/null | ./weathex301d -b --json" decode_cmd += f"./iq_dec --FM --IFbw {_if_bw} --lpFM --wav --iq 0.0 - {_sample_rate} 16 2>/dev/null | ./weathex301d -b --json"
elif self.sonde_type == "WXRPN9":
# Weathex WxR-301D (PN9)
_sample_rate = 96000
_if_bw = 64
decode_cmd = get_sdr_iq_cmd(
sdr_type = self.sdr_type,
frequency = self.sonde_freq,
sample_rate = _sample_rate,
sdr_hostname = self.sdr_hostname,
sdr_port = self.sdr_port,
ss_iq_path = self.ss_iq_path,
rtl_device_idx = self.rtl_device_idx,
ppm = self.ppm,
gain = self.gain,
bias = self.bias
)
# Add in tee command to save IQ to disk if debugging is enabled.
if self.save_decode_iq:
decode_cmd += f" tee {self.save_decode_iq_path} |"
# WXR301, via iq_dec as a FM Demod.
decode_cmd += f"./iq_dec --FM --IFbw {_if_bw} --lpFM --wav --iq 0.0 - {_sample_rate} 16 2>/dev/null | ./weathex301d -b --json --pn9"
elif self.sonde_type == "UDP": elif self.sonde_type == "UDP":
# UDP Input Mode. # UDP Input Mode.
@ -1313,6 +1339,50 @@ class SondeDecoder(object):
demod_stats = FSKDemodStats(averaging_time=5.0, peak_hold=True) demod_stats = FSKDemodStats(averaging_time=5.0, peak_hold=True)
self.rx_frequency = self.sonde_freq self.rx_frequency = self.sonde_freq
elif self.sonde_type == "WXRPN9":
# Weathex WxR-301D Sonde, PN9 variant
_baud_rate = 4800
_sample_rate = 96000
# Limit FSK estimator window to roughly +/- 40 kHz
_lower = -40000
_upper = 40000
demod_cmd = get_sdr_iq_cmd(
sdr_type = self.sdr_type,
frequency = self.sonde_freq,
sample_rate = _sample_rate,
sdr_hostname = self.sdr_hostname,
sdr_port = self.sdr_port,
ss_iq_path = self.ss_iq_path,
rtl_device_idx = self.rtl_device_idx,
ppm = self.ppm,
gain = self.gain,
bias = self.bias,
dc_block = True
)
# Add in tee command to save IQ to disk if debugging is enabled.
if self.save_decode_iq:
demod_cmd += f" tee {self.save_decode_iq_path} |"
# Trying out using the mask estimator here to reduce issues with interference
demod_cmd += "./fsk_demod --cs16 -s -b %d -u %d --mask 60000 --stats=%d 2 %d %d - -" % (
_lower,
_upper,
_stats_rate,
_sample_rate,
_baud_rate,
)
# Soft-decision decoding, inverted.
decode_cmd = f"./weathex301d --softin -i --json --pn9 2>/dev/null"
# Weathex sondes transmit continuously - average over the last frame, and use a peak hold
demod_stats = FSKDemodStats(averaging_time=5.0, peak_hold=True)
self.rx_frequency = self.sonde_freq
else: else:
return None return None
@ -1700,7 +1770,7 @@ class SondeDecoder(object):
# Weathex Specific Actions # Weathex Specific Actions
# Same datetime issues as with iMets, and LMS6 # Same datetime issues as with iMets, and LMS6
if self.sonde_type == "WXR301": if (self.sonde_type == "WXR301") or (self.sonde_type == "WXRPN9"):
# Fix up the time. # Fix up the time.
_telemetry["datetime_dt"] = fix_datetime(_telemetry["datetime"]) _telemetry["datetime_dt"] = fix_datetime(_telemetry["datetime"])
# Re-generate the datetime string. # Re-generate the datetime string.

Wyświetl plik

@ -620,6 +620,15 @@ def detect_sonde(
# to do no whitening on the signal. # to do no whitening on the signal.
_offset_est = 0.0 _offset_est = 0.0
elif "WXRPN9" in _type:
logging.debug(
"Scanner (%s) - Detected a Weathex WxR-301D Sonde (PN9 Variant)! (Score: %.2f, Offset: %.1f Hz)"
% (_sdr_name, _score, _offset_est)
)
_sonde_type = "WXRPN9"
# Clear out the offset estimate for WxR-301's as it's not accurate
# to do no whitening on the signal.
_offset_est = 0.0
else: else:
_sonde_type = None _sonde_type = None

Wyświetl plik

@ -233,6 +233,16 @@ class SondehubUploader(object):
_output["type"] = "WxR-301D" _output["type"] = "WxR-301D"
_output["serial"] = telemetry["id"].split("-")[1] _output["serial"] = telemetry["id"].split("-")[1]
# Double check for the subtype being present, just in case...
if "subtype" in telemetry:
if telemetry["subtype"] == "WXR_PN9":
_output["type"] = "WxR-301D (PN9)"
elif telemetry["type"] == "WXRPN9":
_output["manufacturer"] = "Weathex"
_output["type"] = "WxR-301D (PN9)"
_output["serial"] = telemetry["id"].split("-")[1]
else: else:
self.log_error("Unknown Radiosonde Type %s" % telemetry["type"]) self.log_error("Unknown Radiosonde Type %s" % telemetry["type"])
return None return None

Wyświetl plik

@ -1665,6 +1665,7 @@
<option value="MRZ">MRZ-H1</option> <option value="MRZ">MRZ-H1</option>
<option value="MTS01">MTS01</option> <option value="MTS01">MTS01</option>
<option value="WXR301">WXR301</option> <option value="WXR301">WXR301</option>
<option value="WXRPN9">WXR301 (PN9 variant)</option>
</select> </select>
<div style="display:inline;vertical-align:middle;"> <div style="display:inline;vertical-align:middle;">
<button id="start-decoder" onclick="start_decoder();">Start</button> <button id="start-decoder" onclick="start_decoder();">Start</button>

Wyświetl plik

@ -212,6 +212,8 @@ def short_type_lookup(type_name):
return "Meteosis MTS01" return "Meteosis MTS01"
elif type_name == "WXR301": elif type_name == "WXR301":
return "Weathex WxR-301D" return "Weathex WxR-301D"
elif type_name == "WXRPN9":
return "Weathex WxR-301D (PN9 Variant)"
else: else:
return "Unknown" return "Unknown"
@ -256,6 +258,8 @@ def short_short_type_lookup(type_name):
return "MTS01" return "MTS01"
elif type_name == "WXR301": elif type_name == "WXR301":
return "WXR301" return "WXR301"
elif type_name == "WXRPN9":
return "WXR301(PN9)"
else: else:
return "Unknown" return "Unknown"

Wyświetl plik

@ -116,6 +116,10 @@ static char weathex_header[] =
"10101010""10101010""10101010" // AA AA AA (preamble) "10101010""10101010""10101010" // AA AA AA (preamble)
"00101101""11010100"; //"10101010"; // 2D D4 55/AA "00101101""11010100"; //"10101010"; // 2D D4 55/AA
static char wxr2pn9_header[] =
"10101010""10101010""10101010" // AA AA AA (preamble)
"11000001""10010100"; //"11000001"; // C1 94 C1
typedef struct { typedef struct {
int sps; // header: symbol rate, baud int sps; // header: symbol rate, baud
@ -140,28 +144,29 @@ static float lpFM_bw[2] = { 4e3, 10e3 }; // FM-audio lowpass bandwidth
static float lpIQ_bw[N_bwIQ] = { 6e3, 12e3, 22e3, 200e3 }; // IF iq lowpass bandwidth static float lpIQ_bw[N_bwIQ] = { 6e3, 12e3, 22e3, 200e3 }; // IF iq lowpass bandwidth
static float set_lpIQ = 0.0; static float set_lpIQ = 0.0;
#define tn_DFM 2 #define tn_DFM 2
#define tn_RS41 3 #define tn_RS41 3
#define tn_RS92 4 #define tn_RS92 4
#define tn_M10 5 #define tn_M10 5
#define tn_M20 6 #define tn_M20 6
#define tn_LMS6 8 #define tn_LMS6 8
#define tn_MEISEI 9 #define tn_MEISEI 9
#define tn_MRZ 12 #define tn_MRZ 12
#define tn_MTS01 13 #define tn_MTS01 13
#define tn_C34C50 15 #define tn_C34C50 15
#define tn_WXR301 16 #define tn_WXR301 16
#define tn_MK2LMS 18 #define tn_WXRpn9 17
#define tn_IMET5 24 #define tn_MK2LMS 18
#define tn_IMETa 25 #define tn_IMET5 24
#define tn_IMET4 26 #define tn_IMETa 25
#define tn_IMET1rs 28 #define tn_IMET4 26
#define tn_IMET1ab 29 #define tn_IMET1rs 28
#define tn_IMET1ab 29
#define Nrs 16 #define Nrs 17
#define idxIMETafsk 13 #define idxIMETafsk 14
#define idxRS 14 #define idxRS 15
#define idxI4 15 #define idxI4 16
static rsheader_t rs_hdr[Nrs] = { static rsheader_t rs_hdr[Nrs] = {
{ 2500, 0, 0, dfm_header, 1.0, 0.0, 0.65, 2, NULL, "DFM9", tn_DFM, 0, 1, 0.0, 0.0}, // DFM6: -2 ? { 2500, 0, 0, dfm_header, 1.0, 0.0, 0.65, 2, NULL, "DFM9", tn_DFM, 0, 1, 0.0, 0.0}, // DFM6: -2 ?
{ 4800, 0, 0, rs41_header, 0.5, 0.0, 0.70, 2, NULL, "RS41", tn_RS41, 0, 1, 0.0, 0.0}, { 4800, 0, 0, rs41_header, 0.5, 0.0, 0.70, 2, NULL, "RS41", tn_RS41, 0, 1, 0.0, 0.0},
@ -175,6 +180,7 @@ static rsheader_t rs_hdr[Nrs] = {
{ 1200, 0, 0, mts01_header, 1.0, 0.0, 0.65, 2, NULL, "MTS01", tn_MTS01, 0, 0, 0.0, 0.0}, { 1200, 0, 0, mts01_header, 1.0, 0.0, 0.65, 2, NULL, "MTS01", tn_MTS01, 0, 0, 0.0, 0.0},
{ 5800, 0, 0, c34_preheader, 1.5, 0.0, 0.80, 2, NULL, "C34C50", tn_C34C50, 0, 2, 0.0, 0.0}, // C34/C50 2900 Hz tone { 5800, 0, 0, c34_preheader, 1.5, 0.0, 0.80, 2, NULL, "C34C50", tn_C34C50, 0, 2, 0.0, 0.0}, // C34/C50 2900 Hz tone
{ 4800, 0, 0, weathex_header, 1.0, 0.0, 0.65, 2, NULL, "WXR301", tn_WXR301, 0, 3, 0.0, 0.0}, { 4800, 0, 0, weathex_header, 1.0, 0.0, 0.65, 2, NULL, "WXR301", tn_WXR301, 0, 3, 0.0, 0.0},
{ 5000, 0, 0, wxr2pn9_header, 1.0, 0.0, 0.65, 2, NULL, "WXRPN9", tn_WXRpn9, 0, 3, 0.0, 0.0},
{ 9600, 0, 0, imet1ab_header, 1.0, 0.0, 0.80, 2, NULL, "IMET1AB", tn_IMET1ab, 1, 3, 0.0, 0.0}, // (rs_hdr[idxAB]) { 9600, 0, 0, imet1ab_header, 1.0, 0.0, 0.80, 2, NULL, "IMET1AB", tn_IMET1ab, 1, 3, 0.0, 0.0}, // (rs_hdr[idxAB])
{ 9600, 0, 0, imet_preamble, 0.5, 0.0, 0.80, 4, NULL, "IMETafsk", tn_IMETa , 1, 1, 0.0, 0.0}, // IMET1AB, IMET1RS (IQ)IMET4 { 9600, 0, 0, imet_preamble, 0.5, 0.0, 0.80, 4, NULL, "IMETafsk", tn_IMETa , 1, 1, 0.0, 0.0}, // IMET1AB, IMET1RS (IQ)IMET4
{ 9600, 0, 0, imet1rs_header, 0.5, 0.0, 0.80, 2, NULL, "IMET1RS", tn_IMET1rs, 0, 3, 0.0, 0.0}, // (rs_hdr[idxRS]) IMET4: lpIQ=0 ... { 9600, 0, 0, imet1rs_header, 0.5, 0.0, 0.80, 2, NULL, "IMET1RS", tn_IMET1rs, 0, 3, 0.0, 0.0}, // (rs_hdr[idxRS]) IMET4: lpIQ=0 ...
@ -184,6 +190,7 @@ static rsheader_t rs_hdr[Nrs] = {
static int idx_MTS01 = -1, static int idx_MTS01 = -1,
idx_C34C50 = -1, idx_C34C50 = -1,
idx_WXR301 = -1, idx_WXR301 = -1,
idx_WXRPN9 = -1,
idx_IMET1AB = -1; idx_IMET1AB = -1;
@ -1143,6 +1150,7 @@ static int init_buffers() {
#endif #endif
#ifdef NOWXR301 #ifdef NOWXR301
if ( strncmp(rs_hdr[j].type, "WXR301", 5) == 0 ) idx_WXR301 = j; if ( strncmp(rs_hdr[j].type, "WXR301", 5) == 0 ) idx_WXR301 = j;
if ( strncmp(rs_hdr[j].type, "WXRPN9", 5) == 0 ) idx_WXRPN9 = j;
#endif #endif
#ifdef NOIMET1AB #ifdef NOIMET1AB
if ( strncmp(rs_hdr[j].type, "IMET1AB", 7) == 0 ) idx_IMET1AB = j; if ( strncmp(rs_hdr[j].type, "IMET1AB", 7) == 0 ) idx_IMET1AB = j;
@ -1153,7 +1161,7 @@ static int init_buffers() {
rs_hdr[j].spb = sample_rate/(float)rs_hdr[j].sps; rs_hdr[j].spb = sample_rate/(float)rs_hdr[j].sps;
rs_hdr[j].hLen = strlen(rs_hdr[j].header); rs_hdr[j].hLen = strlen(rs_hdr[j].header);
rs_hdr[j].L = rs_hdr[j].hLen * rs_hdr[j].spb + 0.5; rs_hdr[j].L = rs_hdr[j].hLen * rs_hdr[j].spb + 0.5;
if (j != idx_MTS01 && j != idx_C34C50 && j != idx_WXR301 && j != idx_IMET1AB) { if (j != idx_MTS01 && j != idx_C34C50 && j != idx_WXR301 && j != idx_WXRPN9 && j != idx_IMET1AB) {
if (rs_hdr[j].hLen > hLen) hLen = rs_hdr[j].hLen; if (rs_hdr[j].hLen > hLen) hLen = rs_hdr[j].hLen;
if (rs_hdr[j].L > Lmax) Lmax = rs_hdr[j].L; if (rs_hdr[j].L > Lmax) Lmax = rs_hdr[j].L;
} }
@ -1477,6 +1485,7 @@ int main(int argc, char **argv) {
if ( j == idx_MTS01 ) continue; // only ifdef NOMTS01 if ( j == idx_MTS01 ) continue; // only ifdef NOMTS01
if ( j == idx_C34C50 ) continue; // only ifdef NOC34C50 if ( j == idx_C34C50 ) continue; // only ifdef NOC34C50
if ( j == idx_WXR301 ) continue; // only ifdef NOWXR301 if ( j == idx_WXR301 ) continue; // only ifdef NOWXR301
if ( j == idx_WXRPN9 ) continue; // only ifdef NOWXR301
if ( j == idx_IMET1AB ) continue; // only ifdef NOIMET1AB if ( j == idx_IMET1AB ) continue; // only ifdef NOIMET1AB
mv0_pos[j] = mv_pos[j]; mv0_pos[j] = mv_pos[j];

Wyświetl plik

@ -1,10 +1,8 @@
/* /*
Malaysia Weathex WxR-301D (64kHz wide)
401100 kHz (64kHz wide) UAII2022 Lindenberg: w/ PN9, 5000 baud
2023-05-12 ([ 4400] 12:20:37 alt: 12616.6 lat: 2.6785 lon: 101.5827) Malaysia: w/o PN9, 4800 baud
2023-07-27 ([ 6402] 00:47:32 alt: 26835.9 lat: 2.6918 lon: 101.5025)
Weathex WxR-301D w/o PN9
*/ */
#include <stdio.h> #include <stdio.h>
@ -38,25 +36,21 @@ int option_verbose = 0,
wavloaded = 0; wavloaded = 0;
int wav_channel = 0; // audio channel: left int wav_channel = 0; // audio channel: left
int option_pn9 = 0;
#define BAUD_RATE 4800.0 // (4997.2) // 5000 #define BAUD_RATE 4800.0
#define BAUD_RATE_PN9 5000.0 //(4997.2) // 5000
#define FRAMELEN 69 //64 #define FRAMELEN 69 //64
#define BITFRAMELEN (8*FRAMELEN) #define BITFRAMELEN (8*FRAMELEN)
/*
#define HEADLEN 56
#define HEADOFS 0
char header[] = "10101010""10101010""10101010" // AA AA AA (preamble)
"11000001""10010100""11000001"; // C1 94 C1
*/
//preamble_header_sn1: 101010101010101010101010 1100000110010100110000011100011001111000 110001010110110111100100
//preamble_header_sn2: 101010101010101010101010 1100000110010100110000011100011001111000 001100100110110111100100
//preamble_header_sn3: 101010101010101010101010 1100000110010100110000011100011001111000 001010000110110111100100
#define HEADLEN 40 //48 #define HEADLEN 40
#define HEADOFS 0 #define HEADOFS 0
char header_pn9[] = "10101010""10101010""10101010"//"10101010" // AA AA AA (preamble)
"11000001""10010100"; //"11000001""11000110"; // C1 94 (C1 C6)
char header[] = "10101010""10101010""10101010" // AA AA AA (preamble) char header[] = "10101010""10101010""10101010" // AA AA AA (preamble)
"00101101""11010100"; //"10101010"; // 2D D4 55/AA "00101101""11010100"; //"10101010"; // 2D D4 (55/AA)
char buf[HEADLEN+1] = "xxxxxxxxxx\0"; char buf[HEADLEN+1] = "xxxxxxxxxx\0";
int bufpos = 0; int bufpos = 0;
@ -65,6 +59,7 @@ char frame_bits[BITFRAMELEN+1];
ui8_t frame_bytes[FRAMELEN+1]; ui8_t frame_bytes[FRAMELEN+1];
ui8_t xframe[FRAMELEN+1]; ui8_t xframe[FRAMELEN+1];
float baudrate = BAUD_RATE;
/* ------------------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------ */
@ -131,7 +126,7 @@ int read_wav_header(FILE *fp) {
if (sample_rate == 900001) sample_rate -= 1; if (sample_rate == 900001) sample_rate -= 1;
samples_per_bit = sample_rate/(float)BAUD_RATE; samples_per_bit = sample_rate/(float)baudrate;
fprintf(stderr, "samples/bit: %.2f\n", samples_per_bit); fprintf(stderr, "samples/bit: %.2f\n", samples_per_bit);
@ -252,9 +247,9 @@ int f32soft_read(FILE *fp, float *s) {
} }
int compare() { int compare(char *hdr) {
int i=0; int i=0;
while ((i < HEADLEN) && (buf[(bufpos+i) % HEADLEN] == header[HEADLEN+HEADOFS-1-i])) { while ((i < HEADLEN) && (buf[(bufpos+i) % HEADLEN] == hdr[HEADLEN+HEADOFS-1-i])) {
i++; i++;
} }
return i; return i;
@ -266,9 +261,9 @@ char inv(char c) {
return c; return c;
} }
int compare2() { int compare2(char *hdr) {
int i=0; int i=0;
while ((i < HEADLEN) && (buf[(bufpos+i) % HEADLEN] == inv(header[HEADLEN+HEADOFS-1-i]))) { while ((i < HEADLEN) && (buf[(bufpos+i) % HEADLEN] == inv(hdr[HEADLEN+HEADOFS-1-i]))) {
i++; i++;
} }
return i; return i;
@ -307,8 +302,8 @@ int bits2bytes(char *bitstr, ui8_t *bytes) {
// cf. https://www.ti.com/lit/an/swra322/swra322.pdf // cf. https://www.ti.com/lit/an/swra322/swra322.pdf
// https://destevez.net/2019/07/lucky-7-decoded/ // https://destevez.net/2019/07/lucky-7-decoded/
// //
// counter low byte: frame[OFS+4] XOR 0xCC // counter low byte: frame[ofs+4] XOR 0xCC
// zero bytes, frame[OFS+30]: 0C CA C9 FB 49 37 E5 A8 // zero bytes, frame[ofs+30]: 0C CA C9 FB 49 37 E5 A8
// //
ui8_t PN9b[64] = { 0xFF, 0x87, 0xB8, 0x59, 0xB7, 0xA1, 0xCC, 0x24, ui8_t PN9b[64] = { 0xFF, 0x87, 0xB8, 0x59, 0xB7, 0xA1, 0xCC, 0x24,
0x57, 0x5E, 0x4B, 0x9C, 0x0E, 0xE9, 0xEA, 0x50, 0x57, 0x5E, 0x4B, 0x9C, 0x0E, 0xE9, 0xEA, 0x50,
@ -356,7 +351,10 @@ typedef struct {
gpx_t gpx; gpx_t gpx;
#define OFS 6 // xPN9: OFS=8, different baud // xPN9: OFS=8, 5000 baud ; w/o PN9: OFS=6, 4800 baud
#define OFS 6
#define OFS_PN9 8
int ofs = OFS;
int print_frame() { int print_frame() {
int j; int j;
@ -366,12 +364,14 @@ int print_frame() {
for (j = 0; j < FRAMELEN; j++) { for (j = 0; j < FRAMELEN; j++) {
ui8_t b = frame_bytes[j]; ui8_t b = frame_bytes[j];
//if (j >= 6) b ^= PN9b[(j-6)%64]; // PN9 baud diff if (option_pn9) {
if (j >= 6) b ^= PN9b[(j-6)%64];
}
xframe[j] = b; xframe[j] = b;
} }
chkval = xor8sum(xframe+OFS, 53); chkval = xor8sum(xframe+ofs, 53);
chkdat = (xframe[OFS+53]<<8) | xframe[OFS+53+1]; chkdat = (xframe[ofs+53]<<8) | xframe[ofs+53+1];
chk_ok = (chkdat == chkval); chk_ok = (chkdat == chkval);
if (option_raw) { if (option_raw) {
@ -398,12 +398,12 @@ int print_frame() {
int val; int val;
// SN // SN
sn = xframe[OFS] | (xframe[OFS+1]<<8) | (xframe[OFS+2]<<16) | (xframe[OFS+3]<<24); sn = xframe[ofs] | (xframe[ofs+1]<<8) | (xframe[ofs+2]<<16) | (xframe[ofs+3]<<24);
// counter // counter
cnt = xframe[OFS+4] | (xframe[OFS+5]<<8); cnt = xframe[ofs+4] | (xframe[ofs+5]<<8);
ui8_t frid = xframe[OFS+6]; ui8_t frid = xframe[ofs+6];
if (frid == 1) if (frid == 1)
{ {
@ -436,7 +436,7 @@ int print_frame() {
// time/UTC // time/UTC
int hms; int hms;
hms = xframe[OFS+7] | (xframe[OFS+8]<<8) | (xframe[OFS+9]<<16); hms = xframe[ofs+7] | (xframe[ofs+8]<<8) | (xframe[ofs+9]<<16);
hms &= 0x3FFFF; hms &= 0x3FFFF;
//printf(" (%6d) ", hms); //printf(" (%6d) ", hms);
ui8_t h = hms / 10000; ui8_t h = hms / 10000;
@ -448,30 +448,35 @@ int print_frame() {
gpx.sec = s; gpx.sec = s;
// alt // alt
val = xframe[OFS+13] | (xframe[OFS+14]<<8) | (xframe[OFS+15]<<16); val = xframe[ofs+13] | (xframe[ofs+14]<<8) | (xframe[ofs+15]<<16);
val >>= 4; val >>= 4;
val &= 0x7FFFF; // int19 ? val &= 0x7FFFF; // int19 ?
//if (val & 0x40000) val -= 0x80000; ?? or sign bit ? //if (val & 0x40000) val -= 0x80000; ?? or sign bit ?
float alt = val / 10.0f; float alt = val / 10.0f;
printf(" alt: %.1f ", alt); // MSL printf(" alt: %.1f ", alt); // MSL
gpx.alt = alt; gpx.alt = alt;
int val_alt = val;
// lat // lat
val = xframe[OFS+15] | (xframe[OFS+16]<<8) | (xframe[OFS+17]<<16) | (xframe[OFS+18]<<24); val = xframe[ofs+15] | (xframe[ofs+16]<<8) | (xframe[ofs+17]<<16) | (xframe[ofs+18]<<24);
val >>= 7; val >>= 7;
val &= 0x1FFFFFF; // int25 ? ?? sign NMEA N/S ? val &= 0x1FFFFFF; // int25 ? ?? sign NMEA N/S ?
//if (val & 0x1000000) val -= 0x2000000; // sign bit ? (or 90 -> -90 wrap ?) //if (val & 0x1000000) val -= 0x2000000; // sign bit ? (or 90 -> -90 wrap ?)
float lat = val / 1e5f; float lat = val / 1e5f;
printf(" lat: %.4f ", lat); printf(" lat: %.4f ", lat);
gpx.lat = lat; gpx.lat = lat;
int val_lat = val;
// lon // lon
val = xframe[OFS+19] | (xframe[OFS+20]<<8) | (xframe[OFS+21]<<16)| (xframe[OFS+22]<<24); val = xframe[ofs+19] | (xframe[ofs+20]<<8) | (xframe[ofs+21]<<16)| (xframe[ofs+22]<<24);
val &= 0x3FFFFFF; // int26 ? ?? sign NMEA E/W ? val &= 0x3FFFFFF; // int26 ? ?? sign NMEA E/W ?
//if (val & 0x2000000) val -= 0x4000000; // or sign bit ? (or 180 -> -180 wrap ?) //if (val & 0x2000000) val -= 0x4000000; // or sign bit ? (or 180 -> -180 wrap ?)
float lon = val / 1e5f; float lon = val / 1e5f;
printf(" lon: %.4f ", lon); printf(" lon: %.4f ", lon);
gpx.lon = lon; gpx.lon = lon;
int val_lon = val;
int zero_pos = val_alt == 0 && val_lat == 0 && val_lon == 0;
// checksum // checksum
printf(" %s", chk_ok ? "[OK]" : "[NO]"); printf(" %s", chk_ok ? "[OK]" : "[NO]");
@ -480,7 +485,7 @@ int print_frame() {
printf("\n"); printf("\n");
// JSON // JSON
if (option_json && gpx.chk2ok) { if (option_json && gpx.chk2ok && !zero_pos) {
if (gpx.chk1ok && gpx.sn2 == gpx.sn1 && gpx.cnt2 == gpx.cnt1) // double check, unreliable checksums if (gpx.chk1ok && gpx.sn2 == gpx.sn1 && gpx.cnt2 == gpx.cnt1) // double check, unreliable checksums
{ {
char *ver_jsn = NULL; char *ver_jsn = NULL;
@ -493,6 +498,10 @@ int print_frame() {
// if data from subframe1, // if data from subframe1,
// check gpx.chk1ok && gpx.sn1==gpx.sn2 && gpx.cnt1==gpx.cnt2 // check gpx.chk1ok && gpx.sn1==gpx.sn2 && gpx.cnt1==gpx.cnt2
if (option_pn9) {
fprintf(stdout, ", \"subtype\": \"WXR_PN9\"");
}
if (gpx.jsn_freq > 0) { if (gpx.jsn_freq > 0) {
fprintf(stdout, ", \"freq\": %d", gpx.jsn_freq ); fprintf(stdout, ", \"freq\": %d", gpx.jsn_freq );
} }
@ -527,6 +536,7 @@ int main(int argc, char **argv) {
int header_found = 0; int header_found = 0;
int cfreq = -1; int cfreq = -1;
char *hdr = header;
fpname = argv[0]; fpname = argv[0];
++argv; ++argv;
@ -538,6 +548,7 @@ int main(int argc, char **argv) {
fprintf(stderr, " -b\n"); fprintf(stderr, " -b\n");
return 0; return 0;
} }
else if (strcmp(*argv, "--pn9") == 0) { option_pn9 = 1; }
else if ( (strcmp(*argv, "-i") == 0) || (strcmp(*argv, "--invert") == 0) ) { else if ( (strcmp(*argv, "-i") == 0) || (strcmp(*argv, "--invert") == 0) ) {
option_inv = 1; option_inv = 1;
} }
@ -575,6 +586,11 @@ int main(int argc, char **argv) {
} }
if (!wavloaded) fp = stdin; if (!wavloaded) fp = stdin;
if (option_pn9) {
baudrate = BAUD_RATE_PN9;
hdr = header_pn9;
ofs = OFS_PN9;
}
if ( !option_softin ) { if ( !option_softin ) {
i = read_wav_header(fp); i = read_wav_header(fp);
@ -592,7 +608,7 @@ int main(int argc, char **argv) {
{ {
float s = 0.0f; float s = 0.0f;
int bit = 0; int bit = 0;
sample_rate = BAUD_RATE; sample_rate = baudrate;
sample_count = 0; sample_count = 0;
while (!f32soft_read(fp, &s)) { while (!f32soft_read(fp, &s)) {
@ -605,12 +621,12 @@ int main(int argc, char **argv) {
if (!header_found) if (!header_found)
{ {
h = compare(); //h2 = compare2(); h = compare(hdr); //h2 = compare2(hdr);
if ((h >= HEADLEN)) { if ((h >= HEADLEN)) {
header_found = 1; header_found = 1;
fflush(stdout); fflush(stdout);
if (option_timestamp) printf("<%8.3f> ", sample_count/(double)sample_rate); if (option_timestamp) printf("<%8.3f> ", sample_count/(double)sample_rate);
strncpy(frame_bits, header, HEADLEN); strncpy(frame_bits, hdr, HEADLEN);
bit_count += HEADLEN; bit_count += HEADLEN;
frames++; frames++;
} }
@ -649,12 +665,12 @@ int main(int argc, char **argv) {
if (!header_found) if (!header_found)
{ {
h = compare(); //h2 = compare2(); h = compare(hdr); //h2 = compare2(hdr);
if ((h >= HEADLEN)) { if ((h >= HEADLEN)) {
header_found = 1; header_found = 1;
fflush(stdout); fflush(stdout);
if (option_timestamp) printf("<%8.3f> ", sample_count/(double)sample_rate); if (option_timestamp) printf("<%8.3f> ", sample_count/(double)sample_rate);
strncpy(frame_bits, header, HEADLEN); strncpy(frame_bits, hdr, HEADLEN);
bit_count += HEADLEN; bit_count += HEADLEN;
frames++; frames++;
} }