1 #ifdef STANDALONE_PARSER
20 : mCount(cnt), mTimeArray(nullptr), mValueArray(nullptr)
36 : mVersion(0), mStorageFormat(Uint64),
37 mValue(-1), mBeginTime(0), mEndTime(0), mNumTransitions(0)
75 ff.read((
char*)&tmp,
sizeof(tmp));
77 ff.read((
char*)&tmp,
sizeof(tmp));
99 :
std::ifstream(filename,
std::ios::binary), mReadPointer(0),
103 mStatus = mHeader.
read(*
this);
113 mReader = [
this](
bool* ok) {
115 if (this->read((
char*)&timeVal,
sizeof(timeVal)))
124 mReader = [
this](
bool* ok) {
126 if (this->read((
char*)&timeVal,
sizeof(timeVal)))
143 if (!n)
return nullptr;
151 int val = (mReadPointer % 2 == 0) ? mHeader.
value() : 1-mHeader.
value();
160 if (!n)
return retval;
167 double* tmp =
new double[n];
168 this->read((
char*)tmp,
sizeof(
double)*n);
169 for (uint64_t j=0; j<n; j++)
179 this->read((
char*)(retval->
mTimeArray+i),
sizeof(uint64_t)*n);
180 for (uint64_t j=0; j<n; j++)
187 this->read((
char*)(retval->
mTimeArray+i),
sizeof(uint64_t)*n);
188 for (uint64_t j=0; j<n; j++)
191 retval->
mTimeArray[i+j] &= 0x3fffffffffffffffull;
206 return "Error opening SALEAE file";
208 return "No <SALEAE> identifier found";
210 return "Expected SALEAE type 0 (digital data)";
214 return std::string();
230 retval.
mTime = mReader(&ok);
240 retval.
mTime &= 0x3fffffffffffffffull;
256 if ((uint64_t)-delta > mReadPointer)
259 mReadPointer += delta;
266 mReadPointer += delta;
270 seekTransition(mReadPointer-1);
278 seekTransition(pos ? pos-1 : 0);
285 uint64_t t1 = mHeader.
endTime();
287 if (t < t0)
return -1;
288 if (t == t0)
return 0;
292 if (successor && t > t1)
302 int64_t delta = max > 4 ? max / 4 : 1;
308 if (pos < 0) pos = 0;
309 if (pos >= (int64_t) max-1) pos = max-1;
312 seekTransition(pos-1);
313 t0 = mReader(&ok) & 0x3fffffffffffffffull;
320 t1 = mReader(&ok) & 0x3fffffffffffffffull;
321 if (t0 <= t && t1 > t)
323 if (successor && t0 < t) ++pos;
325 seekTransition(pos ? pos-1 : 0);
330 if (delta < 0) delta = - delta/2;
331 if (!delta) delta = 1;
335 if (delta > 0) delta = - delta/2;
336 if (!delta) delta = -1;
345 if (pos < 0)
return -1;
351 uint64_t tuple = mReader(&ok);
352 return ((tuple >> 62) & 0x3) - 2;
355 return (pos%2==0) ? mHeader.
value() : 1 - mHeader.
value();
359 :
std::ofstream(filename,
std::ios::binary), mIndex(index_), mFilename(filename), mStatus(
SaleaeStatus::Ok),
360 mFirstValue(true), mLastWrittenValue(0), mLastWrittenTime(0)
365 mHeader.
write(*
this);
368 void SaleaeOutputFile::convertToCoded()
371 seekp(std::ios_base::beg);
372 mHeader.
write(*
this);
375 SaleaeDataBuffer* sdf = sif.get_buffered_data(sif.header()->numTransitions()+1);
377 seekp(std::ios_base::beg);
379 mHeader.
write(*
this);
388 for (uint64_t i = 0; i<buf->
mCount; i++)
396 uint64_t n = buf->
mCount - 1;
415 mLastWrittenValue = val;
416 mLastWrittenTime = t;
423 if(t < mLastWrittenTime || val == mLastWrittenValue)
return;
424 mLastWrittenValue = val;
425 mLastWrittenTime = t;
429 uint64_t buf = val + 2;
431 buf |= (t & 0xfffffffffffffffull);
432 write((
char*)&buf,
sizeof(buf));
435 write((
char*)&t,
sizeof(t));
450 seekp(std::ios_base::beg);
451 mHeader.
write(*
this);
452 std::ofstream::close();
466 for (uint64_t i = 1; i<
mCount; i++)
476 std::cout <<
mCount <<
" :";
477 for (uint64_t i = 0; i<
mCount; i++)
481 std::cout << std::endl;
void convertCoded()
Convert data buffer from "hal " format to "halx".
uint64_t mCount
Number of elements in buffer.
SaleaeDataBuffer(uint64_t cnt=0)
Constructor. Generates null instance when no argument is given.
~SaleaeDataBuffer()
Destructor takes care of disposing allocated memory.
uint64_t * mTimeArray
Buffer for mCount transition time values.
int * mValueArray
Buffer for mCount data values.
void dump() const
Dump buffer content to stdout.
static const int sReadError
Fake data value to indicate all kind of errors.
uint64_t mTime
Transition time.
The SaleaeDirectoryFileIndex class represents a single SALEAE data file. The class comprises the inde...
void writeTimeValue(uint64_t t, int32_t val)
Write single data tuple to disk.
void close()
Update header on disk and close file.
SaleaeOutputFile(const std::string &filename, int index_)
SaleaeDirectoryFileIndex fileIndex() const
File index summary for saleae directory.
void put_data(SaleaeDataBuffer *buf)
Write buffered data.
static uint64_t sTimeScaleFactor
conversion factor to be applied when converting double values from original SALEAE file to integer va...
bool write(const GateLibrary *gate_lib, const std::filesystem::path &file_path)