| 59 | |
| 60 | public: |
| 61 | std::unique_ptr<Fluxmap> encode(const LogicalTrackLayout& ltl, |
| 62 | const std::vector<std::shared_ptr<const Sector>>& sectors, |
| 63 | const Image& image) override |
| 64 | { |
| 65 | double clockRateUs = _config.target_clock_period_us() / 2.0; |
| 66 | int bitsPerRevolution = |
| 67 | (_config.target_rotational_period_ms() * 1000.0) / clockRateUs; |
| 68 | _bits.resize(bitsPerRevolution); |
| 69 | _cursor = 0; |
| 70 | |
| 71 | writeFillerRawBytes(_config.post_index_gap_bytes(), 0xaaaa); |
| 72 | |
| 73 | for (const auto& sector : sectors) |
| 74 | { |
| 75 | /* Header */ |
| 76 | |
| 77 | writeFillerRawBytes(_config.pre_sector_gap_bytes(), 0xaaaa); |
| 78 | writeRawBits(SECTOR_ID, 64); |
| 79 | writeByte(0x5a); |
| 80 | writeByte((sector->logicalCylinder << 1) | sector->logicalHead); |
| 81 | writeByte(sector->logicalSector); |
| 82 | writeByte(0x5a); |
| 83 | |
| 84 | /* Data */ |
| 85 | |
| 86 | writeFillerRawBytes(_config.pre_data_gap_bytes(), 0xaaaa); |
| 87 | auto data = sector->data.slice(0, AGAT_SECTOR_SIZE); |
| 88 | writeRawBits(DATA_ID, 64); |
| 89 | writeBytes(data); |
| 90 | writeByte(agatChecksum(data)); |
| 91 | writeByte(0x5a); |
| 92 | } |
| 93 | |
| 94 | if (_cursor >= _bits.size()) |
| 95 | error("track data overrun"); |
| 96 | fillBitmapTo(_bits, _cursor, _bits.size(), {true, false}); |
| 97 | |
| 98 | auto fluxmap = std::make_unique<Fluxmap>(); |
| 99 | fluxmap->appendBits(_bits, |
| 100 | calculatePhysicalClockPeriod(_config.target_clock_period_us() * 1e3, |
| 101 | _config.target_rotational_period_ms() * 1e6)); |
| 102 | return fluxmap; |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | const AgatEncoderProto& _config; |
nothing calls this directly
no test coverage detected