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

Cleanup Borzoi #22

Merged
merged 20 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "lib/ViterbiDecoderCpp"]
path = lib/ViterbiDecoderCpp
url = https://github.com/FiendChain/ViterbiDecoderCpp.git
[submodule "lib/rapidcsv"]
path = lib/rapidcsv
url = https://github.com/d99kris/rapidcsv.git
71 changes: 39 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -5,36 +5,38 @@ set(CMAKE_CXX_STANDARD 17)

option(NIX_BUILD "Is CMake called by a nix build?" OFF)

add_library(tetra-decoder-library
src/decoder.cpp
src/bit_stream_decoder.cpp
src/iq_stream_decoder.cpp
src/prometheus.cpp
src/borzoi/borzoi_packets.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
src/l2/logical_link_control_packet.cpp
src/l2/lower_mac.cpp
src/l2/slot.cpp
src/l2/timebase_counter.cpp
src/l2/upper_mac.cpp
src/l2/upper_mac_packet.cpp
src/l2/upper_mac_packet_builder.cpp
src/l2/upper_mac_packet_formatter.cpp
src/l3/circuit_mode_control_entity_formatter.cpp
src/l3/circuit_mode_control_entity_packet.cpp
src/l3/mobile_link_entity_formatter.cpp
src/l3/mobile_link_entity_packet.cpp
src/l3/mobile_management_formatter.cpp
src/l3/mobile_management_packet.cpp
src/l3/short_data_service_formatter.cpp
src/l3/short_data_service_packet.cpp
src/utils/address.cpp
src/utils/bit_vector.cpp
src/utils/viter_bi_codec.cpp)

add_executable(tetra-decoder
src/main.cpp
src/decoder.cpp
src/bit_stream_decoder.cpp
src/iq_stream_decoder.cpp
src/prometheus.cpp
src/borzoi/borzoi_converter.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
src/l2/logical_link_control_packet.cpp
src/l2/lower_mac.cpp
src/l2/slot.cpp
src/l2/timebase_counter.cpp
src/l2/upper_mac.cpp
src/l2/upper_mac_packet.cpp
src/l2/upper_mac_packet_builder.cpp
src/l2/upper_mac_packet_formatter.cpp
src/l3/circuit_mode_control_entity_formatter.cpp
src/l3/circuit_mode_control_entity_packet.cpp
src/l3/mobile_link_entity_formatter.cpp
src/l3/mobile_link_entity_packet.cpp
src/l3/mobile_management_formatter.cpp
src/l3/mobile_management_packet.cpp
src/l3/short_data_service_formatter.cpp
src/l3/short_data_service_packet.cpp
src/utils/address.cpp
src/utils/bit_vector.cpp
src/utils/viter_bi_codec.cpp)
src/main.cpp)

add_executable(tetra-puncturing
src/examples/tetra_puncturing.cpp)
@@ -43,11 +45,13 @@ add_executable(tetra-viterbi
src/examples/viter_bi_codec.cpp
src/examples/tetra_viterbi.cpp)

target_compile_options(tetra-decoder PUBLIC -std=c++17 -Wall -Wno-unused-variable -msse4.1 -O3 -fcolor-diagnostics)
target_compile_options(tetra-decoder-library PUBLIC -std=c++17 -Wall -Wno-unused-variable -msse4.1 -O3 -fcolor-diagnostics)
target_compile_options(tetra-decoder PUBLIC -std=c++17 -Wall -Wno-unused-variable)
target_compile_options(tetra-puncturing PUBLIC -std=c++17 -Wall -Wno-unused-variable)
target_compile_options(tetra-viterbi PUBLIC -std=c++17 -Wall -Wno-unused-variable)

include(lib/ViterbiDecoderCpp/viterbi-config.cmake)
include_directories(lib/rapidcsv/src)

include_directories(src)

@@ -61,12 +65,15 @@ find_package(cpr REQUIRED)
include_directories(${CMAKE_SOURCE_DIR}/include)

if (NOT NIX_BUILD)
target_link_libraries(tetra-decoder cxxopts::cxxopts)
target_link_libraries(tetra-decoder-library cxxopts::cxxopts)
endif()

