MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / CwfFluxSource

Method CwfFluxSource

lib/fluxsource/cwffluxsource.cc:38–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36{
37public:
38 CwfFluxSource(const CwfFluxSourceProto& config): _config(config)
39 {
40 _if.open(_config.filename(), std::ios::in | std::ios::binary);
41 if (!_if.is_open())
42 error("cannot open input file '{}': {}",
43 _config.filename(),
44 strerror(errno));
45
46 _if.read((char*)&_header, sizeof(_header));
47 check_for_error();
48
49 if ((_header.file_id[0] != 'C') || (_header.file_id[1] != 'W') ||
50 (_header.file_id[2] != 'S') || (_header.file_id[3] != 'F'))
51 error("input not a CWF file");
52
53 switch (_header.clock_rate)
54 {
55 case 1:
56 _clockPeriod = 1e9 / 14161000.0;
57 break;
58 case 2:
59 _clockPeriod = 1e9 / 28322000.0;
60 break;
61 default:
62 error("unsupported clock rate");
63 }
64
65 std::cout << fmt::format("CWF {}x{} = {} cylinders, {} heads\n",
66 _header.cylinders,
67 _header.heads,
68 _header.cylinders * _header.step,
69 _header.heads);
70 std::cout << fmt::format(
71 "CWF sample clock rate: {} MHz\n", 1e3 / _clockPeriod);
72
73 int cylinders = _header.cylinders * _header.heads;
74 for (int i = 0; i < cylinders; i++)
75 {
76 CwfTrack trackHeader;
77 _if.read((char*)&trackHeader, sizeof(trackHeader));
78 check_for_error();
79
80 uint32_t length =
81 Bytes(trackHeader.length, 4).reader().read_le32() -
82 sizeof(CwfTrack);
83 unsigned track_number = trackHeader.cylinder * _header.step;
84
85 off_t pos = _if.tellg();
86 _trackOffsets[CylinderHead{track_number, trackHeader.head}] =
87 std::make_pair(pos, length);
88 _if.seekg(pos + length);
89 }
90
91 std::vector<CylinderHead> chs;
92 for (auto& [key, value] : _trackOffsets)
93 chs.push_back(key);
94 _extraConfig.mutable_drive()->set_tracks(
95 convertCylinderHeadsToString(chs));

Callers

nothing calls this directly

Calls 9

errorFunction · 0.85
check_for_errorFunction · 0.85
openMethod · 0.80
read_le32Method · 0.80
readerMethod · 0.80
BytesClass · 0.50
readMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected