summaryrefslogtreecommitdiffstats
path: root/master/model-50-v1.patch
blob: b9a10c84ebbafa1106ee4225c1b025f8c2f82aaa (plain)
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
diff --git a/Makefile b/Makefile
index 22a7c9e..e758fa4 100644
--- a/Makefile
+++ b/Makefile
@@ -11,13 +11,15 @@ LIBDIR=$(PREFIX)/lib
 MANDIR=$(PREFIX)/man
 INCDIR=$(PREFIX)/include
 
+PORT = /dev/ttyUSB1
+
 CC = gcc
-#CFLAGS = -Wall -g -DBINDIR=\"$(BINDIR)\"
-CFLAGS = -O2 -DBINDIR=\"$(BINDIR)\"
+CPPFLAGS = -DBINDIR=\"$(BINDIR)\" -DPORT=\"$(PORT)\"
+#CFLAGS = -g -Wall -fPIC ${CPPFLAGS}
+CFLAGS = -O2 -fPIC ${CPPFLAGS}
 
-PORT = /dev/ttyS0
 
-ENGINES = svgablink serblink
+ENGINES = serblink
 
 RANLIB = echo
 #RANLIB = ranlib
@@ -74,12 +76,12 @@ parse.c: dataread.l dl_read_save.c y.tab.h
 	mv lex.yy.c $@
 
 depend: parse.c dl_read_save.c
-	makedepend -f- -o.o $(CFLAGS) $(SRC) $(SVGASRC) $(SERSRC) > depend
+	makedepend -f- -o.o $(CPPFLAGS) $(SRC) $(SVGASRC) $(SERSRC) > depend
 	@echo "Dependencies have been made, re-run make to build"
 	@false
 
 serblink.o: $(SERSRC)
-	$(CC) -c $(CFLAGS) -DPORT=\"$(PORT)\" $(SERSRC)
+	$(CC) $(CFLAGS) -o $@ -c $(SERSRC)
 
 serblink: $(SEROBJ)
 	rm -f $@
@@ -90,19 +92,19 @@ svgablink: $(SVGAOBJ)
 	$(CC) $(CFLAGS) -o $@ $(SVGAOBJ) -lvga
 
 settime.o: settime.c
-	$(CC) $(CFLAGS) -I. -c settime.c 
+	$(CC) $(CFLAGS) -I. -c -o $@ settime.c
 
 setwatch.o: setwatch.c
-	$(CC) $(CFLAGS) -I. -c setwatch.c 
+	$(CC) $(CFLAGS) -I. -c -o $@ setwatch.c
 
 settime: settime.o libdatalink.a
-	$(CC) $(CFLAGS) -o $@ settime.o -L. -ldatalink
+	$(CC) $(CFLAGS) -o $@ settime.o libdatalink.a
 
 setwatch: setwatch.o libdatalink.a
-	$(CC) $(CFLAGS) -o $@ setwatch.o -L. -ldatalink
+	$(CC) $(CFLAGS) -o $@ setwatch.o libdatalink.a
 
 cvt: cvt.o
-	$(CC) $(CFLAGS) -o $@
+	$(CC) $(CFLAGS) -o $@ -c $@.o
 
 install: all
 	mkdir -p $(BINDIR) $(MANDIR)/man1
diff --git a/dl_send_data.c b/dl_send_data.c
index 3dfa12e..b3ac3ec 100644
--- a/dl_send_data.c
+++ b/dl_send_data.c
@@ -27,10 +27,15 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <termios.h>
 #include "datalink.h"
 #include "datalink_private.h"
 
+#if 0
 #define MAX_PCKT 38
+#else
+#define MAX_PCKT 32
+#endif
 
 #define TIME_70 0x30
 #define DSTART_70 0x60
@@ -60,7 +65,7 @@ static unsigned char dstart[] = { 5, 0x93, 0, 0, 0 };
 static unsigned char dinfo[] = { 20, 0x90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	0, 0, 0, 0, 0, 0, 0
 };
