linking with C library and replace enum interface to GRC with native type (int)

pull/17/head
Jean-Michel Friedt 2024-12-23 12:48:03 +01:00
parent 0c63ce4213
commit 87557953a9
10 changed files with 40 additions and 25 deletions

View File

@ -43,7 +43,8 @@ asserts:
templates:
imports: from gnuradio import m17
make: m17.m17_decoder(${debug_data},${debug_ctrl},${threshold},${callsign},${signed_str},${key},${encr_type})
make: m17.m17_decoder(${debug_data},${debug_ctrl},${threshold},${callsign},${signed_str},${encr_type},${key})
callbacks:
- set_debug_data(${debug_data})
- set_debug_ctrl(${debug_ctrl})

View File

@ -42,7 +42,7 @@ namespace gr
* creating new instances.
*/
static sptr make (std::string src_id, std::string dst_id, int mode,
int data, encr_t encr_type, int encr_subtype, int can,
int data, int encr_type, int encr_subtype, int can,
std::string meta, std::string key,
std::string priv_key, bool debug, bool signed_str);
virtual void set_key (std::string meta) = 0;
@ -56,7 +56,7 @@ namespace gr
int encr_subtype, int can) = 0;
virtual void set_mode (int mode) = 0;
virtual void set_data (int data) = 0;
virtual void set_encr_type (encr_t encr_type) = 0;
virtual void set_encr_type (int encr_type) = 0;
virtual void set_encr_subtype (int encr_subtype) = 0;
virtual void set_can (int can) = 0;
};

View File

@ -42,7 +42,7 @@ namespace gr
* creating new instances.
*/
static sptr make (bool debug_data, bool debug_ctrl, float threshold,
bool callsign, bool signed_str, encr_t encr_type,
bool callsign, bool signed_str, int encr_type,
std::string key);
virtual void set_debug_data (bool debug) = 0;
virtual void set_debug_ctrl (bool debug) = 0;

View File

@ -29,6 +29,8 @@ list(APPEND m17_sources
../M17_Implementations/libm17/phy/randomize.c
../M17_Implementations/libm17/phy/sync.c
../M17_Implementations/libm17/phy/slice.c
../M17_Implementations/micro-ecc/uECC.c
../M17_Implementations/tinier-aes/aes.c
)
set(m17_sources "${m17_sources}" PARENT_SCOPE)

View File

@ -51,7 +51,7 @@ namespace gr
m17_coder::sptr
m17_coder::make (std::string src_id, std::string dst_id, int mode,
int data, encr_t encr_type, int encr_subtype, int can,
int data, int encr_type, int encr_subtype, int can,
std::string meta, std::string key,
std::string priv_key, bool debug, bool signed_str)
{
@ -65,7 +65,7 @@ namespace gr
* The private constructor
*/
m17_coder_impl::m17_coder_impl (std::string src_id, std::string dst_id,
int mode, int data, encr_t encr_type,
int mode, int data, int encr_type,
int encr_subtype, int can,
std::string meta, std::string key,
std::string priv_key, bool debug,
@ -80,11 +80,12 @@ namespace gr
make (1, 1,
sizeof
(float))),
_mode (mode), _data (data), _encr_type (encr_type),
_mode (mode), _data (data),
_encr_subtype (encr_subtype), _can (can), _meta (meta), _debug (debug),
_signed_str (signed_str)
{
set_type (mode, data, encr_type, encr_subtype, can);
set_encr_type(encr_type);
set_type (mode, data, _encr_type, encr_subtype, can);
set_meta (meta); // depends on ^^^ encr_subtype
set_src_id (src_id);
set_dst_id (dst_id);
@ -111,6 +112,18 @@ namespace gr
}
}
void m17_coder_impl::set_encr_type (int encr_type)
{
switch (encr_type)
{case 0:_encr_type=ENCR_NONE;break;
case 1:_encr_type=ENCR_SCRAM;break;
case 2:_encr_type=ENCR_AES;break;
case 3:_encr_type=ENCR_RES;break;
default:_encr_type=ENCR_NONE;
}
printf ("new encr type: %x -> ", _encr_type);
}
void m17_coder_impl::set_signed (bool signed_str)
{
_signed_str = signed_str;
@ -297,13 +310,6 @@ namespace gr
set_type (_mode, _data, _encr_type, _encr_subtype, _can);
}
void m17_coder_impl::set_encr_type (encr_t encr_type)
{
_encr_type = encr_type;
printf ("new encr type: %x -> ", _encr_type);
set_type (_mode, _data, _encr_type, _encr_subtype, _can);
}
void m17_coder_impl::set_encr_subtype (int encr_subtype)
{
_encr_subtype = encr_subtype;

View File

@ -84,13 +84,13 @@ namespace gr
int can);
void set_mode (int mode);
void set_data (int data);
void set_encr_type (encr_t encr_type);
void set_encr_type (int encr_type);
void set_encr_subtype (int encr_subtype);
void set_can (int can);
void set_debug (bool debug);
void set_signed (bool signed_str);
m17_coder_impl (std::string src_id, std::string dst_id, int mode,
int data, encr_t encr_type, int encr_subtype, int can,
int data, int encr_type, int encr_subtype, int can,
std::string meta, std::string key, std::string priv_key,
bool debug, bool signed_str);
~m17_coder_impl ();

