|
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; };
+ void Update(const std::string& channel, const int val, const float fadeStep);
+ void Process(const Trigger& trigger);
+ void Refresh();
+
+ int GetCurrentValue(const std::string& channel);
+ std::string& GetName() { return name_; };
+
+ void Lock(const std::string& cuelist, int lockpriority);
+ int isLocked();
+ void Release();
- 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(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;
- 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;
-};
+ 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 Process(const Trigger& trigger);
+ void Refresh();
+
+ pFixture Get(const std::string& name) { return fixture_list_[name]; };
+ };
}
Modified: tools/knxdmxd/src/knxdmxd.cc
===================================================================
--- tools/knxdmxd/src/knxdmxd.cc 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/knxdmxd.cc 2012-05-28 18:11:33 UTC (rev 846)
@@ -28,12 +28,12 @@
#include <signal.h>
#include <getopt.h>
#include <json/json.h>
+#include <thread>
#include <ola/Logging.h>
#include <ola/StreamingClient.h>
#include <ola/StringUtils.h>
-#include <pthread.h>
#include <eibclient.h>
#include <iostream>
@@ -45,8 +45,8 @@
#include <fixture.h>
#include <cue.h>
-#include <cuelist.h>
#include <dmxsender.h>
+#include <trigger.h>
#define DEBUG 1
#define DAEMON_NAME "knxdmxd"
@@ -55,8 +55,7 @@
"\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 NUM_THREADS 4
#define RETRY_TIME 5
#define BUFLEN 1024
#define POLLING_INTERVAL 10
@@ -95,27 +94,17 @@
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";
-unsigned long long loopCounter = 0;
+std::string pidfilename = "/var/run/knxdmxd.pid";
-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;
+std::map<int, ola::DmxBuffer> knxdmxd::DMX::output;
-knxdmxd::knx_patch_map_t KNX_fixture_patchMap;
-knxdmxd::knx_patch_map_t KNX_scene_patchMap;
-knxdmxd::knx_patch_map_t KNX_cuelist_patchMap;
-
+knxdmxd::TriggerList triggerList;
knxdmxd::DMXSender sender;
+
void daemonShutdown() {
//FIXME: clean exit pthread_exit(NULL); pthread_cancel(..);
std::clog << kLogInfo << DAEMON_NAME << " daemon exiting" << std::endl;
@@ -145,124 +134,37 @@
}
}
-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);
- }
+void olahandler() { // thread for OLA connection
+ std::clog << kLogDebug << "OLA thread started" << std::endl;
- 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; // 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)
- {
- sceneList[it->second].Update(fixtureList, dest, val, loopCounter);
- unum++;
- }
- 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;
-}
-
-
-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
- if (!sender.Init(&dmxWriteBuffer)) {
- std::clog << kLogWarning << "OLA: Sender setup failed" << std::endl;
+ if (!sender.Init()) {
+ std::clog << kLogWarning << "OLA: Client setup failed" << std::endl;
sleep(RETRY_TIME);
continue;
}
sender.Start(); // Start the sender
- while (1) { // loop forever, should be used fopr monitoring the client
+ while (1) { // loop forever, should be used for monitoring the client
+ if (!sender.Running())
+ break;
usleep(20000);
}
}
- pthread_exit(NULL);
}
+void knxhandler() {
-void *knxhandler(void *) {
- std::clog << "KNX reader thread started" << std::endl;
+ std::clog << "KNX thread started" << std::endl;
int len;
EIBConnection *con;
eibaddr_t dest;
eibaddr_t src;
- unsigned char buf[255];
+ unsigned char buf[255], val;
while (1) //retry infinite
{
@@ -287,47 +189,59 @@
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)+KNX_cuelist_patchMap.count(dest))<=0 ) //not for us
- continue;
- handleKNXdgram(dest,buf,len);
+ 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];
+ std::clog << "Received " << (int)val << " @ " << dest << std::endl;
+ 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);
}
- pthread_exit(NULL);
+
}
knxdmxd::Trigger *json_get_trigger(struct json_object *trigger, const int type) {
- knxdmxd::Trigger *new_trigger = new knxdmxd::Trigger;
-
- (*new_trigger).type = type;
-
+
if (!trigger) {
- delete new_trigger;
- return new_trigger;
+ return NULL;
}
struct json_object *trigger_knx = json_object_object_get(trigger, "knx");
struct json_object *trigger_value = json_object_object_get(trigger, "value");
if (!trigger_knx) {
- delete new_trigger;
- return new_trigger;
+ return NULL;
}
- (*new_trigger).knx = readgaddr(json_object_get_string(trigger_knx));
- (*new_trigger).value = (trigger_value) ? json_object_get_int(trigger_value) : -1;
-
+ int knx = readgaddr(json_object_get_string(trigger_knx));
+ int val = (trigger_value) ? json_object_get_int(trigger_value) : -1;
+
+ knxdmxd::Trigger *new_trigger = new knxdmxd::Trigger(type, knx, val);
return new_trigger;
}
@@ -353,8 +267,7 @@
return new_cue;
}
- int channelnum = json_object_array_length(channels);
- for (int j=0; j<channelnum; 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);
@@ -368,7 +281,7 @@
}
knxdmxd::cue_channel_t channeldata;
- channeldata.fixture = json_object_get_string(fixt);
+ channeldata.fixture = sender.GetFixture(json_object_get_string(fixt));
channeldata.name = json_object_get_string(chan);
channeldata.value = json_object_get_int(value);
@@ -396,7 +309,7 @@
}
}
- // waittime;
+ // waittime
struct json_object *waittime = json_object_object_get(cue, "waittime");
if (waittime) {
@@ -410,23 +323,21 @@
delete new_cue;
return new_cue;
}
-
+
struct json_object *go = json_object_object_get(triggers, "go");
knxdmxd::Trigger *go_trigger = json_get_trigger(go, knxdmxd::kTriggerGo);
if (go_trigger) {
- new_cue->AddTrigger(KNX_scene_patchMap, (*go_trigger));
+ triggerList.Add(*go_trigger, new_cue);
}
-
- }
+ }
return new_cue;
-
}
void load_config() {
struct json_object *config;
-
+
config = json_object_from_file((char *)conf_file.c_str());
/*
@@ -444,7 +355,7 @@
// 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);
+ knxdmxd::Fixture* f = new knxdmxd::Fixture(fname);
// get channels & patch them
struct json_object *channels = json_object_object_get(fixture, "channels");
@@ -453,8 +364,7 @@
continue;
}
- int channelnum = json_object_array_length(channels);
- for (int j=0; j<channelnum; 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);
@@ -475,15 +385,15 @@
std::string cknx = (knx) ? json_object_get_string(knx) : "";
// patch
- f.Patch(KNX_fixture_patchMap, cname, cdmx, cknx);
+ f->AddChannel(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);
+ f->SetFadeTime(ftime);
- fixtureList[fname] = f;
+ sender.AddFixture(f);
}
/*
@@ -502,11 +412,6 @@
std::string sname = (name) ? json_object_get_string(name) : "_s_"+t_to_string(i);
knxdmxd::Cue *s = json_get_cue(scene, i, knxdmxd::kScene);
-
- if (s) {
- sceneList[s->GetName()] = *s;
- }
-
}
/*
@@ -523,45 +428,41 @@
// 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);
+ knxdmxd::Cuelist *c = new knxdmxd::Cuelist(cname);
+
+ // get cues
+ struct json_object *cues = json_object_object_get(cuelist, "cues");
+ for (int i=0; i<json_object_array_length(cues); i++) { // read all
+ struct json_object *cue = json_object_array_get_idx(cues, i);
+ c->AddCue(*json_get_cue(cue, i, knxdmxd::kCue));
+ }
// trigger is required
struct json_object *triggers = json_object_object_get(cuelist, "trigger");
if (!triggers) {
- std::clog << kLogInfo << "Skipping cue '" << name << "' (trigger required in cuelist definition)" << std::endl;
+ std::clog << kLogInfo << "Skipping cuelist '" << name << "' (trigger required in cuelist definition)" << std::endl;
continue;
}
- struct json_object *go = json_object_object_get(triggers, "go");
- knxdmxd::Trigger *go_trigger = json_get_trigger(go, knxdmxd::kTriggerGo);
+ knxdmxd::Trigger *go_trigger = json_get_trigger(json_object_object_get(triggers, "go"), knxdmxd::kTriggerGo);
if (go_trigger) {
- c.AddTrigger(KNX_cuelist_patchMap, (*go_trigger));
+ triggerList.Add(*go_trigger, c);
}
-
- struct json_object *halt = json_object_object_get(triggers, "halt");
- knxdmxd::Trigger *halt_trigger = json_get_trigger(halt, knxdmxd::kTriggerHalt);
+
+ knxdmxd::Trigger *halt_trigger = json_get_trigger(json_object_object_get(triggers, "halt"), knxdmxd::kTriggerHalt);
if (halt_trigger) {
- c.AddTrigger(KNX_cuelist_patchMap, (*halt_trigger));
+ triggerList.Add(*halt_trigger, c);
}
-
- 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);
- c.AddCue(*json_get_cue(cue, i, knxdmxd::kCue));
- }
-
- cuelistList[cname] = c;
}
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)
@@ -597,14 +498,12 @@
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));
+ setlogmask(LOG_UPTO(LOG_DEBUG));
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) {
@@ -646,14 +545,14 @@
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?
+ load_config();
+
+ std::thread knx(knxhandler);
+ std::thread ola(olahandler);
+
+ knx.join();
+ ola.join();
+
while (1) {
// std::clog << DAEMON_NAME << " daemon running" << std::endl;
sleep(POLLING_INTERVAL*1000);
Modified: tools/knxdmxd/src/knxdmxd.h
===================================================================
--- tools/knxdmxd/src/knxdmxd.h 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/knxdmxd.h 2012-05-28 18:11:33 UTC (rev 846)
@@ -11,7 +11,6 @@
#include <iostream>
#include <map>
-#include <vector>
#include <log.h>
#include <eibclient.h>
@@ -21,19 +20,11 @@
#define DMX_INTERVAL 25 // in ms
namespace knxdmxd {
-// typedef std::vector<std::string> svector_t;
- typedef std::pair<int, std::string> knx_patch_map_element_t;
- typedef std::multimap<int, std::string> knx_patch_map_t;
- typedef struct { int knx; int value; int type; } Trigger;
-
const int kFixture = 1;
const int kScene = 2;
const int kCue = 4;
const int kCuelist = 8;
- const int kTriggerGo = 1;
- const int kTriggerHalt = 2;
-
}
eibaddr_t readgaddr (const std::string addr);
Modified: tools/knxdmxd/src/log.cc
===================================================================
--- tools/knxdmxd/src/log.cc 2012-05-28 15:03:03 UTC (rev 845)
+++ tools/knxdmxd/src/log.cc 2012-05-28 18:11:33 UTC (rev 846)
@@ -24,7 +24,7 @@
int Log::sync() {
if (buffer_.length()) {
- syslog(priority_, buffer_.c_str());
+ syslog(priority_, "%s", (char *)buffer_.c_str());
buffer_.erase();
priority_ = LOG_DEBUG; // default to debug for each message
}
Added: tools/knxdmxd/src/trigger.cc
===================================================================
--- tools/knxdmxd/src/trigger.cc (rev 0)
+++ tools/knxdmxd/src/trigger.cc 2012-05-28 18:11:33 UTC (rev 846)
@@ -0,0 +1,70 @@
+/*
+ * trigger.cc
+ *
+ * (c) by JNK 2012
+ *
+ *
+*/
+
+#include "trigger.h"
+
+namespace knxdmxd {
+
+ Trigger::Trigger(const int type, int knx, const int val) {
+ _type= type;
+ _knx = knx;
+ _val = val;
+ }
+
+ bool Trigger::operator==(const Trigger &other) const {
+ return ((_knx == other._knx) // same knx
+ && ((_type == other._type) || (other._type == kTriggerAll) || (_type==kTriggerAll)) // same trigger type
+ && ((_val == other._val) || (other._val ==-1) || (_val==-1))); // same value
+ }
+
+ Trigger& Trigger::operator= (Trigger const& other) {
+ if (this != &other) {
+ _knx = other._knx;
+ _type = other._type;
+ _val = other._val;
+ }
+ return *this;
+ }
+
+ void TriggerList::Add(Trigger& trigger, pTriggerHandler handler) {
+ _triggers.push_back(trigger);
+ _handlers.push_back(handler);
+ std::clog << "Added Trigger " << trigger << " for handler " << (*handler) << std::endl;
+ }
+
+ void TriggerList::Process(const Trigger& trigger) {
+ for (unsigned i=0; i<_triggers.size(); i++) {
+ knxdmxd::Trigger tr = _triggers[i];
+ if (tr==trigger) {
+ switch (tr.GetType()) {
+ case knxdmxd::kTriggerGo:
+ _handlers[i]->Go();
+ break;
+ case knxdmxd::kTriggerHalt:
+ _handlers[i]->Halt();
+ break;
+ default: ;
+ }
+ }
+ }
+
+}
+
+std::ostream& operator<<(std::ostream& stream, const knxdmxd::Trigger& trigger)
+{
+ stream << trigger._type << "(" << trigger._val << "@" << trigger._knx <<")";
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const knxdmxd::TriggerHandler& handler)
+{
+ stream << handler._name;
+ return stream;
+}
+
+}
Added: tools/knxdmxd/src/trigger.h
===================================================================
--- tools/knxdmxd/src/trigger.h (rev 0)
+++ tools/knxdmxd/src/trigger.h 2012-05-28 18:11:33 UTC (rev 846)
@@ -0,0 +1,65 @@
+/*
+ * trigger.h
+ *
+ * (c) by JNK 2012
+ *
+ *
+*/
+
+#ifndef TRIGGER_H
+#define TRIGGER_H
+
+#include <knxdmxd.h>
+#include <vector>
+
+namespace knxdmxd {
+
+ const int kTriggerAll = 0;
+ const int kTriggerGo = 1;
+ const int kTriggerHalt = 2;
+ const int kTriggerDirect = 4;
+
+ class Trigger {
+ int _knx;
+ int _val;
+ int _type;
+
+ public:
+ Trigger(const int type, const int knx, const int val);
+
+ bool operator == (const Trigger &other) const;
+ Trigger& operator = (const Trigger &other);
+ const int GetKNX() const { return _knx; };
+ const int GetValue() const { return _val; };
+ const int GetType() const { return _type; };
+
+ friend std::ostream& operator<<(std::ostream &stream, const Trigger& t);
+ };
+
+ class TriggerHandler {
+ protected:
+ std::string _name;
+ public:
+ virtual void Go() {};
+ virtual void Halt() {};
+ virtual void Refresh() {};
+
+ friend std::ostream& operator<<(std::ostream &stream, const TriggerHandler& handler);
+ };
+
+ typedef TriggerHandler* pTriggerHandler;
+
+
+ class TriggerList {
+ std::vector<Trigger> _triggers;
+ std::vector<pTriggerHandler> _handlers;
+ public:
+ TriggerList() { };
+
+ void Add(Trigger& trigger, pTriggerHandler handler);
+ void Process(const Trigger& trigger);
+ };
+
+}
+
+#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|