view frbl/test/main.c @ 406:1a852266ba74

tfo moved to gsm-net-reveng repository
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 24 May 2024 21:19:59 +0000
parents cefa700d1b8f
children
line wrap: on
line source

#include <sys/types.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <termios.h>
#include <unistd.h>
#include "srecreader.h"

char *target_ttydev;
int target_fd;
int baudrate_code;
struct termios target_termios;
struct srecreader srimage;

main(argc, argv)
	char **argv;
{
	if (argc != 4) {
		fprintf(stderr, "usage: %s ttyport baud image.srec\n", argv[0]);
		exit(1);
	}
	target_ttydev = argv[1];
	if (!strcmp(argv[2], "115200"))
		baudrate_code = B115200;
	else if (!strcmp(argv[2], "230400"))
		baudrate_code = B230400;
	else {
		fprintf(stderr,
			"error: baud rate argument must be 115200 or 230400\n");
		exit(1);
	}
	srimage.filename = argv[3];

	target_fd = open(target_ttydev, O_RDWR|O_NONBLOCK);
	if (target_fd < 0) {
		perror(target_ttydev);
		exit(1);
	}
	ioctl(target_fd, TIOCEXCL);
	target_termios.c_iflag = IGNBRK;
	target_termios.c_oflag = 0;
	target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8;
	target_termios.c_lflag = 0;
	target_termios.c_cc[VMIN] = 1;
	target_termios.c_cc[VTIME] = 0;
	cfsetispeed(&target_termios, baudrate_code);
	cfsetospeed(&target_termios, baudrate_code);
	if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
		perror("tcsetattr");
		exit(1);
	}
	frbl_test_main();
	tty_passthru();
	exit(0);
}