View File

@ -43,7 +43,7 @@ namespace gr
m17_decoder::sptr
m17_decoder::make (bool debug_data, bool debug_ctrl, float threshold,
bool callsign, bool signed_str, encr_t encr_type,
bool callsign, bool signed_str, int encr_type,
std::string key)
{
return gnuradio::get_initial_sptr
@ -58,7 +58,7 @@ namespace gr
*/
m17_decoder_impl::m17_decoder_impl (bool debug_data, bool debug_ctrl,
float threshold, bool callsign,
bool signed_str, encr_t encr_type,
bool signed_str, int encr_type,
std::string key):gr::
block ("m17_decoder", gr::io_signature::make (1, 1, sizeof (float)),
gr::io_signature::make (1, 1, sizeof (char))),
@ -106,9 +106,15 @@ namespace gr
printf ("Debug control: false\n");
}
void m17_decoder_impl::set_encr_type (encr_t encr_type)
void m17_decoder_impl::set_encr_type (int encr_type)
{
_encr_type = encr_type;
switch (encr_type)
{case 0:_encr_type=ENCR_NONE;break;
case 1:_encr_type=ENCR_SCRAM;break;
case 2:_encr_type=ENCR_AES;break;
case 3:_encr_type=ENCR_RES;break;
default:_encr_type=ENCR_NONE;
}
printf ("new encr type: %x -> ", _encr_type);
}

View File

@ -83,7 +83,7 @@ namespace gr
public:
m17_decoder_impl (bool debug_data, bool debug_ctrl, float threshold,
bool callsign, bool signed_str, encr_t encr_type,
bool callsign, bool signed_str, int encr_type,
std::string key);
~m17_decoder_impl ();
void set_debug_data (bool debug);
@ -93,7 +93,7 @@ namespace gr
void set_callsign (bool callsign);
void set_threshold (float threshold);
void set_signed (bool signed_str);
void set_encr_type (encr_t encr_type);
void set_encr_type (int encr_type);
void parse_raw_key_string (uint8_t * dest, const char *inp);
void scrambler_sequence_generator ();
uint32_t scrambler_seed_calculation (int8_t subtype, uint32_t key,

View File

@ -16,7 +16,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(m17_coder.h) */
/* BINDTOOL_HEADER_FILE_HASH(94fa30734504cc76bf84692d850f98e1) */
/* BINDTOOL_HEADER_FILE_HASH(d3d92e833946721163c71aa788430568) */
/***********************************************************************************/
#include <pybind11/complex.h>

View File

@ -16,7 +16,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(m17_decoder.h) */
/* BINDTOOL_HEADER_FILE_HASH(e74f1151dff2abb4329d6d3b2e746f85) */
/* BINDTOOL_HEADER_FILE_HASH(7fb976e65a8b3a3a7bc91eaabc63f7ea) */
/***********************************************************************************/
#include <pybind11/complex.h>