/*! Creation of a local destination. */ int setup_destination() { destination = mdev_new("testrecv", port, 0); if (!destination) goto error; printf("destination created.\n"); float mn=0, mx=1; recvsig_1 = mdev_add_input(destination, "/insig_1", 1, 'f', 0, &mn, &mx, insig_handler, 0); recvsig_2 = mdev_add_input(destination, "/insig_2", 1, 'f', 0, &mn, &mx, insig_handler, 0); recvsig_3 = mdev_add_input(destination, "/insig_3", 3, 'f', 0, &mn, &mx, insig_handler, 0); recvsig_4 = mdev_add_input(destination, "/insig_4", 1, 'f', 0, &mn, &mx, insig_handler, 0); printf("Input signal /insig registered.\n"); // Make sure we can add and remove inputs and inputs within crashing. mdev_remove_input(destination, mdev_add_input(destination, "/insig_5", 1, 'f', 0, &mn, &mx, 0, 0)); printf("Number of inputs: %d\n", mdev_num_inputs(destination)); return 0; error: return 1; }
int main() { signal(SIGINT, ctrlc); mapper_device dev = mdev_new("pwm", 9000, 0); float min0 = 0; float max1 = 1; float max1000 = 1000; mdev_add_input(dev, "/freq", 1, 'f', "Hz", &min0, &max1000, (mapper_signal_handler*)handler_freq, 0); mdev_add_input(dev, "/gain", 1, 'f', "Hz", &min0, &max1, (mapper_signal_handler*)handler_gain, 0); mdev_add_input(dev, "/duty", 1, 'f', "Hz", &min0, &max1, (mapper_signal_handler*)handler_duty, 0); run_synth(); set_duty(0.1); set_freq(110.0); set_gain(0.1); printf("Press Ctrl-C to quit.\n"); while (!done) mdev_poll(dev, 10); mdev_free(dev); set_freq(0); sleep(1); stop_synth(); }
int setup_destinations() { char str[20]; int number; float mn=0, mx=1; for ( int i=0; i<num_dests; i++ ) { dest_device_list[i] = mdev_new("dest", port, 0); number = num_signals[i]; for ( int j=0; j<number; j++ ) { sprintf( str, "/insig%d", j ); mdev_add_input(dest_device_list[i], str, 1, 'f', 0, &mn, &mx, 0, 0); } if ( !dest_device_list[i] ) { goto error; } } return 0; error: return 1; }
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; }
int setup_destination() { destination = mdev_new("testrecv", port, 0); if (!destination) goto error; printf("destination created.\n"); float mn=0, mx=1; recvsig = mdev_add_input(destination, "/insig", 3, 'f', 0, &mn, &mx, insig_handler, 0); printf("Input signal /insig registered.\n"); printf("Number of inputs: %d\n", mdev_num_inputs(destination)); return 0; error: return 1; }
/*! Creation of a local destination. */ int setup_destination() { destination = mdev_new("testselect-recv", 0, 0); if (!destination) goto error; eprintf("destination created.\n"); float mn=0, mx=1; recvsig = mdev_add_input(destination, "/insig", 1, 'f', 0, &mn, &mx, insig_handler, 0); eprintf("Input signal /insig registered.\n"); return 0; error: return 1; }
/*! Creation of a local destination. */ int setup_destination() { destination = mdev_new("testSpeedRecv", 0, 0); if (!destination) goto error; printf("destination created.\n"); recvsig = mdev_add_input(destination, "/insig", 1, 'f', 0, 0, 0, insig_handler, 0); if (!recvsig) goto error; msig_reserve_instances(recvsig, 9); printf("Input signal registered.\n"); printf("Number of inputs: %d\n", mdev_num_inputs(destination)); return 0; error: return 1; }
/*! Creation of a local destination. */ int setup_destination() { char sig_name[10]; destination = mdev_new("testrecv", port, 0); if (!destination) goto error; printf("destination created.\n"); float mn=0, mx=1; for (int i = 0; i < 4; i++) { snprintf(sig_name, 10, "%s%i", "/insig_", i); recvsig[i] = mdev_add_input(destination, sig_name, 1, 'f', 0, &mn, &mx, insig_handler, 0); } printf("Input signal /insig registered.\n"); printf("Number of inputs: %d\n", mdev_num_inputs(destination)); return 0; error: return 1; }
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; }