Skip to content

Commit

Permalink
dsssframe64sync: addinf copy() method, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaeddert committed Mar 18, 2024
1 parent d84f50d commit afa0d80
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/framing/src/dsssframe64sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand All @@ -181,7 +175,10 @@ int dsssframe64sync_destroy(dsssframe64sync _q)
// print frame synchronizer object internals
int dsssframe64sync_print(dsssframe64sync _q)
{
printf("<liquid.dsssframe64sync>\n");
printf("<liquid.dsssframe64sync, %u, %u, %u>\n",
_q->preamble_counter,
_q->chip_counter,
_q->payload_counter);
return LIQUID_OK;
}

Expand Down
49 changes: 49 additions & 0 deletions src/framing/tests/dsssframe64_autotest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit afa0d80

Please sign in to comment.