ReduxLib C++ 2024.1.1-beta0
Loading...
Searching...
No Matches
redux::frames::Frame< T > Class Template Reference

#include <Frame.h>

Public Member Functions

 Frame (T value, units::second_t timestamp)
 
void Update (T value, units::second_t timestamp)
 
FrameData< T > GetFrameData ()
 
GetValue ()
 
units::second_t GetTimestamp ()
 
uint32_t AddCallback (std::function< void(FrameData< T >)> callback)
 
bool RemoveCallback (uint32_t key)
 
void AddListener (FrameListener< T > *listener)
 
void RemoveListener (FrameListener< T > *listener)
 

Detailed Description

template<typename T>
class redux::frames::Frame< T >

Class representing periodic timestamped data received from CAN or other sources.

For applications like latency compensation, we often need both sensor/device data and a timestamp of when the data was received. Frames provide this by holding the most recently received raw data and the timestamps they were received at and allowing retrieval of both data and timestamps in one FrameData object via Frame.GetFrameData(), avoiding race conditions involving reading data and timestamp separately. Additionally, they allow for synchronous reads through WaitForFrames by notifying when new data has been received.

Constructor & Destructor Documentation

◆ Frame()

template<typename T >
redux::frames::Frame< T >::Frame ( value,
units::second_t  timestamp 
)
inline

Constructs a new Frame object.

Parameters
valueThe initial value to hold.
timestampThe initial timestamp at which the value was received in seconds.

Member Function Documentation

◆ AddCallback()

template<typename T >
uint32_t redux::frames::Frame< T >::AddCallback ( std::function< void(FrameData< T >)>  callback)
inline

Add a callback that will be run whenever this Frame gets updated. Example application (may not be applicable)

// Log Canandcoder position FrameData.
std::vector<FrameData<units::turn_t>> position_packets;
enc0.GetPositionFrame().AddCallback([&](FrameData<units::turn_t> frameData) {
position_packets.push_back(frameData);
});
// Timestamped data is now appended to the Vector.
Definition: Frame.h:21
Definition: Canandcoder.h:91
Parameters
callbackthe callback
Returns
an handle key that can be used to unregister the callback later

◆ AddListener()

template<typename T >
void redux::frames::Frame< T >::AddListener ( FrameListener< T > *  listener)
inline

Internal use function (for WaitForFrames)

Parameters
listenerlistener pointer to add

◆ GetFrameData()

template<typename T >
FrameData< T > redux::frames::Frame< T >::GetFrameData ( )
inline

Fetches an immutable FrameData snapshot of the currently stored values

Returns
FrameData of value/timestamp pair

◆ GetTimestamp()

template<typename T >
units::second_t redux::frames::Frame< T >::GetTimestamp ( )
inline

Gets the timestamp in seconds of when this frame was last updated.

Returns
the timestamp in seconds.

◆ GetValue()

template<typename T >
T redux::frames::Frame< T >::GetValue ( )
inline

Returns the current frame's value.

Returns
the value the data frame holds.

◆ RemoveCallback()

template<typename T >
bool redux::frames::Frame< T >::RemoveCallback ( uint32_t  key)
inline

Unregister a callback run whenever this Frame gets updated.

Parameters
keythe key returned by AddCallback
Returns
true on unregister, false if the callback didn't exist

◆ RemoveListener()

template<typename T >
void redux::frames::Frame< T >::RemoveListener ( FrameListener< T > *  listener)
inline

Internal use function (for WaitForFrames)

Parameters
listenerlistener pointer to remove. you must remove your listener before the end of its life or you will cause memory corruption

◆ Update()

template<typename T >
void redux::frames::Frame< T >::Update ( value,
units::second_t  timestamp 
)
inline

Updates the Frame's value, notifying any listeners of new data.

Parameters
valuethe new value
timestampthe new timestamp of the received data

The documentation for this class was generated from the following file: