Skip to content

Commit

Permalink
parse cmce type3 elements for sds
Browse files Browse the repository at this point in the history
  • Loading branch information
marenz2569 committed Jul 6, 2024
1 parent 4ede98f commit 268b66e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 7 deletions.
61 changes: 59 additions & 2 deletions include/l3/circuit_mode_control_entity_packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "l3/mobile_link_entity_packet.hpp"
#include "utils/address.hpp"
#include "utils/bit_vector.hpp"
#include "utils/type234_parser.hpp"
#include <optional>
#include <variant>

Expand Down Expand Up @@ -229,15 +230,71 @@ constexpr auto to_string(CircuitModeControlEntityPacketType type) -> const char*
return std::visit([](auto&& arg) { return to_string(arg); }, type);
}

enum class CircuitModeControlEntityType3ElementIdentifiers {
kReserved,
kDTMF,
kExternalSubsriberNumber,
kFacility,
kPollResponseAddresses,
kTemporaryAddress,
kDmMsAddress,
kReservedForAnyFutureSpecifiedType3Element7,
kReservedForAnyFutureSpecifiedType3Element8,
kReservedForAnyFutureSpecifiedType3Element9,
kReservedForAnyFutureSpecifiedType3Element10,
kReservedForAnyFutureSpecifiedType3Element11,
kReservedForAnyFutureSpecifiedType3Element12,
kReservedForAnyFutureSpecifiedType3Element13,
kReservedForAnyFutureSpecifiedType3Element14,
kProprietary,
};

constexpr auto to_string(CircuitModeControlEntityType3ElementIdentifiers type) -> const char* {
switch (type) {
case CircuitModeControlEntityType3ElementIdentifiers::kReserved:
return "Reserved";
case CircuitModeControlEntityType3ElementIdentifiers::kDTMF:
return "DTMF";
case CircuitModeControlEntityType3ElementIdentifiers::kExternalSubsriberNumber:
return "External subscriber number";
case CircuitModeControlEntityType3ElementIdentifiers::kFacility:
return "Facility";
case CircuitModeControlEntityType3ElementIdentifiers::kPollResponseAddresses:
return "Poll response addresses";
case CircuitModeControlEntityType3ElementIdentifiers::kTemporaryAddress:
return "Temporary address";
case CircuitModeControlEntityType3ElementIdentifiers::kDmMsAddress:
return "DM-MS address";
case CircuitModeControlEntityType3ElementIdentifiers::kReservedForAnyFutureSpecifiedType3Element7:
return "Reserved for any future specified Type 3 element 7";
case CircuitModeControlEntityType3ElementIdentifiers::kReservedForAnyFutureSpecifiedType3Element8:
return "Reserved for any future specified Type 3 element 8";
case CircuitModeControlEntityType3ElementIdentifiers::kReservedForAnyFutureSpecifiedType3Element9:
return "Reserved for any future specified Type 3 element 9";
case CircuitModeControlEntityType3ElementIdentifiers::kReservedForAnyFutureSpecifiedType3Element10:
return "Reserved for any future specified Type 3 element 10";
case CircuitModeControlEntityType3ElementIdentifiers::kReservedForAnyFutureSpecifiedType3Element11:
return "Reserved for any future specified Type 3 element 11";
case CircuitModeControlEntityType3ElementIdentifiers::kReservedForAnyFutureSpecifiedType3Element12:
return "Reserved for any future specified Type 3 element 12";
case CircuitModeControlEntityType3ElementIdentifiers::kReservedForAnyFutureSpecifiedType3Element13:
return "Reserved for any future specified Type 3 element 13";
case CircuitModeControlEntityType3ElementIdentifiers::kReservedForAnyFutureSpecifiedType3Element14:
return "Reserved for any future specified Type 3 element 14";
case CircuitModeControlEntityType3ElementIdentifiers::kProprietary:
return "Proprietary";
}
};

struct SdsData {
/// the area selection that is present in the uplink sds
std::optional<unsigned _BitInt(4)> area_selection_;
/// the from or to address of the sds cmce packet
Address address_;
/// the sds data that is included int he cmce packet
BitVector data_;
/// TODO: The "External subscriber number" and "DM-MS address" is not parsed!
BitVector unparsed_;
// This map may contain the "External subscriber number" and "DM-MS address"
Type234Parser<CircuitModeControlEntityType3ElementIdentifiers>::Map optional_elements_;

private:
SdsData() = default;
Expand Down
26 changes: 24 additions & 2 deletions src/borzoi/borzoi_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,30 @@ auto BorzoiConverter::to_json(ShortDataServicePacket* packet) -> nlohmann::json
message["data"].push_back(bits);
}
message["arbitrary"] = nlohmann::json::object();
message["arbitrary"]["bits_in_last_byte"] = data.bits_left();
message["data"].push_back(data.take_all());
if (data.bits_left() > 0) {
message["arbitrary"]["bits_in_last_byte"] = data.bits_left();
message["data"].push_back(data.take_all());
} else {
message["arbitrary"]["bits_in_last_byte"] = 8;
}
message["arbitrary"]["optional_fiels"] = nlohmann::json::object();
for (const auto& [key, value] : packet->sds_data_->optional_elements_) {
auto& vec = message["arbitrary"]["optional_fiels"][to_string(key)];
vec = nlohmann::json::object();
vec["repeated_elements"] = value.repeated_elements;
vec["unparsed_bits"] = nlohmann::json::array();
auto data = BitVector(value.unparsed_bits);
while (data.bits_left() >= 8) {
unsigned bits = data.take<8>();
vec["unparsed_bits"].push_back(bits);
}
if (data.bits_left() > 0) {
vec["bits_in_last_byte"] = data.bits_left();
vec["unparsed_bits"].push_back(data.take_all());
} else {
vec["bits_in_last_byte"] = 8;
}
}
message["time"] = get_time();

return message;
Expand Down
4 changes: 3 additions & 1 deletion src/l3/circuit_mode_control_entity_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ auto operator<<(std::ostream& stream, const SdsData& sds) -> std::ostream& {
}
stream << " SDS Address: " << sds.address_ << std::endl;
stream << " Data: " << sds.data_ << std::endl;
stream << " Unparsed: " << sds.unparsed_ << std::endl;
for (const auto& [key, value] : sds.optional_elements_) {
stream << " " << to_string(key) << " " << value << std::endl;
}
return stream;
};

Expand Down
14 changes: 12 additions & 2 deletions src/l3/circuit_mode_control_entity_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ auto SdsData::from_d_sds_data(BitVector& data) -> SdsData {
break;
}
sds.data_ = data.take_vector(length_identifier);
sds.unparsed_ = data.take_vector(data.bits_left());
auto parser = Type234Parser<CircuitModeControlEntityType3ElementIdentifiers>(
data,
{CircuitModeControlEntityType3ElementIdentifiers::kExternalSubsriberNumber,
CircuitModeControlEntityType3ElementIdentifiers::kDmMsAddress},
{});
sds.optional_elements_ = parser.parse_type34(data);

return sds;
}
Expand Down Expand Up @@ -76,7 +81,12 @@ auto SdsData::from_u_sds_data(BitVector& data) -> SdsData {
break;
}
sds.data_ = data.take_vector(length_identifier);
sds.unparsed_ = data.take_vector(data.bits_left());
auto parser = Type234Parser<CircuitModeControlEntityType3ElementIdentifiers>(
data,
{CircuitModeControlEntityType3ElementIdentifiers::kExternalSubsriberNumber,
CircuitModeControlEntityType3ElementIdentifiers::kDmMsAddress},
{});
sds.optional_elements_ = parser.parse_type34(data);

return sds;
}
Expand Down

0 comments on commit 268b66e

Please sign in to comment.