22#include <netinet/in.h>
29#include "logging/log.hpp"
46constexpr uint16_t NLX_NFIELDS_EXTRA = 10;
47constexpr uint16_t NLX_FIELDBYTESIZE = 4;
48constexpr uint16_t NLX_NFIELDS(uint16_t c) {
49 return (8 + NLX_NFIELDS_EXTRA + (c));
51constexpr uint16_t NLX_PACKETBYTESIZE(uint16_t c) {
52 return (NLX_FIELDBYTESIZE * NLX_NFIELDS(c));
54constexpr uint16_t NLX_NCHANNELS_FROM_PACKETBYTESIZE(uint16_t sz) {
55 return ((sz / NLX_FIELDBYTESIZE) - 8 - NLX_NFIELDS_EXTRA);
57constexpr uint16_t NLX_NCHANNELS_FROM_NFIELDS(uint16_t n) {
58 return n - 8 - NLX_NFIELDS_EXTRA;
61constexpr uint16_t SUCCESS_READING_BUFFER = 0;
62constexpr uint16_t ERROR_NLX_FIELD_STX = 2;
63constexpr uint16_t ERROR_NLX_FIELD_RAWPACKETID = 3;
64constexpr uint16_t ERROR_NLX_FIELD_PACKETSIZE = 5;
65constexpr uint16_t ERROR_TOO_SMALL_PACKET = 4;
66constexpr uint16_t ERROR_BAD_CRC = 1;
68constexpr uint16_t NLX_FIELD_STX = 0;
69constexpr uint16_t NLX_FIELD_RAWPACKETID = 1;
70constexpr uint16_t NLX_FIELD_PACKETSIZE = 2;
71constexpr uint16_t NLX_FIELD_TIMESTAMP_HIGH = 3;
72constexpr uint16_t NLX_FIELD_TIMESTAMP_LOW = 4;
73constexpr uint16_t NLX_FIELD_DIO = 6;
74constexpr uint16_t NLX_FIELD_EXTRA_FIRST = 7;
75constexpr uint16_t NLX_FIELD_DATA_FIRST = NLX_FIELD_EXTRA_FIRST + NLX_NFIELDS_EXTRA;
78constexpr double NLX_AD_BIT_MICROVOLTS = 0.000000305175781250000006;
79constexpr int32_t NLX_STX = 2048;
80constexpr int32_t NLX_RAWPACKETID = 1;
81constexpr uint16_t NLX_DEFAULT_NCHANNELS = 128;
82constexpr uint16_t NLX_MAX_NCHANNELS = 1024;
83constexpr double NLX_SIGNAL_SAMPLING_FREQUENCY = 32000;
84constexpr unsigned int NLX_DEFAULT_BUFFERSIZE = NLX_PACKETBYTESIZE(NLX_DEFAULT_NCHANNELS);
86const double NLX_VIDEO_SAMPLING_FREQUENCY = 25;
87const int VTRecNumTransitionBitfields = 400;
89const int VTRecNumTargets = 50;
91const std::uint16_t VTRecSWST = 0x800;
98 std::uint32_t
dwPoints[VTRecNumTransitionBitfields];
129const std::array<std::int32_t, 2> NLX_VIDEO_RESOLUTION = {{720, 576}};
131bool valid_nlx_vt(VideoRec* vt_record, std::uint16_t vt_id, ErrorNLXVT::Code& error_code,
132 decltype(NLX_VIDEO_RESOLUTION) resolution);
134inline const unsigned int nlx_field_data_last(
unsigned int nchannels = NLX_DEFAULT_NCHANNELS) {
135 return NLX_FIELD_DATA_FIRST + nchannels - 1;
137inline const unsigned int nlx_field_crc(
unsigned int nchannels = NLX_DEFAULT_NCHANNELS) {
138 return NLX_FIELD_DATA_FIRST + nchannels;
140inline const int32_t nlx_packetsize(
unsigned int nchannels = NLX_DEFAULT_NCHANNELS) {
141 return nchannels + NLX_NFIELDS_EXTRA;
144class NlxSignalRecord {
146 NlxSignalRecord(
unsigned int nchannels = NLX_DEFAULT_NCHANNELS,
bool convert_byte_order =
true);
148 unsigned int nchannels()
const;
149 void set_nchannels(
unsigned int n);
151 bool convert_byte_order()
const;
152 void set_convert_byte_order(
bool b);
154 int FromNetworkBuffer(
const char* buffer,
size_t n);
156 template <
typename T>
157 int FromNetworkBuffer(
const std::vector<T>& buffer) {
158 return FromNetworkBuffer((
char*) buffer.data(), buffer.size() *
sizeof(T));
161 size_t ToNetworkBuffer(
char* buffer,
size_t n);
163 template <
typename T>
164 size_t ToNetworkBuffer(std::vector<T>& buffer) {
166 if (buffer.size() < (nlx_packetbytesize_ /
sizeof(T))) {
167 buffer.resize(nlx_packetbytesize_ /
sizeof(T));
170 return ToNetworkBuffer((
char*) buffer.data(), buffer.size() *
sizeof(T));
178 bool initialized()
const;
179 bool finalized()
const;
181 int valid(std::vector<int32_t> buffer);
184 uint64_t timestamp()
const;
185 void set_timestamp(uint64_t t);
186 void inc_timestamp(uint64_t delta);
187 void inc_timestamp(
double delta);
190 uint32_t parallel_port()
const;
191 void set_parallel_port(uint32_t dio = 0);
194 void data(std::vector<int32_t>& v)
const;
195 std::vector<int32_t>::iterator data(std::vector<int32_t>::iterator it)
const;
196 int32_t sample(
unsigned int index)
const;
199 void set_data(int32_t value = 0);
200 void set_data(std::vector<int32_t>& v);
201 void set_data(std::vector<int32_t>::iterator it);
204 void data(std::vector<double>& v)
const;
205 std::vector<double>::iterator data(std::vector<double>::iterator it)
const;
206 double sample_microvolt(
unsigned int index)
const;
209 void set_data(
double value = 0);
210 void set_data(std::vector<double>& v);
211 void set_data(std::vector<double>::iterator it);
213 std::vector<int32_t> buffer_;
214 int32_t nlx_packetsize_;
217 std::vector<int32_t>::iterator data_begin();
218 std::vector<int32_t>::iterator data_end();
220 std::vector<int32_t>::const_iterator data_begin()
const;
221 std::vector<int32_t>::const_iterator data_end()
const;
223 bool convert_byte_order_;
224 unsigned int nchannels_;
225 bool initialized_ =
false;
226 bool finalized_ =
false;
228 unsigned int nlx_nfields_;
229 unsigned int nlx_packetbytesize_;
230 uint16_t nlx_field_crc_;
231 uint16_t nlx_field_data_last_;
236constexpr decltype(NLX_SIGNAL_SAMPLING_FREQUENCY) SAMPLING_PERIOD_MICROSEC =
237 1e6 / NLX_SIGNAL_SAMPLING_FREQUENCY;
240const uint64_t MAX_ALLOWABLE_TIMEGAP_MICROSECONDS = trunc(SAMPLING_PERIOD_MICROSEC) + 1;
242constexpr uint64_t INVALID_TIMESTAMP = std::numeric_limits<uint64_t>::max();
246 NlxStatistics() : n_invalid(0), n_duplicated(0), n_outoforder(0), n_missed(0), n_gaps(0) {}
250 uint64_t n_duplicated;
251 uint64_t n_outoforder;
std::int32_t dntargets[VTRecNumTargets]
Definition nlx.hpp:109
std::uint16_t swdata_size
The size of the VT record in bytes.
Definition nlx.hpp:96
std::int32_t dnextracted_y
Definition nlx.hpp:105
std::int32_t dnextracted_angle
Definition nlx.hpp:107
std::uint32_t dwPoints[VTRecNumTransitionBitfields]
Definition nlx.hpp:98
std::int32_t dnextracted_x
Definition nlx.hpp:103
std::uint16_t swid
The ID assigned to the video tracker that created this record.
Definition nlx.hpp:95
std::uint64_t qwTimeStamp
Timestamp of this record in microseconds.
Definition nlx.hpp:97
std::int16_t sncrc
Ignored, relic from Cheetah160VT.
Definition nlx.hpp:102
std::uint16_t swstx
Value is always NlxDataTypes::NLX_VTREC_SWSTX.
Definition nlx.hpp:94