コード例 #1
0
ファイル: rtcfg.c プロジェクト: ChunHungLiu/xenomai
void cmd_server(int argc, char *argv[])
{
    int i;


    cmd.args.server.period    = 1000;
    cmd.args.server.burstrate = 4;
    cmd.args.server.heartbeat = 1000;
    cmd.args.server.threshold = 2;
    cmd.args.server.flags     = 0;

    for (i = 3; i < argc; i++) {
        if (strcmp(argv[i], "-p") == 0)
            cmd.args.server.period = getintopt(argc, ++i, argv, 1);
        else if (strcmp(argv[i], "-b") == 0)
            cmd.args.server.burstrate = getintopt(argc, ++i, argv, 1);
        else if (strcmp(argv[i], "-h") == 0)
            cmd.args.server.heartbeat = getintopt(argc, ++i, argv, 0);
        else if (strcmp(argv[i], "-t") == 0)
            cmd.args.server.threshold = getintopt(argc, ++i, argv, 1);
        else if (strcmp(argv[i], "-r") == 0)
            cmd.args.server.flags |= FLAG_READY;
        else
            help();
    }

    i = ioctl(f, RTCFG_IOC_SERVER, &cmd);
    if (i < 0) {
        perror("ioctl");
        exit(1);
    }
    exit(0);
}
コード例 #2
0
ファイル: rtcfg.c プロジェクト: BackupTheBerlios/rtnet-svn
void cmd_client(int argc, char *argv[])
{
    int i;


    cmd.args.client.timeout     = 0; /* infinite */
    cmd.args.client.buffer_size = 0;
    cmd.args.client.max_clients = 32;

    for (i = 3; i < argc; i++) {
        if (strcmp(argv[i], "-t") == 0)
            cmd.args.client.timeout = getintopt(argc, ++i, argv, 1);
        else if (strcmp(argv[i], "-c") == 0) {
            fprintf(stderr, "Configuration files are not supported yet.\n");
            exit(1);
        } else if (strcmp(argv[i], "-f") == 0) {
            fprintf(stderr, "Configuration files are not supported yet.\n");
            exit(1);
        } else if (strcmp(argv[i], "-m") == 0)
            cmd.args.client.max_clients = getintopt(argc, ++i, argv, 1);
        else
            help();
    }

    i = ioctl(f, RTCFG_IOC_CLIENT, &cmd);
    if (i < 0) {
        perror("ioctl");
        exit(1);
    }
    exit(0);
}
コード例 #3
0
ファイル: rtcfg.c プロジェクト: BackupTheBerlios/rtnet-svn
void cmd_announce(int argc, char *argv[])
{
    int i;


    cmd.args.announce.timeout     = 0; /* infinite */
    cmd.args.announce.buffer_size = 0;
    cmd.args.announce.burstrate   = 32;

    for (i = 3; i < argc; i++) {
        if (strcmp(argv[i], "-t") == 0)
            cmd.args.announce.timeout = getintopt(argc, ++i, argv, 1);
        else if (strcmp(argv[i], "-c") == 0) {
            fprintf(stderr, "Configuration files are not supported yet.\n");
            exit(1);
        } else if (strcmp(argv[i], "-f") == 0) {
            fprintf(stderr, "Configuration files are not supported yet.\n");
            exit(1);
        } else if (strcmp(argv[i], "-b") == 0)
            cmd.args.announce.burstrate = getintopt(argc, ++i, argv, 1);
        else
            help();
    }

    i = ioctl(f, RTCFG_IOC_ANNOUNCE, &cmd);
    if (i < 0) {
        perror("ioctl");
        exit(1);
    }
    exit(0);
}
コード例 #4
0
ファイル: tdmacfg.c プロジェクト: ChunHungLiu/xenomai
void do_slave(int argc, char *argv[])
{
    int     i;
    int     r;


    if (argc < 3)
        help();

    tdma_cfg.args.slave.cal_rounds  = 100;
    tdma_cfg.args.slave.max_slot_id = 7;

    for (i = 3; i < argc; i++) {
        if (strcmp(argv[i], "-c") == 0)
            tdma_cfg.args.slave.cal_rounds = getintopt(argc, ++i, argv, 0);
        else if (strcmp(argv[i], "-i") == 0)
            tdma_cfg.args.slave.max_slot_id = getintopt(argc, ++i, argv, 0);
        else
            help();
    }

    r = ioctl(f, TDMA_IOC_SLAVE, &tdma_cfg);
    if (r < 0) {
        perror("ioctl");
        exit(1);
    }
    exit(0);
}
コード例 #5
0
ファイル: rtping.c プロジェクト: BackupTheBerlios/rtnet-svn
int main(int argc, char *argv[])
{
    const char          rtnet_dev[] = "/dev/rtnet";
    struct timeval      time;
    struct itimerval    timer = {{0, 0}, {0, 1}};
    int                 i;


    if (argc < 2)
        help();

    gettimeofday(&time, NULL);
    cmd.args.ping.id       = time.tv_usec & 0xFFFF;
    cmd.args.ping.sequence = 1;
    cmd.args.ping.msg_size = 56;
    cmd.args.ping.timeout  = 500;

    for (i = 1; i < argc-1; i++) {
        if (strcmp(argv[i], "-c") == 0)
            count = getintopt(argc, ++i, argv, 1);
        else if (strcmp(argv[i], "-i") == 0)
            delay = getintopt(argc, ++i, argv, 1);
        else if (strcmp(argv[i], "-s") == 0) {
            cmd.args.ping.msg_size = getintopt(argc, ++i, argv, 0);
            if (cmd.args.ping.msg_size > 1472)
                cmd.args.ping.msg_size = 1472;
        } else
            help();
    }

    if (!inet_aton(argv[i], &addr))
        help();

    f = open(rtnet_dev, O_RDWR);
    if (f < 0) {
        perror(rtnet_dev);
        exit(1);
    }

    printf("Real-time PING %s %d(%d) bytes of data.\n",
           inet_ntoa(addr), cmd.args.ping.msg_size,
           cmd.args.ping.msg_size + 28);

    signal(SIGINT, terminate);
    signal(SIGALRM, ping);
    timer.it_interval.tv_sec  = delay / 1000;
    timer.it_interval.tv_usec = (delay % 1000) * 1000;
    setitimer(ITIMER_REAL, &timer, NULL);

    while (1) pause();
}
コード例 #6
0
ファイル: tdmacfg.c プロジェクト: ChunHungLiu/xenomai
void do_master(int argc, char *argv[])
{
    int     r;
    int     i;


    if (argc < 4)
        help();

    if ((sscanf(argv[3], "%u", &r) != 1) || (r <= 0)) {
        fprintf(stderr, "invalid cycle period: %s\n", argv[3]);
        exit(1);
    }
    tdma_cfg.args.master.cycle_period = ((uint64_t)r) * 1000;

    tdma_cfg.args.master.backup_sync_offset = 0;
    tdma_cfg.args.master.cal_rounds         = 100;
    tdma_cfg.args.master.max_cal_requests   = 64;
    tdma_cfg.args.master.max_slot_id        = 7;

    for (i = 4; i < argc; i++) {
        if (strcmp(argv[i], "-b") == 0)
            tdma_cfg.args.master.backup_sync_offset =
                getintopt(argc, ++i, argv, 0) * 1000;
        else if (strcmp(argv[i], "-c") == 0)
            tdma_cfg.args.master.cal_rounds = getintopt(argc, ++i, argv, 0);
        else if (strcmp(argv[i], "-i") == 0)
            tdma_cfg.args.master.max_slot_id = getintopt(argc, ++i, argv, 0);
        else if (strcmp(argv[i], "-m") == 0)
            tdma_cfg.args.master.max_cal_requests =
                getintopt(argc, ++i, argv, 1);
        else
            help();
    }

    r = ioctl(f, TDMA_IOC_MASTER, &tdma_cfg);
    if (r < 0) {
        perror("ioctl");
        exit(1);
    }
    exit(0);
}
コード例 #7
0
ファイル: rtcfg.c プロジェクト: BackupTheBerlios/rtnet-svn
void cmd_wait(int argc, char *argv[])
{
    int i;


    cmd.args.wait.timeout = 0;  /* infinite */

    for (i = 3; i < argc; i++) {
        if (strcmp(argv[i], "-t") == 0)
            cmd.args.wait.timeout = getintopt(argc, ++i, argv, 1);
        else
            help();
    }

    i = ioctl(f, RTCFG_IOC_WAIT, &cmd);
    if (i < 0) {
        perror("ioctl");
        exit(1);
    }
    exit(0);
}
コード例 #8
0
ファイル: rtcfg.c プロジェクト: ChunHungLiu/xenomai
void cmd_ready(int argc, char *argv[])
{
    int i;


    cmd.args.ready.timeout = 0; /* infinite */

    for (i = 3; i < argc; i++) {
        if (strcmp(argv[i], "-t") == 0)
            cmd.args.ready.timeout = getintopt(argc, ++i, argv, 0);
        else
            help();
    }

    i = ioctl(f, RTCFG_IOC_READY, &cmd);
    if (i < 0) {
        if (errno != ETIME)
            perror("ioctl");
        exit(1);
    }
    exit(0);
}
コード例 #9
0
ファイル: rtcfg.c プロジェクト: ChunHungLiu/xenomai
void cmd_announce(int argc, char *argv[])
{
    int    i;
    int    cfg_size;
    int    cfg_file      = -1;
    char   *cfg_filename = NULL;
    size_t buffer_size   = 0;


    cmd.args.announce.timeout     = 0; /* infinite */
    cmd.args.announce.buffer_size = 0;
    cmd.args.announce.flags       = 0;
    cmd.args.announce.burstrate   = DFLT_CLIENT_BURST_RATE;

    for (i = 3; i < argc; i++) {
        if (strcmp(argv[i], "-t") == 0)
            cmd.args.announce.timeout = getintopt(argc, ++i, argv, 0);
        else if (strcmp(argv[i], "-c") == 0) {
            cfg_file    = 1; /* standard output file descriptor */
            buffer_size = DFLT_CLIENT_BURST_RATE * DFLT_PACKET_SIZE;
        } else if (strcmp(argv[i], "-f") == 0) {
            if (++i >= argc)
                help();
            cfg_filename = argv[i];
            buffer_size  = DFLT_CLIENT_BURST_RATE * DFLT_PACKET_SIZE;
        } else if (strcmp(argv[i], "-b") == 0)
            cmd.args.announce.burstrate = getintopt(argc, ++i, argv, 1);
        else if (strcmp(argv[i], "-r") == 0)
            cmd.args.announce.flags |= FLAG_READY;
        else
            help();
    }

    if (buffer_size > 0) {
        cmd.args.announce.buffer = malloc(buffer_size);
        if (cmd.args.announce.buffer == NULL) {
            fprintf(stderr, "insufficient memory\n");
            exit(1);
        }
        cmd.args.announce.flags |= FLAG_STAGE_2_DATA;
    }
    cmd.args.announce.buffer_size = buffer_size;

    if (cfg_filename != NULL) {
        cfg_file = open(cfg_filename, O_CREAT | O_WRONLY | O_TRUNC,
                        S_IREAD | S_IWRITE);
        if (cfg_file < 0) {
            perror("create output file");
            free(cmd.args.announce.buffer);
            exit(1);
        }
    }

    while ((cfg_size = ioctl(f, RTCFG_IOC_ANNOUNCE, &cmd)) > 0) {
        i = write(cfg_file, cmd.args.announce.buffer, cfg_size);
        if (i < 0) {
            perror("write output file");
            exit(1);
        }
    }

    if (cmd.args.announce.buffer != NULL)
        free(cmd.args.announce.buffer);

    if (i < 0) {
        if (errno != ETIME)
            perror("ioctl");
        exit(1);
    }
    exit(0);
}
コード例 #10
0
ファイル: rtcfg.c プロジェクト: ChunHungLiu/xenomai
void cmd_client(int argc, char *argv[])
{
    int  i;
    int  cfg_size;
    int  cfg_file      = -1;
    char *cfg_filename = NULL;
    int  buffer_size   = 0;


    cmd.args.client.timeout      = 0; /* infinite */
    cmd.args.client.max_stations = 32;

    for (i = 3; i < argc; i++) {
        if (strcmp(argv[i], "-t") == 0) {
            cmd.args.client.timeout = getintopt(argc, ++i, argv, 0);
        } else if (strcmp(argv[i], "-c") == 0) {
            cfg_file    = 1; /* standard output file descriptor */
            buffer_size = DFLT_PACKET_SIZE;
        } else if (strcmp(argv[i], "-f") == 0) {
            if (++i >= argc)
                help();
            cfg_filename = argv[i];
            buffer_size  = DFLT_PACKET_SIZE;
        } else if (strcmp(argv[i], "-m") == 0)
            cmd.args.client.max_stations = getintopt(argc, ++i, argv, 1);
        else
            help();
    }

    if (buffer_size > 0) {
        cmd.args.client.buffer = malloc(buffer_size);
        if (cmd.args.client.buffer == NULL) {
            fprintf(stderr, "insufficient memory\n");
            exit(1);
        }
    }
    cmd.args.client.buffer_size = buffer_size;

    cfg_size = ioctl(f, RTCFG_IOC_CLIENT, &cmd);

    /* Buffer too small? Let's try again! */
    if (cfg_size > buffer_size) {
        free(cmd.args.client.buffer);

        buffer_size = i;
        cmd.args.client.buffer = malloc(buffer_size);
        if (cmd.args.client.buffer == NULL) {
            fprintf(stderr, "insufficient memory\n");
            exit(1);
        }
        cmd.args.client.buffer_size = buffer_size;

        cfg_size = ioctl(f, RTCFG_IOC_CLIENT, &cmd);
    }

    if (cfg_size < 0) {
        if (errno != ETIME)
            perror("ioctl");
        if (cmd.args.client.buffer_size > 0)
            free(cmd.args.client.buffer);
        exit(1);
    }

    if (cfg_filename != NULL) {
        cfg_file = open(cfg_filename, O_CREAT | O_WRONLY | O_TRUNC,
                        S_IREAD | S_IWRITE);
        if (cfg_file < 0) {
            perror("create output file");
            free(cmd.args.client.buffer);
            exit(1);
        }
    }

    if (cfg_file > 0) {
        i = write(cfg_file, cmd.args.client.buffer, cfg_size);
        free(cmd.args.client.buffer);
        if (i < 0) {
            perror("write output file");
            exit(1);
        }
    }

    exit(0);
}
コード例 #11
0
ファイル: rtcfg.c プロジェクト: ChunHungLiu/xenomai
void cmd_add(int argc, char *argv[])
{
    int               i;
    struct in_addr    ip_addr;
    struct ether_addr mac_addr;
    const char        *stage1_filename = NULL;
    const char        *stage2_filename = NULL;
    int               file;
    size_t            buf_size;
    void              *new_buf;


    if (argc < 4)
        help();

    if (inet_aton(argv[3], &ip_addr)) {
        cmd.args.add.addr_type = RTCFG_ADDR_IP;
        cmd.args.add.ip_addr   = ip_addr.s_addr;
    } else if (ether_aton_r(argv[3], &mac_addr) != NULL) {
        cmd.args.add.addr_type = RTCFG_ADDR_MAC;
        memcpy(cmd.args.add.mac_addr, mac_addr.ether_addr_octet,
               sizeof(mac_addr.ether_addr_octet));
    } else {
        fprintf(stderr, "invalid IP or physical address: %s\n", argv[3]);
        exit(1);
    }

    cmd.args.add.stage1_data     = NULL;
    cmd.args.add.stage1_size     = 0;
    cmd.args.add.stage2_filename = NULL;
    cmd.args.add.timeout         = 0;   /* infinite */

    for (i = 4; i < argc; i++) {
        if (strcmp(argv[i], "-hw") == 0) {
            if ((++i >= argc) || (ether_aton_r(argv[i], &mac_addr) == NULL))
                help();
            cmd.args.add.addr_type = RTCFG_ADDR_IP | FLAG_ASSIGN_ADDR_BY_MAC;
            memcpy(cmd.args.add.mac_addr, mac_addr.ether_addr_octet,
                   sizeof(mac_addr.ether_addr_octet));
        } else if (strcmp(argv[i], "-stage1") == 0) {
            if (++i >= argc)
                help();
            stage1_filename = argv[i];
        } else if (strcmp(argv[i], "-stage2") == 0) {
            if (++i >= argc)
                help();
            stage2_filename = argv[i];
        } else if (strcmp(argv[i], "-t") == 0)
            cmd.args.add.timeout = getintopt(argc, ++i, argv, 0);
        else
            help();
    }

    if (stage1_filename != NULL) {
        if (strcmp(stage1_filename, "-") == 0)
            file = 0; /* stdin */
        else {
            file = open(stage1_filename, O_RDONLY);
            if (file < 0) {
                perror("open stage 1 file");
                exit(1);
            }
        }

        buf_size = 0;
        do {
            buf_size += 4096;

            new_buf = realloc(cmd.args.add.stage1_data, buf_size);
            if (new_buf == NULL) {
                fprintf(stderr, "insufficient memory\n");
                if (cmd.args.add.stage1_data != NULL)
                    free(cmd.args.add.stage1_data);
                exit(1);
            }
            cmd.args.add.stage1_data = new_buf;

            i = read(file, cmd.args.add.stage1_data+cmd.args.add.stage1_size,
                     4096);
            if (i < 0) {
                perror("read stage 1 file");
                free(cmd.args.add.stage1_data);
                exit(1);
            }
            cmd.args.add.stage1_size += i;
        } while (i == 4096);

        close(file);
    }

    if (stage2_filename != NULL) {
        cmd.args.add.stage2_filename = malloc(PATH_MAX);
        if (cmd.args.add.stage2_filename == NULL) {
            fprintf(stderr, "insufficient memory\n");
            if (cmd.args.add.stage1_data != NULL)
                free(cmd.args.add.stage1_data);
            exit(1);
        }

        if (realpath(stage2_filename,
                     (char *)cmd.args.add.stage2_filename) == NULL) {
            perror("resolve stage 2 file");
            free((void *)cmd.args.add.stage2_filename);
            if (cmd.args.add.stage1_data != NULL)
                free(cmd.args.add.stage1_data);
            exit(1);
        }
    }

    i = ioctl(f, RTCFG_IOC_ADD, &cmd);

    if (cmd.args.add.stage1_data != NULL)
        free(cmd.args.add.stage1_data);
    if (cmd.args.add.stage2_filename != NULL)
        free((void *)cmd.args.add.stage2_filename);

    if (i < 0) {
        switch (errno) {
            case ESTAGE1SIZE:
                fprintf(stderr, "stage 1 file too big\n");
                break;

            case EEXIST:
                fprintf(stderr, "client entry already exists\n");
                break;

            default:
                perror("ioctl (add)");
        }
        exit(1);
    }
    exit(0);
}
コード例 #12
0
ファイル: tdmacfg.c プロジェクト: ChunHungLiu/xenomai
void do_slot(int argc, char *argv[])
{
    char            *log_filename = NULL;
    int             result_size = 0;
    unsigned int    ioc;
    int             r;
    int             i;


    if (argc < 4)
        help();

    if ((sscanf(argv[3], "%u", &r) != 1) || (r < 0)) {
        fprintf(stderr, "invalid slot id: %s\n", argv[3]);
        exit(1);
    }

    if (argc > 4) {
        tdma_cfg.args.set_slot.id = r;

        if ((sscanf(argv[4], "%u", &r) != 1) || (r < 0)) {
            fprintf(stderr, "invalid slot offset: %s\n", argv[4]);
            exit(1);
        }
        tdma_cfg.args.set_slot.offset = ((uint64_t)r) * 1000;

        tdma_cfg.args.set_slot.period      = 1;
        tdma_cfg.args.set_slot.phasing     = 0;
        tdma_cfg.args.set_slot.size        = 0;
        tdma_cfg.args.set_slot.cal_timeout = 0;
        tdma_cfg.args.set_slot.joint_slot  = -1;
        tdma_cfg.args.set_slot.cal_results = NULL;

        for (i = 5; i < argc; i++) {
            if (strcmp(argv[i], "-l") == 0) {
                if (++i >= argc)
                    help();
                log_filename = argv[i];
            } else if (strcmp(argv[i], "-p") == 0) {
                if (++i >= argc)
                    help();
                if ((sscanf(argv[i], "%u/%u",
                            &tdma_cfg.args.set_slot.phasing,
                            &tdma_cfg.args.set_slot.period) != 2) ||
                    (tdma_cfg.args.set_slot.phasing < 1) ||
                    (tdma_cfg.args.set_slot.period < 1) ||
                    (tdma_cfg.args.set_slot.phasing >
                        tdma_cfg.args.set_slot.period)) {
                    fprintf(stderr, "invalid parameter: %s %s\n", argv[i-1],
                            argv[i]);
                    exit(1);
                }
                tdma_cfg.args.set_slot.phasing--;
            } else if (strcmp(argv[i], "-s") == 0)
                tdma_cfg.args.set_slot.size =
                    getintopt(argc, ++i, argv, MIN_SLOT_SIZE);
            else if (strcmp(argv[i], "-t") == 0)
                tdma_cfg.args.set_slot.cal_timeout =
                    getintopt(argc, ++i, argv, 0);
            else if (strcmp(argv[i], "-j") == 0)
                tdma_cfg.args.set_slot.joint_slot =
                    getintopt(argc, ++i, argv, 0);
            else
                help();
        }

        if (log_filename) {
            /* note: we can reuse tdma_cfg here as the head is the same and
             *       will remain unmodified */
            result_size = ioctl(f, TDMA_IOC_CAL_RESULT_SIZE, &tdma_cfg);
            if (result_size > 0) {
                tdma_cfg.args.set_slot.cal_results =
                    (__u64 *)malloc(result_size * sizeof(__u64));
                if (!tdma_cfg.args.set_slot.cal_results) {
                    fprintf(stderr, "insufficient memory\n");
                    exit(1);
                }
            } else
                log_filename = NULL;
        }

        ioc = TDMA_IOC_SET_SLOT;
    } else {
        tdma_cfg.args.remove_slot.id = r;

        ioc = TDMA_IOC_REMOVE_SLOT;
    }

    r = ioctl(f, ioc, &tdma_cfg);
    if (r < 0) {
        perror("ioctl");
        exit(1);
    }

    if (log_filename)
        write_calibration_log(log_filename, result_size,
                              tdma_cfg.args.set_slot.cal_results);
    exit(0);
}