void loop(int iterations) { printf("-------------------- GO ! --------------------\n"); int i = 0, j = 0; float value = 0; while (i >= 0 && iterations-- >= 0 && !done) { // here we should create, update and destroy some instances switch (rand() % 5) { case 0: // try to create a new instance for (j = 0; j < 10; j++) { if (!sendinst[j]) { sendinst[j] = nextid++; printf("--> Created new sender instance: %d\n", sendinst[j]); break; } } break; case 1: // try to destroy an instance j = rand() % 10; if (sendinst[j]) { printf("--> Retiring sender instance %ld\n", (long)sendinst[j]); msig_release_instance(sendsig, sendinst[j], MAPPER_TIMETAG_NOW); sendinst[j] = 0; break; } break; default: j = rand() % 10; if (sendinst[j]) { // try to update an instance value = (rand() % 10) * 1.0f; msig_update_instance(sendsig, sendinst[j], &value, 0, MAPPER_TIMETAG_NOW); printf("--> sender instance %d updated to %f\n", sendinst[j], value); sent++; } break; } print_instance_ids(sendsig); print_instance_ids(recvsig); printf("\n"); mdev_poll(destination, 100); mdev_poll(source, 0); i++; //usleep(1 * 1000); } }
void loop() { eprintf("-------------------- GO ! --------------------\n"); int i = 0; float value = 0; mapper_id instance; while (i < iterations && !done) { // here we should create, update and destroy some instances instance = (rand() % 10); switch (rand() % 5) { case 0: // try to destroy an instance eprintf("--> Retiring sender instance %"PR_MAPPER_ID"\n", instance); mapper_signal_instance_release(sendsig, (long)instance, MAPPER_NOW); break; default: // try to update an instance value = (rand() % 10) * 1.0f; mapper_signal_instance_update(sendsig, instance, &value, 0, MAPPER_NOW); eprintf("--> sender instance %"PR_MAPPER_ID" updated to %f\n", instance, value); sent++; break; } mapper_device_poll(destination, 100); mapper_device_poll(source, 0); i++; if (verbose) { print_instance_ids(sendsig); print_instance_ids(recvsig); eprintf("\n"); print_instance_vals(sendsig); print_instance_vals(recvsig); printf("\n"); } else { printf("\r Sent: %4i, Received: %4i ", sent, received); fflush(stdout); } } }