Skip to content

Commit

Permalink
add config parsing for borzoi
Browse files Browse the repository at this point in the history
  • Loading branch information
marenz2569 committed Jul 2, 2024
1 parent a40daf3 commit a091dba
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ add_executable(tetra-decoder
src/main.cpp
src/decoder.cpp
src/bit_stream_decoder.cpp
src/borzoi_sender.cpp
src/iq_stream_decoder.cpp
src/prometheus.cpp
src/borzoi/borzoi_sender.cpp
src/l2/access_assignment_channel.cpp
src/l2/broadcast_synchronization_channel.cpp
src/l2/logical_link_control_formatter.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class BorzoiSender {
/// \param queue the queue holds either the parsed packets (std::unique_ptr<LogicalLinkControlPacket>) or Slots that
/// failed to decode
/// \param termination_flag this flag is set when the sender should terminate after finishing all work
/// \param borzoi_url the URL of borzoi
BorzoiSender(ThreadSafeFifo<std::variant<std::unique_ptr<LogicalLinkControlPacket>, Slots>>& queue,
std::atomic_bool& termination_flag, unsigned borzoi_port);
std::atomic_bool& termination_flag, const std::string& borzoi_url);

~BorzoiSender();

Expand All @@ -38,6 +39,10 @@ class BorzoiSender {
/// The flag that is set when terminating the program
std::atomic_bool& termination_flag_;

/// The urls of borzoi
std::string borzoi_url_sds_;
std::string borzoi_url_failed_slots_;

/// The worker thread
std::thread worker_thread_;
};
4 changes: 2 additions & 2 deletions include/decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
*/
class Decoder {
public:
Decoder(unsigned int receive_port, unsigned int send_port, bool packed, std::optional<std::string> input_file,
std::optional<std::string> output_file, bool iq_or_bit_stream,
Decoder(unsigned int receive_port, const std::string& borzoi_url, bool packed,
std::optional<std::string> input_file, std::optional<std::string> output_file, bool iq_or_bit_stream,
std::optional<unsigned int> uplink_scrambling_code,
const std::shared_ptr<PrometheusExporter>& prometheus_exporter);
~Decoder();
Expand Down
8 changes: 5 additions & 3 deletions src/borzoi_sender.cpp → src/borzoi/borzoi_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Marenz Schmidl
*/

#include "borzoi_sender.hpp"
#include "borzoi/borzoi_sender.hpp"
#include "l3/circuit_mode_control_entity_packet.hpp"
#include "l3/mobile_link_entity_packet.hpp"
#include "l3/short_data_service_packet.hpp"
Expand All @@ -16,9 +16,11 @@
#endif

BorzoiSender::BorzoiSender(ThreadSafeFifo<std::variant<std::unique_ptr<LogicalLinkControlPacket>, Slots>>& queue,
std::atomic_bool& termination_flag, unsigned borzoi_port)
std::atomic_bool& termination_flag, const std::string& borzoi_url)
: queue_(queue)
, termination_flag_(termination_flag) {
, termination_flag_(termination_flag)
, borzoi_url_sds_(borzoi_url + "/tetra")
, borzoi_url_failed_slots_(borzoi_url + "/tetra/failed_slots") {
worker_thread_ = std::thread(&BorzoiSender::worker, this);

#if defined(__linux__)
Expand Down
6 changes: 3 additions & 3 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <sys/types.h>
#include <unistd.h>

Decoder::Decoder(unsigned receive_port, unsigned send_port, bool packed, std::optional<std::string> input_file,
std::optional<std::string> output_file, bool iq_or_bit_stream,
Decoder::Decoder(unsigned receive_port, const std::string& borzoi_url, bool packed,
std::optional<std::string> input_file, std::optional<std::string> output_file, bool iq_or_bit_stream,
std::optional<unsigned int> uplink_scrambling_code,
const std::shared_ptr<PrometheusExporter>& prometheus_exporter)
: lower_mac_work_queue_(std::make_shared<StreamingOrderedOutputThreadPoolExecutor<LowerMac::return_type>>(
Expand All @@ -37,7 +37,7 @@ Decoder::Decoder(unsigned receive_port, unsigned send_port, bool packed, std::op
auto lower_mac = std::make_shared<LowerMac>(prometheus_exporter, uplink_scrambling_code);
upper_mac_ = std::make_unique<UpperMac>(lower_mac_work_queue_, bozoi_queue_, upper_mac_termination_flag_,
borzoi_sender_termination_flag_, prometheus_exporter);
borzoi_sender_ = std::make_unique<BorzoiSender>(bozoi_queue_, borzoi_sender_termination_flag_, send_port);
borzoi_sender_ = std::make_unique<BorzoiSender>(bozoi_queue_, borzoi_sender_termination_flag_, borzoi_url);
bit_stream_decoder_ =
std::make_shared<BitStreamDecoder>(lower_mac_work_queue_, lower_mac, uplink_scrambling_code_.has_value());
iq_stream_decoder_ =
Expand Down
27 changes: 13 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "decoder.hpp"
#include <csignal>
#include <cstdlib>
#include <cxxopts.hpp>
#include <memory>
#include <stdio.h>

#include <decoder.hpp>
#include <signal_handler.hpp>

volatile bool stop = false;
Expand All @@ -16,9 +14,12 @@ void sigint_handler(int s) {
}

auto main(int argc, char** argv) -> int {
unsigned int receive_port, send_port, debug_level;
bool packed, iq_or_bit_stream;
std::optional<std::string> input_file, output_file;
unsigned int receive_port;
bool packed;
bool iq_or_bit_stream;
std::optional<std::string> input_file;
std::optional<std::string> output_file;
std::string borzoi_url;
std::optional<unsigned> uplink_scrambling_code;
std::optional<std::string> prometheus_address;
std::optional<std::string> prometheus_name;
Expand All @@ -35,10 +36,10 @@ auto main(int argc, char** argv) -> int {
options.add_options()
("h,help", "Print usage")
("r,rx", "<UDP socket> receiving from phy", cxxopts::value<unsigned>()->default_value("42000"))
("t,tx", "<UDP socket> sending Json data", cxxopts::value<unsigned>()->default_value("42100"))
("t,tx", "<UDP socket> sending Json data", cxxopts::value<unsigned>()->default_value("42100"))
("borzoi-url", "<borzoi-url> the base url of which borzoi is running", cxxopts::value<std::string>(borzoi_url)->default_value("http://localhost:3000"))
("i,infile", "<file> replay data from binary file instead of UDP", cxxopts::value<std::optional<std::string>>(input_file))
("o,outfile", "<file> record data to binary file (can be replayed with -i option)", cxxopts::value<std::optional<std::string>>(output_file))
("d", "<level> print debug information", cxxopts::value<unsigned>()->default_value("0"))
("P,packed", "pack rx data (1 byte = 8 bits)", cxxopts::value<bool>()->default_value("false"))
("iq", "Receive IQ instead of bitstream", cxxopts::value<bool>()->default_value("false"))
("uplink", "<scrambling code> enable uplink parsing with predefined scrambilng code", cxxopts::value<std::optional<unsigned>>(uplink_scrambling_code))
Expand All @@ -52,13 +53,11 @@ auto main(int argc, char** argv) -> int {

if (result.count("help")) {
std::cout << options.help() << std::endl;
exit(0);
return EXIT_SUCCESS;
}

receive_port = result["rx"].as<unsigned>();
send_port = result["tx"].as<unsigned>();

debug_level = result["d"].as<unsigned>();
packed = result["packed"].as<bool>();
iq_or_bit_stream = result["iq"].as<bool>();

Expand All @@ -71,15 +70,15 @@ auto main(int argc, char** argv) -> int {
return EXIT_FAILURE;
}

auto decoder = std::make_unique<Decoder>(receive_port, send_port, packed, input_file, output_file, iq_or_bit_stream,
uplink_scrambling_code, prometheus_exporter);
auto decoder = std::make_unique<Decoder>(receive_port, borzoi_url, packed, input_file, output_file,
iq_or_bit_stream, uplink_scrambling_code, prometheus_exporter);

if (input_file.has_value()) {
std::cout << "Reading from input file " << *input_file << std::endl;
} else {
std::cout << "Listening on UDP socket " << receive_port << std::endl;
}
std::cout << "Sending on UDP socket " << send_port << std::endl;
std::cout << "Sending to Borzoi on: " << borzoi_url << std::endl;
if (output_file.has_value()) {
std::cout << "Writing to output file " << *output_file << std::endl;
}
Expand Down

0 comments on commit a091dba

Please sign in to comment.