1 // =====================================================================
2 //
3 // TOD_clock.cxx
4 //
5 // Copyright (C) 2017
6 // Dave Freese, W1HKJ
7 //
8 // This file is part of flrig
9 //
10 // Fldigi 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 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Fldigi 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 fldigi. If not, see <http://www.gnu.org/licenses/>.
22 // =====================================================================
23
24 #include <config.h>
25
26 #include <time.h>
27 #include <sys/time.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <fcntl.h>
33
34 #include <cmath>
35 #include <cstring>
36
37 #include <iostream>
38
39 #include <FL/Fl.H>
40
41 #include "util.h"
42 #include "debug.h"
43 //#include "status.h"
44 #include "icons.h"
45
46 #include "tod_clock.h"
47 #include "timeops.h"
48
49 using namespace std;
50
51 static int _zmsec = 0;
52 static int _zsec = 0;
53 static int _zmin = 0;
54 static int _zhr = 0;
55
ztimer()56 void ztimer()
57 {
58 struct tm tm;
59 time_t t_temp;
60 struct timeval tv;
61
62 gettimeofday(&tv, NULL);
63
64 t_temp=(time_t)tv.tv_sec;
65 gmtime_r(&t_temp, &tm);
66
67 _zmsec = tv.tv_usec / 1000;
68 _zsec = tm.tm_sec;
69 _zmin = tm.tm_min;
70 _zhr = tm.tm_hour;
71 }
72
zmsec(void)73 int zmsec(void)
74 {
75 ztimer();
76 return _zmsec;
77 }
78
79 char exttime[13];
ztime()80 char *ztime()
81 {
82 ztimer();
83 snprintf(exttime, sizeof(exttime),
84 "%02d:%02d:%02d.%03d",
85 _zhr, _zmin, _zsec, _zmsec);
86 return exttime;
87 }
88