14 int send(uchar*, int);
15 int notifyf(void*, char*);
17 int debug, progress, onek;
20 errorout(int ctl, int bytes)
26 fprint(2, "\nxms: gave up after %d bytes\n", bytes);
27 write(ctl, "rawoff", 6);
32 updcrc(int c, ushort crc)
36 for (count=8; --count>=0;) {
39 crc += (((c<<=1) & 0400) != 0);
44 crc += (((c<<=1) & 0400) != 0);
51 main(int argc, char **argv)
76 fprint(2, "usage: xms filename\n");
79 fd = open(argv[0], OREAD);
85 ctl = open("/dev/consctl", OWRITE);
90 write(ctl, "rawon", 5);
92 /* give the other side a 30 seconds to signal ready */
97 if(read(0, &c, 1) != 1){
98 fprint(2, "xms: timeout\n");
106 fprint(2, "crc mode engaged\n");
113 /* send the file in 128/1024 byte chunks */
114 for(bytes = 0, seqno = 1; ; bytes += n, seqno++){
115 n = read(fd, buf+3, onek ? 1024 : 128);
120 if(n < (onek ? 1024 : 128))
121 memset(&buf[n+3], 0, (onek ? 1024 : 128)-n);
122 buf[0] = onek ? Stx : Soh;
124 buf[2] = 255 - seqno;
126 /* calculate checksum and stuff into last byte */
130 for(p = buf + 3; p < &buf[(onek ? 1024 : 128)+3]; p++)
131 crc = updcrc(*p, crc);
132 crc = updcrc(0, crc);
133 crc = updcrc(0, crc);
134 buf[(onek ? 1024 : 128) + 3] = crc >> 8;
135 buf[(onek ? 1024 : 128) + 4] = crc;
139 for(p = buf + 3; p < &buf[(onek ? 1024 : 128)+3]; p++)
141 buf[(onek ? 1024 : 128) + 3] = sum;
144 if(send(buf, (onek ? 1024 : 128) + 4 + crcmode) < 0)
145 errorout(ctl, bytes);
146 if (progress && bytes % 10240 == 0)
147 fprint(2, "%dK\n", bytes / 1024);
150 /* tell other side we're done */
153 errorout(ctl, bytes);
155 fprint(2, "xms: %d bytes transmitted\n", bytes);
156 write(ctl, "rawoff", 6);
161 * send a message till it's acked or we give up
164 send(uchar *buf, int len)
170 for(tries = 0;; tries++, sleep(2*1000)){
173 if(write(1, buf, len) != len)
193 fprint(2, "\nremote Cancel\n");
199 fprint(2, " \\0%o", c);
202 if(n == 1 && c == Ack)
209 notifyf(void *a, char *msg)
212 if(strcmp(msg, "alarm") == 0)