|
From: <ma...@us...> - 2012-05-08 20:17:13
|
Revision: 799
http://openautomation.svn.sourceforge.net/openautomation/?rev=799&view=rev
Author: makki1
Date: 2012-05-08 20:17:03 +0000 (Tue, 08 May 2012)
Log Message:
-----------
Add debian-packaging, change to autoconf/make - NO source-changes
Added Paths:
-----------
tools/knxdmxd/Makefile.am
tools/knxdmxd/Makefile.org
tools/knxdmxd/configure.ac
tools/knxdmxd/debian/
tools/knxdmxd/debian/README
tools/knxdmxd/debian/README.Debian
tools/knxdmxd/debian/changelog
tools/knxdmxd/debian/compat
tools/knxdmxd/debian/control
tools/knxdmxd/debian/copyright
tools/knxdmxd/debian/docs
tools/knxdmxd/debian/files
tools/knxdmxd/debian/init.d
tools/knxdmxd/debian/knxdmxd.default
tools/knxdmxd/debian/knxdmxd.install
tools/knxdmxd/debian/rules
tools/knxdmxd/debian/source/
tools/knxdmxd/debian/source/format
tools/knxdmxd/src/
tools/knxdmxd/src/Makefile.am
tools/knxdmxd/src/knxdmxd.cpp
Removed Paths:
-------------
tools/knxdmxd/Makefile
tools/knxdmxd/knxdmxd.c
Deleted: tools/knxdmxd/Makefile
===================================================================
--- tools/knxdmxd/Makefile 2012-05-08 20:07:12 UTC (rev 798)
+++ tools/knxdmxd/Makefile 2012-05-08 20:17:03 UTC (rev 799)
@@ -1,7 +0,0 @@
-CC = g++
-CFLAGS = -Wall -Os
-LIBS = -L. -L/usr/lib -L/home/jan/ola-0.8.18/ola -lpthread -leibclient -lolacommon -lola -ljson
-
-knxdmxd: knxdmxd.c
- $(CC) $(CFLAGS) knxdmxd.c $(LIBS) -o knxdmxd
-
Added: tools/knxdmxd/Makefile.am
===================================================================
--- tools/knxdmxd/Makefile.am (rev 0)
+++ tools/knxdmxd/Makefile.am 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,2 @@
+AUTOMAKE_OPTIONS = foreign
+SUBDIRS = src
\ No newline at end of file
Copied: tools/knxdmxd/Makefile.org (from rev 797, tools/knxdmxd/Makefile)
===================================================================
--- tools/knxdmxd/Makefile.org (rev 0)
+++ tools/knxdmxd/Makefile.org 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,7 @@
+CC = g++
+CFLAGS = -Wall -Os
+LIBS = -L. -L/usr/lib -L/home/jan/ola-0.8.18/ola -lpthread -leibclient -lolacommon -lola -ljson
+
+knxdmxd: knxdmxd.c
+ $(CC) $(CFLAGS) knxdmxd.c $(LIBS) -o knxdmxd
+
Added: tools/knxdmxd/configure.ac
===================================================================
--- tools/knxdmxd/configure.ac (rev 0)
+++ tools/knxdmxd/configure.ac 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,38 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+AC_PREREQ([2.61])
+AC_INIT(knxdmxd)
+AM_INIT_AUTOMAKE(knxdmxd, 0.01)
+
+AC_CONFIG_SRCDIR([src])
+#AC_CONFIG_HEADERS([config.h:config.h.in])
+
+# Checks for programs.
+AC_PROG_CXX
+
+# Checks for libraries.
+AC_CHECK_LIB([eibclient], [EIBClose], ,[AC_MSG_ERROR(
+[Couldn't find libeibclient...try installing the eibclient-dev package] )])
+AC_CHECK_LIB([pthread], [pthread_create])
+AC_CHECK_LIB([json], [json_object_get], ,[AC_MSG_ERROR(
+[Couldn't find libjson0...try installing the libjson0-dev package] )])
+
+dnl ************************************
+dnl Check for libola
+dnl ************************************
+PKG_CHECK_MODULES([OLA], [libola], ,[AC_MSG_ERROR(
+[Couldn't find libola...try installing the ola package] )])
+AC_SUBST(OLA_LIBS)
+
+
+# Checks for header files.
+AC_CHECK_HEADERS([arpa/inet.h fcntl.h stdlib.h string.h syslog.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_TYPE_PID_T
+
+# Checks for library functions.
+AC_FUNC_FORK
+
+AC_OUTPUT(src/Makefile Makefile)
+
Added: tools/knxdmxd/debian/README
===================================================================
--- tools/knxdmxd/debian/README (rev 0)
+++ tools/knxdmxd/debian/README 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,6 @@
+The Debian Package knxdmxd
+----------------------------
+
+Comments regarding the Package
+
+ -- Michael Markstaller <de...@wi...> Wed, 07 Sep 2011 18:04:18 +0200
Added: tools/knxdmxd/debian/README.Debian
===================================================================
--- tools/knxdmxd/debian/README.Debian (rev 0)
+++ tools/knxdmxd/debian/README.Debian 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,6 @@
+knxdmxd for Debian
+-----------------------
+
+control startup settings through /etc/default/knxdmxd
+
+ -- Michael Markstaller <de...@wi...> Di 08 Mai 2012 16:52:30 CEST
Added: tools/knxdmxd/debian/changelog
===================================================================
--- tools/knxdmxd/debian/changelog (rev 0)
+++ tools/knxdmxd/debian/changelog 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,5 @@
+knxdmxd (0.1) unstable; urgency=low
+
+ * Initial Release.
+
+ -- Michael Markstaller <de...@wi...> Tue, 08 May 2012 16:53:19 +0200
Added: tools/knxdmxd/debian/compat
===================================================================
--- tools/knxdmxd/debian/compat (rev 0)
+++ tools/knxdmxd/debian/compat 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1 @@
+5
Added: tools/knxdmxd/debian/control
===================================================================
--- tools/knxdmxd/debian/control (rev 0)
+++ tools/knxdmxd/debian/control 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,14 @@
+Source: knxdmxd
+Section: unknown
+Priority: extra
+Maintainer: Michael Markstaller <de...@wi...>
+Build-Depends: debhelper (>= 5.0), autotools-dev, libeibclient-dev, libjson0-dev
+Standards-Version: 3.9.1
+Homepage: http://sourceforge.net/projects/openautomation/
+
+Package: knxdmxd
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: simple daemon to connect EIB/KNX to DMX using OLA
+ simple daemon to connect EIB/KNX to DMX using OLA
+
Added: tools/knxdmxd/debian/copyright
===================================================================
--- tools/knxdmxd/debian/copyright (rev 0)
+++ tools/knxdmxd/debian/copyright 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,39 @@
+Format: http://dep.debian.net/deps/dep5
+Upstream-Name: knxdmxd
+Source: <http://sourceforge.net/projects/openautomation/>
+
+Files: *
+Copyright: 2012 Jan N. Klug 2012 <jan...@ru...>
+License: GPL-3.0+
+
+Files: debian/*
+Copyright: 2011 Michael Markstaller <de...@wi...>
+License: GPL-3.0+
+
+License: GPL-3.0+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ .
+ This package is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ .
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ .
+ On Debian systems, the complete text of the GNU General
+ Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
+
+# Please choose a license for your packaging work. If the program you package
+# uses a mainstream license, using the same license is the safest choice.
+# Please avoid to pick license terms that are more restrictive than the
+# packaged work, as it may make Debian's contributions unacceptable upstream.
+# If you just want it to be GPL version 3, leave the following line in.
+
+and is licensed under the GPL version 3, see above.
+
+# Please also look if there are files or directories which have a
+# different copyright/license attached and list them here.
Added: tools/knxdmxd/debian/docs
===================================================================
--- tools/knxdmxd/debian/docs (rev 0)
+++ tools/knxdmxd/debian/docs 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,2 @@
+README
+
Added: tools/knxdmxd/debian/files
===================================================================
--- tools/knxdmxd/debian/files (rev 0)
+++ tools/knxdmxd/debian/files 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1 @@
+knxdmxd_0.1_i386.deb unknown extra
Added: tools/knxdmxd/debian/init.d
===================================================================
--- tools/knxdmxd/debian/init.d (rev 0)
+++ tools/knxdmxd/debian/init.d 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,152 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: knxdmxd
+# Required-Start: $network $local_fs
+# Required-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: <Enter a short description of the sortware>
+# Description: <Enter a long description of the software>
+# <...>
+# <...>
+### END INIT INFO
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC=knxdmxd # Introduce a short description here
+NAME=knxdmxd # Introduce the short server's name here
+DAEMON=/usr/bin/knxdmxd # Introduce the server's location here
+DAEMON_ARGS="" # Arguments to run the daemon with
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Exit if the package is not installed
+[ -x $DAEMON ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+ # Return
+ # 0 if daemon has been started
+ # 1 if daemon was already running
+ # 2 if daemon could not be started
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+ || return 1
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
+ $DAEMON_ARGS \
+ || return 2
+ # Add code here, if necessary, that waits for the process to be ready
+ # to handle requests from services started subsequently which depend
+ # on this one. As a last resort, sleep for some time.
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+ # Return
+ # 0 if daemon has been stopped
+ # 1 if daemon was already stopped
+ # 2 if daemon could not be stopped
+ # other if a failure occurred
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+ RETVAL="$?"
+ [ "$RETVAL" = 2 ] && return 2
+ # Wait for children to finish too if this is a daemon that forks
+ # and if the daemon is only ever run from this initscript.
+ # If the above conditions are not satisfied then add some other code
+ # that waits for the process to drop all resources that could be
+ # needed by services started subsequently. A last resort is to
+ # sleep for some time.
+ start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+ [ "$?" = 2 ] && return 2
+ # Many daemons don't delete their pidfiles when they exit.
+ rm -f $PIDFILE
+ return "$RETVAL"
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+do_reload() {
+ #
+ # If the daemon can reload its configuration without
+ # restarting (for example, when it is sent a SIGHUP),
+ # then implement that here.
+ #
+ start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+ return 0
+}
+
+case "$1" in
+ start)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
+ do_start
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ stop)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ status)
+ status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+ ;;
+ #reload|force-reload)
+ #
+ # If do_reload() is not implemented then leave this commented out
+ # and leave 'force-reload' as an alias for 'restart'.
+ #
+ #log_daemon_msg "Reloading $DESC" "$NAME"
+ #do_reload
+ #log_end_msg $?
+ #;;
+ restart|force-reload)
+ #
+ # If the "reload" option is implemented then remove the
+ # 'force-reload' alias
+ #
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1)
+ do_start
+ case "$?" in
+ 0) log_end_msg 0 ;;
+ 1) log_end_msg 1 ;; # Old process is still running
+ *) log_end_msg 1 ;; # Failed to start
+ esac
+ ;;
+ *)
+ # Failed to stop
+ log_end_msg 1
+ ;;
+ esac
+ ;;
+ *)
+ #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+esac
+
+:
Added: tools/knxdmxd/debian/knxdmxd.default
===================================================================
--- tools/knxdmxd/debian/knxdmxd.default (rev 0)
+++ tools/knxdmxd/debian/knxdmxd.default 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,17 @@
+# Defaults for knxdmxd initscript
+# sourced by /etc/init.d/knxdmxd
+# installed at /etc/default/knxdmxd by the maintainer scripts
+
+#
+# This is a POSIX shell fragment
+#
+
+#Usage: ./knxdmxd
+# -d Run as daemon/No debug output
+# -p <pidfile> PID-filename
+# -u <eib url> URL to contact eibd like local:/tmp/eib or ip:192.168.0.101
+# -c <config-file> Config-File
+
+# Additional options that are passed to the Daemon.
+DAEMON_ARGS="-d -c /etc/knxdmxd.conf -u local:/tmp/eib -p /var/run/knxdmxd.pid"
+
Added: tools/knxdmxd/debian/knxdmxd.install
===================================================================
--- tools/knxdmxd/debian/knxdmxd.install (rev 0)
+++ tools/knxdmxd/debian/knxdmxd.install 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,2 @@
+knxdmxd.conf etc/
+
Added: tools/knxdmxd/debian/rules
===================================================================
--- tools/knxdmxd/debian/rules (rev 0)
+++ tools/knxdmxd/debian/rules 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1,13 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+%:
+ dh $@
Property changes on: tools/knxdmxd/debian/rules
___________________________________________________________________
Added: svn:executable
+ *
Added: tools/knxdmxd/debian/source/format
===================================================================
--- tools/knxdmxd/debian/source/format (rev 0)
+++ tools/knxdmxd/debian/source/format 2012-05-08 20:17:03 UTC (rev 799)
@@ -0,0 +1 @@
+3.0 (native)
Deleted: tools/knxdmxd/knxdmxd.c
===================================================================
--- tools/knxdmxd/knxdmxd.c 2012-05-08 20:07:12 UTC (rev 798)
+++ tools/knxdmxd/knxdmxd.c 2012-05-08 20:17:03 UTC (rev 799)
@@ -1,653 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
-/*
- * knxdmxd.c
- * Copyright (C) Jan N. Klug 2012 <jan...@ru...>
- * Daemon skeleton by Michael Markstaller 2011 <de...@wi...>
- *
- * knxdmxd is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * knxdmxd is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <string.h>
-#include <signal.h>
-#include <getopt.h>
-#include <json/json.h>
-
-#include <ola/Logging.h>
-#include <ola/DmxBuffer.h>
-#include <ola/StreamingClient.h>
-#include <ola/StringUtils.h>
-
-//#include <assert.h>
-
-#include <arpa/inet.h>
-//#include <netinet/in.h>
-//#include <sys/socket.h>
-
-#include <pthread.h>
-#include <eibclient.h>
-
-#include <iostream>
-#include <fstream>
-#include <map>
-
-/*#include <boost/property_tree/ptree.hpp>
-#include <boost/property_tree/xml_parser.hpp>
-#include <boost/foreach.hpp>*/
-
-#define DEBUG 1
-#define DAEMON_NAME "knxdmxd"
-#define USAGESTRING "\n"\
- "\t-d Run as daemon/No debug output\n"\
- "\t-p <pidfile> PID-filename\n"\
- "\t-u <eib url> URL to contact eibd like local:/tmp/eib or ip:192.168.0.101\n"\
- "\t-c <config-file> Config-File\n"
-#define NUM_THREADS 4
-#define MAX_ZONES 31
-#define RETRY_TIME 5
-#define BUFLEN 1024
-#define POLLING_INTERVAL 10
-#define FADING_INTERVAL 50000
-
-using namespace std;
-//namespace bpt = boost::property_tree;
-typedef vector<string> svector;
-
-void daemonShutdown();
-
-eibaddr_t readgaddr (const char *addr) {
- int a, b, c;
- if (sscanf (addr, "%d/%d/%d", &a, &b, &c) == 3)
- return ((a & 0x01f) << 11) | ((b & 0x07) << 8) | ((c & 0xff));
- if (sscanf (addr, "%d/%d", &a, &b) == 2)
- return ((a & 0x01f) << 11) | ((b & 0x7FF));
- if (sscanf (addr, "%x", &a) == 1)
- return a & 0xffff;
- syslog(LOG_WARNING,"invalid group address format %s", addr);
- daemonShutdown();
- return 0;
-}
-
-int readdaddr (const string addr) {
- int universe, channel;
- sscanf( (char*)addr.c_str(), "%d.%d", &universe, &channel);
- if (channel==-1) { // default universe is 1
- channel = universe;
- universe = 1;
- }
- return (universe << 9) + channel;
-}
-
-namespace knxdmxd {
-
-class Fixture {
- public:
- Fixture() {};
- Fixture(const string str);
-
- void Patch(map<int, svector >& patchMap, const string channel, const int DMX, const int KNX);
- void Patch(map<int, svector >& patchMap, const string channel, const string DMX, const string KNX);
- void SetFadeTime(const float t);
- void PatchFadeTime(const int KNX);
- void Update(const int KNX, const int val);
- void Refresh(map<int, ola::DmxBuffer>& output);
- private:
- string name;
- map <string, int> channelKNX;
- map <string, int> channelDMX;
- map <string, int> channelValue;
- map <string, float> channelFloatValue;
- float fadeTime, fadeStep;
- int fadeTimeKNX;
-};
-
-Fixture::Fixture(const string str) {
- name=str;
- syslog(LOG_DEBUG, "Created Fixture '%s'", (char *)str.c_str());
-}
-
-void Fixture::Patch(map<int, svector>& patchMap, const string channel, const int DMX, const int KNX) {
- channelKNX[channel] = KNX;
- channelDMX[channel] = DMX;
-
- syslog(LOG_DEBUG, "Fixture '%s': Patched channel '%s' (KNX %d to DMX %d) ", (char *)name.c_str(), (char *)channel.c_str(), KNX, DMX);
-
- svector assignedChannels = patchMap[KNX]; // check if already patched
- for (vector<string>::iterator i = assignedChannels.begin(); i != assignedChannels.end(); ++i) {
- if ((*i)==name) { // already patched;
- return;
- }
- }
-
- patchMap[KNX].push_back(name); // no, add to patchMap
-
-}
-
-void Fixture::Patch(map<int, svector>& patchMap, const string channel, const string DMX, const string KNX) {
- Patch(patchMap, channel, readdaddr(DMX), readgaddr((char *) KNX.c_str()));
-}
-
-void Fixture::SetFadeTime(const float t) {
- fadeTime = t;
- fadeStep = (t<=0) ? 256 : 256/(t*1e6/FADING_INTERVAL);
- syslog(LOG_DEBUG, "Fixture '%s': Set Fadetime to %.2f s'(%.2f steps/interval)", (char *)name.c_str(), fadeTime, fadeStep);
-}
-
-void Fixture::PatchFadeTime(const int KNX) {
- fadeTimeKNX = KNX;
-}
-
-void Fixture::Update(const int KNX, const int val) {
- for(std::map<string, int>::const_iterator i = channelKNX.begin(); i != channelKNX.end(); ++i) {
- if (i->second == KNX) {
- channelValue[i->first] = val;
- syslog(LOG_DEBUG, "Updated channel '%s' to %d", (char *)i->first.c_str(), val);
- }
- }
-}
-
-void Fixture::Refresh(map<int, ola::DmxBuffer>& output) {
- for(std::map<string, int>::const_iterator i = channelDMX.begin(); i != channelDMX.end(); ++i) {
- int dmxuniverse = (int) (i->second / 512) , dmxchannel = i->second % 512;
- int oldValue = output[dmxuniverse].Get(dmxchannel);
- int newValue = channelValue[i->first];
- if (oldValue<newValue) {
- channelFloatValue[i->first] += fadeStep;
- if (channelFloatValue[i->first]>newValue) {
- channelFloatValue[i->first] = newValue;
- }
- output[dmxuniverse].SetChannel(dmxchannel, (int) channelFloatValue[i->first]);
- }
- if (oldValue>newValue) {
- channelFloatValue[i->first] -= fadeStep;
- if (channelFloatValue[i->first]<newValue) {
- channelFloatValue[i->first] = newValue;
- }
- output[dmxuniverse].SetChannel(dmxchannel, (int) channelFloatValue[i->first]);
- }
- }
-}
-
-}
-
-pthread_mutex_t zonelock = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t initlock = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t standbylock = PTHREAD_MUTEX_INITIALIZER;
-
-string eibd_url = "local:/tmp/eib";
-string conf_file = "knxdmxd.conf";
-int pidFilehandle;
-string pidfilename = "/var/run/dmxknxd.pid";
-
-map<int, ola::DmxBuffer> dmxWriteBuffer;
-map<string, knxdmxd::Fixture> fixtureList;
-map<int, svector> patchMap;
-
-void daemonShutdown() {
- //FIXME: clean exit pthread_exit(NULL); pthread_cancel(..);
- //close(udpSocket);
- syslog(LOG_INFO, "%s daemon exiting", DAEMON_NAME);
- fprintf(stderr, "%s daemon exiting", DAEMON_NAME);
- close(pidFilehandle);
- unlink((char *)pidfilename.c_str());
- exit(EXIT_SUCCESS);
-}
-
-void signal_handler(int sig) {
- switch(sig) {
- case SIGHUP:
- syslog(LOG_WARNING, "Received SIGHUP signal.");
- break;
- case SIGTERM:
- syslog(LOG_WARNING, "Received SIGTERM signal.");
- daemonShutdown();
- break;
- case SIGINT:
- syslog(LOG_WARNING, "Received SIGINT signal.");
- daemonShutdown();
- break;
- default:
- syslog(LOG_WARNING, "Unhandled signal (%d) %s", sig, strsignal(sig));
- break;
- }
-}
-
-/*void *sendKNXdgram(int type, int dpt, eibaddr_t dest, unsigned char val) {
- int len = 0;
- EIBConnection *con;
- unsigned char buf[255] = { 0, 0x80 };
- buf[1] = type; //0x40 response, 0x80 write
- syslog(LOG_DEBUG,"Send KNX dgram Type %d DPT %d dest %d val %d",type,dpt,dest,val);
- con = EIBSocketURL ((char *)eibd_url.c_str());
- if (!con)
- syslog(LOG_WARNING,"sendknxdgram: Open failed");
- if (EIBOpenT_Group (con, dest, 1) == -1)
- syslog(LOG_WARNING,"sendknxdgram: Connect failed");
- switch (dpt)
- {
- case 0:
- len=1;
- //for(i = 0; i < strlen(val)/2; i++)
- //raw value: nothing for now
- break;
- case 1:
- buf[1] |= val & 0x3f;
- len=2;
- break;
- case 3:
- // EIS2/DPT3 4bit dim
- buf[1] |= val & 0x3f;
- len=2;
- break;
- case 5:
- buf[2] = val*255/100;
- len=3;
- break;
- case 51:
- case 5001:
- buf[2] = val;
- len=3;
- break;
- case 6:
- case 6001:
- //FIXME: This is basically wrong but as we get a uchar we expect the sender to know..
- buf[2] = val;
- len=3;
- break;
- }
-
- len = EIBSendAPDU (con, len, buf);
- if (len == -1)
- syslog (LOG_WARNING,"sendknxdram: Request failed");
- EIBClose (con);
- usleep(50*1000); //throttle a little (50ms/max 20tps)
- return 0;
-} */
-
-void sigtime(int signo)
-{
- for(std::map<string, knxdmxd::Fixture>::const_iterator i = fixtureList.begin(); i != fixtureList.end(); ++i) {
- fixtureList[i->first].Refresh(dmxWriteBuffer);
- }
- signal(SIGALRM, sigtime);
-}
-
-void *worker(void *) {
- syslog(LOG_DEBUG, "Internal worker thread started");
-
- signal(SIGALRM, sigtime);
-
- itimerval itm;
- itm.it_interval.tv_sec=0;
- itm.it_value.tv_sec = 0;
- itm.it_interval.tv_usec = FADING_INTERVAL; // 20 ms is enough
- itm.it_value.tv_usec = FADING_INTERVAL;
- setitimer(ITIMER_REAL,&itm,0);
-
- while (1) {
- sleep(POLLING_INTERVAL);
- }
-
- pthread_exit(NULL);
-}
-
-/*void *sendKNXresponse(eibaddr_t dest, int zone, int func) {
- syslog(LOG_DEBUG, "KNX response %d zone %d func %d", dest,zone,func);
- pthread_mutex_lock (&zonelock);
- switch (func) {
- case 0:
- case 20:
- sendKNXdgram (0x40,1,dest,zones[zone].zonepower);
- break;
- case 1:
- case 21:
- sendKNXdgram (0x40,51,dest,zones[zone].srcid);
- break;
- case 2:
- case 22:
- sendKNXdgram (0x40,5,dest,zones[zone].volume*2);
- break;
- case 3:
- case 23:
- if (zones[zone].bass<10)
- sendKNXdgram (0x40,51,dest,zones[zone].bass-10+256);
- else
- sendKNXdgram (0x40,51,dest,zones[zone].bass-10);
- break;
- case 4:
- case 24:
- if (zones[zone].treble<10)
- sendKNXdgram (0x40,51,dest,zones[zone].treble-10+256);
- else
- sendKNXdgram (0x40,51,dest,zones[zone].treble-10);
- break;
- case 5:
- case 25:
- sendKNXdgram (0x40,1,dest,zones[zone].loudness);
- break;
- case 6:
- case 26:
- if (zones[zone].balance<10)
- sendKNXdgram (0x40,51,dest,zones[zone].balance-10+256);
- else
- sendKNXdgram (0x40,51,dest,zones[zone].balance-10);
- break;
- case 27:
- sendKNXdgram (0x40,1,dest,zones[zone].partymode);
- break;
- case 28:
- sendKNXdgram (0x40,1,dest,zones[zone].dnd);
- break;
- case 29:
- sendKNXdgram (0x40,5,dest,zones[zone].onvolume*2);
- break;
- }
- pthread_mutex_unlock (&zonelock);
- return 0;
-}
-*/
-void *handleKNXdgram(eibaddr_t dest, unsigned char* buf, int len){
- unsigned char val;
- switch (buf[1] & 0xC0) {
- case 0x00:
-// sendKNXresponse (dest,zone+(controller*ZONES_PER_CONTROLLER),func);
- break;
- case 0x40:
- //FIXME: response dunno
- break;
- case 0x80:
- if (buf[1] & 0xC0) {
- if (len == 2)
- val = buf[1] & 0x3F;
- else
- val = buf[2];
- svector uFixtures = patchMap.find(dest)->second;
- for (unsigned int i=0; i < uFixtures.size(); i++) {
- fixtureList[uFixtures[i]].Update(dest, val);
- }
- syslog(LOG_DEBUG, "Received %d @ %d, updated %d fixtures", val, dest, (int) uFixtures.size());
- }
- break;
- }
- return 0;
-}
-
-
-void *olahandler(void *) { // thread just reliably sends the data to DMX via OLA
- syslog(LOG_DEBUG, "OLA sender thread started");
-
- ola::InitLogging(ola::OLA_LOG_WARN, ola::OLA_LOG_STDERR);
-
- while (1) { // retry forever
-
- ola::StreamingClient ola_client;
-
- if (!ola_client.Setup()) { // setup client
- syslog(LOG_WARNING, "OLA: Client setup failed");
- sleep(RETRY_TIME);
- continue;
- }
-
- syslog(LOG_INFO, "OLA: Client connected");
-
- while (1) { // loop forever
- int error_flag=0;
- for(std::map<int, ola::DmxBuffer>::const_iterator i = dmxWriteBuffer.begin(); i != dmxWriteBuffer.end(); ++i) {
- int universe = i->first;
- if (!ola_client.SendDmx(universe, i->second)) { // send all universes
- syslog(LOG_WARNING, "OLA: failed to send universe %d", universe);
- error_flag = 1;
- break; // something went wrong
- }
- }
- if (error_flag==1) {
- sleep(RETRY_TIME);
- break;
- }
-
- usleep(20000);
- }
-
- ola_client.Stop(); // close the client
- }
-
- pthread_exit(NULL);
-}
-
-
-void *knxhandler(void *) {
- syslog(LOG_DEBUG, "KNX reader thread started");
- int len;
- EIBConnection *con;
- eibaddr_t dest;
- eibaddr_t src;
- unsigned char buf[255];
-
- while (1) //retry infinite
- {
- con = EIBSocketURL ((char *)eibd_url.c_str());
- if (!con) {
- syslog(LOG_WARNING, "eibd: Open failed");
- sleep(RETRY_TIME);
- continue;
- }
-
- if (EIBOpen_GroupSocket (con, 0) == -1) {
- syslog(LOG_WARNING, "eibd: Connect failed");
- sleep(RETRY_TIME);
- continue;
- }
-
- while (1)
- {
- len = EIBGetGroup_Src (con, sizeof (buf), buf, &src, &dest);
- if (len == -1) {
- syslog(LOG_WARNING, "eibd: Read failed");
- sleep(RETRY_TIME);
- break;
- }
- if (len < 2) {
- syslog(LOG_WARNING, "eibd: Invalid Packet");
- break;
- }
- if (buf[0] & 0x3 || (buf[1] & 0xC0) == 0xC0) {
- syslog(LOG_WARNING, "eibd: Unknown APDU from %d to %d",src,dest);
- break;
- } else {
- if ( patchMap.count(dest)<=0 ) //not for us
- continue;
- handleKNXdgram(dest,buf,len);
- }
- }
- syslog(LOG_WARNING,"eibd: closed connection"); //break in read-loop
- EIBClose (con);
- }
- pthread_exit(NULL);
-}
-
-void load_config() {
-
-/* bpt::ptree config;
-
- read_xml(conf_file, config);
-
- BOOST_FOREACH( bpt::ptree::value_type const& e, config) {
- if( e.first == "fixture" ) {
- string name = e.second.get<std::string>("<xmlattr>.name");
- knxdmxd::Fixture f(name);
- BOOST_FOREACH( bpt::ptree::value_type const& c, e.second) {
- if (c.first == "channel") {
- f.Patch(patchMap, c.second.data(), c.second.get<std::string>("<xmlattr>.dmx"), c.second.get<std::string>("<xmlattr>.knx"));
- }
- if (c.first == "fading") {
- float t;
- string content = c.second.data();
- sscanf((char*) content.c_str(), "%f", &t);
- f.SetFadeTime((int) (t*1.e6));
- }
- }
- fixtureList[name] = f;
- }
-
- } */
- struct json_object *config;
-
- config = json_object_from_file((char *)conf_file.c_str());
- // first all fixtures
- struct json_object *fixtures = json_object_object_get(config, "fixtures");
-
- int fixturenum = json_object_array_length(fixtures);
-
- for (int i=0; i<fixturenum; i++) { // read all
- // get fi...
[truncated message content] |
|
From: <j-...@us...> - 2012-05-11 18:24:45
|
Revision: 809
http://openautomation.svn.sourceforge.net/openautomation/?rev=809&view=rev
Author: j-n-k
Date: 2012-05-11 18:24:37 +0000 (Fri, 11 May 2012)
Log Message:
-----------
Changed logging, rewrite fixtures, added scenes
Modified Paths:
--------------
tools/knxdmxd/knxdmxd.conf
tools/knxdmxd/src/Makefile.am
Added Paths:
-----------
tools/knxdmxd/src/cue.cc
tools/knxdmxd/src/cue.h
tools/knxdmxd/src/fixture.cc
tools/knxdmxd/src/fixture.h
tools/knxdmxd/src/knxdmxd.cc
tools/knxdmxd/src/knxdmxd.h
tools/knxdmxd/src/log.cc
tools/knxdmxd/src/log.h
Removed Paths:
-------------
tools/knxdmxd/src/knxdmxd.cpp
Modified: tools/knxdmxd/knxdmxd.conf
===================================================================
--- tools/knxdmxd/knxdmxd.conf 2012-05-11 18:16:06 UTC (rev 808)
+++ tools/knxdmxd/knxdmxd.conf 2012-05-11 18:24:37 UTC (rev 809)
@@ -2,8 +2,8 @@
{ "name" : "Treppe",
"channels" : [
{ "name": "oben",
- "knx" : "1/7/170",
- "dmx" : "1.0"
+ "dmx" : "1.0",
+ "knx" : "1/7/170"
},
{ "name": "mitte",
"knx" : "1/7/170",
@@ -16,7 +16,7 @@
],
"fading" : {
"knx" : "1/6/170",
- "time": "1.7"
+ "time": "10"
}
},
{ "name" : "Kueche",
@@ -39,12 +39,48 @@
"time": "3.0"
}
},
- { "name" : "Test",
+ { "name" : "Test"
+ } ],
+"scenes": [
+ { "name" : "Treppe_Full_On",
+ "trigger" : {
+ "knx" : "1/0/170",
+ "call" : 1
+ },
"channels" : [
- { "name": "TestC",
- "knx": "1/7/170",
- "dmx" : "1.100"
+ { "fixture" : "Treppe",
+ "channel" : "oben",
+ "value" : 255
+ },
+ { "fixture" : "Treppe",
+ "channel" : "mitte",
+ "value" : 255
+ },
+ { "fixture" : "Treppe",
+ "channel" : "unten",
+ "value" : 255
}
+ ],
+ },
+ {
+ "name" : "Treppe_Blackout",
+ "trigger" : {
+ "knx" : "1/0/170",
+ "call" : 0
+ },
+ "channels" : [
+ { "fixture" : "Treppe",
+ "channel" : "oben",
+ "value" : 0
+ },
+ { "fixture" : "Treppe",
+ "channel" : "mitte",
+ "value" : 0
+ },
+ { "fixture" : "Treppe",
+ "channel" : "unten",
+ "value" : 0
+ }
]
} ]
}
Modified: tools/knxdmxd/src/Makefile.am
===================================================================
--- tools/knxdmxd/src/Makefile.am 2012-05-11 18:16:06 UTC (rev 808)
+++ tools/knxdmxd/src/Makefile.am 2012-05-11 18:24:37 UTC (rev 809)
@@ -8,4 +8,4 @@
# this lists the binaries to produce, the (non-PHONY, binary) targets in
# the previous manual Makefile
bin_PROGRAMS = knxdmxd
-knxdmxd_SOURCES = knxdmxd.cpp
+knxdmxd_SOURCES = knxdmx.cc log.cc fixture.cc cue.cc
Added: tools/knxdmxd/src/cue.cc
===================================================================
--- tools/knxdmxd/src/cue.cc (rev 0)
+++ tools/knxdmxd/src/cue.cc 2012-05-11 18:24:37 UTC (rev 809)
@@ -0,0 +1,53 @@
+/*
+ * cue.cc
+ *
+ * (c) by JNK 2012
+ *
+ *
+*/
+
+
+#include "cue.h"
+
+namespace knxdmxd {
+
+Cue::Cue(const std::string name) {
+ _name=name;
+ std::clog << "Creating Cue '" << name << "'" << std::endl;
+}
+
+void Cue::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, int KNX, int val) {
+ _triggerKNX = KNX;
+ _trigger_val = val;
+
+ std::clog << kLogDebug << "Cue '" << _name << "': Trigger by KNX:" << _triggerKNX << ", value " << _trigger_val << ((_trigger_val==-1) ? " (all)" : "") << std::endl;
+
+ std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> alreadypatched;
+ alreadypatched = patchMap.equal_range(KNX);
+
+ for (knxdmxd::knx_patch_map_t::iterator it = alreadypatched.first; it != alreadypatched.second; ++it) {
+ if (it->second == _name) return; // already patched that one
+ }
+
+ patchMap.insert(knxdmxd::knx_patch_map_element_t(KNX,_name)); // no, add to patchMap
+}
+
+void Cue::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, std::string KNX, int val) {
+ AddTrigger(patchMap, readgaddr(KNX), val);
+}
+
+void Cue::AddChannel(cue_channel_t channel) {
+ _channel_data.push_back(channel);
+ std::clog << "Added Channel definition " << channel.fixture << "/" << channel.name << "@" << channel.value << std::endl;
+}
+
+void Cue::Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val) {
+ if ((_trigger_val==-1) || (_trigger_val==val)) {
+ for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
+ fixtureList[it->fixture].Update(it->name, it->value, (float)255.);
+ }
+ std::clog << "Called cue " << _name << std::endl;
+ }
+}
+
+}
Added: tools/knxdmxd/src/cue.h
===================================================================
--- tools/knxdmxd/src/cue.h (rev 0)
+++ tools/knxdmxd/src/cue.h 2012-05-11 18:24:37 UTC (rev 809)
@@ -0,0 +1,46 @@
+/*
+ * cue.h
+ *
+ * (c) by JNK 2012
+ *
+ *
+*/
+
+#ifndef CUE_H
+#define CUE_H
+
+#include <string.h>
+#include <knxdmxd.h>
+#include <list>
+#include <fixture.h>
+
+namespace knxdmxd {
+
+typedef struct {
+ std::string fixture;
+ std::string name;
+ int value;
+} cue_channel_t;
+
+class Cue {
+ public:
+ Cue() {};
+ Cue(const std::string name);
+
+ void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, int KNX, int val);
+ void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, std::string KNX, int val);
+ void AddChannel(cue_channel_t channel);
+
+ void Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val);
+
+ private:
+ std::string _name;
+ int _triggerKNX;
+ int _trigger_val;
+ std::list<cue_channel_t> _channel_data;
+};
+
+
+}
+
+#endif
Added: tools/knxdmxd/src/fixture.cc
===================================================================
--- tools/knxdmxd/src/fixture.cc (rev 0)
+++ tools/knxdmxd/src/fixture.cc 2012-05-11 18:24:37 UTC (rev 809)
@@ -0,0 +1,93 @@
+/*
+ * fixture.cc
+ *
+ * (c) by JNK 2012
+ *
+ *
+*/
+
+
+#include "fixture.h"
+
+namespace knxdmxd {
+
+Fixture::Fixture(const std::string name) {
+ _name=name;
+ std::clog << "Creating Fixture '" << _name << "'" << std::endl;
+}
+
+void Fixture::Patch(knx_patch_map_t& patchMap, const std::string channel, const int DMX, const int KNX=-1) {
+ _channelKNX[channel] = KNX;
+ _channelDMX[channel] = DMX;
+
+ std::clog << "Fixture '" << _name << "': Patched channel '" << channel << "' (KNX " << KNX << " to " << DMX << ") " << std::endl;
+
+ std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> alreadypatched; // fixtures that handle this
+ alreadypatched = patchMap.equal_range(KNX);
+
+ for (knxdmxd::knx_patch_map_t::iterator it = alreadypatched.first; it != alreadypatched.second; ++it) {
+ if (it->second == _name) return; // already patched that one
+ }
+
+ patchMap.insert(knxdmxd::knx_patch_map_element_t(KNX,_name)); // no, add to patchMap
+
+}
+
+void Fixture::Patch(knx_patch_map_t& patchMap, const std::string channel, const std::string DMX, const std::string KNX) {
+ Patch(patchMap, channel, readdaddr(DMX), readgaddr(KNX));
+}
+
+void Fixture::SetFadeTime(const float t) {
+ _fadeTime = t;
+ _fadeStep = (t<=0) ? 256 : 256/(t*1e6/FADING_INTERVAL);
+ std::clog << "Fixture '" << _name << "': Set global fadetime to " << _fadeTime << "s (" << _fadeStep << " steps/interval)" << std::endl;
+}
+
+void Fixture::PatchFadeTime(const int KNX) {
+ _fadeTimeKNX = KNX;
+}
+
+void Fixture::Update(std::string channel, const int val, bool direct) {
+ _channelValue[channel] = val;
+ _channelFadeStep[channel] = direct ? 256 : _fadeStep;
+ std::clog << "Fixture '" << _name << "': Channel '" << channel << "' @ " << val << ", direct: " << ((direct) ? "true" : "false") << std::endl;
+}
+
+void Fixture::Update(const int KNX, const int val, bool direct) {
+ for(std::map<std::string, int>::const_iterator i = _channelKNX.begin(); i != _channelKNX.end(); ++i) {
+ if (i->second == KNX) Update(i->first, val, direct);
+ }
+}
+
+void Fixture::Update(std::string channel, const int val, float fadeStep) {
+ _channelValue[channel] = val;
+ _channelFadeStep[channel] = fadeStep;
+ std::clog << "Fixture '" << _name << "': Channel '" << channel << "' @ " << val << ", fading: " << fadeStep << std::endl;
+}
+
+
+void Fixture::Refresh(std::map<int, ola::DmxBuffer>& output) {
+ for(std::map<std::string, int>::const_iterator i = _channelDMX.begin(); i != _channelDMX.end(); ++i) {
+ int dmxuniverse = (int) (i->second / 512) , dmxchannel = i->second % 512;
+ int oldValue = output[dmxuniverse].Get(dmxchannel);
+ int newValue = _channelValue[i->first];
+ if (oldValue<newValue) {
+ _channelFloatValue[i->first] += _channelFadeStep[i->first];
+ if (_channelFloatValue[i->first]>newValue) {
+ _channelFloatValue[i->first] = newValue;
+ }
+ output[dmxuniverse].SetChannel(dmxchannel, (int) _channelFloatValue[i->first]);
+ std::clog << "Fade: " << dmxuniverse << "." << dmxchannel << " @ " << _channelFloatValue[i->first] << std::endl;
+ }
+ if (oldValue>newValue) {
+ _channelFloatValue[i->first] -= _channelFadeStep[i->first];
+ if (_channelFloatValue[i->first]<newValue) {
+ _channelFloatValue[i->first] = newValue;
+ }
+ output[dmxuniverse].SetChannel(dmxchannel, (int) _channelFloatValue[i->first]);
+ std::clog << "Fade: " << dmxuniverse << "." << dmxchannel << " @ " << _channelFloatValue[i->first] << std::endl;
+ }
+ }
+}
+
+}
Added: tools/knxdmxd/src/fixture.h
===================================================================
--- tools/knxdmxd/src/fixture.h (rev 0)
+++ tools/knxdmxd/src/fixture.h 2012-05-11 18:24:37 UTC (rev 809)
@@ -0,0 +1,45 @@
+/*
+ * fixture.h
+ *
+ * (c) by JNK 2012
+ *
+ *
+*/
+
+#ifndef FIXTURE_H
+#define FIXTURE_H
+
+#include <string.h>
+#include <knxdmxd.h>
+
+namespace knxdmxd {
+
+class Fixture {
+ public:
+ Fixture() {};
+ Fixture(const std::string name);
+
+ void Patch(knxdmxd::knx_patch_map_t& patchMap, const std::string channel, const int DMX, const int KNX);
+ void Patch(knxdmxd::knx_patch_map_t& patchMap, const std::string channel, const std::string DMX, const std::string KNX);
+ void SetFadeTime(const float t);
+ void PatchFadeTime(const int KNX);
+ void Update(std::string channel, const int val, const bool direct=false);
+ void Update(std::string channel, const int val, const float fadeStep);
+ void Update(const int KNX, const int val, const bool direct=false);
+ void Refresh(std::map<int, ola::DmxBuffer>& output);
+ private:
+ std::string _name;
+ std::map <std::string, int> _channelKNX;
+ std::map <std::string, int> _channelDMX;
+ std::map <std::string, int> _channelValue; // set value
+ std::map <std::string, float> _channelFadeStep; // individual by channel
+ std::map <std::string, float> _channelFloatValue; // internal calculation
+
+ float _fadeTime; // is set by knx or config
+ float _fadeStep; // calculated from _fadeTime
+ int _fadeTimeKNX;
+};
+
+}
+
+#endif
Added: tools/knxdmxd/src/knxdmxd.cc
===================================================================
--- tools/knxdmxd/src/knxdmxd.cc (rev 0)
+++ tools/knxdmxd/src/knxdmxd.cc 2012-05-11 18:24:37 UTC (rev 809)
@@ -0,0 +1,533 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * knxdmxd.c
+ * Copyright (C) Jan N. Klug 2012 <jan...@ru...>
+ * Daemon skeleton by Michael Markstaller 2011 <de...@wi...>
+ *
+ * knxdmxd is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * knxdmxd is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <getopt.h>
+#include <json/json.h>
+
+#include <ola/Logging.h>
+#include <ola/StreamingClient.h>
+#include <ola/StringUtils.h>
+
+#include <pthread.h>
+#include <eibclient.h>
+
+#include <iostream>
+#include <fstream>
+#include <map>
+
+#include <knxdmxd.h>
+#include <log.h>
+
+#include <fixture.h>
+#include <cue.h>
+
+#define DEBUG 1
+#define DAEMON_NAME "knxdmxd"
+#define USAGESTRING "\n"\
+ "\t-d Run as daemon/No debug output\n"\
+ "\t-p <pidfile> PID-filename\n"\
+ "\t-u <eib url> URL to contact eibd like local:/tmp/eib or ip:192.168.0.101\n"\
+ "\t-c <config-file> Config-File\n"
+#define NUM_THREADS 4
+#define MAX_ZONES 31
+#define RETRY_TIME 5
+#define BUFLEN 1024
+#define POLLING_INTERVAL 10
+
+template<class T>
+std::string t_to_string(T i) {
+ std::stringstream ss;
+ ss << i;
+ return ss.str();
+}
+
+void daemonShutdown();
+
+eibaddr_t readgaddr (const std::string addr) {
+ int a, b, c;
+ char *s = (char *)addr.c_str();
+
+ if (sscanf (s, "%d/%d/%d", &a, &b, &c) == 3)
+ return ((a & 0x01f) << 11) | ((b & 0x07) << 8) | ((c & 0xff));
+ if (sscanf (s, "%d/%d", &a, &b) == 2)
+ return ((a & 0x01f) << 11) | ((b & 0x7FF));
+ if (sscanf (s, "%x", &a) == 1)
+ return a & 0xffff;
+ std::clog << kLogWarning << "invalid group address format " << addr << std::endl;
+ daemonShutdown();
+ return 0;
+}
+
+int readdaddr (const std::string addr) {
+ int universe, channel;
+ sscanf( (char*)addr.c_str(), "%d.%d", &universe, &channel);
+ if (channel==-1) { // default universe is 1
+ channel = universe;
+ universe = 1;
+ }
+ return (universe << 9) + channel;
+}
+
+pthread_mutex_t zonelock = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t initlock = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t standbylock = PTHREAD_MUTEX_INITIALIZER;
+
+std::string eibd_url = "local:/tmp/eib";
+std::string conf_file = "knxdmxd.conf";
+int pidFilehandle;
+std::string pidfilename = "/var/run/dmxknxd.pid";
+
+std::map<int, ola::DmxBuffer> dmxWriteBuffer;
+std::map<std::string, knxdmxd::Fixture> fixtureList;
+std::map<std::string, knxdmxd::Cue> sceneList;
+
+knxdmxd::knx_patch_map_t KNX_fixture_patchMap;
+knxdmxd::knx_patch_map_t KNX_scene_patchMap;
+
+//map<int, channel> DMXpatchMap;
+
+void daemonShutdown() {
+ //FIXME: clean exit pthread_exit(NULL); pthread_cancel(..);
+ std::clog << kLogInfo << DAEMON_NAME << " daemon exiting" << std::endl;
+ fprintf(stderr, "%s daemon exiting", DAEMON_NAME);
+ close(pidFilehandle);
+ unlink((char *)pidfilename.c_str());
+ exit(EXIT_SUCCESS);
+}
+
+void signal_handler(int sig) {
+ switch(sig) {
+ case SIGHUP:
+ std::clog << kLogWarning << "Received SIGHUP signal." << std::endl;
+ break;
+ case SIGTERM:
+ std::clog << kLogWarning << "Received SIGTERM signal." << std::endl;
+ daemonShutdown();
+ break;
+ case SIGINT:
+ std::clog << kLogWarning << "Received SIGINT signal." << std::endl;
+ daemonShutdown();
+ break;
+ default:
+ std::clog << kLogWarning << "Unhandled signal (" << sig << ") " << strsignal(sig) << std::endl;
+ break;
+ }
+}
+
+void refresh_output(int signo)
+{
+ for(std::map<std::string, knxdmxd::Fixture>::const_iterator i = fixtureList.begin(); i != fixtureList.end(); ++i) {
+ fixtureList[i->first].Refresh(dmxWriteBuffer);
+ }
+ signal(SIGALRM, refresh_output);
+}
+
+void *worker(void *) {
+ std::clog << "Internal worker thread started" << std::endl;
+
+ signal(SIGALRM, refresh_output);
+
+ itimerval itm;
+ itm.it_interval.tv_sec=0;
+ itm.it_value.tv_sec = 0;
+ itm.it_interval.tv_usec = FADING_INTERVAL; // 20 ms is enough
+ itm.it_value.tv_usec = FADING_INTERVAL;
+ setitimer(ITIMER_REAL,&itm,0);
+
+ while (1) {
+ sleep(POLLING_INTERVAL);
+ }
+
+ pthread_exit(NULL);
+}
+
+void *handleKNXdgram(eibaddr_t dest, unsigned char* buf, int len){
+ unsigned char val;
+ switch (buf[1] & 0xC0) {
+ case 0x00:
+// sendKNXresponse (dest,zone+(controller*ZONES_PER_CONTROLLER),func);
+ break;
+ case 0x40:
+ //FIXME: response dunno
+ break;
+ case 0x80:
+ if (buf[1] & 0xC0) {
+ if (len == 2)
+ val = buf[1] & 0x3F;
+ else
+ val = buf[2];
+
+ if (KNX_fixture_patchMap.count(dest)>0) {
+ std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> uFixtures; // fixtures that handle this
+ uFixtures = KNX_fixture_patchMap.equal_range(dest);
+ int unum=0;
+ for (knxdmxd::knx_patch_map_t::iterator it = uFixtures.first; it != uFixtures.second; ++it)
+ {
+ fixtureList[it->second].Update(dest, val);
+ unum++;
+ }
+ std::clog << "Received " << (int)val << " @ " << dest << ", updated " << unum << " fixtures" << std::endl;
+ }
+ if (KNX_scene_patchMap.count(dest)>0) {
+ std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> uScenes; // fixtures that handle this
+ uScenes = KNX_scene_patchMap.equal_range(dest);
+ int unum=0;
+ for (knxdmxd::knx_patch_map_t::iterator it = uScenes.first; it != uScenes.second; ++it)
+ {
+ sceneList[it->second].Update(fixtureList, dest, val);
+ unum++;
+ }
+ std::clog << "Received " << (int) val << " @ " << dest << ", checked " << unum << " scenes" << std::endl;
+ }
+
+
+ }
+ break;
+ }
+ return 0;
+}
+
+
+void *olahandler(void *) { // thread just reliably sends the data to DMX via OLA
+ std::clog << kLogDebug << "OLA sender thread started" << std::endl;
+
+ ola::InitLogging(ola::OLA_LOG_WARN, ola::OLA_LOG_STDERR);
+
+ while (1) { // retry forever
+
+ ola::StreamingClient ola_client;
+
+ if (!ola_client.Setup()) { // setup client
+ std::clog << kLogWarning << "OLA: Client setup failed" << std::endl;
+ sleep(RETRY_TIME);
+ continue;
+ }
+
+ std::clog << kLogInfo << "OLA: Client connected" << std::endl;
+
+ while (1) { // loop forever
+ int error_flag=0;
+ for(std::map<int, ola::DmxBuffer>::const_iterator i = dmxWriteBuffer.begin(); i != dmxWriteBuffer.end(); ++i) {
+ int universe = i->first;
+ if (!ola_client.SendDmx(universe, i->second)) { // send all universes
+ std::clog << kLogWarning << "OLA: failed to send universe "<< universe << std::endl;
+ error_flag = 1;
+ break; // something went wrong
+ }
+ }
+ if (error_flag==1) {
+ sleep(RETRY_TIME);
+ break;
+ }
+
+ usleep(20000);
+ }
+
+ ola_client.Stop(); // close the client
+ }
+
+ pthread_exit(NULL);
+}
+
+
+void *knxhandler(void *) {
+ std::clog << "KNX reader thread started" << std::endl;
+ int len;
+ EIBConnection *con;
+ eibaddr_t dest;
+ eibaddr_t src;
+ unsigned char buf[255];
+
+ while (1) //retry infinite
+ {
+ con = EIBSocketURL ((char *)eibd_url.c_str());
+ if (!con) {
+ std::clog << kLogWarning << "eibd: Open failed" << std::endl;
+ sleep(RETRY_TIME);
+ continue;
+ }
+
+ if (EIBOpen_GroupSocket (con, 0) == -1) {
+ std::clog << kLogWarning << "eibd: Connect failed" << std::endl;
+ sleep(RETRY_TIME);
+ continue;
+ }
+
+ while (1)
+ {
+ len = EIBGetGroup_Src (con, sizeof (buf), buf, &src, &dest);
+ if (len == -1) {
+ std::clog << kLogWarning << "eibd: Read failed" << std::endl;
+ sleep(RETRY_TIME);
+ break;
+ }
+ if (len < 2) {
+ std::clog << kLogWarning << "eibd: Invalid Packet" << std::endl;
+ break;
+ }
+ if (buf[0] & 0x3 || (buf[1] & 0xC0) == 0xC0) {
+ std::clog << kLogWarning << "eibd: Unknown APDU from "<< src << " to " << dest << std::endl;
+ break;
+ } else {
+ if ( (KNX_fixture_patchMap.count(dest)+KNX_scene_patchMap.count(dest))<=0 ) //not for us
+ continue;
+ handleKNXdgram(dest,buf,len);
+ }
+ }
+
+ std::clog << kLogWarning << "eibd: Closed connection" << std::endl; //break in read-loop
+ EIBClose (con);
+ }
+ pthread_exit(NULL);
+}
+
+void load_config() {
+
+ struct json_object *config;
+
+ config = json_object_from_file((char *)conf_file.c_str());
+
+ // first all fixtures
+ struct json_object *fixtures = json_object_object_get(config, "fixtures");
+ int fixturenum = json_object_array_length(fixtures);
+ std::clog << "Trying to import " << fixturenum << " fixtures" << std::endl;
+
+ for (int i=0; i<fixturenum; i++) { // read all
+ // get fixture
+ struct json_object *fixture = json_object_array_get_idx(fixtures, i);
+
+ // get name & create
+ struct json_object *name = json_object_object_get(fixture, "name");
+ std::string fname = (name) ? json_object_get_string(name) : "_f_"+t_to_string(i);
+ knxdmxd::Fixture f(fname);
+
+ // get channels & patch them
+ struct json_object *channels = json_object_object_get(fixture, "channels");
+ if (!channels) {
+ std::clog << kLogInfo << "Skipping fixture '" << fname << "' (no channels defined)" << std::endl;
+ continue;
+ }
+
+ int channelnum = json_object_array_length(channels);
+ for (int j=0; j<channelnum; j++) { // read all
+ // get channel
+ struct json_object *channel = json_object_array_get_idx(channels, j);
+
+ // channel name, default is _c_<num>
+ struct json_object *name = json_object_object_get(channel, "name");
+ std::string cname = (name) ? json_object_get_string(name) : "_c_"+t_to_string(j);
+
+ // dmx is required
+ struct json_object *dmx = json_object_object_get(channel, "dmx");
+ if (!dmx) {
+ std::clog << kLogInfo << "Skipping channel '" << cname << "' in fixture '" << fname << "' (missing dmx)" << std::endl;
+ continue;
+ }
+ std::string cdmx(json_object_get_string(dmx));
+
+ // knx is optional
+ struct json_object *knx = json_object_object_get(channel, "knx"); // knx is optional
+ std::string cknx = (knx) ? json_object_get_string(knx) : "";
+
+ // patch
+ f.Patch(KNX_fixture_patchMap, cname, cdmx, cknx);
+ }
+
+ // get fading
+ struct json_object *fading = json_object_object_get(fixture, "fading");
+ float ftime = (fading) ? json_object_get_double(json_object_object_get(fading, "time")) : 0;
+ f.SetFadeTime(ftime);
+
+ fixtureList[fname] = f;
+ }
+
+ struct json_object *scenes = json_object_object_get(config, "scenes");
+ int scenenum = json_object_array_length(scenes);
+ std::clog << "Trying to import " << scenenum << " scenes" << std::endl;
+
+ for (int i=0; i<scenenum; i++) { // read all
+ struct json_object *scene = json_object_array_get_idx(scenes, i);
+
+ // get name & create
+ struct json_object *name = json_object_object_get(scene, "name");
+ std::string sname = (name) ? json_object_get_string(name) : "_s_"+t_to_string(i);
+ knxdmxd::Cue s(sname);
+
+ // trigger is required
+ struct json_object *trigger = json_object_object_get(scene, "trigger");
+ struct json_object *trigger_knx = json_object_object_get(trigger, "knx");
+
+ if ((!trigger) || (!trigger_knx)) {
+ std::clog << kLogInfo << "Skipping scene '" << sname << "' (error in trigger)" << std::endl;
+ continue;
+ }
+
+ struct json_object *trigger_call = json_object_object_get(trigger, "call");
+ s.AddTrigger(KNX_scene_patchMap, json_object_get_string(trigger_knx), (trigger_call) ? json_object_get_int(trigger_call) : -1);
+
+ // get channels
+ struct json_object *channels = json_object_object_get(scene, "channels");
+ if (!channels) {
+ std::clog << kLogInfo << "Skipping scene '" << sname << "' (no channels defined)" << std::endl;
+ continue;
+ }
+
+ int channelnum = json_object_array_length(channels);
+ for (int j=0; j<channelnum; j++) { // read all
+ // get channel
+ struct json_object *channel = json_object_array_get_idx(channels, j);
+
+ struct json_object *fixt = json_object_object_get(channel, "fixture");
+ struct json_object *chan = json_object_object_get(channel, "channel");
+ struct json_object *value = json_object_object_get(channel, "value");
+
+ if ((!fixt) || (!chan) || (!value)) {
+ std::clog << kLogInfo << "Skipping errorneous channel def " << j << "' in scene '" << sname << "'" << std::endl;
+ continue;
+ }
+
+ knxdmxd::cue_channel_t channeldata;
+ channeldata.fixture = json_object_get_string(fixt);
+ channeldata.name = json_object_get_string(chan);
+ channeldata.value = json_object_get_int(value);
+
+ // add
+ s.AddChannel(channeldata);
+ }
+
+
+ sceneList[sname] = s;
+ }
+
+ return;
+}
+
+int main(int argc, char **argv) {
+ int daemonize = 0;
+ int c;
+ //char *p;
+ char pidstr[255];
+
+ while ((c = getopt (argc, argv, "dp:u:c:")) != -1)
+ switch (c) {
+ case 'd':
+ daemonize = 1;
+ break;
+ case 'p':
+ pidfilename.assign(optarg);
+ break;
+ case 'u':
+ eibd_url.assign(optarg);
+ break;
+ case 'c':
+ conf_file.assign(optarg);
+ break;
+ case '?':
+ //FIXME: check arguments better, print_usage
+ fprintf (stderr, "Unknown option `-%c'.\nUsage: %s %s", optopt, argv[0], USAGESTRING);
+ return 1;
+ default:
+ abort ();
+ }
+
+ //FIXME: clean shutdown in sub-thread with signals?
+ signal(SIGHUP, signal_handler);
+ signal(SIGTERM, signal_handler);
+ signal(SIGINT, signal_handler);
+ signal(SIGQUIT, signal_handler);
+
+ if (!daemonize) {
+ setlogmask(LOG_UPTO(LOG_DEBUG));
+ std::clog.rdbuf(new Log(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER));
+ std::clog << "startup with debug; pidfile: " << pidfilename << ", eibd: " << eibd_url << std::endl;
+ } else {
+ setlogmask(LOG_UPTO(LOG_INFO));
+ std::clog.rdbuf(new Log(DAEMON_NAME, LOG_CONS, LOG_USER));
+ }
+
+ std::clog << kLogInfo << "using config-file " << conf_file << std::endl;
+
+ load_config();
+
+ pid_t pid, sid;
+
+ if (daemonize) {
+ std::clog << kLogInfo << "starting daemon" << std::endl;
+
+ pid = fork();
+ if (pid < 0) {
+ exit(EXIT_FAILURE);
+ }
+ if (pid > 0) {
+ exit(EXIT_SUCCESS);
+ }
+ umask(0);
+ sid = setsid();
+ if (sid < 0) {
+ exit(EXIT_FAILURE);
+ }
+ if ((chdir("/")) < 0) {
+ exit(EXIT_FAILURE);
+ }
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+ }
+ //FIXME: output errors to stderr, change order
+ pidFilehandle = open((char *)pidfilename.c_str(), O_RDWR|O_CREAT, 0600);
+ if (pidFilehandle == -1 )
+ {
+ std::clog << kLogInfo << "Could not open pidfile " << pidfilename << ", exiting" << std::endl;
+ fprintf(stderr, "Could not open pidfile %s, exiting", (char *)pidfilename.c_str());
+ exit(EXIT_FAILURE);
+ }
+ if (lockf(pidFilehandle,F_TLOCK,0) == -1)
+ {
+ std::clog << kLogInfo << "Could not lock pidfile " << pidfilename << ", exiting" << std::endl;
+ fprintf(stderr, "Could not lock pidfile %s, exiting", (char *)pidfilename.c_str());
+ exit(EXIT_FAILURE);
+ }
+ sprintf(pidstr,"%d\n",getpid());
+ c = write(pidFilehandle, pidstr, strlen(pidstr));
+
+ int knxthread, olathread, workerthread;
+ pthread_t threads[NUM_THREADS];
+ // PTHREAD_CREATE_DETACHED?
+ knxthread = pthread_create(&threads[1], NULL, knxhandler, NULL); //id, thread attributes, subroutine, arguments
+ olathread = pthread_create(&threads[2], NULL, olahandler, NULL); //id, thread attributes, subroutine, arguments
+ workerthread = pthread_create(&threads[3], NULL, worker, NULL); //id, thread attributes, subroutine, arguments
+ std::clog << "Threads created: " << knxthread << " " << olathread << " " << workerthread << std::endl;
+ //TODO: Maybe another console/TCP-server/Logging thread?
+ while (1) {
+// std::clog << DAEMON_NAME << " daemon running" << std::endl;
+ sleep(POLLING_INTERVAL*1000);
+ }
+ std::clog << kLogInfo << DAEMON_NAME << " daemon exiting" << std::endl;
+ // TODO: Free any allocated resources before exiting - we never get here though -> signal handler
+ exit(EXIT_SUCCESS);
+}
Deleted: tools/knxdmxd/src/knxdmxd.cpp
===================================================================
--- tools/knxdmxd/src/knxdmxd.cpp 2012-05-11 18:16:06 UTC (rev 808)
+++ tools/knxdmxd/src/knxdmxd.cpp 2012-05-11 18:24:37 UTC (rev 809)
@@ -1,653 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
-/*
- * knxdmxd.c
- * Copyright (C) Jan N. Klug 2012 <jan...@ru...>
- * Daemon skeleton by Michael Markstaller 2011 <de...@wi...>
- *
- * knxdmxd is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * knxdmxd is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <string.h>
-#include <signal.h>
-#include <getopt.h>
-#include <json/json.h>
-
-#include <ola/Logging.h>
-#include <ola/DmxBuffer.h>
-#include <ola/StreamingClient.h>
-#includ...
[truncated message content] |
|
From: <ma...@us...> - 2012-05-11 19:12:56
|
Revision: 810
http://openautomation.svn.sourceforge.net/openautomation/?rev=810&view=rev
Author: makki1
Date: 2012-05-11 19:12:49 +0000 (Fri, 11 May 2012)
Log Message:
-----------
Package and small Makefile-fix
Modified Paths:
--------------
tools/knxdmxd/debian/changelog
tools/knxdmxd/debian/files
tools/knxdmxd/src/Makefile.am
Added Paths:
-----------
tools/knxdmxd/README
Added: tools/knxdmxd/README
===================================================================
--- tools/knxdmxd/README (rev 0)
+++ tools/knxdmxd/README 2012-05-11 19:12:49 UTC (rev 810)
@@ -0,0 +1 @@
+Further describe this program ;)
\ No newline at end of file
Modified: tools/knxdmxd/debian/changelog
===================================================================
--- tools/knxdmxd/debian/changelog 2012-05-11 18:24:37 UTC (rev 809)
+++ tools/knxdmxd/debian/changelog 2012-05-11 19:12:49 UTC (rev 810)
@@ -1,3 +1,9 @@
+knxdmxd (0.1-2) unstable; urgency=low
+
+ * new SVN-version
+
+ -- Michael Markstaller / Elaborated Networks GmbH for WireGate <de...@wi...> Fri, 11 May 2012 21:01:39 +0200
+
knxdmxd (0.1) unstable; urgency=low
* Initial Release.
Modified: tools/knxdmxd/debian/files
===================================================================
--- tools/knxdmxd/debian/files 2012-05-11 18:24:37 UTC (rev 809)
+++ tools/knxdmxd/debian/files 2012-05-11 19:12:49 UTC (rev 810)
@@ -1 +1 @@
-knxdmxd_0.1_i386.deb unknown extra
+knxdmxd_0.1-2_i386.deb unknown extra
Modified: tools/knxdmxd/src/Makefile.am
===================================================================
--- tools/knxdmxd/src/Makefile.am 2012-05-11 18:24:37 UTC (rev 809)
+++ tools/knxdmxd/src/Makefile.am 2012-05-11 19:12:49 UTC (rev 810)
@@ -8,4 +8,4 @@
# this lists the binaries to produce, the (non-PHONY, binary) targets in
# the previous manual Makefile
bin_PROGRAMS = knxdmxd
-knxdmxd_SOURCES = knxdmx.cc log.cc fixture.cc cue.cc
+knxdmxd_SOURCES = knxdmxd.cc log.cc fixture.cc cue.cc
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <j-...@us...> - 2012-05-13 15:47:40
|
Revision: 818
http://openautomation.svn.sourceforge.net/openautomation/?rev=818&view=rev
Author: j-n-k
Date: 2012-05-13 15:47:33 +0000 (Sun, 13 May 2012)
Log Message:
-----------
Added cuelists
Modified Paths:
--------------
tools/knxdmxd/knxdmxd.conf
tools/knxdmxd/src/Makefile.am
tools/knxdmxd/src/cue.cc
tools/knxdmxd/src/cue.h
tools/knxdmxd/src/fixture.cc
tools/knxdmxd/src/fixture.h
tools/knxdmxd/src/knxdmxd.cc
Added Paths:
-----------
tools/knxdmxd/src/cuelist.cc
tools/knxdmxd/src/cuelist.h
Modified: tools/knxdmxd/knxdmxd.conf
===================================================================
--- tools/knxdmxd/knxdmxd.conf 2012-05-13 10:36:15 UTC (rev 817)
+++ tools/knxdmxd/knxdmxd.conf 2012-05-13 15:47:33 UTC (rev 818)
@@ -1,86 +1,96 @@
-{ "fixtures": [
- { "name" : "Treppe",
- "channels" : [
- { "name": "oben",
- "dmx" : "1.0",
- "knx" : "1/7/170"
- },
- { "name": "mitte",
- "knx" : "1/7/170",
- "dmx" : "1.1"
- },
- { "name": "unten",
- "knx" : "1/7/170",
- "dmx" : "1.2"
- }
+// CAUTION : never uses names starting with _ !!! These are used internally !
+{ "fixtures": [ // all fixture definitions
+ { "name" : "Treppe", // name is optional, default is _f_<number>
+ "channels" : [ // channel definition, dmx is mandatory, default name is _c_<number>
+ { "name": "oben", "dmx" : "1.0", "knx" : "1/7/170" },
+ { "name": "mitte", "knx" : "1/7/170", "dmx" : "1.1" },
+ { "name": "unten", "knx" : "1/7/170", "dmx" : "1.2" }
],
- "fading" : {
- "knx" : "1/6/170",
- "time": "10"
- }
+ "fading" : { "knx" : "1/6/170", "time": 10 } // knx-like dimming: fading is calculated for 0-100%
},
{ "name" : "Kueche",
"channels" : [
- { "name": "R",
- "knx" : "1/7/141",
- "dmx" : "1.10"
- },
- { "name": "G",
- "knx" : "1/7/142",
- "dmx" : "1.11"
- },
- { "name": "B",
- "knx" : "1/7/143",
- "dmx" : "1.12"
- }
+ { "name": "R", "knx" : "1/7/141", "dmx" : "1.10" },
+ { "name": "G", "knx" : "1/7/142", "dmx" : "1.11" },
+ { "name": "B", "knx" : "1/7/143", "dmx" : "1.12" }
],
+ "fading" : { "knx" : "1/6/141", "time": 3.0 }
+ }
+],
+"scenes": [ // all scene definitions
+ { "name" : "Treppe_Full_On", // name is optional, default is _s_<number>
+ "trigger" : { "knx" : "1/0/170", "call" : 1 }, // if call is omitted, scene is called on any value
+ "channels" : [ // definition of each channel in scene
+ { "fixture" : "Treppe", "channel" : "oben", "value" : 255 },
+ { "fixture" : "Treppe", "channel" : "mitte", "value" : 255 },
+ { "fixture" : "Treppe", "channel" : "unten", "value" : 255 }
+ ],
+ "fading" : { // all fading times used on scene call !
+ "in" : 5.0, // for increasing intensity
+ "out": 5.0, // for decreasing intensity
+ }
+ },
+ { "name" : "Treppe_Blackout",
+ "trigger" : { "knx" : "1/0/170", "call" : 0 },
+ "channels" : [
+ { "fixture" : "Treppe", "channel" : "oben", "value" : 0 },
+ { "fixture" : "Treppe", "channel" : "mitte", "value" : 0 },
+ { "fixture" : "Treppe", "channel" : "unten", "value" : 0 }
+ ],
"fading" : {
- "knx" : "1/6/141",
- "time": "3.0"
+ "time" : 2 // used for in and out
}
},
- { "name" : "Test"
- } ],
-"scenes": [
- { "name" : "Treppe_Full_On",
- "trigger" : {
- "knx" : "1/0/170",
- "call" : 1
- },
+ { "name" : "Treppe_Test",
+ "trigger" : { "knx" : "1/0/171", "call" : 0 },
"channels" : [
- { "fixture" : "Treppe",
- "channel" : "oben",
- "value" : 255
- },
- { "fixture" : "Treppe",
- "channel" : "mitte",
- "value" : 255
- },
- { "fixture" : "Treppe",
- "channel" : "unten",
- "value" : 255
- }
+ { "fixture" : "Treppe", "channel" : "oben", "value" : 255 },
+ { "fixture" : "Treppe", "channel" : "mitte", "value" : 128 },
+ { "fixture" : "Treppe", "channel" : "unten", "value" : 0 }
],
+ "fading" : {
+ "in" : 10,
+ "out" : 0
+ }
},
- {
- "name" : "Treppe_Blackout",
- "trigger" : {
- "knx" : "1/0/170",
- "call" : 0
- },
+ { "name" : "Treppe_Middle",
+ "trigger" : { "knx" : "1/0/171", "call" : 1 },
"channels" : [
- { "fixture" : "Treppe",
- "channel" : "oben",
- "value" : 0
+ { "fixture" : "Treppe", "channel" : "oben", "value" : 128 },
+ { "fixture" : "Treppe", "channel" : "mitte", "value" : 128 },
+ { "fixture" : "Treppe", "channel" : "unten", "value" : 128 }
+ ]
+ },
+],
+"cuelists": [ // all cuelists
+ { "name" : "Treppe Disco",
+ "trigger" : { "knx" : "1/0/172", "go" : 1, "halt" : 0 },
+ "cues" : [ // cues are like scenes, just without individual triggers
+ { "name" : "Cue_1",
+ "channels" : [
+ { "fixture" : "Treppe", "channel" : "oben", "value" : 128 },
+ { "fixture" : "Treppe", "channel" : "mitte", "value" : 128 },
+ { "fixture" : "Treppe", "channel" : "unten", "value" : 128 }
+ ],
+
},
- { "fixture" : "Treppe",
- "channel" : "mitte",
- "value" : 0
+ { "name" : "Cue_2",
+ "channels" : [
+ { "fixture" : "Treppe", "channel" : "oben", "value" : 255 },
+ { "fixture" : "Treppe", "channel" : "mitte", "value" : 255 },
+ { "fixture" : "Treppe", "channel" : "unten", "value" : 255 }
+ ],
+ "waittime" : 10 // waittime start after calling previous cue !
},
- { "fixture" : "Treppe",
- "channel" : "unten",
- "value" : 0
+ { "name" : "Cue_3",
+ "channels" : [
+ { "fixture" : "Treppe", "channel" : "oben", "value" : 0 },
+ { "fixture" : "Treppe", "channel" : "mitte", "value" : 0 },
+ { "fixture" : "Treppe", "channel" : "unten", "value" : 0 }
+ ],
+ "waittime" : 10
}
]
- } ]
-}
+ }
+]
+ }
Modified: tools/knxdmxd/src/Makefile.am
===================================================================
--- tools/knxdmxd/src/Makefile.am 2012-05-13 10:36:15 UTC (rev 817)
+++ tools/knxdmxd/src/Makefile.am 2012-05-13 15:47:33 UTC (rev 818)
@@ -8,4 +8,4 @@
# this lists the binaries to produce, the (non-PHONY, binary) targets in
# the previous manual Makefile
bin_PROGRAMS = knxdmxd
-knxdmxd_SOURCES = knxdmxd.cc log.cc fixture.cc cue.cc
+knxdmxd_SOURCES = knxdmxd.cc log.cc fixture.cc cue.cc cuelist.cc
Modified: tools/knxdmxd/src/cue.cc
===================================================================
--- tools/knxdmxd/src/cue.cc 2012-05-13 10:36:15 UTC (rev 817)
+++ tools/knxdmxd/src/cue.cc 2012-05-13 15:47:33 UTC (rev 818)
@@ -13,6 +13,8 @@
Cue::Cue(const std::string name) {
_name=name;
+ _fadeIn = 0.0;
+ _fadeOut = 0.0;
std::clog << "Creating Cue '" << name << "'" << std::endl;
}
@@ -20,7 +22,7 @@
_triggerKNX = KNX;
_trigger_val = val;
- std::clog << kLogDebug << "Cue '" << _name << "': Trigger by KNX:" << _triggerKNX << ", value " << _trigger_val << ((_trigger_val==-1) ? " (all)" : "") << std::endl;
+ std::clog << kLogDebug << "Cue '" << _name << "': added trigger by KNX:" << _triggerKNX << ", value " << _trigger_val << ((_trigger_val==-1) ? " (all)" : "") << std::endl;
std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> alreadypatched;
alreadypatched = patchMap.equal_range(KNX);
@@ -36,18 +38,45 @@
AddTrigger(patchMap, readgaddr(KNX), val);
}
-void Cue::AddChannel(cue_channel_t channel) {
+void Cue::AddChannel(const cue_channel_t& channel) {
_channel_data.push_back(channel);
- std::clog << "Added Channel definition " << channel.fixture << "/" << channel.name << "@" << channel.value << std::endl;
+ std::clog << "Cue '" << _name << "': added channel definition " << channel.fixture << "/" << channel.name << "@" << channel.value << std::endl;
}
+void Cue::SetFading(const float fadeIn, const float fadeOut) {
+ _fadeIn = fadeIn;
+ _fadeOut = (fadeOut < 0) ? fadeIn : fadeOut;
+ std::clog << kLogDebug << "Cue '" << _name << "': set fading " << _fadeIn << "/" << _fadeOut << std::endl;
+}
+
+void Cue::Update(std::map<std::string, knxdmxd::Fixture>& fixtureList) {
+ for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
+ knxdmxd::Fixture& f = fixtureList[it->fixture];
+ int currentValue = f.GetCurrentValue(it->name);
+ int deltaVal = currentValue - it->value;
+ float ft = (deltaVal>0) ? (deltaVal/(_fadeOut*1.e6/FADING_INTERVAL)) : (-deltaVal/(_fadeIn*1.e6/FADING_INTERVAL));
+ f.Update(it->name, it->value, (float)ft);
+ }
+ std::clog << "Called cue " << _name << std::endl;
+}
+
void Cue::Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val) {
if ((_trigger_val==-1) || (_trigger_val==val)) {
- for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
- fixtureList[it->fixture].Update(it->name, it->value, (float)255.);
- }
- std::clog << "Called cue " << _name << std::endl;
+ Update(fixtureList);
}
}
+std::string Cue::GetName() {
+ return _name;
}
+
+float Cue::GetWaitTime() {
+ return _waittime;
+}
+
+void Cue::SetWaittime(const float waittime) {
+ _waittime = waittime;
+ std::clog << kLogDebug << "Cue '" << _name << "': set waittime " << _waittime << std::endl;
+}
+
+}
Modified: tools/knxdmxd/src/cue.h
===================================================================
--- tools/knxdmxd/src/cue.h 2012-05-13 10:36:15 UTC (rev 817)
+++ tools/knxdmxd/src/cue.h 2012-05-13 15:47:33 UTC (rev 818)
@@ -27,17 +27,24 @@
Cue() {};
Cue(const std::string name);
- void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, int KNX, int val);
- void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, std::string KNX, int val);
- void AddChannel(cue_channel_t channel);
+ void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const int KNX, const int val);
+ void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const std::string KNX, const int val);
+ void AddChannel(const cue_channel_t& channel);
+ void SetFading(const float fadeIn, const float fadeOut=-1);
+ void SetWaittime(const float waittime);
+ void Update(std::map<std::string, knxdmxd::Fixture>& fixtureList);
+ void Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val);
+
+ std::string GetName();
+ float GetWaitTime();
- void Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val);
-
private:
std::string _name;
int _triggerKNX;
int _trigger_val;
std::list<cue_channel_t> _channel_data;
+ float _fadeIn, _fadeOut;
+ float _waittime;
};
Added: tools/knxdmxd/src/cuelist.cc
===================================================================
--- tools/knxdmxd/src/cuelist.cc (rev 0)
+++ tools/knxdmxd/src/cuelist.cc 2012-05-13 15:47:33 UTC (rev 818)
@@ -0,0 +1,80 @@
+/*
+ * cuelist.cc
+ *
+ * (c) by JNK 2012
+ *
+ *
+*/
+
+
+#include "cuelist.h"
+
+namespace knxdmxd {
+
+Cuelist::Cuelist(const std::string name) {
+ _name=name;
+ _current_cue=-1;
+ _next_cue_start=-1;
+ std::clog << "Creating Cuelist '" << name << "'" << std::endl;
+}
+
+void Cuelist::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, int KNX, int val) {
+ _triggerKNX = KNX;
+ _trigger_val = val;
+
+ std::clog << kLogDebug << "Cuelist '" << _name << "': added trigger by KNX:" << _triggerKNX << ", value " << _trigger_val << ((_trigger_val==-1) ? " (all)" : "") << std::endl;
+
+ std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> alreadypatched;
+ alreadypatched = patchMap.equal_range(KNX);
+
+ for (knxdmxd::knx_patch_map_t::iterator it = alreadypatched.first; it != alreadypatched.second; ++it) {
+ if (it->second == _name) return; // already patched that one
+ }
+
+ patchMap.insert(knxdmxd::knx_patch_map_element_t(KNX,_name)); // no, add to patchMap
+}
+
+void Cuelist::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, std::string KNX, int val) {
+ AddTrigger(patchMap, readgaddr(KNX), val);
+}
+
+
+void Cuelist::AddCue(knxdmxd::Cue& cue) {
+ _cue_data.push_back(cue);
+ std::clog << "Cuelist '" << _name << "': added cue " << cue.GetName() << " as #" << _cue_data.size()-1 << std::endl;
+}
+
+void Cuelist::NextCue(std::map<std::string, knxdmxd::Fixture>& fixtureList, const unsigned long long loopCounter) {
+ if (_cue_data.size()>(_current_cue+1)) {
+ _current_cue++;
+ _cue_data.at(_current_cue).Update(fixtureList);
+ float waittime;
+ if (_cue_data.size()>(_current_cue+1)) { // last cue stops automatically
+ waittime = _cue_data.at(_current_cue+1).GetWaitTime();
+ } else {
+ waittime = -1;
+ }
+ if (waittime>=0) { // if waittime < 0 : manual trigger
+ _next_cue_start = loopCounter + (int) (waittime*1.e6/FADING_INTERVAL);
+ } else {
+ _next_cue_start = -1;
+ }
+ } else {
+ _current_cue = -1;
+ _next_cue_start = -1;
+ }
+}
+
+void Cuelist::Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val, const unsigned long long loopCounter) {
+ if ((_trigger_val==-1) || (_trigger_val==val)) {
+ NextCue(fixtureList, loopCounter);
+ }
+}
+
+void Cuelist::Refresh(std::map<std::string, knxdmxd::Fixture>& fixtureList, const unsigned long long loopCounter) {
+ if ((loopCounter>_next_cue_start) && (_next_cue_start>0)) { // if next_cue_start < 0 : manual trigger
+ NextCue(fixtureList, loopCounter);
+ }
+}
+
+}
Added: tools/knxdmxd/src/cuelist.h
===================================================================
--- tools/knxdmxd/src/cuelist.h (rev 0)
+++ tools/knxdmxd/src/cuelist.h 2012-05-13 15:47:33 UTC (rev 818)
@@ -0,0 +1,47 @@
+/*
+ * cuelist.h
+ *
+ * (c) by JNK 2012
+ *
+ *
+*/
+
+#ifndef CUELIST_H
+#define CUELIST_H
+
+#include <string.h>
+#include <knxdmxd.h>
+#include <deque>
+#include <fixture.h>
+#include <cue.h>
+
+namespace knxdmxd {
+
+class Cuelist {
+ public:
+ Cuelist() {};
+ Cuelist(const std::string name);
+
+ void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const int KNX, const int val);
+ void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const std::string KNX, const int val);
+ void AddCue(knxdmxd::Cue& cue);
+
+ void Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val, const unsigned long long loopCounter);
+ void Refresh(std::map<std::string, knxdmxd::Fixture>& fixtureList, const unsigned long long loopCounter);
+
+ private:
+ void NextCue(std::map<std::string, knxdmxd::Fixture>& fixtureList, const unsigned long long loopCounter);
+
+ std::string _name;
+ int _triggerKNX;
+ int _trigger_val;
+ int _current_cue;
+ unsigned long long _next_cue_start;
+ std::deque<knxdmxd::Cue> _cue_data;
+
+};
+
+
+}
+
+#endif
Modified: tools/knxdmxd/src/fixture.cc
===================================================================
--- tools/knxdmxd/src/fixture.cc 2012-05-13 10:36:15 UTC (rev 817)
+++ tools/knxdmxd/src/fixture.cc 2012-05-13 15:47:33 UTC (rev 818)
@@ -47,7 +47,7 @@
_fadeTimeKNX = KNX;
}
-void Fixture::Update(std::string channel, const int val, bool direct) {
+void Fixture::Update(const std::string& channel, const int val, bool direct) {
_channelValue[channel] = val;
_channelFadeStep[channel] = direct ? 256 : _fadeStep;
std::clog << "Fixture '" << _name << "': Channel '" << channel << "' @ " << val << ", direct: " << ((direct) ? "true" : "false") << std::endl;
@@ -59,16 +59,16 @@
}
}
-void Fixture::Update(std::string channel, const int val, float fadeStep) {
+void Fixture::Update(const std::string& channel, const int val, float fadeStep) {
_channelValue[channel] = val;
_channelFadeStep[channel] = fadeStep;
- std::clog << "Fixture '" << _name << "': Channel '" << channel << "' @ " << val << ", fading: " << fadeStep << std::endl;
+ std::clog << "Fixture '" << _name << "': Channel '" << channel << "' @ " << _channelValue[channel] << ", fading: " << fadeStep << " old: "<< _channelFloatValue[channel] << std::endl;
}
void Fixture::Refresh(std::map<int, ola::DmxBuffer>& output) {
for(std::map<std::string, int>::const_iterator i = _channelDMX.begin(); i != _channelDMX.end(); ++i) {
- int dmxuniverse = (int) (i->second / 512) , dmxchannel = i->second % 512;
+ int dmxuniverse = (int) (i->second / 512), dmxchannel = i->second % 512;
int oldValue = output[dmxuniverse].Get(dmxchannel);
int newValue = _channelValue[i->first];
if (oldValue<newValue) {
@@ -77,7 +77,7 @@
_channelFloatValue[i->first] = newValue;
}
output[dmxuniverse].SetChannel(dmxchannel, (int) _channelFloatValue[i->first]);
- std::clog << "Fade: " << dmxuniverse << "." << dmxchannel << " @ " << _channelFloatValue[i->first] << std::endl;
+ //std::clog << "Fade: " << dmxuniverse << "." << dmxchannel << " @ " << _channelFloatValue[i->first] << std::endl;
}
if (oldValue>newValue) {
_channelFloatValue[i->first] -= _channelFadeStep[i->first];
@@ -85,9 +85,12 @@
_channelFloatValue[i->first] = newValue;
}
output[dmxuniverse].SetChannel(dmxchannel, (int) _channelFloatValue[i->first]);
- std::clog << "Fade: " << dmxuniverse << "." << dmxchannel << " @ " << _channelFloatValue[i->first] << std::endl;
+ //std::clog << "Fade: " << dmxuniverse << "." << dmxchannel << " @ " << _channelFloatValue[i->first] << std::endl;
}
}
}
+int Fixture::GetCurrentValue(const std::string& channel) {
+ return (int) _channelFloatValue.find(channel)->second;
}
+}
Modified: tools/knxdmxd/src/fixture.h
===================================================================
--- tools/knxdmxd/src/fixture.h 2012-05-13 10:36:15 UTC (rev 817)
+++ tools/knxdmxd/src/fixture.h 2012-05-13 15:47:33 UTC (rev 818)
@@ -23,10 +23,11 @@
void Patch(knxdmxd::knx_patch_map_t& patchMap, const std::string channel, const std::string DMX, const std::string KNX);
void SetFadeTime(const float t);
void PatchFadeTime(const int KNX);
- void Update(std::string channel, const int val, const bool direct=false);
- void Update(std::string channel, const int val, const float fadeStep);
+ void Update(const std::string& channel, const int val, const bool direct=false);
+ void Update(const std::string& channel, const int val, const float fadeStep);
void Update(const int KNX, const int val, const bool direct=false);
void Refresh(std::map<int, ola::DmxBuffer>& output);
+ int GetCurrentValue(const std::string& channel);
private:
std::string _name;
std::map <std::string, int> _channelKNX;
Modified: tools/knxdmxd/src/knxdmxd.cc
===================================================================
--- tools/knxdmxd/src/knxdmxd.cc 2012-05-13 10:36:15 UTC (rev 817)
+++ tools/knxdmxd/src/knxdmxd.cc 2012-05-13 15:47:33 UTC (rev 818)
@@ -45,6 +45,7 @@
#include <fixture.h>
#include <cue.h>
+#include <cuelist.h>
#define DEBUG 1
#define DAEMON_NAME "knxdmxd"
@@ -101,13 +102,16 @@
std::string conf_file = "knxdmxd.conf";
int pidFilehandle;
std::string pidfilename = "/var/run/dmxknxd.pid";
+unsigned long long loopCounter = 0;
std::map<int, ola::DmxBuffer> dmxWriteBuffer;
std::map<std::string, knxdmxd::Fixture> fixtureList;
std::map<std::string, knxdmxd::Cue> sceneList;
+std::map<std::string, knxdmxd::Cuelist> cuelistList;
knxdmxd::knx_patch_map_t KNX_fixture_patchMap;
knxdmxd::knx_patch_map_t KNX_scene_patchMap;
+knxdmxd::knx_patch_map_t KNX_cuelist_patchMap;
//map<int, channel> DMXpatchMap;
@@ -141,9 +145,14 @@
void refresh_output(int signo)
{
+ loopCounter++;
for(std::map<std::string, knxdmxd::Fixture>::const_iterator i = fixtureList.begin(); i != fixtureList.end(); ++i) {
fixtureList[i->first].Refresh(dmxWriteBuffer);
}
+ for(std::map<std::string, knxdmxd::Cuelist>::const_iterator i = cuelistList.begin(); i != cuelistList.end(); ++i) {
+ cuelistList[i->first].Refresh(fixtureList, loopCounter);
+ }
+
signal(SIGALRM, refresh_output);
}
@@ -194,7 +203,7 @@
std::clog << "Received " << (int)val << " @ " << dest << ", updated " << unum << " fixtures" << std::endl;
}
if (KNX_scene_patchMap.count(dest)>0) {
- std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> uScenes; // fixtures that handle this
+ std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> uScenes; // scenes that handle this
uScenes = KNX_scene_patchMap.equal_range(dest);
int unum=0;
for (knxdmxd::knx_patch_map_t::iterator it = uScenes.first; it != uScenes.second; ++it)
@@ -204,9 +213,18 @@
}
std::clog << "Received " << (int) val << " @ " << dest << ", checked " << unum << " scenes" << std::endl;
}
-
-
- }
+ if (KNX_cuelist_patchMap.count(dest)>0) {
+ std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> uCuelists; // scenes that handle this
+ uCuelists = KNX_cuelist_patchMap.equal_range(dest);
+ int unum=0;
+ for (knxdmxd::knx_patch_map_t::iterator it = uCuelists.first; it != uCuelists.second; ++it)
+ {
+ cuelistList[it->second].Update(fixtureList, dest, val, loopCounter);
+ unum++;
+ }
+ std::clog << "Received " << (int) val << " @ " << dest << ", checked " << unum << " cuelists" << std::endl;
+ }
+ }
break;
}
return 0;
@@ -294,7 +312,7 @@
std::clog << kLogWarning << "eibd: Unknown APDU from "<< src << " to " << dest << std::endl;
break;
} else {
- if ( (KNX_fixture_patchMap.count(dest)+KNX_scene_patchMap.count(dest))<=0 ) //not for us
+ if ( (KNX_fixture_patchMap.count(dest)+KNX_scene_patchMap.count(dest)+KNX_cuelist_patchMap.count(dest))<=0 ) //not for us
continue;
handleKNXdgram(dest,buf,len);
}
@@ -312,11 +330,14 @@
config = json_object_from_file((char *)conf_file.c_str());
- // first all fixtures
+ /*
+ * fixtures
+ */
+
struct json_object *fixtures = json_object_object_get(config, "fixtures");
int fixturenum = json_object_array_length(fixtures);
- std::clog << "Trying to import " << fixturenum << " fixtures" << std::endl;
-
+ std::clog << "Trying to import " << fixturenum << " fixture(s)" << std::endl;
+
for (int i=0; i<fixturenum; i++) { // read all
// get fixture
struct json_object *fixture = json_object_array_get_idx(fixtures, i);
@@ -366,9 +387,13 @@
fixtureList[fname] = f;
}
+ /*
+ * scenes
+ */
+
struct json_object *scenes = json_object_object_get(config, "scenes");
int scenenum = json_object_array_length(scenes);
- std::clog << "Trying to import " << scenenum << " scenes" << std::endl;
+ std::clog << "Trying to import " << scenenum << " scene(s)" << std::endl;
for (int i=0; i<scenenum; i++) { // read all
struct json_object *scene = json_object_array_get_idx(scenes, i);
@@ -407,7 +432,7 @@
struct json_object *value = json_object_object_get(channel, "value");
if ((!fixt) || (!chan) || (!value)) {
- std::clog << kLogInfo << "Skipping errorneous channel def " << j << "' in scene '" << sname << "'" << std::endl;
+ std::clog << kLogInfo << "Skipping errorneous channel def " << j << " in scene '" << sname << "'" << std::endl;
continue;
}
@@ -420,10 +445,103 @@
s.AddChannel(channeldata);
}
-
+ struct json_object *fading = json_object_object_get(scene, "fading");
+ if (fading) {
+ struct json_object *fading_time = json_object_object_get(fading, "time");
+ if (!fading_time) {
+ struct json_object *fading_time_in = json_object_object_get(fading, "in");
+ struct json_object *fading_time_out = json_object_object_get(fading, "out");
+
+ if ((!fading_time_in) || (!fading_time_out)) {
+ std::clog << kLogInfo << "Skipping errorneous fading def in scene '" << sname << "'" << std::endl;
+ } else {
+ float in = json_object_get_double(fading_time_in);
+ s.SetFading(in, json_object_get_double(fading_time_out));
+ }
+ } else {
+ s.SetFading(json_object_get_double(fading_time));
+ }
+ }
+
sceneList[sname] = s;
}
+ /*
+ * cuelists
+ */
+
+ struct json_object *cuelists = json_object_object_get(config, "cuelists");
+ int cuelistnum = json_object_array_length(cuelists);
+ std::clog << "Trying to import " << cuelistnum << " cuelist(s)" << std::endl;
+
+ for (int i=0; i<cuelistnum; i++) { // read all
+ struct json_object *cuelist = json_object_array_get_idx(cuelists, i);
+
+ // get name & create
+ struct json_object *name = json_object_object_get(cuelist, "name");
+ std::string cname = (name) ? json_object_get_string(name) : "_c_"+t_to_string(i);
+ knxdmxd::Cuelist c(cname);
+
+ // trigger is required
+ struct json_object *trigger = json_object_object_get(cuelist, "trigger");
+ struct json_object *trigger_knx = json_object_object_get(trigger, "knx");
+
+ if ((!trigger) || (!trigger_knx)) {
+ std::clog << kLogInfo << "Skipping cuelist '" << cname << "' (error in trigger)" << std::endl;
+ continue;
+ }
+
+ struct json_object *trigger_go = json_object_object_get(trigger, "go");
+ c.AddTrigger(KNX_cuelist_patchMap, json_object_get_string(trigger_knx), (trigger_go) ? json_object_get_int(trigger_go) : -1);
+
+ struct json_object *cues = json_object_object_get(cuelist, "cues");
+ int cuenum = json_object_array_length(cues);
+ for (int i=0; i<cuenum; i++) { // read all
+ struct json_object *cue = json_object_array_get_idx(cues, i);
+
+ struct json_object *name = json_object_object_get(cue, "name");
+ std::string c_name = (name) ? json_object_get_string(name) : cname+"_c_"+t_to_string(i);
+ knxdmxd::Cue c_(c_name);
+
+ struct json_object *waittime = json_object_object_get(cue, "waittime");
+ c_.SetWaittime((waittime) ? (float) json_object_get_double(waittime) : -1);
+
+ // get channels
+ struct json_object *channels = json_object_object_get(cue, "channels");
+ if (!channels) {
+ std::clog << kLogInfo << "Skipping cue '" << c_name << "' (no channels defined)" << std::endl;
+ continue;
+ }
+
+ int channelnum = json_object_array_length(channels);
+ for (int j=0; j<channelnum; j++) { // read all
+ // get channel
+ struct json_object *channel = json_object_array_get_idx(channels, j);
+
+ struct json_object *fixt = json_object_object_get(channel, "fixture");
+ struct json_object *chan = json_object_object_get(channel, "channel");
+ struct json_object *value = json_object_object_get(channel, "value");
+
+ if ((!fixt) || (!chan) || (!value)) {
+ std::clog << kLogInfo << "Skipping errorneous channel def " << j << " in cue '" << c_name << "'" << std::endl;
+ continue;
+ }
+
+ knxdmxd::cue_channel_t channeldata;
+ channeldata.fixture = json_object_get_string(fixt);
+ channeldata.name = json_object_get_string(chan);
+ channeldata.value = json_object_get_int(value);
+
+ // add
+ c_.AddChannel(channeldata);
+ }
+
+ c.AddCue(c_);
+ }
+
+ cuelistList[cname] = c;
+ }
+
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <j-...@us...> - 2012-05-28 18:11:41
|
Revision: 846
http://openautomation.svn.sourceforge.net/openautomation/?rev=846&view=rev
Author: j-n-k
Date: 2012-05-28 18:11:33 +0000 (Mon, 28 May 2012)
Log Message:
-----------
Mainly changes for cleaner code, testing std::thread (for makki)
Modified Paths:
--------------
tools/knxdmxd/README
tools/knxdmxd/knxdmxd
tools/knxdmxd/knxdmxd.conf
tools/knxdmxd/src/Makefile.am
tools/knxdmxd/src/cue.cc
tools/knxdmxd/src/cue.h
tools/knxdmxd/src/dmxsender.cc
tools/knxdmxd/src/dmxsender.h
tools/knxdmxd/src/fixture.cc
tools/knxdmxd/src/fixture.h
tools/knxdmxd/src/knxdmxd.cc
tools/knxdmxd/src/knxdmxd.h
tools/knxdmxd/src/log.cc
Added Paths:
-----------
tools/knxdmxd/src/trigger.cc
tools/knxdmxd/src/trigger.h
Removed Paths:
-------------
tools/knxdmxd/src/cuelist.cc
tools/knxdmxd/src/cuelist.h
Modified: tools/knxdmxd/README
===================================================================
--- tools/knxdmxd/README 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/README 2012-05-28 18:11:33 UTC (rev 846)
@@ -1 +1,3 @@
-Further describe this program ;)
\ No newline at end of file
+Further describe this program ;)
+
+Use ./configure "CXXFLAGS=-std=c++0x -O3 -pthread"
Modified: tools/knxdmxd/knxdmxd
===================================================================
(Binary files differ)
Modified: tools/knxdmxd/knxdmxd.conf
===================================================================
--- tools/knxdmxd/knxdmxd.conf 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/knxdmxd.conf 2012-05-28 18:11:33 UTC (rev 846)
@@ -6,7 +6,7 @@
{ "name": "mitte", "knx" : "1/7/170", "dmx" : "1.1" },
{ "name": "unten", "knx" : "1/7/170", "dmx" : "1.2" }
],
- "fading" : { "knx" : "1/6/170", "time": 10 } // knx-like dimming: fading is calculated for 0-100%
+ "fading" : { "knx" : "1/6/170", "time": 1 } // knx-like dimming: fading is calculated for 0-100%
},
{ "name" : "Kueche",
"channels" : [
@@ -19,15 +19,17 @@
],
"scenes": [ // all scene definitions
{ "name" : "Treppe_Full_On", // name is optional, default is _s_<number>
- "trigger" : { "knx" : "1/0/170", "call" : 1 }, // if call is omitted, scene is called on any value
+ "trigger" : {
+ "go" : { "knx" : "1/0/170", "value" : 1 }, // if value is omitted, scene is called on any value
+ },
"channels" : [ // definition of each channel in scene
{ "fixture" : "Treppe", "channel" : "oben", "value" : 255 },
{ "fixture" : "Treppe", "channel" : "mitte", "value" : 255 },
{ "fixture" : "Treppe", "channel" : "unten", "value" : 255 }
],
"fading" : { // all fading times used on scene call !
- "in" : 5.0, // for increasing intensity
- "out": 5.0, // for decreasing intensity
+ "in" : 1.0, // for increasing intensity
+ "out": 1.0, // for decreasing intensity
}
},
{ "name" : "Treppe_Blackout",
@@ -40,22 +42,8 @@
{ "fixture" : "Treppe", "channel" : "unten", "value" : 0 }
],
"fading" : {
- "time" : 2 // used for in and out
+ "time" : 1 // used for in and out
}
- },
- { "name" : "Treppe_FullOn",
- "trigger" : {
- "go" : { "knx" : "1/0/170", "value" : 1 },
- },
- "channels" : [
- { "fixture" : "Treppe", "channel" : "oben", "value" : 255 },
- { "fixture" : "Treppe", "channel" : "mitte", "value" : 255 },
- { "fixture" : "Treppe", "channel" : "unten", "value" : 255 }
- ],
- "fading" : {
- "in" : 10,
- "out" : 0
- }
}
],
"cuelists": [ // all cuelists
Modified: tools/knxdmxd/src/Makefile.am
===================================================================
--- tools/knxdmxd/src/Makefile.am 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/Makefile.am 2012-05-28 18:11:33 UTC (rev 846)
@@ -8,4 +8,4 @@
# this lists the binaries to produce, the (non-PHONY, binary) targets in
# the previous manual Makefile
bin_PROGRAMS = knxdmxd
-knxdmxd_SOURCES = knxdmxd.cc log.cc fixture.cc cue.cc cuelist.cc dmxsender.cc
+knxdmxd_SOURCES = knxdmxd.cc log.cc fixture.cc cue.cc dmxsender.cc trigger.cc
Modified: tools/knxdmxd/src/cue.cc
===================================================================
--- tools/knxdmxd/src/cue.cc 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/cue.cc 2012-05-28 18:11:33 UTC (rev 846)
@@ -24,33 +24,9 @@
}
}
-void Cue::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, int KNX, int val) {
- _triggerKNX = KNX;
- _trigger_val = val;
-
- std::clog << kLogDebug << "Cue '" << _name << "': added trigger by KNX:" << _triggerKNX << ", value " << _trigger_val << ((_trigger_val==-1) ? " (all)" : "") << std::endl;
-
- std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> alreadypatched;
- alreadypatched = patchMap.equal_range(KNX);
-
- for (knxdmxd::knx_patch_map_t::iterator it = alreadypatched.first; it != alreadypatched.second; ++it) {
- if (it->second == _name) return; // already patched that one
- }
-
- patchMap.insert(knxdmxd::knx_patch_map_element_t(KNX,_name)); // no, add to patchMap
-}
-
-void Cue::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, std::string KNX, int val) {
- AddTrigger(patchMap, readgaddr(KNX), val);
-}
-
-void Cue::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const knxdmxd::Trigger trigger) {
- AddTrigger(patchMap, trigger.knx, trigger.value);
-}
-
void Cue::AddChannel(const cue_channel_t& channel) {
_channel_data.push_back(channel);
- std::clog << "Cue '" << _name << "': added channel definition " << channel.fixture << "/" << channel.name << "@" << channel.value << std::endl;
+ std::clog << "Cue '" << _name << "': added channel definition " << channel.fixture->GetName() << "/" << channel.name << "@" << channel.value << std::endl;
}
void Cue::SetFading(const float fadeIn, const float fadeOut) {
@@ -68,38 +44,77 @@
std::clog << kLogDebug << "Cue '" << _name << "': set fading " << _fadeIn << "/" << _fadeOut << std::endl;
}
-void Cue::Update(std::map<std::string, knxdmxd::Fixture>& fixtureList) {
+void Cue::SetWaittime(const float waittime) {
+ _waittime = waittime;
+ std::clog << kLogDebug << "Cue '" << _name << "': set waittime " << _waittime << std::endl;
+}
+
+bool Cue::isLink() {
+ return _is_link;
+}
+
+void Cue::Go() {
+ std::clog << kLogDebug << "Cue '" << _name << "': go " << std::endl;
for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
- knxdmxd::Fixture& f = fixtureList[it->fixture];
- int currentValue = f.GetCurrentValue(it->name);
+ int currentValue = it->fixture->GetCurrentValue(it->name);
int deltaVal = currentValue - it->value;
float ft = (deltaVal>0) ? (deltaVal/(_fadeOut*1.e6/FADING_INTERVAL)) : (-deltaVal/(_fadeIn*1.e6/FADING_INTERVAL));
- f.Update(it->name, it->value, (float)ft);
+ it->fixture->Update(it->name, it->value, (float)ft);
}
std::clog << "Called cue " << _name << std::endl;
}
-void Cue::Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val, const int loopCounter) {
- if ((_trigger_val==-1) || (_trigger_val==val)) {
- Update(fixtureList);
- }
+Cuelist::Cuelist(const std::string name) {
+ _name=name;
+ _current_cue=-1;
+ _cue_halted=true;
+ std::clog << "Creating Cuelist '" << name << "'" << std::endl;
}
-const std::string Cue::GetName() {
- return _name;
+void Cuelist::AddCue(knxdmxd::Cue& cue) {
+ _cue_data.push_back(cue);
+ int cue_num = _cue_data.size()-1;
+ if (!cue.isLink()) {
+ _cue_names.insert(std::pair<std::string, int>(cue.GetName(), cue_num));
+ std::clog << "Cuelist '" << _name << "': added cue " << cue.GetName() << " as #" << _cue_data.size()-1 << std::endl;
+ } else {
+ std::clog << "Cuelist '" << _name << "': added link to cue '" << cue.GetName() << "' as #" << _cue_data.size()-1 << std::endl;
+ }
}
-const float Cue::GetWaitTime() {
- return _waittime;
+void Cuelist::NextCue() {
+ if (_cue_data.size()>(_current_cue+1)) {
+ _current_cue++;
+ knxdmxd::Cue cue = _cue_data.at(_current_cue);
+ if (cue.isLink()) {
+ _current_cue = _cue_names.find(cue.GetName())->second;
+ }
+
+ _cue_data.at(_current_cue).Go();
+
+ float waittime;
+ int nextCuenum = _current_cue+1;
+ if (_cue_data.size()>nextCuenum) { // last cue stops automatically
+ knxdmxd::Cue nextCue = _cue_data.at(nextCuenum);
+ if (nextCue.isLink()) {
+ nextCuenum = _cue_names.find(nextCue.GetName())->second;
+ nextCue = _cue_data.at(nextCuenum);
+ }
+ waittime = nextCue.GetWaitTime();
+ if ((waittime>=0 && !_cue_halted)) {
+ DMXSender::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
+ (int) waittime*1000, ola::NewSingleCallback(this, &Cuelist::NextCue));
+ }
+ }
+ }
}
-void Cue::SetWaittime(const float waittime) {
- _waittime = waittime;
- std::clog << kLogDebug << "Cue '" << _name << "': set waittime " << _waittime << std::endl;
+void Cuelist::Go() {
+ _cue_halted=false;
+ NextCue();
}
-bool Cue::isLink() {
- return _is_link;
+void Cuelist::Halt() {
+ _cue_halted=true;
}
-
}
Modified: tools/knxdmxd/src/cue.h
===================================================================
--- tools/knxdmxd/src/cue.h 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/cue.h 2012-05-28 18:11:33 UTC (rev 846)
@@ -13,45 +13,55 @@
#include <knxdmxd.h>
#include <list>
#include <fixture.h>
+#include <trigger.h>
+#include <dmxsender.h>
namespace knxdmxd {
-typedef struct {
- std::string fixture;
- std::string name;
- int value;
-} cue_channel_t;
+ typedef struct {
+ pFixture fixture;
+ std::string name;
+ int value;
+ } cue_channel_t;
-class Cue {
- public:
- Cue() {};
- Cue(const std::string name, const bool isLink=false);
+ class Cue : public TriggerHandler {
+ std::list<cue_channel_t> _channel_data;
+ float _fadeIn, _fadeOut;
+ float _waittime;
+ bool _is_link;
- void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const int KNX, const int val);
- void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const std::string KNX, const int val);
- void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const knxdmxd::Trigger trigger);
- void AddChannel(const cue_channel_t& channel);
- void SetFading(const float fadeIn, const float fadeOut=-1);
- void SetWaittime(const float waittime);
- void Update(std::map<std::string, knxdmxd::Fixture>& fixtureList);
- void Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val, const int loopCounter);
+ public:
+ Cue() {};
+ Cue(const std::string name, const bool isLink=false);
- const std::string GetName();
- const float GetWaitTime();
+ void AddChannel(const cue_channel_t& channel);
+ void SetFading(const float fadeIn, const float fadeOut=-1);
+ void SetWaittime(const float waittime);
- bool isLink();
-
- private:
- std::string _name;
- int _triggerKNX;
- int _trigger_val;
- std::list<cue_channel_t> _channel_data;
- float _fadeIn, _fadeOut;
- float _waittime;
- bool _is_link;
-};
+ const std::string GetName() { return _name; };
+ const float GetWaitTime() { return _waittime; };
+ virtual void Go();
+ bool isLink();
+ };
+ class Cuelist : public TriggerHandler {
+ int _current_cue;
+ bool _cue_halted;
+ std::vector<knxdmxd::Cue> _cue_data;
+ std::map<std::string, int> _cue_names;
+
+ void NextCue();
+
+ public:
+ Cuelist() {};
+ Cuelist(const std::string name);
+
+ void AddCue(knxdmxd::Cue& cue);
+ void Go();
+ void Halt();
+ };
+
}
#endif
Deleted: tools/knxdmxd/src/cuelist.cc
===================================================================
--- tools/knxdmxd/src/cuelist.cc 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/cuelist.cc 2012-05-28 18:11:33 UTC (rev 846)
@@ -1,125 +0,0 @@
-/*
- * cuelist.cc
- *
- * (c) by JNK 2012
- *
- *
-*/
-
-
-#include "cuelist.h"
-
-namespace knxdmxd {
-
-Cuelist::Cuelist(const std::string name) {
- _name=name;
- _current_cue=-1;
- _next_cue_start=-1;
- std::clog << "Creating Cuelist '" << name << "'" << std::endl;
-}
-
-void Cuelist::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, int KNX, int val) {
- _go_trigger_knx = KNX;
- _go_trigger_val = val;
-
- std::clog << kLogDebug << "Cuelist '" << _name << "': added trigger by KNX:" << _go_trigger_knx << ", value " << _go_trigger_val << ((_go_trigger_val==-1) ? " (all)" : "") << std::endl;
-
- std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> alreadypatched;
- alreadypatched = patchMap.equal_range(KNX);
-
- for (knxdmxd::knx_patch_map_t::iterator it = alreadypatched.first; it != alreadypatched.second; ++it) {
- if (it->second == _name) return; // already patched that one
- }
-
- patchMap.insert(knxdmxd::knx_patch_map_element_t(KNX,_name)); // no, add to patchMap
-}
-
-void Cuelist::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, std::string KNX, int val) {
- AddTrigger(patchMap, readgaddr(KNX), val);
-}
-
-void Cuelist::AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const knxdmxd::Trigger trigger) {
-
- if ((trigger.type) == knxdmxd::kTriggerGo) {
- _go_trigger_knx = trigger.knx;
- _go_trigger_val = trigger.value;
- }
-
- if ((trigger.type) == knxdmxd::kTriggerHalt) {
- _halt_trigger_knx = trigger.knx;
- _halt_trigger_val = trigger.value;
- }
-
- std::clog << kLogDebug << "Cuelist '" << _name << "': added " << trigger.type << " trigger by KNX:" << trigger.knx << ", value " << trigger.value << ((trigger.value==-1) ? " (all)" : "") << std::endl;
-
- std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> alreadypatched;
- alreadypatched = patchMap.equal_range(trigger.knx);
-
- for (knxdmxd::knx_patch_map_t::iterator it = alreadypatched.first; it != alreadypatched.second; ++it) {
- if (it->second == _name) return; // already patched that one
- }
-
- patchMap.insert(knxdmxd::knx_patch_map_element_t(trigger.knx,_name)); // no, add to patchMap
-}
-
-void Cuelist::AddCue(knxdmxd::Cue& cue) {
- _cue_data.push_back(cue);
- int cue_num = _cue_data.size()-1;
- if (!cue.isLink()) {
- _cue_names.insert(std::pair<std::string, int>(cue.GetName(), cue_num));
- std::clog << "Cuelist '" << _name << "': added cue " << cue.GetName() << " as #" << _cue_data.size()-1 << std::endl;
- } else {
- std::clog << "Cuelist '" << _name << "': added link to cue '" << cue.GetName() << "' as #" << _cue_data.size()-1 << std::endl;
- }
-}
-
-void Cuelist::NextCue(std::map<std::string, knxdmxd::Fixture>& fixtureList, const unsigned long long loopCounter) {
- if (_cue_data.size()>(_current_cue+1)) {
- _current_cue++;
- knxdmxd::Cue cue = _cue_data.at(_current_cue);
- if (cue.isLink()) {
- _current_cue = _cue_names.find(cue.GetName())->second;
- }
-
- _cue_data.at(_current_cue).Update(fixtureList);
-
- float waittime;
- int nextCuenum = _current_cue+1;
- if (_cue_data.size()>nextCuenum) { // last cue stops automatically
- knxdmxd::Cue nextCue = _cue_data.at(nextCuenum);
- if (nextCue.isLink()) {
- nextCuenum = _cue_names.find(nextCue.GetName())->second;
- nextCue = _cue_data.at(nextCuenum);
- }
- waittime = nextCue.GetWaitTime();
- } else {
- waittime = -1;
- }
- if (waittime>=0) { // if waittime < 0 : manual trigger
- _next_cue_start = loopCounter + (int) (waittime*1.e6/FADING_INTERVAL);
- } else {
- _next_cue_start = -1;
- }
- } else {
- _current_cue = -1;
- _next_cue_start = -1;
- }
-}
-
-void Cuelist::Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val, const unsigned long long loopCounter) {
- if ((KNX==_go_trigger_knx) && ((_go_trigger_val==-1) || (_go_trigger_val==val))) {
- NextCue(fixtureList, loopCounter);
- }
- if ((KNX==_halt_trigger_knx) && ((_halt_trigger_val==-1) || (_halt_trigger_val==val))) {
- _next_cue_start = -1;
- }
-
-}
-
-void Cuelist::Refresh(std::map<std::string, knxdmxd::Fixture>& fixtureList, const unsigned long long loopCounter) {
- if ((loopCounter>_next_cue_start) && (_next_cue_start>0)) { // if next_cue_start < 0 : manual GO required
- NextCue(fixtureList, loopCounter);
- }
-}
-
-}
Deleted: tools/knxdmxd/src/cuelist.h
===================================================================
--- tools/knxdmxd/src/cuelist.h 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/cuelist.h 2012-05-28 18:11:33 UTC (rev 846)
@@ -1,52 +0,0 @@
-/*
- * cuelist.h
- *
- * (c) by JNK 2012
- *
- *
-*/
-
-#ifndef CUELIST_H
-#define CUELIST_H
-
-#include <string.h>
-#include <knxdmxd.h>
-#include <deque>
-#include <fixture.h>
-#include <cue.h>
-
-namespace knxdmxd {
-
-class Cuelist {
- public:
- Cuelist() {};
- Cuelist(const std::string name);
-
- void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const int KNX, const int val);
- void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const std::string KNX, const int val);
- void AddTrigger(knxdmxd::knx_patch_map_t& patchMap, const knxdmxd::Trigger trigger);
- void AddCue(knxdmxd::Cue& cue);
-
- void Update(std::map<std::string, knxdmxd::Fixture>& fixtureList, const int KNX, const int val, const unsigned long long loopCounter);
- void Refresh(std::map<std::string, knxdmxd::Fixture>& fixtureList, const unsigned long long loopCounter);
-
- private:
- void NextCue(std::map<std::string, knxdmxd::Fixture>& fixtureList, const unsigned long long loopCounter);
-
- std::string _name;
- int _go_trigger_knx;
- int _go_trigger_val;
- int _halt_trigger_knx;
- int _halt_trigger_val;
-
- int _current_cue;
- unsigned long long _next_cue_start;
- std::deque<knxdmxd::Cue> _cue_data;
- std::map<std::string, int> _cue_names;
-
-};
-
-
-}
-
-#endif
Modified: tools/knxdmxd/src/dmxsender.cc
===================================================================
--- tools/knxdmxd/src/dmxsender.cc 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/dmxsender.cc 2012-05-28 18:11:33 UTC (rev 846)
@@ -11,34 +11,41 @@
namespace knxdmxd {
-bool DMXSender::Init(std::map<int, ola::DmxBuffer> *dmxWriteBuffer) {
- _dmxWriteBuffer = dmxWriteBuffer;
+bool DMXSender::Init() {
if (!m_client.Setup()) {
std::clog << kLogWarning << "OLA: client Setup failed " << std::endl;
return false;
}
-
return true;
}
int DMXSender::Start() {
SendDMX();
+ RefreshFixtures();
m_client.GetSelectServer()->Run();
+ sender_running_ = true;
return 0;
}
void DMXSender::SendDMX() {
- for(std::map<int, ola::DmxBuffer>::const_iterator i = (*_dmxWriteBuffer).begin(); i != (*_dmxWriteBuffer).end(); ++i) {
+ for(std::map<int, ola::DmxBuffer>::const_iterator i = output.begin(); i != output.end(); ++i) {
int universe = i->first;
if (!m_client.GetClient()->SendDmx(universe, i->second)) { // send all universes
m_client.GetSelectServer()->Terminate();
std::clog << kLogWarning << "OLA: failed to send universe "<< universe << std::endl;
+ sender_running_ = false;
+ return;
}
}
RegisterTimeout();
}
+void DMXSender::RefreshFixtures() {
+ fixture_list_.Refresh();
+ RegisterFixtureTimeout();
+}
+
bool DMXSender::RegisterTimeout() {
m_client.GetSelectServer()->RegisterSingleTimeout(
DMX_INTERVAL,
@@ -46,14 +53,23 @@
return true;
}
+bool DMXSender::RegisterFixtureTimeout() {
+ m_client.GetSelectServer()->RegisterSingleTimeout(
+ DMX_INTERVAL,
+ ola::NewSingleCallback(this, &DMXSender::RefreshFixtures));
+ return true;
+}
+
DMXSender::~DMXSender() {
- m_client.GetSelectServer()->Terminate();
+// m_client.GetSelectServer()->Terminate();
}
void DMXSender::Terminate() {
+ sender_running_ = false;
m_client.GetSelectServer()->Terminate();
}
+ola::OlaCallbackClientWrapper DMXSender::m_client;
}
Modified: tools/knxdmxd/src/dmxsender.h
===================================================================
--- tools/knxdmxd/src/dmxsender.h 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/dmxsender.h 2012-05-28 18:11:33 UTC (rev 846)
@@ -15,26 +15,37 @@
#include <ola/OlaCallbackClient.h>
#include <ola/OlaClientWrapper.h>
#include <map>
+#include <fixture.h>
namespace knxdmxd {
-class DMXSender {
+class DMXSender : private DMX {
+ FixtureList fixture_list_;
+ bool sender_running_;
+
public:
- DMXSender() {};
+ DMXSender() { sender_running_ = false; };
~DMXSender();
- bool Init(std::map<int, ola::DmxBuffer> *dmxWriteBuffer);
+ bool Init();
int Start();
void SendDMX();
bool RegisterTimeout();
+
+ void RefreshFixtures();
+ bool RegisterFixtureTimeout();
+
void Terminate();
-
+ bool Running() { return sender_running_; };
+
+ void AddFixture(pFixture fixture) { fixture_list_.Add(fixture); };
+ pFixture GetFixture(const std::string& name) { return fixture_list_.Get(name); };
+ static ola::OlaCallbackClientWrapper& GetOLAClient() { return m_client; };
+
+ void Process(const Trigger& trigger) { fixture_list_.Process(trigger); };
+
private:
-// unsigned int m_tick;
- std::map<int, ola::DmxBuffer> *_dmxWriteBuffer;
-
- // ola::DmxBuffer m_buffer;
- ola::OlaCallbackClientWrapper m_client;
+ static ola::OlaCallbackClientWrapper m_client;
};
Modified: tools/knxdmxd/src/fixture.cc
===================================================================
--- tools/knxdmxd/src/fixture.cc 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/fixture.cc 2012-05-28 18:11:33 UTC (rev 846)
@@ -6,91 +6,95 @@
*
*/
-
#include "fixture.h"
namespace knxdmxd {
-Fixture::Fixture(const std::string name) {
- _name=name;
- std::clog << "Creating Fixture '" << _name << "'" << std::endl;
-}
+ Fixture::Fixture(const std::string name) {
+ name_ = name;
+ std::clog << "Creating Fixture '" << name_ << "'" << std::endl;
+ }
-void Fixture::Patch(knx_patch_map_t& patchMap, const std::string channel, const int DMX, const int KNX=-1) {
- _channelKNX[channel] = KNX;
- _channelDMX[channel] = DMX;
-
- std::clog << "Fixture '" << _name << "': Patched channel '" << channel << "' (KNX " << KNX << " to " << DMX << ") " << std::endl;
-
- std::pair<knxdmxd::knx_patch_map_t::iterator, knxdmxd::knx_patch_map_t::iterator> alreadypatched; // fixtures that handle this
- alreadypatched = patchMap.equal_range(KNX);
+ void Fixture::AddChannel(const std::string& name, const std::string& DMX, const std::string& KNX) {
+ fixture_channel_t channel;
+ channel.KNX = (KNX!="") ? readgaddr(KNX) : -1;
+ channel.DMX = readdaddr(DMX);
+ channel.value = channel.floatValue = 0; // we start blacked out
+ channel.fadeStep = 255; // direct by default
+ channel_data_.push_back(channel);
+ channel_names_.insert(std::pair<std::string, int> (name, channel_data_.size()-1));
+ }
- for (knxdmxd::knx_patch_map_t::iterator it = alreadypatched.first; it != alreadypatched.second; ++it) {
- if (it->second == _name) return; // already patched that one
+ void Fixture::SetFadeTime(const float t) {
+ _fadeTime = t;
+ _fadeStep = (t<=0) ? 256 : 256/(t*1e6/FADING_INTERVAL);
+ std::clog << "Fixture '" << name_ << "': Set global fadetime to " << _fadeTime << "s (" << _fadeStep << " steps/interval)" << std::endl;
}
-
- patchMap.insert(knxdmxd::knx_patch_map_element_t(KNX,_name)); // no, add to patchMap
-}
+ void Fixture::Update(const std::string& channel, const int val, float fadeStep) {
+ unsigned ch = channel_names_[channel];
+ channel_data_[ch].value=val;
+ channel_data_[ch].fadeStep=fadeStep;
+ std::clog << "Fixture '" << name_ << "': Channel '" << channel << "' @ " << val << ", fading: " << fadeStep << " old: "<< channel_data_[ch].floatValue << std::endl;
+ }
-void Fixture::Patch(knx_patch_map_t& patchMap, const std::string channel, const std::string DMX, const std::string KNX) {
- Patch(patchMap, channel, readdaddr(DMX), readgaddr(KNX));
-}
+ void Fixture::Refresh() {
+ for(std::vector<knxdmxd::fixture_channel_t>::iterator it=channel_data_.begin(); it!=channel_data_.end(); ++it) {
+ int oldValue = GetDMXChannel(it->DMX);
+ int newValue = it->value;
+ if (oldValue<newValue) {
+ it->floatValue += it->fadeStep;
+ if (it->floatValue>newValue) {
+ it->floatValue = newValue;
+ }
+ SetDMXChannel(it->DMX, (int) it->floatValue);
+ }
+ if (oldValue>newValue) {
+ it->floatValue -= it->fadeStep;
+ if (it->floatValue<newValue) {
+ it->floatValue = newValue;
+ }
+ SetDMXChannel(it->DMX, (int) it->floatValue);
+ }
+ }
+ }
-void Fixture::SetFadeTime(const float t) {
- _fadeTime = t;
- _fadeStep = (t<=0) ? 256 : 256/(t*1e6/FADING_INTERVAL);
- std::clog << "Fixture '" << _name << "': Set global fadetime to " << _fadeTime << "s (" << _fadeStep << " steps/interval)" << std::endl;
-}
-
-void Fixture::PatchFadeTime(const int KNX) {
- _fadeTimeKNX = KNX;
-}
-
-void Fixture::Update(const std::string& channel, const int val, bool direct) {
- _channelValue[channel] = val;
- _channelFadeStep[channel] = direct ? 256 : _fadeStep;
- std::clog << "Fixture '" << _name << "': Channel '" << channel << "' @ " << val << ", direct: " << ((direct) ? "true" : "false") << std::endl;
-}
-
-void Fixture::Update(const int KNX, const int val, bool direct) {
- for(std::map<std::string, int>::const_iterator i = _channelKNX.begin(); i != _channelKNX.end(); ++i) {
- if (i->second == KNX) Update(i->first, val, direct);
+ int Fixture::GetCurrentValue(const std::string& channel) {
+ return (int) channel_data_[channel_names_[channel]].floatValue;
}
-}
-
-void Fixture::Update(const std::string& channel, const int val, float fadeStep) {
- _channelValue[channel] = val;
- _channelFadeStep[channel] = fadeStep;
- std::clog << "Fixture '" << _name << "': Channel '" << channel << "' @ " << _channelValue[channel] << ", fading: " << fadeStep << " old: "<< _channelFloatValue[channel] << std::endl;
-}
-
-
-void Fixture::Refresh(std::map<int, ola::DmxBuffer>& output) {
- for(std::map<std::string, int>::const_iterator i = _channelDMX.begin(); i != _channelDMX.end(); ++i) {
- int dmxuniverse = (int) (i->second / 512), dmxchannel = i->second % 512;
- int oldValue = output[dmxuniverse].Get(dmxchannel);
- int newValue = _channelValue[i->first];
- if (oldValue<newValue) {
- _channelFloatValue[i->first] += _channelFadeStep[i->first];
- if (_channelFloatValue[i->first]>newValue) {
- _channelFloatValue[i->first] = newValue;
+
+ void Fixture::Process(const Trigger& trigger) {
+ for (std::vector<knxdmxd::fixture_channel_t>::iterator it=channel_data_.begin(); it!=channel_data_.end(); ++it) {
+ if (it->KNX == trigger.GetKNX()) {
+ it->value = trigger.GetValue();
+ it->fadeStep = _fadeStep;
+ std::cout << "Set " << it->value << std::endl;
}
- output[dmxuniverse].SetChannel(dmxchannel, (int) _channelFloatValue[i->first]);
- //std::clog << "Fade: " << dmxuniverse << "." << dmxchannel << " @ " << _channelFloatValue[i->first] << std::endl;
}
- if (oldValue>newValue) {
- _channelFloatValue[i->first] -= _channelFadeStep[i->first];
- if (_channelFloatValue[i->first]<newValue) {
- _channelFloatValue[i->first] = newValue;
- }
- output[dmxuniverse].SetChannel(dmxchannel, (int) _channelFloatValue[i->first]);
- //std::clog << "Fade: " << dmxuniverse << "." << dmxchannel << " @ " << _channelFloatValue[i->first] << std::endl;
+ if (fadeTimeKNX_ == trigger.GetKNX()) {
+ SetFadeTime(trigger.GetValue());
}
}
+
+ void DMX::SetDMXChannel(int channel, int value) {
+ int dmxuniverse = (int) (channel / 512), dmxchannel = channel % 512;
+ output[dmxuniverse].SetChannel(dmxchannel, value);
+ }
+
+ int DMX::GetDMXChannel(int channel) {
+ int dmxuniverse = (int) (channel / 512), dmxchannel = channel % 512;
+ return output[dmxuniverse].Get(dmxchannel);
+ }
+
+ void FixtureList::Process(const Trigger& trigger) {
+ for(std::map<std::string, knxdmxd::pFixture>::iterator it=fixture_list_.begin(); it!=fixture_list_.end(); ++it) {
+ it->second->Process(trigger);
+ }
+ }
+
+ void FixtureList::Refresh() {
+ for(std::map<std::string, knxdmxd::pFixture>::iterator it=fixture_list_.begin(); it!=fixture_list_.end(); ++it) {
+ it->second->Refresh();
+ }
+ }
}
-
-int Fixture::GetCurrentValue(const std::string& channel) {
- return (int) _channelFloatValue.find(channel)->second;
-}
-}
Modified: tools/knxdmxd/src/fixture.h
===================================================================
--- tools/knxdmxd/src/fixture.h 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/fixture.h 2012-05-28 18:11:33 UTC (rev 846)
@@ -11,35 +11,68 @@
#include <string.h>
#include <knxdmxd.h>
+#include <trigger.h>
namespace knxdmxd {
-class Fixture {
- public:
- Fixture() {};
- Fixture(const std::string name);
+ class DMX {
+ protected:
+ static std::map<int, ola::DmxBuffer> output;
+ public:
+ DMX() {};
+ void SetDMXChannel(int channel, int value);
+ int GetDMXChannel(int channel);
+
+ };
+
+ typedef struct {
+ int KNX, DMX, value;
+ float fadeStep, floatValue;
+ } fixture_channel_t;
+
+ class Fixture : private DMX {
+ std::string name_;
+ std::vector<fixture_channel_t> channel_data_;
+ std::map<std::string, unsigned> channel_names_;
+
+ float _fadeTime; // is set by knx or config
+ float _fadeStep; // calculated from _fadeTime
+ int fadeTimeKNX_;
+
+ public:
+ Fixture() {};
+ Fixture(const std::string name);
+
+ void AddChannel(const std::string& name, const std::string& DMX, const std::string& KNX);
+ void SetFadeTime(const float t);
+ void PatchFadeTime(const int KNX) { fadeTimeKNX_ = KNX; };
+ ...
[truncated message content] |
|
From: <j-...@us...> - 2012-06-02 19:21:46
|
Revision: 856
http://openautomation.svn.sourceforge.net/openautomation/?rev=856&view=rev
Author: j-n-k
Date: 2012-06-02 19:21:39 +0000 (Sat, 02 Jun 2012)
Log Message:
-----------
WG-Binary and support files
Modified Paths:
--------------
tools/knxdmxd/README
tools/knxdmxd/debian/changelog
tools/knxdmxd/knxdmxd
Modified: tools/knxdmxd/README
===================================================================
--- tools/knxdmxd/README 2012-06-02 18:49:46 UTC (rev 855)
+++ tools/knxdmxd/README 2012-06-02 19:21:39 UTC (rev 856)
@@ -1,3 +1 @@
-Further describe this program ;)
-
-Use ./configure "CXXFLAGS=-std=c++0x -O3 -pthread"
+doc still missing, but have fun
\ No newline at end of file
Modified: tools/knxdmxd/debian/changelog
===================================================================
--- tools/knxdmxd/debian/changelog 2012-06-02 18:49:46 UTC (rev 855)
+++ tools/knxdmxd/debian/changelog 2012-06-02 19:21:39 UTC (rev 856)
@@ -1,3 +1,10 @@
+knxdmxd (0.1-2.1) unstable; urgency=low
+
+ * Non-maintainer upload.
+ *
+
+ -- root <ro...@wi...> Sat, 02 Jun 2012 21:19:32 +0200
+
knxdmxd (0.1-2) unstable; urgency=low
* new SVN-version
Modified: tools/knxdmxd/knxdmxd
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <j-...@us...> - 2012-07-10 15:37:53
|
Revision: 916
http://openautomation.svn.sourceforge.net/openautomation/?rev=916&view=rev
Author: j-n-k
Date: 2012-07-10 15:37:42 +0000 (Tue, 10 Jul 2012)
Log Message:
-----------
Updated knxdmxd
Modified Paths:
--------------
tools/knxdmxd/Makefile.am
tools/knxdmxd/knxdmxd
tools/knxdmxd/src/cue.cc
tools/knxdmxd/src/cue.h
tools/knxdmxd/src/dmxsender.cc
tools/knxdmxd/src/dmxsender.h
tools/knxdmxd/src/fixture.cc
tools/knxdmxd/src/fixture.h
tools/knxdmxd/src/knxdmxd.cc
tools/knxdmxd/src/knxdmxd.h
tools/knxdmxd/src/trigger.cc
tools/knxdmxd/src/trigger.h
Modified: tools/knxdmxd/Makefile.am
===================================================================
--- tools/knxdmxd/Makefile.am 2012-07-09 06:26:16 UTC (rev 915)
+++ tools/knxdmxd/Makefile.am 2012-07-10 15:37:42 UTC (rev 916)
@@ -1,2 +1,11 @@
-AUTOMAKE_OPTIONS = foreign
-SUBDIRS = src
\ No newline at end of file
+# what flags you want to pass to the C compiler & linker
+#CPPFLAGS = --pedantic -Wall -std=c99 -O2
+#LDFLAGS =
+
+knxdmxd_CXXFLAGS = $(OLA_CFLAGS) $(AM_CXXFLAGS)
+knxdmxd_LDADD = $(OLA_LIBS)
+
+# this lists the binaries to produce, the (non-PHONY, binary) targets in
+# the previous manual Makefile
+bin_PROGRAMS = knxdmxd
+knxdmxd_SOURCES = knxdmxd.cc log.cc fixture.cc cue.cc dmxsender.cc trigger.cc
Modified: tools/knxdmxd/knxdmxd
===================================================================
(Binary files differ)
Modified: tools/knxdmxd/src/cue.cc
===================================================================
--- tools/knxdmxd/src/cue.cc 2012-07-09 06:26:16 UTC (rev 915)
+++ tools/knxdmxd/src/cue.cc 2012-07-10 15:37:42 UTC (rev 916)
@@ -13,6 +13,8 @@
Cue::Cue(const std::string name, const bool isLink) {
_name=name;
+ lock_.locker = name; // default is cue-name
+ lock_.prio = 0;
fadeIn_ = 0.0;
fadeOut_ = 0.0;
waittime_ = -1; // never step automatically
@@ -40,37 +42,52 @@
void Cue::Go() {
if ((delay_>0) && (!delay_on_)) {
- DMXSender::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
+ DMX::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
(int) delay_*1000, ola::NewSingleCallback(this, &Cue::Go));
delay_on_ = true;
+ std::clog << "Called cue " << _name << " (delaying)" << std::endl;
} else {
for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
+ if (!it->fixture->Lock(lock_)) { // Test if we can lock
+ std::clog << _name << ": locking failed " << it->fixture->GetName() << std::endl;
+ continue; // no, we can't
+ }
int deltaVal = it->fixture->GetCurrentValue(it->name) - it->value;
- float ft = (deltaVal>0) ? (deltaVal/(fadeOut_*1.e3/DMX_INTERVAL)) : (-deltaVal/(fadeIn_*1.e3/DMX_INTERVAL));
+ float ft = (deltaVal>0) ? ((deltaVal+1)/(fadeOut_*1.e3/(DMX_INTERVAL+1))) : ((-deltaVal+1)/(fadeIn_*1.e3/(DMX_INTERVAL+1)));
it->fixture->Update(it->name, it->value, ft);
}
delay_on_ = false;
+ std::clog << "Called cue " << _name << std::endl;
}
- std::clog << "Called cue " << _name << std::endl;
+
}
Cuelist::Cuelist(const std::string name) {
_name=name;
+
+ lock_.locker = name; // default is cuelist-name
+ lock_.prio = 0;
current_cue_=-1;
+
was_direct_ = false;
cue_halted_ = true;
+ release_on_halt_ = true;
+
+ max_cue_ = 0;
+
std::clog << "Creating Cuelist '" << name << "'" << std::endl;
}
void Cuelist::AddCue(knxdmxd::Cue& cue) {
- _cue_data.push_back(cue);
- int cue_num = _cue_data.size()-1;
+ cue_data_.push_back(cue);
+ int cue_num = max_cue_;
if (!cue.isLink()) {
- _cue_names.insert(std::pair<std::string, int>(cue.GetName(), cue_num));
- std::clog << "Cuelist " << _name << ": added cue " << cue.GetName() << " as #" << _cue_data.size()-1 << std::endl;
+ cue_names_.insert(std::pair<std::string, int>(cue.GetName(), cue_num));
+ std::clog << "Cuelist " << _name << ": added cue " << cue.GetName() << " as #" << cue_num << std::endl;
} else {
- std::clog << "Cuelist " << _name << ": added link to cue '" << cue.GetName() << "' as #" << _cue_data.size()-1 << std::endl;
+ std::clog << "Cuelist " << _name << ": added link to cue '" << cue.GetName() << "' as #" << cue_num << std::endl;
}
+ max_cue_++;
}
void Cuelist::NextCue(const int direct) {
@@ -79,53 +96,50 @@
return;
}
- if (direct != -1) {
- if (direct>(_cue_data.size()-1)) { // called cue too large
- std::clog << kLogInfo << "Tried direct call to cue " << direct << " in cuelist " << _name << ": too large" << std::endl;
- return;
- }
- current_cue_ = direct - 1;
- if (!cue_halted_) // only if cuelist was running
+ switch (direct) {
+ default: // direct call
+ if (direct>=max_cue_) { // called cue too large
+ std::clog << kLogInfo << "Tried direct call to cue " << direct << " in cuelist " << _name << ": too large" << std::endl;
+ return;
+ }
+ current_cue_ = direct - 1;
+ if (!cue_halted_) // only if cuelist was running
+ was_direct_ = true;
+ break;
+ case -1: // normal call
+ break;
+ case -2: // next on running cuelist
was_direct_ = true;
+ break;
+
}
- if (_cue_data.size()>(current_cue_+1)) {
+ if (max_cue_>(current_cue_+1)) {
+ if (current_cue_>=0)
+ cue_data_.at(current_cue_).Release();
current_cue_++;
- knxdmxd::Cue cue = _cue_data.at(current_cue_);
+ knxdmxd::Cue cue = cue_data_.at(current_cue_);
if (cue.isLink()) {
- current_cue_ = _cue_names.find(cue.GetName())->second;
+ current_cue_ = cue_names_.find(cue.GetName())->second;
}
- _cue_data.at(current_cue_).Go();
+ cue_data_.at(current_cue_).Go();
float waittime;
int nextCuenum = current_cue_+1;
- if (_cue_data.size()>nextCuenum) { // last cue stops automatically
- knxdmxd::Cue nextCue = _cue_data.at(nextCuenum);
+ if (max_cue_>nextCuenum) { // last cue stops automatically
+ knxdmxd::Cue nextCue = cue_data_.at(nextCuenum);
if (nextCue.isLink()) {
- nextCuenum = _cue_names.find(nextCue.GetName())->second;
- nextCue = _cue_data.at(nextCuenum);
+ nextCuenum = cue_names_.find(nextCue.GetName())->second;
+ nextCue = cue_data_.at(nextCuenum);
}
waittime = nextCue.GetWaitTime();
if ((waittime>=0) && (!cue_halted_)) {
- DMXSender::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
+ DMX::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
(int) waittime*1000, ola::NewSingleCallback(this, &Cuelist::NextCue, -1));
}
}
}
}
- void Cuelist::Go() {
- cue_halted_=false;
- NextCue(-1);
- }
-
- void Cuelist::Halt() {
- cue_halted_=true;
- }
-
- void Cuelist::Direct(const int value) {
- NextCue(value);
- }
-
}
Modified: tools/knxdmxd/src/cue.h
===================================================================
--- tools/knxdmxd/src/cue.h 2012-07-09 06:26:16 UTC (rev 915)
+++ tools/knxdmxd/src/cue.h 2012-07-10 15:37:42 UTC (rev 916)
@@ -29,6 +29,7 @@
float fadeIn_, fadeOut_;
float waittime_, delay_;
bool is_link_, delay_on_;
+ fixture_lock_t lock_;
public:
Cue() {};
@@ -38,20 +39,29 @@
void SetFading(const float fadeIn, const float fadeOut);
void SetWaittime(const float waittime) { waittime_ = waittime; };
void SetDelay(const float delay) { delay_ = delay; };
+ void SetLock(const fixture_lock_t lock) { lock_ = lock; };
+ void Go();
+ void Release() {
+ for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
+ it->fixture->Release(lock_);
+ }
+ };
+
const std::string GetName() { return _name; };
const float GetWaitTime() { return waittime_; };
const float GetDelayTime() { return delay_; };
- virtual void Go();
bool isLink() { return is_link_; };
};
class Cuelist : public TriggerHandler {
- int current_cue_;
+ int current_cue_, max_cue_;
bool cue_halted_, was_direct_;
- std::vector<knxdmxd::Cue> _cue_data;
- std::map<std::string, int> _cue_names;
+ bool release_on_halt_;
+ fixture_lock_t lock_;
+ std::vector<knxdmxd::Cue> cue_data_;
+ std::map<std::string, int> cue_names_;
void NextCue(const int direct);
@@ -60,9 +70,23 @@
Cuelist(const std::string name);
void AddCue(knxdmxd::Cue& cue);
- void Go();
- void Halt();
- void Direct(const int value);
+ void Go() {
+ if (cue_halted_) {
+ cue_halted_ = false;
+ NextCue(-1);
+ } else {
+ NextCue(-2);
+ }
+
+ };
+ void Halt() {
+ cue_halted_ = true;
+ if (release_on_halt_) {
+ Release();
+ }
+ };
+ void Direct(const int value) { NextCue(value); };
+ void Release() { cue_data_.at(current_cue_).Release(); };
};
}
Modified: tools/knxdmxd/src/dmxsender.cc
===================================================================
--- tools/knxdmxd/src/dmxsender.cc 2012-07-09 06:26:16 UTC (rev 915)
+++ tools/knxdmxd/src/dmxsender.cc 2012-07-10 15:37:42 UTC (rev 916)
@@ -21,6 +21,7 @@
int DMXSender::Start() {
SendDMX();
+ fixture_list_.StartRefresh();
m_client.GetSelectServer()->Run();
sender_running_ = true;
return 0;
@@ -29,6 +30,7 @@
void DMXSender::SendDMX() {
for(std::map<int, ola::DmxBuffer>::const_iterator i = output.begin(); i != output.end(); ++i) {
int universe = i->first;
+ //std::clog << "C1/2 " << (int) i->second.Get(0) << " " << (int) i->second.Get(1) << " " << (int) i->second.Get(2) << std::endl;
if (!m_client.GetClient()->SendDmx(universe, i->second)) { // send all universes
m_client.GetSelectServer()->Terminate();
std::clog << kLogWarning << "OLA: failed to send universe "<< universe << std::endl;
Modified: tools/knxdmxd/src/dmxsender.h
===================================================================
--- tools/knxdmxd/src/dmxsender.h 2012-07-09 06:26:16 UTC (rev 915)
+++ tools/knxdmxd/src/dmxsender.h 2012-07-10 15:37:42 UTC (rev 916)
@@ -36,9 +36,8 @@
void AddFixture(pFixture fixture) { fixture_list_.Add(fixture); };
pFixture GetFixture(const std::string& name) { return fixture_list_.Get(name); };
- static ola::OlaCallbackClientWrapper& GetOLAClient() { return m_client; };
- void Process(const Trigger& trigger) { fixture_list_.Process(trigger); };
+// void Process(const Trigger& trigger) { fixture_list_.Process(trigger); };
};
Modified: tools/knxdmxd/src/fixture.cc
===================================================================
--- tools/knxdmxd/src/fixture.cc 2012-07-09 06:26:16 UTC (rev 915)
+++ tools/knxdmxd/src/fixture.cc 2012-07-10 15:37:42 UTC (rev 916)
@@ -35,36 +35,37 @@
unsigned ch = channel_names_[channel];
channel_data_[ch].value=val;
channel_data_[ch].fadeStep=fadeStep;
- RegisterRefresh();
+ refresh_ = true;
}
void Fixture::Refresh() {
- bool needs_refresh = false;
- for(std::vector<knxdmxd::fixture_channel_t>::iterator it=channel_data_.begin(); it!=channel_data_.end(); ++it) {
- int oldValue = GetDMXChannel(it->DMX);
- int newValue = it->value;
- if (oldValue<newValue) {
- it->floatValue += it->fadeStep;
- if (it->floatValue>newValue) {
- it->floatValue = newValue;
- } else {
- needs_refresh = true;
+ if (refresh_) {
+ bool refresh = false;
+ for(std::vector<knxdmxd::fixture_channel_t>::iterator it=channel_data_.begin(); it!=channel_data_.end(); ++it) {
+ int oldValue = GetDMXChannel(it->DMX);
+ int newValue = it->value;
+ if (oldValue<newValue) {
+ it->floatValue += it->fadeStep;
+ if (it->floatValue>newValue) {
+ it->floatValue = newValue;
+ } else {
+ refresh = true;
+ }
+ SetDMXChannel(it->DMX, (int) it->floatValue);
}
- SetDMXChannel(it->DMX, (int) it->floatValue);
- }
- if (oldValue>newValue) {
- it->floatValue -= it->fadeStep;
- if (it->floatValue<newValue) {
- it->floatValue = newValue;
- } else {
- needs_refresh = true;
+ if (oldValue>newValue) {
+ it->floatValue -= it->fadeStep;
+ if (it->floatValue<newValue) {
+ it->floatValue = newValue;
+ } else {
+ refresh = true;
+ }
+ SetDMXChannel(it->DMX, (int) it->floatValue);
}
- SetDMXChannel(it->DMX, (int) it->floatValue);
}
+ refresh_ = refresh;
}
- if (needs_refresh) { // we need another refresh
- RegisterRefresh();
- }
+ RegisterRefresh();
}
bool Fixture::RegisterRefresh() {
@@ -78,17 +79,20 @@
}
void Fixture::Process(const Trigger& trigger) {
+ std::clog << "fprocess" << std::endl;
for (std::vector<knxdmxd::fixture_channel_t>::iterator it=channel_data_.begin(); it!=channel_data_.end(); ++it) {
if (it->KNX == trigger.GetKNX()) {
it->value = trigger.GetValue();
it->fadeStep = _fadeStep;
+ refresh_ = true;
+ std::clog << "Updated " << it->DMX << " to " << it->value << "rate: " << it->fadeStep << std::endl;
}
}
if (fadeTimeKNX_ == trigger.GetKNX()) {
SetFadeTime(trigger.GetValue());
}
}
-
+
void DMX::SetDMXChannel(int channel, int value) {
int dmxuniverse = (int) (channel / 512), dmxchannel = channel % 512;
output[dmxuniverse].SetChannel(dmxchannel, value);
@@ -98,8 +102,7 @@
int dmxuniverse = (int) (channel / 512), dmxchannel = channel % 512;
return output[dmxuniverse].Get(dmxchannel);
}
-
-
+
int DMX::Address(const std::string addr) {
int universe, channel;
sscanf( (char*)addr.c_str(), "%d.%d", &universe, &channel);
@@ -110,13 +113,11 @@
return (universe << 9) + channel;
}
-
- void FixtureList::Process(const Trigger& trigger) {
+ void FixtureList::StartRefresh() {
for(std::map<std::string, knxdmxd::pFixture>::iterator it=fixture_list_.begin(); it!=fixture_list_.end(); ++it) {
- it->second->Process(trigger);
+ it->second->RegisterRefresh();
}
}
-
// initalize static variables of DMX class
ola::OlaCallbackClientWrapper DMX::m_client;
std::map<int, ola::DmxBuffer> DMX::output;
Modified: tools/knxdmxd/src/fixture.h
===================================================================
--- tools/knxdmxd/src/fixture.h 2012-07-09 06:26:16 UTC (rev 915)
+++ tools/knxdmxd/src/fixture.h 2012-07-10 15:37:42 UTC (rev 916)
@@ -27,6 +27,7 @@
int GetDMXChannel(int channel);
static int Address(const std::string s);
+ static ola::OlaCallbackClientWrapper& GetOLAClient() { return m_client; };
};
@@ -35,7 +36,12 @@
float fadeStep, floatValue;
} fixture_channel_t;
- class Fixture : private DMX {
+ typedef struct {
+ std::string locker;
+ int prio;
+ } fixture_lock_t;
+
+ class Fixture : private DMX, public TriggerHandler {
std::string name_;
std::vector<fixture_channel_t> channel_data_;
std::map<std::string, unsigned> channel_names_;
@@ -43,6 +49,9 @@
float _fadeTime; // is set by knx or config
float _fadeStep; // calculated from _fadeTime
int fadeTimeKNX_;
+ fixture_lock_t lock_;
+
+ bool refresh_;
public:
Fixture() {};
@@ -53,16 +62,36 @@
void PatchFadeTime(const int KNX) { fadeTimeKNX_ = KNX; };
void Update(const std::string& channel, const int val, const float fadeStep);
void Process(const Trigger& trigger);
+
+ void Wait();
void Refresh();
bool RegisterRefresh();
int GetCurrentValue(const std::string& channel);
std::string& GetName() { return name_; };
- void Lock(const std::string& cuelist, int lockpriority);
- int isLocked();
- void Release();
-
+ // locking
+ bool Lock(const fixture_lock_t& lock) {
+ if ((lock_.locker == lock.locker) || (lock_.locker == "") || (lock_.prio<=lock.prio)) {
+ std::clog << "Locking " << lock.locker << " @ " << lock.prio << std::endl;
+ lock_ = lock;
+ return true;
+ } else {
+ std::clog << "Refused " << lock.locker << " @ " << lock.prio << std::endl;
+ return false;
+ }
+ };
+ bool Release(const fixture_lock_t& lock) {
+ if (lock_.locker == lock.locker) {
+ lock_.locker = "";
+ lock_.prio=0;
+ return true;
+ } else {
+ return false;
+ }
+ };
+ fixture_lock_t GetLock() { return lock_; };
+
};
typedef Fixture* pFixture;
@@ -74,7 +103,8 @@
FixtureList() {};
void Add(pFixture fixture) { fixture_list_.insert(std::pair<std::string, knxdmxd::pFixture> (fixture->GetName(), fixture)); };
- void Process(const Trigger& trigger);
+ void StartRefresh();
+// void Process(const Trigger& trigger);
pFixture Get(const std::string& name) { return fixture_list_[name]; };
};
Modified: tools/knxdmxd/src/knxdmxd.cc
===================================================================
--- tools/knxdmxd/src/knxdmxd.cc 2012-07-09 06:26:16 UTC (rev 915)
+++ tools/knxdmxd/src/knxdmxd.cc 2012-07-10 15:37:42 UTC (rev 916)
@@ -57,17 +57,15 @@
#define BUFLEN 1024
#define POLLING_INTERVAL 10
-
template<class T>
std::string t_to_string(T i) {
- std::stringstream ss;
- ss << i;
- return ss.str();
+ std::stringstream ss;
+ ss << i;
+ return ss.str();
}
void daemonShutdown();
-std::string eibd_url = "local:/tmp/eib";
std::string conf_file = "knxdmxd.conf";
int pidFilehandle;
std::string pidfilename = "/var/run/knxdmxd.pid";
@@ -76,165 +74,139 @@
namespace knxdmxd {
- eibaddr_t KNXHandler::Address(const std::string addr) {
- int a, b, c;
- char *s = (char *)addr.c_str();
-
- if (sscanf (s, "%d/%d/%d", &a, &b, &c) == 3)
- return ((a & 0x01f) << 11) | ((b & 0x07) << 8) | ((c & 0xff));
- if (sscanf (s, "%d/%d", &a, &b) == 2)
- return ((a & 0x01f) << 11) | ((b & 0x7FF));
- if (sscanf (s, "%x", &a) == 1)
- return a & 0xffff;
- std::clog << kLogWarning << "invalid group address format " << addr << std::endl;
- return 0;
- }
+ eibaddr_t KNXHandler::Address(const std::string addr) {
+ int a, b, c;
+ char *s = (char *) addr.c_str();
- void KNXHandler::knxhandler() {
- std::clog << "KNX thread started" << std::endl;
- int len;
- EIBConnection *con;
- eibaddr_t dest;
- eibaddr_t src;
- unsigned char buf[255], val;
-
- while (1) { //retry infinite
- con = EIBSocketURL ((char *)eibd_url.c_str());
- if (!con) {
- std::clog << kLogWarning << "eibd: Open failed" << std::endl;
- sleep(RETRY_TIME);
- continue;
- }
+ if (sscanf(s, "%d/%d/%d", &a, &b, &c) == 3)
+ return ((a & 0x01f) << 11) | ((b & 0x07) << 8) | ((c & 0xff));
+ if (sscanf(s, "%d/%d", &a, &b) == 2)
+ return ((a & 0x01f) << 11) | ((b & 0x7FF));
+ if (sscanf(s, "%x", &a) == 1) return a & 0xffff;
+ std::clog << kLogWarning << "invalid group address format " << addr
+ << std::endl;
+ return 0;
+ }
- if (EIBOpen_GroupSocket (con, 0) == -1) {
- std::clog << kLogWarning << "eibd: Connect failed" << std::endl;
- sleep(RETRY_TIME);
- continue;
- }
+ void KNXHandler::knxhandler() {
+ std::clog << "KNX thread started" << std::endl;
+ int len;
+ EIBConnection *con;
+ eibaddr_t dest;
+ eibaddr_t src;
+ unsigned char buf[255], val;
- while (1) {
- len = EIBGetGroup_Src (con, sizeof (buf), buf, &src, &dest);
- if (len == -1) {
- std::clog << kLogWarning << "eibd: Read failed" << std::endl;
- sleep(RETRY_TIME);
- break;
- }
-
- if (len < 2) {
- std::clog << kLogWarning << "eibd: Invalid Packet" << std::endl;
- break;
- }
-
- if (buf[0] & 0x3 || (buf[1] & 0xC0) == 0xC0) {
- std::clog << kLogWarning << "eibd: Unknown APDU from "<< src << " to " << dest << std::endl;
- break;
- } else {
- switch (buf[1] & 0xC0) {
- case 0x00:
- // sendKNXresponse (dest,zone+(controller*ZONES_PER_CONTROLLER),func);
- break;
- case 0x40:
- //FIXME: response dunno
- break;
- case 0x80:
- if (buf[1] & 0xC0) {
- val = (len==2) ? buf[1] & 0x3F : buf[2];
- knxdmxd::Trigger trigger(knxdmxd::kTriggerAll, dest, val);
- sender.Process(trigger);
- triggerList.Process(trigger);
- }
- break;
- }
- }
- }
-
- std::clog << kLogWarning << "eibd: Closed connection" << std::endl; //break in read-loop
- EIBClose (con);
- }
-
- }
+ while (1) { //retry infinite
+ con = EIBSocketURL((char *) eibd_url_.c_str());
+ if (!con) {
+ std::clog << kLogWarning << "eibd: Open failed" << std::endl;
+ sleep(RETRY_TIME);
+ continue;
+ }
- void *KNXHandler::Run() {
- ola::thread::MutexLocker locker(&m_mutex);
- knxhandler();
- return NULL;
- }
+ if (EIBOpen_GroupSocket(con, 0) == -1) {
+ std::clog << kLogWarning << "eibd: Connect failed" << std::endl;
+ sleep(RETRY_TIME);
+ continue;
+ }
-class OLAThread : public ola::thread::Thread {
- public:
- OLAThread()
- : Thread(),
- m_mutex() {
+ while (1) {
+ len = EIBGetGroup_Src(con, sizeof(buf), buf, &src, &dest);
+ if (len == -1) {
+ std::clog << kLogWarning << "eibd: Read failed" << std::endl;
+ sleep(RETRY_TIME);
+ break;
+ }
+
+ if (len < 2) {
+ std::clog << kLogWarning << "eibd: Invalid Packet" << std::endl;
+ break;
+ }
+
+ if ((buf[0] & 0x3) || (buf[1] & 0xC0) == 0xC0) {
+ std::clog << kLogWarning << "eibd: Unknown APDU from " << src
+ << " to " << dest << std::endl;
+ break;
+ } else {
+ switch (buf[1] & 0xC0) {
+ case 0x00:
+ // sendKNXresponse (dest,zone+(controller*ZONES_PER_CONTROLLER),func);
+ break;
+ case 0x40:
+ //FIXME: response dunno
+ break;
+ case 0x80:
+ if (buf[1] & 0xC0) {
+ val = (len == 2) ? buf[1] & 0x3F : buf[2];
+ knxdmxd::Trigger trigger(knxdmxd::kTriggerAll, dest, val);
+ triggerList.Process(trigger);
+ }
+ break;
+ }
+ }
+ }
+
+ std::clog << kLogWarning << "eibd: Closed connection" << std::endl; //break in read-loop
+ EIBClose(con);
}
- ~OLAThread() {}
- void olahandler() { // thread for OLA connection
- std::clog << kLogDebug << "OLA thread started" << std::endl;
+ }
- ola::InitLogging(ola::OLA_LOG_WARN, ola::OLA_LOG_STDERR);
+ void OLAThread::olahandler() { // thread for OLA connection
+ std::clog << kLogDebug << "OLA thread started" << std::endl;
- while (1) { // retry forever
- if (!sender.Init()) {
- std::clog << kLogWarning << "OLA: Client setup failed" << std::endl;
- sleep(RETRY_TIME);
- continue;
- }
-
- sender.Start(); // Start the sender
+ ola::InitLogging(ola::OLA_LOG_WARN, ola::OLA_LOG_STDERR);
- while (1) { // loop forever, should be used for monitoring the client
- if (!sender.Running())
- break;
- usleep(20000);
- }
+ while (1) { // retry forever
+ if (!sender.Init()) {
+ std::clog << kLogWarning << "OLA: Client setup failed" << std::endl;
+ sleep(RETRY_TIME);
+ continue;
}
- }
- void *Run() {
- ola::thread::MutexLocker locker(&m_mutex);
- olahandler();
- return NULL;
+ sender.Start(); // Start the sender
+
+ while (1) { // loop forever, should be used for monitoring the client
+ if (!sender.Running()) break;
+ usleep(20000);
+ }
}
-
- private:
- ola::thread::Mutex m_mutex;
-};
-
-
+ }
}
void daemonShutdown() {
- //FIXME: clean exit pthread_exit(NULL); pthread_cancel(..);
- std::clog << kLogInfo << DAEMON_NAME << " daemon exiting" << std::endl;
- fprintf(stderr, "%s daemon exiting", DAEMON_NAME);
- sender.Terminate();
- close(pidFilehandle);
- unlink((char *)pidfilename.c_str());
- exit(EXIT_SUCCESS);
+ //FIXME: clean exit pthread_exit(NULL); pthread_cancel(..);
+ std::clog << kLogInfo << DAEMON_NAME << " daemon exiting" << std::endl;
+ fprintf(stderr, "%s daemon exiting", DAEMON_NAME);
+ sender.Terminate();
+ close(pidFilehandle);
+ unlink((char *) pidfilename.c_str());
+ exit(EXIT_SUCCESS);
}
void signal_handler(int sig) {
- switch(sig) {
- case SIGHUP:
- std::clog << kLogWarning << "Received SIGHUP signal." << std::endl;
- break;
- case SIGTERM:
- std::clog << kLogWarning << "Received SIGTERM signal." << std::endl;
- daemonShutdown();
- break;
- case SIGINT:
- std::clog << kLogWarning << "Received SIGINT signal." << std::endl;
- daemonShutdown();
- break;
- default:
- std::clog << kLogWarning << "Unhandled signal (" << sig << ") " << strsignal(sig) << std::endl;
- break;
- }
+ switch (sig) {
+ case SIGHUP:
+ std::clog << kLogWarning << "Received SIGHUP signal." << std::endl;
+ break;
+ case SIGTERM:
+ std::clog << kLogWarning << "Received SIGTERM signal." << std::endl;
+ daemonShutdown();
+ break;
+ case SIGINT:
+ std::clog << kLogWarning << "Received SIGINT signal." << std::endl;
+ daemonShutdown();
+ break;
+ default:
+ std::clog << kLogWarning << "Unhandled signal (" << sig << ") "
+ << strsignal(sig) << std::endl;
+ break;
+ }
}
+knxdmxd::Trigger *json_get_trigger(struct json_object *trigger,
+ const int type) {
-knxdmxd::Trigger *json_get_trigger(struct json_object *trigger, const int type) {
-
if (!trigger) {
return NULL;
}
@@ -252,72 +224,79 @@
return new knxdmxd::Trigger(type, knx, val);
}
-knxdmxd::Cue *json_get_cue(struct json_object *cue, const int cuenum, const int type) {
+knxdmxd::Cue *json_get_cue(struct json_object *cue, const int cuenum,
+ const int type) {
// check link first
- struct json_object *link = json_object_object_get(cue, "link");
+ struct json_object *link = json_object_object_get(cue, "link");
if (link) { // is link
- knxdmxd::Cue *new_cue = new knxdmxd::Cue(json_object_get_string(link), true);
+ knxdmxd::Cue *new_cue = new knxdmxd::Cue(json_object_get_string(link),
+ true);
return new_cue;
}
struct json_object *name = json_object_object_get(cue, "name");
- std::string c_name = (name) ? json_object_get_string(name) : "_c_"+t_to_string(cuenum);
+ std::string c_name =
+ (name) ? json_object_get_string(name) : "_c_" + t_to_string(cuenum);
knxdmxd::Cue *new_cue = new knxdmxd::Cue(c_name);
-
+
// get channels
struct json_object *channels = json_object_object_get(cue, "channels");
if (!channels) {
- std::clog << kLogInfo << "Skipping cue '" << c_name << "' (no channels defined)" << std::endl;
+ std::clog << kLogInfo << "Skipping cue '" << c_name
+ << "' (no channels defined)" << std::endl;
delete new_cue;
return new_cue;
}
-
- for (int j=0; j<json_object_array_length(channels); j++) { // read all
+
+ for (int j = 0; j < json_object_array_length(channels); j++) { // read all
// get channel
struct json_object *channel = json_object_array_get_idx(channels, j);
- struct json_object *fixt = json_object_object_get(channel, "fixture");
- struct json_object *chan = json_object_object_get(channel, "channel");
- struct json_object *value = json_object_object_get(channel, "value");
+ struct json_object *fixt = json_object_object_get(channel, "fixture");
+ struct json_object *chan = json_object_object_get(channel, "channel");
+ struct json_object *value = json_object_object_get(channel, "value");
if ((!fixt) || (!chan) || (!value)) {
- std::clog << kLogInfo << "Skipping errorneous channel def " << j << " in cue '" << c_name << "'" << std::endl;
+ std::clog << kLogInfo << "Skipping errorneous channel def " << j
+ << " in cue '" << c_name << "'" << std::endl;
continue;
- }
-
+ }
+
knxdmxd::cue_channel_t channeldata;
channeldata.fixture = sender.GetFixture(json_object_get_string(fixt));
channeldata.name = json_object_get_string(chan);
channeldata.value = json_object_get_int(value);
-
+
// add
new_cue->AddChannel(channeldata);
}
// fading
-
+
struct json_object *fading = json_object_object_get(cue, "fading");
if (fading) {
- struct json_object *fading_time = json_object_object_get(fading, "time");
+ struct json_object *fading_time = json_object_object_get(fading, "time");
if (!fading_time) {
- struct json_object *fading_time_in = json_object_object_get(fading, "in");
- struct json_object *fading_time_out = json_object_object_get(fading, "out");
-
+ struct json_object *fading_time_in = json_object_object_get(fading, "in");
+ struct json_object *fading_time_out = json_object_object_get(fading,
+ "out");
+
if ((!fading_time_in) || (!fading_time_out)) {
- std::clog << kLogInfo << "Skipping errorneous fading def in cue '" << c_name << "'" << std::endl;
+ std::clog << kLogInfo << "Skip...
[truncated message content] |
|
From: <j-...@us...> - 2012-08-12 16:41:55
|
Revision: 942
http://openautomation.svn.sourceforge.net/openautomation/?rev=942&view=rev
Author: j-n-k
Date: 2012-08-12 16:41:47 +0000 (Sun, 12 Aug 2012)
Log Message:
-----------
knxdmxd: update for source, binary tbd
Modified Paths:
--------------
tools/knxdmxd/Makefile.am
tools/knxdmxd/src/cue.cc
tools/knxdmxd/src/cue.h
tools/knxdmxd/src/dmxsender.cc
tools/knxdmxd/src/dmxsender.h
tools/knxdmxd/src/fixture.cc
tools/knxdmxd/src/fixture.h
tools/knxdmxd/src/knxdmxd.cc
tools/knxdmxd/src/knxdmxd.h
tools/knxdmxd/src/trigger.cc
tools/knxdmxd/src/trigger.h
Modified: tools/knxdmxd/Makefile.am
===================================================================
--- tools/knxdmxd/Makefile.am 2012-08-12 16:33:10 UTC (rev 941)
+++ tools/knxdmxd/Makefile.am 2012-08-12 16:41:47 UTC (rev 942)
@@ -1,11 +1,2 @@
-# what flags you want to pass to the C compiler & linker
-#CPPFLAGS = --pedantic -Wall -std=c99 -O2
-#LDFLAGS =
-
-knxdmxd_CXXFLAGS = $(OLA_CFLAGS) $(AM_CXXFLAGS)
-knxdmxd_LDADD = $(OLA_LIBS)
-
-# this lists the binaries to produce, the (non-PHONY, binary) targets in
-# the previous manual Makefile
-bin_PROGRAMS = knxdmxd
-knxdmxd_SOURCES = knxdmxd.cc log.cc fixture.cc cue.cc dmxsender.cc trigger.cc
+AUTOMAKE_OPTIONS = foreign
+SUBDIRS = src
\ No newline at end of file
Modified: tools/knxdmxd/src/cue.cc
===================================================================
--- tools/knxdmxd/src/cue.cc 2012-08-12 16:33:10 UTC (rev 941)
+++ tools/knxdmxd/src/cue.cc 2012-08-12 16:41:47 UTC (rev 942)
@@ -13,8 +13,6 @@
Cue::Cue(const std::string name, const bool isLink) {
_name=name;
- lock_.locker = name; // default is cue-name
- lock_.prio = 0;
fadeIn_ = 0.0;
fadeOut_ = 0.0;
waittime_ = -1; // never step automatically
@@ -30,7 +28,7 @@
void Cue::AddChannel(const cue_channel_t& channel) {
_channel_data.push_back(channel);
- std::clog << "Cue " << _name << ": added channel definition " << channel.fixture->GetName() << "/" << channel.name << "@" << channel.value << std::endl;
+ std::clog << "Cue " << _name << ": added channel definition " << channel.dmx << "@" << channel.value << std::endl;
}
void Cue::SetFading(const float fadeIn, const float fadeOut) {
@@ -48,13 +46,7 @@
std::clog << "Called cue " << _name << " (delaying)" << std::endl;
} else {
for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
- if (!it->fixture->Lock(lock_)) { // Test if we can lock
- std::clog << _name << ": locking failed " << it->fixture->GetName() << std::endl;
- continue; // no, we can't
- }
- int deltaVal = it->fixture->GetCurrentValue(it->name) - it->value;
- float ft = (deltaVal>0) ? ((deltaVal+1)/(fadeOut_*1.e3/(DMX_INTERVAL+1))) : ((-deltaVal+1)/(fadeIn_*1.e3/(DMX_INTERVAL+1)));
- it->fixture->Update(it->name, it->value, ft);
+ DMX::SetDMXChannel(it->dmx , it->value, fadeIn_, fadeOut_ );
}
delay_on_ = false;
std::clog << "Called cue " << _name << std::endl;
@@ -64,9 +56,6 @@
Cuelist::Cuelist(const std::string name) {
_name=name;
-
- lock_.locker = name; // default is cuelist-name
- lock_.prio = 0;
current_cue_=-1;
was_direct_ = false;
@@ -111,33 +100,37 @@
case -2: // next on running cuelist
was_direct_ = true;
break;
-
}
if (max_cue_>(current_cue_+1)) {
- if (current_cue_>=0)
- cue_data_.at(current_cue_).Release();
- current_cue_++;
- knxdmxd::Cue cue = cue_data_.at(current_cue_);
- if (cue.isLink()) {
- current_cue_ = cue_names_.find(cue.GetName())->second;
- }
+ try {
+ if (current_cue_>=0)
+ cue_data_.at(current_cue_).Release();
+
+ current_cue_++;
+ knxdmxd::Cue cue = cue_data_.at(current_cue_);
+ if (cue.isLink()) {
+ current_cue_ = cue_names_.find(cue.GetName())->second;
+ }
- cue_data_.at(current_cue_).Go();
+ cue_data_.at(current_cue_).Go();
- float waittime;
- int nextCuenum = current_cue_+1;
- if (max_cue_>nextCuenum) { // last cue stops automatically
- knxdmxd::Cue nextCue = cue_data_.at(nextCuenum);
- if (nextCue.isLink()) {
- nextCuenum = cue_names_.find(nextCue.GetName())->second;
- nextCue = cue_data_.at(nextCuenum);
+ float waittime;
+ int nextCuenum = current_cue_+1;
+ if (max_cue_>nextCuenum) { // last cue stops automatically
+ knxdmxd::Cue nextCue = cue_data_.at(nextCuenum);
+ if (nextCue.isLink()) {
+ nextCuenum = cue_names_.find(nextCue.GetName())->second;
+ nextCue = cue_data_.at(nextCuenum);
+ }
+ waittime = nextCue.GetWaitTime();
+ if ((waittime>=0) && (!cue_halted_)) {
+ DMX::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
+ (int) waittime*1000, ola::NewSingleCallback(this, &Cuelist::NextCue, -1));
+ }
}
- waittime = nextCue.GetWaitTime();
- if ((waittime>=0) && (!cue_halted_)) {
- DMX::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
- (int) waittime*1000, ola::NewSingleCallback(this, &Cuelist::NextCue, -1));
- }
+ } catch (char *str) {
+ std::clog << kLogErr << "Exception " << str << " in calling cue, current_cue_ = " << current_cue_ << std::endl;
}
}
}
Modified: tools/knxdmxd/src/cue.h
===================================================================
--- tools/knxdmxd/src/cue.h 2012-08-12 16:33:10 UTC (rev 941)
+++ tools/knxdmxd/src/cue.h 2012-08-12 16:41:47 UTC (rev 942)
@@ -19,8 +19,7 @@
namespace knxdmxd {
typedef struct {
- pFixture fixture;
- std::string name;
+ dmx_addr_t dmx;
int value;
} cue_channel_t;
@@ -29,7 +28,7 @@
float fadeIn_, fadeOut_;
float waittime_, delay_;
bool is_link_, delay_on_;
- fixture_lock_t lock_;
+ // fixture_lock_t lock_;
public:
Cue() {};
@@ -39,13 +38,13 @@
void SetFading(const float fadeIn, const float fadeOut);
void SetWaittime(const float waittime) { waittime_ = waittime; };
void SetDelay(const float delay) { delay_ = delay; };
- void SetLock(const fixture_lock_t lock) { lock_ = lock; };
+ // void SetLock(const fixture_lock_t lock) { lock_ = lock; };
void Go();
void Release() {
- for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
+ /*for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
it->fixture->Release(lock_);
- }
+ }*/
};
const std::string GetName() { return _name; };
@@ -59,7 +58,7 @@
int current_cue_, max_cue_;
bool cue_halted_, was_direct_;
bool release_on_halt_;
- fixture_lock_t lock_;
+ // fixture_lock_t lock_;
std::vector<knxdmxd::Cue> cue_data_;
std::map<std::string, int> cue_names_;
Modified: tools/knxdmxd/src/dmxsender.cc
===================================================================
--- tools/knxdmxd/src/dmxsender.cc 2012-08-12 16:33:10 UTC (rev 941)
+++ tools/knxdmxd/src/dmxsender.cc 2012-08-12 16:41:47 UTC (rev 942)
@@ -11,9 +11,20 @@
namespace knxdmxd {
+ dmx_addr_t DMX::Address(const std::string addr) {
+ char universe;
+ int channel;
+ sscanf( (char*)addr.c_str(), "%d.%d", &universe, &channel);
+ return (channel==-1) ? (universe+512) : ((universe << 9) + channel);
+ }
+
+ // initalize static variables of DMX class
+ ola::OlaCallbackClientWrapper DMX::m_client;
+ std::map<char, knxdmxd::pUniverse> DMX::output;
+
bool DMXSender::Init() {
if (!m_client.Setup()) {
- std::clog << kLogWarning << "OLA: client Setup failed " << std::endl;
+ std::clog << kLogWarning << "DMXSender: OLA client setup failed " << std::endl;
return false;
}
return true;
@@ -21,19 +32,41 @@
int DMXSender::Start() {
SendDMX();
- fixture_list_.StartRefresh();
m_client.GetSelectServer()->Run();
sender_running_ = true;
return 0;
}
+ void Universe::Crossfade() {
+ ola::thread::MutexLocker locker(&data_mutex);
+ int i;
+ int max=512;
+ unsigned long currenttime = Timer::Get();
+
+ for(i=511; i>=0; max=i, i--) // find last value
+ if(new_[i]||old_[i])
+ break;
+
+ for(i=0; i<max; i++) {
+ if ((new_[i] || old_[i]) && (new_[i] != old_[i])) { /* avoid calculating with only 0 or finished */
+ if (currenttime>fadeend_[i]) {
+ current_[i] = old_[i] = new_[i];
+ } else {
+ float p = (float)(currenttime-fadestart_[i])/(fadeend_[i]-fadestart_[i]);
+ float q = 1.0f - p;
+ current_[i]=(unsigned char)(old_[i]*q + new_[i]*p);
+ }
+ }
+ }
+ }
+
void DMXSender::SendDMX() {
- for(std::map<int, ola::DmxBuffer>::const_iterator i = output.begin(); i != output.end(); ++i) {
+ for(std::map<char, pUniverse>::const_iterator i = output.begin(); i != output.end(); ++i) {
int universe = i->first;
- //std::clog << "C1/2 " << (int) i->second.Get(0) << " " << (int) i->second.Get(1) << " " << (int) i->second.Get(2) << std::endl;
- if (!m_client.GetClient()->SendDmx(universe, i->second)) { // send all universes
+ i->second->Crossfade();
+ if (!m_client.GetClient()->SendDmx(universe, i->second->GetBuffer())) { // send all universes
m_client.GetSelectServer()->Terminate();
- std::clog << kLogWarning << "OLA: failed to send universe "<< universe << std::endl;
+ std::clog << kLogWarning << "DMXSender: OLA failed to send universe "<< universe << std::endl;
sender_running_ = false;
return;
}
Modified: tools/knxdmxd/src/dmxsender.h
===================================================================
--- tools/knxdmxd/src/dmxsender.h 2012-08-12 16:33:10 UTC (rev 941)
+++ tools/knxdmxd/src/dmxsender.h 2012-08-12 16:41:47 UTC (rev 942)
@@ -4,7 +4,7 @@
* (c) by JNK 2012
*
*
-*/
+ */
#ifndef DMXSENDER_H
#define DMXSENDER_H
@@ -15,33 +15,91 @@
#include <ola/OlaCallbackClient.h>
#include <ola/OlaClientWrapper.h>
#include <map>
-#include <fixture.h>
namespace knxdmxd {
- class DMXSender : private DMX {
- FixtureList fixture_list_;
+ class Universe {
+ protected:
+ unsigned char current_[512], new_[512], old_[512];
+ unsigned long fadestart_[512], fadeend_[512];
+ ola::DmxBuffer buffer_;
+ ola::thread::Mutex data_mutex;
+ public:
+ Universe() {
+ ola::thread::MutexLocker locker(&data_mutex);
+ for (int i=0; i<512; i++) {
+ current_[i] = new_[i] = old_[i] = 0;
+ }
+ buffer_.Blackout();
+ };
+ void Set(const unsigned channel, const unsigned char value, const float fade_in=1.e-4, const float fade_out=1.e-4) {
+ ola::thread::MutexLocker locker(&data_mutex);
+ new_[channel] = value;
+ old_[channel] = current_[channel];
+ float fadeTime = (new_[channel]>current_[channel]) ? fade_in : fade_out;
+ fadestart_[channel] = Timer::Get();
+ fadeend_[channel] = fadestart_[channel] + (unsigned long) (fadeTime*1000.0);
+ }
+ unsigned char Get(const unsigned channel) {
+ return current_[channel];
+ }
+ ola::DmxBuffer &GetBuffer() {
+ ola::thread::MutexLocker locker(&data_mutex);
+ buffer_.Set(current_, 512);
+ return buffer_;
+ }
+ void Crossfade();
+ };
+
+ typedef Universe* pUniverse;
+
+ class DMX {
+ protected:
+ static std::map<char, pUniverse> output;
+ static ola::OlaCallbackClientWrapper m_client;
+
+ public:
+ DMX() {};
+ static void SetDMXChannel(const dmx_addr_t channel, const unsigned char value, const float fade_in=1.e-4, const float fade_out=1.e-4) {
+ int dmxuniverse = (int) (channel / 512), dmxchannel = channel % 512;
+ output[dmxuniverse]->Set(dmxchannel, value, fade_in, fade_out);
+ };
+ char GetDMXChannel(int channel);
+
+ static dmx_addr_t Address(const std::string s);
+ static ola::OlaCallbackClientWrapper& GetOLAClient() { return m_client; };
+
+ };
+
+ class DMXSender: private DMX {
bool sender_running_;
-
+
public:
- DMXSender() { sender_running_ = false; };
+ DMXSender() {
+ sender_running_ = false;
+ }
+
~DMXSender();
bool Init();
int Start();
void SendDMX();
-
+
void Terminate();
- bool Running() { return sender_running_; };
-
- void AddFixture(pFixture fixture) { fixture_list_.Add(fixture); };
- pFixture GetFixture(const std::string& name) { return fixture_list_.Get(name); };
+ bool Running() {
+ return sender_running_;
+ };
-// void Process(const Trigger& trigger) { fixture_list_.Process(trigger); };
+ void AddUniverse(char universe) {
+ if (!output.count(universe)) { // only create if not already existing;
+ pUniverse new_universe = new Universe();
+ output.insert(std::pair<char, pUniverse> (universe, new_universe));
+ std::clog << "DMXSender created universe " << (int) universe << std::endl;
+ }
+ };
};
-
}
#endif
Modified: tools/knxdmxd/src/fixture.cc
===================================================================
--- tools/knxdmxd/src/fixture.cc 2012-08-12 16:33:10 UTC (rev 941)
+++ tools/knxdmxd/src/fixture.cc 2012-08-12 16:41:47 UTC (rev 942)
@@ -10,7 +10,7 @@
namespace knxdmxd {
- Fixture::Fixture(const std::string name) {
+ /* Fixture::Fixture(const std::string name) {
name_ = name;
fadeTimeKNX_ = 0;
std::clog << "Creating Fixture " << name_ << std::endl;
@@ -70,20 +70,20 @@
bool Fixture::RegisterRefresh() {
m_client.GetSelectServer()->RegisterSingleTimeout(
- DMX_INTERVAL, ola::NewSingleCallback(this, &Fixture::Refresh));
+ DMX_INTERVAL, ola::NewSingleCallback(this, &Fixture::Refresh));
return true;
}
-
+
int Fixture::GetCurrentValue(const std::string& channel) {
return (int) channel_data_[channel_names_[channel]].floatValue;
}
-
+
void Fixture::Process(const Trigger& trigger) {
std::clog << "fprocess" << std::endl;
for (std::vector<knxdmxd::fixture_channel_t>::iterator it=channel_data_.begin(); it!=channel_data_.end(); ++it) {
if (it->KNX == trigger.GetKNX()) {
it->value = trigger.GetValue();
- it->fadeStep = _fadeStep;
+ it->fadeStep = _fadeStep;
refresh_ = true;
std::clog << "Updated " << it->DMX << " to " << it->value << "rate: " << it->fadeStep << std::endl;
}
@@ -91,35 +91,7 @@
if (fadeTimeKNX_ == trigger.GetKNX()) {
SetFadeTime(trigger.GetValue());
}
- }
-
- void DMX::SetDMXChannel(int channel, int value) {
- int dmxuniverse = (int) (channel / 512), dmxchannel = channel % 512;
- output[dmxuniverse].SetChannel(dmxchannel, value);
- }
-
- int DMX::GetDMXChannel(int channel) {
- int dmxuniverse = (int) (channel / 512), dmxchannel = channel % 512;
- return output[dmxuniverse].Get(dmxchannel);
- }
-
- int DMX::Address(const std::string addr) {
- int universe, channel;
- sscanf( (char*)addr.c_str(), "%d.%d", &universe, &channel);
- if (channel==-1) { // default universe is 1
- channel = universe;
- universe = 1;
- }
- return (universe << 9) + channel;
- }
+ } */
- void FixtureList::StartRefresh() {
- for(std::map<std::string, knxdmxd::pFixture>::iterator it=fixture_list_.begin(); it!=fixture_list_.end(); ++it) {
- it->second->RegisterRefresh();
- }
- }
- // initalize static variables of DMX class
- ola::OlaCallbackClientWrapper DMX::m_client;
- std::map<int, ola::DmxBuffer> DMX::output;
-
+
}
Modified: tools/knxdmxd/src/fixture.h
===================================================================
--- tools/knxdmxd/src/fixture.h 2012-08-12 16:33:10 UTC (rev 941)
+++ tools/knxdmxd/src/fixture.h 2012-08-12 16:41:47 UTC (rev 942)
@@ -13,101 +13,47 @@
#include <knxdmxd.h>
#include <trigger.h>
#include <ola/OlaClientWrapper.h>
+#include <ola/thread/Mutex.h>
+#include <dmxsender.h>
+
namespace knxdmxd {
- class DMX {
- protected:
- static std::map<int, ola::DmxBuffer> output;
- static ola::OlaCallbackClientWrapper m_client;
-
- public:
- DMX() {};
- void SetDMXChannel(int channel, int value);
- int GetDMXChannel(int channel);
-
- static int Address(const std::string s);
- static ola::OlaCallbackClientWrapper& GetOLAClient() { return m_client; };
-
- };
-
- typedef struct {
- int KNX, DMX, value;
- float fadeStep, floatValue;
- } fixture_channel_t;
-
- typedef struct {
- std::string locker;
- int prio;
- } fixture_lock_t;
-
- class Fixture : private DMX, public TriggerHandler {
+ class Dimmer : public TriggerHandler {
std::string name_;
- std::vector<fixture_channel_t> channel_data_;
- std::map<std::string, unsigned> channel_names_;
-
- float _fadeTime; // is set by knx or config
- float _fadeStep; // calculated from _fadeTime
- int fadeTimeKNX_;
- fixture_lock_t lock_;
-
- bool refresh_;
-
+ dmx_addr_t dmx_;
+ float fade_time_;
+ eibaddr_t ga_, ga_fading_;
public:
- Fixture() {};
- Fixture(const std::string name);
-
- void AddChannel(const std::string& name, const std::string& DMX, const std::string& KNX);
- void SetFadeTime(const float t);
- void PatchFadeTime(const int KNX) { fadeTimeKNX_ = KNX; };
- void Update(const std::string& channel, const int val, const float fadeStep);
- void Process(const Trigger& trigger);
-
- void Wait();
- void Refresh();
- bool RegisterRefresh();
-
- int GetCurrentValue(const std::string& channel);
- std::string& GetName() { return name_; };
-
- // locking
- bool Lock(const fixture_lock_t& lock) {
- if ((lock_.locker == lock.locker) || (lock_.locker == "") || (lock_.prio<=lock.prio)) {
- std::clog << "Locking " << lock.locker << " @ " << lock.prio << std::endl;
- lock_ = lock;
- return true;
- } else {
- std::clog << "Refused " << lock.locker << " @ " << lock.prio << std::endl;
- return false;
+ Dimmer() {};
+ Dimmer(const std::string name, eibaddr_t ga, dmx_addr_t dmx) {
+ name_ = name;
+ dmx_ = dmx;
+ ga_ = ga;
+ fade_time_ = 1.e-4;
+ std::clog << "Created dimmer '" << name << "' for "
+ << dmx << std::endl;
+ }
+ void SetFadeTime(float fade_time) {
+ fade_time_ = fade_time;
+ }
+ void SetFadeKNX(eibaddr_t ga) {
+ ga_fading_ = ga;
+ }
+ void Process(const Trigger& trigger) {
+ eibaddr_t ga = trigger.GetKNX();
+ std::clog << "Checking trigger" << trigger << " / " << ga_ << std::endl;
+ if (ga == ga_) {
+ DMX::SetDMXChannel(dmx_, trigger.GetValue(), fade_time_, fade_time_ );
+ std::clog << "Dimmer/Process: Updating value" << std::endl;
}
- };
- bool Release(const fixture_lock_t& lock) {
- if (lock_.locker == lock.locker) {
- lock_.locker = "";
- lock_.prio=0;
- return true;
- } else {
- return false;
+ if (ga == ga_fading_) {
+ std::clog << "Dimmer/Process: Updating fading" << std::endl;
}
- };
- fixture_lock_t GetLock() { return lock_; };
-
+ }
};
- typedef Fixture* pFixture;
- class FixtureList {
- std::map<std::string, knxdmxd::pFixture> fixture_list_;
-
- public:
- FixtureList() {};
-
- void Add(pFixture fixture) { fixture_list_.insert(std::pair<std::string, knxdmxd::pFixture> (fixture->GetName(), fixture)); };
- void StartRefresh();
-// void Process(const Trigger& trigger);
-
- pFixture Get(const std::string& name) { return fixture_list_[name]; };
- };
}
Modified: tools/knxdmxd/src/knxdmxd.cc
===================================================================
--- tools/knxdmxd/src/knxdmxd.cc 2012-08-12 16:33:10 UTC (rev 941)
+++ tools/knxdmxd/src/knxdmxd.cc 2012-08-12 16:41:47 UTC (rev 942)
@@ -71,9 +71,20 @@
std::string pidfilename = "/var/run/knxdmxd.pid";
knxdmxd::TriggerList triggerList;
knxdmxd::DMXSender sender;
+std::map<std::string, knxdmxd::dmx_addr_t> channel_names;
+std::map<knxdmxd::dmx_addr_t, eibaddr_t> statusmap;
+
namespace knxdmxd {
+ std::queue<Trigger> KNXHandler::fromKNX;
+ ola::thread::Mutex KNXHandler::mutex_fromKNX;
+ std::queue<eib_message_t> KNXHandler::toKNX;
+ ola::thread::Mutex KNXHandler::mutex_toKNX;
+
+ std::set<eibaddr_t> KNXHandler::listenGA;
+ std::map<eibaddr_t, long> KNXHandler::messagetracker;
+
eibaddr_t KNXHandler::Address(const std::string addr) {
int a, b, c;
char *s = (char *) addr.c_str();
@@ -111,6 +122,16 @@
}
while (1) {
+ triggerList.Process();
+ knxdmxd::eib_message_t message;
+ if (!KNXHandler::toKNX.empty()) { // there is something to send
+ {
+ ola::thread::MutexLocker locker(&KNXHandler::mutex_toKNX);
+ message = KNXHandler::toKNX.front();
+ KNXHandler::toKNX.pop();
+ }
+ std::clog << "KNXOut : " << message.ga << std::endl;
+ }
len = EIBGetGroup_Src(con, sizeof(buf), buf, &src, &dest);
if (len == -1) {
std::clog << kLogWarning << "eibd: Read failed" << std::endl;
@@ -138,8 +159,13 @@
case 0x80:
if (buf[1] & 0xC0) {
val = (len == 2) ? buf[1] & 0x3F : buf[2];
- knxdmxd::Trigger trigger(knxdmxd::kTriggerAll, dest, val);
- triggerList.Process(trigger);
+ if (KNXHandler::listenGA.count(dest)) { // keep queue clean from unwanted messages
+ std::clog << "EIBD: " << dest << " " << (int) val << std::endl;
+ knxdmxd::Trigger trigger(knxdmxd::kTriggerAll, dest, val);
+ ola::thread::MutexLocker locker(&KNXHandler::mutex_fromKNX);
+ KNXHandler::fromKNX.push(trigger);
+ }
+
}
break;
}
@@ -218,9 +244,10 @@
return NULL;
}
- int knx = knxdmxd::KNXHandler::Address(json_object_get_string(trigger_knx));
- int val = (trigger_value) ? json_object_get_int(trigger_value) : -1;
+ eibaddr_t knx = knxdmxd::KNXHandler::Address(json_object_get_string(trigger_knx));
+ int val = (trigger_value) ? json_object_get_int(trigger_value) : 256;
+ knxdmxd::KNXHandler::listenGA.insert(knx);
return new knxdmxd::Trigger(type, knx, val);
}
@@ -241,7 +268,7 @@
knxdmxd::Cue *new_cue = new knxdmxd::Cue(c_name);
// get channels
- struct json_object *channels = json_object_object_get(cue, "channels");
+ struct json_object *channels = json_object_object_get(cue, "data");
if (!channels) {
std::clog << kLogInfo << "Skipping cue '" << c_name
<< "' (no channels defined)" << std::endl;
@@ -253,19 +280,26 @@
// get channel
struct json_object *channel = json_object_array_get_idx(channels, j);
- struct json_object *fixt = json_object_object_get(channel, "fixture");
struct json_object *chan = json_object_object_get(channel, "channel");
struct json_object *value = json_object_object_get(channel, "value");
- if ((!fixt) || (!chan) || (!value)) {
+ if ((!chan) || (!value)) {
std::clog << kLogInfo << "Skipping errorneous channel def " << j
<< " in cue '" << c_name << "'" << std::endl;
continue;
}
+ std::string chan_str = json_object_get_string(chan);
+ if (!channel_names.count(chan_str)) {
+ std::clog << kLogInfo << "Skipping errorneous channel def " << j
+ << " in cue '" << c_name << "'" << std::endl;
+ continue;
+ }
+ knxdmxd::dmx_addr_t dmx = channel_names.find(chan_str)->second;
+
knxdmxd::cue_channel_t channeldata;
- channeldata.fixture = sender.GetFixture(json_object_get_string(fixt));
- channeldata.name = json_object_get_string(chan);
+
+ channeldata.dmx = dmx;
channeldata.value = json_object_get_int(value);
// add
@@ -333,82 +367,107 @@
config = json_object_from_file((char *) conf_file.c_str());
/*
- * fixtures
+ * channel definitions
*/
+ struct json_object *in_data = json_object_object_get(config, "channels");
+ int in_length = json_object_array_length(in_data);
+ std::clog << "Trying to import " << in_length << " channel(s)" << std::endl;
- struct json_object *fixtures = json_object_object_get(config, "fixtures");
- int fixturenum = json_object_array_length(fixtures);
- std::clog << "Trying to import " << fixturenum << " fixture(s)" << std::endl;
+ for (int i = 0; i < in_length; i++) { // read all
+ struct json_object *element = json_object_array_get_idx(in_data, i);
+ struct json_object *name = json_object_object_get(element, "name");
+ std::string name_str =
+ (name) ? json_object_get_string(name) : "_f_" + t_to_string(i);
+ struct json_object *dmx = json_object_object_get(element, "dmx");
+ if (!dmx) {
+ std::clog << kLogInfo << "Skipping channel '" << name_str
+ << " (missing dmx)" << std::endl;
+ continue;
+ }
+ knxdmxd::dmx_addr_t dmx_addr(knxdmxd::DMX::Address(json_object_get_string(dmx)));
+ sender.AddUniverse((char) (dmx_addr / 512));
+ channel_names.insert(std::pair<std::string, knxdmxd::dmx_addr_t> (name_str, dmx_addr));
- for (int i = 0; i < fixturenum; i++) { // read all
+ std::clog << "Named DMX " << dmx_addr << " as " << name_str;
+ struct json_object *ga = json_object_object_get(element, "statusga");
+ if (!ga) {
+ std::clog << std::endl;
+ continue;
+ }
+
+ std::string ga_str = json_object_get_string(ga);
+ statusmap.insert(std::pair<knxdmxd::dmx_addr_t, eibaddr_t> (dmx_addr, knxdmxd::KNXHandler::Address(ga_str)));
+ std::clog << " (GA: " << ga_str << ")" << std::endl;
+
+ }
+
+ /*
+ * dimmers
+ */
+
+ in_data = json_object_object_get(config, "dimmers");
+ in_length = json_object_array_length(in_data);
+ std::clog << "Trying to import " << in_length << " dimmer(s)" << std::endl;
+
+ for (int i = 0; i < in_length; i++) { // read all
// get fixture
- struct json_object *fixture = json_object_array_get_idx(fixtures, i);
+ struct json_object *element = json_object_array_get_idx(in_data, i);
// get name & create
- struct json_object *name = json_object_object_get(fixture, "name");
- std::string fname =
- (name) ? json_object_get_string(name) : "_f_" + t_to_string(i);
- knxdmxd::Fixture* f = new knxdmxd::Fixture(fname);
+ struct json_object *name = json_object_object_get(element, "name");
+ std::string name_str =
+ (name) ? json_object_get_string(name) : "_d_" + t_to_string(i);
- // get channels & patch them
- struct json_object *channels = json_object_object_get(fixture, "channels");
- if (!channels) {
- std::clog << kLogInfo << "Skipping fixture '" << fname
+ // get channel
+ struct json_object *channel = json_object_object_get(element, "channel");
+ if (!channel) {
+ std::clog << kLogInfo << "Skipping dimmer '" << name_str
<< "' (no channels defined)" << std::endl;
continue;
}
+ std::string channel_str = json_object_get_string(channel);
+ if (!channel_names.count(channel_str)) {
+ std::clog << kLogInfo << "Skipping dimmer '" << name_str
+ << "' (invalid channel name)" << std::endl;
+ continue;
+ }
+ knxdmxd::dmx_addr_t dmx = channel_names.find(channel_str)->second;
- for (int j = 0; j < json_object_array_length(channels); j++) { // read all
- // get channel
- struct json_object *channel = json_object_array_get_idx(channels, j);
+ struct json_object *ga = json_object_object_get(element, "ga");
+ if (!ga) {
+ std::clog << kLogInfo << "Skipping dimmer '" << name_str
+ << "' (no group address defined)" << std::endl;
+ continue;
+ }
- // channel name, default is _c_<num>
- struct json_object *name = json_object_object_get(channel, "name");
- std::string cname =
- (name) ? json_object_get_string(name) : "_c_" + t_to_string(j);
+ eibaddr_t ga_ = knxdmxd::KNXHandler::Address(json_object_get_string(ga));
- // dmx is required
- struct json_object *dmx = json_object_object_get(channel, "dmx");
- if (!dmx) {
- std::clog << kLogInfo << "Skipping channel '" << cname
- << "' in fixture '" << fname << "' (missing dmx)" << std::endl;
- continue;
- }
- std::string cdmx(json_object_get_string(dmx));
+ knxdmxd::Dimmer* d = new knxdmxd::Dimmer(name_str, ga_, dmx);
- // knx is optional
- struct json_object *knx = json_object_object_get(channel, "knx"); // knx is optional
- if (knx) { // if we have knx, add to triggerlist
- f->AddChannel(cname, cdmx, json_object_get_string(knx));
- knxdmxd::Trigger* trigger = new knxdmxd::Trigger(
- knxdmxd::kTriggerProcess,
- knxdmxd::KNXHandler::Address(json_object_get_string(knx)), -1);
- triggerList.Add(*trigger, f);
- } else {
- f->AddChannel(cname, cdmx, "");
- }
- }
+ knxdmxd::KNXHandler::listenGA.insert(ga_);
+ knxdmxd::Trigger* trigger = new knxdmxd::Trigger(
+ knxdmxd::kTriggerProcess,
+ ga_, 256);
+ triggerList.Add(*trigger, d);
// get fading
- struct json_object *fading = json_object_object_get(fixture, "fading");
- float ftime =
- (fading) ?
- json_object_get_double(json_object_object_get(fading, "time")) : 0;
- f->SetFadeTime(ftime);
+ struct json_object *fading = json_object_object_get(element, "fading");
+ if (fading) {
+ d->SetFadeTime(json_object_get_do...
[truncated message content] |
|
From: <j-...@us...> - 2012-08-12 18:10:50
|
Revision: 943
http://openautomation.svn.sourceforge.net/openautomation/?rev=943&view=rev
Author: j-n-k
Date: 2012-08-12 18:10:44 +0000 (Sun, 12 Aug 2012)
Log Message:
-----------
knxdmxd: Minor bugfix and binary
Modified Paths:
--------------
tools/knxdmxd/knxdmxd
tools/knxdmxd/knxdmxd.conf
tools/knxdmxd/src/dmxsender.cc
tools/knxdmxd/src/dmxsender.h
tools/knxdmxd/src/knxdmxd.cc
Modified: tools/knxdmxd/knxdmxd
===================================================================
(Binary files differ)
Modified: tools/knxdmxd/knxdmxd.conf
===================================================================
--- tools/knxdmxd/knxdmxd.conf 2012-08-12 16:41:47 UTC (rev 942)
+++ tools/knxdmxd/knxdmxd.conf 2012-08-12 18:10:44 UTC (rev 943)
@@ -1,31 +1,40 @@
// CAUTION : never uses names starting with _ !!! These are used internally !
-{ "fixtures": [ // all fixture definitions
- { "name" : "Treppe", // name is optional, default is _f_<number>
- "channels" : [ // channel definition, dmx is mandatory, default name is _c_<number>
- { "name": "oben", "dmx" : "1.0", "knx" : "1/7/170" },
- { "name": "mitte", "knx" : "1/7/170", "dmx" : "1.1" },
- { "name": "unten", "knx" : "1/7/170", "dmx" : "1.2" }
- ],
- "fading" : { "knx" : "1/6/170", "time": 1 } // knx-like dimming: fading is calculated for 0-100%
- },
- { "name" : "Kueche",
- "channels" : [
- { "name": "R", "knx" : "1/7/141", "dmx" : "1.10" },
- { "name": "G", "knx" : "1/7/142", "dmx" : "1.11" },
- { "name": "B", "knx" : "1/7/143", "dmx" : "1.12" }
- ],
- "fading" : { "knx" : "1/6/141", "time": 3.0 }
- }
+{
+"channels" : [
+ { "name" : "treppe_01", "dmx" : "1.1" },
+ { "name" : "treppe_02", "dmx" : "1.2" },
+ { "name" : "treppe_03", "dmx" : "1.3" },
+ { "name" : "treppe_04", "dmx" : "1.4" },
+ { "name" : "treppe_05", "dmx" : "1.5" },
+ { "name" : "treppe_06", "dmx" : "1.6" },
+ { "name" : "treppe_07", "dmx" : "1.7" },
+ { "name" : "treppe_08", "dmx" : "1.8" },
+ { "name" : "treppe_09", "dmx" : "1.16" },
+ { "name" : "treppe_10", "dmx" : "1.17" },
+ { "name" : "treppe_11", "dmx" : "1.18" },
+ { "name" : "treppe_12", "dmx" : "1.19" },
+ { "name" : "treppe_13", "dmx" : "1.20" },
+ { "name" : "kueche_r", "dmx" : "1.40", "statusga" : "12/1/20"},
+ { "name" : "kueche_g", "dmx" : "1.41", "statusga" : "12/1/21"},
+ { "name" : "kueche_b", "dmx" : "1.42", "statusga" : "12/1/22"}
],
+"dimmers": [ // all dimmer definitions, name is optional (default is _d_<number>), knx-like dimming: fading is calculated for 0-100%
+ { "name" : "Treppe01", "channel" : "treppe_01", "ga" : "12/0/1", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe02", "channel" : "treppe_02", "ga" : "12/0/2", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe03", "channel" : "treppe_03", "ga" : "12/0/3", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "KuecheR", "channel" : "kueche_r", "ga" : "12/0/20" },
+ { "name" : "KuecheG", "channel" : "kueche_g", "ga" : "12/0/21" },
+ { "name" : "KuecheB", "channel" : "kueche_b", "ga" : "12/0/22" }
+],
"scenes": [ // all scene definitions
{ "name" : "Treppe_Full_On", // name is optional, default is _s_<number>
"trigger" : {
- "go" : { "knx" : "1/0/170", "value" : 1 }, // if value is omitted, scene is called on any value
+ "go" : { "knx" : "12/0/170", "value" : 1 }, // if value is omitted, scene is called on any value
},
- "channels" : [ // definition of each channel in scene
- { "fixture" : "Treppe", "channel" : "oben", "value" : 255 },
- { "fixture" : "Treppe", "channel" : "mitte", "value" : 255 },
- { "fixture" : "Treppe", "channel" : "unten", "value" : 255 }
+ "data" : [ // definition of each channel in scene
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 255 }
],
"fading" : { // all fading times used on scene call !
"in" : 1.0, // for increasing intensity
@@ -34,12 +43,12 @@
},
{ "name" : "Treppe_Blackout",
"trigger" : {
- "go" : { "knx" : "1/0/170", "value" : 0 },
+ "go" : { "knx" : "12/0/170", "value" : 0 },
},
- "channels" : [
- { "fixture" : "Treppe", "channel" : "oben", "value" : 0 },
- { "fixture" : "Treppe", "channel" : "mitte", "value" : 0 },
- { "fixture" : "Treppe", "channel" : "unten", "value" : 0 }
+ "data" : [
+ { "channel" : "treppe_01", "value" : 0 },
+ { "channel" : "treppe_02", "value" : 0 },
+ { "channel" : "treppe_03", "value" : 0 }
],
"fading" : {
"time" : 1 // used for in and out
@@ -48,51 +57,91 @@
],
"cuelists": [ // all cuelists
{ "name" : "Treppe Disco",
+ "priority" : 100,
+ "release_on_halt" : true,
"trigger" : {
"go" : { "knx" : "1/0/172", "value" : 1 },
- "halt" : { "knx" : "1/0/172", "value" : 0 }
+ "halt" : { "knx" : "1/0/172", "value" : 0 },
+ "direct" : { "knx" : "1/0/173" }, // direct call of a cue (first is 0)
},
"cues" : [ // cues are like scenes, just without individual triggers
- { "name" : "allesaus",
- "channels" : [
- { "fixture" : "Treppe", "channel" : "oben", "value" : 0 },
- { "fixture" : "Treppe", "channel" : "mitte", "value" : 0 },
- { "fixture" : "Treppe", "channel" : "unten", "value" : 0 }
+ { "name" : "start",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 0 },
+ { "channel" : "treppe_02", "value" : 0 },
+ { "channel" : "treppe_03", "value" : 0 }
],
- "waittime" : 3, // only relevant for loops
+ "waittime" : 3.1, // only relevant for loops
+ "delay" : 5,
"fading" : { "time" : 3 }
},
- { "name" : "obenan",
- "channels" : [
- { "fixture" : "Treppe", "channel" : "oben", "value" : 0 },
- { "fixture" : "Treppe", "channel" : "mitte", "value" : 255 },
- { "fixture" : "Treppe", "channel" : "unten", "value" : 0 }
+ { "name" : "c1",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 0 },
+ { "channel" : "treppe_03", "value" : 0 }
],
- "waittime" : 3,
+ "waittime" : 8.1,
"fading" : { "time" : 3 }
},
- { "name" : "beidean",
- "channels" : [
- { "fixture" : "Treppe", "channel" : "oben", "value" : 255 },
- { "fixture" : "Treppe", "channel" : "mitte", "value" : 255 },
- { "fixture" : "Treppe", "channel" : "unten", "value" : 0 }
+ { "name" : "c2",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 0 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 0 }
],
- "waittime" : 3, // waittime start after calling previous cue !
+ "waittime" : 3.1, // waittime start after calling previous cue !
"fading" : { "time" : 3 }
},
- { "name" : "untenan",
- "channels" : [
- { "fixture" : "Treppe", "channel" : "oben", "value" : 255 },
- { "fixture" : "Treppe", "channel" : "mitte", "value" : 0 },
- { "fixture" : "Treppe", "channel" : "unten", "value" : 0 }
+ { "name" : "c3",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 0 },
+ { "channel" : "treppe_02", "value" : 0 },
+ { "channel" : "treppe_03", "value" : 255 }
],
- "waittime" : 3,
+ "waittime" : 3.1, // waittime start after calling previous cue !
"fading" : { "time" : 3 }
},
- { "link" : "allesaus"
+ { "link" : "start"
}
-
]
+ },
+ { "name" : "KuecheFarbwechsler",
+ "trigger" : {
+ "go" : { "knx" : "1/0/131", "value" : 1 },
+ "halt" : { "knx" : "1/0/131", "value" : 0 }
+ },
+ "cues" : [ // cues are like scenes, just without individual triggers
+ { "name" : "step1",
+ "data" : [
+ { "channel" : "kueche_r", "value" : 255 },
+ { "channel" : "kueche_g", "value" : 0 },
+ { "channel" : "kueche_b", "value" : 0 }
+ ],
+ "waittime" : 10, // only relevant for loops
+ "fading" : { "time" : 10 },
+ },
+ { "name" : "step2",
+ "data" : [
+ { "channel" : "kueche_r", "value" : 0 },
+ { "channel" : "kueche_g", "value" : 255 },
+ { "channel" : "kueche_b", "value" : 0 }
+ ],
+ "waittime" : 10, // only relevant for loops
+ "fading" : { "time" : 10 },
+ },
+ { "name" : "step3",
+ "data" : [
+ { "channel" : "kueche_r", "value" : 0 },
+ { "channel" : "kueche_g", "value" : 0 },
+ { "channel" : "kueche_b", "value" : 255 }
+ ],
+ "waittime" : 10, // only relevant for loops
+ "fading" : { "time" : 10 },
+ },
+ { "link" : "step1"
+ }
+ ]
}
]
}
Modified: tools/knxdmxd/src/dmxsender.cc
===================================================================
--- tools/knxdmxd/src/dmxsender.cc 2012-08-12 16:41:47 UTC (rev 942)
+++ tools/knxdmxd/src/dmxsender.cc 2012-08-12 18:10:44 UTC (rev 943)
@@ -14,7 +14,9 @@
dmx_addr_t DMX::Address(const std::string addr) {
char universe;
int channel;
+ std::clog << "a " << addr << std::endl;
sscanf( (char*)addr.c_str(), "%d.%d", &universe, &channel);
+ std::clog << "b" << std::endl;
return (channel==-1) ? (universe+512) : ((universe << 9) + channel);
}
Modified: tools/knxdmxd/src/dmxsender.h
===================================================================
--- tools/knxdmxd/src/dmxsender.h 2012-08-12 16:41:47 UTC (rev 942)
+++ tools/knxdmxd/src/dmxsender.h 2012-08-12 18:10:44 UTC (rev 943)
@@ -66,7 +66,7 @@
};
char GetDMXChannel(int channel);
- static dmx_addr_t Address(const std::string s);
+ static dmx_addr_t Address(const std::string addr);
static ola::OlaCallbackClientWrapper& GetOLAClient() { return m_client; };
};
Modified: tools/knxdmxd/src/knxdmxd.cc
===================================================================
--- tools/knxdmxd/src/knxdmxd.cc 2012-08-12 16:41:47 UTC (rev 942)
+++ tools/knxdmxd/src/knxdmxd.cc 2012-08-12 18:10:44 UTC (rev 943)
@@ -376,18 +376,21 @@
for (int i = 0; i < in_length; i++) { // read all
struct json_object *element = json_object_array_get_idx(in_data, i);
struct json_object *name = json_object_object_get(element, "name");
+
std::string name_str =
(name) ? json_object_get_string(name) : "_f_" + t_to_string(i);
struct json_object *dmx = json_object_object_get(element, "dmx");
+
if (!dmx) {
std::clog << kLogInfo << "Skipping channel '" << name_str
<< " (missing dmx)" << std::endl;
continue;
}
- knxdmxd::dmx_addr_t dmx_addr(knxdmxd::DMX::Address(json_object_get_string(dmx)));
+ std::string s = json_object_get_string(dmx);
+
+ knxdmxd::dmx_addr_t dmx_addr(knxdmxd::DMX::Address(s));
sender.AddUniverse((char) (dmx_addr / 512));
channel_names.insert(std::pair<std::string, knxdmxd::dmx_addr_t> (name_str, dmx_addr));
-
std::clog << "Named DMX " << dmx_addr << " as " << name_str;
struct json_object *ga = json_object_object_get(element, "statusga");
if (!ga) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <j-...@us...> - 2012-10-08 18:15:50
|
Revision: 1033
http://openautomation.svn.sourceforge.net/openautomation/?rev=1033&view=rev
Author: j-n-k
Date: 2012-10-08 18:15:43 +0000 (Mon, 08 Oct 2012)
Log Message:
-----------
knxdmxd: Smaller fixes, new binary, ney sample config (important !)
Modified Paths:
--------------
tools/knxdmxd/knxdmxd
tools/knxdmxd/knxdmxd.conf
tools/knxdmxd/src/dmxsender.cc
tools/knxdmxd/src/dmxsender.h
tools/knxdmxd/src/knxdmxd.cc
Modified: tools/knxdmxd/knxdmxd
===================================================================
(Binary files differ)
Modified: tools/knxdmxd/knxdmxd.conf
===================================================================
--- tools/knxdmxd/knxdmxd.conf 2012-10-08 07:44:15 UTC (rev 1032)
+++ tools/knxdmxd/knxdmxd.conf 2012-10-08 18:15:43 UTC (rev 1033)
@@ -29,12 +29,22 @@
"scenes": [ // all scene definitions
{ "name" : "Treppe_Full_On", // name is optional, default is _s_<number>
"trigger" : {
- "go" : { "knx" : "12/0/170", "value" : 1 }, // if value is omitted, scene is called on any value
+ "go" : { "knx" : "1/0/170", "value" : 1 }, // if value is omitted, scene is called on any value
},
"data" : [ // definition of each channel in scene
{ "channel" : "treppe_01", "value" : 255 },
{ "channel" : "treppe_02", "value" : 255 },
- { "channel" : "treppe_03", "value" : 255 }
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 255 },
+ { "channel" : "treppe_05", "value" : 255 },
+ { "channel" : "treppe_06", "value" : 255 },
+ { "channel" : "treppe_07", "value" : 255 },
+ { "channel" : "treppe_08", "value" : 255 },
+ { "channel" : "treppe_09", "value" : 255 },
+ { "channel" : "treppe_10", "value" : 255 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 }
],
"fading" : { // all fading times used on scene call !
"in" : 1.0, // for increasing intensity
@@ -43,16 +53,39 @@
},
{ "name" : "Treppe_Blackout",
"trigger" : {
- "go" : { "knx" : "12/0/170", "value" : 0 },
+ "go" : { "knx" : "1/0/170", "value" : 0 },
},
"data" : [
- { "channel" : "treppe_01", "value" : 0 },
- { "channel" : "treppe_02", "value" : 0 },
- { "channel" : "treppe_03", "value" : 0 }
+ { "channel" : "treppe_01", "value" : 0 },
+ { "channel" : "treppe_02", "value" : 0 },
+ { "channel" : "treppe_03", "value" : 0 },
+ { "channel" : "treppe_04", "value" : 0 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 0 },
+ { "channel" : "treppe_11", "value" : 0 },
+ { "channel" : "treppe_12", "value" : 0 },
+ { "channel" : "treppe_13", "value" : 0 }
],
"fading" : {
"time" : 1 // used for in and out
}
+ },
+ { "name" : "Kueche_aus",
+ "trigger" : {
+ "go" : { "knx" : "0/0/4", "value" : 0 },
+ },
+ "data" : [
+ { "channel" : "kueche_r", "value" : 0 },
+ { "channel" : "kueche_g", "value" : 0 },
+ { "channel" : "kueche_b", "value" : 0 }
+ ],
+ "fading" : {
+ "time" : 1 // used for in and out
+ }
}
],
"cuelists": [ // all cuelists
Modified: tools/knxdmxd/src/dmxsender.cc
===================================================================
--- tools/knxdmxd/src/dmxsender.cc 2012-10-08 07:44:15 UTC (rev 1032)
+++ tools/knxdmxd/src/dmxsender.cc 2012-10-08 18:15:43 UTC (rev 1033)
@@ -12,12 +12,12 @@
{
dmx_addr_t
- DMX::Address(const std::string addr)
+ DMX::Address(const std::string &addr)
{
- char universe;
- int channel;
- sscanf((char*) addr.c_str(), "%d.%d", &universe, &channel);
- return (channel == -1) ? (universe + 512) : ((universe << 9) + channel);
+ int universe, channel;
+ std::string c(addr);
+ sscanf((char*) c.c_str(), "%d.%d", &universe, &channel);
+ return (channel == -1) ? (universe + 512) : ((((unsigned) universe) << 9) + channel);
}
// initalize static variables of DMX class
Modified: tools/knxdmxd/src/dmxsender.h
===================================================================
--- tools/knxdmxd/src/dmxsender.h 2012-10-08 07:44:15 UTC (rev 1032)
+++ tools/knxdmxd/src/dmxsender.h 2012-10-08 18:15:43 UTC (rev 1033)
@@ -93,7 +93,7 @@
GetDMXChannel(int channel);
static dmx_addr_t
- Address(const std::string addr);
+ Address(const std::string &addr);
static ola::OlaCallbackClientWrapper&
GetOLAClient()
{
Modified: tools/knxdmxd/src/knxdmxd.cc
===================================================================
--- tools/knxdmxd/src/knxdmxd.cc 2012-10-08 07:44:15 UTC (rev 1032)
+++ tools/knxdmxd/src/knxdmxd.cc 2012-10-08 18:15:43 UTC (rev 1033)
@@ -91,12 +91,12 @@
eibaddr_t
KNXHandler::Address(const std::string addr)
{
- int a, b, c;
+ unsigned int a, b, c;
char *s = (char *) addr.c_str();
- if (sscanf(s, "%d/%d/%d", &a, &b, &c) == 3)
+ if (sscanf(s, "%u/%u/%u", &a, &b, &c) == 3)
return ((a & 0x01f) << 11) | ((b & 0x07) << 8) | ((c & 0xff));
- if (sscanf(s, "%d/%d", &a, &b) == 2)
+ if (sscanf(s, "%u/%u", &a, &b) == 2)
return ((a & 0x01f) << 11) | ((b & 0x7FF));
if (sscanf(s, "%x", &a) == 1)
return a & 0xffff;
@@ -108,12 +108,12 @@
eibaddr_t
KNXSender::Address(const std::string addr)
{
- int a, b, c;
+ unsigned int a, b, c;
char *s = (char *) addr.c_str();
- if (sscanf(s, "%d/%d/%d", &a, &b, &c) == 3)
+ if (sscanf(s, "%u/%u/%u", &a, &b, &c) == 3)
return ((a & 0x01f) << 11) | ((b & 0x07) << 8) | ((c & 0xff));
- if (sscanf(s, "%d/%d", &a, &b) == 2)
+ if (sscanf(s, "%u/%u", &a, &b) == 2)
return ((a & 0x01f) << 11) | ((b & 0x7FF));
if (sscanf(s, "%x", &a) == 1)
return a & 0xffff;
@@ -128,9 +128,7 @@
std::clog << "KNX sender thread started" << std::endl;
int len;
EIBConnection *con;
- eibaddr_t dest;
- eibaddr_t src;
- unsigned char buf[255], val;
+ unsigned char buf[255];
knxdmxd::eib_message_t message;
while (1)
{
@@ -204,7 +202,7 @@
void
KNXHandler::knxhandler()
{
- std::clog << "KNX thread started" << std::endl;
+ std::clog << "KNX handler thread started" << std::endl;
int len;
EIBConnection *con;
eibaddr_t dest;
@@ -233,7 +231,6 @@
while (1)
{
triggerList.Process();
- knxdmxd::eib_message_t message;
len = EIBGetGroup_Src(con, sizeof(buf), buf, &src, &dest);
if (len == -1)
{
@@ -677,8 +674,8 @@
(name) ? json_object_get_string(name) : "_c_" + t_to_string(i);
knxdmxd::Cuelist *c = new knxdmxd::Cuelist(cname);
- struct json_object *lprio = json_object_object_get(cuelist, "priority");
- int prio = (lprio) ? json_object_get_int(lprio) : 0;
+ //struct json_object *lprio = json_object_object_get(cuelist, "priority");
+ //int prio = (lprio) ? json_object_get_int(lprio) : 0;
// get cues
struct json_object *cues = json_object_object_get(cuelist, "cues");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <j-...@us...> - 2012-10-14 17:55:14
|
Revision: 1060
http://openautomation.svn.sourceforge.net/openautomation/?rev=1060&view=rev
Author: j-n-k
Date: 2012-10-14 17:55:08 +0000 (Sun, 14 Oct 2012)
Log Message:
-----------
Updating knxdmxd (fixing issue sending only one status-message)
Modified Paths:
--------------
tools/knxdmxd/knxdmxd
tools/knxdmxd/src/knxdmxd.cc
Modified: tools/knxdmxd/knxdmxd
===================================================================
(Binary files differ)
Modified: tools/knxdmxd/src/knxdmxd.cc
===================================================================
--- tools/knxdmxd/src/knxdmxd.cc 2012-10-13 18:39:52 UTC (rev 1059)
+++ tools/knxdmxd/src/knxdmxd.cc 2012-10-14 17:55:08 UTC (rev 1060)
@@ -133,9 +133,7 @@
while (1)
{
ola::thread::MutexLocker locker(&KNXSender::mutex_toKNX);
- std::clog << "KNX sender waiting for message" << std::endl;
- KNXSender::condition_toKNX.Wait(&KNXSender::mutex_toKNX);
- std::clog << "KNX sender resumed" << std::endl;
+
if (!KNXSender::toKNX.empty())
{ // there is something to send
@@ -192,9 +190,14 @@
<< message.ga << " (DPT: " << (int) message.dpt << ")"
<< std::endl;
}
-
+ usleep(25000); // wait 25 ms, max. 40 tps
EIBClose(con);
+ } else {
+ std::clog << "KNX sender waiting for message" << std::endl;
+ KNXSender::condition_toKNX.Wait(&KNXSender::mutex_toKNX);
+ std::clog << "KNX sender resumed" << std::endl;
+
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <j-...@us...> - 2012-10-28 16:06:12
|
Revision: 1079
http://openautomation.svn.sourceforge.net/openautomation/?rev=1079&view=rev
Author: j-n-k
Date: 2012-10-28 16:06:00 +0000 (Sun, 28 Oct 2012)
Log Message:
-----------
Fixed lots of bugs, including
- spamming of logfile in daemon-mode (should be INFO+up, was ALL)
- wrong DMX-channel numbering (started 0, but should be 1)
- cuelists should be halted after last cue (and released if
configured)
- waittime in cuelists should be treated as float, not integer
Modified Paths:
--------------
tools/knxdmxd/knxdmxd
tools/knxdmxd/src/cue.cc
tools/knxdmxd/src/cue.h
tools/knxdmxd/src/dmxsender.cc
tools/knxdmxd/src/dmxsender.h
tools/knxdmxd/src/knxdmxd.cc
tools/knxdmxd/src/trigger.cc
Modified: tools/knxdmxd/knxdmxd
===================================================================
(Binary files differ)
Modified: tools/knxdmxd/src/cue.cc
===================================================================
--- tools/knxdmxd/src/cue.cc 2012-10-28 08:54:08 UTC (rev 1078)
+++ tools/knxdmxd/src/cue.cc 2012-10-28 16:06:00 UTC (rev 1079)
@@ -4,131 +4,173 @@
* (c) by JNK 2012
*
*
-*/
+ */
-
#include "cue.h"
-namespace knxdmxd {
+namespace knxdmxd
+{
- Cue::Cue(const std::string name, const bool isLink) {
- _name=name;
+ Cue::Cue(const std::string name, const bool isLink)
+ {
+ _name = name;
fadeIn_ = 0.0;
fadeOut_ = 0.0;
waittime_ = -1; // never step automatically
delay_ = 0.0; // call immediately
delay_on_ = false;
is_link_ = isLink;
- if (!is_link_) {
- std::clog << "Creating Cue " << name << std::endl;
- } else {
- std::clog << "Creating link to cue " << name << std::endl;
- }
+ if (!is_link_)
+ {
+ std::clog << kLogDebug << "Creating Cue " << name << std::endl;
+ }
+ else
+ {
+ std::clog << kLogDebug << "Creating link to cue " << name << std::endl;
+ }
}
- void Cue::AddChannel(const cue_channel_t& channel) {
+ void
+ Cue::AddChannel(const cue_channel_t& channel)
+ {
_channel_data.push_back(channel);
- std::clog << "Cue " << _name << ": added channel definition " << channel.dmx << "@" << channel.value << std::endl;
+ std::clog << kLogDebug << "Cue " << _name << ": added channel definition "
+ << channel.dmx << "@" << channel.value << std::endl;
}
- void Cue::SetFading(const float fadeIn, const float fadeOut) {
- fadeIn_ = (fadeIn<1.e-3) ? (DMX_INTERVAL/1.e3) : fadeIn;
- fadeOut_ = (fadeOut<1.e-3) ? (DMX_INTERVAL/1.e3) : fadeOut;
-
- std::clog << kLogDebug << "Cue " << _name << ": set fading " << fadeIn_ << "/" << fadeOut_ << std::endl;
+ void
+ Cue::SetFading(const float fadeIn, const float fadeOut)
+ {
+ fadeIn_ = (fadeIn < 1.e-3) ? (DMX_INTERVAL / 1.e3) : fadeIn;
+ fadeOut_ = (fadeOut < 1.e-3) ? (DMX_INTERVAL / 1.e3) : fadeOut;
+
+ std::clog << kLogDebug << "Cue " << _name << ": set fading " << fadeIn_
+ << "/" << fadeOut_ << std::endl;
}
- void Cue::Go() {
- if ((delay_>0) && (!delay_on_)) {
- DMX::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
- (int) delay_*1000, ola::NewSingleCallback(this, &Cue::Go));
- delay_on_ = true;
- std::clog << "Called cue " << _name << " (delaying)" << std::endl;
- } else {
- for(std::list<cue_channel_t>::iterator it = _channel_data.begin(); it != _channel_data.end(); ++it) {
- DMX::SetDMXChannel(it->dmx , it->value, fadeIn_, fadeOut_ );
+ void
+ Cue::Go()
+ {
+ if ((delay_ > 0) && (!delay_on_))
+ {
+ DMX::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
+ (int) delay_ * 1000, ola::NewSingleCallback(this, &Cue::Go));
+ delay_on_ = true;
+ std::clog << kLogDebug << "Called cue " << _name << " (delaying)"
+ << std::endl;
}
- delay_on_ = false;
- std::clog << "Called cue " << _name << std::endl;
- }
+ else
+ {
+ for (std::list<cue_channel_t>::iterator it = _channel_data.begin();
+ it != _channel_data.end(); ++it)
+ {
+ DMX::SetDMXChannel(it->dmx, it->value, fadeIn_, fadeOut_);
+ }
+ delay_on_ = false;
+ std::clog << kLogDebug << "Called cue " << _name << std::endl;
+ }
}
- Cuelist::Cuelist(const std::string name) {
- _name=name;
- current_cue_=-1;
-
+ Cuelist::Cuelist(const std::string name)
+ {
+ _name = name;
+ current_cue_ = -1;
+
was_direct_ = false;
cue_halted_ = true;
release_on_halt_ = true;
-
+
max_cue_ = 0;
-
- std::clog << "Creating Cuelist '" << name << "'" << std::endl;
- }
- void Cuelist::AddCue(knxdmxd::Cue& cue) {
+ std::clog << kLogDebug << "Creating Cuelist '" << name << "'" << std::endl;
+ }
+
+ void
+ Cuelist::AddCue(knxdmxd::Cue& cue)
+ {
cue_data_.push_back(cue);
int cue_num = max_cue_;
- if (!cue.isLink()) {
- cue_names_.insert(std::pair<std::string, int>(cue.GetName(), cue_num));
- std::clog << "Cuelist " << _name << ": added cue " << cue.GetName() << " as #" << cue_num << std::endl;
- } else {
- std::clog << "Cuelist " << _name << ": added link to cue '" << cue.GetName() << "' as #" << cue_num << std::endl;
- }
+ if (!cue.isLink())
+ {
+ cue_names_.insert(std::pair<std::string, int>(cue.GetName(), cue_num));
+ std::clog << kLogDebug << "Cuelist " << _name << ": added cue "
+ << cue.GetName() << " as #" << cue_num << std::endl;
+ }
+ else
+ {
+ std::clog << kLogDebug << "Cuelist " << _name << ": added link to cue '"
+ << cue.GetName() << "' as #" << cue_num << std::endl;
+ }
max_cue_++;
}
- void Cuelist::NextCue(const int direct) {
- if (was_direct_) {
- was_direct_ = false;
- return;
- }
+ void
+ Cuelist::NextCue(const int direct)
+ {
+ if (was_direct_)
+ {
+ was_direct_ = false;
+ return;
+ }
- switch (direct) {
- default: // direct call
- if (direct>=max_cue_) { // called cue too large
- std::clog << kLogInfo << "Tried direct call to cue " << direct << " in cuelist " << _name << ": too large" << std::endl;
+ switch (direct)
+ {
+ default: // direct call
+ if (direct >= max_cue_)
+ { // called cue too large
+ std::clog << kLogInfo << "Tried direct call to cue " << direct
+ << " in cuelist " << _name << ": too large" << std::endl;
return;
}
- current_cue_ = direct - 1;
- if (!cue_halted_) // only if cuelist was running
- was_direct_ = true;
- break;
- case -1: // normal call
- break;
- case -2: // next on running cuelist
+ current_cue_ = direct - 1;
+ if (!cue_halted_) // only if cuelist was running
was_direct_ = true;
- break;
- }
+ break;
+ case -1: // normal call
+ break;
+ case -2: // next on running cuelist
+ was_direct_ = true;
+ break;
+ }
- if (max_cue_>(current_cue_+1)) {
- try {
- if (current_cue_>=0)
- cue_data_.at(current_cue_).Release();
+ if (max_cue_ > (current_cue_ + 1))
+ {
+ try
+ {
+ if (current_cue_ >= 0)
+ cue_data_.at(current_cue_).Release();
- current_cue_++;
- knxdmxd::Cue cue = cue_data_.at(current_cue_);
- if (cue.isLink()) {
- current_cue_ = cue_names_.find(cue.GetName())->second;
- }
-
- cue_data_.at(current_cue_).Go();
-
- float waittime;
- int nextCuenum = current_cue_+1;
- if (max_cue_>nextCuenum) { // last cue stops automatically
- knxdmxd::Cue nextCue = cue_data_.at(nextCuenum);
- if (nextCue.isLink()) {
- nextCuenum = cue_names_.find(nextCue.GetName())->second;
- nextCue = cue_data_.at(nextCuenum);
- }
- waittime = nextCue.GetWaitTime();
- if ((waittime>=0) && (!cue_halted_)) {
- DMX::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
- (int) waittime*1000, ola::NewSingleCallback(this, &Cuelist::NextCue, -1));
- }
+ current_cue_++;
+ knxdmxd::Cue cue = cue_data_.at(current_cue_);
+ if (cue.isLink())
+ {
+ current_cue_ = cue_names_.find(cue.GetName())->second;
}
+
+ cue_data_.at(current_cue_).Go();
+
+ float waittime;
+ int nextCuenum = current_cue_ + 1;
+ if (max_cue_ > nextCuenum)
+ {
+ knxdmxd::Cue nextCue = cue_data_.at(nextCuenum);
+ if (nextCue.isLink())
+ {
+ nextCuenum = cue_names_.find(nextCue.GetName())->second;
+ nextCue = cue_data_.at(nextCuenum);
+ }
+ waittime = nextCue.GetWaitTime();
+ if ((waittime >= 0) && (!cue_halted_))
+ {
+ DMX::GetOLAClient().GetSelectServer()->RegisterSingleTimeout(
+ (int) (waittime * 1000.),
+ ola::NewSingleCallback(this, &Cuelist::NextCue, -1));
+ }
+ } else {
+ // last cue halts automatically
+ Halt();
+ }
}
catch (char *str)
{
@@ -136,7 +178,7 @@
<< " in calling cue, current_cue_ = " << current_cue_
<< std::endl;
}
- }
+ }
}
}
Modified: tools/knxdmxd/src/cue.h
===================================================================
--- tools/knxdmxd/src/cue.h 2012-10-28 08:54:08 UTC (rev 1078)
+++ tools/knxdmxd/src/cue.h 2012-10-28 16:06:00 UTC (rev 1079)
@@ -150,7 +150,8 @@
void
Release()
{
- cue_data_.at(current_cue_).Release();
+ cue_halted_ = true;
+ current_cue_ = -1;
}
;
};
Modified: tools/knxdmxd/src/dmxsender.cc
===================================================================
--- tools/knxdmxd/src/dmxsender.cc 2012-10-28 08:54:08 UTC (rev 1078)
+++ tools/knxdmxd/src/dmxsender.cc 2012-10-28 16:06:00 UTC (rev 1079)
@@ -64,13 +64,13 @@
if (currenttime > fadeend_[i])
{
current_[i] = old_[i] = new_[i];
- std::clog << "DMXSender: Finished crossfading universe "
+ std::clog << kLogDebug << "DMXSender: Finished crossfading universe "
<< (int) universe_ << " channel " << i << " to "
<< (int) current_[i] << std::endl;
dmx_addr_t dmx = (universe_ << 9) + i; // calculate dmx-addr
if (knxdmxd::statusmap.count(dmx))
{
- std::clog << "DMXSender: writing status update to KNX "
+ std::clog << kLogDebug << "DMXSender: writing status update to KNX "
<< std::endl;
knxdmxd::eib_message_t message;
message.value = (long) new_[i];
Modified: tools/knxdmxd/src/dmxsender.h
===================================================================
--- tools/knxdmxd/src/dmxsender.h 2012-10-28 08:54:08 UTC (rev 1078)
+++ tools/knxdmxd/src/dmxsender.h 2012-10-28 16:06:00 UTC (rev 1079)
@@ -45,17 +45,18 @@
1.e-4, const float fade_out = 1.e-4)
{
ola::thread::MutexLocker locker(&data_mutex);
- new_[channel] = value;
- old_[channel] = current_[channel];
- float fadeTime = (new_[channel] > current_[channel]) ? fade_in : fade_out;
- fadestart_[channel] = Timer::Get();
- fadeend_[channel] = fadestart_[channel]
+ const unsigned ch = channel - 1;
+ new_[ch] = value;
+ old_[ch] = current_[ch];
+ float fadeTime = (new_[ch] > current_[ch]) ? fade_in : fade_out;
+ fadestart_[ch] = Timer::Get();
+ fadeend_[ch] = fadestart_[ch]
+ (unsigned long) (fadeTime * 1000.0);
}
unsigned char
Get(const unsigned channel)
{
- return current_[channel];
+ return current_[channel-1];
}
ola::DmxBuffer &
GetBuffer()
@@ -138,7 +139,7 @@
{ // only create if not already existing;
pUniverse new_universe = new Universe(universe);
output.insert(std::pair<char, pUniverse>(universe, new_universe));
- std::clog << "DMXSender created universe " << (int) universe
+ std::clog << kLogInfo << "DMXSender created universe " << (int) universe
<< std::endl;
}
}
@@ -163,7 +164,7 @@
dmx_ = dmx;
ga_ = ga;
fade_time_ = 1.e-4;
- std::clog << "Created dimmer '" << name << "' for " << dmx << std::endl;
+ std::clog << kLogDebug << "Created dimmer '" << name << "' for " << dmx << std::endl;
}
void
SetFadeTime(float fade_time)
@@ -179,17 +180,17 @@
Process(const Trigger& trigger)
{
eibaddr_t ga = trigger.GetKNX();
- std::clog << "Checking trigger " << trigger << " for " << name_
+ std::clog << kLogDebug << "Checking trigger " << trigger << " for " << name_
<< " (GA: " << ga_ << ")" << std::endl;
if (ga == ga_)
{
DMX::SetDMXChannel(dmx_, trigger.GetValue(), fade_time_, fade_time_);
- std::clog << "Dimmer/Process: Updating value for " << name_ << " to "
+ std::clog << kLogDebug << "Dimmer/Process: Updating value for " << name_ << " to "
<< trigger.GetValue() << std::endl;
}
if (ga == ga_fading_)
{
- std::clog << "Dimmer/Process: Updating (tba) fading for " << name_
+ std::clog << kLogDebug << "Dimmer/Process: Updating (tba) fading for " << name_
<< " to " << trigger.GetValue() << std::endl;
}
}
Modified: tools/knxdmxd/src/knxdmxd.cc
===================================================================
--- tools/knxdmxd/src/knxdmxd.cc 2012-10-28 08:54:08 UTC (rev 1078)
+++ tools/knxdmxd/src/knxdmxd.cc 2012-10-28 16:06:00 UTC (rev 1079)
@@ -179,14 +179,14 @@
len = EIBSendAPDU(con, len, buf);
if (len == -1)
{
- std::clog << "KNXSender: failed to sent " << (int) message.value
+ std::clog << kLogDebug << "KNXSender: failed to sent " << (int) message.value
<< " to " << message.ga << " (DPT: " << (int) message.dpt
<< ")" << std::endl;
}
else
{
- std::clog << "KNXSender: sent " << (int) message.value << " to "
+ std::clog << kLogDebug << "KNXSender: sent " << (int) message.value << " to "
<< message.ga << " (DPT: " << (int) message.dpt << ")"
<< std::endl;
}
@@ -194,9 +194,9 @@
EIBClose(con);
} else {
- std::clog << "KNX sender waiting for message" << std::endl;
+ std::clog << kLogDebug << "KNX sender waiting for message" << std::endl;
KNXSender::condition_toKNX.Wait(&KNXSender::mutex_toKNX);
- std::clog << "KNX sender resumed" << std::endl;
+ std::clog << kLogDebug << "KNX sender resumed" << std::endl;
}
}
@@ -271,7 +271,7 @@
val = (len == 2) ? buf[1] & 0x3F : buf[2];
if (KNXHandler::listenGA.count(dest))
{ // keep queue clean from unwanted messages
- std::clog << "KNXHandler: " << dest << " "
+ std::clog << kLogDebug << "KNXHandler: " << dest << " "
<< (int) val << std::endl;
knxdmxd::Trigger trigger(knxdmxd::kTriggerAll, dest,
val);
@@ -562,7 +562,7 @@
sender.AddUniverse((char) (dmx_addr / 512));
knxdmxd::channel_names.insert(
std::pair<std::string, knxdmxd::dmx_addr_t>(name_str, dmx_addr));
- std::clog << "Named DMX " << dmx_addr << " as " << name_str;
+ std::clog << kLogDebug << "Named DMX " << dmx_addr << " as " << name_str;
struct json_object *ga = json_object_object_get(element, "statusga");
if (!ga)
{
@@ -584,7 +584,7 @@
in_data = json_object_object_get(config, "dimmers");
in_length = json_object_array_length(in_data);
- std::clog << "Trying to import " << in_length << " dimmer(s)" << std::endl;
+ std::clog << kLogDebug << "Trying to import " << in_length << " dimmer(s)" << std::endl;
for (int i = 0; i < in_length; i++)
{ // read all
@@ -665,7 +665,7 @@
struct json_object *cuelists = json_object_object_get(config, "cuelists");
int cuelistnum = json_object_array_length(cuelists);
- std::clog << "Trying to import " << cuelistnum << " cuelist(s)" << std::endl;
+ std::clog << kLogDebug << "Trying to import " << cuelistnum << " cuelist(s)" << std::endl;
for (int i = 0; i < cuelistnum; i++)
{ // read all
@@ -777,15 +777,15 @@
std::clog.rdbuf(
new Log(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID,
LOG_USER));
- std::clog << "startup with debug; pidfile: " << pidfilename << ", eibd: "
+ std::clog << kLogDebug << "startup with debug; pidfile: " << pidfilename << ", eibd: "
<< knxhandler.GetEIBDURL() << std::endl;
}
else
{
- setlogmask(LOG_UPTO(LOG_DEBUG));
+ setlogmask(LOG_UPTO(LOG_INFO));
std::clog.rdbuf(new Log(DAEMON_NAME, LOG_CONS, LOG_USER));
}
- std::clog << kLogDebug << DAEMON_NAME << " compiled on " << __DATE__ << " "
+ std::clog << kLogInfo << DAEMON_NAME << " compiled on " << __DATE__ << " "
<< __TIME__ << " with GCC " << __VERSION__ << std::endl;
std::clog << kLogInfo << "using config-file " << conf_file << std::endl;
Modified: tools/knxdmxd/src/trigger.cc
===================================================================
--- tools/knxdmxd/src/trigger.cc 2012-10-28 08:54:08 UTC (rev 1078)
+++ tools/knxdmxd/src/trigger.cc 2012-10-28 16:06:00 UTC (rev 1079)
@@ -46,7 +46,7 @@
{
_triggers.push_back(trigger);
_handlers.push_back(handler);
- std::clog << "Added Trigger " << trigger << " for handler " << (*handler)
+ std::clog << kLogDebug << "Added Trigger " << trigger << " for handler " << (*handler)
<< std::endl;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <j-...@us...> - 2012-11-14 17:54:28
|
Revision: 1142
http://openautomation.svn.sourceforge.net/openautomation/?rev=1142&view=rev
Author: j-n-k
Date: 2012-11-14 17:54:16 +0000 (Wed, 14 Nov 2012)
Log Message:
-----------
Fixed some bugs, added patch function
Modified Paths:
--------------
tools/knxdmxd/knxdmxd
tools/knxdmxd/knxdmxd.conf
tools/knxdmxd/src/cue.cc
tools/knxdmxd/src/cue.h
tools/knxdmxd/src/dmxsender.cc
tools/knxdmxd/src/dmxsender.h
tools/knxdmxd/src/knxdmxd.cc
tools/knxdmxd/src/knxdmxd.h
tools/knxdmxd/src/trigger.cc
Modified: tools/knxdmxd/knxdmxd
===================================================================
(Binary files differ)
Modified: tools/knxdmxd/knxdmxd.conf
===================================================================
--- tools/knxdmxd/knxdmxd.conf 2012-11-14 14:32:26 UTC (rev 1141)
+++ tools/knxdmxd/knxdmxd.conf 2012-11-14 17:54:16 UTC (rev 1142)
@@ -1,35 +1,73 @@
// CAUTION : never uses names starting with _ !!! These are used internally !
{
"channels" : [
- { "name" : "treppe_01", "dmx" : "1.1" },
- { "name" : "treppe_02", "dmx" : "1.2" },
- { "name" : "treppe_03", "dmx" : "1.3" },
- { "name" : "treppe_04", "dmx" : "1.4" },
- { "name" : "treppe_05", "dmx" : "1.5" },
- { "name" : "treppe_06", "dmx" : "1.6" },
- { "name" : "treppe_07", "dmx" : "1.7" },
- { "name" : "treppe_08", "dmx" : "1.8" },
- { "name" : "treppe_09", "dmx" : "1.16" },
- { "name" : "treppe_10", "dmx" : "1.17" },
- { "name" : "treppe_11", "dmx" : "1.18" },
- { "name" : "treppe_12", "dmx" : "1.19" },
- { "name" : "treppe_13", "dmx" : "1.20" },
- { "name" : "kueche_r", "dmx" : "1.40", "statusga" : "12/1/20"},
- { "name" : "kueche_g", "dmx" : "1.41", "statusga" : "12/1/21"},
- { "name" : "kueche_b", "dmx" : "1.42", "statusga" : "12/1/22"}
+ { "name" : "treppe_01", "dmx" : "1.5", "statusga" : "0/3/1" },
+ { "name" : "treppe_02", "dmx" : "1.6", "statusga" : "0/3/2" },
+ { "name" : "treppe_03", "dmx" : "1.7", "statusga" : "0/3/3" },
+ { "name" : "treppe_04", "dmx" : "1.8", "statusga" : "0/3/4" },
+ { "name" : "treppe_05", "dmx" : "1.9", "statusga" : "0/3/5" },
+ { "name" : "treppe_06", "dmx" : "1.14", "statusga" : "0/3/6" },
+ { "name" : "treppe_07", "dmx" : "1.15", "statusga" : "0/3/7" },
+ { "name" : "treppe_08", "dmx" : "1.16", "statusga" : "0/3/8" },
+ { "name" : "treppe_09", "dmx" : "1.17", "statusga" : "0/3/9" },
+ { "name" : "treppe_10", "dmx" : "1.18", "statusga" : "0/3/10" },
+ { "name" : "treppe_11", "dmx" : "1.19", "statusga" : "0/3/11" },
+ { "name" : "treppe_12", "dmx" : "1.20", "statusga" : "0/3/12" },
+ { "name" : "treppe_13", "dmx" : "1.21", "statusga" : "0/3/13" },
+ { "name" : "kueche_r", "dmx" : "1.41", "statusga" : "0/3/20"},
+ { "name" : "kueche_g", "dmx" : "1.42", "statusga" : "0/3/21"},
+ { "name" : "kueche_b", "dmx" : "1.43", "statusga" : "0/3/22"}
],
"dimmers": [ // all dimmer definitions, name is optional (default is _d_<number>), knx-like dimming: fading is calculated for 0-100%
- { "name" : "Treppe01", "channel" : "treppe_01", "ga" : "12/0/1", "fading" : 1, "fadingga" : "1/6/170" },
- { "name" : "Treppe02", "channel" : "treppe_02", "ga" : "12/0/2", "fading" : 1, "fadingga" : "1/6/170" },
- { "name" : "Treppe03", "channel" : "treppe_03", "ga" : "12/0/3", "fading" : 1, "fadingga" : "1/6/170" },
- { "name" : "KuecheR", "channel" : "kueche_r", "ga" : "12/0/20" },
- { "name" : "KuecheG", "channel" : "kueche_g", "ga" : "12/0/21" },
- { "name" : "KuecheB", "channel" : "kueche_b", "ga" : "12/0/22" }
+ { "name" : "Treppe01", "channel" : "treppe_01", "ga" : "0/2/1", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe02", "channel" : "treppe_02", "ga" : "0/2/2", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe03", "channel" : "treppe_03", "ga" : "0/2/3", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe04", "channel" : "treppe_04", "ga" : "0/2/4", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe05", "channel" : "treppe_05", "ga" : "0/2/5", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe06", "channel" : "treppe_06", "ga" : "0/2/6", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe07", "channel" : "treppe_07", "ga" : "0/2/7", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe08", "channel" : "treppe_08", "ga" : "0/2/8", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe09", "channel" : "treppe_09", "ga" : "0/2/9", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe10", "channel" : "treppe_10", "ga" : "0/2/10", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe11", "channel" : "treppe_11", "ga" : "0/2/11", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe12", "channel" : "treppe_12", "ga" : "0/2/12", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "Treppe13", "channel" : "treppe_13", "ga" : "0/2/13", "fading" : 1, "fadingga" : "1/6/170" },
+ { "name" : "KuecheR", "channel" : "kueche_r", "ga" : "0/2/20" },
+ { "name" : "KuecheG", "channel" : "kueche_g", "ga" : "0/2/21" },
+ { "name" : "KuecheB", "channel" : "kueche_b", "ga" : "0/2/22" }
],
-"scenes": [ // all scene definitions
+"scenes": [ // all scene definitions
+ { "name" : "Kueche_Nacht_an",
+ "trigger" : {
+ "go" : {"knx" : "6/3/140", "value" : 1 }
+ },
+ "data" : [
+ { "channel" : "kueche_r", "value" : 180 },
+ { "channel" : "kueche_g", "value" : 180 },
+ { "channel" : "kueche_b", "value" : 180 }
+ ],
+ "fading" : { // all fading times used on scene call !
+ "in" : 1.0, // for increasing intensity
+ "out": 1.0, // for decreasing intensity
+ }
+ },
+ { "name" : "Kueche_Nacht_aus",
+ "trigger" : {
+ "go" : {"knx" : "6/3/140", "value" : 0 }
+ },
+ "data" : [
+ { "channel" : "kueche_r", "value" : 0 },
+ { "channel" : "kueche_g", "value" : 0 },
+ { "channel" : "kueche_b", "value" : 0 }
+ ],
+ "fading" : { // all fading times used on scene call !
+ "in" : 1.0, // for increasing intensity
+ "out": 1.0, // for decreasing intensity
+ }
+ },
{ "name" : "Treppe_Full_On", // name is optional, default is _s_<number>
"trigger" : {
- "go" : { "knx" : "1/0/170", "value" : 1 }, // if value is omitted, scene is called on any value
+ "go" : { "knx" : "1/0/171", "value" : 1 }, // if value is omitted, scene is called on any value
},
"data" : [ // definition of each channel in scene
{ "channel" : "treppe_01", "value" : 255 },
@@ -53,7 +91,7 @@
},
{ "name" : "Treppe_Blackout",
"trigger" : {
- "go" : { "knx" : "1/0/170", "value" : 0 },
+ "go" : { "knx" : "1/0/171", "value" : 0 },
},
"data" : [
{ "channel" : "treppe_01", "value" : 0 },
@@ -89,54 +127,298 @@
}
],
"cuelists": [ // all cuelists
- { "name" : "Treppe Disco",
- "priority" : 100,
- "release_on_halt" : true,
+ { "name" : "Treppe An",
+ "release_on_halt" : false, // release only when explicitely requested (default)
+ "proceed_on_go" : false, // proceed to next steo on go trigger (default)
"trigger" : {
- "go" : { "knx" : "1/0/172", "value" : 1 },
- "halt" : { "knx" : "1/0/172", "value" : 0 },
- "direct" : { "knx" : "1/0/173" }, // direct call of a cue (first is 0)
+ "go" : { "knx" : "1/0/170", "value" : 1 },
+ "halt" : { "knx" : "1/0/173", "value" : 1 },
+ "release" : { "knx" : "1/0/170", "value" : 0 },
+ "direct" : { "knx" : "1/0/174" }, // direct call of a cue (first is 0)
},
"cues" : [ // cues are like scenes, just without individual triggers
{ "name" : "start",
"data" : [
- { "channel" : "treppe_01", "value" : 0 },
+ { "channel" : "treppe_01", "value" : 255 },
{ "channel" : "treppe_02", "value" : 0 },
- { "channel" : "treppe_03", "value" : 0 }
+ { "channel" : "treppe_03", "value" : 0 },
+ { "channel" : "treppe_04", "value" : 0 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 0 },
+ { "channel" : "treppe_11", "value" : 0 },
+ { "channel" : "treppe_12", "value" : 0 },
+ { "channel" : "treppe_13", "value" : 255 },
],
- "waittime" : 3.1, // only relevant for loops
- "delay" : 5,
- "fading" : { "time" : 3 }
+ "waittime" : 0, // only relevant for loops
+ "delay" : 0,
+ "fading" : { "time" : 0.5 }
},
{ "name" : "c1",
"data" : [
{ "channel" : "treppe_01", "value" : 255 },
- { "channel" : "treppe_02", "value" : 0 },
- { "channel" : "treppe_03", "value" : 0 }
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 0 },
+ { "channel" : "treppe_04", "value" : 0 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 0 },
+ { "channel" : "treppe_11", "value" : 0 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
],
- "waittime" : 8.1,
- "fading" : { "time" : 3 }
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
},
{ "name" : "c2",
"data" : [
- { "channel" : "treppe_01", "value" : 0 },
+ { "channel" : "treppe_01", "value" : 255 },
{ "channel" : "treppe_02", "value" : 255 },
- { "channel" : "treppe_03", "value" : 0 }
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 0 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 0 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
],
- "waittime" : 3.1, // waittime start after calling previous cue !
- "fading" : { "time" : 3 }
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
},
{ "name" : "c3",
"data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 255 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 255 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
+ },
+ { "name" : "c4",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 255},
+ { "channel" : "treppe_05", "value" : 255 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 255 },
+ { "channel" : "treppe_10", "value" : 255 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5}
+ },
+ { "name" : "c5",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 255 },
+ { "channel" : "treppe_05", "value" : 255 },
+ { "channel" : "treppe_06", "value" : 255 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 255 },
+ { "channel" : "treppe_09", "value" : 255 },
+ { "channel" : "treppe_10", "value" : 255 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
+ },
+ { "name" : "c6",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 255 },
+ { "channel" : "treppe_05", "value" : 255 },
+ { "channel" : "treppe_06", "value" : 255 },
+ { "channel" : "treppe_07", "value" : 255 },
+ { "channel" : "treppe_08", "value" : 255 },
+ { "channel" : "treppe_09", "value" : 255 },
+ { "channel" : "treppe_10", "value" : 255 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
+ }
+
+ ]
+ },
+ { "name" : "Treppe Aus",
+ "release_on_halt" : false,
+ "proceed_on_go" : false,
+ "trigger" : {
+ "go" : { "knx" : "1/0/170", "value" : 0 },
+ "halt" : { "knx" : "1/0/173", "value" : 0 },
+ "direct" : { "knx" : "1/0/175" }, // direct call of a cue (first is 0)
+ "release" : { "knx" : "1/0/170", "value" : 1 }
+ },
+ "cues" : [ // cues are like scenes, just without individual triggers
+ { "name" : "start",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 255 },
+ { "channel" : "treppe_05", "value" : 255 },
+ { "channel" : "treppe_06", "value" : 255 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 255 },
+ { "channel" : "treppe_09", "value" : 255 },
+ { "channel" : "treppe_10", "value" : 255 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0, // only relevant for loops
+ "delay" : 0,
+ "fading" : { "time" : 0.5 }
+ },
+ { "name" : "c1",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 255 },
+ { "channel" : "treppe_05", "value" : 255 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 255 },
+ { "channel" : "treppe_10", "value" : 255 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
+ },
+ { "name" : "c2",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 255 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 255 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
+ },
+ { "name" : "c3",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 255 },
+ { "channel" : "treppe_04", "value" : 0 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 0 },
+ { "channel" : "treppe_11", "value" : 255 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
+ },
+ { "name" : "c4",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 255 },
+ { "channel" : "treppe_03", "value" : 0 },
+ { "channel" : "treppe_04", "value" : 0 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 0 },
+ { "channel" : "treppe_11", "value" : 0 },
+ { "channel" : "treppe_12", "value" : 255 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5}
+ },
+ { "name" : "c5",
+ "data" : [
+ { "channel" : "treppe_01", "value" : 255 },
+ { "channel" : "treppe_02", "value" : 0 },
+ { "channel" : "treppe_03", "value" : 0 },
+ { "channel" : "treppe_04", "value" : 0 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 0 },
+ { "channel" : "treppe_11", "value" : 0 },
+ { "channel" : "treppe_12", "value" : 0 },
+ { "channel" : "treppe_13", "value" : 255 },
+ ],
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
+ },
+ { "name" : "c6",
+ "data" : [
{ "channel" : "treppe_01", "value" : 0 },
{ "channel" : "treppe_02", "value" : 0 },
- { "channel" : "treppe_03", "value" : 255 }
+ { "channel" : "treppe_03", "value" : 0 },
+ { "channel" : "treppe_04", "value" : 0 },
+ { "channel" : "treppe_05", "value" : 0 },
+ { "channel" : "treppe_06", "value" : 0 },
+ { "channel" : "treppe_07", "value" : 0 },
+ { "channel" : "treppe_08", "value" : 0 },
+ { "channel" : "treppe_09", "value" : 0 },
+ { "channel" : "treppe_10", "value" : 0 },
+ { "channel" : "treppe_11", "value" : 0 },
+ { "channel" : "treppe_12", "value" : 0 },
+ { "channel" : "treppe_13", "value" : 0 },
],
- "waittime" : 3.1, // waittime start after calling previous cue !
- "fading" : { "time" : 3 }
- },
- { "link" : "start"
+ "waittime" : 0.52,
+ "fading" : { "time" : 0.5 }
}
+
]
},
{ "name" : "KuecheFarbwechsler",
Modified: tools/knxdmxd/src/cue.cc
===================================================================
--- tools/knxdmxd/src/cue.cc 2012-11-14 14:32:26 UTC (rev 1141)
+++ tools/knxdmxd/src/cue.cc 2012-11-14 17:54:16 UTC (rev 1142)
@@ -80,6 +80,7 @@
was_direct_ = false;
cue_halted_ = true;
release_on_halt_ = true;
+ proceed_on_go_ = true;
max_cue_ = 0;
@@ -106,6 +107,30 @@
}
void
+ Cuelist::Go()
+ {
+ std::clog << kLogDebug << "Cue " << _name << ": go ";
+ if ((cue_halted_) && ((current_cue_+1) < max_cue_))
+ {
+ std::clog << "was halted before" << std::endl;
+ cue_halted_ = false;
+ NextCue(-1);
+ }
+ else
+ {
+ if (proceed_on_go_)
+ {
+ std::clog << "was running, next step" << std::endl;
+ NextCue(-2);
+ }
+ else
+ {
+ std::clog << "ignored" << std::endl;
+ }
+ }
+
+ }
+ void
Cuelist::NextCue(const int direct)
{
if (was_direct_)
@@ -167,10 +192,12 @@
(int) (waittime * 1000.),
ola::NewSingleCallback(this, &Cuelist::NextCue, -1));
}
- } else {
- // last cue halts automatically
- Halt();
}
+ else
+ {
+ // last cue halts automatically
+ Halt();
+ }
}
catch (char *str)
{
Modified: tools/knxdmxd/src/cue.h
===================================================================
--- tools/knxdmxd/src/cue.h 2012-11-14 14:32:26 UTC (rev 1141)
+++ tools/knxdmxd/src/cue.h 2012-11-14 17:54:16 UTC (rev 1142)
@@ -99,7 +99,7 @@
{
int current_cue_, max_cue_;
bool cue_halted_, was_direct_;
- bool release_on_halt_;
+ bool release_on_halt_, proceed_on_go_;
// fixture_lock_t lock_;
std::vector<knxdmxd::Cue> cue_data_;
std::map<std::string, int> cue_names_;
@@ -115,25 +115,30 @@
Cuelist(const std::string name);
void
- AddCue(knxdmxd::Cue& cue);
+ SetReleaseOnHalt(const bool release_on_halt)
+ {
+ release_on_halt_ = release_on_halt;
+ std::clog << kLogDebug << "Cue " << _name << ": set release_on_halt to "
+ << release_on_halt << std::endl;
+ }
void
- Go()
+ SetProceedOnGo(const bool proceed_on_go)
{
- if (cue_halted_)
- {
- cue_halted_ = false;
- NextCue(-1);
- }
- else
- {
- NextCue(-2);
- }
+ proceed_on_go_ = proceed_on_go;
+ std::clog << kLogDebug << "Cue " << _name << ": set proceed_on_go to "
+ << proceed_on_go << std::endl;
+ }
- }
- ;
void
+ AddCue(knxdmxd::Cue& cue);
+
+ void
+ Go();
+
+ void
Halt()
{
+ std::clog << kLogDebug << "Cue " << _name << ": halt " << std::endl;
cue_halted_ = true;
if (release_on_halt_)
{
@@ -150,7 +155,7 @@
void
Release()
{
- cue_halted_ = true;
+ std::clog << kLogDebug << "Cue " << _name << ": release " << std::endl;
current_cue_ = -1;
}
;
Modified: tools/knxdmxd/src/dmxsender.cc
===================================================================
--- tools/knxdmxd/src/dmxsender.cc 2012-11-14 14:32:26 UTC (rev 1141)
+++ tools/knxdmxd/src/dmxsender.cc 2012-11-14 17:54:16 UTC (rev 1142)
@@ -17,12 +17,15 @@
int universe, channel;
std::string c(addr);
sscanf((char*) c.c_str(), "%d.%d", &universe, &channel);
- return (channel == -1) ? (universe + 512) : ((((unsigned) universe) << 9) + channel);
+ return
+ (channel == -1) ?
+ (universe + 512) : ((((unsigned) universe) << 9) + channel);
}
// initalize static variables of DMX class
ola::OlaCallbackClientWrapper DMX::m_client;
std::map<char, knxdmxd::pUniverse> DMX::output;
+ std::list<patch_table_t> DMX::patchTable;
bool
DMXSender::Init()
@@ -33,6 +36,22 @@
<< std::endl;
return false;
}
+ if (patchTable.size())
+ {
+ for (std::list<patch_table_t>::const_iterator iterator =
+ patchTable.begin(), end = patchTable.end(); iterator != end;
+ ++iterator)
+ {
+ patch_table_t pEntry = *iterator;
+
+ m_client.GetClient()->Patch(pEntry.device, pEntry.port,
+ ola::OUTPUT_PORT, ola::PATCH, pEntry.universe,
+ ola::NewSingleCallback(this, &DMXSender::PatchComplete));
+
+ }
+
+ }
+
return true;
}
@@ -64,13 +83,15 @@
if (currenttime > fadeend_[i])
{
current_[i] = old_[i] = new_[i];
- std::clog << kLogDebug << "DMXSender: Finished crossfading universe "
+ std::clog << kLogDebug
+ << "DMXSender: Finished crossfading universe "
<< (int) universe_ << " channel " << i << " to "
<< (int) current_[i] << std::endl;
- dmx_addr_t dmx = (universe_ << 9) + i; // calculate dmx-addr
+ dmx_addr_t dmx = (universe_ << 9) + i + 1; // calculate dmx-addr
if (knxdmxd::statusmap.count(dmx))
{
- std::clog << kLogDebug << "DMXSender: writing status update to KNX "
+ std::clog << kLogDebug
+ << "DMXSender: writing status update to KNX "
<< std::endl;
knxdmxd::eib_message_t message;
message.value = (long) new_[i];
Modified: tools/knxdmxd/src/dmxsender.h
===================================================================
--- tools/knxdmxd/src/dmxsender.h 2012-11-14 14:32:26 UTC (rev 1141)
+++ tools/knxdmxd/src/dmxsender.h 2012-11-14 17:54:16 UTC (rev 1142)
@@ -16,10 +16,18 @@
#include <ola/OlaClientWrapper.h>
#include <trigger.h>
#include <map>
+#include <list>
namespace knxdmxd
{
+ typedef struct
+ {
+ unsigned int device;
+ unsigned int port;
+ unsigned int universe;
+ } patch_table_t;
+
class Universe
{
protected:
@@ -29,7 +37,7 @@
ola::thread::Mutex data_mutex;
char universe_;
public:
- Universe(char universe )
+ Universe(char universe)
{
universe_ = universe; // universe should now it's own number
ola::thread::MutexLocker locker(&data_mutex);
@@ -50,13 +58,12 @@
old_[ch] = current_[ch];
float fadeTime = (new_[ch] > current_[ch]) ? fade_in : fade_out;
fadestart_[ch] = Timer::Get();
- fadeend_[ch] = fadestart_[ch]
- + (unsigned long) (fadeTime * 1000.0);
+ fadeend_[ch] = fadestart_[ch] + (unsigned long) (fadeTime * 1000.0);
}
unsigned char
Get(const unsigned channel)
{
- return current_[channel-1];
+ return current_[channel - 1];
}
ola::DmxBuffer &
GetBuffer()
@@ -76,12 +83,12 @@
protected:
static std::map<char, pUniverse> output;
static ola::OlaCallbackClientWrapper m_client;
-
+ static std::list<patch_table_t> patchTable;
public:
DMX()
{
}
- ;
+
static void
SetDMXChannel(const dmx_addr_t channel, const unsigned char value,
const float fade_in = 1.e-4, const float fade_out = 1.e-4)
@@ -89,23 +96,36 @@
int dmxuniverse = (int) (channel / 512), dmxchannel = channel % 512;
output[dmxuniverse]->Set(dmxchannel, value, fade_in, fade_out);
}
- ;
+
char
GetDMXChannel(int channel);
static dmx_addr_t
Address(const std::string &addr);
+
static ola::OlaCallbackClientWrapper&
GetOLAClient()
{
return m_client;
}
- ;
+ static void
+ Patch(unsigned int device, unsigned int port, unsigned int universe)
+ {
+ patch_table_t p;
+ p.device = device;
+ p.port = port;
+ p.universe = universe;
+ patchTable.push_back(p);
+ std::clog << kLogDebug << "Added d " << device << " / p " << port
+ << " / u " << universe << " to patch Table " << std::endl;
+ }
+
};
class DMXSender : private DMX
{
+ private:
bool sender_running_;
public:
@@ -130,71 +150,79 @@
{
return sender_running_;
}
- ;
void
+ PatchComplete(const std::string &error)
+ {
+ std::clog << kLogDebug << "DMX: patch completed : " << error << std::endl;
+ (void) error;
+ }
+
+ void
AddUniverse(char universe)
{
if (!output.count(universe))
{ // only create if not already existing;
pUniverse new_universe = new Universe(universe);
output.insert(std::pair<char, pUniverse>(universe, new_universe));
- std::clog << kLogInfo << "DMXSender created universe " << (int) universe
- << std::endl;
+ std::clog << kLogInfo << "DMXSender created universe "
+ << (int) universe << std::endl;
}
+
}
;
};
class Dimmer : public TriggerHandler
+ {
+ std::string name_;
+ dmx_addr_t dmx_;
+ float fade_time_;
+ eibaddr_t ga_, ga_fading_;
+ public:
+ Dimmer()
{
- std::string name_;
- dmx_addr_t dmx_;
- float fade_t...
[truncated message content] |
|
From: <j-...@us...> - 2013-07-05 16:59:48
|
Revision: 1800
http://sourceforge.net/p/openautomation/code/1800
Author: j-n-k
Date: 2013-07-05 16:59:45 +0000 (Fri, 05 Jul 2013)
Log Message:
-----------
Test binary for new knxdmxd
Added Paths:
-----------
tools/knxdmxd/testing/
tools/knxdmxd/testing/knxdmxd
Added: tools/knxdmxd/testing/knxdmxd
===================================================================
(Binary files differ)
Index: tools/knxdmxd/testing/knxdmxd
===================================================================
--- tools/knxdmxd/testing/knxdmxd 2013-07-04 08:50:36 UTC (rev 1799)
+++ tools/knxdmxd/testing/knxdmxd 2013-07-05 16:59:45 UTC (rev 1800)
Property changes on: tools/knxdmxd/testing/knxdmxd
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|