target_link_libraries(tetra-decoder ZLIB::ZLIB fmt::fmt nlohmann_json::nlohmann_json viterbi prometheus-cpp::pull cpr::cpr)
target_link_libraries(tetra-decoder-library ZLIB::ZLIB fmt::fmt nlohmann_json::nlohmann_json viterbi prometheus-cpp::pull cpr::cpr)
target_link_libraries(tetra-decoder tetra-decoder-library)
target_link_libraries(tetra-viterbi viterbi)

install(TARGETS tetra-decoder DESTINATION bin)
install(TARGETS tetra-puncturing DESTINATION bin)
install(TARGETS tetra-viterbi DESTINATION bin)

include(src/experiments/CMakeLists.txt)
17 changes: 0 additions & 17 deletions include/borzoi/borzoi_converter.hpp

This file was deleted.

68 changes: 68 additions & 0 deletions include/borzoi/borzoi_packets.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2024 Transit Live Mapping Solutions
* All rights reserved.
*
* Authors:
* Marenz Schmidl
*/

#pragma once

#include "l2/logical_link_control_packet.hpp"
#include "l2/slot.hpp"

struct BorzoiSendTetraPacket {
std::string time;
std::string station;
const std::unique_ptr<LogicalLinkControlPacket>& packet;

BorzoiSendTetraPacket() = delete;

/// Construct a packet for Borzoi containing the parsed packet, the current time and the uuid of this instance of
/// tetra decoder.
BorzoiSendTetraPacket(const std::unique_ptr<LogicalLinkControlPacket>& packet, std::string borzoi_uuid);

friend auto operator<<(std::ostream& stream, const BorzoiSendTetraPacket& packet) -> std::ostream&;
};

auto operator<<(std::ostream& stream, const BorzoiSendTetraPacket& packet) -> std::ostream&;

struct BorzoiReceiveTetraPacket {
std::string time;
std::string station;
std::unique_ptr<LogicalLinkControlPacket> packet;

BorzoiReceiveTetraPacket() = default;

friend auto operator<<(std::ostream& stream, const BorzoiReceiveTetraPacket& packet) -> std::ostream&;
};

auto operator<<(std::ostream& stream, const BorzoiReceiveTetraPacket& packet) -> std::ostream&;

struct BorzoiSendTetraSlots {
std::string time;
std::string station;
const Slots& slots;

BorzoiSendTetraSlots() = delete;

/// Construct a packet for Borzoi containing the received slot, the current time and the uuid of this instance of
/// tetra decoder.
BorzoiSendTetraSlots(const Slots& slots, std::string borzoi_uuid);

friend auto operator<<(std::ostream& stream, const BorzoiSendTetraSlots& packet) -> std::ostream&;
};

auto operator<<(std::ostream& stream, const BorzoiSendTetraSlots& packet) -> std::ostream&;

struct BorzoiReceiveTetraSlots {
std::string time;
std::string station;
Slots slots;

BorzoiReceiveTetraSlots() = default;

friend auto operator<<(std::ostream& stream, const BorzoiReceiveTetraSlots& packet) -> std::ostream&;
};

auto operator<<(std::ostream& stream, const BorzoiReceiveTetraSlots& packet) -> std::ostream&;
3 changes: 2 additions & 1 deletion include/decoder.hpp
Original file line number Diff line number Diff line change
@@ -88,5 +88,6 @@ class Decoder {
// bit stream -> false
bool iq_or_bit_stream_;

static const std::size_t kRX_BUFFER_SIZE = 4096;
// 64KB receive buffer.
static const std::size_t kRX_BUFFER_SIZE = 64 * 1024;
};
14 changes: 11 additions & 3 deletions include/l2/logical_link_control_packet.hpp
Original file line number Diff line number Diff line change
@@ -46,15 +46,17 @@ constexpr auto to_string(BasicLinkType type) noexcept -> const char* {
};

