Added more ymodem upload code

This commit is contained in:
Michiel Broek 2004-11-23 21:40:30 +00:00
parent e3a13e9126
commit 51e402ef71
3 changed files with 67 additions and 11 deletions

View File

@ -33,6 +33,7 @@
#include "../lib/mbse.h" #include "../lib/mbse.h"
#include "ttyio.h" #include "ttyio.h"
#include "zmmisc.h" #include "zmmisc.h"
#include "zmrecv.h"
#include "ymrecv.h" #include "ymrecv.h"
@ -41,8 +42,11 @@ static int Firstsec;
static int eof_seen; static int eof_seen;
static int errors; static int errors;
extern long Bytesleft;
extern int Crcflg; extern int Crcflg;
extern char Lastrx; extern char Lastrx;
extern char *secbuf;
#define sendline(c) PUTCHAR((c) & 0377) #define sendline(c) PUTCHAR((c) & 0377)
@ -54,18 +58,19 @@ int wcrxpn(char *rpn)
size_t Blklen = 0; /* record length of received packets */ size_t Blklen = 0; /* record length of received packets */
purgeline(0); purgeline(0);
Syslog('x', "%s: wcrxpn()", protname());
et_tu: et_tu:
Firstsec = TRUE; Firstsec = TRUE;
eof_seen = FALSE; eof_seen = FALSE;
sendline(Crcflg?WANTCRC:NAK); sendline(Crcflg?WANTCRC:NAK);
fflush(stdout); ioctl(1, TCFLSH, 0);
purgeline(0); /* Do read next time ... */ purgeline(0); /* Do read next time ... */
while ((c = wcgetsec(&Blklen, rpn, 100)) != 0) { while ((c = wcgetsec(&Blklen, rpn, 10)) != 0) {
if (c == WCEOT) { if (c == WCEOT) {
Syslog('x', "Pathname fetch returned EOT"); Syslog('x', "Pathname fetch returned EOT");
sendline(ACK); sendline(ACK);
fflush(stdout); ioctl(1, TCFLSH, 0);
purgeline(0); /* Do read next time ... */ purgeline(0); /* Do read next time ... */
GETCHAR(1); GETCHAR(1);
goto et_tu; goto et_tu;
@ -73,7 +78,7 @@ et_tu:
return ERROR; return ERROR;
} }
sendline(ACK); sendline(ACK);
fflush(stdout); ioctl(1, TCFLSH, 0);
return OK; return OK;
} }
@ -81,9 +86,56 @@ et_tu:
int wcrx(void) int wcrx(void)
{ {
register int sectnum, sectcurr;
register char sendchar;
size_t Blklen;
long bytes_received = 0;
Firstsec = TRUE; sectnum = 0;
eof_seen = FALSE;
sendchar = Crcflg ? WANTCRC:NAK;
Syslog('x', "%s: wcrx", protname());
for (;;) {
sendline(sendchar); /* send it now, we're ready! */
ioctl(1, TCFLSH, 0);
purgeline(0); /* Do read next time ... */
sectcurr = wcgetsec(&Blklen, secbuf, (unsigned int) ((sectnum & 0177) ? 5 : 13));
Syslog('x', "%s: got sector %d", sectcurr);
if (sectcurr == ((sectnum+1) &0377)) {
sectnum++;
/* if using xmodem we don't know how long a file is */
if (Bytesleft && (Bytesleft - bytes_received) < Blklen)
Blklen = Bytesleft - bytes_received;
bytes_received += Blklen;
if (putsec(secbuf, Blklen) == ERROR)
return ERROR;
sendchar = ACK;
}
else if (sectcurr == (sectnum & 0377)) {
Syslog('x', "Received dup Sector");
sendchar = ACK;
} else if (sectcurr == WCEOT) {
if (closeit(1))
return ERROR;
sendline(ACK);
ioctl(1, TCFLSH, 0);
purgeline(0); /* Do read next time ... */
return OK;
}
else if (sectcurr == ERROR)
return ERROR;
else {
Syslog('x', "Sync Error");
return ERROR;
}
}
} }
int wcgetsec(size_t *Blklen, char *rxbuf, unsigned int maxtime) int wcgetsec(size_t *Blklen, char *rxbuf, unsigned int maxtime)
{ {
register int Checksum, wcj, firstch; register int Checksum, wcj, firstch;
@ -91,6 +143,8 @@ int wcgetsec(size_t *Blklen, char *rxbuf, unsigned int maxtime)
register char *p; register char *p;
int sectcurr; int sectcurr;
Syslog('x', "%s: wcgetsec()", protname());
for (Lastrx = errors = 0; errors < RETRYMAX; errors++) { for (Lastrx = errors = 0; errors < RETRYMAX; errors++) {
if ((firstch = GETCHAR(maxtime)) == STX) { if ((firstch = GETCHAR(maxtime)) == STX) {
@ -99,6 +153,7 @@ int wcgetsec(size_t *Blklen, char *rxbuf, unsigned int maxtime)
if (firstch == SOH) { if (firstch == SOH) {
*Blklen=128; *Blklen=128;
get2: get2:
Syslog('x', "%s: wcgetsec blklen %d", protname(), Blklen);
sectcurr = GETCHAR(1); sectcurr = GETCHAR(1);
if ((sectcurr + (oldcrc = GETCHAR(1))) == 0377) { if ((sectcurr + (oldcrc = GETCHAR(1))) == 0377) {
oldcrc = Checksum = 0; oldcrc = Checksum = 0;
@ -156,12 +211,14 @@ humbug:
if (Firstsec) { if (Firstsec) {
sendline(Crcflg ? WANTCRC:NAK); sendline(Crcflg ? WANTCRC:NAK);
fflush(stdout); ioctl(1, TCFLSH, 0);
Syslog('x', "%s: send %s", protname(), Crcflg ? "WANTCRC":"NAK");
purgeline(0); /* Do read next time ... */ purgeline(0); /* Do read next time ... */
} else { } else {
maxtime = 40; maxtime = 40;
sendline(NAK); sendline(NAK);
fflush(stdout); Syslog('x', "%s: send NAK", protname());
ioctl(1, TCFLSH, 0);
purgeline(0); /* Do read next time ... */ purgeline(0); /* Do read next time ... */
} }
} }

View File

@ -52,11 +52,11 @@ struct timeval starttime, endtime;
struct timezone tz; struct timezone tz;
#define DEFBYTL 2000000000L /* default rx file size */ #define DEFBYTL 2000000000L /* default rx file size */
static long Bytesleft; /* number of bytes of incoming file left */ long Bytesleft; /* number of bytes of incoming file left */
static long Modtime; /* Unix style mod time for incoming file */ static long Modtime; /* Unix style mod time for incoming file */
static int Filemode; /* Unix style mode for incoming file */ static int Filemode; /* Unix style mode for incoming file */
static int Thisbinary = TRUE; /* current file is to be received in bin mode */ static int Thisbinary = TRUE; /* current file is to be received in bin mode */
static char *secbuf=0; /* "sector" buffer */ char *secbuf=0; /* "sector" buffer */
static int tryzhdrtype; static int tryzhdrtype;
static char zconv; /* ZMODEM file conversion request */ static char zconv; /* ZMODEM file conversion request */
static char zmanag; /* ZMODEM file management request */ static char zmanag; /* ZMODEM file management request */
@ -66,8 +66,6 @@ static int tryz(void);
static int rzfiles(void); static int rzfiles(void);
static int rzfile(void); static int rzfile(void);
static void zmputs(char*); static void zmputs(char*);
int closeit(int);
static int putsec(char*,int);
static int procheader(char*); static int procheader(char*);
static int ackbibi(void); static int ackbibi(void);
static long getfree(void); static long getfree(void);

View File

@ -4,6 +4,7 @@
/* $Id$ */ /* $Id$ */
int zmrcvfiles(void); int zmrcvfiles(void);
int putsec(char*,int);
int closeit(int);
#endif #endif