|
1 | | -// oscsendtest.c - test o2_osc_delegate() |
| 1 | +// oscsendtest.c - test o2_osc_delegate() |
2 | 2 | // |
3 | | -// this test is designed to run with oscrecvtest.c |
| 3 | +// this test is designed to run with oscrecvtest.c |
| 4 | +// |
| 5 | +// Usage: oscsendtest [flags] (see o2.h for flags, |
| 6 | +// use a for all, also u for UDP, M for master) |
| 7 | +// |
| 8 | +// The test: |
| 9 | +// initialize as a clock slave or master depending on M flag |
| 10 | +// if we are master, assume we are talking to a liblo server, |
| 11 | +// so sleep 2 seconds allowing liblo server to launch |
| 12 | +// (you should launch it first if running manually) |
| 13 | +// send 12 messages, 1 every 0.5s, and stop, |
| 14 | +// message are /oscsend/i 1234 |
| 15 | +// send 10 messages with timestamps, |
| 16 | +// messages are /oscsend/i <2000+i> |
| 17 | +// reciever can now call o2_osc_port_free to test closing the port |
| 18 | +// wait 1 second |
| 19 | +// send 1 message: /oscsend/i 5678 |
| 20 | +// wait 0.1 seconds |
| 21 | +// send 1 message with timestamp: /oscsend/i 6789 |
| 22 | +// wait 1 second |
| 23 | +// shut everything down |
4 | 24 |
|
5 | 25 | #include "o2.h" |
6 | 26 | #include "stdio.h" |
@@ -33,7 +53,7 @@ int main(int argc, const char * argv[]) |
33 | 53 |
|
34 | 54 | o2_initialize("test"); |
35 | 55 |
|
36 | | - // you can make this run without an O2 server by passing "master" |
| 56 | + // you can make this run without an O2 server by passing "M" flag |
37 | 57 | if (master) |
38 | 58 | o2_clock_set(NULL, NULL); |
39 | 59 | else if (argc > 2) |
@@ -70,6 +90,25 @@ int main(int argc, const char * argv[]) |
70 | 90 | o2_poll(); |
71 | 91 | usleep(2000); // 2ms |
72 | 92 | } |
| 93 | + // receiver may want to close port now and check that these |
| 94 | + printf("Time to close receiver's port if you want to test that.\n"); |
| 95 | + // messages are NOT received: |
| 96 | + err = o2_send("/oscsend/i", 0, "i", 5678); |
| 97 | + assert(err == O2_SUCCESS); |
| 98 | + printf("sent 5678 to /oscsend/i\n"); |
| 99 | + // pause for 0.1s, but keep running O2 by polling |
| 100 | + for (int i = 0; i < 50; i++) { |
| 101 | + o2_poll(); |
| 102 | + usleep(2000); // 2ms |
| 103 | + } |
| 104 | + double ts = o2_time_get() + 0.1; |
| 105 | + o2_send("/oscsend/i", ts, "i", 6789); |
| 106 | + printf("sent 6789 to /oscsend/i with timestamp %g\n", ts); |
| 107 | + // pause for 1s, but keep running O2 by polling |
| 108 | + for (int i = 0; i < 500; i++) { |
| 109 | + o2_poll(); |
| 110 | + usleep(2000); // 2ms |
| 111 | + } |
73 | 112 | o2_service_free("oscsend"); |
74 | 113 | o2_finish(); |
75 | 114 | sleep(1); // finish closing sockets |
|
0 commit comments