void wait_local_devices() { while (!(mdev_ready(source) && mdev_ready(destination))) { mdev_poll(source, 25); mdev_poll(destination, 25); } }
void wait_local_devices(int *cancel) { int keep_waiting = 1; while ( keep_waiting && !*cancel ) { keep_waiting = 0; for ( int i=0; i<num_sources; i++ ) { mdev_poll( source_device_list[i], 0 ); if ( !mdev_ready(source_device_list[i]) ) { keep_waiting = 1; } } for ( int i=0; i<num_dests; i++ ) { mdev_poll( dest_device_list[i], 0 ); if ( !mdev_ready(dest_device_list[i]) ) { keep_waiting = 1; } } } //mapper_db_dump(); }
void wait_ready() { while (!(mdev_ready(source) && mdev_ready(destination))) { mdev_poll(source, 0); mdev_poll(destination, 0); usleep(500 * 1000); } }
void wait_local_devices() { while (!done && !(mdev_ready(source) && mdev_ready(destination))) { mdev_poll(source, 0); mdev_poll(destination, 0); usleep(50 * 1000); } }
void recmonitor_poll() { mapper_monitor_poll(mon, 0); if (!dev_ready && mdev_ready(recdev)) { mapper_monitor_request_devices(mon); dev_ready = 1; } record_signals_on_stack(); }
void loop() { int i = 0; printf("Loading devices...\n"); while (i >= 0 && !done) { for (i=0; i<5; i++) mdev_poll(devices[i], 0); lo_timetag_now(&system_time); if (system_time.sec != last_update) { last_update = system_time.sec; if (ready) { for (i=0; i<5; i++) { mdev_timetag_now(devices[i], &device_times[i]); } // calculate standard deviation double mean = 0; for (i=0; i<5; i++) { mean += mapper_timetag_get_double(device_times[i]); } mean /= 5; double difference_aggregate = 0; for (i=0; i<5; i++) { difference_aggregate += powf(mapper_timetag_get_double(device_times[i]) - mean, 2); } // print current system time and device diffs printf("%f", (double)system_time.sec + (double)system_time.frac * 0.00000000023283064365); for (i=0; i<5; i++) { printf(" | %f", mapper_timetag_difference(system_time, device_times[i])); } printf(" | %f", sqrtf(difference_aggregate / 5)); printf("\n"); } else { int count = 0; for (i=0; i<5; i++) { count += mdev_ready(devices[i]); } if (count >= 5) { printf("\nSYSTEM TIME ***** | OFFSETS *****\n"); for (i=0; i<5; i++) { // Give each device clock a random starting offset devices[i]->admin->clock.offset = (rand() % 100) - 50; } ready = 1; } } } usleep(10 * 1000); } }
struct _agentInfo *agentInit() { obs[0] = obs[1] = 0; id = 0; struct _agentInfo *info = &agentInfo; memset(info, 0, sizeof(struct _agentInfo)); info->influence_device_name = strdup("/influence.1"); info->xagora_device_name = strdup("/XAgora_receiver.1"); info->admin = mapper_admin_new(0, 0, 0); // add device info->dev = mdev_new("agent", 9000 + id, info->admin); while (!mdev_ready(info->dev)) { mdev_poll(info->dev, 100); } printf("ordinal: %d\n", mdev_ordinal(info->dev)); fflush(stdout); // add monitor and monitor callbacks info->mon = mapper_monitor_new(info->admin, 0); info->db = mapper_monitor_get_db(info->mon); mapper_db_add_device_callback(info->db, dev_db_callback, info); mapper_db_add_link_callback(info->db, link_db_callback, info); // add signals float mn=-1, mx=1; mdev_add_input(info->dev, "observation", 2, 'f', "norm", &mn, &mx, signal_handler, 0); int imn=0, imx=WIDTH; info->sig_pos = mdev_add_output(info->dev, "position", 2, 'i', 0, &imn, &imx); info->sig_gain = mdev_add_output(info->dev, "gain", 1, 'f', "normalized", &mn, &mx); mx = 0.9; info->sig_fade = mdev_add_output(info->dev, "fade", 1, 'f', "normalized", &mn, &mx); mn = -1.5; mx = 1.5; info->sig_spin = mdev_add_output(info->dev, "spin", 1, 'f', "radians", &mn, &mx); mn = -3.1415926; mx = 3.1315926; info->sig_dir = mdev_add_output(info->dev, "direction", 1, 'f', "radians", &mn, &mx); mn = -1; info->sig_flow = mdev_add_output(info->dev, "flow", 1, 'f', "noramlized", &mn, &mx); return info; }
void recmonitor_stop() { if (!mon) return; if (mdev_ready(recdev)) { const char *devname = mdev_name(recdev); if (devname) { struct stringlist **node = &device_strings; while (*node) { mapper_db_device *dev = mapper_db_match_devices_by_name(db, (*node)->string); while (dev) { printf("Unlinking %s %s\n", (*dev)->name, devname); mapper_monitor_unlink(mon, (*dev)->name, devname); dev = mapper_db_device_next(dev); } node = &(*node)->next; } } } mapper_monitor_free(mon); }
void record_signals_on_stack() { if (!mdev_ready(recdev)) return; const char *devname = mdev_name(recdev); char destname[256] = ""; if (!devname) return; signal_list_t *n = pop_signal_stack(); if (!n) return; while (n) { printf("Recording %s%s\n", n->device_name, n->signal_name); if (strncmp(n->device_name, destname, 256)) { mapper_monitor_link(mon, n->device_name, devname, 0, 0); snprintf(destname, 256, "%s", n->device_name); } recdevice_add_input(n->device_name, n->signal_name, n->type, n->length); char signame[1024], recsigname[1024]; snprintf(signame, 1024, "%s%s", n->device_name, n->signal_name); snprintf(recsigname, 1024, "%s%s%s", devname, n->device_name, n->signal_name); mapper_monitor_connect(mon, signame, recsigname, 0, 0); free_signal(n); n = pop_signal_stack(); } recdevice_reset_generic_handler(); }
int test_recv() { mapper_device md = mdev_new("synth", 0, 0); if (!md) goto error; printf("Mapper device created.\n"); float mn=0, mx=1; mapper_signal sig = mdev_add_input(md, "/mapped1", 1, 'f', 0, &mn, &mx, handler, 0); printf("Input signal /mapped1 registered.\n"); printf("Number of inputs: %d\n", mdev_num_inputs(md)); printf("Waiting for port/ordinal allocation..\n"); int i; for (i = 0; i < 10; i++) { mdev_poll(md, 500); if (mdev_ready(md)) break; usleep(500 * 1000); } if (i >= 10) { printf("Timed out waiting for signal name.\n"); goto error; } char port[10]; sprintf(port, "%i", md->admin->port); printf("using port = %s\n", port); lo_address a = lo_address_new("localhost", port); if (!a) { printf("Error creating lo_address for test.\n"); return 1; } printf("Polling device..\n"); for (i = 0; i < 10; i++) { lo_send(a, sig->props.name, "f", (float) i); printf("Updating signal %s to %f\n", sig->props.name, (float) i); sent++; mdev_poll(md, 500); //usleep(500 * 1000); } if (sent != received) { printf("Not all sent values were received.\n"); printf("Sent %d values, but %d received.\n", sent, received); goto error; } if (sent == 0) { printf("Unable to send any values.\n"); goto error; } printf("Sent and received %d values.\n", sent); mdev_free(md); lo_address_free(a); return 0; error: if (md) mdev_free(md); lo_address_free(a); return 1; }