1 /*
2  *    Copyright (C) 2020
3  *    Matthias P. Braendli (matthias.braendli@mpb.li)
4  *
5  *    This file is part of the welle.io.
6  *    Many of the ideas as implemented in welle.io are derived from
7  *    other work, made available through the GNU general Public License.
8  *    All copyrights of the original authors are recognized.
9  *
10  *    welle.io is free software; you can redistribute it and/or modify
11  *    it under the terms of the GNU General Public License as published by
12  *    the Free Software Foundation; either version 2 of the License, or
13  *    (at your option) any later version.
14  *
15  *    welle.io is distributed in the hope that it will be useful,
16  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *    GNU General Public License for more details.
19  *
20  *    You should have received a copy of the GNU General Public License
21  *    along with welle.io; if not, write to the Free Software
22  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  *
24  */
25 #pragma once
26 
27 #include <string>
28 #include <chrono>
29 #include <list>
30 #include <vector>
31 #include <memory>
32 #include <ctime>
33 #include "dab-constants.h"
34 #include "backend/radio-controller.h"
35 
36 struct SoftwareJson {
37     std::string name;
38     std::string version;
39     std::string fftwindowplacement;
40     bool coarsecorrectorenabled = false;
41     std::string freqsyncmethod;
42     std::chrono::system_clock::time_point lastchannelchange;
43 };
44 
45 struct HardwareJson {
46     std::string name;
47     float gain = 0.0f;
48 };
49 
50 struct ReceiverJson {
51     HardwareJson hardware;
52     SoftwareJson software;
53 };
54 
55 
56 struct ComponentJson {
57     int16_t componentnr = 0;
58     bool primary = false;
59     bool caflag = false;
60 
61     // std::optional would be preferable
62     std::unique_ptr<uint16_t> scid;
63     std::unique_ptr<std::string> ascty;
64     std::unique_ptr<uint16_t> dscty;
65     std::string transportmode;
66 
67     DabLabel label;
68 
69     Subchannel subchannel;
70 };
71 
72 struct ServiceJson {
73     std::string sid;
74     int16_t programType = 0;
75     std::string ptystring;
76     int16_t language = 0;
77     std::string languagestring;
78     DabLabel label;
79 
80     std::vector<ComponentJson> components;
81 
82     std::string url_mp3;
83 
84     bool audiolevel_present = false;
85     std::time_t audiolevel_time = 0;
86     int audiolevel_left = -1;
87     int audiolevel_right = -1;
88 
89     int channels = 0;
90     int samplerate = 0;
91     std::string mode;
92 
93     std::time_t mot_time = 0;
94     std::time_t mot_lastchange = 0;
95 
96     std::string dls_label;
97     std::time_t dls_time = 0;
98     std::time_t dls_lastchange = 0;
99 
100     size_t errorcounters_frameerrors = 0;
101     size_t errorcounters_rserrors = 0;
102     size_t errorcounters_aacerrors = 0;
103     std::time_t errorcounters_time = 0;
104 
105     bool xpaderror_haserror = false;
106     size_t xpaderror_announcedlen = 0;
107     size_t xpaderror_len = 0;
108     std::time_t xpaderror_time = 0;
109 };
110 
111 struct EnsembleJson {
112     DabLabel label;
113     std::string id;
114     std::string ecc;
115 };
116 
117 struct UTCJson {
118     int year = 0;
119     int month = 0;
120     int day = 0;
121     int hour = 0;
122     int minutes = 0;
123     double lto = 0.0;
124 };
125 
126 struct PeakJson {
127     int index = -1;
128     float value = -1e30f;
129 };
130 
131 struct MuxJson {
132     ReceiverJson receiver;
133     EnsembleJson ensemble;
134     std::vector<ServiceJson> services;
135     size_t demodulator_fic_numcrcerrors = 0;
136     UTCJson utctime;
137     std::vector<std::string> messages;
138 
139     double demodulator_snr = 0.0;
140     double demodulator_frequencycorrection = 0.0;
141     std::chrono::system_clock::time_point demodulator_timelastfct0frame;
142 
143     std::list<tii_measurement_t> tii;
144     std::vector<PeakJson> cir_peaks;
145 };
146 
147 std::string build_mux_json(const MuxJson& mux);
148