Beispiel #1
0
/*! \brief Create 64 bit counter for a packet.
	\details 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
	\param pack The XsDataPacket that needs its 64-bit sample counter updated
	\param highestPacket The highest packet available for the current device, it will be updated if
		the new counter is higher than the stored value.
	\returns The computed counter for the packet.
*/
int64_t PacketStamper::stampPacket(XsDataPacket& pack, XsDataPacket& highestPacket)
{
//	int did = 0;
//	if (pack.containsMtwSdiData())
//	{
//		MtwSdiData sdi = pack.mtwSdiData();
//		did = sdi.m_deviceId;
//		JLDEBUG(gJournal, "XsensDeviceAPI", "%s [%08x] SDI interval (%d-%d)\n", __FUNCTION__, sdi.m_deviceId, sdi.m_firstFrameNumber, sdi.m_lastFrameNumber);
//	}

    //! \todo This could be a (couple of) milliseconds too late, this should be set as soon as the source message arrives: mantis 7157
    pack.setTimeOfArrival(XsTimeStamp::now());
    int64_t newCounter, lastCounter = -1;

    if (!highestPacket.empty())
        lastCounter = highestPacket.packetId().msTime();

    if (pack.containsPacketCounter())
        newCounter = calculateLargePacketCounter(pack.packetCounter(), lastCounter);
    else if (pack.containsSampleTimeFine())
    {
        if (pack.containsSampleTimeCoarse())
            newCounter = (int64_t) pack.sampleTime64();
        else
            newCounter = calculateLargeSampleTime((int32_t) pack.sampleTimeFine(), lastCounter);
    }
    else if (pack.containsPacketCounter8())
        newCounter = calculateLargePacketCounter8(pack.packetCounter8(), lastCounter);
    else
        newCounter = lastCounter + 1;

//	JLDEBUG(gJournal, "XsensDeviceAPI", "%s [%08x] old = %I64d new = %I64d diff = %I64d\n", __FUNCTION__, did, lastCounter, newCounter, (newCounter-lastCounter));

    pack.setPacketId(newCounter);
    if (newCounter > lastCounter)
        highestPacket = pack;

    return newCounter;
}