From 2477edba0ae270a337f284ac7862d172f66a0303 Mon Sep 17 00:00:00 2001 From: cbdev Date: Wed, 28 Feb 2018 17:05:56 +0100 Subject: Update ArtNet configuration syntax, add mm_timestamp API --- README.md | 8 ++++---- artnet.c | 6 +++--- midimonster.c | 21 ++++++++++++++++++++- midimonster.h | 10 ++++++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 77dcba2..f323968 100644 --- a/README.md +++ b/README.md @@ -74,10 +74,10 @@ fixture control. | Option | Example value | Default value | Description | |---------------|-----------------------|-----------------------|-----------------------| -| `net` | `0` | `0` | ArtNet net to use | -| `uni` | `0` | `0` | ArtNet universe to use| -| `dest` | `10.2.2.2` | none | Destination address for sent ArtNet frames. Setting this enables the universe for output | -| `iface` | `1` | `0` | The bound address to use for data input/output | +| `net` | `0` | `0` | ArtNet `net` to use | +| `universe` | `0` | `0` | Universe identifier | +| `destination` | `10.2.2.2` | none | Destination address for sent ArtNet frames. Setting this enables the universe for output | +| `interface` | `1` | `0` | The bound address to use for data input/output | #### Channel specification diff --git a/artnet.c b/artnet.c index 6863861..474d0a6 100644 --- a/artnet.c +++ b/artnet.c @@ -209,11 +209,11 @@ static int artnet_configure_instance(instance* inst, char* option, char* value){ data->net = strtoul(value, NULL, 0); return 0; } - else if(!strcmp(option, "uni")){ + else if(!strcmp(option, "uni") || !strcmp(option, "universe")){ data->uni = strtoul(value, NULL, 0); return 0; } - else if(!strcmp(option, "iface")){ + else if(!strcmp(option, "iface") || !strcmp(option, "interface")){ data->fd_index = strtoul(value, NULL, 0); if(data->fd_index >= artnet_fds){ @@ -222,7 +222,7 @@ static int artnet_configure_instance(instance* inst, char* option, char* value){ } return 0; } - else if(!strcmp(option, "dest")){ + else if(!strcmp(option, "dest") || !strcmp(option, "destination")){ if(artnet_separate_hostspec(value, &host, &port)){ fprintf(stderr, "Not a valid ArtNet destination for instance %s\n", inst->name); return 1; diff --git a/midimonster.c b/midimonster.c index eb5510c..87abfb1 100644 --- a/midimonster.c +++ b/midimonster.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "midimonster.h" #include "config.h" #include "backend.h" @@ -19,6 +20,7 @@ static size_t mappings = 0; static channel_mapping* map = NULL; static size_t fds = 0; static managed_fd* fd = NULL; +static uint64_t global_timestamp = 0; static event_collection event_pool[2] = { {0}, @@ -28,10 +30,24 @@ static event_collection* primary = event_pool; volatile static sig_atomic_t shutdown_requested = 0; -void signal_handler(int signum){ +static void signal_handler(int signum){ shutdown_requested = 1; } +uint64_t mm_timestamp(){ + return global_timestamp; +} + +static void update_timestamp(){ + struct timespec current; + if(clock_gettime(CLOCK_MONOTONIC_COARSE, ¤t)){ + fprintf(stderr, "Failed to update global timestamp, time-based processing for some backends may be impaired: %s\n", strerror(errno)); + return; + } + + global_timestamp = current.tv_sec * 1000 + current.tv_nsec / 1000000; +} + int mm_map_channel(channel* from, channel* to){ size_t u, m; //find existing source mapping @@ -277,6 +293,9 @@ int main(int argc, char** argv){ } } + //update this iteration's timestamp + update_timestamp(); + //run backend processing, collect events DBGPF("%zu backend FDs signaled\n", n); if(backends_handle(n, signaled_fds)){ diff --git a/midimonster.h b/midimonster.h index 630399a..9f1a33e 100644 --- a/midimonster.h +++ b/midimonster.h @@ -187,5 +187,15 @@ int mm_channel_event(channel* c, channel_value v); * *i will need to be freed by the caller. */ int mm_backend_instances(char* backend, size_t* n, instance*** i); +/* + * Query an internal timestamp, which is updated every core iteration. + * This timestamp should not be used as a performance counter, but can be + * used for timeouting. Resolution is milliseconds. + */ +uint64_t mm_timestamp(); +/* + * Create a channel-to-channel mapping. This API should not + * be used by backends. It is only exported for core modules. + */ int mm_map_channel(channel* from, channel* to); #endif -- cgit v1.2.3