Skip to content
Permalink
Browse files

fix candlelight timestamp bugs

  • Loading branch information...
HubertD committed May 17, 2016
1 parent c8d29c6 commit 804b7e142c3c55cdcf5498e5a1a0c1c5ff975e0d
@@ -5,7 +5,8 @@ CandleApiInterface::CandleApiInterface(CandleApiDriver *driver, candle_handle ha
: CanInterface(driver),
_perfCountStart(0),
_deviceTicksLastSync(0),
_tLastSync_us(0),
_hostTicksLastSync(0),
_startTime_us(0),
_handle(handle),
_numRx(0),
_numTx(0),
@@ -206,7 +207,7 @@ void CandleApiInterface::syncTimestamp()
t *= 1000000;
t /= _perfTicksPerSecond;

_tLastSync_us = t;
_hostTicksLastSync = t;
_deviceTicksLastSync = t_dev;
}
}
@@ -222,7 +223,7 @@ void CandleApiInterface::checkSyncTimestamp()
t /= _perfTicksPerSecond;

// resync if last sync is older than 10sec
if ( (t - _tLastSync_us) > 10000000 ) {
if ( (t - _hostTicksLastSync) > 10000000 ) {
syncTimestamp();
}

@@ -280,6 +281,8 @@ void CandleApiInterface::open()
_numTx = 0;
_numTxErr = 0;

_startTime_us = 1000 * QDateTime::currentMSecsSinceEpoch();

candle_channel_start(_handle, 0, flags);
}

@@ -337,10 +340,13 @@ bool CandleApiInterface::readMessage(CanMessage &msg, unsigned int timeout_ms)

checkSyncTimestamp();

uint32_t dev_ts = candle_frame_timestamp_us(&frame);
int64_t dev_ts = candle_frame_timestamp_us(&frame);
dev_ts -= _deviceTicksLastSync;
if (dev_ts<-20000000) {
dev_ts += 0x100000000;
}

uint64_t ts_us = _tLastSync_us + dev_ts;
uint64_t ts_us = _startTime_us + _hostTicksLastSync + dev_ts;
msg.setTimestamp(ts_us/1000000, ts_us % 1000000);

return true;
@@ -51,9 +51,10 @@ class CandleApiInterface : public CanInterface

uint64_t _perfTicksPerSecond;
uint64_t _perfCountStart;

uint32_t _deviceTicksLastSync;
uint64_t _tLastSync_us;
uint64_t _hostTicksLastSync;
uint64_t _startTime_us;


candle_handle _handle;
MeasurementInterface _settings;
@@ -468,6 +468,7 @@ bool __stdcall DLL candle_channel_start(candle_handle hdev, uint8_t ch, uint32_t
{
// TODO ensure device is open, check channel count..
candle_device_t *dev = (candle_device_t*)hdev;
flags |= CANDLE_MODE_HW_TIMESTAMP;
return candle_ctrl_set_device_mode(dev, ch, CANDLE_DEVMODE_START, flags);
}

0 comments on commit 804b7e1

Please sign in to comment.
You can’t perform that action at this time.