Esempio n. 1
0
int main(int argc, char **argv)
{
    int cooked_baud = cook_baud(DefaultBaud);
    char const * serial_dev = DefaultSerialDevice;
    int low_port = -1, high_port = -1;
    int serial_fd, low_listener, high_listener;

    while ( --argc != 0 )
    {
        char *p = argv[argc];
        if ( *(p++) != '-' )
            usage();
        switch (*(p++))
        {
        case 'b':
            if ( (cooked_baud = cook_baud(atoi(p))) == 0 )
            {
                fprintf(stderr, "Bad baud rate\n");
                exit(1);
            }
            break;
        case 'd':
            serial_dev = p;
            break;
        case 'l':
            if ((low_port = atoi(p)) <= 0)
                usage();
            break;
        case 'h':
            if ((high_port = atoi(p)) <= 0)
                usage();
            break;
        default:
            usage();
        }
    }

    if (low_port == -1 && high_port == -1)
        low_port = DefaultLowPort;
    if (low_port == -1)
        low_port = high_port - 1;
    if (high_port == -1)
        high_port = low_port + 1;

    if ((serial_fd = open_serial(serial_dev, cooked_baud)) < 0 ||
        (low_listener = start_listener(low_port)) < 0 ||
        (high_listener = start_listener(high_port)) < 0)
        exit(1);

    main_loop(serial_fd, low_listener, high_listener);

    return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
    int              fd, c, cooked_baud = cook_baud(DEFAULT_BAUDRATE);
    char            *sername = DEFAULT_SERDEVICE;
    struct termios   oldsertio, newsertio, oldstdtio, newstdtio;
    struct sigaction sa;
    static char start_str[] = 
        "************ REMOTE CONSOLE: CTRL-[ TO QUIT ********\r\n";
    static char end_str[] =
        "\n************ REMOTE CONSOLE EXITED *****************\n";

    while ( --argc != 0 )
    {
        char *p = argv[argc];
        if ( *p++ != '-' )
            goto usage;
        if ( *p == 'b' )
        {
            p++;
            if ( (cooked_baud = cook_baud(atoi(p))) == 0 )
            {
                fprintf(stderr, "Bad baud rate '%d'\n", atoi(p));
                goto usage;
            }
        }
        else if ( *p == 'd' )
        {
            sername = ++p;
            if ( *sername == '\0' )
                goto usage;
        }
        else
            goto usage;
    }

    /* Not a controlling tty: CTRL-C shouldn't kill us. */
    fd = open(sername, O_RDWR | O_NOCTTY);
    if ( fd < 0 )
    {
        perror(sername); 
        exit(-1);
    }
 
    tcgetattr(fd, &oldsertio); /* save current modem settings */
 
    /*
     * 8 data, no parity, 1 stop bit. Ignore modem control lines. Enable 
     * receive. Set appropriate baud rate. NO HARDWARE FLOW CONTROL!
     */
    newsertio.c_cflag = cooked_baud | CS8 | CLOCAL | CREAD;

    /* Raw input. Ignore errors and breaks. */
    newsertio.c_iflag = IGNBRK | IGNPAR;

    /* Raw output. */
    newsertio.c_oflag = OPOST;

    /* No echo and no signals. */
    newsertio.c_lflag = 0;
 
    /* blocking read until 1 char arrives */
    newsertio.c_cc[VMIN]=1;
    newsertio.c_cc[VTIME]=0;
 
    /* now clean the modem line and activate the settings for modem */
    tcflush(fd, TCIFLUSH);
    tcsetattr(fd,TCSANOW,&newsertio);
 
    /* next stop echo and buffering for stdin */
    tcgetattr(0,&oldstdtio);
    tcgetattr(0,&newstdtio); /* get working stdtio */
    newstdtio.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
    newstdtio.c_oflag &= ~OPOST;
    newstdtio.c_cflag &= ~(CSIZE | PARENB);
    newstdtio.c_cflag |= CS8;
    newstdtio.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
    newstdtio.c_cc[VMIN]=1;
    newstdtio.c_cc[VTIME]=0;
    tcsetattr(0,TCSANOW,&newstdtio);

    /* Terminal settings done: now enter the main I/O loops. */
    switch ( fork() )
    {
    case 0:
        close(1); /* stdout not needed */
        for ( c = (char)getchar(); c != ENDMINITERM; c = (char)getchar() )
            write(fd,&c,1);
        tcsetattr(fd,TCSANOW,&oldsertio);
        tcsetattr(0,TCSANOW,&oldstdtio);
        close(fd);
        exit(0); /* will send a SIGCHLD to the parent */
        break;
    case -1:
        perror("fork");
        tcsetattr(fd,TCSANOW,&oldsertio);
        close(fd);
        exit(-1);
    default:
        write(1, start_str, strlen(start_str));
        close(0); /* stdin not needed */
        sa.sa_handler = child_handler;
        sa.sa_flags = 0;
        sigaction(SIGCHLD,&sa,NULL); /* handle dying child */
        while ( !stop )
        {
            read(fd,&c,1); /* modem */
            c = (char)c;
            write(1,&c,1); /* stdout */
        }
        wait(NULL); /* wait for child to die or it will become a zombie */
        write(1, end_str, strlen(end_str));
        break;
    }

    return 0;

 usage:
    printf("miniterm [-b<baudrate>] [-d<devicename>]\n");
    printf("Default baud rate: %d\n", DEFAULT_BAUDRATE);
    printf("Default device: %s\n", DEFAULT_SERDEVICE);
    return 1;
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	pthread_t threads[3];
	void *res;
    int fd, gto, c, cooked_baud;
	int bc=0, rs=0, cycle;
	double t,t0,t1;
	double decl=0, ra=0;
	int hh, mm, ss;
	char sg;
    char *gtoname = DEFAULT_GTODEVICE;
	char *tmpi;
	char lrfmt[]="%02d:%02d:%02d";
	char ldfmt[]="%c%02d*%02d:%02d";

    struct termios   oldsertio, newsertio, oldgtotio, newgtotio;

    while ( --argc != 0 )
    {
        char *p = argv[argc];
        if ( *p++ != '-' )
            goto usage;
        if ( *p == 'b' )
        {
            p++;
            if ( (cooked_baud = cook_baud(atoi(p))) == 0 )
            {
                fprintf(stderr, "Bad baud rate '%d'\n", atoi(p));
                goto usage;
            }
        }
        else if ( *p == 'd' )
        {
            tmpi = ++p;
            if ( *tmpi == '\0' )
                goto usage;
			sscanf(tmpi, ldfmt, &sg, &hh, &mm, &ss);
			decl=(sg=='+'?1:-1)*decimal_hours(hh,mm,ss);
			printf("DECL %lf %d %d %d\n", decl, hh,mm,ss);
        }
        else if ( *p == 'R' )
        {
            tmpi = ++p;
            if ( *tmpi == '\0' )
                goto usage;
			sscanf(tmpi, lrfmt, &hh, &mm, &ss);
			ra=decimal_hours(hh,mm,ss);
			printf("RA %lf %d %d %d\n", ra, hh,mm,ss);
        }
        else if ( *p == 'D' )
        {
            gtoname = ++p;
            if ( *gtoname == '\0' )
                goto usage;
        }
		else if ( *p == 'r' )
		{
			rs=1;
		}
        else
            goto usage;
    }

    gto = open(gtoname, O_RDWR | O_NOCTTY);
    if ( gto < 0 )
    {
        perror(gtoname); 
        exit(-1);
    }
 
 	cooked_baud=cook_baud(DEFAULT_BAUDRATE);
    tcgetattr(gto,&oldgtotio);
    newgtotio.c_iflag = IGNBRK | IGNPAR;
    newgtotio.c_oflag = OPOST;
    newgtotio.c_cflag = cooked_baud | CS8 | CLOCAL | CREAD;
    newgtotio.c_lflag = 0;
    newgtotio.c_cc[VMIN]=0;
    newgtotio.c_cc[VTIME]=8;
    tcflush(gto, TCIFLUSH);
    tcsetattr(gto,TCSANOW,&newgtotio);
	
	mmp_fd=gto;
	GTOCP3_init_f("gto.conf", rs);

	gto_m.dst[GTO_RA]=ra;
	gto_m.dst[GTO_DECL]=decl;
	gto_m.RDrun=1;
	printf("GOTO RD: %.4lf %.4lf\n", ra, decl);
	gto_track();
    return 0;

 usage:
    printf("miniterm -d+HH*MM:SS -RHH:MM:SS [-b<baudrate>] [-D<devicename>]\n");
    printf("Default baud rate: %d\n", DEFAULT_BAUDRATE);
    printf("Default device: %s\n", DEFAULT_GTODEVICE);
	printf("-r: set position\n");
	printf("-d: set decl\n");
	printf("-R: set RA\n");
    return 1;
}
Esempio n. 4
0
File: gg.c Progetto: choupi/astroMP
int main(int argc, char **argv)
{
	pthread_t threads;
    int fd, gto, c, cooked_baud;
	int bc=0, rs=0, cycle;
	double t, t0,t1;
    char *sername = DEFAULT_SERDEVICE;
    char *gtoname = DEFAULT_GTODEVICE;
    struct termios   oldsertio, newsertio, oldgtotio, newgtotio;
    struct sigaction sa;
    static char start_str[] = 
        "************ REMOTE CONSOLE: CTRL-[ TO QUIT ********\r\n";
    static char end_str[] =
        "\n************ REMOTE CONSOLE EXITED *****************\n";
	char op[] = "PK02003E\n\r";
	char buf[100];

    while ( --argc != 0 )
    {
        char *p = argv[argc];
        if ( *p++ != '-' )
            goto usage;
        if ( *p == 'b' )
        {
            p++;
            if ( (cooked_baud = cook_baud(atoi(p))) == 0 )
            {
                fprintf(stderr, "Bad baud rate '%d'\n", atoi(p));
                goto usage;
            }
        }
        else if ( *p == 'd' )
        {
            sername = ++p;
            if ( *sername == '\0' )
                goto usage;
        }
		
        else if ( *p == 'D' )
        {
            gtoname = ++p;
            if ( *gtoname == '\0' )
                goto usage;
        }
		else if ( *p == 'g' )
		{
			bc=0;
		}
		else if ( *p == 'r' )
		{
			rs=1;
		}
        else
            goto usage;
    }

    gto = open(gtoname, O_RDWR | O_NOCTTY);
    if ( gto < 0 )
    {
        perror(gtoname); 
        exit(-1);
    }
 
 	cooked_baud=cook_baud(DEFAULT_BAUDRATE);
    tcgetattr(gto,&oldgtotio);
    newgtotio.c_iflag = IGNBRK | IGNPAR;
    newgtotio.c_oflag = OPOST;
    newgtotio.c_cflag = cooked_baud | CS8 | CLOCAL | CREAD;
    newgtotio.c_lflag = 0;
    newgtotio.c_cc[VMIN]=0;
    newgtotio.c_cc[VTIME]=8;
    tcflush(gto, TCIFLUSH);
    tcsetattr(gto,TCSANOW,&newgtotio);

	
	mmp_fd=gto;
	GTOCP3_init(TW_LAT, TW_LONGTD, M_RATE0, M_RATE1);
	GTOCP3_init_f("gto.conf", rs);

	if(bc) {
    fd = open(sername, O_RDWR | O_NOCTTY);
    if ( fd < 0 )
    {
        perror(sername); 
        exit(-1);
    }
 	cooked_baud=cook_baud(DEFAULT_SBAUDRATE);
    tcgetattr(fd, &oldsertio); 
    newsertio.c_cflag = cooked_baud | CS8 | CLOCAL | CREAD;
    newsertio.c_iflag = IGNBRK | IGNPAR;
    newsertio.c_oflag = OPOST;
    newsertio.c_lflag = 0;
    newsertio.c_cc[VMIN]=1;
    newsertio.c_cc[VTIME]=0;
    tcflush(fd, TCIFLUSH);
    tcsetattr(fd,TCSANOW,&newsertio);
 
	pthread_create(&threads, NULL, child_thread, (void*)fd);
	}

			printf("alt: "); scanf("%lf", &t0);
			printf("azm: "); scanf("%lf", &t1);
			gto_goto_aa(t0,t1);
		do {
			gto_update();
		/*
		bc=read(gto,buf,50);
		if(bc>0) write(1, buf, bc);
		printf("****\n"); fflush(stdout);
		MMPGetTime(&cycle);
		printf("%d# ", cycle);
		MMPGetProfileMode(0,&cycle);
		printf("%d$ ",cycle);
		MMPGetPosition(0,&cycle);
		printf("%d@ ",cycle);
		MMPGetAcceleration(0,&cycle);
		printf("%.2f/",cycle/65536.0);
		MMPGetDeceleration(0,&cycle);
		printf("%.2f\n",cycle/65536.0);
		MMPSetActualPosition(0, 100);
		MMPGetActualPosition(0, &cycle);
		printf("%d@\n",cycle);
		*/
		} while(!usleep(1500000));
	
    return 0;

 usage:
    printf("miniterm [-b<baudrate>] [-d<devicename>]\n");
    printf("Default baud rate: %d\n", DEFAULT_BAUDRATE);
    printf("Default device: %s\n", DEFAULT_SERDEVICE);
    return 1;
}