-static unsigned char dspace[] = { 4, 0x91, 0, 0 };
+static unsigned char dspace[] = { 3, 0x91, 0 };
 static unsigned char dend[] = { 5, 0x92, 0, 0, 0 };
 static unsigned char blank_alarm[] = { 18, 0x50, 0, 0, 0, 0, 0, 0, 0, 0,
 	0, 0, 0, 0, 0, 0, 0, 0
@@ -94,11 +99,19 @@ int _write_data(int fd, unsigned char *buf, unsigned char *data, int size,
 
 		memcpy(buf, dspace, *dspace);
 
+#if 1
+		buf[0] = 0x3;
+#endif
+
 		if (wi->dl_device == DATALINK_70)
 			buf[1] = DATA_70;
 
+#if 0
 		buf[2] = type;
 		buf[3] = (*pnum)++;
+#else
+		buf[2] = (*pnum)++;
+#endif
 	}
 
 	if (!size)
@@ -119,7 +132,11 @@ int dl_send_data(WatchInfoPtr wi, int type)
 	char * template="/datalink_XXXXXX";
 	unsigned char buf[64];
 	unsigned char data[64];
+#if 0
 	unsigned short addr = 0x0236;
+#else
+	unsigned short addr = 0x000e;
+#endif
 	char *protocol;
 	AppointmentPtr ap;
 	ToDoPtr tp;
@@ -135,7 +152,9 @@ int dl_send_data(WatchInfoPtr wi, int type)
 	int status;
 	int ret=0;
 	int p;
+	struct termios tios;
 
+#if 0
 	if (type == BLINK_FILE)
 	{
 		strcpy(fname, "DEBUGOUTPUT");
@@ -172,6 +191,33 @@ int dl_send_data(WatchInfoPtr wi, int type)
 			return ((*dl_error_proc) (buf));
 		}
 	}
+#else
+	if (getenv("TIMEX_PORT")) {
+		strcpy(fname, getenv("TIMEX_PORT"));
+	} else {
+		strcpy(fname, PORT);
+	}
+
+	if ((ofd = open(fname, O_WRONLY)) == -1) {
+		sprintf(buf, "Can't open %s for writing.", fname);
+		return ((*dl_error_proc) (buf));
+	}
+
+	if (tcgetattr(ofd, &tios) < 0)
+	{
+		return ((*dl_error_proc) ("tcgetattr failed"));
+	}
+
+        cfmakeraw(&tios);
+	cfsetspeed(&tios, B115200); /* It's usb so baudrate doesn't matter */
+
+	if (tcsetattr(ofd, TCSANOW, &tios) < 0)
+	{
+		return ((*dl_error_proc) ("tcsetattr failed"));
+	}
+
+        write(ofd, "Timex", 5);
+#endif
 
 	memcpy(buf, start1, *start1);
 
