From afa0d80b95cc3992bfafc881e1a94200965614b9 Mon Sep 17 00:00:00 2001 From: "Joseph D. Gaeddert" Date: Sun, 17 Mar 2024 21:46:29 -0400 Subject: [PATCH] dsssframe64sync: addinf copy() method, tests --- src/framing/src/dsssframe64sync.c | 25 ++++++------ src/framing/tests/dsssframe64_autotest.c | 49 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/framing/src/dsssframe64sync.c b/src/framing/src/dsssframe64sync.c index 9d0164b6d..27a84e620 100644 --- a/src/framing/src/dsssframe64sync.c +++ b/src/framing/src/dsssframe64sync.c @@ -136,7 +136,6 @@ dsssframe64sync dsssframe64sync_create(framesync_callback _callback, // copy object dsssframe64sync dsssframe64sync_copy(dsssframe64sync q_orig) { -#if 0 // validate input if (q_orig == NULL) return liquid_error_config("dsssframe64sync_copy(), object cannot be NULL"); @@ -147,21 +146,16 @@ dsssframe64sync dsssframe64sync_copy(dsssframe64sync q_orig) // copy entire memory space over and overwrite values as needed memmove(q_copy, q_orig, sizeof(struct dsssframe64sync_s)); - // set callback and context fields - q_copy->callback = q_orig->callback; - q_copy->context = q_orig->context; + // copy internal objects + q_copy->detector = qdsync_cccf_copy (q_orig->detector); + q_copy->ms = msequence_copy (q_orig->ms); + q_copy->dec = qpacketmodem_copy(q_orig->dec); + q_copy->pilotsync = qpilotsync_copy (q_orig->pilotsync); - // copy objects - q_copy->detector = qdsync_cccf_copy(q_orig->detector); - q_copy->dec = qpacketmodem_copy (q_orig->dec); - q_copy->pilotsync= qpilotsync_copy (q_orig->pilotsync); + // update detector callback's context to use q_copy + qdsync_cccf_set_context(q_copy->detector, (void*)q_copy); return q_copy; -#else - // not yet implemented - liquid_error(LIQUID_ENOIMP, "dsssframe64sync_copy(), method not yet implemented"); - return NULL; -#endif } // destroy frame synchronizer object, freeing all internal memory @@ -181,7 +175,10 @@ int dsssframe64sync_destroy(dsssframe64sync _q) // print frame synchronizer object internals int dsssframe64sync_print(dsssframe64sync _q) { - printf("\n"); + printf("\n", + _q->preamble_counter, + _q->chip_counter, + _q->payload_counter); return LIQUID_OK; } diff --git a/src/framing/tests/dsssframe64_autotest.c b/src/framing/tests/dsssframe64_autotest.c index 747eb8720..cfe7ae752 100644 --- a/src/framing/tests/dsssframe64_autotest.c +++ b/src/framing/tests/dsssframe64_autotest.c @@ -126,3 +126,52 @@ void autotest_dsssframe64gen_copy() free(buf_1); } +// test that the complete internal state of one synchronizer can be copied to a new +// object and it can maintain state +void autotest_dsssframe64sync_copy() +{ + // create object and generte frame + dsssframe64gen fg = dsssframe64gen_create(); + unsigned int frame_len = dsssframe64gen_get_frame_len(fg); + float complex * frame= (float complex *)malloc(frame_len*sizeof(float complex)); + dsssframe64gen_execute(fg, NULL, NULL, frame); + + // creamte original frame synchronizer + dsssframe64sync q0 = dsssframe64sync_create(NULL, NULL); + + // run half of frame through synchronizer + unsigned int n = 12000; + dsssframe64sync_execute(q0, frame, n); + + // ensure frame was not yet decoded + framedatastats_s s0, s1; + s0 = dsssframe64sync_get_framedatastats(q0); + CONTEND_EQUALITY(s0.num_frames_detected, 0); + + // copy object + dsssframe64sync q1 = dsssframe64sync_copy(q0); + + // run remaining half of frame through synchronizers + dsssframe64sync_execute(q0, frame+n, frame_len-n); + dsssframe64sync_execute(q1, frame+n, frame_len-n); + + // ensure frame was decoded by both synchronizers + s0 = dsssframe64sync_get_framedatastats(q0); + CONTEND_EQUALITY(s0.num_frames_detected, 1); + CONTEND_EQUALITY(s0.num_headers_valid, 1); + CONTEND_EQUALITY(s0.num_payloads_valid, 1); + CONTEND_EQUALITY(s0.num_bytes_received, 64); + + s1 = dsssframe64sync_get_framedatastats(q1); + CONTEND_EQUALITY(s1.num_frames_detected, 1); + CONTEND_EQUALITY(s1.num_headers_valid, 1); + CONTEND_EQUALITY(s1.num_payloads_valid, 1); + CONTEND_EQUALITY(s1.num_bytes_received, 64); + + // destroy objects and free memory + dsssframe64gen_destroy(fg); + dsssframe64sync_destroy(q0); + dsssframe64sync_destroy(q1); + free(frame); +} +