[comp.protocols.tcp-ip] Asynchronous Framing Technique Software: TEST1.C

n2dsy@hou2d.UUCP (G.BEATTIE) (04/08/88)

/*
	This is a test program for the AFT system.

            Version 1.0, by John Howell (N2FVN), Copyright August 7, 1987
               
            This software is free for non-commercial use.  All commercial
            rights are retained by the author or his designees.  Commercial 
            use without the explicit written permission of the author is
            prohibited.  This package is provided on an 'as is' basis 
            without warranty.
*/

#include "stdio.h"

main()
{
	char ebdt, c, level, suff_str[10], suff_len;
	char in_str[256], out_str[256];

	int rx_max, in_len, out_len, i, match, tc;

	printf("AFT Test Program 1\n\n");

	printf("Eight-bit data transparency?");
	scanf("%1s",&c);
	ebdt = c == 'y' || c == 'Y';

	printf("Transparency level?");
	scanf("%d",&level);

	printf("Suffix?");
	get_array(suff_str, &suff_len);

	printf("Maximum receive length?");
	scanf("%d",&rx_max);

	aft_options(ebdt, level, suff_len, suff_str, rx_max);

	while (1) {

		printf("Frame to send?");
		get_array(out_str, &out_len);

		if (out_len == 0)
			exit(0);

		aft_tx_start(out_len, out_str);
		aft_rx_start(in_str);

		tc = aft_tx_complete();

		if (tc) {
			printf("ERR: Tx CMPL 1\n");
		}
		
		if (aft_rx_complete()) {
			printf("ERR: Rx CMPL 1\n");
		}
		
		do {

			i = aft_tx_char();

			if (tc != (i == 0x017e)) {
				printf("ERR: Tx CMPL 2\n");
			}
			
			tc = aft_tx_complete();

			if (i != 0x017e) {	
				printf("%4x ",i);

				in_len = aft_rx_char(i & 0x00ff);
				
				if (in_len != aft_rx_complete())
					printf("ERR: Rx CMPL 2\n");
					
				if (in_len != 0)
					printf("RX ");

			}

		} while ((i & 0xff00) == 0);

		printf("TX\n");

		if (!aft_tx_complete()) {
			printf("ERR: Tx CMPL 3\n");
		}
		
		aft_rx_error();
		
		match = 1;
		if (in_len != out_len) {
			printf(" ERR: in_len=%d  out_len=%d\n",
				in_len, out_len);
			match = 0;
		}
		
		for (i = 0; i < out_len; i++)
			if (in_str[i] != out_str[i])
				match = 0;
				
		if (!match) {
			printf(" ERR: RX mismatch\n");
			for (i = 0; i < in_len; i++) 
				printf("%2x ",in_str[i]);
			printf("\n");
		}
	}
}

get_array(buffer, len)
char *buffer;
int *len;
{
	char c;

	c = getc(stdin);
	*len = 0;
	while (1) {
		c = getc(stdin);
		ungetc(c, stdin);

		if (c == '\n')
			return;

		if (!scanf("%2x", buffer++)) 
			return;

		(*len)++;
	}
}