⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zmtx-new.c

📁 这是G.723和G.729的音频编解码的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	if (c > '9') {		if (c < 'a' || c > 'f') {			/*			 * illegal hex; different than expected.			 * we might as well time out.			 */			return TIMEOUT;		}		c -= 'a' - 10;	}	else {		if (c < '0') {			/*			 * illegal hex; different than expected.			 * we might as well time out.			 */			return TIMEOUT;		}		c -= '0';	}	return c;}intrx_hex(int to){	int n1;	int n0;	n1 = rx_nibble(to);	if (n1 == TIMEOUT) {		return n1;	}	n0 = rx_nibble(to);	if (n0 == TIMEOUT) {		return n0;	}	return (n1 << 4) | n0;}/* * receive routines for each of the six different styles of header. * each of these leaves rxd_header_len set to 0 if the end result is * not a valid header. */voidrx_bin16_header(int to){	int c;	int n;	unsigned short int crc;	unsigned short int rxd_crc;#ifdef DEBUG	fprintf(stderr,"rx binary header 16 bits crc\n");#endif	crc = 0;	for (n=0;n<5;n++) {		c = rx(to);		if (c == TIMEOUT) {#ifdef DEBUG			fprintf(stderr,"timeout\n");#endif			return;		}		crc = UPDCRC16(c,crc);		rxd_header[n] = c;	}	crc = UPDCRC16(0,crc);	crc = UPDCRC16(0,crc);	rxd_crc  = rx(1000) << 8;	rxd_crc |= rx(1000);	if (rxd_crc != crc) {#ifdef DEBUG		fprintf(stderr,"bad crc %4.4x %4.4x\n",rxd_crc,crc);#endif		return;	}	rxd_header_len = 5;}voidrx_hex_header(int to){	int c;	int i;	unsigned short int crc = 0;	unsigned short int rxd_crc;#ifdef DEBUG	fprintf(stderr,"rx_hex_header : ");#endif	for (i=0;i<5;i++) {		c = rx_hex(to);		if (c == TIMEOUT) {			return;		}		crc = UPDCRC16(c,crc);		rxd_header[i] = c;	}	crc = UPDCRC16(0,crc);	crc = UPDCRC16(0,crc);	/*	 * receive the crc	 */	c = rx_hex(to);	if (c == TIMEOUT) {		return;	}	rxd_crc = c << 8;	c = rx_hex(to);	if (c == TIMEOUT) {		return;	}	rxd_crc |= c;	if (rxd_crc == crc) {		rxd_header_len = 5;	}#ifdef DEBUG	else {		fprintf(stderr,"bad crc.\n");	}#endif	/*	 * drop the end of line sequence after a hex header	 */	c = rx(to);	if (c == CR) {		/*		 * both are expected with CR		 */		c = rx(to);	}}voidrx_bin32_header(int to){	int c;	int n;	unsigned long crc;	unsigned long rxd_crc;#ifdef DEBUG	fprintf(stderr,"rx binary header 32 bits crc\n");#endif	crc = 0xffffffffL;	for (n=0;n<5;n++) {		c = rx(1000);		if (c == TIMEOUT) {			return;		}		crc = UPDCRC32(c,crc);		rxd_header[n] = c;	}	crc = ~crc;	rxd_crc  = rx(1000);	rxd_crc |= rx(1000) << 8;	rxd_crc |= rx(1000) << 16;	rxd_crc |= rx(1000) << 24;	if (rxd_crc != crc) {		return;	}	rxd_header_len = 5;}/* * receive any style header * if the errors flag is set than whenever an invalid header packet is * received INVHDR will be returned. otherwise we wait for a good header * also; a flag (receive_32_bit_data) will be set to indicate whether data * packets following this header will have 16 or 32 bit data attached. * variable headers are not implemented. */intrx_header_raw(int to,int errors){	int c;#ifdef DEBUG	fprintf(stderr,"rx header : ");#endif	rxd_header_len = 0;	do {		do {			c = rx_raw(to);			if (c == TIMEOUT) {				return c;			}		} while (c != ZPAD);		c = rx_raw(to);		if (c == TIMEOUT) {			return c;		}		if (c == ZPAD) {			c = rx_raw(to);			if (c == TIMEOUT) {				return c;			}		}		/*		 * spurious ZPAD check		 */		if (c != ZDLE) {#ifdef DEBUG			fprintf(stderr,"expected ZDLE; got %c\n",c);#endif			continue;		}		/*		 * now read the header style		 */		c = rx(to);		if (c == TIMEOUT) {			return c;		}#ifdef DEBUG		fprintf(stderr,"\n");#endif		switch (c) {			case ZBIN:				rx_bin16_header(to);				receive_32_bit_data = FALSE;				break;			case ZHEX:				rx_hex_header(to);				receive_32_bit_data = FALSE;				break;			case ZBIN32:				rx_bin32_header(to);				receive_32_bit_data = TRUE;				break;			default:				/*				 * unrecognized header style				 */#ifdef DEBUG				fprintf(stderr,"unrecognized header style %c\n",c);#endif				if (errors) {					return INVHDR;				}				continue;				break;		}		if (errors && rxd_header_len == 0) {			return INVHDR;		}	} while (rxd_header_len == 0);	/* 	 * this appears to have been a valid header.	 * return its type.	 */	if (rxd_header[0] == ZDATA) {		ack_file_pos = rxd_header[ZP0] | (rxd_header[ZP1] << 8) |			(rxd_header[ZP2] << 16) | (rxd_header[ZP3] << 24);	}	if (rxd_header[0] == ZFILE) {		ack_file_pos = 0l;	}#ifdef DEBUG	fprintf(stderr,"type %d\n",rxd_header[0]);#endif	return rxd_header[0];}intrx_header(int timeout){	return rx_header_raw(timeout,FALSE);}intrx_header_and_check(int timeout){	int type;	while (TRUE) {		type = rx_header_raw(timeout,TRUE);				if (type != INVHDR) {			break;		}		tx_znak();	}	return type;}//END_OF_zmdm.c//if test 19033 -ne `wc -c <zmdm.c`; then//    echo shar: \"zmdm.c\" unpacked with wrong size!//fi//# end of overwriting check//fi//if test -f zmdm.h -a "${1}" != "-c" ; then // echo shar: Will not over-write existing file \"zmdm.h\"//else//echo shar: Extracting \"zmdm.h\" \(1801 characters\)//sed "s/^X//" >zmdm.h <<'END_OF_zmdm.h'/* * zmdm.h * zmodem primitives prototypes and global data * (C) Mattheij Computer Service 1994*/#ifndef _ZMDM_H#define _ZMDM_H#ifdef ZMDM#define EXTERN#else#define EXTERN extern#endif#include <errno.h>#define TRUE  1#define FALSE 0#define ENDOFFRAME 2#define FRAMEOK    1#define TIMEOUT   -1											/* rx routine did not receive a character within timeout */#define INVHDR    -2											/* invalid header received; but within timeout */#define INVDATA   -3											/* invalid data subpacket received */#define ZDLEESC 0x8000											/* one of ZCRCE; ZCRCG; ZCRCQ or ZCRCW was received; ZDLE escaped */#define HDRLEN     5											/* size of a zmodme header */EXTERN int in_fp;												/* input file descriptor */EXTERN int out_fp;												/* output file descriptor */EXTERN unsigned char rxd_header[ZMAXHLEN];						/* last received header */EXTERN int rxd_header_len;										/* last received header size *//* * receiver capability flags * extracted from the ZRINIT frame as received */EXTERN int can_full_duplex;EXTERN int can_overlap_io;EXTERN int can_break;EXTERN int can_fcs_32;EXTERN int escape_all_control_characters;						/* guess */EXTERN int escape_8th_bit;EXTERN int use_variable_headers;								/* use variable length headers *//* * file management options. * only one should be on */EXTERN int management_newer;EXTERN int management_clobber;EXTERN int management_protect;voidfd_init(void);													/* make the io channel raw */voidfd_exit(void);													/* reset io channel to state before zmtx was called */voidtx_hheader(unsigned char * buf,int n);voidtx_bheader(unsigned char * buf,int n);intrx_header(int to);												/* receive any header with timeout in milliseconds */#endif//END_OF_zmdm.h//if test 1801 -ne `wc -c <zmdm.h`; then//    echo shar: \"zmdm.h\" unpacked with wrong size!//fi//# end of overwriting check//fi//if test -f zmodem.doc -a "${1}" != "-c" ; then //  echo shar: Will not over-write existing file \"zmodem.doc\"//else//echo shar: Extracting \"zmodem.doc\" \(37474 characters\)//sed "s/^X//" >zmodem.doc <<'END_OF_zmodem.doc'//Xzmodem.doc !copyrighted by MCS 1994 use it anyway you like but don't complain////Xthis file should be accompanied by a readme which contains some background//Xinformation on implementing zmodem.//X//XGENERAL//X-------//X//Documentation about the zmodem protocol internals; should be sufficient//to implement a completely functional zmodem protocol suite.//X	//X	Zmodem is a file transfer protocol that attempts to maximize bandwidth//	and minimize transfer times. it is a unidirectional protocol; i.e. the//	return channel only transfers control information; no data. either side//	may initiate the transfer; but the downloading site may respond to //	an initialization frame by auto starting the download software.	//	Schematically a zmodem file transfer in progress looks like this://             |----------<< back channel <<-------------|//     ------+-------                          --------+------//       |   Sender   |                          |   Receiver  |//       |  (upload)  |                          |  (download) |//       --------------                          --------+------//           |---------->> data channel >>-------------|

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -