summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Eefting <edwin@datux.nl>2011-08-12 21:33:42 (GMT)
committer Edwin Eefting <edwin@datux.nl>2011-08-12 21:33:42 (GMT)
commitd307f57ea6e8311c8e143bd3342dac55b022cffd (patch)
tree9539fd5f65a80c84df69bc97b7024ec00c023fba
parentc2039283f334685448636230c22382489038c5aa (diff)
base
-rw-r--r--modules/dmx.module/CMakeLists.txt28
-rw-r--r--modules/dmx.module/module.cpp185
-rw-r--r--wwwdir/dmx.html68
3 files changed, 281 insertions, 0 deletions
diff --git a/modules/dmx.module/CMakeLists.txt b/modules/dmx.module/CMakeLists.txt
new file mode 100644
index 0000000..b8e68d9
--- /dev/null
+++ b/modules/dmx.module/CMakeLists.txt
@@ -0,0 +1,28 @@
+#this is just a basic CMakeLists.txt, for more information see the cmake manpage
+
+cmake_minimum_required(VERSION 2.6)
+
+#add definitions, compiler switches, etc.
+ADD_DEFINITIONS()
+
+#Determine name of the .so module:
+#A module should always be in a modulename.module directory!.
+string(REGEX REPLACE ".*/([^/]*).module$" "\\1" module_name "${CMAKE_CURRENT_BINARY_DIR}")
+MESSAGE(STATUS "Module name of ${CMAKE_CURRENT_BINARY_DIR} is: '${module_name}'")
+
+#automaticly add all sourcefiles to current module
+file(GLOB sources *.cpp)
+ADD_LIBRARY(${module_name} MODULE ${sources} ../../libs/cnet.cpp)
+
+#need to link to some other libraries ? just add them here
+TARGET_LINK_LIBRARIES(${module_name})
+
+INCLUDE_DIRECTORIES(../..)
+
+#add an install target here
+#INSTALL_FILES(...)
+#INSTALL_PROGRAMS(...)
+#INSTALL_TARGET(...)
+
+
+
diff --git a/modules/dmx.module/module.cpp b/modules/dmx.module/module.cpp
new file mode 100644
index 0000000..056b26d
--- /dev/null
+++ b/modules/dmx.module/module.cpp
@@ -0,0 +1,185 @@
+/* Copyright 2008,2009,2010 Edwin Eefting (edwin@datux.nl)
+
+ This file is part of Synapse.
+
+ Synapse 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.
+
+ Synapse 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 Synapse. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#include "cnetman.h"
+#include "synapse.h"
+#include <boost/regex.hpp>
+#include <sstream>
+#include <iomanip>
+
+using namespace boost;
+using namespace std;
+
+SYNAPSE_REGISTER(module_Init)
+{
+ Cmsg out;
+
+ out.clear();
+ out.event="core_ChangeModule";
+ out["maxThreads"]=10;
+ out.send();
+
+ out.clear();
+ out.event="core_ChangeSession";
+ out["maxThreads"]=10;
+ out.send();
+
+ out.clear();
+ out.event="core_LoadModule";
+ out["name"]="http_json";
+ out.send();
+
+ //anyone can set
+ out.clear();
+ out.event="core_ChangeEvent";
+ out["event"]= "dmx_Set";
+ out["modifyGroup"]= "modules";
+ out["sendGroup"]= "anonymous";
+ out["recvGroup"]= "anonymous";
+ out.send();
+
+ //just connect something
+ out.clear();
+ out.event="dmx_Connect";
+ out["id"]=1;
+ out["host"]="localhost";
+ out["port"]=7777;
+ out.send();
+
+
+ ///tell the rest of the world we are ready for duty
+ out.clear();
+ out.event="core_Ready";
+ out.send();
+
+
+}
+
+class CnetDmx : public synapse::Cnet
+{
+
+ void connected(int id, const string &host, int port)
+ {
+ Cmsg out;
+ out.dst=id;
+ out.event="dmx_Connected";
+ out.send();
+ }
+
+ void received(int id, asio::streambuf &readBuffer, std::size_t bytesTransferred)
+ {
+ //convert streambuf to string
+ string dataStr(boost::asio::buffer_cast<const char*>(readBuffer.data()), readBuffer.size());
+ dataStr.resize(dataStr.find(delimiter)+delimiter.length());
+
+
+ /* Example lirc output:
+ 0000000000001010 00 sys_00_command_10 PHILIPS_RC-5
+ 0000000000001010 01 sys_00_command_10 PHILIPS_RC-5
+ 0000000000001010 02 sys_00_command_10 PHILIPS_RC-5
+ 0000000000001010 03 sys_00_command_10 PHILIPS_RC-5
+ 0000000000001011 00 sys_00_command_11 PHILIPS_RC-5
+ 0000000000001011 01 sys_00_command_11 PHILIPS_RC-5
+ 0000000000001011 02 sys_00_command_11 PHILIPS_RC-5
+ */
+ //parse lirc output
+ smatch what;
+ if (regex_match(
+ dataStr,
+ what,
+ boost::regex("(.*?) (.*?) (.*?) (.*?)\n")
+ ))
+ {
+ //send to destination -1: this is the user configurable event mapper
+ //TODO: different events for long-presses and double presses?
+ Cmsg out;
+ out.dst=-1;
+ out.event="dmx_"+what[4]+"."+what[3];
+ out["code"] =what[1];
+ out["repeat"] =what[2];
+ out.send();
+ }
+ else
+ {
+ ERROR("Cant parse dmx output: " << dataStr);
+ }
+
+ readBuffer.consume(dataStr.length());
+
+ }
+
+ void disconnected(int id, const boost::system::error_code& ec)
+ {
+ Cmsg out;
+ out.dst=id;
+ out.event="dmx_Disconnected";
+ out["reason"]=ec.message();
+ out.send();
+ }
+
+
+};
+
+synapse::CnetMan<CnetDmx> net;
+
+SYNAPSE_REGISTER(dmx_Connect)
+{
+ net.runConnect(msg["id"], msg["host"], msg["port"], 5);
+
+}
+
+/** Set specified dmx channel to a value
+ *
+ */
+SYNAPSE_REGISTER(dmx_Set)
+{
+ stringstream dmxStr;
+ //*C9<layer><channel><value>#
+ dmxStr << "*C9fe";
+ dmxStr << setfill('0');
+ dmxStr << hex << setw(2) << (int)msg["channel"];
+ dmxStr << hex << setw(2) << (int)msg["value"];
+ dmxStr << "#";
+ string s=dmxStr.str();
+ net.doWrite(msg["id"], s);
+}
+
+
+SYNAPSE_REGISTER(dmx_Disconnect)
+{
+ net.doDisconnect(msg["id"]);
+}
+
+/** When a session ends, make sure the corresponding network connection is disconnected as well.
+ *
+ */
+SYNAPSE_REGISTER(module_SessionEnded)
+{
+ net.doDisconnect(msg["id"]);
+}
+
+/** Called when synapse whats the module to shutdown completely
+ * This makes sure that all ports and network connections are closed, so there wont be any 'hanging' threads left.
+ * If you care about data-ordering, send this to session-id that sended you the net_Connected.
+ */
+SYNAPSE_REGISTER(module_Shutdown)
+{
+ INFO("dmx shutting down...");
+ //let the net module shut down to fix the rest
+ net.doShutdown();
+}
diff --git a/wwwdir/dmx.html b/wwwdir/dmx.html
new file mode 100644
index 0000000..6448f04
--- /dev/null
+++ b/wwwdir/dmx.html
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+
+<html>
+
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+ <title>playlist test</title>
+
+ <script type="text/javascript" src="/synapse/synapse.js"></script>
+
+ <script type="text/javascript">
+
+ /// SYNAPSE EVENT HANDLERS
+
+
+ synapse_register("error",function(errortxt)
+ {
+ $('#error').html(errortxt);
+ });
+
+
+ synapse_register("module_SessionStart",function(msg_src, msg_dst, msg_event, msg)
+ {
+ });
+
+
+ /// JAVA SCRIPT EVENT HANDLERS
+ $(document).ready(function(){
+
+ $(".send").click(function()
+ {
+ var msg=JSON.parse($(this).parent().children(".message").val());
+ send(msg[0],msg[1],msg[2]);
+
+ });
+
+ $(".slider").slider({
+ orientation: 'vertical',
+ min:0,
+ max:255,
+ slide: function(event, ui) {
+ ui.value
+ send(0,"dmx_Set",{
+ id:1,
+ channel:5,
+ value:ui.value
+ });
+
+ }
+
+ });
+ });
+
+
+ </script>
+
+ <style>
+
+
+ </style>
+</head>
+
+
+<body>
+<div class='slider'></div>
+</body>
+</html>
+