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,
39 uint32_t headSize,
40 uint32_t tailSize,
41 uint32_t alignSize,
42 bool enSsi) {
43 uint32_t x;
44
45 enSsi_ = enSsi;
46 app_ = app;
47 tran_ = tran;
48 appIndex_ = 0;
49 tranIndex_ = 0;
50 tranDest_ = 0;
51 dropCount_ = 0;
53 log_ = rogue::Logging::create("packetizer.Controller");
54
56
57 headSize_ = headSize;
58 tailSize_ = tailSize;
59 alignSize_ = alignSize;
60
61 for (x = 0; x < 256; x++) {
62 transSof_[x] = true;
63 crc_[x] = 0;
64 tranCount_[x] = 0;
65 }
66}
67
69rpp::Controller::~Controller() {
70 this->stopQueue();
71}
72
74void rpp::Controller::stopQueue() {
76 tranQueue_.stop();
77}
78
80// Needs to be updated to support cascaded packetizers
81ris::FramePtr rpp::Controller::reqFrame(uint32_t size) {
82 ris::FramePtr lFrame;
83 ris::FramePtr rFrame;
84 ris::BufferPtr buff;
85 uint32_t fSize;
86
87 // Create frame container for request response
88 lFrame = ris::Frame::create();
89
90 // Align total size to configured alignment
91 if ((size % alignSize_) != 0) size += (alignSize_ - (size % alignSize_));
92
93 // Request individual frames upstream
94 while (lFrame->getAvailable() < size) {
95 // Generate a new size with header and tail
96 fSize = (size - lFrame->getAvailable()) + headSize_ + tailSize_;
97
98 // Pass request
99 rFrame = tran_->reqFrame(fSize, false);
100
101 // Take only the first buffer. This will break a cascaded packetizer
102 // system. We need to fix this!
103 buff = *(rFrame->beginBuffer());
104
105 // Use buffer tail reservation to align available payload
106 if (((buff->getAvailable() - tailSize_) % alignSize_) != 0)
107 buff->adjustTail((buff->getAvailable() - tailSize_) % alignSize_);
108
109 // Buffer should support our header/tail plus at least one payload byte
110 if (buff->getAvailable() < (headSize_ + tailSize_ + 1))
111 throw(rogue::GeneralError::create("packetizer::Controller::reqFrame",
112 "Buffer size %" PRIu32 " is less than min size required %" PRIu32,
113 buff->getAvailable(),
114 (headSize_ + tailSize_ + 1)));
115
116 // Add 8 bytes to head and tail reservation
117 buff->adjustHeader(headSize_);
118 buff->adjustTail(tailSize_);
119
120 // Add buffer to return frame
121 lFrame->appendBuffer(buff);
122 }
123 return (lFrame);
124}
125
127void rpp::Controller::transportRx(ris::FramePtr frame) {}
128
130// Called by transport class thread
131ris::FramePtr rpp::Controller::transportTx() {
132 ris::FramePtr frame;
133 frame = tranQueue_.pop();
134 return (frame);
135}
136
138void rpp::Controller::applicationRx(ris::FramePtr frame, uint8_t tDest) {}
139
141uint32_t rpp::Controller::getDropCount() {
142 return (dropCount_);
143}
144
146void rpp::Controller::setTimeout(uint32_t timeout) {
147 div_t divResult = div(timeout, 1000000);
148 timeout_.tv_sec = divResult.quot;
149 timeout_.tv_usec = divResult.rem;
150}
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:60
void setThold(uint32_t thold)
Sets busy-threshold depth used by busy().
Definition Queue.h:84
rogue::Queue< std::shared_ptr< rogue::interfaces::stream::Frame > > tranQueue_
Definition Controller.h:72
std::shared_ptr< rogue::protocols::packetizer::Application > * app_
Definition Controller.h:70
std::shared_ptr< rogue::protocols::packetizer::Transport > tran_
Definition Controller.h:69
std::shared_ptr< rogue::Logging > log_
Definition Controller.h:62
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:109
std::shared_ptr< rogue::protocols::packetizer::Application > ApplicationPtr
void defaultTimeout(struct timeval &tout)
Returns Rogue default timeout as a timeval.
Definition Helpers.h:49