Ejemplo n.º 1
0
void PipelineManager::readPipeline(const std::string& filename)
{
    if (FileUtils::extension(filename) == ".xml")
    {
        PipelineReaderXML pipeReader(*this);
        return pipeReader.readPipeline(filename);
    }
    else if (FileUtils::extension(filename) == ".json")
    {
        PipelineReaderJSON pipeReader(*this);
        return pipeReader.readPipeline(filename);
    }
    else
    {
        Utils::closeFile(m_input);
        m_input = Utils::openFile(filename);
        readPipeline(*m_input);
    }
}
Ejemplo n.º 2
0
void PipelineManager::readPipeline(const std::string& filename)
{
    if (FileUtils::extension(filename) == ".json")
    {
        PipelineReaderJSON pipeReader(*this);
        return pipeReader.readPipeline(filename);
    }
    else
    {
        Utils::closeFile(m_input);
        m_input = Utils::openFile(filename);
        if (!m_input)
            throw pdal_error("Can't open file '" + filename + "' as pipeline "
                "input.");
        try
        {
            readPipeline(*m_input);
        }
        catch (const pdal_error& err)
        {
            throw pdal_error(filename + ": " + err.what());
        }
    }
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
    
    int             maxfd, optret = 1;
    char            *ptr1, *ptr2;
    fd_set          rset;
    
#ifdef HAVE_GETOPT_LONG
    struct option longopts[] = {
        {"bytes",      0, NULL, 'b'},
        {"help",       0, NULL, 'h'},
        {"nolock",     0, NULL, 'n'},
        {"samples",    1, NULL, 's'},
        {"timestamp",  0, NULL, 't'},
        {"verbose",    0, NULL, 'v'},
        {"version",    0, NULL, 'V'},
        {NULL,         0, NULL,   0}
    };
#endif
    /* don't lose last chunk of data when output is non-interactive */
    setvbuf(stdout,NULL,_IONBF,0);
    setvbuf(stderr,NULL,_IONBF,0);

    /* initialize variables */
    tty_data.logfd = STDOUT_FILENO;
    tty_data.portraw = tty_data.nolock = FALSE;
    tty_data.dspbytes = tty_data.tstamp = tty_data.verbose = FALSE;
    tty_data.cstatpipefd[RPIPE] = tty_data.cstatpipefd[WPIPE] = -1;
    tty_data.portpipefd[RPIPE] = tty_data.portpipefd[WPIPE] = -1;
    tty_data.maxSamples = tty_data.numSamples = 0;
    timeStamp   = timestamp_new();
    meterPacket = rs22812_packet_new();
    serialPort  = serport_new();
    serport_set_format(serialPort, F8N1);
    serport_set_speed(serialPort, DEFBAUDRATE);
    /* parse rc-file */
    readRC(&tty_data);
    /* activate signal handlers */
    signal(SIGINT, sigintP);
    signal(SIGCHLD, sigchldP);
    /* register closeAll() function to be called on normal termination */
    /* atexit(closeAll); */
    /* process command line arguments */
#ifdef HAVE_GETOPT_LONG
    while ((optret = getopt_long(argc, argv, OPTSTR, longopts, NULL)) != -1) {
#else
    while ((optret = getopt(argc, argv, OPTSTR)) != -1) {
#endif
        switch (optret) {
            case 'b':
                tty_data.dspbytes = TRUE;
                break;
            case 'n':
                tty_data.nolock = TRUE;
                break;
            case 's':
                tty_data.maxSamples = atoi(optarg);
                break;
            case 't':
                tty_data.tstamp = TRUE;
                break;
            case 'v':
                tty_data.verbose = TRUE;
                break;
            case 'V':
		copyright();
		return 0;
            case 'h':
            case '?':
            default :
                usage();
                return -1;
        }
    }
    if (optind < argc) {
	   if (!(serialPort->device_name = malloc(PORTNAMELEN))) fatalError(MEMFAIL);
	   ptr1 = argv[optind];
	   ptr2 = serialPort->device_name;
	   while((*ptr1 == '/' || isalnum(*ptr1))
                && ptr2 - serialPort->device_name < PORTNAMELEN - 1) *ptr2++ = *ptr1++;
	   *ptr2 = 0;
    }
    if (!serialPort->device_name || !serialPort->device_name[0]) {
        usage();
        return -1;
    }
    /* create pipes */
    if ( (pipe(tty_data.cstatpipefd) < 0) ||
         (pipe(tty_data.portpipefd)  < 0) )
    {
        perror(PIPEFAIL);
        return -1;
    }
    /* fork child process */
    switch (pid = fork()) {
    case 0:
        /* child process */
        /* close child status read pipe and port write pipe */
        close(tty_data.cstatpipefd[RPIPE]);
        close(tty_data.portpipefd[WPIPE]);
        signal(SIGINT, sigintC);
        pipeReader(&tty_data);  /*child proc lives entirely within pipeReader*/
        closeAll();
        break;
    case -1:
        /* fork() failed */
        perror(FORKFAIL);
        return -1;
    default:
        /* parent process */
        /* close child status write pipe and port read pipe */
        close(tty_data.cstatpipefd[WPIPE]);
        close(tty_data.portpipefd[RPIPE]);
        break;
    }
    /* lock port */
    if (!tty_data.nolock && dev_setlock(serialPort->device_name) == -1) {
        /* couldn't lock the device */
        return -1;
    }

    /* set raw mode on port */
    serport_set_raw_mode( serialPort );
    
    /* try to open port */
    serport_open( serialPort );
    if (tty_data.verbose) {
        printf("Opened port: %s\n", serialPort->device_name);
    }
    tty_data.portraw = TRUE;

    /* start listening to the child and port */
    maxfd  = max(tty_data.cstatpipefd[RPIPE], serialPort->file_des);
    while (TRUE) {
        FD_ZERO(&rset);
        FD_SET(serialPort->file_des, &rset);
        FD_SET(tty_data.cstatpipefd[RPIPE], &rset);
        if (select(maxfd + 1, &rset, NULL, NULL, NULL) < 0) {
            perror(SELFAIL);
            return -1;
        }
        if (FD_ISSET(serialPort->file_des, &rset)) {
            /* data coming from device */
            writeDataFromPort(serialPort->file_des, tty_data.portpipefd[WPIPE]);
        }
        if (FD_ISSET(tty_data.cstatpipefd[RPIPE], &rset)) {
            /* data coming from child - means time to quit */
            if (tty_data.verbose)
                printf("* DONE *\n");
            break;
        }
    }
    /* closeAll() */
    return 1;
}