summaryrefslogtreecommitdiff
path: root/cethcan
diff options
context:
space:
mode:
Diffstat (limited to 'cethcan')
-rw-r--r--cethcan/cethcan.json12
-rw-r--r--cethcan/espnet.c19
2 files changed, 23 insertions, 8 deletions
diff --git a/cethcan/cethcan.json b/cethcan/cethcan.json
index 50954b7..229f55e 100644
--- a/cethcan/cethcan.json
+++ b/cethcan/cethcan.json
@@ -22,5 +22,15 @@
{ "addr": 257, "name": "door.left", "values": [ "open", "closed" ] },
{ "addr": 258, "name": "door.light", "values": [ "triggered", "normal" ] },
{ "addr": 259, "name": "door.lock", "values": [ "open", "closed" ] }
- ]
+ ],
+ "espnet": [ {
+ "interface": "eth0",
+ "devices": [
+ { "baseaddr": 2, "name": "dmx.lounge_buero_ecke" },
+ { "baseaddr": 7, "name": "dmx.lounge_midwest" },
+ { "baseaddr": 12, "name": "dmx.lounge_buehne_links" },
+ { "baseaddr": 17, "name": "dmx.lounge_traverse" },
+ { "baseaddr": 22, "name": "dmx.lounge_decke" }
+ ]
+ } ]
}
diff --git a/cethcan/espnet.c b/cethcan/espnet.c
index 0661351..2cfd157 100644
--- a/cethcan/espnet.c
+++ b/cethcan/espnet.c
@@ -99,15 +99,15 @@ void espnet_sink_writer(evutil_socket_t fd, short event, void *arg)
};
for (struct espnet_device *d = sink->devs; d; d = d->next) {
- if (d->baseaddr >= 510)
+ if (d->baseaddr >= 511)
continue;
- packet.dmx[d->baseaddr] = d->r;
- packet.dmx[d->baseaddr + 1] = d->g;
- packet.dmx[d->baseaddr + 2] = d->b;
+ packet.dmx[d->baseaddr - 1] = d->r;
+ packet.dmx[d->baseaddr + 0] = d->g;
+ packet.dmx[d->baseaddr + 1] = d->b;
}
if (sendto(sink->fd, &packet, sizeof(packet), 0,
- (struct sockaddr *)&addr, sizeof(addr) != sizeof(packet)))
+ (struct sockaddr *)&addr, sizeof(addr)) != sizeof(packet))
lprintf("ESPnet[%s#%d] send failed: %s",
sink->ifname, sink->universe, strerror(errno));
@@ -184,8 +184,8 @@ int espnet_init_conf(json_t *config)
lprintf("ESPnet config must have a string 'interface' key");
return 1;
}
- if (!json_is_object(json_object_get(config, "devices"))) {
- lprintf("ESPnet config must have an object 'device' key");
+ if (!json_is_array(json_object_get(config, "devices"))) {
+ lprintf("ESPnet config must have an array 'devices' key");
return 1;
}
@@ -218,11 +218,14 @@ int espnet_init_conf(json_t *config)
struct ip_mreqn mrn = { .imr_ifindex = ifindex };
struct sockaddr_in addr = { .sin_family = AF_INET,
.sin_port = htons(ESPNET_PORT) };
+ int mone = -1;
sink->fd = socket(AF_INET, SOCK_DGRAM, 0);
if (sink->fd < 0
|| setsockopt(sink->fd, SOL_IP, IP_MULTICAST_IF,
&mrn, sizeof(mrn))
+ || setsockopt(sink->fd, SOL_SOCKET, SO_BROADCAST,
+ &mone, sizeof(mone))
|| setsockopt(sink->fd, SOL_SOCKET, SO_BINDTODEVICE,
iface, strlen(iface) + 1)
|| bind(sink->fd, (struct sockaddr *)&addr, sizeof(addr))) {
@@ -254,6 +257,8 @@ int espnet_init_conf(json_t *config)
sink->u->json = espnet_json_handler;
sink->writer = event_new(ev_base, -1, 0, espnet_sink_writer, sink);
+ struct timeval tvs = { .tv_sec = 0, .tv_usec = ESPNET_TIMER };
+ event_add(sink->writer, &tvs);
*psinks = sink;
psinks = &sink->next;