openDAQ
Open data acquisition platform
GenericDataPacketPtr< InterfaceType > Class Template Reference

Packet that contains data sent by a signal. The data can be either explicit, or implicit. More...

+ Inheritance diagram for GenericDataPacketPtr< InterfaceType >:
+ Collaboration diagram for GenericDataPacketPtr< InterfaceType >:

Detailed Description

template<typename InterfaceType>
class GenericDataPacketPtr< InterfaceType >

Packet that contains data sent by a signal. The data can be either explicit, or implicit.

Explicit data is contained within a signal's buffer, accessible through getRawData, while implicit packets do not carry any data. Their values are calculated given a rule, packet offset, and the index of a sample within the data buffer.

To obtain implicitly calculated, or scaled values, getData should be used. The data descriptor and sample count provide information about the type and amount of data available at the obtained address.

Public Member Functions

daq::DataDescriptorPtr getDataDescriptor () const
 Gets the signal descriptor of the signal that sent the packet at the time of sending. More...
 
daq::SizeT getSampleCount () const
 Gets the number of samples in the packet. More...
 
daq::NumberPtr getOffset () const
 Gets current packet offset. This offset is later applied to the data rule used by a signal to calculate actual data value. This value is usually a time or other domain value. Packet offset is particularly useful when one wants to transfer a gap in otherwise equidistant samples. If we have a linear data rule, defined by equation f(x) = k*x + n, then the data value will be calculated by the equation g(x) = offset + f(x). More...
 
void * getData () const
 Gets the calculated/scaled data address of the packet. More...
 
void * getRawData () const
 Gets a pointer to the raw packet data. nullptr if the signal's data rule is implicit. More...
 
daq::SizeT getDataSize () const
 Gets size of data buffer in bytes. More...
 
daq::SizeT getRawDataSize () const
 Gets size of raw data buffer in bytes. More...
 
daq::GenericDataPacketPtr< daq::IDataPacket > getDomainPacket () const
 Gets the associated domain Data packet. More...
 
daq::Int getPacketId () const
 Gets the unique packet id. More...
 
daq::BaseObjectPtr getLastValue (const daq::TypeManagerPtr &typeManager=nullptr) const
 Gets the data packet last value. More...
 
daq::BaseObjectPtr getValueByIndex (daq::SizeT index, const daq::TypeManagerPtr &typeManager=nullptr) const
 Gets the data packet last value. More...
 
void * getRawLastValue () const
 Gets the last raw value of the data packet. More...
 
void * getRawValueByIndex (daq::SizeT index) const
 Gets the raw value of the data packet at the specified index. More...
 
- Public Member Functions inherited from GenericPacketPtr< InterfaceType >
daq::PacketType getType () const
 Gets the packet's type. More...
 
void subscribeForDestructNotification (const daq::PacketDestructCallbackPtr &packetDestructCallback) const
 Subscribes for notification when the packet is destroyed. More...
 
daq::SizeT getRefCount () const
 Gets the reference count of the packet. More...
 

Member Function Documentation

◆ getData()

void* getData ( ) const
inline

Gets the calculated/scaled data address of the packet.

Returns
The address of the data.

getData uses the packet's data descriptor to calculate the values as follows:

  1. If the data rule is implicit, it uses the packet offset and sample count to calculate the data according to the rule.
  2. If the data rule is explicit:
  • If the data is a Struct, it returns a pointer to the raw data.
  • If no Post scaling is defined, it simply returns a pointer to the raw data.
  • If the Post scaling is defined, it scales the data and returns a pointer to the scaled data.

The data should be cast to the appropriate type, as defined by the data descriptor, and read while keeping the data dimensions in mind.

◆ getDataDescriptor()

daq::DataDescriptorPtr getDataDescriptor ( ) const
inline

Gets the signal descriptor of the signal that sent the packet at the time of sending.

Returns
The signal descriptor.

◆ getDataSize()

daq::SizeT getDataSize ( ) const
inline

Gets size of data buffer in bytes.

