summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYour Name <you@example.com>2019-04-30 14:15:36 +0100
committerYour Name <you@example.com>2019-04-30 14:15:36 +0100
commit37daf91cae1298d38ec7a81f97ed907274c59633 (patch)
tree1b8f950005c91be9632069ee7a7fd68c30caaf10
downloaddatalink-pq-37daf91cae1298d38ec7a81f97ed907274c59633.zip
datalink-pq-37daf91cae1298d38ec7a81f97ed907274c59633.tar.gz
datalink-pq-37daf91cae1298d38ec7a81f97ed907274c59633.tar.bz2
fish
-rw-r--r--.gitignore2
-rw-r--r--master/model-50-v1.patch458
-rw-r--r--master/model-50-v2-cumul.patch484
-rw-r--r--master/model-50-v2.patch739
-rw-r--r--master/series3
5 files changed, 1686 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..094a6e8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*~
+status
diff --git a/master/model-50-v1.patch b/master/model-50-v1.patch
new file mode 100644
index 0000000..b9a10c8
--- /dev/null
+++ b/master/model-50-v1.patch
@@ -0,0 +1,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;
+ }
diff --git a/master/model-50-v2-cumul.patch b/master/model-50-v2-cumul.patch
new file mode 100644
index 0000000..d4205c7
--- /dev/null
+++ b/master/model-50-v2-cumul.patch
@@ -0,0 +1,484 @@
+diff --git a/Makefile b/Makefile
+index e758fa4..ee168c2 100644
+--- a/Makefile
++++ b/Makefile
+@@ -11,7 +11,7 @@ LIBDIR=$(PREFIX)/lib
+ MANDIR=$(PREFIX)/man
+ INCDIR=$(PREFIX)/include
+
+-PORT = /dev/ttyUSB1
++PORT = /dev/ttyACM1
+
+ CC = gcc
+ CPPFLAGS = -DBINDIR=\"$(BINDIR)\" -DPORT=\"$(PORT)\"
+diff --git a/datalink.h b/datalink.h
+index ab6f2d7..d14eeae 100644
+--- a/datalink.h
++++ b/datalink.h
+@@ -212,10 +212,11 @@ typedef struct watch_info_s
+
+ /* Watch types */
+ #define NO_WATCH 0
+-#define DATALINK_70 1
+-#define DATALINK_150 2
+-#define DATALINK_150S 3
+-#define DATALINK_IRONMAN 4
++#define DATALINK_50 1
++#define DATALINK_70 2
++#define DATALINK_150 3
++#define DATALINK_150S 4
++#define DATALINK_IRONMAN 5
+
+ #define DEF_LPTRANSINFO 1
+
+diff --git a/dl_init_watch.c b/dl_init_watch.c
+index 9cfc929..9e88500 100644
+--- a/dl_init_watch.c
++++ b/dl_init_watch.c
+@@ -62,6 +62,32 @@ WatchInfoPtr dl_init_watch(int type)
+
+ switch (type)
+ {
++ case DATALINK_50:
++ result->dl_device = type;
++ result->max_tz = 2;
++ result->max_alarms = 5;
++ result->max_chrons = 0;
++ result->max_chron_str = 0;
++ result->max_apps = 255;
++ result->max_phones = 255;
++ result->max_timers = 0;
++ result->max_todos = 255;
++ result->max_annivs = 255;
++ result->max_system = 1;
++ result->max_wristapp = 0;
++ result->max_melody = 0;
++ result->max_tzlen = 3;
++ result->max_mem = 850;
++ result->mem_size = 0;
++ result->max_str = 15;
++ result->max_alarm_str = 8;
++ result->max_phone_str = 12;
++ result->max_timer_str = 0;
++ result->max_wristapp_len = 0;
++ result->max_mel_len = 0;
++ result->pre_notification_time = 0;
++ result->time_adjust = 9;
++ break;
+ case DATALINK_70:
+ result->dl_device = type;
+ result->max_tz = 2;
+diff --git a/dl_send_data.c b/dl_send_data.c
+index 94f93e7..1ccbcf0 100644
+--- a/dl_send_data.c
++++ b/dl_send_data.c
+@@ -99,19 +99,18 @@ 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_50)
++ buf[0] = 0x3;
+
+- if (wi->dl_device == DATALINK_70)
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ buf[1] = DATA_70;
+
+-#if 0
+- buf[2] = type;
+- buf[3] = (*pnum)++;
+-#else
+- buf[2] = (*pnum)++;
+-#endif
++ if (wi->dl_device == DATALINK_50) {
++ buf[2] = (*pnum)++;
++ } else {
++ buf[2] = type;
++ buf[3] = (*pnum)++;
++ }
+ }
+
+ if (!size)
+@@ -221,7 +220,7 @@ int dl_send_data(WatchInfoPtr wi, int type)
+
+ memcpy(buf, start1, *start1);
+
+- if (wi->dl_device == DATALINK_70)
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ {
+ buf[4] = 1;
+ }
+@@ -259,9 +258,8 @@ 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
++ if (wi->dl_device == DATALINK_50)
++ buf[0] = 0xd;
+
+ p = 2;
+ if (wi->dl_device == DATALINK_IRONMAN)
+@@ -285,29 +283,29 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ buf[p++] = dl_download_data.times[i].year;
+ buf[p++] = dl_download_data.times[i].dow;
+ buf[p++] = dl_download_data.times[i].seconds;
+- } else
+- {
++ } else {
+ buf[p++] = dl_download_data.times[i].hours;
+ buf[p++] = dl_download_data.times[i].minutes;
+ 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]);
+- buf[p++] =
+- dl_pack_char(dl_download_data.
+- times[i].label[1]);
+- buf[p++] =
+- 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_50) {
++ 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;
++ } else {
++ buf[p++] =
++ dl_pack_char(dl_download_data.
++ times[i].label[0]);
++ buf[p++] =
++ dl_pack_char(dl_download_data.
++ times[i].label[1]);
++ buf[p++] =
++ dl_pack_char(dl_download_data.
++ times[i].label[2]);
++ buf[p++] = dl_download_data.times[i].dow - 1;
++ }
+ }
+
+ if (wi->dl_device == DATALINK_150 ||
+@@ -319,7 +317,7 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ dl_download_data.times[i].date_fmt & 0xFF;
+ }
+
+- if (wi->dl_device == DATALINK_70)
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ buf[1] = TIME_70;
+
+ dl_docrc(buf);
+@@ -332,18 +330,19 @@ 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 (wi->dl_device == DATALINK_50) {
++ buf[0] = 0x05;
++ buf[1] = 0x60;
++ buf[2] = dl_download_data.memory / (MAX_PCKT - 6);
+
+- if (dl_download_data.memory % (MAX_PCKT - 6))
++ if (dl_download_data.memory % (MAX_PCKT - 6))
++ buf[2]++;
+ buf[2]++;
+- buf[2]++;
+-#endif
++ } else {
++ memcpy(buf, dstart, *dstart);
++ buf[2] = 1;
++ }
++
+ dl_docrc(buf);
+
+ if (write(ofd, buf, *buf) != *buf)
+@@ -351,61 +350,60 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ ("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);
+-
+- if (dl_download_data.memory % (MAX_PCKT - 6))
+- buf[3]++;
++ if (wi->dl_device == DATALINK_50) {
++ pnum=1;
+
+- buf[12] = dl_download_data.num_apps;
+- buf[13] = dl_download_data.num_todos;
+- buf[14] = dl_download_data.num_phones;
+- buf[15] = dl_download_data.num_annivs;
+- buf[4] = (addr >> 8) & 0xff;
+- buf[5] = addr & 0xff;
+- addr += dl_download_data.app_size;
+- buf[6] = (addr >> 8) & 0xff;
+- buf[7] = addr & 0xff;
+- addr += dl_download_data.todo_size;
+- buf[8] = (addr >> 8) & 0xff;
+- buf[9] = addr & 0xff;
+- addr += dl_download_data.phone_size;
+- buf[10] = (addr >> 8) & 0xff;
+- buf[11] = addr & 0xff;
+- buf[16] = 0x62;
+- buf[17] = dl_download_data.pre_notification_time / 5;
+- if (!buf[17])
+- buf[17] = 0xff;
+-
+- 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
++ 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;
++ } else {
++ memcpy(buf, dinfo, *dinfo);
++ buf[2] = 1;
++ buf[3] = dl_download_data.memory / (MAX_PCKT - 6);
++
++ if (dl_download_data.memory % (MAX_PCKT - 6))
++ buf[3]++;
++
++ buf[12] = dl_download_data.num_apps;
++ buf[13] = dl_download_data.num_todos;
++ buf[14] = dl_download_data.num_phones;
++ buf[15] = dl_download_data.num_annivs;
++ buf[4] = (addr >> 8) & 0xff;
++ buf[5] = addr & 0xff;
++ addr += dl_download_data.app_size;
++ buf[6] = (addr >> 8) & 0xff;
++ buf[7] = addr & 0xff;
++ addr += dl_download_data.todo_size;
++ buf[8] = (addr >> 8) & 0xff;
++ buf[9] = addr & 0xff;
++ addr += dl_download_data.phone_size;
++ buf[10] = (addr >> 8) & 0xff;
++ buf[11] = addr & 0xff;
++ buf[16] = 0x62;
++ buf[17] = dl_download_data.pre_notification_time / 5;
++ if (!buf[17])
++ buf[17] = 0xff;
++
++ if (wi->dl_device == DATALINK_70)
++ buf[1] = DATA_70;
++ }
+
+ dl_docrc(buf);
+
+@@ -413,27 +411,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
++ if (wi->dl_device == DATALINK_50)
++ pnum = 2;
++ else
++ pnum = 1;
++
+ memcpy(buf, dspace, *dspace);
+
+-#if 1
+- buf[0] = 0x3;
+-#endif
++ if (wi->dl_device == DATALINK_50)
++ buf[0] = 0x3;
+
+- if (wi->dl_device == DATALINK_70)
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ buf[1] = DATA_70;
+
+-#if 0
+- buf[2] = 1;
+- buf[3] = pnum++;
+-#else
+- buf[2] = pnum++;
+-#endif
+-
++ if (wi->dl_device == DATALINK_50) {
++ buf[2] = pnum++;
++ } else {
++ buf[2] = 1;
++ buf[3] = pnum++;
++ }
++
+ for (i = 0; i < dl_download_data.num_apps; i++)
+ {
+ ap = &dl_download_data.apps[i];
+@@ -792,11 +789,10 @@ int dl_send_data(WatchInfoPtr wi, int type)
+
+ memcpy(buf, dspace, *dspace);
+
+-#if 1
+- buf[0] = 0x3;
+-#endif
++ if (wi->dl_device == DATALINK_50)
++ buf[0] = 0x3;
+
+- if (wi->dl_device == DATALINK_70)
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ buf[1] = DATA_70;
+
+ pnum = 1;
+@@ -858,11 +854,10 @@ int dl_send_data(WatchInfoPtr wi, int type)
+
+ memcpy(buf, dspace, *dspace);
+
+-#if 1
+- buf[0] = 0x3;
+-#endif
++ if (wi->dl_device == DATALINK_50)
++ buf[0] = 0x3;
+
+- if (wi->dl_device == DATALINK_70)
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ buf[1] = DATA_70;
+
+ pnum = 1;
+diff --git a/settime.c b/settime.c
+index 3c89093..ab98990 100644
+--- a/settime.c
++++ b/settime.c
+@@ -117,6 +117,9 @@ int main( int argc, char ** argv)
+
+ if(argc==2)
+ {
++ if(!strcmp("-model50",argv[1])||!strcmp("-50",argv[1]))
++ wi = dl_init_watch(DATALINK_50);
++ else
+ if(!strcmp("-model70",argv[1])||!strcmp("-70",argv[1]))
+ wi = dl_init_watch(DATALINK_70);
+ else
+@@ -130,7 +133,7 @@ int main( int argc, char ** argv)
+ wi = dl_init_watch(DATALINK_IRONMAN);
+ else
+ {
+- printf("Usage: %s [ -model70 | -70 | -model70 | "
++ printf("Usage: %s [ -model50 | -50 | -70 | -model70 | "
+ "-150 | -model150 | -model150s | -150s |"
+ " -ironman]\nVersion "
+ "$Id: settime.c,v 1.13 2002/07/10 04:23:23 david Exp $\n", argv[0]);
+diff --git a/setwatch.c b/setwatch.c
+index 93a9364..eee146b 100644
+--- a/setwatch.c
++++ b/setwatch.c
+@@ -120,7 +120,8 @@ void Usage()
+ printf("Usage: datalink [watch type] [options] [datafile]\n");
+ printf
+ ("watchtype (ironman is default, must be specified before other options)\n");
+- printf(" -model70\t use if you have this watch\n");
++ printf(" -50\t use if you have this watch\n");
++ printf(" -model50\t use if you have this watch\n");
+ printf(" -70\t use if you have this watch\n");
+ printf(" -model70\t use if you have this watch\n");
+ printf(" -150\t use if you have this watch\n");
+@@ -199,6 +200,7 @@ void Usage()
+ #define CHRON 0x400
+
+ /* All would be 0x755 */
++#define ALL50 0x07F
+ #define ALL70 0x07F
+ #define ALL150 0x1FF
+ #define ALLIRONMAN 0x653
+@@ -228,6 +230,8 @@ int main(int argc, char **argv)
+
+ if (strcmp("-all", argv[1]) == 0)
+ {
++ if (type == DATALINK_50)
++ flags = ALL50;
+ if (type == DATALINK_70)
+ flags = ALL70;
+ if (type == DATALINK_150 || type == DATALINK_150S)
+@@ -300,6 +304,10 @@ int main(int argc, char **argv)
+ output = BLINK_FILE;
+ else if (strcmp("-serial", argv[1]) == 0)
+ output = SER_BLINK;
++ else if (strcmp("-model50", argv[1]) == 0)
++ type = DATALINK_50;
++ else if (strcmp("-50", argv[1]) == 0)
++ type = DATALINK_50;
+ else if (strcmp("-model70", argv[1]) == 0)
+ type = DATALINK_70;
+ else if (strcmp("-70", argv[1]) == 0)
+diff --git a/svgablink.c b/svgablink.c
+index 185a2ca..3e30461 100644
+--- a/svgablink.c
++++ b/svgablink.c
+@@ -70,10 +70,14 @@ int main(int argc, char **argv)
+ || strcmp(argv[1], "-model70") == 0)
+ type = DATALINK_70;
+ else
++ if (strcmp(argv[1], "-50") == 0
++ || strcmp(argv[1], "-model50") == 0)
++ type = DATALINK_50;
++ else
+ {
+ fprintf(stderr, "Unknown option %s.\n", argv[1]);
+ fprintf(stderr, "Usage: %s [ -ironman | -modelironman | -150 | -model150 | -150s | \n"
+- "\t-model150s | -70 | -model70 ] datafile\n"
++ "\t-model150s | -70 | -model70 | -50 | -model50 ] datafile\n"
+ "Version $Id: svgablink.c,v 1.12 2002/07/10 04:27:08 david Exp $\n", argv[0]);
+ exit(-1);
+ }
diff --git a/master/model-50-v2.patch b/master/model-50-v2.patch
new file mode 100644
index 0000000..2f93d98
--- /dev/null
+++ b/master/model-50-v2.patch
@@ -0,0 +1,739 @@
+diff --git a/Makefile b/Makefile
+index 22a7c9e..48db9f2 100644
+--- a/Makefile
++++ b/Makefile
+@@ -11,13 +11,15 @@ LIBDIR=$(PREFIX)/lib
+ MANDIR=$(PREFIX)/man
+ INCDIR=$(PREFIX)/include
+
++PORT = /dev/ttyACM0
++
+ 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/datalink.h b/datalink.h
+index ab6f2d7..d14eeae 100644
+--- a/datalink.h
++++ b/datalink.h
+@@ -212,10 +212,11 @@ typedef struct watch_info_s
+
+ /* Watch types */
+ #define NO_WATCH 0
+-#define DATALINK_70 1
+-#define DATALINK_150 2
+-#define DATALINK_150S 3
+-#define DATALINK_IRONMAN 4
++#define DATALINK_50 1
++#define DATALINK_70 2
++#define DATALINK_150 3
++#define DATALINK_150S 4
++#define DATALINK_IRONMAN 5
+
+ #define DEF_LPTRANSINFO 1
+
+diff --git a/dl_init_watch.c b/dl_init_watch.c
+index 9cfc929..9e88500 100644
+--- a/dl_init_watch.c
++++ b/dl_init_watch.c
+@@ -62,6 +62,32 @@ WatchInfoPtr dl_init_watch(int type)
+
+ switch (type)
+ {
++ case DATALINK_50:
++ result->dl_device = type;
++ result->max_tz = 2;
++ result->max_alarms = 5;
++ result->max_chrons = 0;
++ result->max_chron_str = 0;
++ result->max_apps = 255;
++ result->max_phones = 255;
++ result->max_timers = 0;
++ result->max_todos = 255;
++ result->max_annivs = 255;
++ result->max_system = 1;
++ result->max_wristapp = 0;
++ result->max_melody = 0;
++ result->max_tzlen = 3;
++ result->max_mem = 850;
++ result->mem_size = 0;
++ result->max_str = 15;
++ result->max_alarm_str = 8;
++ result->max_phone_str = 12;
++ result->max_timer_str = 0;
++ result->max_wristapp_len = 0;
++ result->max_mel_len = 0;
++ result->pre_notification_time = 0;
++ result->time_adjust = 9;
++ break;
+ case DATALINK_70:
+ result->dl_device = type;
+ result->max_tz = 2;
+diff --git a/dl_send_data.c b/dl_send_data.c
+index 3dfa12e..6dcb577 100644
+--- a/dl_send_data.c
++++ b/dl_send_data.c
+@@ -27,10 +27,16 @@
+ #include <sys/wait.h>
+ #include <string.h>
+ #include <limits.h>
++#include <termios.h>
++#include <time.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
+@@ -53,14 +59,14 @@ static unsigned char datablock2[] = { 0x14, 0x70, 0x02, 0x5a,
+ 0x47, 0xb7, 0xa9, 0xcc,
+ 0x74, 0x6f, 0x00, 0x00
+ };
+-static unsigned char time[] = { 17, 0x32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
++static unsigned char time_msg[] = { 17, 0x32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0
+ };
+ 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 +100,18 @@ int _write_data(int fd, unsigned char *buf, unsigned char *data, int size,
+
+ memcpy(buf, dspace, *dspace);
+
+- if (wi->dl_device == DATALINK_70)
++ if (wi->dl_device == DATALINK_50)
++ buf[0] = 0x3;
++
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ buf[1] = DATA_70;
+
+- buf[2] = type;
+- buf[3] = (*pnum)++;
++ if (wi->dl_device == DATALINK_50) {
++ buf[2] = (*pnum)++;
++ } else {
++ buf[2] = type;
++ buf[3] = (*pnum)++;
++ }
+ }
+
+ 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,6 +152,14 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ int status;
+ int ret=0;
+ int p;
++ struct termios tios;
++ time_t now;
++ struct tm *tm;
++ unsigned char year;
++
++ time(&now);
++ tm = localtime(&now);
++ year = tm->tm_year % 100;
+
+ if (type == BLINK_FILE)
+ {
+@@ -148,6 +173,7 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ }
+ else
+ {
++#if 0
+ /* Try to get the directory for a temporary file from
+ * the envinronment variable TMPDIR
+ * Try P_tmpdir if that fails
+@@ -171,11 +197,38 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ sprintf(buf, "Can't open %s for writing.", fname);
+ 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);
+
+- if (wi->dl_device == DATALINK_70)
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ {
+ buf[4] = 1;
+ }
+@@ -212,7 +265,10 @@ int dl_send_data(WatchInfoPtr wi, int type)
+
+ for (i = 0; i < dl_download_data.num_times; i++)
+ {
+- memcpy(buf, time, *time);
++ memcpy(buf, time_msg, *time_msg);
++ if (wi->dl_device == DATALINK_50)
++ buf[0] = 0xd;
++
+ p = 2;
+ if (wi->dl_device == DATALINK_IRONMAN)
+ {
+@@ -235,23 +291,29 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ buf[p++] = dl_download_data.times[i].year;
+ buf[p++] = dl_download_data.times[i].dow;
+ buf[p++] = dl_download_data.times[i].seconds;
+- } else
+- {
++ } else {
+ buf[p++] = dl_download_data.times[i].hours;
+ buf[p++] = dl_download_data.times[i].minutes;
+ buf[p++] = dl_download_data.times[i].month;
+ buf[p++] = dl_download_data.times[i].day;
+ buf[p++] = dl_download_data.times[i].year;
+- buf[p++] =
+- dl_pack_char(dl_download_data.
+- times[i].label[0]);
+- buf[p++] =
+- dl_pack_char(dl_download_data.
+- times[i].label[1]);
+- buf[p++] =
+- dl_pack_char(dl_download_data.
+- times[i].label[2]);
+- buf[p++] = dl_download_data.times[i].dow - 1;
++
++ if (wi->dl_device == DATALINK_50) {
++ 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;
++ } else {
++ buf[p++] =
++ dl_pack_char(dl_download_data.
++ times[i].label[0]);
++ buf[p++] =
++ dl_pack_char(dl_download_data.
++ times[i].label[1]);
++ buf[p++] =
++ dl_pack_char(dl_download_data.
++ times[i].label[2]);
++ buf[p++] = dl_download_data.times[i].dow - 1;
++ }
+ }
+
+ if (wi->dl_device == DATALINK_150 ||
+@@ -263,7 +325,7 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ dl_download_data.times[i].date_fmt & 0xFF;
+ }
+
+- if (wi->dl_device == DATALINK_70)
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ buf[1] = TIME_70;
+
+ dl_docrc(buf);
+@@ -276,43 +338,80 @@ int dl_send_data(WatchInfoPtr wi, int type)
+
+ if (wi->dl_device != DATALINK_IRONMAN && dl_download_data.memory)
+ {
+- memcpy(buf, dstart, *dstart);
+- buf[2] = 1;
++ if (wi->dl_device == DATALINK_50) {
++ 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]++;
++ } else {
++ memcpy(buf, dstart, *dstart);
++ buf[2] = 1;
++ }
++
+ dl_docrc(buf);
+
+ if (write(ofd, buf, *buf) != *buf)
+ return ((*dl_error_proc)
+ ("Can't write dstart to tmp file."));
+
+- memcpy(buf, dinfo, *dinfo);
+- buf[2] = 1;
+- buf[3] = dl_download_data.memory / (MAX_PCKT - 6);
+
+- if (dl_download_data.memory % (MAX_PCKT - 6))
+- buf[3]++;
++ if (wi->dl_device == DATALINK_50) {
++ pnum=1;
+
+- buf[12] = dl_download_data.num_apps;
+- buf[13] = dl_download_data.num_todos;
+- buf[14] = dl_download_data.num_phones;
+- buf[15] = dl_download_data.num_annivs;
+- buf[4] = (addr >> 8) & 0xff;
+- buf[5] = addr & 0xff;
+- addr += dl_download_data.app_size;
+- buf[6] = (addr >> 8) & 0xff;
+- buf[7] = addr & 0xff;
+- addr += dl_download_data.todo_size;
+- buf[8] = (addr >> 8) & 0xff;
+- buf[9] = addr & 0xff;
+- addr += dl_download_data.phone_size;
+- buf[10] = (addr >> 8) & 0xff;
+- buf[11] = addr & 0xff;
+- buf[16] = 0x62;
+- buf[17] = dl_download_data.pre_notification_time / 5;
+- if (!buf[17])
+- buf[17] = 0xff;
+-
+- if (wi->dl_device == DATALINK_70)
+- buf[1] = DATA_70;
++ 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] = year;
++ buf[16] = dl_download_data.pre_notification_time / 5;
++ } else {
++ memcpy(buf, dinfo, *dinfo);
++ buf[2] = 1;
++ buf[3] = dl_download_data.memory / (MAX_PCKT - 6);
++
++ if (dl_download_data.memory % (MAX_PCKT - 6))
++ buf[3]++;
++
++ buf[12] = dl_download_data.num_apps;
++ buf[13] = dl_download_data.num_todos;
++ buf[14] = dl_download_data.num_phones;
++ buf[15] = dl_download_data.num_annivs;
++ buf[4] = (addr >> 8) & 0xff;
++ buf[5] = addr & 0xff;
++ addr += dl_download_data.app_size;
++ buf[6] = (addr >> 8) & 0xff;
++ buf[7] = addr & 0xff;
++ addr += dl_download_data.todo_size;
++ buf[8] = (addr >> 8) & 0xff;
++ buf[9] = addr & 0xff;
++ addr += dl_download_data.phone_size;
++ buf[10] = (addr >> 8) & 0xff;
++ buf[11] = addr & 0xff;
++ buf[16] = 0x62;
++ buf[17] = dl_download_data.pre_notification_time / 5;
++ if (!buf[17])
++ buf[17] = 0xff;
++
++ if (wi->dl_device == DATALINK_70)
++ buf[1] = DATA_70;
++ }
+
+ dl_docrc(buf);
+
+@@ -320,15 +419,26 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ return ((*dl_error_proc)
+ ("Can't write dinfo to tmp file."));
+
+- pnum = 1;
++ if (wi->dl_device == DATALINK_50)
++ pnum = 2;
++ else
++ pnum = 1;
++
+ memcpy(buf, dspace, *dspace);
+
+- if (wi->dl_device == DATALINK_70)
+- buf[1] = DATA_70;
++ if (wi->dl_device == DATALINK_50)
++ buf[0] = 0x3;
+
+- buf[2] = 1;
+- buf[3] = pnum++;
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
++ buf[1] = DATA_70;
+
++ if (wi->dl_device == DATALINK_50) {
++ buf[2] = pnum++;
++ } else {
++ buf[2] = 1;
++ buf[3] = pnum++;
++ }
++
+ for (i = 0; i < dl_download_data.num_apps; i++)
+ {
+ ap = &dl_download_data.apps[i];
+@@ -421,8 +531,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 +676,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;
+@@ -621,6 +743,22 @@ int dl_send_data(WatchInfoPtr wi, int type)
+ return ((*dl_error_proc)
+ ("Can't write to tmp file."));
+
++ /* The 50, enables the alarm by default, and you send this packet to disable it */
++
++ if ((wi->dl_device == DATALINK_50) && (!dl_download_data.alarms[i].audible)) {
++ buf[0] = 0x07;
++ buf[1] = 0x70;
++ buf[2] = 0x00;
++ buf[3] = 0x61 + dl_download_data.alarms[i].alarm_num;
++ buf[4] = 0x00;
++
++ dl_docrc(buf);
++
++ if (write(ofd, buf, *buf) != *buf)
++ return ((*dl_error_proc)
++ ("Can't write to tmp file."));
++ }
++
+ }
+
+ for (i = 0; i < dl_download_data.num_timers; i++)
+@@ -673,7 +811,10 @@ int dl_send_data(WatchInfoPtr wi, int type)
+
+ memcpy(buf, dspace, *dspace);
+
+- if (wi->dl_device == DATALINK_70)
++ if (wi->dl_device == DATALINK_50)
++ buf[0] = 0x3;
++
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ buf[1] = DATA_70;
+
+ pnum = 1;
+@@ -735,7 +876,10 @@ int dl_send_data(WatchInfoPtr wi, int type)
+
+ memcpy(buf, dspace, *dspace);
+
+- if (wi->dl_device == DATALINK_70)
++ if (wi->dl_device == DATALINK_50)
++ buf[0] = 0x3;
++
++ if ((wi->dl_device == DATALINK_50) || (wi->dl_device == DATALINK_70))
+ buf[1] = DATA_70;
+
+ pnum = 1;
+@@ -798,6 +942,7 @@ int dl_send_data(WatchInfoPtr wi, int type)
+
+ close(ofd);
+
++#if 0
+ switch (type)
+ {
+ case BLINK_FILE:
+@@ -892,6 +1037,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..ab98990 100644
+--- a/settime.c
++++ b/settime.c
+@@ -117,6 +117,9 @@ int main( int argc, char ** argv)
+
+ if(argc==2)
+ {
++ if(!strcmp("-model50",argv[1])||!strcmp("-50",argv[1]))
++ wi = dl_init_watch(DATALINK_50);
++ else
+ if(!strcmp("-model70",argv[1])||!strcmp("-70",argv[1]))
+ wi = dl_init_watch(DATALINK_70);
+ else
+@@ -130,7 +133,7 @@ int main( int argc, char ** argv)
+ wi = dl_init_watch(DATALINK_IRONMAN);
+ else
+ {
+- printf("Usage: %s [ -model70 | -70 | -model70 | "
++ printf("Usage: %s [ -model50 | -50 | -70 | -model70 | "
+ "-150 | -model150 | -model150s | -150s |"
+ " -ironman]\nVersion "
+ "$Id: settime.c,v 1.13 2002/07/10 04:23:23 david Exp $\n", argv[0]);
+@@ -151,6 +154,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;
+ }
+diff --git a/setwatch.c b/setwatch.c
+index 93a9364..eee146b 100644
+--- a/setwatch.c
++++ b/setwatch.c
+@@ -120,7 +120,8 @@ void Usage()
+ printf("Usage: datalink [watch type] [options] [datafile]\n");
+ printf
+ ("watchtype (ironman is default, must be specified before other options)\n");
+- printf(" -model70\t use if you have this watch\n");
++ printf(" -50\t use if you have this watch\n");
++ printf(" -model50\t use if you have this watch\n");
+ printf(" -70\t use if you have this watch\n");
+ printf(" -model70\t use if you have this watch\n");
+ printf(" -150\t use if you have this watch\n");
+@@ -199,6 +200,7 @@ void Usage()
+ #define CHRON 0x400
+
+ /* All would be 0x755 */
++#define ALL50 0x07F
+ #define ALL70 0x07F
+ #define ALL150 0x1FF
+ #define ALLIRONMAN 0x653
+@@ -228,6 +230,8 @@ int main(int argc, char **argv)
+
+ if (strcmp("-all", argv[1]) == 0)
+ {
++ if (type == DATALINK_50)
++ flags = ALL50;
+ if (type == DATALINK_70)
+ flags = ALL70;
+ if (type == DATALINK_150 || type == DATALINK_150S)
+@@ -300,6 +304,10 @@ int main(int argc, char **argv)
+ output = BLINK_FILE;
+ else if (strcmp("-serial", argv[1]) == 0)
+ output = SER_BLINK;
++ else if (strcmp("-model50", argv[1]) == 0)
++ type = DATALINK_50;
++ else if (strcmp("-50", argv[1]) == 0)
++ type = DATALINK_50;
+ else if (strcmp("-model70", argv[1]) == 0)
+ type = DATALINK_70;
+ else if (strcmp("-70", argv[1]) == 0)
+diff --git a/svgablink.c b/svgablink.c
+index 185a2ca..3e30461 100644
+--- a/svgablink.c
++++ b/svgablink.c
+@@ -70,10 +70,14 @@ int main(int argc, char **argv)
+ || strcmp(argv[1], "-model70") == 0)
+ type = DATALINK_70;
+ else
++ if (strcmp(argv[1], "-50") == 0
++ || strcmp(argv[1], "-model50") == 0)
++ type = DATALINK_50;
++ else
+ {
+ fprintf(stderr, "Unknown option %s.\n", argv[1]);
+ fprintf(stderr, "Usage: %s [ -ironman | -modelironman | -150 | -model150 | -150s | \n"
+- "\t-model150s | -70 | -model70 ] datafile\n"
++ "\t-model150s | -70 | -model70 | -50 | -model50 ] datafile\n"
+ "Version $Id: svgablink.c,v 1.12 2002/07/10 04:27:08 david Exp $\n", argv[0]);
+ exit(-1);
+ }
diff --git a/master/series b/master/series
new file mode 100644
index 0000000..637727e
--- /dev/null
+++ b/master/series
@@ -0,0 +1,3 @@
+model-50-v2.patch
+#model-50-v1.patch
+#model-50-v2-cumul.patch