// File: /workspace/github_cpp_makefile_star2_O3/flightaware[P]beast-splitter/status_writer.cc
// Function: splitter::StatusWriter::write(modes::Message const&)
void StatusWriter::write(const modes::Message &message) {
        if (message.type() != modes::MessageType::STATUS)
            return;

        reset_timeout();

        const auto &data = message.data();

        // 0: settings, including:
        //    10: 1=GPS timestamps, 0=12MHz timestamps
        // 1: signed timestamp offset at last PPS edge, 15ns units
        // 2: GPS status
        //    80: 1=UTC, 0=UTC+1; if 0, other bits are unused
        //    40: unused
        //    20: 1=timestamp from FPGA, 0=timestamp from GPS
        //    10: 1=degradation <= 45ms, 0=degradation > 45ms
        //    08: 1=UTC time, 0=GPS time
        //    04: 1=good sats, 0=not enough good sats
        //    02: 1=tracking sats, 0=no sats
        //    01: 1=antenna OK, 0=antenna fault

        int pps_offset = (std::int8_t)data[1];

        if (!(data[0] & 0x10)) {
            // 12MHz mode
            write_status_file("red", "Not in GPS timestamp mode", pps_offset);
            return;
        }

        if (!(data[2] & 0x80)) {
            // Old style message. Assume it's good if abs(degradation) < 45ms
            if (pps_offset <= 3 || pps_offset >= -3) {
                write_status_file("green", "Receiver synchronized to GPS time", pps_offset);
            } else {
                write_status_file("amber", "Receiver more than 45ns from GPS time", pps_offset);
            }
            return;
        }

        // New style message

        if (!(data[2] & 0x20)) {
            // FPGA is using GPS time
            if (data[2] & 0x10) {
                write_status_file("green", "Receiver synchronized to GPS time", pps_offset);
            } else {
                write_status_file("amber", "Receiver more than 45ns from GPS time", pps_offset);
            }
            return;
        }

        // FPGA is not using GPS time, work out why.

        std::vector<std::string> status_messages;
        if (!(data[2] & 0x08)) {
            status_messages.push_back("GPS/UTC time offset not known");
        }

        if (!(data[2] & 0x02)) {
            status_messages.push_back("Not tracking any satellites");
        } else if (!(data[2] & 0x04)) {
            status_messages.push_back("Not tracking sufficient satellites");
        }

        if (!(data[2] & 0x01)) {
            status_messages.push_back("Antenna fault");
        }

        if (status_messages.empty()) {
            status_messages.push_back("Unrecognized GPS fault");
        }

        std::ostringstream status_buffer;
        for (auto i = status_messages.begin(); i != status_messages.end(); ++i) {
            if (i != status_messages.begin())
                status_buffer << "; ";
            status_buffer << *i;
        }

        write_status_file("red", status_buffer.str(), pps_offset);
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d0, %rsp            # imm = 0x1D0
cmpl $0x4, (%rsi)
jne 0x2b4eb
movq %rsi, %r15
movq %rdi, %r14
callq 0x2b954
movq 0x18(%r15), %rax
movsbl 0x1(%rax), %ebx
testb $0x10, (%rax)
jne 0x2b460
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x24c86(%rip), %rsi     # 0x500a1
leaq 0x24c82(%rip), %rdx     # 0x500a4
leaq 0x58(%rsp), %rdi
callq 0x134ac
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x24c8e(%rip), %rsi     # 0x500cb
leaq 0x24ca0(%rip), %rdx     # 0x500e4
movq %rsp, %rdi
callq 0x134ac
leaq 0x58(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
movl %ebx, %ecx
callq 0x2bbd0
jmp 0x2b4be
movb 0x2(%rax), %cl
testb %cl, %cl
js 0x2b4fc
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x24c6a(%rip), %rsi     # 0x500e5
leaq 0x24c68(%rip), %rdx     # 0x500ea
leaq 0x58(%rsp), %rdi
callq 0x134ac
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x24c4e(%rip), %rsi     # 0x500eb
leaq 0x24c68(%rip), %rdx     # 0x5010c
movq %rsp, %rdi
callq 0x134ac
leaq 0x58(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
movl %ebx, %ecx
callq 0x2bbd0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x2b4d4
movq 0x10(%rsp), %rsi
incq %rsi
callq 0xe650
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x2b4eb
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xe650
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
testb $0x20, %cl
jne 0x2b562
leaq 0x68(%rsp), %r15
testb $0x10, %cl
jne 0x2b607
movq %r15, -0x10(%r15)
leaq 0x24bf3(%rip), %rsi     # 0x5010d
leaq 0x24bf1(%rip), %rdx     # 0x50112
leaq 0x58(%rsp), %rdi
callq 0x134ac
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x24bd7(%rip), %rsi     # 0x50113
leaq 0x24bf5(%rip), %rdx     # 0x50138
movq %rsp, %rdi
callq 0x134ac
leaq 0x58(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
movl %ebx, %ecx
callq 0x2bbd0
jmp 0x2b4be
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movb 0x2(%rax), %al
testb $0x8, %al
jne 0x2b5c9
leaq 0x68(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x24bae(%rip), %rsi     # 0x50139
leaq 0x24bc4(%rip), %rdx     # 0x50156
leaq 0x58(%rsp), %rdi
callq 0x134ac
leaq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2cb02
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x2b5c2
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xe650
movq 0x18(%r15), %rax
movb 0x2(%rax), %al
testb $0x2, %al
jne 0x2b65a
leaq 0x68(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x24b75(%rip), %rsi     # 0x50157
leaq 0x24b89(%rip), %rdx     # 0x50172
leaq 0x58(%rsp), %rdi
callq 0x134ac
leaq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2cb02
jmp 0x2b68f
movq %r15, -0x10(%r15)
leaq 0x24ad3(%rip), %rsi     # 0x500e5
leaq 0x24ad1(%rip), %rdx     # 0x500ea
leaq 0x58(%rsp), %rdi
callq 0x134ac
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x24ab7(%rip), %rsi     # 0x500eb
leaq 0x24ad1(%rip), %rdx     # 0x5010c
movq %rsp, %rdi
callq 0x134ac
leaq 0x58(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
movl %ebx, %ecx
callq 0x2bbd0
jmp 0x2b4be
testb $0x4, %al
jne 0x2b6a6
leaq 0x68(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x24b04(%rip), %rsi     # 0x50173
leaq 0x24b1f(%rip), %rdx     # 0x50195
leaq 0x58(%rsp), %rdi
callq 0x134ac
leaq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2cb02
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x2b6a6
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xe650
movq 0x18(%r15), %rax
testb $0x1, 0x2(%rax)
jne 0x2b6f7
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x24ad6(%rip), %rsi     # 0x50196
leaq 0x24adc(%rip), %rdx     # 0x501a3
leaq 0x58(%rsp), %rdi
callq 0x134ac
leaq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2cb02
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x2b6f7
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xe650
movq 0x20(%rsp), %rax
cmpq 0x28(%rsp), %rax
jne 0x2b74a
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x24a91(%rip), %rsi     # 0x501a4
leaq 0x24aa0(%rip), %rdx     # 0x501ba
leaq 0x58(%rsp), %rdi
callq 0x134ac
leaq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2cb02
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x2b74a
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xe650
leaq 0x58(%rsp), %rdi
callq 0xe8a0
movq 0x20(%rsp), %r13
cmpq 0x28(%rsp), %r13
je 0x2b79e
leaq 0x58(%rsp), %r15
leaq 0x24a4f(%rip), %r12     # 0x501bb
cmpq 0x20(%rsp), %r13
je 0x2b783
movl $0x2, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0xe730
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %r15, %rdi
callq 0xe730
addq $0x20, %r13
cmpq 0x28(%rsp), %r13
jne 0x2b76c
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x248f3(%rip), %rsi     # 0x500a1
leaq 0x248ef(%rip), %rdx     # 0x500a4
movq %rsp, %rdi
callq 0x134ac
leaq 0x60(%rsp), %rsi
leaq 0x38(%rsp), %rdi
callq 0xea50
movq %rsp, %rsi
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
movl %ebx, %ecx
callq 0x2bbd0
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2b7f9
movq 0x48(%rsp), %rsi
incq %rsi
callq 0xe650
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x2b80f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0xe650
movq 0x4575a(%rip), %rsi     # 0x70f70
leaq 0x58(%rsp), %rdi
callq 0xe370
leaq 0xc8(%rsp), %rdi
callq 0xe1f0
leaq 0x20(%rsp), %rdi
callq 0x2c328
jmp 0x2b4eb
jmp 0x2b86e
jmp 0x2b8d9
jmp 0x2b84a
jmp 0x2b8d9
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
jne 0x2b87f
jmp 0x2b941
jmp 0x2b8d9
jmp 0x2b8e4
jmp 0x2b86e
jmp 0x2b8e4
jmp 0x2b8ff
jmp 0x2b8d9
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x2b941
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xe650
jmp 0x2b941
jmp 0x2b8ff
jmp 0x2b91b
jmp 0x2b8d9
jmp 0x2b91b
movq %rax, %rbx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2b8bf
movq 0x48(%rsp), %rsi
incq %rsi
callq 0xe650
jmp 0x2b8bf
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x2b923
movq 0x10(%rsp), %rsi
incq %rsi
callq 0xe650
jmp 0x2b923
jmp 0x2b920
movq %rax, %rbx
jmp 0x2b941
jmp 0x2b8e4
jmp 0x2b8ff
jmp 0x2b91b
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x2b902
movq 0x10(%rsp), %rsi
incq %rsi
callq 0xe650
jmp 0x2b902
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x2b94b
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xe650
jmp 0x2b94b
movq %rax, %rbx
jmp 0x2b94b
movq %rax, %rbx
movq 0x45646(%rip), %rsi     # 0x70f70
leaq 0x58(%rsp), %rdi
callq 0xe370
leaq 0xc8(%rsp), %rdi
callq 0xe1f0
leaq 0x20(%rsp), %rdi
callq 0x2c328
movq %rbx, %rdi
callq 0xeb40
nop