Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/message hook #814

Merged
merged 6 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion docs/notes/PLUGIN-SYSTEM.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Plugins can *optionally* implement the following methods, based on usage, or set
* `call_end(plugin_t * const plugin, Call_Data_t call_info)`
* Called when a call has ended.

* `trunk_message(std::vector<TrunkMessage> messages, System *system)`
* Called when a new message is received from the control channel of a Trunk system

* `setup_recorder(plugin_t * const plugin, Recorder *recorder)`
* Called when a new recorder has been created.

Expand All @@ -41,7 +44,7 @@ Plugins can *optionally* implement the following methods, based on usage, or set
* `setup_systems(plugin_t * const plugin, std::vector<System *> systems)`
* Called during startup when the initial systems have been created.

* `**`setup_sources(plugin_t * const plugin, std::vector<Source *> sources)`
* `setup_sources(plugin_t * const plugin, std::vector<Source *> sources)`
* Called during startup when the initial sources have been created.

* `signal(plugin_t * const plugin, long unitId, const char *signaling_type, gr::blocks::SignalType sig_type, Call *call, System *system, Recorder *recorder)`
Expand All @@ -50,3 +53,24 @@ Plugins can *optionally* implement the following methods, based on usage, or set
* `audio_stream(plugin_t * const plugin, Call *call, Recorder *recorder, float *samples, int sampleCount)`
* Called when a set of audio samples that would be written out to the wav file writer is available.
* Useful to implement live audio streaming.

* `unit_registration(System *sys, long source_id)`
* Called when a Subscriber Unit (radio) registers with a Trunk System

* `unit_deregistration(System *sys, long source_id)`
* Called when a Subscriber Unit (radio) deregisters from a Trunk System

* `unit_acknowledge_response(System *sys, long source_id)`
* Called for the Unit Ack Trunk message

* `unit_group_affiliation(System *sys, long source_id, long talkgroup_num)`
* Called when a new Subscriber Unit (radio) selects a Talkgroup on a Trunk System

* `unit_data_grant(System *sys, long source_id)`
* Called for the Unit Data Grant Trunk Message

* `unit_answer_request(System *sys, long source_id, long talkgroup)`
* Called for the Unit Answer Request Trunk Message

* `unit_location(System *sys, long source_id, long talkgroup_num)`
* Called for the Unit Location Trunk Message
4 changes: 3 additions & 1 deletion trunk-recorder/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1472,15 +1472,17 @@ for (vector<System *>::iterator sys_it = systems.begin(); sys_it != systems.end(
msg = system->get_msg_queue()->delete_head_nowait();
while (msg != 0) {
system->set_message_count(system->get_message_count() + 1);

if (system->get_system_type() == "smartnet") {
trunk_messages = smartnet_parser->parse_message(msg->to_string(), system);
handle_message(trunk_messages, system);
plugman_trunk_message(trunk_messages, system);
}

if (system->get_system_type() == "p25") {
trunk_messages = p25_parser->parse_message(msg, system);
handle_message(trunk_messages, system);
plugman_trunk_message(trunk_messages, system);
}


Expand Down
2 changes: 2 additions & 0 deletions trunk-recorder/plugin_manager/plugin_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../global_structs.h"
#include "../gr_blocks/decoder_wrapper.h"
#include "../systems/system.h"
#include "../systems/parser.h"
#include "../formatter.h"
typedef enum {
PLUGIN_UNKNOWN,
Expand All @@ -24,6 +25,7 @@ class Plugin_Api {
virtual int poll_one() { return 0; };
virtual int signal(long unitId, const char *signaling_type, gr::blocks::SignalType sig_type, Call *call, System *system, Recorder *recorder) { return 0; };
virtual int audio_stream(Call *call, Recorder *recorder, int16_t *samples, int sampleCount) { return 0; };
virtual int trunk_message(std::vector<TrunkMessage> messages, System *system) { return 0; };
virtual int call_start(Call *call) { return 0; };
virtual int call_end(Call_Data_t call_info) { return 0; }; //= 0; //{ BOOST_LOG_TRIVIAL(info) << "plugin_api call_end"; return 0; };
virtual int calls_active(std::vector<Call *> calls) { return 0; };
Expand Down
11 changes: 11 additions & 0 deletions trunk-recorder/plugin_manager/plugin_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ int plugman_signal(long unitId, const char *signaling_type, gr::blocks::SignalTy
return error;
}

int plugman_trunk_message(std::vector<TrunkMessage> messages, System *system) {
int error = 0;
for (std::vector<Plugin *>::iterator it = plugins.begin(); it != plugins.end(); it++) {
Plugin *plugin = *it;
if (plugin->state == PLUGIN_RUNNING) {
plugin->api->trunk_message(messages, system);
}
}
return error;
}

int plugman_call_start(Call *call) {
int error = 0;
for (std::vector<Plugin *>::iterator it = plugins.begin(); it != plugins.end(); it++) {
Expand Down
1 change: 1 addition & 0 deletions trunk-recorder/plugin_manager/plugin_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void stop_plugins();
void plugman_poll_one();
void plugman_audio_callback(Call *call, Recorder *recorder, int16_t *samples, int sampleCount);
int plugman_signal(long unitId, const char *signaling_type, gr::blocks::SignalType sig_type, Call *call, System *system, Recorder *recorder);
int plugman_trunk_message(std::vector<TrunkMessage> messages, System *system);
int plugman_call_start(Call *call);
int plugman_call_end(Call_Data_t call_info);
int plugman_calls_active(std::vector<Call *> calls);
Expand Down
7 changes: 5 additions & 2 deletions trunk-recorder/systems/p25_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ std::vector<TrunkMessage> P25Parser::decode_mbt_data(unsigned long opcode, boost
message.phase2_tdma = false;
message.tdma_slot = 0;
message.freq = 0;
message.opcode = opcode;

BOOST_LOG_TRIVIAL(trace) << "decode_mbt_data: $" << opcode;
if (opcode == 0x0) { // grp voice channel grant
Expand Down Expand Up @@ -213,6 +214,8 @@ std::vector<TrunkMessage> P25Parser::decode_tsbk(boost::dynamic_bitset<> &tsbk,
TrunkMessage message;
std::ostringstream os;

unsigned long opcode = bitset_shift_mask(tsbk, 88, 0x3f); // x3f

message.message_type = UNKNOWN;
message.source = -1;
message.wacn = 0;
Expand All @@ -224,8 +227,7 @@ std::vector<TrunkMessage> P25Parser::decode_tsbk(boost::dynamic_bitset<> &tsbk,
message.phase2_tdma = false;
message.tdma_slot = 0;
message.freq = 0;

unsigned long opcode = bitset_shift_mask(tsbk, 88, 0x3f); // x3f
message.opcode = opcode;

BOOST_LOG_TRIVIAL(trace) << "TSBK: opcode: $" << std::hex << opcode;
if (opcode == 0x00) { // group voice chan grant
Expand Down Expand Up @@ -892,6 +894,7 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
int sys_num = system->get_sys_num();
TrunkMessage message;
message.message_type = UNKNOWN;
message.opcode = 255;
message.source = -1;
message.sys_num = sys_num;
if (type == -2) { // # request from gui
Expand Down
2 changes: 2 additions & 0 deletions trunk-recorder/systems/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct TrunkMessage {
unsigned long nac;
unsigned long wacn;
PatchData patch_data;
unsigned long opcode;

};

class TrunkParser {
Expand Down
1 change: 1 addition & 0 deletions trunk-recorder/systems/smartnet_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ std::vector<TrunkMessage> SmartnetParser::parse_message(std::string s,
message.sys_id = 0;
message.sys_num = system->get_sys_num();
message.emergency = false;
message.opcode = 0;

std::vector<std::string> x;
boost::split(x, s, boost::is_any_of(","), boost::token_compress_on);
Expand Down