Returns
the size of data buffer in bytes.

◆ getDomainPacket()

daq::GenericDataPacketPtr<daq::IDataPacket> getDomainPacket ( ) const
inline

Gets the associated domain Data packet.

Returns
The domain data packet.

◆ getLastValue()

daq::BaseObjectPtr getLastValue ( const daq::TypeManagerPtr &  typeManager = nullptr) const
inline

Gets the data packet last value.

Returns
The IBaseObject value can be a nullptr if there is no value, or if the data type is not supported by the function.
Parameters
typeManagerOptional ITypeManager value can be provided to enable getLastValue for IStruct.

If a value is assigned, it can be cast based on the signal description to IFloat if the type is Float32 or Float64, to IInteger if the type is Int8 through Int64 or UInt8 through UInt64, to IComplexNumber if the type is ComplexFloat32 or ComplexFloat64, to IRange if the type is RangeInt64, to IStruct if the type is Struct, and to IList of the forementioned types if there is exactly one dimension.

◆ getOffset()

daq::NumberPtr getOffset ( ) const
inline

Gets current packet offset. This offset is later applied to the data rule used by a signal to calculate actual data value. This value is usually a time or other domain value. Packet offset is particularly useful when one wants to transfer a gap in otherwise equidistant samples. If we have a linear data rule, defined by equation f(x) = k*x + n, then the data value will be calculated by the equation g(x) = offset + f(x).

Returns
The packet offset

◆ getPacketId()

daq::Int getPacketId ( ) const
inline

Gets the unique packet id.

Returns
The packet unique id.

The packet id is automatically created on packet construction.

◆ getRawData()

void* getRawData ( ) const
inline

Gets a pointer to the raw packet data. nullptr if the signal's data rule is implicit.

Returns
Pointer to the raw packet data.

◆ getRawDataSize()

daq::SizeT getRawDataSize ( ) const
inline

Gets size of raw data buffer in bytes.

Parameters
[out]dataSizethe size of raw data buffer in bytes.

Raw data size is 0 if signal's data rule is implicit.

◆ getRawLastValue()

void* getRawLastValue ( ) const
inline

Gets the last raw value of the data packet.

Returns
A pointer to a memory location where the raw value will be stored.

This method writes the raw value of the last sample to the provided memory location. It does not allocate memory and assumes that sufficient memory has already been allocated. The value is not cast to any specific type; it remains a raw data pointer. The method does not verify whether the allocated memory size matches the sample size.

◆ getRawValueByIndex()

void* getRawValueByIndex ( daq::SizeT  index) const
inline

Gets the raw value of the data packet at the specified index.

Returns
A pointer to a memory location where the raw value will be stored.
Parameters
[in]indexThe index of the sample to retrieve.

This method writes the raw value of the sample at the specified index to the provided memory location. It does not allocate memory and assumes that sufficient memory has already been allocated. The value is not cast to any specific type; it remains a raw data pointer. The method does not verify whether the allocated memory size matches the sample size.

◆ getSampleCount()

daq::SizeT getSampleCount ( ) const
inline

Gets the number of samples in the packet.

Returns
the number of samples.

◆ getValueByIndex()

daq::BaseObjectPtr getValueByIndex ( daq::SizeT  index,
const daq::TypeManagerPtr &  typeManager = nullptr 
) const
inline

Gets the data packet last value.

Returns
The IBaseObject value can be a nullptr if there is no value, or if the data type is not supported by the function.
Parameters
[in]indexIndex of the sample to obtain.
typeManagerOptional ITypeManager value can be provided to enable getLastValue for IStruct.

If a value is assigned, it can be cast based on the signal description to IFloat if the type is Float32 or Float64, to IInteger if the type is Int8 through Int64 or UInt8 through UInt64, to IComplexNumber if the type is ComplexFloat32 or ComplexFloat64, to IRange if the type is RangeInt64, to IStruct if the type is Struct, and to IList of the forementioned types if there is exactly one dimension.