//	ld-c103test1.c	gg630504 hg9ieg linux.ubuntu.gcc utf-8
//	2021-01-24
// $ sudo usermod -a -G dialout $USER
// $ sudo apt-get update
// $ sudo apt-get install gcc
// $ sudo apt-get install make

#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <time.h>
#include <unistd.h>

#define td	10	// mérési idő, másodperc

int		main()
{
int		fdKey;
unsigned int	bwModem = TIOCM_RTS;
time_t		tStart;
time_t		tAct;
time_t		tLim;
int		c;

fprintf( stdout, "gg630504.hg9ieg/ld-c103test1/" __DATE__ " " __TIME__ "\n" );
if( (fdKey = open( "/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY ))>=0 )
	{
	ioctl( fdKey, TIOCMBIC, &bwModem );	// szünet, space
	c = 0;

	time( &tStart );
	time( &tAct );
	while( tAct==tStart )	// másodperc váltásra vár
		time( &tAct );

	tLim = tAct+td;
	time( &tAct );
	while( tAct!=tLim )
		{
		ioctl( fdKey, TIOCMBIS, &bwModem );	// jel, mark
		ioctl( fdKey, TIOCMBIC, &bwModem );	// szünet, space
		ioctl( fdKey, TIOCMBIS, &bwModem );
		ioctl( fdKey, TIOCMBIC, &bwModem );
		ioctl( fdKey, TIOCMBIS, &bwModem );
		ioctl( fdKey, TIOCMBIC, &bwModem );
		ioctl( fdKey, TIOCMBIS, &bwModem );
		ioctl( fdKey, TIOCMBIC, &bwModem );
		ioctl( fdKey, TIOCMBIS, &bwModem );
		ioctl( fdKey, TIOCMBIC, &bwModem );
		c += 10;
		time( &tAct );
		}

	close( fdKey );
	fprintf( stdout, "t = %f μs, f = %f kHz\n", 1.0e6*td/c, 0.5e-3*c/td );
	}
return( 0 );
}

