forked from mutability/dump978
-
Notifications
You must be signed in to change notification settings - Fork 17
/
demodulator.h
75 lines (56 loc) · 2.15 KB
/
demodulator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// -*- c++ -*-
// Copyright (c) 2019, FlightAware LLC.
// All rights reserved.
// Licensed under the 2-clause BSD license; see the LICENSE file
#ifndef DUMP978_DEMODULATOR_H
#define DUMP978_DEMODULATOR_H
#include <functional>
#include <vector>
#include "common.h"
#include "convert.h"
#include "fec.h"
#include "message_source.h"
#include "uat_message.h"
namespace flightaware::uat {
class Demodulator {
public:
// Return value of Demodulate
struct Message {
Bytes payload;
unsigned corrected_errors;
PhaseBuffer::const_iterator begin;
PhaseBuffer::const_iterator end;
};
virtual ~Demodulator() {}
virtual std::vector<Message> Demodulate(PhaseBuffer::const_iterator begin, PhaseBuffer::const_iterator end) = 0;
virtual unsigned NumTrailingSamples() = 0;
protected:
FEC fec_;
};
class TwoMegDemodulator : public Demodulator {
public:
std::vector<Message> Demodulate(PhaseBuffer::const_iterator begin, PhaseBuffer::const_iterator end) override;
unsigned NumTrailingSamples() override;
private:
boost::optional<Message> DemodBest(PhaseBuffer::const_iterator begin, bool downlink);
boost::optional<Message> DemodOneDownlink(PhaseBuffer::const_iterator begin);
boost::optional<Message> DemodOneUplink(PhaseBuffer::const_iterator begin);
};
class Receiver : public MessageSource {
public:
virtual void HandleSamples(std::uint64_t timestamp, Bytes::const_iterator begin, Bytes::const_iterator end) = 0;
virtual void HandleError(const boost::system::error_code &ec) { DispatchError(ec); }
};
class SingleThreadReceiver : public Receiver {
public:
SingleThreadReceiver(SampleFormat format);
void HandleSamples(std::uint64_t timestamp, Bytes::const_iterator begin, Bytes::const_iterator end) override;
private:
SampleConverter::Pointer converter_;
std::unique_ptr<Demodulator> demodulator_;
Bytes samples_;
std::size_t saved_samples_ = 0;
PhaseBuffer phase_;
};
}; // namespace flightaware::uat
#endif