8#include <condition_variable>
61class IChannelConversion;
113 [[nodiscard]] std::string
Name()
const;
122 bool Init(
const std::string& filename);
272 void MaxLength(uint32_t max_length) {max_length_ = max_length;};
275 [[nodiscard]] uint32_t
MaxLength()
const {
return max_length_; }
320 virtual void SaveQueue(std::unique_lock<std::mutex>& lock);
330 bool compress_data_ =
false;
333 uint32_t max_length_ = 8;
334 std::map<uint64_t, const IChannel*> master_channels_;
335 void RecalculateTimeMaster();
336 void CreateCanConfig(
IDataGroup& dg_block)
const;
372 void CreateCanRemoteFrameChannel(
IChannelGroup& group)
const;
405 static void CreateCanOverloadFrameChannel(
IChannelGroup& group);
Simple wrapper around a CAN or CAN FD message.
Helper class when logging CAN and CAN FD messages.
Definition canmessage.h:47
Defines a channel conversion (CC) block.
Definition ichannelconversion.h:142
Interface against a channel group (CG) block.
Definition ichannelgroup.h:66
Defines a MDF channel (CN) block.
Definition ichannel.h:126
Interface to a data group (DG) block.
Definition idatagroup.h:42
Interface for timestamp handling in MDF files.
Definition itimestamp.h:17
Implements an user interface against a MDF file.
Definition mdffile.h:37
Interface against an MDF writer object.
Definition mdfwriter.h:104
static IChannel * CreateChannel(IChannelGroup *parent)
Creates a new channel (CN) block.
MdfStorageType StorageType() const
Returns the type of data storage the MDF file is associated with. Only used when doing bus logging.
Definition mdfwriter.h:262
void BusType(MdfBusType type)
Only used when doing bus logging. It defines the default channel and channel group names when doing b...
Definition mdfwriter.h:227
std::atomic< uint64_t > pre_trig_time_
Nanoseconds difference.
Definition mdfwriter.h:297
bool CompressData() const
Returns true if the data block is compressed.
Definition mdfwriter.h:280
std::condition_variable sample_event_
Used internally.
Definition mdfwriter.h:304
virtual bool FinalizeMeasurement()
Stop the sample queue and write all unwritten blocks to the file.
SampleQueue sample_queue_
Sample queue.
Definition mdfwriter.h:308
IDataGroup * CreateDataGroup()
Create a new data group (DG) block.
void WorkThread()
Worker thread function.
double PreTrigTime() const
Pre-trig time (s).
std::unique_ptr< MdfFile > mdf_file_
Holds the actual file object.
Definition mdfwriter.h:294
virtual void StartMeasurement(ITimestamp &start_time)
Starts the measurement.
virtual void StartMeasurement(uint64_t start_time)
Starts the measurement.
void SaveCanMessage(const IChannelGroup &group, uint64_t time, const CanMessage &msg)
Saves a CAN message into a bus logger channel group.
virtual void StopMeasurement(ITimestamp &start_time)
Stops the measurement.
std::atomic_bool stop_thread_
Set to true to stop the thread.
Definition mdfwriter.h:302
virtual bool PrepareForWriting()=0
Prepare for writing.
MdfFile * GetFile() const
Returns the MDF file interface.
Definition mdfwriter.h:150
bool CreateBusLogConfiguration()
Creates all default DG, CG and CN blocks that bus loggers uses.
void StorageType(MdfStorageType type)
Only used when doing bus logging. It defines how raw data is stored.
Definition mdfwriter.h:256
virtual void SetLastPosition(std::FILE *file)=0
Set the last file position.
static IChannelGroup * CreateChannelGroup(IDataGroup *parent)
Create a new channel group (CG) block.
std::mutex locker_
Mutex for thread-safe handling of the sample queue.
Definition mdfwriter.h:303
void PreTrigTime(double pre_trig_time)
Sets the pre-trig time (s) of the writer.
virtual void CreateMdfFile()=0
Creates an MDF file.
bool Init(const std::string &filename)
Initiate the file.
virtual bool WriteSignalData(std::FILE *file)
Write an SD block.
MdfBusType BusType() const
Returns the type of bus the MDF file is associated with. Only used when doing bus logging.
Definition mdfwriter.h:233
std::string filename_
Full name of file with path and extension.
Definition mdfwriter.h:295
virtual IChannelConversion * CreateChannelConversion(IChannel *parent)=0
Create a new channel conversion (CC) block.
void CompressData(bool compress)
If set to true, the data block will be compressed.
Definition mdfwriter.h:278
virtual void SaveSample(const IChannelGroup &group, uint64_t time)
Saves a sample record for a channel group.
std::thread work_thread_
Sample queue thread.
Definition mdfwriter.h:301
std::atomic< uint64_t > stop_time_
Nanoseconds since 1970.
Definition mdfwriter.h:299
virtual bool InitMeasurement()
Initialize the sample queue and write any unwritten block to the file.
std::string_view BusTypeAsString() const
Returns the bus type as text.
uint64_t StartTime() const
Returns start time in nano-seconds since 1970.
Definition mdfwriter.h:139
IHeader * Header() const
Returns the header block (HD).
virtual ~MdfWriter()
Default destructor.
virtual void CleanQueue(std::unique_lock< std::mutex > &lock)
Flush the sample queue.
std::atomic< WriteState > write_state_
Keeps track of the worker thread state.
Definition mdfwriter.h:291
MdfWriter()=default
Default constructor.
void IncrementNofSamples(uint64_t record_id) const
Increment the sample counter.
std::atomic< uint64_t > start_time_
Nanoseconds since 1970.
Definition mdfwriter.h:298
virtual void TrimQueue()
Trims the sample queue.
virtual void SaveQueue(std::unique_lock< std::mutex > &lock)
Saves the queue to file.
void StopWorkThread()
Stops the worker thread.
virtual void SetDataPosition(std::FILE *file)
Set the data position.
WriteState
Internal state of the thread.
Definition mdfwriter.h:284
@ StopMeas
Stop saving samples. OK to.
@ StartMeas
Start saving samples to file.
@ Create
Only at first measurement.
@ Init
Start work thread and start collecting samples.
@ Finalize
OK to add new DG and CG blocks.
virtual void StopMeasurement(uint64_t stop_time)
Stops the measurement.
void MaxLength(uint32_t max_length)
Sets max number of payload data bytes.
Definition mdfwriter.h:272
bool IsFileNew() const
Returns true if this is a new file.
Definition mdfwriter.h:125
uint32_t MaxLength() const
Returns maximum number of payload data bytes.
Definition mdfwriter.h:275
std::atomic< size_t > sample_queue_size_
Used to trig flushing to disc.
Definition mdfwriter.h:305
uint64_t StopTime() const
Returns stop time in nano-seconds since 1970.
Definition mdfwriter.h:141
std::deque< SampleRecord > SampleQueue
Sample queue.
Definition mdfwriter.h:307
std::string Name() const
Returns the filename without extension and path (stem).
Interface against an MDF file object.
Main namespace for the MDF library.
Definition canmessage.h:17
MdfStorageType
Enumerate that defines how the raw data is stored. By default the fixed length record is stored....
Definition mdfwriter.h:53
@ VlsdStorage
Using variable length storage.
@ FixedLengthStorage
The default is to use fixed length records.
@ MlsdStorage
Using maximum length storage.
MdfBusType
Enumerate that defines type of bus. Only relevant for bus logging.
Definition mdfwriter.h:29
@ UNKNOWN
Unknown bus type (Default)