Exemple #1
0
void time_incr(a_time *t, int sec)
{
  if (0 != sec) {
    time_t stamp = time_time(t);
    time_init(t, stamp + sec);
  }
}
Exemple #2
0
static int generate_signals(sd_bus_message *m, void *userdata, sd_bus_error
        *ret_error) {
    uint64_t num_signals, payload_size;
    uint64_t i = 0;
    double c_time;
    int r;
    struct timeval ts;
    char *pl = NULL;

    /* Read the parameters */
    r = sd_bus_message_read(m, "tt", &num_signals, &payload_size);
    if (r < 0) {
        fprintf(stderr, "Failed to parse parameters: %s\n", strerror(-r));
        return r;
    }

    printf("SpamSignal: %"PRIu64", %"PRIu64 "\n", num_signals,
            payload_size);

    pl = (char*) malloc(payload_size + 1);
    _rs(pl, payload_size);

    for (i = 0; i < num_signals; i++) {
        c_time = time_time();
        r = sd_bus_emit_signal(bus, OBJ, INT,
                "Spam", "dts", c_time, payload_size, pl);
        if (r < 0) {
            fprintf(stderr, "Failed to emit signal: %s\n", strerror(-r));
            free(pl);
            return sd_bus_reply_method_return(m, "t", i);
        }
    }
    free(pl);
    return sd_bus_reply_method_return(m, "t", num_signals);
}
Exemple #3
0
int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)
{
   int triggered = 0;
   int id;
   double due;

   if (timeout <= 0.0) return 0;

   due = time_time() + timeout;

   id = callback_ex(user_gpio, edge, _wfe, &triggered);

   while (!triggered && (time_time() < due)) time_sleep(0.1);

   callback_cancel(id);

   return triggered;
}
Exemple #4
0
int main(int argc, char *argv[])
{
   int loops=LOOPS;
   int speed=SPEED;
   int bytes=BYTES;
   int i;
   int h;
   double start, diff, sps;
   unsigned char buf[16384];

   if (argc > 1) bytes = atoi(argv[1]);
   if ((bytes < 1) || (bytes > 16383)) bytes = BYTES;

   if (argc > 2) speed = atoi(argv[2]);
   if ((speed < 32000) || (speed > 32000000)) speed = SPEED;

   if (argc > 3) loops = atoi(argv[3]);
   if ((loops < 1) || (loops > 10000000)) loops = LOOPS;

   if (gpioInitialise() < 0) return 1;

   h = spiOpen(0, speed, 0);

   if (h < 0) return 2;

   start = time_time();

   for (i=0; i<loops; i++)
   {
      spiXfer(h, buf, buf, bytes);
   }

   diff = time_time() - start;

   printf("sps=%.1f: %d bytes @ %d bps (loops=%d time=%.1f)\n",
      (double)loops / diff, bytes, speed, loops, diff);

   spiClose(h);

   gpioTerminate();

   return 0;
}
Exemple #5
0
int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)
{
   int triggered = 0;
   int id;
   double due;

   if ((pi < 0) || (pi >= MAX_PI) || !gPiInUse[pi])
      return pigif_unconnected_pi;

   if (timeout <= 0.0) return 0;

   due = time_time() + timeout;

   id = callback_ex(pi, user_gpio, edge, _wfe, &triggered);

   while (!triggered && (time_time() < due)) time_sleep(0.05);

   callback_cancel(id);

   return triggered;
}
Exemple #6
0
static int bus_signal_cb(sd_bus_message *m, void *user_data, sd_bus_error
        *ret_error) {
    int r = 0;
    double ts = 0;
    double now;
    const char *msg = NULL;
    uint64_t size = 0;

    now = time_time();

    r = sd_bus_message_read(m, "dts", &ts, &size, &msg);
    if (r < 0) {
        fprintf(stderr, "Failed to parse signal message: %s\n", strerror(-r));
        return -1;
    }

    if (size > 2) {
        count += 1;
        diff_sum += (now - ts);
    } else if (size == 1) {
        start = now;
        diff_sum = 0.0;
        count = 0;
    } else if (size == 2) {
        if (prev_size > 2 && count > 10) {
            double avg = diff_sum / (double) count;
            double msg_sec = (double) count / (now - start);
            double mib = (prev_size * msg_sec) / (double) (1024 * 1024);
            printf("%d,%f,%f,%f, %d\n", prev_size, avg, msg_sec, mib, count);
        }
        diff_sum = 0.0;
        count = 0;
        start = now;
    }

    prev_size = size;
    sd_bus_message_unref(m);
    return 0;
}
Exemple #7
0
int time_diff(const a_time *later, const a_time *earlier)
{
  return (int)(time_time(later) - time_time(earlier));
}
Exemple #8
0
a_time *time_maximum(const a_time *a, const a_time *b)
{
  time_t time_a = time_time(a);
  time_t time_b = time_time(b);
  return (a_time *)(time_a < time_b ? b : a);
}