[Debian-iot-packaging] [openzwave-controlpanel] 21/81: Some group handling fixes. Add handheld button support. Don't save configuration when closing driver.

Dara Adib daradib-guest at moszumanska.debian.org
Thu Dec 22 16:57:46 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 92251552b94528ff3243f4b418010abfe585559a
Author: glsatz at gmail.com <glsatz at gmail.com>
Date:   Sat Feb 11 07:08:54 2012 +0000

    Some group handling fixes.
    Add handheld button support.
    Don't save configuration when closing driver.
---
 cp.html       | 21 ++++++++++++--------
 cp.js         | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 ozwcp.cpp     | 56 ++++++++++++++++++++++++++++++++++--------------------
 webserver.cpp | 28 +++++++++++++++++++++++++--
 4 files changed, 125 insertions(+), 41 deletions(-)

diff --git a/cp.html b/cp.html
index a7f920d..cb533d5 100644
--- a/cp.html
+++ b/cp.html
@@ -259,9 +259,9 @@
     </div>
     <div id="admin" style="float: left; width: 100%;">
       <fieldset> <legend> Controller </legend>
-	<form name="AdmPost" method="post"> <input name="admhidden"
-						   class="hide" value="hidden">
-	  <div class="esb" style="margin-left: 14px; width: 275px;">
+	<form name="AdmPost" method="post">
+	  <input name="admhidden" class="hide" value="hidden">
+	  <div class="esb" style="margin-left: 14px; width: 200px;">
 	    <select id="adminops" onchange="return DoAdmHelp();">
 	      <option value="choice" selected="true">Select an operation:</option>
 	      <option value="addc">Add Controller</option>
@@ -278,13 +278,18 @@
 	      <option value="reqnnu">Request Node Neighbor Update</option>
 	      <option value="assrr">Assign Return Route</option>
 	      <option value="delarr">Delete All Return Routes</option>
+	      <option value="addbtn">Add Button</option>
+	      <option value="delbtn">Delete Button</option>
 	    </select>
-	    <button id="admgo" name="go" style="text-align: center;"
-		    onclick="return DoAdmPost(0);" type="submit">Go</button> 
-	    <button id="admcan" name="cancel" style="text-align: center; display: none;"
-		    onclick="return DoAdmPost(1);" type="submit">Cancel</button>
 	  </div>
-	  <div class="rsb"><span id="adminfo" name="adminfo" class="admmsg"></span></div>
+	  <div id="admcntl" name="admcntl" class="rsb" style="display: none;"></div>
+	  <button id="admgo" name="go" style="float: left; text-align: center; display: none; margin-left: 10px;"
+		  onclick="return DoAdmPost(0);" type="submit">Go</button> 
+	  <button id="admcan" name="cancel" style="float: left; text-align: center; display: none;"
+		  onclick="return DoAdmPost(1);" type="submit">Cancel</button>
+	  <div class="rsb" style="margin-left: 10px;">
+	    <span id="adminfo" name="adminfo" class="admmsg"></span>
+	  </div>
 	</form>
       </fieldset>
     </div>
diff --git a/cp.js b/cp.js
index f9973de..212f7e4 100644
--- a/cp.js
+++ b/cp.js
@@ -315,7 +315,9 @@ function BED()
   info.style.display = 'none';
   document.AdmPost.adminops.selectedIndex = 0;
   document.AdmPost.adminops.disabled = off;
-  info = document.getElementById('netinfo');
+  info = document.getElementById('adminfo');
+  info.style.display = 'none';
+  info = document.getElementById('admcntl');
   info.style.display = 'none';
   document.NodePost.nodeops.selectedIndex = 0;
   document.NodePost.nodeops.disabled = off;
@@ -549,15 +551,29 @@ function DoAdmPost(can)
   }
   params = 'fun='+fun;
 
