Skip to content

Commit

Permalink
Merge pull request #12 from tlm-solutions/refactor-upper-mac
Browse files Browse the repository at this point in the history
Refactor Lower Mac
  • Loading branch information
marenz2569 authored Jun 11, 2024
2 parents 4a43f93 + c30050e commit 377ef60
Show file tree
Hide file tree
Showing 23 changed files with 1,295 additions and 947 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ add_executable(tetra-decoder
src/l2/broadcast_synchronization_channel.cpp
src/l2/logical_link_control.cpp
src/l2/lower_mac.cpp
src/l2/lower_mac_coding.cpp
src/l2/timebase_counter.cpp
src/l2/upper_mac.cpp
src/l2/upper_mac_fragmentation.cpp
Expand Down
6 changes: 3 additions & 3 deletions include/l2/access_assignment_channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

#include "burst_type.hpp"
#include "l2/timebase_counter.hpp"
#include <cstdint>
#include "utils/bit_vector.hpp"
#include <optional>
#include <ostream>
#include <vector>

enum DownlinkUsage { CommonControl, Unallocated, AssignedControl, CommonAndAssignedControl, Traffic };

Expand All @@ -22,7 +21,8 @@ struct AccessAssignmentChannel {
std::optional<int> downlink_traffic_usage_marker;

AccessAssignmentChannel() = delete;
AccessAssignmentChannel(BurstType burst_type, const TimebaseCounter& time, const std::vector<uint8_t>& data);

AccessAssignmentChannel(BurstType burst_type, const TimebaseCounter& time, BitVector&& vec);

friend auto operator<<(std::ostream& stream, const AccessAssignmentChannel& aac) -> std::ostream&;
};
Expand Down
6 changes: 3 additions & 3 deletions include/l2/broadcast_synchronization_channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "burst_type.hpp"
#include "l2/timebase_counter.hpp"
#include "utils/bit_vector.hpp"
#include <cstdint>
#include <vector>

struct BroadcastSynchronizationChannel {
public:
Expand All @@ -29,11 +29,11 @@ struct BroadcastSynchronizationChannel {
uint32_t mobile_network_code = 0;
uint8_t dNwrk_broadcast_broadcast_supported = 0;
uint8_t dNwrk_broadcast_enquiry_supported = 0;
uint8_t cell_load_ca = 0;
unsigned _BitInt(2) cell_load_ca = 0;
uint8_t late_entry_supported = 0;

BroadcastSynchronizationChannel() = default;
BroadcastSynchronizationChannel(const BurstType burst_type, const std::vector<uint8_t>& data);
BroadcastSynchronizationChannel(const BurstType burst_type, BitVector&& vec);

friend auto operator<<(std::ostream& stream, const BroadcastSynchronizationChannel& bsc) -> std::ostream&;
};
Expand Down
28 changes: 28 additions & 0 deletions include/l2/logical_channel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2024 Transit Live Mapping Solutions
* All rights reserved.
*
* Authors:
* Marenz Schmidl
*/

#pragma once

#include "utils/bit_vector.hpp"

enum class LogicalChannel {
kSignalingChannelHalfDownlink,
kSignalingChannelHalfUplink,
kTrafficChannel,
kSignalingChannelFull,
kStealingChannel
};

struct LogicalChannelDataAndCrc {
/// the logical channel
LogicalChannel channel;
/// the data on the logical channel
BitVector data;
/// true if the crc of the signaling channels is ok
bool crc_ok;
};
26 changes: 10 additions & 16 deletions include/l2/lower_mac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#pragma once

#include "l2/broadcast_synchronization_channel.hpp"
#include "l2/slot.hpp"
#include "l2/timebase_counter.hpp"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -62,6 +64,8 @@ class LowerMacPrometheusCounters {
/// The counter for the too many bursts in the downlink lower MAC
prometheus::Counter& lower_mac_burst_too_many_count_;

/// TODO: add gauge for the synchronization burst time

public:
LowerMacPrometheusCounters(std::shared_ptr<PrometheusExporter>& prometheus_exporter)
: burst_received_count_family_(prometheus_exporter->burst_received_count())
Expand Down Expand Up @@ -167,35 +171,25 @@ class LowerMac {
std::optional<uint32_t> scrambling_code = std::nullopt);
~LowerMac() = default;

// does the signal processing and then returns a list of function that need to be executed for data to be passed
// to upper mac sequentially.
// does the signal processing and then returns the slots containing the correct logical channels and their
// associated data to be passed to the upper mac and further processed in a sequential order.
[[nodiscard]] auto processChannels(const std::vector<uint8_t>& frame, BurstType burst_type,
const BroadcastSynchronizationChannel& bsc)
-> std::vector<std::function<void()>>;
const BroadcastSynchronizationChannel& bsc) -> Slots;

/// handles the decoding of the synchronization bursts and once synchronized passes the data to the decoding of the
/// channels. keeps track of the current network time
[[nodiscard]] auto process(const std::vector<uint8_t>& frame, BurstType burst_type)
-> std::vector<std::function<void()>>;

private:
std::shared_ptr<Reporter> reporter_{};
std::shared_ptr<ViterbiCodec> viter_bi_codec_1614_{};
std::shared_ptr<UpperMac> upper_mac_{};
std::shared_ptr<Reporter> reporter_;
const ViterbiCodec viter_bi_codec_1614_;
std::shared_ptr<UpperMac> upper_mac_;

std::unique_ptr<LowerMacPrometheusCounters> metrics_;

/// The last received synchronization burst.
/// This include the current scrambling code. Set by Synchronization Burst on downlink or injected from the side for
/// uplink processing, as we decouple it from the downlink for data/control packets.
std::optional<BroadcastSynchronizationChannel> sync_;

static auto descramble(const uint8_t* data, uint8_t* res, std::size_t len, uint32_t scramblingCode) noexcept
-> void;
static auto deinterleave(const uint8_t* data, uint8_t* res, std::size_t K, std::size_t a) noexcept -> void;
[[nodiscard]] static auto depuncture23(const uint8_t* data, uint32_t len) noexcept -> std::vector<int16_t>;
static auto reed_muller_3014_decode(const uint8_t* data, uint8_t* res) noexcept -> void;
[[nodiscard]] static auto check_crc_16_ccitt(const uint8_t* data, std::size_t len) noexcept -> bool;

[[nodiscard]] auto viter_bi_decode_1614(const std::vector<int16_t>& data) const noexcept -> std::vector<uint8_t>;
};
Loading

0 comments on commit 377ef60

Please sign in to comment.