[Debian-iot-packaging] [openzwave-controlpanel] 78/81: Autoconnect default device; autoinit connected device.
Dara Adib
daradib-guest at moszumanska.debian.org
Thu Dec 22 16:57:56 UTC 2016
This is an automated email from the git hooks/post-receive script.
daradib-guest pushed a commit to branch debian/master
in repository openzwave-controlpanel.
commit e3011f6e0cbaba19441a45a5324a654b0d98ec61
Author: Manan <aarsucom at gmail.com>
Date: Sat Sep 24 15:49:32 2016 -0500
Autoconnect default device; autoinit connected device.
---
cp.html | 3 +-
cp.js | 27 +++++++++++-
webserver.cpp | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
webserver.h | 1 +
4 files changed, 163 insertions(+), 3 deletions(-)
diff --git a/cp.html b/cp.html
index d0ad1df..465ae27 100644
--- a/cp.html
+++ b/cp.html
@@ -46,7 +46,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
- <body onload="return BED();" onmousemove="PosToolTip(event);">
+ <body onload="GetDefaultDevice();" onmousemove="PosToolTip(event);">
<h1 id="title">OpenZWave Control Panel</h1>
<div class="container-fluid">
<div class="col-xs-6 col-sm-4">
@@ -78,6 +78,7 @@
<div style="float: right; padding-right: 7px;">
<button class="btn btn-default" name="close" type="button" style="text-align: left;" onclick=" return DoDevPost('close');">Close</button>
</div>
+
</form>
</div>
<div class="col-xs-6 col-sm-4">
diff --git a/cp.js b/cp.js
index c6c23a6..c196364 100644
--- a/cp.js
+++ b/cp.js
@@ -71,6 +71,30 @@ if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
racphttp = new ActiveXObject("Microsoft.XMLHTTP");
}
+function GetDefaultDevice() {
+ var devhttp;
+ if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
+ devhttp = new XMLHttpRequest();
+ } else {
+ devhttp = new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ devhttp.onreadystatechange = function() {
+ if (devhttp.readyState==4 && devhttp.status==200){
+ if (devhttp.responseText == 'NULL')
+ document.DevPost.devname.value = '';
+ else
+ document.DevPost.devname.value = devhttp.responseText;
+ }
+ BED();
+ }
+ devhttp.open("GET", "currdev", true);
+ if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
+ devhttp.send(null);
+ } else { // code for IE6, IE5
+ devhttp.send();
+ }
+}
+
function OptionGroup(label, disabled) {
var element = document.createElement('optgroup');
if (disabled !== undefined) element.disabled = disabled;
@@ -391,8 +415,7 @@ function PollReply() {
function BED() {
var forms = document.forms;
- var off = false;
- (document.DevPost.devname.value.length == 0) && !document.DevPost.usbb.checked;
+ var off = (document.DevPost.devname.value.length == 0) && !document.DevPost.usbb.checked;
var info;
tt.setAttribute('id', 'tt');
diff --git a/webserver.cpp b/webserver.cpp
index 5a488e2..f6aa67b 100644
--- a/webserver.cpp
+++ b/webserver.cpp
@@ -806,6 +806,113 @@ int Webserver::SendPollResponse (struct MHD_Connection *conn)
ret = web_send_file(conn, fn, MHD_HTTP_OK, true);
return ret;
}
+/*
+ * SendDeviceListResponse
+ * Process request for Device List from client and return
+ * data as xml.
+ */
+int Webserver::SendDeviceListResponse (struct MHD_Connection *conn)
+{
+ TiXmlDocument doc;
+ char str[16];
+ int32 i, j;
+ char fntemp[32];
+ char *fn;
+ int32 ret;
+
+ TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "utf-8", "" );
+ doc.LinkEndChild(decl);
+ TiXmlElement* pollElement = new TiXmlElement("devices");
+ doc.LinkEndChild(pollElement);
+ if (homeId != 0L)
+ snprintf(str, sizeof(str), "%08x", homeId);
+ else
+ str[0] = '\0';
+ pollElement->SetAttribute("homeid", str);
+ if (nodeId != 0)
+ snprintf(str, sizeof(str), "%d", nodeId);
+ else
+ str[0] = '\0';
+ pollElement->SetAttribute("nodeid", str);
+ snprintf(str, sizeof(str), "%d", SUCnodeId);
+ pollElement->SetAttribute("sucnodeid", str);
+ pollElement->SetAttribute("nodecount", MyNode::getNodeCount());
+ pollElement->SetAttribute("cmode", cmode);
+ pollElement->SetAttribute("save", needsave);
+ pollElement->SetAttribute("noop", noop);
+
+ pthread_mutex_lock(&nlock);
+ i = 0;
+ j = 1;
+ while (j <= MyNode::getNodeCount() && i < MAX_NODES) {
+ if (nodes[i] != NULL) {
+ bool listening;
+ bool flirs;
+ bool zwaveplus;
+ TiXmlElement* nodeElement = new TiXmlElement("node");
+ pollElement->LinkEndChild(nodeElement);
+ nodeElement->SetAttribute("id", i);
+ zwaveplus = Manager::Get()->IsNodeZWavePlus(homeId, i);
+ if (zwaveplus) {
+ string value = Manager::Get()->GetNodePlusTypeString(homeId, i);
+ value += " " + Manager::Get()->GetNodeRoleString(homeId, i);
+ nodeElement->SetAttribute("btype", value.c_str());
+ nodeElement->SetAttribute("gtype", Manager::Get()->GetNodeDeviceTypeString(homeId, i).c_str());
+ } else {
+ nodeElement->SetAttribute("btype", nodeBasicStr(Manager::Get()->GetNodeBasic(homeId, i)));
+ nodeElement->SetAttribute("gtype", Manager::Get()->GetNodeType(homeId, i).c_str());
+ }
+ nodeElement->SetAttribute("name", Manager::Get()->GetNodeName(homeId, i).c_str());
+ nodeElement->SetAttribute("location", Manager::Get()->GetNodeLocation(homeId, i).c_str());
+ nodeElement->SetAttribute("manufacturer", Manager::Get()->GetNodeManufacturerName(homeId, i).c_str());
+ nodeElement->SetAttribute("product", Manager::Get()->GetNodeProductName(homeId, i).c_str());
+ listening = Manager::Get()->IsNodeListeningDevice(homeId, i);
+ nodeElement->SetAttribute("listening", listening ? "true" : "false");
+ flirs = Manager::Get()->IsNodeFrequentListeningDevice(homeId, i);
+ nodeElement->SetAttribute("frequent", flirs ? "true" : "false");
+ nodeElement->SetAttribute("zwaveplus", zwaveplus ? "true" : "false");
+ nodeElement->SetAttribute("beam", Manager::Get()->IsNodeBeamingDevice(homeId, i) ? "true" : "false");
+ nodeElement->SetAttribute("routing", Manager::Get()->IsNodeRoutingDevice(homeId, i) ? "true" : "false");
+ nodeElement->SetAttribute("security", Manager::Get()->IsNodeSecurityDevice(homeId, i) ? "true" : "false");
+#if 0
+ fprintf(stderr, "i=%d failed=%d\n", i, Manager::Get()->IsNodeFailed(homeId, i));
+ fprintf(stderr, "i=%d awake=%d\n", i, Manager::Get()->IsNodeAwake(homeId, i));
+ fprintf(stderr, "i=%d state=%s\n", i, Manager::Get()->GetNodeQueryStage(homeId, i).c_str());
+ fprintf(stderr, "i=%d listening=%d flirs=%d\n", i, listening, flirs);
+#endif
+ if (Manager::Get()->IsNodeFailed(homeId, i))
+ nodeElement->SetAttribute("status", "Dead");
+ else {
+ string s = Manager::Get()->GetNodeQueryStage(homeId, i);
+ if (s == "Complete") {
+ if (i != nodeId && !listening && !flirs)
+ nodeElement->SetAttribute("status", Manager::Get()->IsNodeAwake(homeId, i) ? "Awake" : "Sleeping" );
+ else
+ nodeElement->SetAttribute("status", "Ready");
+ } else {
+ if (i != nodeId && !listening && !flirs)
+ s = s + (Manager::Get()->IsNodeAwake(homeId, i) ? " (awake)" : " (sleeping)");
+ nodeElement->SetAttribute("status", s.c_str());
+ }
+ }
+ web_get_groups(i, nodeElement);
+ web_get_values(i, nodeElement);
+ j++;
+ }
+ i++;
+ }
+ pthread_mutex_unlock(&nlock);
+ strncpy(fntemp, "/tmp/ozwcp.devices.XXXXXX", sizeof(fntemp));
+ fn = mktemp(fntemp);
+ if (fn == NULL)
+ return MHD_YES;
+ strncat(fntemp, ".xml", sizeof(fntemp));
+ if (debug)
+ doc.Print(stdout, 0);
+ doc.SaveFile(fn);
+ ret = web_send_file(conn, fn, MHD_HTTP_OK, true);
+ return ret;
+}
/*
* web_controller_update
@@ -1028,6 +1135,10 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
ret = web_send_file(conn, "openzwavetinyicon.png", MHD_HTTP_OK, false);
else if (strcmp(url, "/poll.xml") == 0 && (devname != NULL || usb))
ret = SendPollResponse(conn);
+ else if (strcmp(url, "/devices.xml") == 0 && (devname != NULL || usb))
+ ret = SendDeviceListResponse(conn);
+ else if (strcmp(url, "/currdev") == 0)
+ ret = web_send_data(conn, devname ? devname : "NULL", MHD_HTTP_OK, false, false, "text/pain"); // no free, no copy
else
ret = web_send_data(conn, UNKNOWN, MHD_HTTP_NOT_FOUND, false, false, NULL); // no free, no copy
return ret;
@@ -1412,6 +1523,21 @@ Webserver::Webserver (int const wport) : sortcol(COL_NODE), logbytes(0), adminst
if (wdata != NULL) {
ready = true;
}
+ if (devname == NULL){
+ char* default_device;
+ default_device = getenv("OZW_DEFAULT_DEVICE");
+ if ( (default_device != NULL) &&
+ (strcmp(default_device, "") != 0)){
+ devname = (char *)malloc(strlen(default_device) + 1);
+ if (devname == NULL) {
+ fprintf(stderr, "Out of memory open devname\n");
+ exit(1);
+ }
+ usb=false;
+ strcpy(devname, default_device);
+ Manager::Get()->AddDriver(devname);
+ }
+ }
}
/*
@@ -1426,4 +1552,13 @@ Webserver::~Webserver ()
wdata = NULL;
ready = false;
}
+ pthread_mutex_lock(&glock);
+ if (devname != NULL || usb) {
+ Manager::Get()->RemoveDriver(devname ? devname : "HID Controller");
+ free(devname);
+ devname = NULL;
+ homeId = 0;
+ usb = false;
+ }
+ pthread_mutex_unlock(&glock);
}
diff --git a/webserver.h b/webserver.h
index a0326fe..0e819c9 100644
--- a/webserver.h
+++ b/webserver.h
@@ -58,6 +58,7 @@ class Webserver {
void web_get_groups(int i, TiXmlElement *ep);
void web_get_values(int i, TiXmlElement *ep);
int SendPollResponse(struct MHD_Connection *conn);
+ int SendDeviceListResponse(struct MHD_Connection *conn);
const char *SendSceneResponse(struct MHD_Connection *conn, const char *fun, const char *arg1, const char *arg2, const char *arg3);
const char *SendTopoResponse(struct MHD_Connection *conn, const char *fun, const char *arg1, const char *arg2, const char *arg3);
const char *SendStatResponse(struct MHD_Connection *conn, const char *fun, const char *arg1, const char *arg2, const char *arg3);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-iot/openzwave-controlpanel.git
More information about the Debian-iot-packaging
mailing list