Neuralynx library

The Neuralynx library is used to:

  • handle incoming records (e.g. nlxreader)

  • construct a NlxRecord object with required number of channels

  • read packet into char buffer and call NlxRecord::FromNetworkBuffer

If the buffer is valid (i.e. record size is OK, first 3 fields are OK, CRC checks out), it grabs data, timestamp, parallel port value with member methods to create new record and constructs a NlxRecord object with required number of channels (optionally Initialize() - will be done during construction), then it sets the new record and Finalize() (will compute CRC) and finally copy packet into external buffer to be sent over network using ToNetworkBuffer.

namespace nlx

Functions

constexpr uint16_t NLX_NFIELDS(uint16_t c)
constexpr uint16_t NLX_PACKETBYTESIZE(uint16_t c)
constexpr uint16_t NLX_NCHANNELS_FROM_PACKETBYTESIZE(uint16_t sz)
constexpr uint16_t NLX_NCHANNELS_FROM_NFIELDS(uint16_t n)
bool valid_nlx_vt(VideoRec *vt_record, std::uint16_t vt_id, ErrorNLXVT::Code &error_code, decltype(NLX_VIDEO_RESOLUTION) resolution)
inline const unsigned int nlx_field_data_last(unsigned int nchannels = NLX_DEFAULT_NCHANNELS)
inline const unsigned int nlx_field_crc(unsigned int nchannels = NLX_DEFAULT_NCHANNELS)
inline const int32_t nlx_packetsize(unsigned int nchannels = NLX_DEFAULT_NCHANNELS)
uint64_t CheckTimestamp(const NlxSignalRecord &rec, uint64_t &last_timestamp, NlxStatistics &stats)

Variables

constexpr uint16_t NLX_NFIELDS_EXTRA = 10
constexpr uint16_t NLX_FIELDBYTESIZE = 4
constexpr uint16_t SUCCESS_READING_BUFFER = 0
constexpr uint16_t ERROR_NLX_FIELD_STX = 2
constexpr uint16_t ERROR_NLX_FIELD_RAWPACKETID = 3
constexpr uint16_t ERROR_NLX_FIELD_PACKETSIZE = 5
constexpr uint16_t ERROR_TOO_SMALL_PACKET = 4
constexpr uint16_t ERROR_BAD_CRC = 1
constexpr uint16_t NLX_FIELD_STX = 0
constexpr uint16_t NLX_FIELD_RAWPACKETID = 1
constexpr uint16_t NLX_FIELD_PACKETSIZE = 2
constexpr uint16_t NLX_FIELD_TIMESTAMP_HIGH = 3
constexpr uint16_t NLX_FIELD_TIMESTAMP_LOW = 4
constexpr uint16_t NLX_FIELD_DIO = 6
constexpr uint16_t NLX_FIELD_EXTRA_FIRST = 7
constexpr uint16_t NLX_FIELD_DATA_FIRST = NLX_FIELD_EXTRA_FIRST + NLX_NFIELDS_EXTRA
constexpr double NLX_AD_BIT_MICROVOLTS = 0.015624999960550667
constexpr int32_t NLX_STX = 2048
constexpr int32_t NLX_RAWPACKETID = 1
constexpr uint16_t NLX_DEFAULT_NCHANNELS = 128
constexpr uint16_t NLX_MAX_NCHANNELS = 1024
constexpr double NLX_SIGNAL_SAMPLING_FREQUENCY = 32000
constexpr unsigned int NLX_DEFAULT_BUFFERSIZE = NLX_PACKETBYTESIZE(NLX_DEFAULT_NCHANNELS)
const double NLX_VIDEO_SAMPLING_FREQUENCY = 25
const int VTRecNumTransitionBitfields = 400

Number of VT bitfield transitions stored in the VideoRec::dwPoints array

const int VTRecNumTargets = 50

Number of VT bitfield transitions stored in the VideoRec::dntargets array

const std::uint16_t VTRecSWST = 0x800

Value always used for VideoRec::swstx.

const std::array<std::int32_t, 2> NLX_VIDEO_RESOLUTION = {{720, 576}}
constexpr decltype(NLX_SIGNAL_SAMPLING_FREQUENCY) SAMPLING_PERIOD_MICROSEC = 1e6 / NLX_SIGNAL_SAMPLING_FREQUENCY
const uint64_t MAX_ALLOWABLE_TIMEGAP_MICROSECONDS = trunc(SAMPLING_PERIOD_MICROSEC) + 1
constexpr uint64_t INVALID_TIMESTAMP = std::numeric_limits<uint64_t>::max()
__attribute__

Public Members

std::uint16_t swstx

Value is always NlxDataTypes::NLX_VTREC_SWSTX.

std::uint16_t swid

The ID assigned to the video tracker that created this record.

std::uint16_t swdata_size

The size of the VT record in bytes.

std::uint64_t qwTimeStamp

Timestamp of this record in microseconds.

std::uint32_t dwPoints[VTRecNumTransitionBitfields]

An array of bitfields encoding all threshold crossings in the video frame.

std::int16_t sncrc

Ignored, relic from Cheetah160VT.

std::int32_t dnextracted_x

Calculated x coordinate from our extraction algorithm.

std::int32_t dnextracted_y

Calculated y coordinate from our extraction algorithm.

std::int32_t dnextracted_angle

the Y axis

Calculated head direction in degrees from

std::int32_t dntargets[VTRecNumTargets]

An array of aggregated transitions in the same bitfield format as VideoRec::dwPoints

struct ErrorNLXVT

Public Types

enum Code

Values:

enumerator UNKNOWN
enumerator NO_ERROR
enumerator SWSTX
enumerator SWID
enumerator SWDATA_SIZE
enumerator NEGATIVE_COORDINATE
enumerator OUT_OF_RESOLUTION
class NlxSignalRecord

Public Functions

NlxSignalRecord(unsigned int nchannels = NLX_DEFAULT_NCHANNELS, bool convert_byte_order = true)
unsigned int nchannels() const
void set_nchannels(unsigned int n)
bool convert_byte_order() const
void set_convert_byte_order(bool b)
int FromNetworkBuffer(const char *buffer, size_t n)
template<typename T>
inline int FromNetworkBuffer(const std::vector<T> &buffer)
size_t ToNetworkBuffer(char *buffer, size_t n)
template<typename T>
inline size_t ToNetworkBuffer(std::vector<T> &buffer)
void Initialize()
void Finalize()
int32_t crc() const
bool initialized() const
bool finalized() const
int valid(std::vector<int32_t> buffer)
uint64_t timestamp() const
void set_timestamp(uint64_t t)
void inc_timestamp(uint64_t delta)
void inc_timestamp(double delta)
uint32_t parallel_port() const
void set_parallel_port(uint32_t dio = 0)
void data(std::vector<int32_t> &v) const
std::vector<int32_t>::iterator data(std::vector<int32_t>::iterator it) const
int32_t sample(unsigned int index) const
void set_data(int32_t value = 0)
void set_data(std::vector<int32_t> &v)
void set_data(std::vector<int32_t>::iterator it)
void data(std::vector<double> &v) const
std::vector<double>::iterator data(std::vector<double>::iterator it) const
double sample_microvolt(unsigned int index) const
void set_data(double value = 0)
void set_data(std::vector<double> &v)
void set_data(std::vector<double>::iterator it)

Public Members

std::vector<int32_t> buffer_
int32_t nlx_packetsize_
class NlxStatistics

Public Functions

inline NlxStatistics()
void clear()

Public Members

uint64_t n_invalid
uint64_t n_duplicated
uint64_t n_outoforder
uint64_t n_missed
uint64_t n_gaps