Skip to content

Commit

Permalink
Add support for WxR-301 PN9 variant
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Jessop authored and Mark Jessop committed May 31, 2024
1 parent 111f03f commit bbb4322
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 69 deletions.
2 changes: 1 addition & 1 deletion auto_rx/autorx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.

__version__ = "1.7.3-beta11"
__version__ = "1.7.3-beta12"


# Global Variables
Expand Down
3 changes: 2 additions & 1 deletion auto_rx/autorx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ def read_auto_rx_config(filename, no_sdr_test=False):
"MEISEI": True,
"MTS01": False, # Until we test it
"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,
}

Expand Down
76 changes: 73 additions & 3 deletions auto_rx/autorx/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"MRZ",
"MTS01",
"UDP",
"WXR301"
"WXR301",
"WXRPN9"
]

# Known 'Drifty' Radiosonde types
Expand Down Expand Up @@ -120,7 +121,8 @@ class SondeDecoder(object):
"MRZ",
"MTS01",
"UDP",
"WXR301"
"WXR301",
"WXRPN9"
]

def __init__(
Expand Down Expand Up @@ -762,7 +764,31 @@ def generate_decoder_command(self):
# 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"

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":
# UDP Input Mode.
Expand Down Expand Up @@ -1313,6 +1339,50 @@ def generate_decoder_command_experimental(self):
demod_stats = FSKDemodStats(averaging_time=5.0, peak_hold=True)
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:
return None

Expand Down Expand Up @@ -1700,7 +1770,7 @@ def handle_decoder_line(self, data):

# Weathex Specific Actions
# 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.
_telemetry["datetime_dt"] = fix_datetime(_telemetry["datetime"])
# Re-generate the datetime string.
Expand Down
9 changes: 9 additions & 0 deletions auto_rx/autorx/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@ def detect_sonde(
# to do no whitening on the signal.
_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:
_sonde_type = None

Expand Down
10 changes: 10 additions & 0 deletions auto_rx/autorx/sondehub.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ def reformat_data(self, telemetry):
_output["type"] = "WxR-301D"
_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:
self.log_error("Unknown Radiosonde Type %s" % telemetry["type"])
return None
Expand Down
1 change: 1 addition & 0 deletions auto_rx/autorx/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,7 @@ <h2>Decoder Control</h2>
<option value="MRZ">MRZ-H1</option>
<option value="MTS01">MTS01</option>
<option value="WXR301">WXR301</option>
<option value="WXRPN9">WXR301 (PN9 variant)</option>
</select>
<div style="display:inline;vertical-align:middle;">
<button id="start-decoder" onclick="start_decoder();">Start</button>
Expand Down
4 changes: 4 additions & 0 deletions auto_rx/autorx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ def short_type_lookup(type_name):
return "Meteosis MTS01"
elif type_name == "WXR301":
return "Weathex WxR-301D"
elif type_name == "WXRPN9":
return "Weathex WxR-301D (PN9 Variant)"
else:
return "Unknown"

Expand Down Expand Up @@ -256,6 +258,8 @@ def short_short_type_lookup(type_name):
return "MTS01"
elif type_name == "WXR301":
return "WXR301"
elif type_name == "WXRPN9":
return "WXR301(PN9)"
else:
return "Unknown"

Expand Down
55 changes: 32 additions & 23 deletions scan/dft_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ static char weathex_header[] =
"10101010""10101010""10101010" // AA AA AA (preamble)
"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 {
int sps; // header: symbol rate, baud
Expand All @@ -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 set_lpIQ = 0.0;

#define tn_DFM 2
#define tn_RS41 3
#define tn_RS92 4
#define tn_M10 5
#define tn_M20 6
#define tn_LMS6 8
#define tn_MEISEI 9
#define tn_MRZ 12
#define tn_MTS01 13
#define tn_C34C50 15
#define tn_WXR301 16
#define tn_MK2LMS 18
#define tn_IMET5 24
#define tn_IMETa 25
#define tn_IMET4 26
#define tn_IMET1rs 28
#define tn_IMET1ab 29

#define Nrs 16
#define idxIMETafsk 13
#define idxRS 14
#define idxI4 15
#define tn_DFM 2
#define tn_RS41 3
#define tn_RS92 4
#define tn_M10 5
#define tn_M20 6
#define tn_LMS6 8
#define tn_MEISEI 9
#define tn_MRZ 12
#define tn_MTS01 13
#define tn_C34C50 15
#define tn_WXR301 16
#define tn_WXRpn9 17
#define tn_MK2LMS 18
#define tn_IMET5 24
#define tn_IMETa 25
#define tn_IMET4 26
#define tn_IMET1rs 28
#define tn_IMET1ab 29

#define Nrs 17
#define idxIMETafsk 14
#define idxRS 15
#define idxI4 16
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 ?
{ 4800, 0, 0, rs41_header, 0.5, 0.0, 0.70, 2, NULL, "RS41", tn_RS41, 0, 1, 0.0, 0.0},
Expand All @@ -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},
{ 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},
{ 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, 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 ...
Expand All @@ -184,6 +190,7 @@ static rsheader_t rs_hdr[Nrs] = {
static int idx_MTS01 = -1,
idx_C34C50 = -1,
idx_WXR301 = -1,
idx_WXRPN9 = -1,
idx_IMET1AB = -1;


Expand Down Expand Up @@ -1143,6 +1150,7 @@ static int init_buffers() {
#endif
#ifdef NOWXR301
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
#ifdef NOIMET1AB
if ( strncmp(rs_hdr[j].type, "IMET1AB", 7) == 0 ) idx_IMET1AB = j;
Expand All @@ -1153,7 +1161,7 @@ static int init_buffers() {
rs_hdr[j].spb = sample_rate/(float)rs_hdr[j].sps;
rs_hdr[j].hLen = strlen(rs_hdr[j].header);
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].L > Lmax) Lmax = rs_hdr[j].L;
}
Expand Down Expand Up @@ -1477,6 +1485,7 @@ int main(int argc, char **argv) {
if ( j == idx_MTS01 ) continue; // only ifdef NOMTS01
if ( j == idx_C34C50 ) continue; // only ifdef NOC34C50
if ( j == idx_WXR301 ) continue; // only ifdef NOWXR301
if ( j == idx_WXRPN9 ) continue; // only ifdef NOWXR301
if ( j == idx_IMET1AB ) continue; // only ifdef NOIMET1AB

mv0_pos[j] = mv_pos[j];
Expand Down
Loading

0 comments on commit bbb4322

Please sign in to comment.