forked from rene0/dcf77pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcf77pi-analyze.c
196 lines (181 loc) · 4.46 KB
/
dcf77pi-analyze.c
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Copyright 2013-2018 René Ladan
// SPDX-License-Identifier: BSD-2-Clause
#include "bits1to14.h"
#include "calendar.h"
#include "decode_alarm.h"
#include "decode_time.h"
#include "input.h"
#include "mainloop.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <time.h>
static void
display_bit(struct GB_result bit, int bitpos)
{
if (is_space_bit(bitpos)) {
printf(" ");
}
if (bit.hwstat == ehw_receive) {
printf("r");
} else if (bit.hwstat == ehw_transmit) {
printf("x");
} else if (bit.hwstat == ehw_random) {
printf("#");
} else if (bit.bitval == ebv_none) {
printf("_");
} else {
printf("%i", get_buffer()[bitpos]);
}
}
static void
display_time(struct DT_result dt, struct tm time)
{
printf("%s %04d-%02d-%02d %s %02d:%02d\n",
time.tm_isdst == 1 ? "summer" : time.tm_isdst == 0 ? "winter" :
"? ",
time.tm_year, time.tm_mon, time.tm_mday, weekday[time.tm_wday],
time.tm_hour, time.tm_min);
if (dt.minute_length == emin_long) {
printf("Minute too long\n");
} else if (dt.minute_length == emin_short) {
printf("Minute too short\n");
}
if (dt.dst_status == eDST_error) {
printf("Time offset error\n");
} else if (dt.dst_status == eDST_jump) {
printf("Time offset jump (ignored)\n");
} else if (dt.dst_status == eDST_done) {
printf("Time offset changed\n");
}
if (dt.minute_status == eval_parity) {
printf("Minute parity error\n");
} else if (dt.minute_status == eval_bcd) {
printf("Minute value error\n");
} else if (dt.minute_status == eval_jump) {
printf("Minute value jump\n");
}
if (dt.hour_status == eval_parity) {
printf("Hour parity error\n");
} else if (dt.hour_status == eval_bcd) {
printf("Hour value error\n");
} else if (dt.hour_status == eval_jump) {
printf("Hour value jump\n");
}
if (dt.mday_status == eval_parity) {
printf("Date parity error\n");
}
if (dt.wday_status == eval_bcd) {
printf("Day-of-week value error\n");
} else if (dt.wday_status == eval_jump) {
printf("Day-of-week value jump\n");
}
if (dt.mday_status == eval_bcd) {
printf("Day-of-month value error\n");
} else if (dt.mday_status == eval_jump) {
printf("Day-of-month value jump\n");
}
if (dt.month_status == eval_bcd) {
printf("Month value error\n");
} else if (dt.month_status == eval_jump) {
printf("Month value jump\n");
}
if (dt.year_status == eval_bcd) {
printf("Year value error\n");
} else if (dt.year_status == eval_jump) {
printf("Year value jump\n");
}
if (!dt.bit0_ok) {
printf("Minute marker error\n");
}
if (!dt.bit20_ok) {
printf("Date/time start marker error\n");
}
if (dt.transmit_call) {
printf("Transmitter call bit set\n");
}
if (dt.dst_announce) {
printf("Time offset change announced\n");
}
if (dt.leap_announce) {
printf("Leap second announced\n");
}
if (dt.leapsecond_status == els_done) {
printf("Leap second processed\n");
} else if (dt.leapsecond_status == els_one) {
printf("Leap second processed with value 1 instead of 0\n");
}
printf("\n");
}
static void
display_alarm(struct alm alarm)
{
printf("German civil warning for: %s\n", get_region_name(alarm));
for (unsigned i = 0; i < 2; i++) {
printf("%u Regions: %x %x %x %x parities %x %x\n", i,
alarm.region[i].r1, alarm.region[i].r2, alarm.region[i].r3,
alarm.region[i].r4, alarm.parity[i].ps, alarm.parity[i].pl);
}
}
static void
display_unknown(void)
{
printf("Unknown third party contents\n");
}
static void
display_weather(void)
{
printf("Meteotime weather\n");
}
static void
display_long_minute(void)
{
printf(" L ");
}
static void
display_minute(int minlen)
{
int cutoff;
cutoff = get_cutoff();
printf(" (%u) %i ", get_acc_minlen(), minlen);
if (cutoff == -1) {
printf("?\n");
} else {
printf("%6.4f\n", cutoff / 1e4);
}
}
static void
display_thirdparty_buffer(const unsigned tpbuf[])
{
printf("Third party buffer: ");
for (int i = 0; i < TPBUFLEN; i++) {
printf("%u", tpbuf[i]);
}
printf("\n");
}
int
main(int argc, char *argv[])
{
int res;
char *logfilename;
if (argc == 2) {
logfilename = strdup(argv[1]);
} else {
printf("usage: %s infile\n", argv[0]);
return EX_USAGE;
}
res = set_mode_file(logfilename);
if (res != 0) {
/* something went wrong */
cleanup();
free(logfilename);
return res;
}
mainloop(NULL, get_bit_file, display_bit, display_long_minute,
display_minute, NULL, display_alarm, display_unknown,
display_weather, display_time, display_thirdparty_buffer, NULL,
NULL, NULL);
free(logfilename);
return res;
}