MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / main

Function main

lib/mdflib/docs/mdfreaderexample.cpp:7–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5using namespace mdf;
6
7int main() {
8
9 MdfReader reader("c:/mdf/example.mf4"); // Note the file is now open.
10
11 // Read all blocks but not the raw data and attachments.
12 // This reads in the block information into memory.
13 reader.ReadEverythingButData();
14
15 const auto* mdf_file = reader.GetFile(); // Get the file interface.
16 DataGroupList dg_list; // Get all measurements.
17 mdf_file->DataGroups(dg_list);
18
19 // In this example, we read in all sample data and fetch all values.
20 for (auto* dg4 : dg_list) {
21 // Subscribers holds the sample data for a channel.
22 // You should normally only subscribe on some channels.
23 // We need a list to hold them.
24 ChannelObserverList subscriber_list;
25 const auto cg_list = dg4->ChannelGroups();
26 for (const auto* cg4 : cg_list ) {
27 const auto cn_list = cg4->Channels();
28 for (const auto* cn4 : cn_list) {
29 // Create a subscriber and add it to the temporary list
30 auto sub = CreateChannelObserver(*dg4, *cg4, *cn4);
31 subscriber_list.emplace_back(std::move(sub));
32 }
33 }
34
35 // Now it is time to read in all samples
36 reader.ReadData(*dg4); // Read raw data from file
37 double channel_value = 0.0; // Channel value (no scaling)
38 double eng_value = 0.0; // Engineering value
39 for (auto& obs : subscriber_list) {
40 for (size_t sample = 0; sample < obs->NofSamples(); ++sample) {
41 const auto channel_valid = obs->GetChannelValue(sample, channel_value);
42 const auto eng_valid = obs->GetEngValue(sample, eng_value);
43 // You should do something with data here
44 }
45 }
46
47 // Not needed in this example as we delete the subscribers,
48 // but it is good practise to remove samples data from memory
49 // when it is no longer needed.
50 dg4->ClearData();
51 }
52 reader.Close(); // Close the file
53
54}

Callers

nothing calls this directly

Calls 12

CreateChannelObserverFunction · 0.85
ReadEverythingButDataMethod · 0.45
GetFileMethod · 0.45
DataGroupsMethod · 0.45
ChannelGroupsMethod · 0.45
ChannelsMethod · 0.45
ReadDataMethod · 0.45
NofSamplesMethod · 0.45
GetChannelValueMethod · 0.45
GetEngValueMethod · 0.45
ClearDataMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected