Supplies functionality for timestamping data packets. More...
#include <packetstamper.h>
Classes | |
struct | DataPair |
Public Member Functions | |
PacketStamper () | |
Default constructor. More... | |
void | resetTosEstimation () |
Reset the Time Of Sampling estimation parameters. More... | |
int64_t | stampPacket (XsDataPacket &pack, XsDataPacket const &highest) |
Create 64 bit counter for a packet. More... | |
Static Public Member Functions | |
static int64_t | calculateLargePacketCounter (int64_t frameCounter, int64_t lastCounter, int64_t boundary) |
Calculate the new large packet counter value based on frameCounter and the lastCounter. More... | |
static int64_t | calculateLargeSampleTime (int64_t frameTime, int64_t lastTime) |
Calculate the new large sample time value based on frameTime and the lastTime. More... | |
Static Public Attributes | |
static const int64_t | AWINDABOUNDARY = 0x100000000LL |
32 bit MT Sample Counter boundary More... | |
static const int64_t | MTSCBOUNDARY = 0x00010000LL |
16 bit MT Sample Counter boundary More... | |
static const int64_t | SC8BOUNDARY = 0x00000100LL |
8 bit Sample Counter boundary More... | |
Protected Member Functions | |
void | estimateClockParameters () |
Estimate the clock parameters based on the available data points. More... | |
void | estimateTos (XsDataPacket &pack) |
Estimate the time of sampling for the supplied packet pack and update it. More... | |
int64_t | estimateTosInternal (int64_t pid, int64_t toa) |
Estimate the time of sampling for the supplied pid. More... | |
bool | rejectOutlier () |
Remove the worst outlier from the known data points. More... | |
Protected Attributes | |
std::list< DataPair > | m_dataPoints |
The filtered history of interesting data items. More... | |
DataPair | m_latest |
Latest known data (later data may arrive with a lower pid, which will not be put in this item) More... | |
DataPair | m_linearize |
The very first item received, used to normalize to 0,0 so we have less computational issues with large numbers. More... | |
double | m_rate |
The estimated clock rate per pid. More... | |
int | m_rejectionCountdown |
A countdown value that is used after the input sanity check rejects input to reject subsequent samples as well. More... | |
double | m_toa0 |
The recomputed Time Of Arrival of PID 0. More... | |
Supplies functionality for timestamping data packets.
This class can analyze a data packet and create a proper packet id for it.
Definition at line 73 of file packetstamper.h.
PacketStamper::PacketStamper | ( | ) |
Default constructor.
Definition at line 83 of file packetstamper.cpp.
|
static |
Calculate the new large packet counter value based on frameCounter and the lastCounter.
Wraparound is at the given boundary
[in] | frameCounter | The frame counter |
[in] | lastCounter | The last counter |
[in] | boundary | the boundary at which to assume a wrap-around |
Definition at line 106 of file packetstamper.cpp.
|
static |
Calculate the new large sample time value based on frameTime and the lastTime.
Wraparound is at 864000000 (1 day @ 10kHz)
[in] | frameTime | The frame time |
[in] | lastTime | The last time |
Definition at line 175 of file packetstamper.cpp.
|
protected |
Estimate the clock parameters based on the available data points.
Uses a least-square estimation to fit a line through the known dataset and then shifts the line down to ensure the TOA >= ETOS constraint holds
Definition at line 203 of file packetstamper.cpp.
|
protected |
Estimate the time of sampling for the supplied packet pack and update it.
Definition at line 191 of file packetstamper.cpp.
|
protected |
Estimate the time of sampling for the supplied pid.
This function will estimate the time of samplinmg based on the supplied PID. If both PID and TOA are acceptable values, they will be used to update the estimation parameters.
The current algorithm expects the values to be estimated to be constant for the lifetime of the object.
pid | The packet ID to estimate the time of sampling for. |
toa | The time of arrival associated with this pid |
Definition at line 284 of file packetstamper.cpp.
|
protected |
Remove the worst outlier from the known data points.
Only items that are more than the estimated rate off from the current estimation are considered outliers
Definition at line 252 of file packetstamper.cpp.
void PacketStamper::resetTosEstimation | ( | ) |
Reset the Time Of Sampling estimation parameters.
Definition at line 89 of file packetstamper.cpp.
int64_t PacketStamper::stampPacket | ( | XsDataPacket & | pack, |
XsDataPacket const & | highestPacket | ||
) |
Create 64 bit counter for a packet.
Wrap when new XsDataPacket is too far away from the previous XsDataPacket in time. Use half cache size as reasonable time difference When infinite cache, simply wrap when new is lower than old
pack | The XsDataPacket that needs its 64-bit sample counter updated |
highestPacket | The highest packet available for the current device, it will be updated if the new counter is higher than the stored value. |
Definition at line 133 of file packetstamper.cpp.
|
static |
32 bit MT Sample Counter boundary
Definition at line 79 of file packetstamper.h.
|
protected |
The filtered history of interesting data items.
Definition at line 102 of file packetstamper.h.
|
protected |
Latest known data (later data may arrive with a lower pid, which will not be put in this item)
Definition at line 100 of file packetstamper.h.
|
protected |
The very first item received, used to normalize to 0,0 so we have less computational issues with large numbers.
Definition at line 101 of file packetstamper.h.
|
protected |
The estimated clock rate per pid.
Definition at line 105 of file packetstamper.h.
|
protected |
A countdown value that is used after the input sanity check rejects input to reject subsequent samples as well.
Definition at line 106 of file packetstamper.h.
|
protected |
The recomputed Time Of Arrival of PID 0.
Definition at line 104 of file packetstamper.h.
|
static |
16 bit MT Sample Counter boundary
Definition at line 80 of file packetstamper.h.
|
static |
8 bit Sample Counter boundary
Definition at line 81 of file packetstamper.h.