Rename timestampMultiplier to timestampResolution

We've also decided to leave it out of the message structures since, for most uses going forward, it will not be needed.

Anyone who wants the timestamp resolution can always make the inexpensive device call to get it.
This commit is contained in:
Paul Hollinsky
2019-05-06 12:32:04 -04:00
parent d1cd34fb24
commit 7cf0ec5f4f
16 changed files with 64 additions and 39 deletions
+7 -2
View File
@@ -599,13 +599,18 @@ bool icsneo_getSupportedDevices(devicetype_t* devices, size_t* count) {
return true;
}
extern bool DLLExport icsneo_getTimestampMultiplier(const neodevice_t* device, int* multiplier)
extern bool DLLExport icsneo_getTimestampResolution(const neodevice_t* device, uint16_t* resolution)
{
if (!icsneo_isValidNeoDevice(device)) {
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
return false;
}
*multiplier = device->device->getTimestampMultiplier();
if (resolution == nullptr) {
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
return false;
}
*resolution = device->device->getTimestampResolution();
return true;
}
+22 -9
View File
@@ -37,7 +37,7 @@ static NeoDevice OldNeoDeviceFromNew(const neodevice_t* newnd) {
return oldnd;
}
static void NeoMessageToSpyMessage(const neomessage_t& newmsg, icsSpyMessage& oldmsg) {
static void NeoMessageToSpyMessage(const neodevice_t* device, const neomessage_t& newmsg, icsSpyMessage& oldmsg) {
memset(&oldmsg, 0, sizeof(icsSpyMessage));
oldmsg.NumberBytesData = (uint8_t)std::min(newmsg.length, (size_t)255);
oldmsg.NumberBytesHeader = 4;
@@ -59,12 +59,25 @@ static void NeoMessageToSpyMessage(const neomessage_t& newmsg, icsSpyMessage& ol
oldmsg.Protocol = SPY_PROTOCOL_ETHERNET;
break;
}
// Timestamp - epoch = 1/1/2007 - 25ns per tick most of the time
uint64_t t = newmsg.timestamp;
if (newmsg.timestampMultiplier)
t /= newmsg.timestampMultiplier;
oldmsg.TimeHardware2 = (unsigned long)(t >> 32);
oldmsg.TimeHardware = (unsigned long)(t & 0xFFFFFFFF);
uint16_t res = 0;
if (icsneo_getTimestampResolution(device, &res)) {
t /= res;
oldmsg.TimeHardware2 = (unsigned long)(t >> 32);
oldmsg.TimeHardware = (unsigned long)(t & 0xFFFFFFFF);
switch (res) {
case 25:
oldmsg.TimeStampHardwareID = HARDWARE_TIMESTAMP_ID_NEORED_25NS;
break;
case 10:
oldmsg.TimeStampHardwareID = HARDWARE_TIMESTAMP_ID_NEORED_10NS;
break;
default:
oldmsg.TimeStampHardwareID = HARDWARE_TIMESTAMP_ID_NONE;
}
}
}
//Basic Functions
@@ -186,7 +199,7 @@ int icsneoGetMessages(void* hObject, icsSpyMessage* pMsg, int* pNumberOfMessages
*pNumberOfErrors = 0;
for(size_t i = 0; i < messageCount; i++)
NeoMessageToSpyMessage(messages[i], pMsg[i]);
NeoMessageToSpyMessage(device, messages[i], pMsg[i]);
return true;
}
@@ -236,8 +249,8 @@ int icsneoGetTimeStampForMsg(void* hObject, icsSpyMessage* pMsg, double* pTimeSt
return false;
neodevice_t* device = (neodevice_t*)hObject;
int multiplier = 0;
if (!icsneo_getTimestampMultiplier(device, &multiplier))
uint16_t resolution = 0;
if (!icsneo_getTimestampResolution(device, &resolution))
return false;
// Convert back to ticks
@@ -246,7 +259,7 @@ int icsneoGetTimeStampForMsg(void* hObject, icsSpyMessage* pMsg, double* pTimeSt
ticks += pMsg->TimeHardware;
// convert to ns
ticks *= multiplier;
ticks *= resolution;
// icsneoGetTimeStampForMsg() expects pTimeStamp to be in seconds
*pTimeStamp = ticks / (double)1000000000;