rogue
Loading...
Searching...
No Matches
Controller.cpp
Go to the documentation of this file.
1
18
19#include <inttypes.h>
20
21#include <cmath>
22#include <memory>
23
24#include "rogue/GeneralError.h"
25#include "rogue/GilRelease.h"
26#include "rogue/Helpers.h"
32
35
37rpp::Controller::Controller(rpp::TransportPtr tran,
38 uint32_t headSize,
39 uint32_t tailSize,
40 uint32_t alignSize,
41 bool enSsi) {
42 uint32_t x;
43
44 enSsi_ = enSsi;
45 tran_ = tran;
46 appIndex_ = 0;
47 tranIndex_ = 0;
48 tranDest_ = 0;
49 dropCount_ = 0;
51 log_ = rogue::Logging::create("packetizer.Controller");
52
54
55 headSize_ = headSize;
56 tailSize_ = tailSize;
57 alignSize_ = alignSize;
58
59 for (x = 0; x < 256; x++) {
60 transSof_[x] = true;
61 crc_[x] = 0;
62 tranCount_[x] = 0;
63 }
64}
65
67rpp::Controller::~Controller() {
68 this->stopQueue();
69}
70
72void rpp::Controller::stopQueue() {
74 tranQueue_.stop();
75}
76
78// Needs to be updated to support cascaded packetizers
79ris::FramePtr rpp::Controller::reqFrame(uint32_t size) {
80 ris::FramePtr lFrame;
81 ris::FramePtr rFrame;
82 ris::BufferPtr buff;
83 uint32_t fSize;
84
85 // Create frame container for request response
86 lFrame = ris::Frame::create();
87
88 // Align total size to configured alignment
89 if ((size % alignSize_) != 0) size += (alignSize_ - (size % alignSize_));
90
91 // Request individual frames upstream
92 while (lFrame->getAvailable() < size) {
93 // Generate a new size with header and tail
94 fSize = (size - lFrame->getAvailable()) + headSize_ + tailSize_;
95
96 // Pass request
97 rFrame = tran_->reqFrame(fSize, false);
98
99 // Take only the first buffer. This will break a cascaded packetizer
100 // system. We need to fix this!
101 buff = *(rFrame->beginBuffer());
102
103 // Use buffer tail reservation to align available payload
104 if (((buff->getAvailable() - tailSize_) % alignSize_) != 0)
105 buff->adjustTail((buff->getAvailable() - tailSize_) % alignSize_);
106
107 // Buffer should support our header/tail plus at least one payload byte
108 if (buff->getAvailable() < (headSize_ + tailSize_ + 1))
109 throw(rogue::GeneralError::create("packetizer::Controller::reqFrame",
110 "Buffer size %" PRIu32 " is less than min size required %" PRIu32,
111 buff->getAvailable(),
112 (headSize_ + tailSize_ + 1)));
113
114 // Add 8 bytes to head and tail reservation
115 buff->adjustHeader(headSize_);
116 buff->adjustTail(tailSize_);
117
118 // Add buffer to return frame
119 lFrame->appendBuffer(buff);
120 }
121 return (lFrame);
122}
123
125void rpp::Controller::transportRx(ris::FramePtr frame) {}
126
128// Called by transport class thread
129ris::FramePtr rpp::Controller::transportTx() {
130 ris::FramePtr frame;
131 frame = tranQueue_.pop();
132 return (frame);
133}
134
136void rpp::Controller::applicationRx(ris::FramePtr frame, uint8_t tDest) {}
137
139uint32_t rpp::Controller::getDropCount() {
140 return (dropCount_);
141}
142
144void rpp::Controller::setApplication(uint8_t dest, rpp::ApplicationPtr app) {
145 std::lock_guard<std::mutex> lock(tranMtx_);
146 app_[dest] = app;
147}
148
150void rpp::Controller::setTimeout(uint32_t timeout) {
151 div_t divResult = div(timeout, 1000000);
152 timeout_.tv_sec = divResult.quot;
153 timeout_.tv_usec = divResult.rem;
154}
static GeneralError create(std::string src, const char *fmt,...)
Creates a formatted error instance.
RAII helper that releases the Python GIL for a scope.
Definition GilRelease.h:36
static std::shared_ptr< rogue::Logging > create(const std::string &name, bool quiet=false)
Creates a logger instance.
Definition Logging.cpp:95
void setThold(uint32_t thold)
Sets busy-threshold depth used by busy().
Definition Queue.h:80
rogue::Queue< std::shared_ptr< rogue::interfaces::stream::Frame > > tranQueue_
Definition Controller.h:74
std::atomic< uint32_t > dropCount_
Definition Controller.h:56
std::shared_ptr< rogue::protocols::packetizer::Transport > tran_
Definition Controller.h:70
std::shared_ptr< rogue::Logging > log_
Definition Controller.h:63
std::shared_ptr< rogue::interfaces::stream::Buffer > BufferPtr
Shared pointer alias for Buffer.
Definition Buffer.h:270
std::shared_ptr< rogue::interfaces::stream::Frame > FramePtr
Shared pointer alias for Frame.
Definition Frame.h:549
std::shared_ptr< rogue::protocols::packetizer::Transport > TransportPtr
Definition Transport.h:120
std::shared_ptr< rogue::protocols::packetizer::Application > ApplicationPtr
void defaultTimeout(struct timeval &tout)
Returns Rogue default timeout as a timeval.
Definition Helpers.h:49