Skip to content

Commit

Permalink
Expose some POCSAG and TSL debug options via CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
pvachon committed Aug 14, 2020
1 parent b9023f1 commit cde4b92
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.7)

include(CMakeDependentOption)

project(TSL-SDR VERSION 1.0.0)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3 -gdwarf-4 -rdynamic")
Expand All @@ -24,6 +26,13 @@ add_definitions(-DSYS_CACHE_LINE_LENGTH=64)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")

# Enable POCSAG debugging
option(DEBUG_POCSAG "Enable POCSAG State Machine Debugging" OFF)

# Enable DIAG statements
cmake_dependent_option(DEBUG_TSL "Enable verbose TSL debugging" ON
"DEBUG_POCSAG" OFF)

# Grab the revision from git
execute_process(COMMAND git describe --abbrev=16 --dirty --always --tags
OUTPUT_VARIABLE GIT_REV
Expand All @@ -37,6 +46,16 @@ endif()

add_definitions(-D_VC_VERSION="${GIT_REV}")

# Enable POCSAG debugging if requested
if (DEBUG_POCSAG)
add_definitions(-D_PAGER_POCSAG_DEBUG)

endif (DEBUG_POCSAG)

if (DEBUG_TSL)
add_definitions(-D_TSL_DEBUG)
endif (DEBUG_TSL)

# Grab the CPU model we're building on (no cross-compiling support)
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CPU_ARCH
Expand Down
5 changes: 4 additions & 1 deletion decoder/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ aresult_t process_samples(void)

struct dc_blocker blck;
struct sample_buf *read_buf = NULL;
size_t sample_count = 0;

TSL_BUG_IF_FAILED(dc_blocker_init(&blck, dc_block_pole));

Expand Down Expand Up @@ -615,6 +616,7 @@ aresult_t process_samples(void)
TSL_BUG_ON((1 & op_ret) != 0);

read_buf->nr_samples += op_ret/sizeof(int16_t);
sample_count += op_ret/sizeof(int16_t);

if (true == _invert) {
int16_t *samp = (int16_t *)read_buf->data_buf;
Expand Down Expand Up @@ -666,6 +668,7 @@ aresult_t process_samples(void)
} while (app_running());

done:
DEC_MSG(SEV_INFO, "TERMINATING", "Terminating processing loop, processed %zu samples", sample_count);
return ret;
}

