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

Function main

lib/mdflib/fuzzytest/fuzzytest.cpp:12–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 13

CreateChannelObserverFunction · 0.85
dataMethod · 0.45
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

Tested by

no test coverage detected