34 #include "tdmascheduleevent.pb.h" 39 class EMANE::Events::TDMAScheduleEvent::Implementation
47 if(!msg.ParseFromString(serialization))
49 throw SerializationException(
"unable to deserialize : TDMAScheduleEvent");
52 std::uint32_t u32FramesPerMultiFrame{};
53 std::uint32_t u32SlotsPerFrame{};
55 if(msg.has_structure())
57 const auto & structure = msg.structure();
59 u32FramesPerMultiFrame = structure.framespermultiframe();
60 u32SlotsPerFrame = structure.slotsperframe();
62 structure_ = SlotStructure{structure.bandwidthhz(),
63 u32FramesPerMultiFrame,
68 bHasStructure_ =
true;
70 slotInfos_.reserve(u32FramesPerMultiFrame * u32SlotsPerFrame);
76 for(
unsigned i = 0; i < u32FramesPerMultiFrame; ++i)
78 for(
unsigned j = 0; j < u32SlotsPerFrame; ++j)
85 for(
const auto & frame :msg.frames())
87 std::uint32_t u32FrameIndex = frame.index();
89 if(bHasStructure_ && u32FrameIndex >= u32FramesPerMultiFrame)
91 throw makeException<SerializationException>(
"TDMAScheduleEvent : Frame %lu index out of range",
95 std::set<std::uint32_t> presentSlots{};
97 for(
const auto & slot : frame.slots())
100 std::uint64_t u64FrequencyHz{};
101 std::uint64_t u64DataRatebps{};
102 std::uint8_t u8ServiceClass{};
106 std::uint32_t u32SlotIndex = slot.index();
108 if(bHasStructure_ && u32SlotIndex >= u32SlotsPerFrame)
110 throw makeException<SerializationException>(
"TDMAScheduleEvent : Frame %lu Slot %lu slot index out of range",
115 presentSlots.insert(u32SlotIndex);
119 case EMANEMessage::TDMAScheduleEvent::Frame::Slot::SLOT_TX:
121 const auto & tx = slot.tx();
125 if(tx.has_frequencyhz())
127 u64FrequencyHz = tx.frequencyhz();
129 else if(frame.has_frequencyhz())
131 u64FrequencyHz = frame.frequencyhz();
133 else if(msg.has_frequencyhz())
135 u64FrequencyHz = msg.frequencyhz();
139 throw makeException<SerializationException>(
"TDMAScheduleEvent : Frame %lu Slot %lu has undeterminable frequency",
144 if(tx.has_dataratebps())
146 u64DataRatebps = tx.dataratebps();
148 else if(frame.has_dataratebps())
150 u64DataRatebps = frame.dataratebps();
152 else if(msg.has_dataratebps())
154 u64DataRatebps = msg.dataratebps();
158 throw makeException<SerializationException>(
"TDMAScheduleEvent : Frame %lu Slot %lu has undeterminable datarate",
164 if(tx.has_serviceclass())
166 u8ServiceClass = tx.serviceclass();
168 else if(frame.has_serviceclass())
170 u8ServiceClass = frame.serviceclass();
172 else if(msg.has_serviceclass())
174 u8ServiceClass = msg.serviceclass();
178 throw makeException<SerializationException>(
"TDMAScheduleEvent : Frame %lu Slot %lu has undeterminable class",
184 if(tx.has_powerdbm())
186 dPowerdBm = tx.powerdbm();
188 else if(frame.has_powerdbm())
190 dPowerdBm = frame.powerdbm();
192 else if(msg.has_powerdbm())
194 dPowerdBm = msg.powerdbm();
198 throw makeException<SerializationException>(
"TDMAScheduleEvent : Frame %lu Slot %lu has undeterminable power",
204 if(tx.has_destination())
206 destination = tx.destination();
211 case EMANEMessage::TDMAScheduleEvent::Frame::Slot::SLOT_RX:
213 const auto & rx = slot.rx();
217 if(rx.has_frequencyhz())
219 u64FrequencyHz = rx.frequencyhz();
221 else if(frame.has_frequencyhz())
223 u64FrequencyHz = frame.frequencyhz();
225 else if(msg.has_frequencyhz())
227 u64FrequencyHz = msg.frequencyhz();
231 throw makeException<SerializationException>(
"TDMAScheduleEvent : Frame %lu Slot %lu has undeterminable frequency",
238 case EMANEMessage::TDMAScheduleEvent::Frame::Slot::SLOT_IDLE:
244 frequencies_.insert(u64FrequencyHz);
248 slotInfos_[u32FrameIndex * u32SlotsPerFrame + u32SlotIndex] =
260 slotInfos_.push_back({type,
274 for(
unsigned i = 0; i < u32SlotsPerFrame; ++i)
276 if(!presentSlots.count(i))
278 std::uint64_t u64FrequencyHz{};
280 if(frame.has_frequencyhz())
282 u64FrequencyHz = frame.frequencyhz();
284 else if(msg.has_frequencyhz())
286 u64FrequencyHz = msg.frequencyhz();
290 throw makeException<SerializationException>(
"TDMAScheduleEvent : Frame %lu Slot %lu has undeterminable frequency",
295 frequencies_.insert(u64FrequencyHz);
319 return {structure_,bHasStructure_};
325 SlotStructure structure_;
332 pImpl_{
new Implementation{serialization}}{}
338 return pImpl_->getSlotInfos();
345 return pImpl_->getFrequencies();
348 std::pair<const EMANE::Events::SlotStructure &,bool>
351 return pImpl_->getSlotStructure();
std::string Serialization
Event interface is the base for all events.
std::set< uint64_t > Frequencies
const Frequencies & getFrequencies() const
std::pair< const SlotStructure &, bool > getSlotStructure() const
std::chrono::microseconds Microseconds
std::vector< SlotInfo > SlotInfos
TDMAScheduleEvent(const Serialization &serialization)
const SlotInfos & getSlotInfos() const