-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add to_json function for borzoi packets
- Loading branch information
1 parent
ef0f885
commit e83f72d
Showing
6 changed files
with
122 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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; | ||
|
||
/// 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); | ||
}; | ||
|
||
struct BorzoiSendTetraSlots { | ||
std::string time; | ||
std::string station; | ||
const Slots& slots; | ||
|
||
/// 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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2024 Transit Live Mapping Solutions | ||
* All rights reserved. | ||
* | ||
* Authors: | ||
* Marenz Schmidl | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "borzoi/borzoi_packets.hpp" | ||
#include "nlohmann/std_unique_ptr_logical_link_control_packet.hpp" | ||
#include <nlohmann/json.hpp> | ||
|
||
namespace nlohmann { | ||
template <> struct adl_serializer<BorzoiSendTetraPacket> { | ||
static void to_json(json& j, const BorzoiSendTetraPacket& bstp) { | ||
j = json::object(); | ||
j["time"] = bstp.time; | ||
j["station"] = bstp.station; | ||
adl_serializer<std::unique_ptr<LogicalLinkControlPacket>>::to_json(j, bstp.packet); | ||
} | ||
}; | ||
} // namespace nlohmann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2024 Transit Live Mapping Solutions | ||
* All rights reserved. | ||
* | ||
* Authors: | ||
* Marenz Schmidl | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "borzoi/borzoi_packets.hpp" | ||
#include "nlohmann/slots.hpp" | ||
#include <nlohmann/json.hpp> | ||
|
||
namespace nlohmann { | ||
template <> struct adl_serializer<BorzoiSendTetraSlots> { | ||
static void to_json(json& j, const BorzoiSendTetraSlots& bsts) { | ||
j = json::object(); | ||
j["time"] = bsts.time; | ||
j["station"] = bsts.station; | ||
adl_serializer<Slots>::to_json(j, bsts.slots); | ||
} | ||
}; | ||
} // namespace nlohmann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2024 Transit Live Mapping Solutions | ||
* All rights reserved. | ||
* | ||
* Authors: | ||
* Marenz Schmidl | ||
*/ | ||
|
||
#include "borzoi/borzoi_packets.hpp" | ||
|
||
inline static auto get_time() -> std::string { | ||
auto t = std::time(nullptr); | ||
auto tm = *std::localtime(&t); | ||
std::stringstream ss; | ||
ss << std::put_time(&tm, "%FT%T%z"); | ||
return ss.str(); | ||
} | ||
|
||
BorzoiSendTetraPacket::BorzoiSendTetraPacket(const std::unique_ptr<LogicalLinkControlPacket>& packet, | ||
std::string borzoi_uuid) | ||
: station(std::move(borzoi_uuid)) | ||
, packet(packet) { | ||
time = get_time(); | ||
} | ||
|
||
BorzoiSendTetraSlots::BorzoiSendTetraSlots(const Slots& slots, std::string borzoi_uuid) | ||
: station(std::move(borzoi_uuid)) | ||
, slots(slots) { | ||
time = get_time(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters