Skip to content
Snippets Groups Projects
Commit 52a2e59c authored by rswindell's avatar rswindell
Browse files

Using lprintf (log print) callback for error messages from xmodem module.

Increased highwater mark to 1100 (x/ymodem packets are slightly larger than 1k)
this may be the cause of occasional "short packets" reported by receiver.
parent 204b8d8a
No related branches found
No related tags found
No related merge requests found
......@@ -124,22 +124,38 @@ static BOOL winsock_startup(void)
#endif
/********/
/* Code */
/********/
void newline(void)
{
fprintf(statfp,"\n");
}
int lprintf(int level, char *fmt, ...)
{
va_list argptr;
int retval;
FILE* fp=statfp;
if(level<LOG_NOTICE)
fp=errfp;
va_start(argptr,fmt);
retval = vfprintf(fp,fmt,argptr);
va_end(argptr);
return(retval);
}
/**************/
/* Exit Point */
/**************/
void bail(int code)
{
fprintf(statfp,"Terminating\n");
YIELD();
#if !SINGLE_THREADED
lprintf(LOG_DEBUG,"Waiting for output buffer to empty...");
WaitForSingleObject(outbuf_empty,5000);
lprintf(LOG_DEBUG,"\n");
#endif
terminate=TRUE;
// sem_post(outbuf.sem);
// sem_post(outbuf.highwater_sem);
......@@ -1279,7 +1295,7 @@ int main(int argc, char **argv)
RingBufInit(&inbuf, IO_THREAD_BUF_SIZE);
RingBufInit(&outbuf, IO_THREAD_BUF_SIZE);
outbuf.highwater_mark=1024;
outbuf.highwater_mark=1100;
outbuf_empty=CreateEvent(NULL,FALSE,TRUE,NULL);
#if 0
......@@ -1480,8 +1496,6 @@ int main(int argc, char **argv)
xm.sock=sock;
xm.mode=&mode;
xm.errfp=errfp;
xm.statfp=statfp;
zm.sock=sock;
zm.mode=&mode;
......
......@@ -41,7 +41,7 @@
#define getcom(t) recv_byte(xm->sock,t,*xm->mode)
#define putcom(ch) send_byte(xm->sock,ch,10,*xm->mode)
#define newline() fprintf(xm->statfp,"\n");
#define newline()
void xmodem_put_nak(xmodem_t* xm)
{
......@@ -97,15 +97,15 @@ int xmodem_get_block(xmodem_t* xm, uchar* block, BOOL hdrblock)
newline();
if(!can) { /* must get two CANs in a row */
can=1;
fprintf(xm->statfp,"Received CAN Expected SOH, STX, or EOT\n");
xm->lprintf(LOG_WARNING,"Received CAN Expected SOH, STX, or EOT\n");
continue;
}
fprintf(xm->statfp,"Cancelled remotely\n");
xm->lprintf(LOG_WARNING,"Cancelled remotely\n");
bail(-1);
break;
default:
newline();
fprintf(xm->statfp,"Received %s Expected SOH, STX, or EOT\n",chr((uchar)i));
xm->lprintf(LOG_WARNING,"Received %s Expected SOH, STX, or EOT\n",chr((uchar)i));
case NOINP: /* Nothing came in */
if(hdrblock || (*xm->mode)&GMODE)
return(-1);
......@@ -129,7 +129,7 @@ int xmodem_get_block(xmodem_t* xm, uchar* block, BOOL hdrblock)
}
if(block_num!=(uchar)~i) {
newline();
fprintf(xm->statfp,"Block number error\n");
xm->lprintf(LOG_ERR,"Block number error\n");
if(hdrblock || (*xm->mode)&GMODE)
return(-1);
xmodem_put_nak(xm);
......@@ -165,14 +165,14 @@ int xmodem_get_block(xmodem_t* xm, uchar* block, BOOL hdrblock)
if(crc==calc_crc)
break;
newline();
fprintf(xm->statfp,"CRC error\n");
xm->lprintf(LOG_ERR,"CRC error\n");
}
else /* CHKSUM */
{
if(chksum==calc_chksum)
break;
newline();
fprintf(xm->statfp,"Checksum error\n");
xm->lprintf(LOG_ERR,"Checksum error\n");
}
if((*xm->mode)&GMODE) /* Don't bother sending a NAK. He's not listening */
......@@ -183,7 +183,7 @@ int xmodem_get_block(xmodem_t* xm, uchar* block, BOOL hdrblock)
if(errors>=MAXERRORS) {
newline();
fprintf(xm->statfp,"Too many errors\n");
xm->lprintf(LOG_ERR,"Too many errors\n");
return(-1);
}
return(block_num);
......@@ -238,7 +238,7 @@ int xmodem_get_ack(xmodem_t* xm, int tries)
YIELD();
if(getcom(0)==CAN) {
newline();
fprintf(xm->statfp,"Cancelled remotely\n");
xm->lprintf(LOG_WARNING,"Cancelled remotely\n");
xmodem_cancel(xm);
bail(1);
}
......@@ -253,7 +253,7 @@ int xmodem_get_ack(xmodem_t* xm, int tries)
if(i==CAN) {
if(can) {
newline();
fprintf(xm->statfp,"Cancelled remotely\n");
xm->lprintf(LOG_WARNING,"Cancelled remotely\n");
xmodem_cancel(xm);
bail(1);
}
......@@ -261,7 +261,7 @@ int xmodem_get_ack(xmodem_t* xm, int tries)
}
if(i!=NOINP) {
newline();
fprintf(xm->statfp,"Received %s Expected ACK\n",chr((uchar)i));
xm->lprintf(LOG_WARNING,"Received %s Expected ACK\n",chr((uchar)i));
if(i!=CAN)
return(0);
}
......
......@@ -46,11 +46,10 @@ typedef struct {
SOCKET sock; /* socket descriptor */
long* mode;
FILE* statfp;
FILE* errfp;
unsigned block_size;
unsigned ack_timeout;
unsigned byte_timeout;
int (*lprintf)(int level, char *fmt, ...);
} xmodem_t;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment