| 5 | #include "lib/external/flx.h" |
| 6 | |
| 7 | std::unique_ptr<Fluxmap> readFlxBytes(const Bytes& bytes) |
| 8 | { |
| 9 | ByteReader br(bytes); |
| 10 | |
| 11 | /* Skip header. */ |
| 12 | |
| 13 | for (;;) |
| 14 | { |
| 15 | if (br.eof()) |
| 16 | error("malformed FLX stream"); |
| 17 | uint8_t b = br.read_8(); |
| 18 | if (b == 0) |
| 19 | break; |
| 20 | } |
| 21 | |
| 22 | auto fluxmap = std::make_unique<Fluxmap>(); |
| 23 | while (!br.eof()) |
| 24 | { |
| 25 | uint8_t b = br.read_8(); |
| 26 | switch (b) |
| 27 | { |
| 28 | case FLX_INDEX: |
| 29 | fluxmap->appendIndex(); |
| 30 | continue; |
| 31 | |
| 32 | case FLX_STOP: |
| 33 | goto stop; |
| 34 | |
| 35 | default: |
| 36 | { |
| 37 | if (b < 32) |
| 38 | error("unknown FLX opcode 0x{:2x}", b); |
| 39 | nanoseconds_t interval = b * FLX_TICK_NS; |
| 40 | fluxmap->appendInterval(interval / NS_PER_TICK); |
| 41 | fluxmap->appendPulse(); |
| 42 | break; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | stop: |
| 47 | |
| 48 | return fluxmap; |
| 49 | } |