Logiciels divers autour du protocole « Open Sound Control » aka OSC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

asyncburp.c 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Joystick to Laser
  3. * async version, with continuous refresh
  4. * post Sonoptic 2020
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9. #include <string.h>
  10. #include <lo/lo.h> /* OSC library */
  11. #include "laserblast.h"
  12. #include "burpmsg.h"
  13. /* ------------------------------------------------------------------- */
  14. #define LOCAL_PORT "9000"
  15. #define REMOTE_HOST "localhost" /* just loling */
  16. #define REMOTE_PORT "9999"
  17. /* ------------------------------------------------------------------- */
  18. int verbosity; /* global variable */
  19. /* ------------------------------------------------------------------- */
  20. /* ------------------------------------------------------------------- */
  21. int init_osc_receiver(char *port, int notused)
  22. {
  23. #if DEBUG_LEVEL
  24. fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, port, notused);
  25. #endif
  26. return -1;
  27. }
  28. /* ------------------------------------------------------------------- */
  29. int init_osc_sender(char *r_host, char *r_port, int notused)
  30. {
  31. int foo;
  32. #if DEBUG_LEVEL
  33. fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
  34. r_host, r_port, notused);
  35. #endif
  36. foo = blast_init(r_host, r_port, 0, 0);
  37. if (foo) {
  38. fprintf(stderr, "blast_init return %d\n", foo);
  39. return -2;
  40. }
  41. if (verbosity) blast_NOP(getpid());
  42. return 0;
  43. }
  44. /* ------------------------------------------------------------------- */
  45. /*
  46. * this is a tool function for debugging, do not use in real life
  47. */
  48. static int tentative(void)
  49. {
  50. int foo;
  51. blast_rewind();
  52. blast_addpoint(200, 200, 0xff0000);
  53. blast_addpoint(300, 300, 0xff0000);
  54. blast_flush(0);
  55. return 42;
  56. }
  57. /* ------------------------------------------------------------------- */
  58. static int help(int krkrkr)
  59. {
  60. puts("HELP ME !");
  61. puts("\t-p NNN\t\tlocal listening port");
  62. puts("\t-R a.b.c.d\tremote host");
  63. puts("\t-P NNN\t\tremote port");
  64. puts("\t-L N\t\tlaser number");
  65. puts("\t-S N\t\tscene number");
  66. puts("\t-v\t\tincrease verbosity");
  67. return 1;
  68. }
  69. /* ------------------------------------------------------------------- */
  70. int main(int argc, char *argv[])
  71. {
  72. char *local_port = LOCAL_PORT;
  73. char *remote_host = REMOTE_HOST;
  74. char *remote_port = REMOTE_PORT;
  75. int lasernumber, scenenumber;
  76. int opt, foo;
  77. fprintf(stderr, "%s compiled %s at %s\n",argv[0], __DATE__, __TIME__);
  78. /* set some default values */
  79. lasernumber = scenenumber = 0;
  80. /* parsing command line options */
  81. while ((opt = getopt(argc, argv, "hp:vL:S:R:P:")) != -1) {
  82. switch (opt) {
  83. case 'h': if (help(0)) exit(1); break;
  84. case 'p': local_port = optarg; break;
  85. case 'R': remote_host = optarg; break;
  86. case 'P': remote_port = optarg; break;
  87. case 'L': lasernumber = atoi(optarg); break;
  88. case 'S': scenenumber = atoi(optarg); break;
  89. case 'v': verbosity++; break;
  90. }
  91. }
  92. if (verbosity) {
  93. fprintf(stderr, "-------------: %s\n", argv[0]);
  94. fprintf(stderr, "pid : %d\n", getpid());
  95. fprintf(stderr, "local port : %s\n", local_port);
  96. fprintf(stderr, "remote : %s %s\n", remote_host, remote_port);
  97. fprintf(stderr, "scn/laser : %d %d\n", scenenumber, lasernumber);
  98. }
  99. foo = init_osc_sender(remote_host, remote_port, 0);
  100. fprintf(stderr, "init osc sender -> %d\n", foo);
  101. tentative();
  102. return 2;
  103. }
  104. /* ------------------------------------------------------------------- */