1 /*
2 * Copyright 1996, 1997, 1998, 1999 by Daniel B. Suthers,
3 * Pleasanton Ca. 94588 USA
4 * E-MAIL dbs@tanj.com
5 *
6 */
7
8 /*
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24
25 #include <ctype.h>
26 #include <stdio.h>
27 #include <time.h>
28 #include "x10.h"
29 #include "version.h"
30 #include "process.h"
31
32 extern unsigned int x2unitmap();
33
34 extern int Irev, Idays, Ihours, Iminutes, Ijday, Iseconds;
35 extern int Istatdim, Istatmon, Iaddmon;
36 extern unsigned int Ibattery;
37 extern unsigned char Ihcode;
38
39 extern void error();
40 extern char *heyu_tzname[];
41 extern struct tm *cm11a_to_legal();
42 extern CONFIG config;
43 extern CONFIG *configp;
44
45 extern char *wday_name[7];
46 extern char *month_name[12];
47 extern char heyu_config[PATH_LEN + 1];
48
49 /* ARGSUSED */
50
c_info(int argc,char * argv[])51 int c_info( int argc, char *argv[] )
52 {
53 extern int usage(), get_status();
54
55 struct tm *tms;
56 int expire;
57 char error_msg[127];
58
59
60 if (argc != 2)
61 usage(E_2MANY);
62
63 if ( configp->device_type & DEV_DUMMY ) {
64 printf("Heyu version %s\n", VERSION);
65 printf("Configuration at %s\n", pathspec(heyu_config));
66 printf("Dummy powerline interface (TTY %s)\n", configp->tty);
67 if ( configp->ttyaux[0] )
68 printf("Auxiliary RF interface on %s\n", configp->ttyaux);
69 if ( configp->ttyrfxmit[0] ) {
70 printf("%sMHz RFXmitter on %s\n",
71 ((configp->rfxmit_freq == MHZ310) ? "310" : "433"), configp->ttyrfxmit);
72 }
73 return 0;
74 }
75
76 if ( configp->device_type & DEV_CM10A ) {
77 printf("Heyu version %s\n", VERSION);
78 printf("Configuration at %s\n", pathspec(heyu_config));
79 printf("Powerline interface CM10A on %s\n", configp->tty);
80 if ( configp->ttyaux[0] )
81 printf("Auxiliary RF interface on %s\n", configp->ttyaux);
82 if ( configp->ttyrfxmit[0] ) {
83 printf("%sMHz RFXmitter on %s\n",
84 ((configp->rfxmit_freq == MHZ310) ? "310" : "433"), configp->ttyrfxmit);
85 }
86 return 0;
87 }
88
89 if ( get_status() < 0 ) {
90 sprintf(error_msg,
91 "No response from the CM11A on %s\nProgram exiting.",
92 configp->tty);
93 error(error_msg);
94 }
95
96 printf("Heyu version %s\n", VERSION);
97 printf("Configuration at %s\n", pathspec(heyu_config));
98 printf("Powerline interface on %s\n", configp->tty);
99 if ( configp->ttyaux[0] )
100 printf("Auxiliary RF interface on %s\n", configp->ttyaux);
101 if ( configp->ttyrfxmit[0] ) {
102 printf("%sMHz RFXmitter on %s\n",
103 ((configp->rfxmit_freq == MHZ310) ? "310" : "433"), configp->ttyrfxmit);
104 }
105 printf("Firmware revision Level = %d\n", Irev );
106
107 /* Display CM11a battery timer */
108 if ( Ibattery == 0xFFFF )
109 (void) printf("Interface battery usage = Unknown\n");
110 else
111 (void) printf("Interface battery usage = %d:%02d (hh:mm)\n",
112 Ibattery / 60, Ibattery % 60);
113
114 if ((Ihours + Iminutes + Idays + Ijday) != 0 ) {
115 (void) printf("Raw interface clock: %s, Day %03d, %02d:%02d:%02d\n",
116 bmap2ascdow(Idays), Ijday, Ihours, Iminutes, Iseconds);
117
118 tms = cm11a_to_legal(&Idays, &Ijday, &Ihours, &Iminutes, &Iseconds, &expire);
119
120 if ( expire != BAD_RECORD_FILE ) {
121 (void) printf("(--> Civil Time: %s %02d %s %d %02d:%02d:%02d %s)\n",
122 bmap2ascdow(Idays), tms->tm_mday, month_name[tms->tm_mon], tms->tm_year + 1900,
123 tms->tm_hour, tms->tm_min, tms->tm_sec, heyu_tzname[tms->tm_isdst]);
124 }
125
126 display_status_message( expire );
127 }
128 else
129 (void) printf("Interface clock not yet set\n");
130
131 (void) printf("Housecode = %c\n", code2hc(Ihcode));
132
133 (void) printf("0 = off, 1 = on, unit 16.......8...4..1\n");
134
135 (void) printf("Last addressed device = 0x%04x (%s)\n", Iaddmon,
136 bmap2rasc(Iaddmon, "01") );
137 (void) printf("Status of monitored devices = 0x%04x (%s)\n", Istatmon,
138 bmap2rasc(Istatmon, "01") );
139 (void) printf("Status of dimmed devices = 0x%04x (%s)\n", Istatdim,
140 bmap2rasc(Istatdim, "01") );
141 return(0);
142 }
143
wait_next_tick(void)144 void wait_next_tick (void )
145 {
146 time_t first, now;
147 int j;
148
149 time(&first);
150
151 for ( j = 0; j < 25; j++ ) {
152 time(&now);
153 if ( now > first )
154 break;
155 millisleep(50);
156 }
157 return;
158 }
159
160
161
c_readclock(int argc,char * argv[])162 int c_readclock( int argc, char *argv[] )
163 {
164 extern int usage(), get_status();
165 extern char *bits2day(), *b2s();
166
167 time_t now;
168 struct tm *tms;
169 int expire;
170 char error_msg[127];
171
172
173 if (argc != 2)
174 usage(E_2MANY);
175
176 if ( configp->device_type & DEV_CM10A ) {
177 printf("CM10A interface has no clock.\n");
178 return 1;
179 }
180
181 wait_next_tick();
182
183 if ( get_status() < 0 ) {
184 sprintf(error_msg,
185 "No response from the CM11A on %s\nProgram exiting.",
186 configp->tty);
187 error(error_msg);
188 }
189
190 if ((Ihours + Iminutes + Idays + Ijday) != 0 ) {
191
192 tms = cm11a_to_legal(&Idays, &Ijday, &Ihours, &Iminutes, &Iseconds, &expire);
193
194 if ( expire != BAD_RECORD_FILE ) {
195 (void) printf("CM11A Time : %s %02d %s %d %02d:%02d:%02d %s\n",
196 bmap2ascdow(Idays), tms->tm_mday, month_name[tms->tm_mon], tms->tm_year + 1900,
197 tms->tm_hour, tms->tm_min, tms->tm_sec, heyu_tzname[tms->tm_isdst]);
198 time(&now);
199 tms = localtime(&now);
200 (void) printf("System Time: %s %02d %s %d %02d:%02d:%02d %s\n",
201 bmap2ascdow(1 << tms->tm_wday), tms->tm_mday, month_name[tms->tm_mon], tms->tm_year + 1900,
202 tms->tm_hour, tms->tm_min, tms->tm_sec, heyu_tzname[tms->tm_isdst]);
203 }
204 else {
205 (void) fprintf(stderr, "File x10record has been corrupted.\n");
206 return 1;
207 }
208 }
209 else
210 (void) printf("Interface clock not yet set\n");
211
212 return 0;
213 }
214