コード例 #1
0
ファイル: uei_of.c プロジェクト: BlastTNG/flight
int initialize_uei_of_channels(void)
{
    int ret;
    DQRDCFG *DQRdCfg = NULL;

    for (int i = 0; i < 8; i++) {
        SL508_write_buffer[i] = ph_bufq_new(0);
        SL508_read_buffer[i] = ph_bufq_new(0);
    }

    ret = DqInitDAQLib();
    if (ret < 0) {
        blast_err("Error %d in DqInitDAQLib", ret);
        goto uei_init_err;
    }

    ret = DqOpenIOM("192.168.1.10", DQ_UDP_DAQ_PORT, 1000, &hd_of, &DQRdCfg);
    if (ret < 0) {
        blast_err("Error %d in DqOpenIOM", ret);
        goto uei_init_err;
    }

    if ((ret = DqAddIOMPort(hd_of, &hd_dmap, DQ_UDP_DAQ_PORT, 1000)) < 0) {
        blast_err("Error %d adding DMAP port", ret);
        goto uei_init_err;
    }

    if ((ret = DqAddIOMPort(hd_of, &hd_508, DQ_UDP_DAQ_PORT, 1000)) < 0) {
        blast_err("Error %d adding 508 port", ret);
        goto uei_init_err;
    }

    if ((ret = DqRtDmapInit(hd_of, &dmapid, frequency)) < 0) {
        blast_err("Could not initialize DMAP: %s", DqTranslateError(ret));
    }

//    hd_508 = hd_of;
//    if ((ret = DqRtVmapInit(hd_508, &vmapid_508, 0.1)) < 0) {
//        blast_err("Could not initialize VMAP: %s", DqTranslateError(ret));
//    }

    return 0;
uei_init_err:
    if (hd_dmap)DqCloseIOM(hd_dmap);
    hd_dmap = 0;
    if (hd_508)DqCloseIOM(hd_508);
    hd_508 = 0;
    if (hd_of)DqCloseIOM(hd_of);
    hd_of = 0;
    DqCleanUpDAQLib();
    return -1;
}
コード例 #2
0
ファイル: buf.c プロジェクト: GamingAtheist/libphenom
static void test_straddle_edges(void)
{
  const char *delim = "\r\n";
  int delim_len = strlen(delim);
  int default_buf_size = 8192;
  int i;
  char pad[8192];

  memset(pad, 'x', sizeof(pad));
#define PAD_IT(__n) { \
  uint64_t n = __n; \
  while (n > 0) { \
    ph_bufq_append(q, pad, MIN(n, sizeof(pad)), 0); \
    n -= MIN(n, sizeof(pad)); \
  } \
}

  // We want two buffers: [8192][8192]
  // And then to place our delimiter around the first boundary to verify
  // that the delimiter matching operates correctly
  // We define a cursor offset relative to the end of the first buffer
  // (0 means the last byte of the delimiter is in the last byte of the
  // first buffer, 1 means that the last delimiter byte is in the first
  // byte of the second buffer)

  for (i = - 2 * delim_len; i < 2 * delim_len; i++) {
    ph_bufq_t *q;

    q = ph_bufq_new(16*1024);

    // Fill up the start of the buffer
    uint64_t num_first = default_buf_size + i - delim_len;

    // first data
    PAD_IT(num_first);
    is(num_first, ph_bufq_len(q));
    // first delim
    ph_bufq_append(q, delim, delim_len, 0);

    // second data
    PAD_IT(16);
    // second delim
    ph_bufq_append(q, delim, delim_len, 0);

    ph_buf_t *first = ph_bufq_consume_record(q, delim, delim_len);
    is_int(num_first + 2, ph_buf_len(first));

    ph_buf_t *second = ph_bufq_consume_record(q, delim, delim_len);
    is_int(18, ph_buf_len(second));

    diag("for i = %d, num_first = %d.  first->len=%d second->len=%d",
        i, (int)num_first, (int)ph_buf_len(first), (int)ph_buf_len(second));

    ph_buf_delref(first);
    ph_buf_delref(second);

    ph_bufq_free(q);
  }

  // Now, test the case where we have a partial match at a boundary, but not
  // the true match until later

  ph_bufq_t *q;

  q = ph_bufq_new(24*1024);
  PAD_IT(8191);
  ph_bufq_append(q, "\r", 1, 0);
  PAD_IT(8192);
  ph_bufq_append(q, delim, delim_len, 0);

  ph_buf_t *first = ph_bufq_consume_record(q, delim, delim_len);
  is_int(16386, ph_buf_len(first));

  ph_buf_delref(first);
  ph_bufq_free(q);
}