/alps/ipecamera

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to cli.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-12-09 08:30:21 UTC
  • Revision ID: csa@dside.dyndns.org-20111209083021-b031rh6pr033to38
Parse required event & data_type

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
typedef enum {
98
98
    PARTITION_UNKNOWN,
99
99
    PARTITION_RAW,
100
 
    PARTITION_EXT4
 
100
    PARTITION_EXT4,
 
101
    PARTITION_NULL
101
102
} PARTITION;
102
103
 
103
104
typedef enum {
1116
1117
    ctx->event_count++;
1117
1118
    
1118
1119
    if (info->flags&PCILIB_EVENT_INFO_FLAG_BROKEN) ctx->broken_count++;
 
1120
 
 
1121
    data = pcilib_get_data(handle, ctx->event, ctx->data, &size);
 
1122
    if (!data) Error("Internal Error: No data is provided to event callback");
 
1123
 
 
1124
    written = fwrite(data, 1, size, ctx->output);
 
1125
    if (written != size) {
 
1126
        if (written > 0) Error("Write failed, only %z bytes out of %z are stored", written, size);
 
1127
        else Error("Write failed");
 
1128
    }
 
1129
 
 
1130
    pcilib_return_data(handle, ctx->event, data);
1119
1131
    
1120
1132
//    printf("%lu %lu\n", info->seqnum, info->offset);
1121
1133
 
1161
1173
 
1162
1174
    gettimeofday(&start, NULL);
1163
1175
    do {
1164
 
        pcilib_trigger(ctx->handle, PCILIB_EVENT0, 0, NULL);
 
1176
        pcilib_trigger(ctx->handle, ctx->event, 0, NULL);
1165
1177
        if ((++ctx->trigger_count == max_triggers)&&(max_triggers)) break;
1166
1178
        
1167
1179
        if (trigger_time) {
1240
1252
    return NULL;
1241
1253
}
1242
1254
 
1243
 
int TriggerAndGrab(pcilib_t *handle, GRAB_MODE grab_mode, const char *event, const char *data_type, size_t num, size_t run_time, size_t trigger_time, pcilib_timeout_t timeout, PARTITION partition, FORMAT format, size_t buffer_size, FILE *ofile) {
 
1255
int TriggerAndGrab(pcilib_t *handle, GRAB_MODE grab_mode, const char *evname, const char *data_type, size_t num, size_t run_time, size_t trigger_time, pcilib_timeout_t timeout, PARTITION partition, FORMAT format, size_t buffer_size, FILE *ofile) {
1244
1256
    int err;
1245
1257
    GRABContext ctx;    
1246
 
    void *data = NULL;
1247
 
    size_t size, written;
 
1258
//    void *data = NULL;
 
1259
//    size_t size, written;
 
1260
 
 
1261
    pcilib_event_t event;
 
1262
    pcilib_event_t listen_events;
 
1263
    pcilib_event_data_type_t data;
1248
1264
 
1249
1265
    pthread_t monitor_thread;
1250
1266
    pthread_t trigger_thread;
1254
1270
    struct timeval end_time;
1255
1271
    pcilib_event_flags_t flags;
1256
1272
 
 
1273
    if (evname) {
 
1274
        event = pcilib_find_event(handle, evname);
 
1275
        if (event == PCILIB_EVENT_INVALID) 
 
1276
            Error("Can't find event (%s)", evname);
 
1277
 
 
1278
        listen_events = event;
 
1279
    } else {
 
1280
        listen_events = PCILIB_EVENTS_ALL;
 
1281
        event = PCILIB_EVENT0;
 
1282
    }
 
1283
    
 
1284
    if (data_type) {
 
1285
        data = pcilib_find_event_data_type(handle, event, data_type);
 
1286
        if (data == PCILIB_EVENT_DATA_TYPE_INVALID)
 
1287
            Error("Can't find data type (%s)", data_type);
 
1288
    } else {
 
1289
        data = PCILIB_EVENT_DATA;
 
1290
    }
 
1291
 
1257
1292
    ctx.handle = handle;
1258
1293
    ctx.output = ofile;
1259
 
    ctx.event = PCILIB_EVENT0;
 
1294
    ctx.event = event;
 
1295
    ctx.data = data;
1260
1296
    ctx.run_time = run_time;
1261
1297
    ctx.timeout = timeout;
1262
1298
    
1268
1304
    ctx.run_flag = 1;
1269
1305
    
1270
1306
    memset(&ctx.stop_time, 0, sizeof(struct timeval));
 
1307
 
 
1308
 
1271
1309
    
1272
1310
//    printf("Limits: %lu %lu %lu\n", num, run_time, timeout);
1273
1311
    pcilib_configure_autostop(handle, num, run_time);//PCILIB_TIMEOUT_TRIGGER);
1303
1341
    gettimeofday(&ctx.start_time, NULL);
1304
1342
 
1305
1343
    if (grab_mode&GRAB_MODE_GRAB) {
1306
 
        err = pcilib_start(handle, PCILIB_EVENTS_ALL, PCILIB_EVENT_FLAGS_DEFAULT);
 
1344
        err = pcilib_start(handle, listen_events, flags);
1307
1345
        if (err) Error("Failed to start event engine, error %i", err);
1308
1346
    }
1309
1347
    
2307
2345
                if (!strcmp(fsname, "ext4")) partition = PARTITION_EXT4;
2308
2346
                else if (!strcmp(fsname, "raw")) partition = PARTITION_RAW;
2309
2347
            }
 
2348
        } else {
 
2349
            output = "/dev/null";
 
2350
            partition = PARTITION_NULL;
2310
2351
        }
2311
2352
 
2312
2353
        if (!timeout_set) {