From ba4cad888865cd19e14cde42c03cc50f2a0745ab Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 20 Apr 2020 13:37:13 +0200 Subject: Add fw simulator --- controller/fw/tools/dsss_demod_test.c | 3 +- controller/fw/tools/dsss_demod_test_runner.py | 32 +++++++++++++++------- .../fw/tools/dsss_demod_test_waveform_gen.py | 4 +-- 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'controller/fw/tools') diff --git a/controller/fw/tools/dsss_demod_test.c b/controller/fw/tools/dsss_demod_test.c index a1e269a..f7df111 100644 --- a/controller/fw/tools/dsss_demod_test.c +++ b/controller/fw/tools/dsss_demod_test.c @@ -15,7 +15,8 @@ void handle_dsss_received(symbol_t data[static TRANSMISSION_SYMBOLS]) { printf("data sequence received: [ "); for (size_t i=0; i>1)); + //printf("%+3d", ((data[i]&1) ? 1 : -1) * (data[i]>>1)); + printf("%2d", data[i]); if (i+1 < TRANSMISSION_SYMBOLS) printf(", "); } diff --git a/controller/fw/tools/dsss_demod_test_runner.py b/controller/fw/tools/dsss_demod_test_runner.py index e31a686..a7acccd 100644 --- a/controller/fw/tools/dsss_demod_test_runner.py +++ b/controller/fw/tools/dsss_demod_test_runner.py @@ -83,15 +83,18 @@ def run_test(seed, amplitude_spec, background, nbits, decimation, symbols, thfs, signal = np.repeat(dsss_modulate(test_data, nbits) * 2.0 - 1, decimation) # We're re-using the seed here. This is not a problem. noise = noise_gen(seed, len(signal), *noise_params) + # DEBUG + # Map lsb to sign to match test program + # test_data = (test_data>>1) * (2*(test_data&1) - 1) amplitudes = amplitude_spec[0] * 10 ** np.linspace(0, amplitude_spec[1], amplitude_spec[2]) output = [] for amp in amplitudes: with tempfile.NamedTemporaryFile(dir=cachedir) as f: waveform = signal*amp + noise - f.write(waveform.astype('float').tobytes()) + f.write(waveform.astype('float32').tobytes()) f.flush() - + for thf in thfs: cmdline = [lookup_binary(nbits, thf, decimation, symbols), f.name] proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, text=True) @@ -107,10 +110,10 @@ def run_test(seed, amplitude_spec, background, nbits, decimation, symbols, thfs, ser = min(sequence_matcher(test_data, match) for match in matched) if matched else None rpars = ResultParams(nbits, thf, decimation, symbols, seed, amp, background) output.append((rpars, ser)) - print(f'ran {rpars} {ser=} {" ".join(cmdline)}') return output -def parallel_generator(db, table, columns, builder, param_list, desc, context={}, params_mapper=lambda *args: args): +def parallel_generator(db, table, columns, builder, param_list, desc, context={}, params_mapper=lambda *args: args, + disable_cache=False): with multiprocessing.Pool(multiprocessing.cpu_count()) as pool: with db as conn: jobs = [] @@ -119,7 +122,7 @@ def parallel_generator(db, table, columns, builder, param_list, desc, context={} f'SELECT result FROM {table} WHERE ({",".join(columns)}) = ({",".join("?"*len(columns))})', params_mapper(*params)).fetchone() - if found_res: + if found_res and not disable_cache: yield params, json.loads(*found_res) else: @@ -142,13 +145,18 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--dump', help='Write results to JSON file') parser.add_argument('-c', '--cachedir', default='dsss_test_cache', help='Directory to store build output and data in') + parser.add_argument('-n', '--no-cache', action='store_true', help='Disable result cache') args = parser.parse_args() DecoderParams = namedtuple('DecoderParams', ['nbits', 'thf', 'decimation', 'symbols']) - dec_paramses = [ DecoderParams(nbits=nbits, thf=thf, decimation=decimation, symbols=20) +# dec_paramses = [ DecoderParams(nbits=nbits, thf=thf, decimation=decimation, symbols=20) +# for nbits in [5, 6] +# for thf in [4.5, 4.0, 5.0] +# for decimation in [10, 5, 22] ] + dec_paramses = [ DecoderParams(nbits=nbits, thf=thf, decimation=decimation, symbols=100) for nbits in [5, 6] - for thf in [4.5, 4.0, 5.0] - for decimation in [10, 5, 22] ] + for thf in [3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0] + for decimation in [1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 16, 22, 30, 40, 50] ] # dec_paramses = [ DecoderParams(nbits=nbits, thf=thf, decimation=decimation, symbols=100) # for nbits in [5, 6, 7, 8] # for thf in [1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0] @@ -171,8 +179,11 @@ if __name__ == '__main__': GeneratorParams = namedtuple('GeneratorParams', ['seed', 'amplitude_spec', 'background']) gen_params = [ GeneratorParams(rep, (5e-3, 1, 5), background) #GeneratorParams(rep, (0.05e-3, 3.5, 50), background) - for rep in range(30) + for rep in range(50) for background in ['meas://fmeas_export_ocxo_2day.bin', 'synth://grid_freq_psd_spl_108pt.json'] ] +# gen_params = [ GeneratorParams(rep, (5e-3, 1, 5), background) +# for rep in range(1) +# for background in ['meas://fmeas_export_ocxo_2day.bin'] ] data_db = sqlite3.connect(path.join(args.cachedir, 'data_db.sqlite3')) data_db.execute('CREATE TABLE IF NOT EXISTS waveforms' @@ -198,7 +209,8 @@ if __name__ == '__main__': params_mapper=params_mapper, builder=run_test, param_list=waveform_params, desc='Generating waveforms', - context=dict(cachedir=data_cache_dir, lookup_binary=lookup_binary)): + context=dict(cachedir=data_cache_dir, lookup_binary=lookup_binary), + disable_cache=args.no_cache): results += chunk if args.dump: diff --git a/controller/fw/tools/dsss_demod_test_waveform_gen.py b/controller/fw/tools/dsss_demod_test_waveform_gen.py index aa9ec93..1749bd7 100644 --- a/controller/fw/tools/dsss_demod_test_waveform_gen.py +++ b/controller/fw/tools/dsss_demod_test_waveform_gen.py @@ -48,7 +48,7 @@ def mains_noise_measured(seed, n, meas_data): last_valid = len(meas_data) - n st = np.random.RandomState(seed) start = st.randint(last_valid) - return meas_data[start:start+n] + return meas_data[start:start+n] + 50.00 def load_noise_synth_params(specfile): with open(specfile) as f: @@ -67,5 +67,5 @@ def mains_noise_synthetic(seed, n, psd_spl, spl_N, spl_x): spec **= 1/2 renoise = scipy.fftpack.ifft(spec) - return renoise[10000:][:n] + return renoise[10000:][:n] + 50.00 -- cgit