Merge remote-tracking branch 'drebbe-intrepid/master' into timestamp

pull/13/head
Paul Hollinsky 2019-05-06 12:01:09 -04:00
commit d1cd34fb24
9 changed files with 61 additions and 4 deletions

View File

@ -597,4 +597,15 @@ bool icsneo_getSupportedDevices(devicetype_t* devices, size_t* count) {
*count = len;
return true;
}
}
extern bool DLLExport icsneo_getTimestampMultiplier(const neodevice_t* device, int* multiplier)
{
if (!icsneo_isValidNeoDevice(device)) {
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
return false;
}
*multiplier = device->device->getTimestampMultiplier();
return true;
}

View File

@ -59,6 +59,12 @@ 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);
}
//Basic Functions
@ -226,8 +232,26 @@ int icsneoEnableNetworkRXQueue(void* hObject, int iEnable) {
}
int icsneoGetTimeStampForMsg(void* hObject, icsSpyMessage* pMsg, double* pTimeStamp) {
// TODO Implement
return false;
if(!icsneoValidateHObject(hObject))
return false;
neodevice_t* device = (neodevice_t*)hObject;
int multiplier = 0;
if (!icsneo_getTimestampMultiplier(device, &multiplier))
return false;
// Convert back to ticks
uint64_t ticks = pMsg->TimeHardware2;
ticks <<= 32;
ticks += pMsg->TimeHardware;
// convert to ns
ticks *= multiplier;
// icsneoGetTimeStampForMsg() expects pTimeStamp to be in seconds
*pTimeStamp = ticks / (double)1000000000;
return true;
}
void icsneoGetISO15765Status(void* hObject, int lNetwork, int lClearTxStatus, int lClearRxStatus, int*lTxStatus, int*lRxStatus) {

View File

@ -28,6 +28,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
// Timestamps are in (multiplier) ns increments since 1/1/2007 GMT 00:00:00.0000
// The resolution (multiplier) depends on the device
result->timestamp *= timestampMultiplier;
result->timestampMultiplier = timestampMultiplier;
result->network = packet->network;
return true;
case Network::Type::CAN:
@ -43,6 +44,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
// Timestamps are in (multiplier) ns increments since 1/1/2007 GMT 00:00:00.0000
// The resolution (multiplier) depends on the device
result->timestamp *= timestampMultiplier;
result->timestampMultiplier = timestampMultiplier;
result->network = packet->network;
return true;
}

View File

@ -14,6 +14,7 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
neomsg.length = message->data.size();
neomsg.data = message->data.data();
neomsg.timestamp = message->timestamp;
neomsg.timestampMultiplier = message->timestampMultiplier;
neomsg.status.globalError = message->error;
neomsg.status.transmitMessage = message->transmitted;

View File

@ -67,6 +67,10 @@ bool Device::SerialStringIsNumeric(const std::string& serial) {
return isdigit(serial[0]) && isdigit(serial[1]);
}
int Device::getTimestampMultiplier() const {
return com->decoder->timestampMultiplier;
}
std::string Device::describe() const {
std::stringstream ss;
ss << getType() << ' ' << getSerial();

View File

@ -12,6 +12,7 @@ public:
Network network;
std::vector<uint8_t> data;
uint64_t timestamp = 0;
int timestampMultiplier = 0;
uint16_t description = 0;
bool transmitted = false;
bool error = false;

View File

@ -108,7 +108,8 @@ typedef struct {
uint8_t header[4];
uint16_t netid;
uint8_t type;
uint8_t reserved[17];
uint8_t reserved[15];
uint16_t timestampMultiplier;
} neomessage_t; // 72 bytes total
// Any time you add another neomessage_*_t type, make sure to add it to the static_asserts below!

View File

@ -29,6 +29,7 @@ public:
static uint32_t SerialStringToNum(const std::string& serial);
static bool SerialStringIsNumeric(const std::string& serial);
int getTimestampMultiplier() const;
DeviceType getType() const { return DeviceType(data.type); }
uint16_t getProductId() const { return productId; }
std::string getSerial() const { return data.serial; }

View File

@ -626,6 +626,18 @@ extern size_t DLLExport icsneo_getErrorLimit(void);
*/
extern bool DLLExport icsneo_getSupportedDevices(devicetype_t* devices, size_t* count);
/**
* \brief Get the devices timestamp multiplier
* \param[out] device A pointer to a buffer of devicetype_t structures which will be written to.
* \param[inout] multiplier A pointer to an int, for legacy tick rate to ns
* \returns True unless device is invalid
*/
extern bool DLLExport icsneo_getTimestampMultiplier(const neodevice_t* device, int* multiplier);
#ifdef __cplusplus
} // extern "C"
#endif