-  if ((fun == 'hnf' || fun == 'remfn' || fun == 'repfn' || fun == 'reqnu' || fun == 'reqnnu' ||
-       fun == 'assrr' || fun == 'delarr') && curnode == null) {
-    ainfo = document.getElementById('adminfo');
-    ainfo.innerHTML = 'Must select a node below for this function.';
-    ainfo.style.display = 'block';
-    return false;
+  if (fun == 'hnf' || fun == 'remfn' || fun == 'repfn' || fun == 'reqnu' ||
+      fun == 'reqnnu' || fun == 'assrr' || fun == 'delarr' || 
+      fun == 'addbtn' || fun == 'delbtn') {
+    if (curnode == null) {
+      ainfo = document.getElementById('adminfo');
+      ainfo.innerHTML = 'Must select a node below for this function.';
+      ainfo.style.display = 'block';
+      return false;
+    }
+    params = params+'&node='+curnode;
+  }
+
+  if (fun == 'addbtn' || fun == 'delbtn') {
+    if (document.AdmPost.button.value.length == 0) {
+      ainfo = document.getElementById('adminfo');
+      ainfo.innerHTML = 'Button number is required.';
+      ainfo.style.display = 'block';
+      document.AdmPost.button.select();
+      return false;
+    }
+    params = params+'&button='+document.AdmPost.button.value;
   }
 
-  params = params+'&node='+curnode;
   if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
     posthttp=new XMLHttpRequest();
   } else {
@@ -579,6 +595,9 @@ function DoAdmPost(can)
 function DoAdmHelp()
 {
   ainfo = document.getElementById('adminfo');
+  var acntl = document.getElementById('admcntl');
+  acntl.innerHTML = '';
+  document.AdmPost.admgo.style.display = 'inline';
   if (document.AdmPost.adminops.value == 'addc') {
     ainfo.innerHTML = 'Add a new secondary controller to the Z-Wave network.';
     ainfo.style.display = 'block';
@@ -586,7 +605,7 @@ function DoAdmHelp()
     ainfo.innerHTML = 'Add a new device (but not a controller) to the Z-Wave network.';
     ainfo.style.display = 'block';
   } else if (document.AdmPost.adminops.value == 'cprim') {
-    ainfo.innerHTML = '(Not yet implemented)';
+    ainfo.innerHTML = 'Add a new primary controller in place of dead old controller.';
     ainfo.style.display = 'block';
   } else if (document.AdmPost.adminops.value == 'rconf') {
     ainfo.innerHTML = 'Receive configuration from another controller.';   
@@ -607,7 +626,7 @@ function DoAdmHelp()
     ainfo.innerHTML = 'Replace a failed device with another.';
     ainfo.style.display = 'block';
   } else if (document.AdmPost.adminops.value == 'tranpr') {
-    ainfo.innerHTML = '(Not yet implemented) - Add a new controller to the network and make it the primary.';
+    ainfo.innerHTML = 'Add a new controller to the network and make it the primary.';
     ainfo.style.display = 'block';
   } else if (document.AdmPost.adminops.value == 'reqnu') {
     ainfo.style.display = 'block';
@@ -621,8 +640,26 @@ function DoAdmHelp()
   } else if (document.AdmPost.adminops.value == 'delarr') {
     ainfo.innerHTML = 'Delete all network return routes from a device.';
     ainfo.style.display = 'block';
+  } else if (document.AdmPost.adminops.value == 'addbtn' ||
+	     document.AdmPost.adminops.value == 'delbtn') {
+    if (curnode == null) {
+      ainfo.innerHTML = 'Must select a node below for this funcion.';
+      ainfo.style.display = 'block';
+      document.AdmPost.adminops.selectedIndex = 0;
+      document.AdmPost.admgo.style.display = 'none';
+      return false;
+    }
+    acntl.innerHTML = '<label style="margin-left: 10px;"><span class="legend">Button number: </span></label><input type="text" class="legend" size="3" id="button" value="">';
+    acntl.style.display = 'block';
+    document.AdmPost.button.select();
+    if (document.AdmPost.adminops.value == 'addbtn')
+      ainfo.innerHTML = 'Add a button from a handheld.';
+    else
+      ainfo.innerHTML = 'Remove a button from a handheld.';
+    ainfo.style.display = 'block';
   } else {
     ainfo.style.display = 'none';
+    document.AdmPost.admgo.style.display = 'none';
   }
   return true;
 }
@@ -1275,7 +1312,9 @@ function CreateGroup(ind)
     nodegrp[ind]=nodegrp[ind]+'<option value="'+nodes[ind].groups[i].id+'">'+nodes[ind].groups[i].label+' ('+nodes[ind].groups[i].id+')</option>';
     nodegrpgrp[ind][grp] = '<td><div id="nodegrp" name="nodegrp" style="float: right;"><select id="groups" multiple size="4" style="vertical-align: top; margin-left: 5px;">';
     k = 0;
-    for (j = 1; j <= nodecount; j++) {
+    for (j = 1; j < nodes.length; j++) {
+      if (nodes[j] == null)
+	continue;
       if (nodes[ind].groups[i].nodes != null)
 	while (k < nodes[ind].groups[i].nodes.length && nodes[ind].groups[i].nodes[k] < j)
 	  k++;
diff --git a/ozwcp.cpp b/ozwcp.cpp
index 5698b4c..74275c4 100644
--- a/ozwcp.cpp
+++ b/ozwcp.cpp
@@ -205,6 +205,7 @@ void MyNode::newGroup (uint8 node)
  */
 void MyNode::addGroup (uint8 node, uint8 g, uint8 n, uint8 *v)
 {
+  fprintf(stderr, "addGroup: node %d group %d n %d\n", node, g, n);
   if (groups.size() == 0)
     newGroup(node);
   for (vector<MyGroup*>::iterator it = groups.begin(); it != groups.end(); ++it)
@@ -243,11 +244,12 @@ void MyNode::updateGroup (uint8 node, uint8 grp, char *glist)
   uint8 n;
   uint8 j;
 
+  fprintf(stderr, "updateGroup: node %d group %d\n", node, grp);
   for (it = groups.begin(); it != groups.end(); ++it)
     if ((*it)->groupid == grp)
       break;
   if (it == groups.end()) {
-    fprintf(stderr, "updateGroup: group %d not found\n", grp);
+    fprintf(stderr, "updateGroup: node %d group %d not found\n", node, grp);
     return;
   }
   v = new uint8((*it)->max);
@@ -459,12 +461,10 @@ void OnNotification (Notification const* _notification, void* _context)
 		 _notification->GetHomeId(), _notification->GetNodeId(), _notification->GetGroupIdx());
       uint8 *v;
       int8 n = Manager::Get()->GetAssociations(homeId, _notification->GetNodeId(), _notification->GetGroupIdx(), &v);
-      if (n > 0) {
-	pthread_mutex_lock(&nlock);
-	nodes[_notification->GetNodeId()]->addGroup(_notification->GetNodeId(), _notification->GetGroupIdx(), n, v);
-	pthread_mutex_unlock(&nlock);
-	delete [] v;
-      }
+      pthread_mutex_lock(&nlock);
+      nodes[_notification->GetNodeId()]->addGroup(_notification->GetNodeId(), _notification->GetGroupIdx(), n, v);
+      pthread_mutex_unlock(&nlock);
+      delete [] v;
     }
     break;
   case Notification::Type_NodeNew:
@@ -500,15 +500,6 @@ void OnNotification (Notification const* _notification, void* _context)
     needsave = true;
     pthread_mutex_unlock(&glock);
     break;
-  case Notification::Type_NodeEvent:
-    Log::Write("Notification: Node Event Home %08x Node %d Status %d Genre %s Class %s Instance %d Index %d Type %s",
-	       _notification->GetHomeId(), _notification->GetNodeId(), _notification->GetEvent(),
-	       valueGenreStr(id.GetGenre()), cclassStr(id.GetCommandClassId()), id.GetInstance(),
-	       id.GetIndex(), valueTypeStr(id.GetType()));
-    pthread_mutex_lock(&nlock);
-    nodes[_notification->GetNodeId()]->saveValue(id);
-    pthread_mutex_unlock(&nlock);
-    break;
   case Notification::Type_NodeProtocolInfo:
     Log::Write("Notification: Node Protocol Info Home %08x Node %d Genre %s Class %s Instance %d Index %d Type %s",
 	       _notification->GetHomeId(), _notification->GetNodeId(),
@@ -521,6 +512,15 @@ void OnNotification (Notification const* _notification, void* _context)
 	       valueGenreStr(id.GetGenre()), cclassStr(id.GetCommandClassId()), id.GetInstance(),
 	       id.GetIndex(), valueTypeStr(id.GetType()));
     break;
+  case Notification::Type_NodeEvent:
+    Log::Write("Notification: Node Event Home %08x Node %d Status %d Genre %s Class %s Instance %d Index %d Type %s",
+	       _notification->GetHomeId(), _notification->GetNodeId(), _notification->GetEvent(),
+	       valueGenreStr(id.GetGenre()), cclassStr(id.GetCommandClassId()), id.GetInstance(),
+	       id.GetIndex(), valueTypeStr(id.GetType()));
+    pthread_mutex_lock(&nlock);
+    nodes[_notification->GetNodeId()]->saveValue(id);
+    pthread_mutex_unlock(&nlock);
+    break;
   case Notification::Type_PollingDisabled:
     Log::Write("Notification: Polling Disabled Home %08x Node %d Genre %s Class %s Instance %d Index %d Type %s",
 	       _notification->GetHomeId(), _notification->GetNodeId(),
@@ -539,6 +539,22 @@ void OnNotification (Notification const* _notification, void* _context)
     //nodes[_notification->GetNodeId()]->setPolled(true);
     //pthread_mutex_unlock(&nlock);
     break;
+  case Notification::Type_CreateButton:
+    Log::Write("Notification: Create button Home %08x Node %d Button %d",
+	       _notification->GetHomeId(), _notification->GetNodeId(), _notification->GetButtonId());
+    break;
+  case Notification::Type_DeleteButton:
+    Log::Write("Notification: Delete button Home %08x Node %d Button %d",
+	       _notification->GetHomeId(), _notification->GetNodeId(), _notification->GetButtonId());
+    break;
+  case Notification::Type_ButtonOn:
+    Log::Write("Notification: Button On Home %08x Node %d Button %d",
+	       _notification->GetHomeId(), _notification->GetNodeId(), _notification->GetButtonId());
+    break;
+  case Notification::Type_ButtonOff:
+    Log::Write("Notification: Button Off Home %08x Node %d Button %d",
+	       _notification->GetHomeId(), _notification->GetNodeId(), _notification->GetButtonId());
+    break;
   case Notification::Type_DriverReady:
     Log::Write("Notification: Driver Ready, homeId %08x, nodeId %d", _notification->GetHomeId(),
 	       _notification->GetNodeId());
@@ -587,15 +603,15 @@ void OnNotification (Notification const* _notification, void* _context)
   case Notification::Type_MsgComplete:
     Log::Write("Notification: Message Complete");
     break;
+  case Notification::Type_EssentialNodeQueriesComplete:
+    Log::Write("Notification: Essential Node %d Queries Complete", _notification->GetNodeId());
+    break;
   case Notification::Type_NodeQueriesComplete:
     Log::Write("Notification: Node %d Queries Complete", _notification->GetNodeId());
     pthread_mutex_lock(&nlock);
     nodes[_notification->GetNodeId()]->sortValues();
     pthread_mutex_unlock(&nlock);
     break;
-  case Notification::Type_EssentialNodeQueriesComplete:
-    Log::Write("Notification: Essential Node %d Queries Complete", _notification->GetNodeId());
-    break;
   case Notification::Type_AwakeNodesQueried:
     Log::Write("Notification: Awake Nodes Queried");
     break;
@@ -641,7 +657,7 @@ int32 main(int32 argc, char* argv[])
   for (i = 0; i < MAX_NODES; i++)
     nodes[i] = NULL;
 
-  Options::Create("config/", "", "");
+  Options::Create("./config/", "", "--SaveConfiguration=false");
   Options::Get()->Lock();
 
   Manager::Create();
diff --git a/webserver.cpp b/webserver.cpp
index 28a558a..6852207 100644
--- a/webserver.cpp
+++ b/webserver.cpp
@@ -592,7 +592,7 @@ void web_controller_update (Driver::ControllerState cs, void *ct)
     cp->setAdminMessage(": waiting for a user action.");
     break;
   case Driver::ControllerState_InProgress:
-    cp->setAdminMessage(": communicationg with the other device.");
+    cp->setAdminMessage(": communicating with the other device.");
     break;
   case Driver::ControllerState_Completed:
     cp->setAdminMessage(": command has completed successfully.");
@@ -646,6 +646,8 @@ int web_config_post (void *cls, enum MHD_ValueKind kind, const char *key, const
       cp->conn_arg1 = (void *)strdup(data);
     else if (strcmp(key, "node") == 0)
       cp->conn_arg2 = (void *)strdup(data);
+    else if (strcmp(key, "button") == 0)
+      cp->conn_arg3 = (void *)strdup(data);
   } else if (strcmp(cp->conn_url, "/nodepost.html") == 0) {
     if (strcmp(key, "fun") == 0)
       cp->conn_arg1 = (void *)strdup(data);
@@ -974,6 +976,28 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 								 Driver::ControllerCommand_DeleteAllReturnRoutes,
 								 web_controller_update, this, true, node));
 	  }
+	} else if (strcmp((char *)cp->conn_arg1, "addbtn") == 0) {
+	  if (cp->conn_arg2 != NULL && strlen((char *)cp->conn_arg2) > 4 &&
+	      cp->conn_arg3 != NULL) {
+	    uint8 node = strtol(((char *)cp->conn_arg2) + 4, NULL, 10);
+	    uint8 button = strtol(((char *)cp->conn_arg3), NULL, 10);
+	    setAdminFunction("Add Button");
+	    setAdminState(
+			  Manager::Get()->BeginControllerCommand(homeId,
+								 Driver::ControllerCommand_CreateButton,
+								 web_controller_update, this, true, node, button));
+	  }
+	} else if (strcmp((char *)cp->conn_arg1, "delbtn") == 0) {
+	  if (cp->conn_arg2 != NULL && strlen((char *)cp->conn_arg2) > 4 &&
+	      cp->conn_arg3 != NULL) {
+	    uint8 node = strtol(((char *)cp->conn_arg2) + 4, NULL, 10);
+	    uint8 button = strtol(((char *)cp->conn_arg3), NULL, 10);
+	    setAdminFunction("Delete Button");
+	    setAdminState(
+			  Manager::Get()->BeginControllerCommand(homeId,
+								 Driver::ControllerCommand_DeleteButton,
+								 web_controller_update, this, true, node, button));
+	  }
 	}
 	return MHD_YES;
       } else
@@ -1007,7 +1031,7 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 
 	if (cp->conn_arg2 != NULL && strlen((char *)cp->conn_arg2) > 4 &&
 	    cp->conn_arg3 != NULL && strlen((char *)cp->conn_arg3) > 0 && cp->conn_arg4 != NULL) {
-	  node = strtol(((char *)cp->conn_arg2) + 4, NULL, 10) + 1;
+	  node = strtol(((char *)cp->conn_arg2) + 4, NULL, 10);
 	  grp = strtol((char *)cp->conn_arg3, NULL, 10);
 	  if (strcmp((char *)cp->conn_arg1, "group") == 0) { /* Group update */
 	    pthread_mutex_lock(&nlock);

-- 
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