Expand All @@ -687,7 +690,7 @@ int main(int argc, char * const argv[])
TSL_BUG_IF_FAILED(pager_flex_new(&flex, center_freq, _on_flex_alnum_msg, _on_flex_num_msg, _on_flex_siv_msg));
} else if (_decoder_type == DECODER_PAGER_TYPE_POCSAG) {
DEC_MSG(SEV_INFO, "PROTOCOL", "Using the POCSAG Pager Protocol.");
TSL_BUG_IF_FAILED(pager_pocsag_new(&pocsag, center_freq, _on_pocsag_num_msg, _on_pocsag_alnum_msg));
TSL_BUG_IF_FAILED(pager_pocsag_new(&pocsag, center_freq, _on_pocsag_num_msg, _on_pocsag_alnum_msg, false));
} else if (_decoder_type == DECODER_PROTO_TYPE_AIS) {
DEC_MSG(SEV_INFO, "PROTOCOL", "Using the AIS Message Format.");
TSL_BUG_IF_FAILED(ais_decode_new(&ais_decode, center_freq, _on_ais_position_report, _on_ais_base_station_report, _on_ais_static_voyage_data));
Expand Down
6 changes: 5 additions & 1 deletion pager/pager_pocsag.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ void _pager_pocsag_baud_search_reset(struct pager_pocsag *pocsag)

aresult_t pager_pocsag_new(struct pager_pocsag **ppocsag, uint32_t freq_hz,
pager_pocsag_on_numeric_msg_func_t on_numeric,
pager_pocsag_on_alpha_msg_func_t on_alpha)
pager_pocsag_on_alpha_msg_func_t on_alpha,
bool skip_bch_decode)
{
aresult_t ret = A_OK;

Expand Down Expand Up @@ -181,6 +182,8 @@ aresult_t pager_pocsag_new(struct pager_pocsag **ppocsag, uint32_t freq_hz,
_pager_pocsag_baud_search_reset(pocsag);
_pager_pocsag_message_decode_reset(&pocsag->decoder);

pocsag->skip_bch = skip_bch_decode;

*ppocsag = pocsag;

done:
Expand Down Expand Up @@ -337,6 +340,7 @@ aresult_t _pager_pocsag_process_batch(struct pager_pocsag *pocsag, struct pager_
decode->early_termination = true;
TSL_BUG_IF_FAILED(_pager_pocsag_message_decode_deliver(pocsag, decode));
}
DIAG("Terminating processing batch; multibit errors detected.");
ret = A_E_INVAL;
goto done;
}
Expand Down
4 changes: 3 additions & 1 deletion pager/pager_pocsag.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <tsl/result.h>
#include <stdbool.h>

struct pager_pocsag;

Expand All @@ -27,11 +28,12 @@ typedef aresult_t (*pager_pocsag_on_alpha_msg_func_t)(
* \param freq_hz The center frequency of this channel
* \param on_numeric Function called when a numeric page has been successfully decoded.
* \param on_alpha Function called when an alphanumeric page has been successfully decoded.
* \param skip_bch_decode Skip BCH checks (not recommended)
*
* \return A_OK on success, an error code otherwise.
*/
aresult_t pager_pocsag_new(struct pager_pocsag **ppocsag, uint32_t freq_hz, pager_pocsag_on_numeric_msg_func_t on_numeric,
pager_pocsag_on_alpha_msg_func_t on_alpha);
pager_pocsag_on_alpha_msg_func_t on_alpha, bool skip_bch_decode);

/**
* Destroy a POCSAG decoder.
Expand Down
5 changes: 5 additions & 0 deletions pager/pager_pocsag_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ struct pager_pocsag {
*/
uint16_t baud_rate;

/**
* Whether or not we should skip the BCH code validation
*/
bool skip_bch;

/**
* Callback for handling the arrival of numeric messages
*/
Expand Down
4 changes: 2 additions & 2 deletions pager/test/test_pager_pocsag.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ TEST_DECLARE_UNIT(test_one_shot, pocsag)
{
struct pager_pocsag *pocsag = NULL;

TEST_ASSERT_OK(pager_pocsag_new(&pocsag, 929612500ul, _test_pocsag_on_num_message_simple_cb, _test_pocsag_on_message_simple_cb));
TEST_ASSERT_OK(pager_pocsag_new(&pocsag, 929612500ul, _test_pocsag_on_num_message_simple_cb, _test_pocsag_on_message_simple_cb, false));
TEST_ASSERT_OK(pager_pocsag_on_pcm(pocsag, samples, nr_samples));
TEST_ASSERT_OK(pager_pocsag_delete(&pocsag));

Expand All @@ -205,7 +205,7 @@ TEST_DECLARE_UNIT(test_smoke, pocsag)
{
struct pager_pocsag *pocsag = NULL;

TEST_ASSERT_OK(pager_pocsag_new(&pocsag, 929612500ul, _test_pocsag_on_num_message_simple_cb, _test_pocsag_on_message_simple_cb));
TEST_ASSERT_OK(pager_pocsag_new(&pocsag, 929612500ul, _test_pocsag_on_num_message_simple_cb, _test_pocsag_on_message_simple_cb, false));
TEST_ASSERT_NOT_NULL(pocsag);
TEST_ASSERT_OK(pager_pocsag_delete(&pocsag));
TEST_ASSERT_EQUALS(pocsag, NULL);
Expand Down

0 comments on commit cde4b92

Please sign in to comment.