struct BasicLinkInformation {
BasicLinkType basic_link_type_;
BasicLinkType basic_link_type_{};
std::optional<unsigned _BitInt(1)> n_r_;
std::optional<unsigned _BitInt(1)> n_s_;
std::optional<bool> fcs_good_;

BasicLinkInformation() = delete;
BasicLinkInformation() = default;

/// construct a BasicLinkInformation from a BitVector
explicit BasicLinkInformation(BitVector& data);

NLOHMANN_DEFINE_TYPE_INTRUSIVE(BasicLinkInformation, basic_link_type_, n_r_, n_s_, fcs_good_)
};

auto operator<<(std::ostream& stream, const BasicLinkInformation& bli) -> std::ostream&;
@@ -65,9 +67,15 @@ struct LogicalLinkControlPacket : public UpperMacCPlaneSignallingPacket {
/// The data that is passed from the Logical Link Control layer to the Mobile Link Entity
BitVector tl_sdu_;

LogicalLinkControlPacket() = delete;
LogicalLinkControlPacket() = default;

explicit LogicalLinkControlPacket(const UpperMacCPlaneSignallingPacket& packet);

NLOHMANN_DEFINE_TYPE_INTRUSIVE(LogicalLinkControlPacket, burst_type_, logical_channel_, type_, encrypted_, address_,
fragmentation_, fragmentation_on_stealling_channel_, reservation_requirement_,
tm_sdu_, encryption_mode_, immediate_napping_permission_flag_,
basic_slot_granting_element_, position_of_grant_, channel_allocation_element_,
random_access_flag_, power_control_element_, basic_link_information_, tl_sdu_)
};

auto operator<<(std::ostream& stream, const LogicalLinkControlPacket& llc) -> std::ostream&;
23 changes: 13 additions & 10 deletions include/l2/slot.hpp
Original file line number Diff line number Diff line change
@@ -82,15 +82,15 @@ class Slot {
auto operator<<(std::ostream& stream, const Slot& slot) -> std::ostream&;

/// defines the number and types of slots in a packet
enum class SlotsType { kOneSubslot, kTwoSubslots, kFullSlot };
enum class SlotType { kOneSubslot, kTwoSubslots, kFullSlot };

constexpr auto to_string(SlotsType type) noexcept -> const char* {
constexpr auto to_string(SlotType type) noexcept -> const char* {
switch (type) {
case SlotsType::kOneSubslot:
case SlotType::kOneSubslot:
return "OneSubslot";
case SlotsType::kTwoSubslots:
case SlotType::kTwoSubslots:
return "TwoSubslots";
case SlotsType::kFullSlot:
case SlotType::kFullSlot:
return "FullSlot";
}
};
@@ -113,24 +113,24 @@ struct ConcreateSlot {
class Slots {
private:
/// which burst type ths slots originated from
BurstType burst_type_;
BurstType burst_type_{};
/// the number and types of slots
SlotsType slot_type_;
SlotType slot_type_{};
/// The slots, either one half or full slot or two half slots.
/// We are doing accesses that would normally not be const but are in this case, because we make assumption about
/// the content of this vector based on the constructor used to initialize this class.
mutable std::vector<Slot> slots_;

public:
Slots() = delete;
Slots() = default;

Slots(const Slots& other) = default;

/// constructor for one subslot or a full slot
Slots(BurstType burst_type, SlotsType slot_type, Slot&& slot);
Slots(BurstType burst_type, SlotType slot_type, Slot&& slot);

/// construct for two half slot
Slots(BurstType burst_type, SlotsType slot_type, Slot&& first_slot, Slot&& second_slot);
Slots(BurstType burst_type, SlotType slot_type, Slot&& first_slot, Slot&& second_slot);

/// get a reference to the concreate slots
[[nodiscard]] auto get_concreate_slots() const -> std::vector<ConcreateSlot> {
@@ -169,6 +169,9 @@ class Slots {
/// get the type of the underlying burst
[[nodiscard]] auto get_burst_type() const noexcept -> BurstType { return burst_type_; }

/// get the type of the underlying slot
[[nodiscard]] auto get_slot_type() const noexcept -> SlotType { return slot_type_; }

friend auto operator<<(std::ostream& stream, const Slots& slots) -> std::ostream&;
};

Loading