Skip to content

Commit

Permalink
cpfskmodem: adding configuration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaeddert committed Mar 10, 2024
1 parent 2f94f82 commit 22fa2ac
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/liquid.h
Original file line number Diff line number Diff line change
Expand Up @@ -8222,6 +8222,7 @@ int gmskdem_demodulate(gmskdem _q,

// CP-FSK filter prototypes
typedef enum {
//LIQUID_CPFSK_UNKNOWN=0
LIQUID_CPFSK_SQUARE=0, // square pulse
LIQUID_CPFSK_RCOS_FULL, // raised-cosine (full response)
LIQUID_CPFSK_RCOS_PARTIAL, // raised-cosine (partial response)
Expand Down
6 changes: 3 additions & 3 deletions src/modem/src/cpfskdem.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2020 Joseph Gaeddert
* Copyright (c) 2007 - 2024 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -138,14 +138,14 @@ cpfskdem cpfskdem_create(unsigned int _bps,
// validate input
if (_bps == 0)
return liquid_error_config("cpfskdem_create(), bits/symbol must be greater than 0");
if (_h <= 0.0f)
return liquid_error_config("cpfskdem_create(), modulation index must be greater than 0");
if (_k < 2 || (_k%2))
return liquid_error_config("cpfskmod_create(), samples/symbol must be greater than 2 and even");
if (_m == 0)
return liquid_error_config("cpfskdem_create(), filter delay must be greater than 0");
if (_beta <= 0.0f || _beta > 1.0f)
return liquid_error_config("cpfskdem_create(), filter roll-off must be in (0,1]");
if (_h <= 0.0f)
return liquid_error_config("cpfskdem_create(), modulation index must be greater than 0");

// create main object memory
cpfskdem q = (cpfskdem) malloc(sizeof(struct cpfskdem_s));
Expand Down
6 changes: 3 additions & 3 deletions src/modem/src/cpfskmod.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2023 Joseph Gaeddert
* Copyright (c) 2007 - 2024 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -79,14 +79,14 @@ cpfskmod cpfskmod_create(unsigned int _bps,
// validate input
if (_bps == 0)
return liquid_error_config("cpfskmod_create(), bits/symbol must be greater than 0");
if (_h <= 0.0f)
return liquid_error_config("cpfskmod_create(), modulation index must be greater than 0");
if (_k < 2 || (_k%2))
return liquid_error_config("cpfskmod_create(), samples/symbol must be greater than 2 and even");
if (_m == 0)
return liquid_error_config("cpfskmod_create(), filter delay must be greater than 0");
if (_beta <= 0.0f || _beta > 1.0f)
return liquid_error_config("cpfskmod_create(), filter roll-off must be in (0,1]");
if (_h <= 0.0f)
return liquid_error_config("cpfskmod_create(), modulation index must be greater than 0");

// create main object memory
cpfskmod q = (cpfskmod) malloc(sizeof(struct cpfskmod_s));
Expand Down
28 changes: 28 additions & 0 deletions src/modem/tests/cpfskmodem_autotest.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,31 @@ void autotest_cpfskmodem_spectrum()
liquid_autotest_verbose ? filename : NULL);
}


// test errors and invalid configuration
void autotest_cpfskmodem_config()
{
#if LIQUID_STRICT_EXIT
AUTOTEST_WARN("skipping modem config test with strict exit enabled\n");
return;
#endif
#if !LIQUID_SUPPRESS_ERROR_OUTPUT
fprintf(stderr,"warning: ignore potential errors here; checking for invalid configurations\n");
#endif
// test copying/creating invalid objects
//CONTEND_ISNULL( modemcf_copy(NULL) );
CONTEND_ISNULL( cpfskmod_create(0, 0.5f, 4, 12, 0.25f, LIQUID_CPFSK_SQUARE) ); // _bps is less than 1
CONTEND_ISNULL( cpfskmod_create(1, 0.0f, 4, 12, 0.25f, LIQUID_CPFSK_SQUARE) ); // _h (mod index) is out of range
CONTEND_ISNULL( cpfskmod_create(1, 0.5f, 5, 12, 0.25f, LIQUID_CPFSK_SQUARE) ); // _k is not even
CONTEND_ISNULL( cpfskmod_create(1, 0.5f, 4, 0, 0.25f, LIQUID_CPFSK_SQUARE) ); // _m is too small
CONTEND_ISNULL( cpfskmod_create(1, 0.5f, 4, 12, 0.00f, LIQUID_CPFSK_SQUARE) ); // _beta is too small

CONTEND_ISNULL( cpfskdem_create(0, 0.5f, 4, 12, 0.25f, LIQUID_CPFSK_SQUARE) ); // _bps is less than 1
CONTEND_ISNULL( cpfskdem_create(1, 0.0f, 4, 12, 0.25f, LIQUID_CPFSK_SQUARE) ); // _h (mod index) is out of range
CONTEND_ISNULL( cpfskdem_create(1, 0.5f, 5, 12, 0.25f, LIQUID_CPFSK_SQUARE) ); // _k is not even
CONTEND_ISNULL( cpfskdem_create(1, 0.5f, 4, 0, 0.25f, LIQUID_CPFSK_SQUARE) ); // _m is too small
CONTEND_ISNULL( cpfskdem_create(1, 0.5f, 4, 12, 0.00f, LIQUID_CPFSK_SQUARE) ); // _beta is too small

// TODO: create object and check configuration
}

0 comments on commit 22fa2ac

Please sign in to comment.