Esempio n. 1
0
int main(int argc, char** argv) {
    (void) argc;
    (void) argv;
    int rc;
    
    user_data_t user_data = {
        .io_listen = -1,
        .io = -1,
        .control_io_listen = -1,
        .control_io = -1,
        .fio = NULL,
    };

    // user_context will be pointer to socket
    scpi_context.user_context = &user_data;
    
    SCPI_Init(&scpi_context);

    user_data.io_listen = createServer(5025);
    user_data.control_io_listen = createServer(CONTROL_PORT);
    
    while(1) {
        rc = waitServer(&user_data);
        
        if (rc < 0) { // failed
            perror("select failed");
            exit(-1);
        }
        
        if (rc == 0) { // timeout
            SCPI_Input(&scpi_context, NULL, 0);
        }
        
        if ((user_data.io_listen >= 0) && FD_ISSET(user_data.io_listen, &user_data.fds)) {
            processIoListen(&user_data);
        }

        if ((user_data.control_io_listen >= 0) && FD_ISSET(user_data.control_io_listen, &user_data.fds)) {
            processSrqIoListen(&user_data);
        }
        
        if ((user_data.io >= 0) && FD_ISSET(user_data.io, &user_data.fds)) {
            processIo(&user_data);
        }
        
        if ((user_data.control_io >= 0) && FD_ISSET(user_data.control_io, &user_data.fds)) {
            processSrqIo(&user_data);
        }
        
    }
    
    return (EXIT_SUCCESS);
}
Esempio n. 2
0
static void scpi_server_thread(void *arg) {
    int rc;

    (void)arg;

    user_data.evtQueue = xQueueCreate(10, sizeof(uint32_t));
    
    // user_context will be pointer to socket
    scpi_context.user_context = &user_data;
    
    SCPI_Init(&scpi_context);

    user_data.io_listen = createServer(DEVICE_PORT);
    user_data.control_io_listen = createServer(CONTROL_PORT);
    
    while(1) {
        rc = waitServer(&user_data);
        
        if (rc < 0) { // failed
            iprintf("select failed");
            break;
        }

        if (rc == 0) { // timeout
            SCPI_Input(&scpi_context, NULL, 0);
        }        
        
        if ((user_data.io_listen != NULL) && (rc == SCPI_MSG_IO_LISTEN)) {
            processIoListen(&user_data);
        }

        if ((user_data.control_io_listen != NULL) && (rc == SCPI_MSG_CONTROL_IO_LISTEN)) {
            processSrqIoListen(&user_data);
        }
        
        if ((user_data.io != NULL) && (rc == SCPI_MSG_IO)) {
            processIo(&user_data);
        }
        
        if ((user_data.control_io != NULL) && (rc == SCPI_MSG_CONTROL_IO)) {
            processSrqIo(&user_data);
        }
        
    }
    
    vTaskDelete(NULL);
}
Esempio n. 3
0
int main(int argc, char** argv) {
    (void) argc;
    (void) argv;
    int rc;

#ifdef __cplusplus
    user_data_t user_data = {
        /*.io_listen =*/ -1,
        /*.io =*/ -1,
        /*.control_io_listen =*/ -1,
        /*.control_io =*/ -1,
        /*.fio =*/ NULL,
        /*.fds =*/ 0,
    };
#else
    user_data_t user_data = {
        .io_listen = -1,
        .io = -1,
        .control_io_listen = -1,
        .control_io = -1,
        .fio = NULL,
    };
#endif

    /* user_context will be pointer to socket */
    SCPI_Init(&scpi_context,
            scpi_commands,
            &scpi_interface,
            scpi_units_def,
            SCPI_IDN1, SCPI_IDN2, SCPI_IDN3, SCPI_IDN4,
            scpi_input_buffer, SCPI_INPUT_BUFFER_LENGTH,
            scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE);
    scpi_context.user_context = &user_data;

    user_data.io_listen = createServer(5025);
    user_data.control_io_listen = createServer(CONTROL_PORT);

    while (1) {
        rc = waitServer(&user_data);

        if (rc < 0) { /* failed */
            perror("select failed");
            exit(-1);
        }

        if (rc == 0) { /* timeout */
            SCPI_Input(&scpi_context, NULL, 0);
        }

        if ((user_data.io_listen >= 0) && FD_ISSET(user_data.io_listen, &user_data.fds)) {
            processIoListen(&user_data);
        }

        if ((user_data.control_io_listen >= 0) && FD_ISSET(user_data.control_io_listen, &user_data.fds)) {
            processSrqIoListen(&user_data);
        }

        if ((user_data.io >= 0) && FD_ISSET(user_data.io, &user_data.fds)) {
            processIo(&user_data);
        }

        if ((user_data.control_io >= 0) && FD_ISSET(user_data.control_io, &user_data.fds)) {
            processSrqIo(&user_data);
        }

    }

    return (EXIT_SUCCESS);
}