[dss-commits] r8861 - in dss/trunk/examples/plugins: . ds485Client
dss-commits at forum.digitalstrom.org
dss-commits at forum.digitalstrom.org
Fri Oct 23 11:37:03 CEST 2009
Author: pstaehlin
Date: 2009-10-23 11:37:03 +0200 (Fri, 23 Oct 2009)
New Revision: 8861
Added:
dss/trunk/examples/plugins/ds485Client/
dss/trunk/examples/plugins/ds485Client/Makefile
dss/trunk/examples/plugins/ds485Client/Makefile.OSX
dss/trunk/examples/plugins/ds485Client/webserver_plugin_ds485client.cpp
Log:
Example showing the use of DS485Client
Added: dss/trunk/examples/plugins/ds485Client/Makefile
===================================================================
--- dss/trunk/examples/plugins/ds485Client/Makefile (rev 0)
+++ dss/trunk/examples/plugins/ds485Client/Makefile 2009-10-23 09:37:03 UTC (rev 8861)
@@ -0,0 +1,13 @@
+
+
+all: webserver_plugin_ds485client.so install
+
+webserver_plugin_ds485client.so2: webserver_plugin_ds485client.o
+ g++ -shared -o webserver_plugin_ds485client.so *.o
+
+
+webserver_plugin_ds485client.so: webserver_plugin_ds485client.cpp ../../../core/web/plugin/webserver_plugin_ds485client.h
+ g++ -I../../../ -g3 -O0 -Wall -fPIC -shared webserver_plugin_ds485client.cpp -o webserver_plugin_ds485client.so
+
+install: webserver_plugin_ds485client.so
+ cp webserver_plugin_ds485client.so ../../../data/webplugins/
Added: dss/trunk/examples/plugins/ds485Client/Makefile.OSX
===================================================================
--- dss/trunk/examples/plugins/ds485Client/Makefile.OSX (rev 0)
+++ dss/trunk/examples/plugins/ds485Client/Makefile.OSX 2009-10-23 09:37:03 UTC (rev 8861)
@@ -0,0 +1,11 @@
+
+
+all: webserver_plugin_ds485client.so install
+
+webserver_plugin_ds485client.so: webserver_plugin_ds485client.o
+ g++ -dynamiclib -undefined dynamic_lookup -single_module -o webserver_plugin_ds485client.so *.o
+webserver_plugin_ds485client.o: webserver_plugin_ds485client.cpp
+ g++ -I../../../ -I/opt/local/include -g3 -O0 -Wall -fPIC -c webserver_plugin_ds485client.cpp
+
+install: webserver_plugin_ds485client.so
+ cp webserver_plugin_ds485client.so ../../../data/webplugins/
Added: dss/trunk/examples/plugins/ds485Client/webserver_plugin_ds485client.cpp
===================================================================
--- dss/trunk/examples/plugins/ds485Client/webserver_plugin_ds485client.cpp (rev 0)
+++ dss/trunk/examples/plugins/ds485Client/webserver_plugin_ds485client.cpp 2009-10-23 09:37:03 UTC (rev 8861)
@@ -0,0 +1,57 @@
+#include <cstdlib>
+#include <iostream>
+
+#include "core/base.h"
+#include "core/web/plugin/webserver_plugin.h"
+#include "core/datetools.h"
+#include "core/dss.h"
+#include "core/model.h"
+#include "core/ds485client.h"
+#include "unix/ds485.h"
+#include "core/ds485const.h"
+
+using namespace dss;
+
+int plugin_getversion() {
+ return WEBSERVER_PLUGIN_API_VERSION;
+}
+
+bool plugin_handlerequest(const std::string& _uri, dss::HashMapConstStringString& _parameter, std::string& result) {
+ std::cout << "in plugin_handlerequest" << std::endl;
+ if(endsWith(_uri, "/send")) {
+ DS485Client oClient;
+
+ int destination = strToIntDef(_parameter["destination"],0) & 0x3F;
+ bool broadcast = _parameter["broadcast"] == "true";
+ int counter = strToIntDef(_parameter["counter"], 0x00) & 0x03;
+ int command = strToIntDef(_parameter["command"], 0x09 /* request */) & 0x00FF;
+ int length = strToIntDef(_parameter["length"], 0x00) & 0x0F;
+
+ std::cout
+ << "sending frame: "
+ << "\ndest: " << destination
+ << "\nbcst: " << broadcast
+ << "\ncntr: " << counter
+ << "\ncmd : " << command
+ << "\nlen : " << length << std::endl;
+
+ DS485CommandFrame frame;
+ frame.getHeader().setBroadcast(broadcast);
+ frame.getHeader().setDestination(destination);
+ frame.getHeader().setCounter(counter);
+ frame.setCommand(command);
+ for(int iByte = 0; iByte < length; iByte++) {
+ uint8_t byte = strToIntDef(_parameter[std::string("payload_") + intToString(iByte+1)], 0xFF);
+ std::cout << "b" << std::dec << iByte << ": " << std::hex << (int)byte << "\n";
+ frame.getPayload().add<uint8_t>(byte);
+ }
+ std::cout << std::dec << "done" << std::endl;
+
+ oClient.sendFrameDiscardResult(frame);
+ result = "done.";
+ } else {
+ result = "echo... from: " + _uri;
+ }
+ return true;
+}
+
More information about the dss-commits
mailing list