From b688084c1bba08771d258f1eaa48776f9c49a1be Mon Sep 17 00:00:00 2001 From: Mark Jessop Date: Mon, 14 Aug 2023 14:58:26 +0930 Subject: [PATCH] Working towards WXR301D support. Also added Wideband option --- .gitignore | 2 + Makefile | 1 + auto_rx/auto_rx.py | 4 +- auto_rx/autorx/__init__.py | 2 +- auto_rx/autorx/config.py | 45 +- auto_rx/autorx/decode.py | 52 ++- auto_rx/autorx/scan.py | 39 +- auto_rx/autorx/sondehub.py | 5 + auto_rx/autorx/templates/index.html | 5 +- auto_rx/autorx/utils.py | 9 +- auto_rx/build.sh | 1 + auto_rx/station.cfg.example | 10 +- auto_rx/station.cfg.example.network | 7 + auto_rx/utils/plot_rtl_power.py | 18 +- scan/dft_detect.c | 79 +++- weathex/Makefile | 11 + weathex/weathex301d.c | 623 ++++++++++++++++++++++++++++ 17 files changed, 853 insertions(+), 60 deletions(-) create mode 100644 weathex/Makefile create mode 100644 weathex/weathex301d.c diff --git a/.gitignore b/.gitignore index 62ec1fe..986e154 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ auto_rx/imet54mod auto_rx/mXXmod auto_rx/mp3h1mod auto_rx/mts01mod +auto_rx/weathex301d m10 meisei100mod @@ -82,3 +83,4 @@ rs_module/rs41mod rs_module/rs92mod scan/reset_usb scan/rs_detect +weathex/weathex301d diff --git a/Makefile b/Makefile index 71addf1..8d3cca8 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ SUBDIRS := \ mk2a \ scan \ utils \ + weathex \ all: $(SUBDIRS) diff --git a/auto_rx/auto_rx.py b/auto_rx/auto_rx.py index 83610a4..3235a3e 100644 --- a/auto_rx/auto_rx.py +++ b/auto_rx/auto_rx.py @@ -181,6 +181,7 @@ def start_scanner(): ppm=autorx.sdr_list[_device_idx]["ppm"], bias=autorx.sdr_list[_device_idx]["bias"], save_detection_audio=config["save_detection_audio"], + wideband_sondes=config["wideband_sondes"], temporary_block_list=temporary_block_list, temporary_block_time=config["temporary_block_time"], ) @@ -272,7 +273,8 @@ def start_decoder(freq, sonde_type, continuous=False): rs92_ephemeris=rs92_ephemeris, rs41_drift_tweak=config["rs41_drift_tweak"], experimental_decoder=config["experimental_decoders"][_exp_sonde_type], - save_raw_hex=config["save_raw_hex"] + save_raw_hex=config["save_raw_hex"], + wideband_sondes=config["wideband_sondes"] ) autorx.sdr_list[_device_idx]["task"] = autorx.task_list[freq]["task"] diff --git a/auto_rx/autorx/__init__.py b/auto_rx/autorx/__init__.py index 9ee8a1a..d91039f 100644 --- a/auto_rx/autorx/__init__.py +++ b/auto_rx/autorx/__init__.py @@ -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. # PATCH - Small changes, or minor feature additions. -__version__ = "1.6.3-beta1" +__version__ = "1.6.3-beta2" # Global Variables diff --git a/auto_rx/autorx/config.py b/auto_rx/autorx/config.py index ff04798..8188465 100644 --- a/auto_rx/autorx/config.py +++ b/auto_rx/autorx/config.py @@ -175,6 +175,7 @@ def read_auto_rx_config(filename, no_sdr_test=False): "sondehub_enabled": True, "sondehub_upload_rate": 30, # "sondehub_contact_email": "none@none.com" # Commented out to ensure a warning message is shown on startup + "wideband_sondes": False, # Wideband sonde detection / decoding } try: @@ -455,27 +456,30 @@ 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": False, # No fsk_demod chain for this yet. "UDP": False, } auto_rx_config["decoder_spacing_limit"] = config.getint( "advanced", "decoder_spacing_limit" ) - auto_rx_config["experimental_decoders"]["RS41"] = config.getboolean( - "advanced", "rs41_experimental" - ) - auto_rx_config["experimental_decoders"]["RS92"] = config.getboolean( - "advanced", "rs92_experimental" - ) - auto_rx_config["experimental_decoders"]["M10"] = config.getboolean( - "advanced", "m10_experimental" - ) - auto_rx_config["experimental_decoders"]["DFM"] = config.getboolean( - "advanced", "dfm_experimental" - ) - auto_rx_config["experimental_decoders"]["LMS6"] = config.getboolean( - "advanced", "lms6-400_experimental" - ) + # Use 'experimental' (not really, anymore!) decoders for RS41, RS92, M10, DFM and LMS6-400. + # Don't allow overriding to the FM based decoders. + # auto_rx_config["experimental_decoders"]["RS41"] = config.getboolean( + # "advanced", "rs41_experimental" + # ) + # auto_rx_config["experimental_decoders"]["RS92"] = config.getboolean( + # "advanced", "rs92_experimental" + # ) + # auto_rx_config["experimental_decoders"]["M10"] = config.getboolean( + # "advanced", "m10_experimental" + # ) + # auto_rx_config["experimental_decoders"]["DFM"] = config.getboolean( + # "advanced", "dfm_experimental" + # ) + # auto_rx_config["experimental_decoders"]["LMS6"] = config.getboolean( + # "advanced", "lms6-400_experimental" + # ) try: auto_rx_config["web_control"] = config.getboolean("web", "web_control") @@ -760,6 +764,17 @@ def read_auto_rx_config(filename, no_sdr_test=False): auto_rx_config["email_encrypted_sonde_notifications"] = True + # 1.6.3 - Weathex WXR301d support + try: + auto_rx_config["wideband_sondes"] = config.getboolean( + "advanced", "wideband_sondes" + ) + except: + logging.warning( + "Config - Missing wideband_sondes option (new in v1.6.3), using default (False)" + ) + auto_rx_config["wideband_sondes"] = False + # If we are being called as part of a unit test, just return the config now. if no_sdr_test: return auto_rx_config diff --git a/auto_rx/autorx/decode.py b/auto_rx/autorx/decode.py index a996b30..455f24c 100644 --- a/auto_rx/autorx/decode.py +++ b/auto_rx/autorx/decode.py @@ -40,6 +40,7 @@ VALID_SONDE_TYPES = [ "MRZ", "MTS01", "UDP", + "WXR301" ] # Known 'Drifty' Radiosonde types @@ -119,6 +120,7 @@ class SondeDecoder(object): "MRZ", "MTS01", "UDP", + "WXR301" ] def __init__( @@ -143,7 +145,8 @@ class SondeDecoder(object): rs92_ephemeris=None, rs41_drift_tweak=False, experimental_decoder=False, - save_raw_hex=False + save_raw_hex=False, + wideband_sondes=False ): """ Initialise and start a Sonde Decoder. @@ -182,6 +185,7 @@ class SondeDecoder(object): rs41_drift_tweak (bool): If True, add a high-pass filter in the decode chain, which can improve decode performance on drifty SDRs. experimental_decoder (bool): If True, use the experimental fsk_demod-based decode chain. save_raw_hex (bool): If True, save the raw hex output from the decoder to a file. + wideband_sondes (bool): If True, use a wider bandwidth for iMet sondes. Does not affect settings for any other radiosonde types. """ # Thread running flag self.decoder_running = True @@ -212,6 +216,7 @@ class SondeDecoder(object): self.experimental_decoder = experimental_decoder self.save_raw_hex = save_raw_hex self.raw_file = None + self.wideband_sondes = wideband_sondes # Raw hex filename if self.save_raw_hex: @@ -521,7 +526,11 @@ class SondeDecoder(object): elif self.sonde_type == "IMET": # iMet-4 Sondes - _sample_rate = 48000 + # These samples rates probably need to be revisited. + if self.wideband_sondes: + _sample_rate = 96000 + else: + _sample_rate = 48000 decode_cmd = get_sdr_iq_cmd( sdr_type = self.sdr_type, @@ -718,6 +727,35 @@ class SondeDecoder(object): # Meteosis MTS01 decoder decode_cmd += f"./mts01mod --json --IQ 0.0 --lpIQ --dc - {_sample_rate} 16 2>/dev/null" + + elif self.sonde_type == "WXR301": + # Weathex WxR-301D + + _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" + + + elif self.sonde_type == "UDP": # UDP Input Mode. # Used only for testing of new decoders, prior to them being integrated into auto_rx. @@ -1607,6 +1645,16 @@ class SondeDecoder(object): "%Y-%m-%dT%H:%M:%SZ" ) + # Weathex Specific Actions + # Same datetime issues as with iMets, and LMS6 + if self.sonde_type == "WXR301": + # Fix up the time. + _telemetry["datetime_dt"] = fix_datetime(_telemetry["datetime"]) + # Re-generate the datetime string. + _telemetry["datetime"] = _telemetry["datetime_dt"].strftime( + "%Y-%m-%dT%H:%M:%SZ" + ) + # Grab a snapshot of modem statistics, if we are using an experimental decoder. if self.demod_stats is not None: if self.demod_stats.snr != -999.0: diff --git a/auto_rx/autorx/scan.py b/auto_rx/autorx/scan.py index 3c1b113..478711a 100644 --- a/auto_rx/autorx/scan.py +++ b/auto_rx/autorx/scan.py @@ -234,6 +234,7 @@ def detect_sonde( bias=False, save_detection_audio=False, ngp_tweak=False, + wideband_sondes=False ): """Receive some FM and attempt to detect the presence of a radiosonde. @@ -248,6 +249,7 @@ def detect_sonde( bias (bool): If True, enable the bias tee on the SDR. save_detection_audio (bool): Save the audio used in detection to a file. ngp_tweak (bool): When scanning in the 1680 MHz sonde band, use a narrower FM filter for better RS92-NGP detection. + wideband_sondes (bool): Use a wider detection filter to allow detection of Weathex and wideband iMet sondes. Returns: str/None: Returns None if no sonde found, otherwise returns a sonde type, from the following: @@ -262,7 +264,9 @@ def detect_sonde( """ # Notes: - # 400 MHz sondes: Use --bw 20 (20 kHz BW) + # 400 MHz sondes + # Normal mode: 48 kHz sample rate, 20 kHz IF BW + # Wideband mode: 96 kHz sample rate, 64 kHz IF BW # 1680 MHz RS92 Setting: --bw 32 # 1680 MHz LMS6-1680: Use FM demod. as usual. @@ -280,16 +284,20 @@ def detect_sonde( # Adjust the detection bandwidth based on the band the scanning is occuring in. if frequency < 1000e6: - # 400-406 MHz sondes - use a 20 kHz detection bandwidth. + # 400-406 MHz sondes _mode = "IQ" - _iq_bw = 48000 - _if_bw = 20 + if wideband_sondes: + _iq_bw = 96000 + _if_bw = 64 + else: + _iq_bw = 48000 + _if_bw = 20 - # Try and avoid the RTLSDR 403.2 MHz spur. - # Note that this is only goign to work if we are detecting on 403.210 or 403.190 MHz. - if (abs(403200000 - frequency) < 20000) and (sdr_type == "RTLSDR"): - logging.debug("Scanner - Narrowing detection IF BW to avoid RTLSDR spur.") - _if_bw = 15 + # Try and avoid the RTLSDR 403.2 MHz spur. + # Note that this is only goign to work if we are detecting on 403.210 or 403.190 MHz. + if (abs(403200000 - frequency) < 20000) and (sdr_type == "RTLSDR"): + logging.debug("Scanner - Narrowing detection IF BW to avoid RTLSDR spur.") + _if_bw = 15 else: # 1680 MHz sondes @@ -341,7 +349,7 @@ def detect_sonde( # ) # Saving of Debug audio, if enabled, if save_detection_audio: - detect_iq_path = os.path.join(autorx.logging_path, f"detect_IQ_{frequency}_{str(rtl_device_idx)}.raw") + detect_iq_path = os.path.join(autorx.logging_path, f"detect_IQ_{frequency}_{_iq_bw}_{str(rtl_device_idx)}.raw") rx_test_command += f" tee {detect_iq_path} |" rx_test_command += os.path.join( @@ -594,6 +602,13 @@ def detect_sonde( else: _sonde_type = "MTS01" + elif "WXR301" in _type: + logging.debug( + "Scanner (%s) - Detected a Weathex WxR-301D Sonde! (Score: %.2f, Offset: %.1f Hz)" + % (_sdr_name, _score, _offset_est) + ) + _sonde_type = "WXR301" + else: _sonde_type = None @@ -648,6 +663,7 @@ class SondeScanner(object): temporary_block_list={}, temporary_block_time=60, ngp_tweak=False, + wideband_sondes=False ): """Initialise a Sonde Scanner Object. @@ -697,6 +713,7 @@ class SondeScanner(object): temporary_block_list (dict): A dictionary where each attribute represents a frequency that should be blocked for a set time. temporary_block_time (int): How long (minutes) frequencies in the temporary block list should remain blocked for. ngp_tweak (bool): Narrow the detection filter when searching for 1680 MHz sondes, to enhance detection of RS92-NGPs. + wideband_sondes (bool): Use a wider detection filter to allow detection of Weathex and wideband iMet sondes. """ # Thread flag. This is set to True when a scan is running. @@ -735,6 +752,7 @@ class SondeScanner(object): self.callback = callback self.save_detection_audio = save_detection_audio + self.wideband_sondes = wideband_sondes # Temporary block list. self.temporary_block_list = temporary_block_list.copy() @@ -1100,6 +1118,7 @@ class SondeScanner(object): bias=self.bias, dwell_time=self.detect_dwell_time, save_detection_audio=self.save_detection_audio, + wideband_sondes=self.wideband_sondes ) if detected != None: diff --git a/auto_rx/autorx/sondehub.py b/auto_rx/autorx/sondehub.py index 141c59d..fbb3b03 100644 --- a/auto_rx/autorx/sondehub.py +++ b/auto_rx/autorx/sondehub.py @@ -226,6 +226,11 @@ class SondehubUploader(object): _output["type"] = "MTS01" _output["serial"] = telemetry["id"].split("-")[1] + elif telemetry["type"] == "WXR301": + _output["manufacturer"] = "Weathex" + _output["type"] = "WxR-301D" + _output["serial"] = telemetry["id"].split("-")[1] + else: self.log_error("Unknown Radiosonde Type %s" % telemetry["type"]) return None diff --git a/auto_rx/autorx/templates/index.html b/auto_rx/autorx/templates/index.html index 2bf751d..6efba9a 100644 --- a/auto_rx/autorx/templates/index.html +++ b/auto_rx/autorx/templates/index.html @@ -471,8 +471,8 @@ {title:'Freq (MHz)', field:"freq", headerSort:true}, {title:"ID", field:"id", width:125, headerSort:true, formatter:function(cell, formatterParams, onRendered){ _cell_data = cell.getData(); - _id = _cell_data.id.replace(/^(DFM|M10|M20|IMET|IMET5|IMET54|MRZ|IMS100|RS11G|MTS01)-/,""); - _sondehub_id = _cell_data.id.replace(/^(DFM|M10|M20|IMET|IMET5|IMET54|MRZ|IMS100|RS11G|MTS01)-/,""); + _id = _cell_data.id.replace(/^(DFM|M10|M20|IMET|IMET5|IMET54|MRZ|IMS100|RS11G|MTS01|WXR)-/,""); + _sondehub_id = _cell_data.id.replace(/^(DFM|M10|M20|IMET|IMET5|IMET54|MRZ|IMS100|RS11G|MTS01|WXR)-/,""); // Add Sondehub Link _id += " " + "" + ""; @@ -1658,6 +1658,7 @@ +
diff --git a/auto_rx/autorx/utils.py b/auto_rx/autorx/utils.py index 9a016af..83ba65d 100644 --- a/auto_rx/autorx/utils.py +++ b/auto_rx/autorx/utils.py @@ -43,7 +43,8 @@ REQUIRED_RS_UTILS = [ "m20mod", "imet4iq", "mts01mod", - "iq_dec" + "iq_dec", + "weathex301d" ] _timeout_cmd = None @@ -158,7 +159,7 @@ def strip_sonde_serial(serial): """ Strip off any leading sonde type that may be present in a serial number """ # Look for serials with prefixes matching the following known sonde types. - _re = re.compile("^(DFM|M10|M20|IMET|IMET5|IMET54|MRZ|LMS6|IMS100|RS11G|MTS01)-") + _re = re.compile("^(DFM|M10|M20|IMET|IMET5|IMET54|MRZ|LMS6|IMS100|RS11G|MTS01|WXR)-") # If we have a match, return the trailing part of the serial, re-adding # any - separators if they exist. @@ -206,6 +207,8 @@ def short_type_lookup(type_name): return "Meteo-Radiy MRZ" elif type_name == "MTS01": return "Meteosis MTS01" + elif type_name == "WXR301": + return "Weathex WxR-301D" else: return "Unknown" @@ -246,6 +249,8 @@ def short_short_type_lookup(type_name): return "MRZ" elif type_name == "MTS01": return "MTS01" + elif type_name == "WXR301": + return "WXR301" else: return "Unknown" diff --git a/auto_rx/build.sh b/auto_rx/build.sh index 0c84746..84e6ac6 100755 --- a/auto_rx/build.sh +++ b/auto_rx/build.sh @@ -38,5 +38,6 @@ mv ../demod/mod/imet54mod . mv ../demod/mod/mp3h1mod . mv ../demod/mod/mts01mod . mv ../demod/mod/iq_dec . +mv ../weathex/weathex301d . echo "Done!" diff --git a/auto_rx/station.cfg.example b/auto_rx/station.cfg.example index 081f3e5..7a8ce8e 100644 --- a/auto_rx/station.cfg.example +++ b/auto_rx/station.cfg.example @@ -590,8 +590,6 @@ lms6-1680_experimental = False # If someone can confirm that this works, I'll set it to True by default! mrz_experimental = False - - # Note: As iMet-4 sondes use AFSK, using fsk_demod does not give any advantage, so there is no experimental decoder for them. # Optimize 1680 MHz Scanning for RS92-NGP Sondes @@ -600,6 +598,14 @@ mrz_experimental = False # Set this to True if you are sure that only RS92-NGPs are flying in your area. ngp_tweak = False +# Wideband Radiosonde Detection: +# Enables some tweaks to better handle detection and decoding of the following radiosonde types: +# - Intermet iMet-1/4 (Wideband versions) +# - Weathex WxR-301d +# If this is enabled in areas with 'narrowband' sondes as well (RS41, DFM, narrowband iMet, etc...) there will likely +# be degradation in detection and decode performance. +wideband_sondes = False + ###################### # POSITION FILTERING # diff --git a/auto_rx/station.cfg.example.network b/auto_rx/station.cfg.example.network index d82cebd..f8ea1f2 100644 --- a/auto_rx/station.cfg.example.network +++ b/auto_rx/station.cfg.example.network @@ -597,6 +597,13 @@ mrz_experimental = False # Set this to True if you are sure that only RS92-NGPs are flying in your area. ngp_tweak = False +# Wideband Radiosonde Detection: +# Enables some tweaks to better handle detection and decoding of the following radiosonde types: +# - Intermet iMet-1/4 (Wideband versions) +# - Weathex WxR-301d +# If this is enabled in areas with 'narrowband' sondes as well (RS41, DFM, narrowband iMet, etc...) there will likely +# be degradation in detection and decode performance. +wideband_sondes = False ###################### # POSITION FILTERING # diff --git a/auto_rx/utils/plot_rtl_power.py b/auto_rx/utils/plot_rtl_power.py index b3832be..2de70c6 100644 --- a/auto_rx/utils/plot_rtl_power.py +++ b/auto_rx/utils/plot_rtl_power.py @@ -7,7 +7,7 @@ # import matplotlib.pyplot as plt import numpy as np -from StringIO import StringIO +from io import StringIO import sys # Need to keep this in sync with auto_rx.py as we're not set up to do relative imports yet. @@ -59,13 +59,15 @@ def read_rtl_power(filename): if __name__ == '__main__': - filename = sys.argv[1] + filename = sys.argv[1] - (freq, power, freq_step) = read_rtl_power(filename) + (freq, power, freq_step) = read_rtl_power(filename) - plt.plot(freq/1e6, power) - plt.xlabel("Frequency (MHz)") - plt.ylabel("Power (dB?)") - plt.title("rtl_power output: %s" % filename) - plt.show() + print(f"Median value: {np.median(power):.2f} dB") + + plt.plot(freq/1e6, power) + plt.xlabel("Frequency (MHz)") + plt.ylabel("Power (dB?)") + plt.title("rtl_power output: %s" % filename) + plt.show() diff --git a/scan/dft_detect.c b/scan/dft_detect.c index 3198971..32ea4cd 100644 --- a/scan/dft_detect.c +++ b/scan/dft_detect.c @@ -32,6 +32,7 @@ static int option_verbose = 0, // ausfuehrliche Anzeige option_dc = 0, option_silent = 0, option_cont = 0, + option_d2 = 0, option_pcmraw = 0, option_singleLpIQ = 0, wavloaded = 0; @@ -107,8 +108,13 @@ static char imet1rs_header[] = // C34/C50: 2400 baud, 1:2900Hz/0:4800Hz static char c34_preheader[] = -"01010101010101010101010101010101"; // 2900 Hz tone -// dft, dB-max(1000Hz..5000Hz) = 2900Hz ? + "01010101010101010101010101010101"; // 2900 Hz tone + // dft, dB-max(1000Hz..5000Hz) = 2900Hz ? + + +static char weathex_header[] = + "10101010""10101010""10101010" // AA AA AA (preamble) + "00101101""11010100"; //"10101010"; // 2D D4 55/AA typedef struct { @@ -144,6 +150,7 @@ static float set_lpIQ = 0.0; #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 @@ -151,10 +158,10 @@ static float set_lpIQ = 0.0; #define tn_IMET1rs 28 #define tn_IMET1ab 29 -#define Nrs 15 -#define idxIMETafsk 12 -#define idxRS 13 -#define idxI4 14 +#define Nrs 16 +#define idxIMETafsk 13 +#define idxRS 14 +#define idxI4 15 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}, @@ -167,6 +174,7 @@ static rsheader_t rs_hdr[Nrs] = { { 2400, 0, 0, mrz_header, 1.5, 0.0, 0.80, 2, NULL, "MRZ", tn_MRZ, 0, 1, 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 + { 4800, 0, 0, weathex_header, 1.0, 0.0, 0.65, 2, NULL, "WXR301", tn_WXR301, 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 ... @@ -175,9 +183,27 @@ static rsheader_t rs_hdr[Nrs] = { static int idx_MTS01 = -1, idx_C34C50 = -1, + idx_WXR301 = -1, idx_IMET1AB = -1; +static int rs_detect2[Nrs]; + +static int rs_d2() { + int tn = 0; + for (tn = 0; tn < Nrs; tn++) { + if ( rs_detect2[tn] > 1 ) break; + } + return tn; +} + +static int reset_d2() { + int n = 0; + for (n = 0; n < Nrs; n++) rs_detect2[n] = 0; + return 0; +} + + /* // m10-false-positive: // m10-preamble similar to rs41-preamble, parts of rs92/imet1ab, imet1ab; diffs: @@ -1115,6 +1141,9 @@ static int init_buffers() { #ifdef NOC34C50 if ( strncmp(rs_hdr[j].type, "C34C50", 6) == 0 ) idx_C34C50 = j; #endif + #ifdef NOWXR301 + if ( strncmp(rs_hdr[j].type, "WXR301", 5) == 0 ) idx_WXR301 = j; + #endif #ifdef NOIMET1AB if ( strncmp(rs_hdr[j].type, "IMET1AB", 7) == 0 ) idx_IMET1AB = j; #endif @@ -1124,7 +1153,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_IMET1AB) { + if (j != idx_MTS01 && j != idx_C34C50 && j != idx_WXR301 && 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; } @@ -1302,6 +1331,8 @@ int main(int argc, char **argv) { int j_max; float mv_max; + int d2_tn = Nrs; + #ifdef CYGWIN _setmode(fileno(stdin), _O_BINARY); // _setmode(_fileno(stdin), _O_BINARY); @@ -1364,6 +1395,9 @@ int main(int argc, char **argv) { if (*argv) tl = atof(*argv); else return -50; } + else if ( (strcmp(*argv, "-d2") == 0) ) { + option_d2 = 1; + } else if ( (strcmp(*argv, "--ch2") == 0) ) { wav_channel = 1; } // right channel (default: 0=left) else if ( (strcmp(*argv, "--ths") == 0) ) { ++argv; @@ -1397,6 +1431,9 @@ int main(int argc, char **argv) { } if (!wavloaded) fp = stdin; + if (option_d2) { + option_cont = 0; + } if (option_pcmraw == 0) { j = read_wav_header(fp, wav_channel); @@ -1439,6 +1476,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_IMET1AB ) continue; // only ifdef NOIMET1AB mv0_pos[j] = mv_pos[j]; @@ -1547,16 +1585,23 @@ int main(int argc, char **argv) { if (header_found) { if (!option_silent && (mv[j] > rs_hdr[j].thres || mv[j] < -rs_hdr[j].thres)) { - if (option_verbose) fprintf(stdout, "sample: %d\n", mv_pos[j]); - fprintf(stdout, "%s: %.4f", rs_hdr[j].type, mv[j]); - if (option_dc && option_iq) { - fprintf(stdout, " , %+.1fHz", rs_hdr[j].df*sr_base); - if (option_verbose) { - fprintf(stdout, " [ fq-ofs: %+.6f", rs_hdr[j].df); - fprintf(stdout, " = %+.1fHz ]", rs_hdr[j].df*sr_base); - } + if (option_d2) { + rs_detect2[j] += 1; + d2_tn = rs_d2(); + if ( d2_tn == Nrs ) header_found = 0; + } + if ( !option_d2 || j == d2_tn ) { + if (option_verbose) fprintf(stdout, "sample: %d\n", mv_pos[j]); + fprintf(stdout, "%s: %.4f", rs_hdr[j].type, mv[j]); + if (option_dc && option_iq) { + fprintf(stdout, " , %+.1fHz", rs_hdr[j].df*sr_base); + if (option_verbose) { + fprintf(stdout, " [ fq-ofs: %+.6f", rs_hdr[j].df); + fprintf(stdout, " = %+.1fHz ]", rs_hdr[j].df*sr_base); + } + } + fprintf(stdout, "\n"); } - fprintf(stdout, "\n"); } // if ((j < 3) && mv[j] < 0) header_found = -1; @@ -1570,7 +1615,7 @@ int main(int argc, char **argv) { } } - if (header_found && !option_cont) break; + if (header_found && !option_cont || d2_tn < Nrs) break; header_found = 0; for (j = 0; j < Nrs; j++) mv[j] = 0.0; } diff --git a/weathex/Makefile b/weathex/Makefile new file mode 100644 index 0000000..f4d21f5 --- /dev/null +++ b/weathex/Makefile @@ -0,0 +1,11 @@ +CFLAGS += -Ofast +LDLIBS = -lm + +PROGRAMS := weathex301d + +all: $(PROGRAMS) + +weathex301d: weathex301d.o + +clean: + $(RM) $(PROGRAMS) $(PROGRAMS:=.o) diff --git a/weathex/weathex301d.c b/weathex/weathex301d.c new file mode 100644 index 0000000..529c7cb --- /dev/null +++ b/weathex/weathex301d.c @@ -0,0 +1,623 @@ + +/* + Malaysia + 401100 kHz (64kHz wide) + 2023-05-12 ([ 4400] 12:20:37 alt: 12616.6 lat: 2.6785 lon: 101.5827) + 2023-07-27 ([ 6402] 00:47:32 alt: 26835.9 lat: 2.6918 lon: 101.5025) + Weathex WxR-301D w/o PN9 +*/ + +#include +#include +#include + + +// optional JSON "version" +// (a) set global +// gcc -DVERSION_JSN [-I] ... +#ifdef VERSION_JSN + #include "version_jsn.h" +#endif +// or +// (b) set local compiler option, e.g. +// gcc -DVER_JSN_STR=\"0.0.2\" ... + + +typedef unsigned char ui8_t; +typedef short i16_t; +typedef unsigned int ui32_t; + + +int option_verbose = 0, + option_raw = 0, + option_inv = 0, + option_b = 0, + option_json = 0, + option_timestamp = 0, + wavloaded = 0; +int wav_channel = 0; // audio channel: left + + +#define BAUD_RATE 4800.0 // (4997.2) // 5000 + +#define FRAMELEN 69 //64 +#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 HEADOFS 0 +char header[] = "10101010""10101010""10101010" // AA AA AA (preamble) + "00101101""11010100"; //"10101010"; // 2D D4 55/AA + +char buf[HEADLEN+1] = "xxxxxxxxxx\0"; +int bufpos = 0; + +char frame_bits[BITFRAMELEN+1]; +ui8_t frame_bytes[FRAMELEN+1]; +ui8_t xframe[FRAMELEN+1]; + + +/* ------------------------------------------------------------------------------------ */ + +int sample_rate = 0, bits_sample = 0, channels = 0; +float samples_per_bit = 0; + +int findstr(char *buff, char *str, int pos) { + int i; + for (i = 0; i < 4; i++) { + if (buff[(pos+i)%4] != str[i]) break; + } + return i; +} + +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) && strncmp(txt, "RF64", 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; + + + fprintf(stderr, "sample_rate: %d\n", sample_rate); + fprintf(stderr, "bits : %d\n", bits_sample); + fprintf(stderr, "channels : %d\n", channels); + + if (bits_sample != 8 && bits_sample != 16 && bits_sample != 32) return -1; + + if (sample_rate == 900001) sample_rate -= 1; + + samples_per_bit = sample_rate/(float)BAUD_RATE; + + fprintf(stderr, "samples/bit: %.2f\n", samples_per_bit); + + return 0; +} + +unsigned long sample_count = 0; +double bitgrenze = 0; + +int f32read_signed_sample(FILE *fp, float *s) { + int i; + unsigned int word = 0; + short *b = (short*)&word; + float *f = (float*)&word; + + for (i = 0; i < channels; i++) { + + if (fread( &word, bits_sample/8, 1, fp) != 1) return EOF; + + if (i == wav_channel) { // i = 0: links bzw. mono + //if (bits_sample == 8) sint = b-128; // 8bit: 00..FF, centerpoint 0x80=128 + //if (bits_sample == 16) sint = (short)b; + + if (bits_sample == 32) { + *s = *f; + } + else { + if (bits_sample == 8) { *b -= 128; } + *s = *b/128.0; + if (bits_sample == 16) { *s /= 256.0; } + } + } + } + + sample_count++; + + return 0; +} + +int par=1, par_alt=1; + +int read_bits_fsk(FILE *fp, int *bit, int *len) { + int n; + float s; + float l; + + n = 0; + do { + if (f32read_signed_sample(fp, &s) == EOF) return EOF; + //sample_count++; // in f32read_signed_sample() + par_alt = par; + par = (s >= 0) ? 1 : -1; + n++; + } while (par*par_alt > 0); + + l = (float)n / samples_per_bit; + + *len = (int)(l+0.5); + + if (!option_inv) *bit = (1+par_alt)/2; // oben 1, unten -1 + else *bit = (1-par_alt)/2; // sdr#= 0) *bit = 1; + else *bit = 0; + + if (option_inv) *bit ^= 1; + + return 0; +} + +int compare() { + int i=0; + while ((i < HEADLEN) && (buf[(bufpos+i) % HEADLEN] == header[HEADLEN+HEADOFS-1-i])) { + i++; + } + return i; +} + +char inv(char c) { + if (c == '0') return '1'; + if (c == '1') return '0'; + return c; +} + +int compare2() { + int i=0; + while ((i < HEADLEN) && (buf[(bufpos+i) % HEADLEN] == inv(header[HEADLEN+HEADOFS-1-i]))) { + i++; + } + return i; +} + +int bits2bytes(char *bitstr, ui8_t *bytes) { + int i, bit, d, byteval; + int bitpos, bytepos; + + bitpos = 0; + bytepos = 0; + + while (bytepos < FRAMELEN) { + + byteval = 0; + d = 1; + for (i = 0; i < 8; i++) { + //bit = bitstr[bitpos+i]; /* little endian */ + bit = bitstr[bitpos+7-i]; /* big endian */ + if (bit == '1') byteval += d; + else /*if ((bit == '0') */ byteval += 0; + d <<= 1; + } + bitpos += 8; + bytes[bytepos++] = byteval; + + } + + //while (bytepos < FRAME_LEN) bytes[bytepos++] = 0; + + return 0; +} + + +// PN9 Data Whitening +// cf. https://www.ti.com/lit/an/swra322/swra322.pdf +// https://destevez.net/2019/07/lucky-7-decoded/ +// +// counter low byte: frame[OFS+4] XOR 0xCC +// 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, + 0x57, 0x5E, 0x4B, 0x9C, 0x0E, 0xE9, 0xEA, 0x50, + 0x2A, 0xBE, 0xB4, 0x1B, 0xB6, 0xB0, 0x5D, 0xF1, + 0xE6, 0x9A, 0xE3, 0x45, 0xFD, 0x2C, 0x53, 0x18, + 0x0C, 0xCA, 0xC9, 0xFB, 0x49, 0x37, 0xE5, 0xA8, + 0x51, 0x3B, 0x2F, 0x61, 0xAA, 0x72, 0x18, 0x84, + 0x02, 0x23, 0x23, 0xAB, 0x63, 0x89, 0x51, 0xB3, + 0xE7, 0x8B, 0x72, 0x90, 0x4C, 0xE8, 0xFb, 0xC1}; + + +ui32_t xor8sum(ui8_t bytes[], int len) { + int j; + ui8_t xor8 = 0; + ui8_t sum8 = 0; + + for (j = 0; j < len; j++) { + xor8 ^= bytes[j]; + sum8 += bytes[j]; + } + //sum8 &= 0xFF; + + return (xor8 << 8) | sum8; +} + + +typedef struct { + ui32_t sn1; + ui32_t cnt1; + int chk1ok; + // + ui32_t sn2; + ui32_t cnt2; + int chk2ok; // GPS subframe + ui8_t hrs; + ui8_t min; + ui8_t sec; + float lat; + float lon; + float alt; + // + int jsn_freq; // freq/kHz (SDR) +} gpx_t; + +gpx_t gpx; + + +#define OFS 6 // xPN9: OFS=8, different baud + +int print_frame() { + int j; + int chkdat, chkval, chk_ok; + + bits2bytes(frame_bits, frame_bytes); + + for (j = 0; j < FRAMELEN; j++) { + ui8_t b = frame_bytes[j]; + //if (j >= 6) b ^= PN9b[(j-6)%64]; // PN9 baud diff + xframe[j] = b; + } + + chkval = xor8sum(xframe+OFS, 53); + chkdat = (xframe[OFS+53]<<8) | xframe[OFS+53+1]; + chk_ok = (chkdat == chkval); + + if (option_raw) { + if (option_raw == 1) { + for (j = 0; j < FRAMELEN; j++) { + //printf("%02X ", frame_bytes[j]); + printf("%02X ", xframe[j]); + } + printf(" # %s", chk_ok ? "[OK]" : "[NO]"); + if (option_verbose) printf(" # [%04X:%04X]", chkdat, chkval); + } + else { + for (j = 0; j < BITFRAMELEN; j++) { + printf("%c", frame_bits[j]); + //if (j % 8 == 7) printf(" "); + } + } + printf("\n"); + } + else { + + ui32_t sn; + ui32_t cnt; + int val; + + // SN + sn = xframe[OFS] | (xframe[OFS+1]<<8) | (xframe[OFS+2]<<16) | (xframe[OFS+3]<<24); + + // counter + cnt = xframe[OFS+4] | (xframe[OFS+5]<<8); + + ui8_t frid = xframe[OFS+6]; + + if (frid == 1) + { + gpx.chk1ok = chk_ok; + gpx.sn1 = sn; + gpx.cnt1 = cnt; + + if (option_verbose) { + + printf(" (%u) ", sn); //printf(" (0x%08X) ", sn); + printf(" [%5d] ", cnt); + + printf(" %s", chk_ok ? "[OK]" : "[NO]"); + if (option_verbose) printf(" # [%04X:%04X]", chkdat, chkval); + + printf("\n"); + } + } + else if (frid == 2) + { + gpx.chk2ok = chk_ok; + gpx.sn2 = sn; + gpx.cnt2 = cnt; + + // SN + printf(" (%u) ", sn); //printf(" (0x%08X) ", sn); + + // counter + printf(" [%5d] ", cnt); + + // time/UTC + int hms; + hms = xframe[OFS+7] | (xframe[OFS+8]<<8) | (xframe[OFS+9]<<16); + hms &= 0x3FFFF; + //printf(" (%6d) ", hms); + ui8_t h = hms / 10000; + ui8_t m = (hms % 10000) / 100; + ui8_t s = hms % 100; + printf(" %02d:%02d:%02d ", h, m, s); // UTC + gpx.hrs = h; + gpx.min = m; + gpx.sec = s; + + // alt + val = xframe[OFS+13] | (xframe[OFS+14]<<8) | (xframe[OFS+15]<<16); + val >>= 4; + val &= 0x7FFFF; // int19 ? + //if (val & 0x40000) val -= 0x80000; + float alt = val / 10.0f; + printf(" alt: %.1f ", alt); // MSL + gpx.alt = alt; + + // lat + val = xframe[OFS+15] | (xframe[OFS+16]<<8) | (xframe[OFS+17]<<16) | (xframe[OFS+18]<<24); + val >>= 7; + val &= 0x1FFFFFF; // int25 ? + if (val & 0x1000000) val -= 0x2000000; // sign ? (or 90 -> -90 wrap ?) + float lat = val / 1e5f; + printf(" lat: %.4f ", lat); + gpx.lat = lat; + + // lon + val = xframe[OFS+19] | (xframe[OFS+20]<<8) | (xframe[OFS+21]<<16)| (xframe[OFS+22]<<24); + val &= 0x3FFFFFF; // int26 ? + if (val & 0x2000000) val -= 0x4000000; // sign ? (or 180 -> -180 wrap ?) + float lon = val / 1e5f; + printf(" lon: %.4f ", lon); + gpx.lon = lon; + + // checksum + printf(" %s", chk_ok ? "[OK]" : "[NO]"); + if (option_verbose) printf(" # [%04X:%04X]", chkdat, chkval); + + printf("\n"); + + // JSON + if (option_json && gpx.chk2ok) { + char *ver_jsn = NULL; + fprintf(stdout, "{ \"type\": \"%s\"", "WXR301"); + fprintf(stdout, ", \"frame\": %u", gpx.cnt2); + fprintf(stdout, ", \"id\": \"WXR-%u\"", gpx.sn2); + fprintf(stdout, ", \"datetime\": \"%02d:%02d:%02dZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.2f", + gpx.hrs, gpx.min, gpx.sec, gpx.lat, gpx.lon, gpx.alt); + + // if data from subframe1, + // check gpx.chk1ok && gpx.sn1==gpx.sn2 && gpx.cnt1==gpx.cnt2 + + if (gpx.jsn_freq > 0) { + fprintf(stdout, ", \"freq\": %d", gpx.jsn_freq ); + } + + // Reference time/position + // (WxR-301D PN9) + fprintf(stdout, ", \"ref_datetime\": \"%s\"", "UTC" ); // {"GPS", "UTC"} GPS-UTC=leap_sec + fprintf(stdout, ", \"ref_position\": \"%s\"", "MSL" ); // {"GPS", "MSL"} GPS=ellipsoid , MSL=geoid + + #ifdef VER_JSN_STR + ver_jsn = VER_JSN_STR; + #endif + if (ver_jsn && *ver_jsn != '\0') fprintf(stdout, ", \"version\": \"%s\"", ver_jsn); + fprintf(stdout, " }\n"); + fprintf(stdout, "\n"); + } + + } + } + + return 0; +} + +int main(int argc, char **argv) { + + FILE *fp; + char *fpname; + + int i, j, h, bit, len; + int bit_count, frames; + int header_found = 0; + int cfreq = -1; + + + fpname = argv[0]; + ++argv; + while ((*argv) && (!wavloaded)) { + if ( (strcmp(*argv, "-h") == 0) || (strcmp(*argv, "--help") == 0) ) { + fprintf(stderr, "%s [options] audio.wav\n", fpname); + fprintf(stderr, " options:\n"); + fprintf(stderr, " -i\n"); + fprintf(stderr, " -b\n"); + return 0; + } + else if ( (strcmp(*argv, "-i") == 0) || (strcmp(*argv, "--invert") == 0) ) { + option_inv = 1; + } + else if ( (strcmp(*argv, "-v") == 0) || (strcmp(*argv, "--verbose") == 0) ) { + option_verbose = 1; + } + else if (strcmp(*argv, "-b" ) == 0) { option_b = 1; } + else if (strcmp(*argv, "-t" ) == 0) { option_timestamp = 1; } + else if ( (strcmp(*argv, "-r") == 0) || (strcmp(*argv, "--raw") == 0) ) { + option_raw = 1; + } + else if ( (strcmp(*argv, "-R") == 0) || (strcmp(*argv, "--RAW") == 0) ) { + option_raw = 2; + } + else if ( (strcmp(*argv, "--json") == 0) ) { + option_json = 1; + } + else if ( (strcmp(*argv, "--jsn_cfq") == 0) ) { + int frq = -1; // center frequency / Hz + ++argv; + if (*argv) frq = atoi(*argv); else return -1; + if (frq < 300000000) frq = -1; + cfreq = frq; + } + else { + fp = fopen(*argv, "rb"); + if (fp == NULL) { + fprintf(stderr, "%s konnte nicht geoeffnet werden\n", *argv); + return -1; + } + wavloaded = 1; + } + ++argv; + } + if (!wavloaded) fp = stdin; + + + i = read_wav_header(fp); + if (i) return -1; + + + if (cfreq > 0) gpx.jsn_freq = (cfreq+500)/1000; + + + bit_count = 0; + frames = 0; + while (!read_bits_fsk(fp, &bit, &len)) { + + if (len == 0) { + bufpos--; + if (bufpos < 0) bufpos = HEADLEN-1; + buf[bufpos] = 'x'; + continue; + } + + + for (j = 0; j < len; j++) { + bufpos--; + if (bufpos < 0) bufpos = HEADLEN-1; + buf[bufpos] = 0x30 + bit; + + if (!header_found) + { + h = compare(); //h2 = compare2(); + if ((h >= HEADLEN)) { + header_found = 1; + fflush(stdout); + if (option_timestamp) printf("<%8.3f> ", sample_count/(double)sample_rate); + strncpy(frame_bits, header, HEADLEN); + bit_count += HEADLEN; + frames++; + } + } + else + { + frame_bits[bit_count] = 0x30 + bit; + bit_count += 1; + } + + if (bit_count >= BITFRAMELEN) { + bit_count = 0; + header_found = 0; + + print_frame(); + } + + } + if (header_found && option_b) { + bitstart = 1; + + while ( bit_count < BITFRAMELEN ) { + if (read_rawbit(fp, &bit) == EOF) break; + frame_bits[bit_count] = 0x30 + bit; + bit_count += 1; + } + + bit_count = 0; + header_found = 0; + + print_frame(); + } + } + printf("\n"); + + fclose(fp); + + return 0; +} +