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

Function fluxEngineToGreaseweazle

lib/external/greaseweazle.cc:6–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "lib/external/greaseweazle.h"
5
6Bytes fluxEngineToGreaseweazle(const Bytes& fldata, nanoseconds_t clock)
7{
8 Bytes gwdata;
9 ByteWriter bw(gwdata);
10 ByteReader br(fldata);
11 uint32_t ticks_fl = 0;
12 uint32_t ticks_gw = 0;
13
14 auto write_28 = [&](uint32_t val)
15 {
16 bw.write_8(1 | (val << 1) & 0xff);
17 bw.write_8(1 | (val >> 6) & 0xff);
18 bw.write_8(1 | (val >> 13) & 0xff);
19 bw.write_8(1 | (val >> 20) & 0xff);
20 };
21
22 while (!br.eof())
23 {
24 uint8_t b = br.read_8();
25 ticks_fl += b & 0x3f;
26 if (b & F_BIT_PULSE)
27 {
28 uint32_t newticks_gw = ticks_fl * NS_PER_TICK / clock;
29 uint32_t delta = newticks_gw - ticks_gw;
30 if (delta < 250)
31 bw.write_8(delta);
32 else
33 {
34 int high = (delta - 250) / 255;
35 if (high < 5)
36 {
37 bw.write_8(250 + high);
38 bw.write_8(1 + (delta - 250) % 255);
39 }
40 else
41 {
42 bw.write_8(255);
43 bw.write_8(FLUXOP_SPACE);
44 write_28(delta - 249);
45 bw.write_8(249);
46 }
47 }
48 ticks_gw = newticks_gw;
49 }
50 }
51 bw.write_8(0); /* end of stream */
52 return gwdata;
53}
54
55Bytes greaseweazleToFluxEngine(const Bytes& gwdata, nanoseconds_t clock)
56{

Callers 2

writeMethod · 0.85
test_convertFunction · 0.85

Calls 2

read_8Method · 0.80
eofMethod · 0.45

Tested by 1

test_convertFunction · 0.68