/*********************************************************************/
/* */
/* This Program Written by Paul Edwards, 3:711/934{at}fidonet. */
/* Released to the Public Domain */
/* */
/*********************************************************************/
/*********************************************************************/
/* */
/* reczm - zmodem receive */
/* this program is designed to receive a file using zmodem */
/* */
/*********************************************************************/
#include
#include
#include
#include
#include
#include
#define ZPAD 0x2a
#define ZDLE 0x18
#define ZBIN 0x41
#define ZHEX 0x42
#define ZBIN32 0x43
#define ZRINIT 0x01
#define CANFDX 0x01
#define CANOVIO 0x02
#define ZFILE 0x04
#define ZCRCW 0x6b
#define ZRPOS 0x09
#define ZDATA 0x0a
#define ZCRCG 0x69
#define ZEOF 0x0b
#define ZFIN 0x08
static char hexdigit[] = "0123456789abcdef";
static void receiveZmodem(void);
static void getrz(void);
static void getZRQINIT(void);
static void sendZRINIT(void);
static void getZFILE(void);
static void getFILEINFO(void);
static void sendZRPOS(void);
static void getZDATA(void);
static void getDATA(void);
static void getZEOF(void);
static void getZFIN(void);
static void sendZFIN(void);
static void getOO(void);
static void listen(void);
PDCOMM pdcomm;
int main(void)
{
pdcommInit(&pdcomm);
pdcommOpen(&pdcomm, "COM2", 19200L);
receiveZmodem();
pdcommClose(&pdcomm);
pdcommTerm(&pdcomm);
return (0);
}
static void receiveZmodem(void)
{
getrz();
getZRQINIT();
sendZRINIT();
getZFILE();
getFILEINFO();
sendZRPOS();
getZDATA();
getDATA();
getZEOF();
sendZRINIT();
getZFIN();
sendZFIN();
getOO();
return;
}
static void getrz(void)
{
DosSleep(3000);
listen();
return;
}
static void getZRQINIT(void)
{
DosSleep(3000);
listen();
return;
}
#define ZRINIT_STR "\x2a\x2a\x18\x42" \
"\x30\x31\x30\x30\x30\x30\x30\x30\x30\x33\x39\x61\x33\x32" \
"\x0d\x0a\x11"
static void sendZRINIT(void)
{
printf("sending %s\n", m2x(ZRINIT_STR, sizeof ZRINIT_STR - 1));
pdcommTxBuf(&pdcomm, (unsigned char *)ZRINIT_STR, sizeof ZRINIT_STR - 1);
return;
}
static void getZFILE(void)
{
DosSleep(3000);
listen();
return;
}
static void getFILEINFO(void)
{
DosSleep(3000);
listen();
return;
}
static void sendZRPOS(void)
{
unsigned char buf[500];
int cnt = 0;
crcxm crc;
int x;
buf[cnt++] = ZPAD;
buf[cnt++] = ZPAD;
buf[cnt++] = ZDLE;
buf[cnt++] = ZHEX;
buf[cnt++] = ZRPOS;
buf[cnt++] = 0x00;
buf[cnt++] = 0x00;
buf[cnt++] = 0x00;
buf[cnt++] = 0x00;
crcxm_init(crc);
for (x = 4; x < 9; x++)
{
crcxm_update(crc, buf[x]);
}
cnt = 4;
buf[cnt++] = hexdigit[ZRPOS >> 4];
buf[cnt++] = hexdigit[ZRPOS & 0x0f];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[crcxm_highbyte(crc) >> 4];
buf[cnt++] = hexdigit[crcxm_highbyte(crc) & 0x0f];
buf[cnt++] = hexdigit[crcxm_lowbyte(crc) >> 4];
buf[cnt++] = hexdigit[crcxm_lowbyte(crc) & 0x0f];
/* buf[cnt++] = (unsigned char)crcxm_highbyte(crc);
buf[cnt++] = (unsigned char)crcxm_lowbyte(crc); */
buf[cnt++] = 0x0d;
buf[cnt++] = 0x0a;
buf[cnt++] = 0x11;
printf("sending %s\n", m2x(buf, cnt));
pdcommTxBuf(&pdcomm, buf, cnt);
return;
}
static void getZDATA(void)
{
DosSleep(3000);
listen();
return;
}
static void getDATA(void)
{
DosSleep(3000);
listen();
return;
}
static void getZEOF(void)
{
DosSleep(3000);
listen();
return;
}
static void getZFIN(void)
{
DosSleep(3000);
listen();
return;
}
static void sendZFIN(void)
{
unsigned char buf[500];
int cnt = 0;
crcxm crc;
int x;
buf[cnt++] = ZPAD;
buf[cnt++] = ZPAD;
buf[cnt++] = ZDLE;
buf[cnt++] = ZHEX;
buf[cnt++] = ZFIN;
buf[cnt++] = 0x00;
buf[cnt++] = 0x00;
buf[cnt++] = 0x00;
buf[cnt++] = 0x00;
crcxm_init(crc);
for (x = 4; x < 9; x++)
{
crcxm_update(crc, buf[x]);
}
cnt = 4;
buf[cnt++] = hexdigit[ZFIN >> 4];
buf[cnt++] = hexdigit[ZFIN & 0x0f];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[0];
buf[cnt++] = hexdigit[crcxm_highbyte(crc) >> 4];
buf[cnt++] = hexdigit[crcxm_highbyte(crc) & 0x0f];
buf[cnt++] = hexdigit[crcxm_lowbyte(crc) >> 4];
buf[cnt++] = hexdigit[crcxm_lowbyte(crc) & 0x0f];
/* buf[cnt++] = (unsigned char)crcxm_highbyte(crc);
buf[cnt++] = (unsigned char)crcxm_lowbyte(crc); */
buf[cnt++] = 0x0d;
buf[cnt++] = 0x0a;
buf[cnt++] = 0x11;
printf("sending %s\n", m2x(buf, cnt));
pdcommTxBuf(&pdcomm, buf, cnt);
return;
}
static void getOO(void)
{
DosSleep(3000);
listen();
return;
}
static void listen(void)
{
unsigned char buf[5000];
int cnt;
cnt = pdcommRecBuf(&pdcomm, buf, 5000);
printf("receive %s\n", m2x(buf, cnt));
return;
}
@EOT:
--- Mksmsg
* Origin: none (3:711/934.9)
|