38using miosix::ConditionVariable;
39using miosix::FastMutex;
41using std::range_error;
54template <
unsigned int len>
78 size_t append(
const uint8_t* msg,
size_t msgLen);
126 inline unsigned int maxSize()
const {
return len; }
145 unsigned int msgCounter = 0;
146 uint64_t timestamp = 0;
150template <
unsigned int len>
153 size_t remaining = len - content.size();
154 msgLen = std::min(remaining, msgLen);
159 if (content.size() == 0)
163 content.insert(content.end(), msg, msg + msgLen);
170template <
unsigned int len>
179template <
unsigned int len>
182 std::copy(content.begin(), content.end(), buf);
183 return content.size();
186template <
unsigned int len>
189 os <<
"timestamp=" << timestamp <<
", ready=" << ready
190 <<
", size=" << content.size() <<
", msgCounter=" << msgCounter
193 for (
auto const& i : content)
208template <
unsigned int pktLen,
unsigned int pktNum>
226 bool put(uint8_t* msg,
size_t msgLen)
233 if (msgLen > pktLen * pktNum)
238 Lock<FastMutex> l(mutex);
241 if (buffer.count() == 0)
248 if (buffer.last().isReady())
252 size_t appendedLength = buffer.last().append(msg, msgLen);
255 if (buffer.last().isFull())
256 buffer.last().markAsReady();
259 msgLen -= appendedLength;
260 msg += appendedLength;
265 condVerNotEmpty.broadcast();
273 const Packet<pktLen>
get()
275 Lock<FastMutex> l(mutex);
282 const Packet<pktLen>
pop()
284 Lock<FastMutex> l(mutex);
293 Lock<FastMutex> l(mutex);
295 if (buffer.count() > 0)
296 return buffer.isFull() && buffer.last().isReady();
306 Lock<FastMutex> l(mutex);
307 return buffer.isEmpty();
317 Lock<FastMutex> l(mutex);
318 if (buffer.isEmpty())
319 condVerNotEmpty.wait(mutex);
327 Lock<FastMutex> l(mutex);
329 if (!buffer.isEmpty())
331 return buffer.last().isReady() ? buffer.count()
332 : buffer.count() - 1;
346 Lock<FastMutex> l(mutex);
347 return buffer.count();
352 ConditionVariable condVerNotEmpty;
353 CircularBuffer<Packet<pktLen>, pktNum> buffer;
The Packet class is used for packing together messages with variable lengths into a fixed size packet...
~Packet()
Clears the buffer.
unsigned int maxSize() const
std::vector< uint8_t > content
uint64_t getTimestamp() const
size_t dump(uint8_t *buf)
Copies the content of the payload at the given address.
void markAsReady()
Mark the packet as ready.
Packet()
Reserves a fixed length for the packet.
void print(std::ostream &os) const
Print information about this object.
void clear()
Clear the buffer and reset members.
unsigned int getMsgCount() const
size_t append(const uint8_t *msg, size_t msgLen)
Append a given message to the packet.
A SyncPacketQueue is a SyncCircularBuffer of Packets.
const Packet< pktLen > get()
bool put(uint8_t *msg, size_t msgLen)
Try to append a given message to the packets queue.
void waitUntilNotEmpty()
Blocks the calling thread until the queue is not empty.
const Packet< pktLen > pop()
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.