From 27eba094a067a0879250a3cf73c83df0da5c63a1 Mon Sep 17 00:00:00 2001 From: cbdev Date: Wed, 24 Jul 2019 21:35:10 +0200 Subject: Add detect option to OSC backend --- backends/osc.c | 31 +++++++++++++++++++++++++------ backends/osc.md | 6 ++++-- 2 files changed, 29 insertions(+), 8 deletions(-) (limited to 'backends') diff --git a/backends/osc.c b/backends/osc.c index 1305169..36b0993 100644 --- a/backends/osc.c +++ b/backends/osc.c @@ -13,6 +13,12 @@ #define osc_align(a) ((((a) / 4) + (((a) % 4) ? 1 : 0)) * 4) #define BACKEND_NAME "osc" +static struct { + uint8_t detect; +} osc_global_config = { + .detect = 0 +}; + int init(){ backend osc = { .name = BACKEND_NAME, @@ -248,7 +254,15 @@ static int osc_validate_path(char* path){ } static int osc_configure(char* option, char* value){ - fprintf(stderr, "The OSC backend does not take any global configuration\n"); + if(!strcmp(option, "detect")){ + osc_global_config.detect = 1; + if(!strcmp(value, "off")){ + osc_global_config.detect = 0; + } + return 0; + } + + fprintf(stderr, "Unknown configuration parameter %s for OSC backend\n", option); return 1; } @@ -384,7 +398,7 @@ static int osc_configure_instance(instance* inst, char* option, char* value){ return 0; } - fprintf(stderr, "Unknown configuration parameter %s for OSC backend\n", option); + fprintf(stderr, "Unknown configuration parameter %s for OSC instance %s\n", option, inst->name); return 1; } @@ -585,16 +599,17 @@ static int osc_handle(size_t num, managed_fd* fds){ else{ bytes_read = recv(fds[fd].fd, recv_buf, sizeof(recv_buf), 0); } + + if(bytes_read < 0){ + break; + } + if(data->root && strncmp(recv_buf, data->root, min(bytes_read, strlen(data->root)))){ //ignore packet for different root continue; } osc_local = recv_buf + (data->root ? strlen(data->root) : 0); - if(bytes_read < 0){ - break; - } - osc_fmt = recv_buf + osc_align(strlen(recv_buf) + 1); if(*osc_fmt != ','){ //invalid format string @@ -603,6 +618,10 @@ static int osc_handle(size_t num, managed_fd* fds){ } osc_fmt++; + if(osc_global_config.detect){ + fprintf(stderr, "Incoming OSC data: Path %s.%s Format %s\n", inst->name, osc_local, osc_fmt); + } + osc_data = (uint8_t*) osc_fmt + (osc_align(strlen(osc_fmt) + 2) - 1); //FIXME check supplied data length diff --git a/backends/osc.md b/backends/osc.md index c784cda..e9aa4d5 100644 --- a/backends/osc.md +++ b/backends/osc.md @@ -5,7 +5,9 @@ spoken primarily by visual interface tools and hardware such as TouchOSC. #### Global configuration -This backend does not take any global configuration. +| Option | Example value | Default value | Description | +|---------------|-----------------------|-----------------------|-----------------------| +| `detect` | `on` | `off` | Output the path of all incoming OSC packets to allow for easier configuration. Any path filters configured using the `root` instance configuration options still apply. | #### Instance configuration @@ -78,4 +80,4 @@ The default ranges are: #### Known bugs / problems -Ping requests are not yet answered. There may be some problems using broadcast output and input. \ No newline at end of file +Ping requests are not yet answered. There may be some problems using broadcast output and input. -- cgit v1.2.3