@@ -213,6 +259,10 @@ int dl_send_data(WatchInfoPtr wi, int type)
 	for (i = 0; i < dl_download_data.num_times; i++)
 	{
 		memcpy(buf, time, *time);
+#if 1
+		buf[0] = 0xd;
+#endif
+
 		p = 2;
 		if (wi->dl_device == DATALINK_IRONMAN)
 		{
@@ -242,6 +292,7 @@ int dl_send_data(WatchInfoPtr wi, int type)
 			buf[p++] = dl_download_data.times[i].month;
 			buf[p++] = dl_download_data.times[i].day;
 			buf[p++] = dl_download_data.times[i].year;
+#if 0
 			buf[p++] =
 			    dl_pack_char(dl_download_data.
 					 times[i].label[0]);
@@ -252,6 +303,11 @@ int dl_send_data(WatchInfoPtr wi, int type)
 			    dl_pack_char(dl_download_data.
 					 times[i].label[2]);
 			buf[p++] = dl_download_data.times[i].dow - 1;
+#else
+			buf[p++] = dl_download_data.times[i].dow;
+			buf[p++] = dl_download_data.times[i].seconds;
+			buf[p++] = dl_download_data.times[i].hour_fmt;
+#endif
 		}
 
 		if (wi->dl_device == DATALINK_150 ||
@@ -276,14 +332,26 @@ int dl_send_data(WatchInfoPtr wi, int type)
 
 	if (wi->dl_device != DATALINK_IRONMAN && dl_download_data.memory)
 	{
+#if 0
 		memcpy(buf, dstart, *dstart);
 		buf[2] = 1;
+#else
+		buf[0] = 0x05;
+		buf[1] = 0x60;
+		buf[2] = dl_download_data.memory / (MAX_PCKT - 6);
+
+		if (dl_download_data.memory % (MAX_PCKT - 6))
+			buf[2]++;
+		buf[2]++;
+#endif
 		dl_docrc(buf);
 
 		if (write(ofd, buf, *buf) != *buf)
 			return ((*dl_error_proc)
 				("Can't write dstart to tmp file."));
 
+
+#if 0
 		memcpy(buf, dinfo, *dinfo);
 		buf[2] = 1;
 		buf[3] = dl_download_data.memory / (MAX_PCKT - 6);
@@ -313,6 +381,31 @@ int dl_send_data(WatchInfoPtr wi, int type)
 
 		if (wi->dl_device == DATALINK_70)
 			buf[1] = DATA_70;
+#else
+
+		pnum=1;
+
+		buf[0] = 0x13;
+		buf[1] = 0x61;
+		buf[2] = pnum;
+		buf[3] = (addr >> 8) & 0xff;
+		buf[4] = addr & 0xff;
+		addr += dl_download_data.app_size;
+		buf[5] = (addr >> 8) & 0xff;
+		buf[6] = addr & 0xff;
+		addr += dl_download_data.todo_size;
+		buf[7] = (addr >> 8) & 0xff;
+		buf[8] = addr & 0xff;
+		addr += dl_download_data.phone_size;
+		buf[9] = (addr >> 8) & 0xff;
+		buf[10] = addr & 0xff;
+		buf[11] = dl_download_data.num_apps;
+		buf[12] = dl_download_data.num_todos;
+		buf[13] = dl_download_data.num_phones;
+		buf[14] = dl_download_data.num_annivs;
+		buf[15] = 0x00;
+		buf[16] = 0x03;
+#endif
 
 		dl_docrc(buf);
 
@@ -320,14 +413,26 @@ int dl_send_data(WatchInfoPtr wi, int type)
 			return ((*dl_error_proc)
 				("Can't write dinfo to tmp file."));
 
+#if 0
 		pnum = 1;
+#else
+		pnum = 2;
+#endif
 		memcpy(buf, dspace, *dspace);
 
+#if 1
+		buf[0] = 0x3;
+#endif
+
 		if (wi->dl_device == DATALINK_70)
 			buf[1] = DATA_70;
 
+#if 0
 		buf[2] = 1;
 		buf[3] = pnum++;
+#else
+		buf[2] = pnum++;
+#endif
 
 		for (i = 0; i < dl_download_data.num_apps; i++)
 		{
@@ -421,8 +526,16 @@ int dl_send_data(WatchInfoPtr wi, int type)
 			return ((*dl_error_proc)
 				("Can't write to tmp file."));
 
+
+#if 0
 		memcpy(buf, dend, *dend);
 		buf[2] = 1;
+#else
+		buf[0]=0x4;
+		buf[1]=0x62;
+#endif
+
+
 		dl_docrc(buf);
 
 		if (write(ofd, buf, *buf) != *buf)
@@ -558,7 +671,11 @@ int dl_send_data(WatchInfoPtr wi, int type)
 	}
 
 	/* timezone label packet for IRONMAN watch */
+#if 0
 	if (wi->dl_device == DATALINK_IRONMAN)
+#else
+	if (1)
+#endif
 		for (i = 0; i < dl_download_data.num_times; i++)
 		{
 			p = 0;
@@ -673,6 +790,10 @@ int dl_send_data(WatchInfoPtr wi, int type)
 
 		memcpy(buf, dspace, *dspace);
 
+#if 1
+		buf[0] = 0x3;
+#endif
+
 		if (wi->dl_device == DATALINK_70)
 			buf[1] = DATA_70;
 
@@ -735,6 +856,10 @@ int dl_send_data(WatchInfoPtr wi, int type)
 
 		memcpy(buf, dspace, *dspace);
 
+#if 1
+		buf[0] = 0x3;
+#endif
+
 		if (wi->dl_device == DATALINK_70)
 			buf[1] = DATA_70;
 
@@ -798,6 +923,7 @@ int dl_send_data(WatchInfoPtr wi, int type)
 
 	close(ofd);
 
+#if 0
 	switch (type)
 	{
 	case BLINK_FILE:
@@ -892,6 +1018,7 @@ int dl_send_data(WatchInfoPtr wi, int type)
 
 		break;
 	}
+#endif
 
 	return (ret);
 }
diff --git a/serblink.c b/serblink.c
index 9ca9fdc..44751f0 100644
--- a/serblink.c
+++ b/serblink.c
@@ -30,7 +30,7 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <stdlib.h>
-#include <termios.h>
+#include <asm/termios.h>
 #include <string.h>
 
 #include <sys/time.h>
@@ -41,7 +41,7 @@
 #endif
 
 #ifndef PORT
-#define PORT "/dev/ttyd1"
+#define PORT "/dev/ttyUSB1"
 #endif
 
 void sendbyte(int fil, unsigned char dat)
@@ -50,6 +50,7 @@ void sendbyte(int fil, unsigned char dat)
 #define LEN 6
 {
 	static int frame = 0;
+#if 0
 	char buff[1024];
 	int c = 0;
 	int i;
@@ -72,11 +73,21 @@ void sendbyte(int fil, unsigned char dat)
 	/* a single CRT frame (different inter-word pause) */
 
 	write(fil, buff, c);
+#else
+	write(fil, &dat, 1);
+	if (!frame)  { 
+		usleep(1492); /*Scanlines 216 to 263 */
+	} else {
+		usleep(6383); /*Scanlines 402 to 78 */
+	}
+	frame = !frame;		/* a frame is 2 words, which would have been on */
+#endif
 }
 
 /* For pauses between packets: */
 static void __pause(int fil, int count)
 {
+#if 0
 	char buff[8192];
 	int i, c;
 
@@ -84,6 +95,9 @@ static void __pause(int fil, int count)
 	for (i = 0; i < (count * LEN); i++)
 		buff[c++] = 0x0;
 	write(fil, buff, c);
+#else
+	usleep(count * 488); // 488 per 2048 baud bit
+#endif
 }
 
 #undef ZERO
@@ -95,6 +109,7 @@ int main(int argc, char **argv)
 	int port;
 	int data;
 	struct termios old, new;
+	struct termios2 tios2;
 	int i, j, len, plen;
 	unsigned char buff[4096];
 	char fil[1024];
@@ -166,13 +181,20 @@ int main(int argc, char **argv)
 		perror("tcgetattr failed:");
 		exit(1);
 	}
-	new = old;
-	cfsetspeed(&new, B115200);
+	cfmakeraw(&new);
+	cfsetspeed(&new, B2400);
 	if (tcsetattr(port, TCSANOW, &new) < 0)
 	{
 		perror("tcsetattr failed:");
 		exit(1);
 	}
+
+	ioctl(port, TCGETS2, &tios2);
+	tios2.c_cflag &= ~CBAUD;
+	tios2.c_cflag |= BOTHER;
+	tios2.c_ispeed = tios2.c_ospeed = 2048;
+	ioctl(port, TCSETS2, &tios2);
+
 #if 0
 	while (1)
 		__pause(port, 20);	/* used for hardware debugging */
diff --git a/settime.c b/settime.c
index 7361599..3c89093 100644
--- a/settime.c
+++ b/settime.c
@@ -151,6 +151,6 @@ int main( int argc, char ** argv)
 /*
  Send it to the watch
 */
-	dl_send_data(wi, SVGA_BLINK);
+	dl_send_data(wi, BLINK_FILE);
 	return 0;
 }