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

Add TSBK Stream Option #888

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ list(APPEND trunk_recorder_sources
trunk-recorder/formatter.cc
trunk-recorder/source.cc
trunk-recorder/call_conventional.cc
trunk-recorder/tsbk_socket.cc
trunk-recorder/systems/smartnet_trunking.cc
trunk-recorder/systems/p25_trunking.cc
trunk-recorder/systems/smartnet_parser.cc
Expand Down
7 changes: 6 additions & 1 deletion trunk-recorder/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ bool load_config(string config_file, Config &config, gr::top_block_sptr &tb, std
config.frequency_format = frequency_format;
BOOST_LOG_TRIVIAL(info) << "Frequency format: " << get_frequency_format();

config.tsbk_stream_server = pt.get<std::string>("tsbkStreamServer", "");
BOOST_LOG_TRIVIAL(info) << "TSBK Stream Host: " << config.tsbk_stream_server;
config.tsbk_stream_port = pt.get<int>("tsbkStreamPort", 5678);
BOOST_LOG_TRIVIAL(info) << "TSBK Stream Port: " << config.tsbk_stream_port;

statusAsString = data.value("statusAsString", statusAsString);
BOOST_LOG_TRIVIAL(info) << "Status as String: " << statusAsString;
std::string log_level = data.value("logLevel", "info");
Expand Down Expand Up @@ -624,4 +629,4 @@ bool load_config(string config_file, Config &config, gr::top_block_sptr &tb, std
}
BOOST_LOG_TRIVIAL(info) << "\n\n";
return true;
}
}
2 changes: 2 additions & 0 deletions trunk-recorder/global_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct Config {
std::string temp_dir;
std::string debug_recorder_address;
std::string log_dir;
std::string tsbk_stream_server;
std::string default_mode;
bool new_call_from_update;
bool debug_recorder;
Expand All @@ -42,6 +43,7 @@ struct Config {
bool soft_vocoder;
bool record_uu_v_calls;
int frequency_format;
int tsbk_stream_port;
};

struct Call_Source {
Expand Down
10 changes: 7 additions & 3 deletions trunk-recorder/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include "call.h"
#include "call_conventional.h"
#include "tsbk_socket.h"
#include "systems/p25_parser.h"
#include "systems/p25_trunking.h"
#include "systems/parser.h"
Expand Down Expand Up @@ -1144,15 +1145,18 @@ int main(int argc, char **argv) {

tb = gr::make_top_block("Trunking");

smartnet_parser = new SmartnetParser(); // this has to eventually be generic;
p25_parser = new P25Parser();

std::string uri = "ws://localhost:3005";

if (!load_config(config_file, config, tb, sources, systems)) {
exit(1);
}

// start up after config load
smartnet_parser = new SmartnetParser(); // this has to eventually be generic;
p25_parser = new P25Parser();

tsbk_socket = new TSBK_Socket(config.tsbk_stream_server, config.tsbk_stream_port);

start_plugins(sources, systems);

if (setup_systems()) {
Expand Down
5 changes: 5 additions & 0 deletions trunk-recorder/systems/p25_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,8 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
}
b <<= 16; // for missing crc

tsbk_socket->send_tsbk(b, system);

return decode_tsbk(b, nac, sys_num);
} else if (type == 12) { // # trunk: MBT
std::string s1 = s.substr(0, 10);
Expand Down Expand Up @@ -1060,6 +1062,9 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
}
}
mbt_data <<= 32; // for missing crc

tsbk_socket->send_mbt(mbt_data, system);

unsigned long opcode = bitset_shift_mask(header, 32, 0x3f);
unsigned long link_id = bitset_shift_mask(header, 48, 0xffffff);
/*BOOST_LOG_TRIVIAL(debug) << "RAW Data " <<b;
Expand Down
1 change: 1 addition & 0 deletions trunk-recorder/systems/p25_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <gnuradio/message.h>
#include "system.h"
#include "system_impl.h"
#include "../tsbk_socket.h"
#include <iomanip>
#include <iostream>
#include <map>
Expand Down
73 changes: 73 additions & 0 deletions trunk-recorder/tsbk_socket.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "tsbk_socket.h"

TSBK_Socket::TSBK_Socket(std::string server_addr, int port) : m_server(""), m_port(5678) {
m_server = server_addr;
m_port = port;


m_servlen = sizeof(m_servaddr);

if ( (m_sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
BOOST_LOG_TRIVIAL(error) << "Failure in creating TSBK UDP socket.";
exit(EXIT_FAILURE);
}

m_servaddr.sin_family = AF_INET;
m_servaddr.sin_port = htons(m_port);
char* c_server = const_cast<char*>(m_server.c_str());
m_servaddr.sin_addr.s_addr = inet_addr(c_server);
}

void TSBK_Socket::send_tsbk(boost::dynamic_bitset<> &tsbk, System *system) {

if (m_server.empty())
return;

boost::property_tree::ptree root;

root.put("version", "V1");
root.put("type", "tsbk");
root.put("sysName", system->get_short_name());
root.put("tsbk", tsbk);

std::stringstream tsbk_str;
boost::property_tree::write_json(tsbk_str, root);

// std::cout << stats_str;
TSBK_Socket::send_msg(tsbk_str.str());
}

int TSBK_Socket::send_msg(std::string val) {
char* c = const_cast<char*>(val.c_str());

sendto(m_sockfd, c, strlen(c), 0,
(struct sockaddr*)&m_servaddr, m_servlen);
return 0;
}

void TSBK_Socket::send_mbt(boost::dynamic_bitset<> &tsbk, System *system) {

if (m_server.empty())
return;

boost::property_tree::ptree root;

root.put("version", "V1");
root.put("type", "mbt");
root.put("sysName", system->get_short_name());
root.put("tsbk", tsbk);

std::stringstream tsbk_str;
boost::property_tree::write_json(tsbk_str, root);

// std::cout << stats_str;
TSBK_Socket::send_msg(tsbk_str.str());
}

int TSBK_Socket::send_msg(std::string val) {
char* c = const_cast<char*>(val.c_str());

sendto(m_sockfd, c, strlen(c), 0,
(struct sockaddr*)&m_servaddr, m_servlen);
return 0;
}
33 changes: 33 additions & 0 deletions trunk-recorder/tsbk_socket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#if !defined(__TSBK_Socket_H__)
#define __TSBK_Socket_H__

#include <bits/stdc++.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <boost/property_tree/json_parser.hpp>
#include <boost/dynamic_bitset.hpp>
#include "systems/system.h"

class TSBK_Socket {

public:
TSBK_Socket(std::string server_addr, int port);
void send_tsbk(boost::dynamic_bitset<> &tsbk, System *system);
int send_msg(std::string val);

private:
std::string m_server;
int m_port;
int m_sockfd;
struct sockaddr_in m_servaddr;
int m_servlen;

};

inline TSBK_Socket *tsbk_socket;

#endif