[dss-commits] r8824 - in dss/branches/0.5: . core core/sim data external external/slaves

dss-commits at forum.digitalstrom.org dss-commits at forum.digitalstrom.org
Tue Oct 6 10:34:27 CEST 2009


Author: jwinkelmann
Date: 2009-10-06 10:34:27 +0200 (Tue, 06 Oct 2009)
New Revision: 8824

Removed:
   dss/branches/0.5/external/slaves/sensornest.cpp
   dss/branches/0.5/external/slaves/sensornest.h
Modified:
   dss/branches/0.5/CMakeLists.txt
   dss/branches/0.5/config.h.in
   dss/branches/0.5/core/dss.cpp
   dss/branches/0.5/core/sim/dssim.cpp
   dss/branches/0.5/data/sim.xml
   dss/branches/0.5/external/CMakeLists.txt
   dss/branches/0.5/external/slaves/CMakeLists.txt
Log:
Prepare 0.5 release:
- remove sensornest code
- rdisable temperature sensor in sim.xml
- bump version to 0.5


Modified: dss/branches/0.5/CMakeLists.txt
===================================================================
--- dss/branches/0.5/CMakeLists.txt	2009-10-06 08:06:15 UTC (rev 8823)
+++ dss/branches/0.5/CMakeLists.txt	2009-10-06 08:34:27 UTC (rev 8824)
@@ -150,7 +150,7 @@
        )
 
 
-TARGET_LINK_LIBRARIES(dss ${TEST_LIB} ${BOOST_TEST_LIB} core unix slaves webservices pthread
+TARGET_LINK_LIBRARIES(dss ${TEST_LIB} ${BOOST_TEST_LIB} core unix webservices pthread
 	mongoose ${REQUIRED_LIBS})
 
 

Modified: dss/branches/0.5/config.h.in
===================================================================
--- dss/branches/0.5/config.h.in	2009-10-06 08:06:15 UTC (rev 8823)
+++ dss/branches/0.5/config.h.in	2009-10-06 08:34:27 UTC (rev 8824)
@@ -1,7 +1,7 @@
 #ifndef DIGITAL_STROM_SERVER_CONFIG_H
 #define DIGITAL_STROM_SERVER_CONFIG_H
 
-#define DSS_VERSION "0.5-dev"
+#define DSS_VERSION "0.5"
 
 /* SpiderMonkey API header */
 #cmakedefine HAVE_MOZJS_JSAPI_H

Modified: dss/branches/0.5/core/dss.cpp
===================================================================
--- dss/branches/0.5/core/dss.cpp	2009-10-06 08:06:15 UTC (rev 8823)
+++ dss/branches/0.5/core/dss.cpp	2009-10-06 08:34:27 UTC (rev 8824)
@@ -49,7 +49,6 @@
 #include "event.h"
 #include "metering/metering.h"
 #include "metering/fake_meter.h"
-#include "external/slaves/sensornest.h"
 #include "foreach.h"
 
 #include <cassert>
@@ -252,13 +251,9 @@
       Logger::getInstance()->log("No logfile configured, logging to stdout", 
                                  lsInfo);
     }
-    
+
     dss::Logger::getInstance()->log(versionString(), lsInfo);
 
-    SensornestServer server;
-    server.run();
-
-
     m_State = ssInitializingSubsystems;
     std::for_each(m_Subsystems.begin(), m_Subsystems.end(), InitializeSubsystem);
 

Modified: dss/branches/0.5/core/sim/dssim.cpp
===================================================================
--- dss/branches/0.5/core/sim/dssim.cpp	2009-10-06 08:06:15 UTC (rev 8823)
+++ dss/branches/0.5/core/sim/dssim.cpp	2009-10-06 08:34:27 UTC (rev 8824)
@@ -20,6 +20,7 @@
 */
 
 #include "dssim.h"
+#include "dsidsim.h"
 
 #include <dlfcn.h>
 
@@ -37,7 +38,6 @@
 #include "core/DS485Interface.h"
 #include "core/foreach.h"
 #include "core/propertysystem.h"
-#include "external/slaves/sensornest.h"
 #include "dsid_js.h"
 #include "dsid_plugin.h"
 
@@ -86,7 +86,6 @@
     Subsystem::initialize();
     m_DSIDFactory.registerCreator(new DSIDSimCreator());
     m_DSIDFactory.registerCreator(new DSIDSimSwitchCreator());
-    m_DSIDFactory.registerCreator(new DSIDSimSensornestCreator());
 
     PropertyNodePtr pNode = getDSS().getPropertySystem().getProperty(getConfigPropertyBasePath() + "js-devices");
     if(pNode != NULL) {

Modified: dss/branches/0.5/data/sim.xml
===================================================================
--- dss/branches/0.5/data/sim.xml	2009-10-06 08:06:15 UTC (rev 8823)
+++ dss/branches/0.5/data/sim.xml	2009-10-06 08:34:27 UTC (rev 8824)
@@ -3,7 +3,7 @@
   <modulator busid="71" dsid="13">
     <zone id="4">
       <device dsid="11" busid="11" type="standard.simple"/>
-      <device dsid="16" busid="16" type="example.temperature_sensor"/>
+<!--      <device dsid="16" busid="16" type="example.temperature_sensor"/> -->
       <group id="3">
         <device busid="16" />
       </group>

Modified: dss/branches/0.5/external/CMakeLists.txt
===================================================================
--- dss/branches/0.5/external/CMakeLists.txt	2009-10-06 08:06:15 UTC (rev 8823)
+++ dss/branches/0.5/external/CMakeLists.txt	2009-10-06 08:34:27 UTC (rev 8824)
@@ -1,2 +1 @@
 add_subdirectory(mongoose)
-add_subdirectory(slaves)

Modified: dss/branches/0.5/external/slaves/CMakeLists.txt
===================================================================
--- dss/branches/0.5/external/slaves/CMakeLists.txt	2009-10-06 08:06:15 UTC (rev 8823)
+++ dss/branches/0.5/external/slaves/CMakeLists.txt	2009-10-06 08:34:27 UTC (rev 8824)
@@ -1 +1 @@
-add_library(slaves sensornest.cpp)
+# This CMakeLists.txt intentionally left blank

Deleted: dss/branches/0.5/external/slaves/sensornest.cpp
===================================================================
--- dss/branches/0.5/external/slaves/sensornest.cpp	2009-10-06 08:06:15 UTC (rev 8823)
+++ dss/branches/0.5/external/slaves/sensornest.cpp	2009-10-06 08:34:27 UTC (rev 8824)
@@ -1,737 +0,0 @@
-/*
-    Copyright (c) 2009 digitalSTROM.org, Zurich, Switzerland
-    Copyright (c) 2009 futureLAB AG, Winterthur, Switzerland
-
-    This file is part of digitalSTROM Server.
-
-    digitalSTROM Server 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.
-
-    digitalSTROM Server 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 digitalSTROM Server. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "sensornest.h"
-#include "core/foreach.h"
-#include "core/base.h"
-#include "core/dss.h"
-#include "core/model.h"
-#include "core/propertysystem.h"
-
-#include <Poco/Net/StreamSocket.h>
-#include <Poco/Net/DatagramSocket.h>
-#include <Poco/Net/ServerSocket.h>
-#include <Poco/Net/TCPServer.h>
-#include <Poco/Net/TCPServerConnection.h>
-#include <Poco/Net/TCPServerConnectionFactory.h>
-
-#include <iostream>
-#include <string>
-
-#include <fcntl.h>
-#include <stdlib.h>
-
-#ifdef linux
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-//#include <linux/if.h>
-#endif
-
-#ifdef __APPLE__
-#include <ifaddrs.h>
-#endif
-
-using namespace std;
-using Poco::Net::StreamSocket;
-using Poco::Net::ServerSocket;
-using Poco::Net::TCPServer;
-using Poco::Net::TCPServerConnection;
-using Poco::Net::TCPServerConnectionFactory;
-
-class SensornestConnection : public TCPServerConnection {
-private:
-  SensornestServer* m_pServer;
-  SensornestSlave* m_pSlave;
-public:
-  SensornestConnection(const StreamSocket& _socket, SensornestServer* _pServer)
-  : TCPServerConnection(_socket),
-    m_pServer(_pServer),
-    m_pSlave(NULL)
-  {}
-
-  void run() {
-    const int BufferSize = 60; // maximal buffer size
-    char buffer[BufferSize];
-    char recBuffer[BufferSize]; // receive buffer
-    int bufferPos = 0; // position in buffer
-    int packetSize = 0; // size of the packet we're currently processing
-    int recBufferPos = 0; // position in the receive buffer
-    bool configured = false;
-    cout << "customer arrived" << endl;
-    time_t timeConnected = time(NULL);
-
-    send("\03_CO", 4);
-    while(true) {
-      time_t lastTime = time(NULL);
-      recBufferPos = 0;
-      int len = socket().receiveBytes(recBuffer, BufferSize);
-      if(len == 0) {
-        break;
-      }
-      time_t now = time(NULL);
-      if(now - lastTime > 2) {
-        bufferPos = 0;
-        packetSize = 0;
-        cout << "resetting buffer/packet-size" << endl;
-      }
-
-      cout << "\nxlen:" << len << endl;
-      for(int iByte = 0; iByte < len; iByte++) {
-        cout << " " << hex << ((int)recBuffer[iByte] & 0x00ff) << dec;
-        flush(cout);
-      }
-      while(recBufferPos < len) {
-        if((len + bufferPos) > BufferSize) {
-          cerr << "Buffer overflow" << endl;
-          bufferPos = 0;
-          packetSize = 0;
-          recBufferPos = 0;
-          len = 0;
-          continue;
-        }
-        if(packetSize == 0) {
-          packetSize = recBuffer[0];
-          // don't copy the size
-          memcpy(&buffer, &recBuffer[1], packetSize);
-          bufferPos = packetSize;
-          recBufferPos += packetSize + 1;
-        } else if(bufferPos < packetSize) {
-          int toCopy = min(packetSize - bufferPos, len);
-          memcpy(&buffer[0] + bufferPos, &recBuffer[0], toCopy);
-          bufferPos += toCopy;
-          recBufferPos += toCopy;
-        }
-        if(bufferPos == packetSize) {
-          cout << "done" << endl;
-          if(!configured) {
-            if(buffer[0] == 'M') {
-              configured = true;
-              char mac[6];
-              memcpy(&mac[0], &buffer[0] + 1, 6);
-              m_pSlave = m_pServer->getSensornestFor(&mac[0]);
-              if(m_pSlave == NULL) {
-                cerr << "unknown slave" << endl;
-                return;
-              }
-              int defaultDevice = buffer[7];
-              cout << "Default device: " << defaultDevice << endl;
-              int zoneID = ((int)buffer[8] << 8) & (buffer[9] & 0xFF);
-              cout << "Zone ID: " << zoneID << endl;
-              m_pSlave->setSelectedColor(1);
-              m_pSlave->setConnection(this);
-            } else {
-              // timeout if not configured after 4 seconds
-              if(now - timeConnected > 4) {
-                cerr << "Configuration timed out" << endl;
-                break;
-              }
-            }
-          } else {
-            handlePacket(buffer, packetSize);
-          }
-          packetSize = 0;
-        }
-      }
-    }
-    if(m_pSlave != NULL) {
-      m_pSlave->setConnection(NULL);
-    }
-    cout << "terminating sensornest-connection" << endl;
-  } // run
-
-  void handlePacket(const char* _buffer, int _packetSize) {
-    const int BufferSize = 50;
-    char outBuf[BufferSize];
-    switch(_buffer[0]) {
-    case 'T': // time
-      outBuf[0] = 10;
-      outBuf[1] = 't';
-      outBuf[2] =  _buffer[1];
-      long t1, t2;
-      if(_buffer[1] == 1) {
-        // sunset/sunrise
-        t1 = time(NULL);
-        t2 = time(NULL);
-      } else {
-        // UTC/local
-        t1 = time(NULL);
-        t2 = time(NULL);
-      }
-      memcpy(&outBuf[0]+3, &t1, 4);
-      memcpy(&outBuf[0]+7, &t2, 4);
-      socket().sendBytes(&outBuf, 11);
-      break;
-    case 'D':
-      switch(_buffer[1]) {
-      case 'V':
-        cout << "DV" << endl;
-        try {
-          dss::Zone& zone = dss::DSS::getInstance()->getApartment().getZone(m_pSlave->getZoneID());
-          dss::Group* group = zone.getGroup(_buffer[2]);
-          if(group != NULL) {
-            if((unsigned char)_buffer[4] == 0xff) {
-              group->callScene(dss::SceneMax);
-            } else {
-              group->callScene(dss::SceneMin);
-            }
-          }
-          // TODO: broadcast stuff
-        } catch(runtime_error&) {
-        }
-        break;
-      case 'O':
-        cout << "DO" << endl;
-        try {
-          dss::Zone& zone = dss::DSS::getInstance()->getApartment().getZone(m_pSlave->getZoneID());
-          dss::Group* group = zone.getGroup(dss::GroupIDBlue);
-          if(group != NULL) {
-            if(_buffer[6]) {
-              group->callScene(dss::SceneMax);
-            } else {
-              group->callScene(dss::SceneMin);
-            }
-          }
-        } catch(runtime_error&) {
-        }
-        break;
-      }
-    case 'K':
-      if(_buffer[1] == 'c') {
-        cout << "key" << endl;
-        onKeyPressed(_buffer[2]);
-      }
-      break;
-    case 'C':
-      cout << "********* function 'C' not yet implemented" << endl;
-    default:
-      cout << "\nfunction: " << _buffer[0] << endl;
-      break;
-    }
-  } // handlePacket
-
-  void onKeyPressed(char _key) {
-    try {
-
-      #define CT_TE    0
-      #define CT_1T    1
-      #define CT_2T    2
-      #define CT_3T    3
-      #define CT_1H    4
-      #define CT_2H    5
-      #define CT_3H    6
-      #define CT_1C    7
-      #define CT_2C    8
-      #define CT_1P    9
-      #define CT_UPDATE 10
-
-      const int KeyUp = 0x01;
-      const int KeyDown = 0x02;
-      const int KeyLeft = 0x03;
-      const int KeyRight = 0x04;
-      const int KeyMiddle = 0x05;
-      const int KeyColor = 0x0f;
-
-      int keyNumber = (_key >> 4) & 0x0f;
-      int clickType = _key & 0x0f;
-
-      cout << "key: " << keyNumber << " clickType:" << clickType << endl;
-
-      if(clickType == CT_TE) {
-        cout << "reset handle counter" << endl;
-        m_pSlave->setHandleCounter(0);
-        return;
-      }
-      if(keyNumber != KeyColor) {
-        if(m_pSlave->getSelectedColor() == dss::GroupIDGreen) {
-          if((clickType == CT_1T) || (clickType == CT_1C)) {
-            cout << "bell" << endl;
-            dss::DSS::getInstance()->getApartment().getDevices().callScene(dss::SceneBell);
-          }
-          return;
-        } else if(m_pSlave->getSelectedColor() == dss::GroupIDViolet) {
-          if((clickType == CT_1T) || (clickType == CT_1C)) {
-            cout << "alarm" << endl;
-            dss::DSS::getInstance()->getApartment().getDevices().callScene(dss::SceneAlarm);
-          }
-          return;
-        }
-      }
-
-      dss::Zone& zone = dss::DSS::getInstance()->getApartment().getZone(m_pSlave->getZoneID());
-      dss::Group* group = zone.getGroup(m_pSlave->getSelectedColor());
-      if(group == NULL) {
-        cout << "could not find group with id " << m_pSlave->getSelectedColor() << endl;
-      }
-
-      switch(keyNumber) {
-      case KeyUp:
-        cout << "up" << endl;
-        if(group != NULL) {
-          group->increaseValue();
-        }
-        break;
-      case KeyDown:
-        cout << "down" << endl;
-        if(group != NULL) {
-          group->decreaseValue();
-        }
-        break;
-      case KeyLeft:
-        cout << "left" << endl;
-        if(group != NULL) {
-          group->previousScene();
-        }
-        break;
-      case KeyRight:
-        cout << "right" << endl;
-        if(group != NULL) {
-          group->nextScene();
-        }
-        break;
-      case KeyMiddle:
-        cout << "middle" << endl;
-        if(group != NULL) {
-          if((clickType != CT_1H) && (clickType != CT_2H) && (clickType != CT_3H)) {
-            cout << "last scene: " << group->getLastCalledScene() << endl;
-            if(group->getLastCalledScene() == dss::SceneOff || group->getLastCalledScene() == dss::SceneDeepOff ||
-               group->getLastCalledScene() == dss::SceneStandBy || group->getLastCalledScene() == dss::ScenePanic ||
-               group->getLastCalledScene() == dss::SceneAlarm)
-            {
-              cout << "calling scene1" << endl;
-              group->callScene(dss::Scene1);
-            } else {
-              cout << "calling scene off" << endl;
-              group->callScene(dss::SceneOff);
-            }
-          } else {
-            cout << "//// Handlecounter before: " << m_pSlave->getHandleCounter() << endl;
-            m_pSlave->setHandleCounter(m_pSlave->getHandleCounter() + 1);
-            cout << "//// Handlecounter after:  " << m_pSlave->getHandleCounter() << endl;
-
-            // handle long presses
-            switch(m_pSlave->getHandleCounter()) {
-            case 2:
-              // turn off all devices in group
-              group->callScene(dss::SceneOff | dss::SceneFlagLocalOff);
-              m_pSlave->broadcastSignal(5, m_pSlave->getZoneID());
-              cout << "////////////////>>>>>>>>>>> calling scene off" << endl;
-              break;
-            case 6:
-              // turn off all devices in zone
-              zone.getGroup(0)->callScene(dss::SceneStandBy | dss::SceneFlagLocalOff);
-              cout << "////////////////>>>>>>>>>>> calling scene standby in group 0" << endl;
-              break;
-            case 10:
-              // apparently it's possible that this line needs to be active depending on who you're asking ;)
-              //dss::DSS::getInstance()->getApartment().getZone(0).callScene(dss::SceneDeepOff);
-
-              // turn off all devices in zone
-              zone.getGroup(0)->callScene(dss::SceneDeepOff);
-              cout << "////////////////>>>>>>>>>>> calling scene deep off on all devices" << endl;
-              break;
-            }
-          }
-        }
-        break;
-      case KeyColor:
-        m_pSlave->setSelectedColor(clickType);
-        cout << "new color: " << m_pSlave->getSelectedColor() << endl;
-        break;
-      }
-    } catch(runtime_error&) {
-      cerr << "exception" << endl;
-    }
-  } // onKeyPressed
-
-  void send(const char* _buf, const int _len) {
-    cout << "sending " << _len << " bytes" << endl;
-    cout << "first byte " << _buf[1] << endl;
-    socket().sendBytes(_buf, _len);
-  } // send
-
-};
-
-//=============================================== SensornestConnectionFactory
-
-class SensornestConnectionFactory : public TCPServerConnectionFactory {
-private:
-  SensornestServer* m_pServer;
-public:
-  SensornestConnectionFactory(SensornestServer* _pServer)
-  : m_pServer(_pServer)
-  { }
-
-  TCPServerConnection* createConnection(const StreamSocket& _socket) {
-    return new SensornestConnection(_socket, m_pServer);
-  }
-};
-
-
-//=============================================== SensornestServer
-
-SensornestServer::SensornestServer()
-: Thread("SensornestServer")
-{
-  m_Instance = this;
-}
-
-void SensornestServer::execute() {
-  SensornestDiscovery discovery;
-  discovery.run();
-  ServerSocket socket(3333);
-  TCPServer server(new SensornestConnectionFactory(this), socket);
-
-  cout << "Running SensornestServer Execute ..." << endl;
-
-  server.start();
-  while(!m_Terminated) {
-    sleep(1000);
-  }
-  server.stop();
-} // execute
-
-SensornestSlave* SensornestServer::getSensornestFor(const char* _mac) {
-  foreach(SensornestSlave* pSlave, m_Slaves) {
-    if(pSlave->hasMAC(_mac)) {
-      return pSlave;
-    }
-  }
-  return NULL;
-} // getSensornestFor
-
-void SensornestServer::onNewSlave(SensornestSlave* _pSlave) {
-  if(m_Instance != NULL) {
-    m_Instance->m_Slaves.push_back(_pSlave);
-    _pSlave->setServer(m_Instance);
-  }
-} // onNewSlave
-
-void SensornestServer::sendToAll(const char* _buf, const int _len, const int _zoneID) {
-  if(m_Instance != NULL) {
-    foreach(SensornestSlave* slave, m_Instance->m_Slaves) {
-      if((_zoneID == 0) || (_zoneID == -1) || (_zoneID == slave->getZoneID())) {
-        cout << "sending to slave" << endl;
-        slave->send(_buf, _len);
-      } else {
-        cout << "slave is not in zone " << _zoneID << endl;
-      }
-    }
-  } else {
-    cout << "m_Instance == NULL" << endl;
-  }
-} // sendToAll
-
-SensornestServer* SensornestServer::m_Instance = NULL;
-
-
-//=============================================== SensornestDiscovery
-
-#ifdef linux
-bool getMACAddress(const string& _interface, char* _buf, const int _bufLen)
-{
-    struct ifreq ifr;
-    int sock, j, k;
-    char *p, addr[32], mask[32], mac[32];
-    char ibuf[128];
-
-    sock=socket(PF_INET, SOCK_STREAM, 0);
-    if (-1==sock) {
-        perror("socket() ");
-        return 0;
-    }
-
-    strcpy(ibuf, _interface.c_str());
-    strncpy(ifr.ifr_name, ibuf, sizeof(ifr.ifr_name)-1);
-    ifr.ifr_name[sizeof(ifr.ifr_name)-1]='\0';
-
-    if (-1==ioctl(sock, SIOCGIFADDR, &ifr)) {
-        perror("ioctl(SIOCGIFADDR) ");
-        return 0;
-    }
-
-    p = inet_ntoa(((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr);
-    strncpy(addr, p, sizeof(addr)-1);
-    addr[sizeof(addr)-1]='\0';
-
-    if (-1==ioctl(sock, SIOCGIFNETMASK, &ifr)) {
-        perror("ioctl(SIOCGIFNETMASK) ");
-        return 0;
-    }
-
-    p = inet_ntoa(((struct sockaddr_in *)(&ifr.ifr_netmask))->sin_addr);
-    strncpy(mask,p,sizeof(mask)-1);
-    mask[sizeof(mask)-1]='\0';
-
-    if (-1==ioctl(sock, SIOCGIFHWADDR, &ifr)) {
-        perror("ioctl(SIOCGIFHWADDR) ");
-        return 0;
-    }
-
-    memcpy(_buf, ifr.ifr_hwaddr.sa_data, 6);
-    for (j=0, k=0; j<6; j++) {
-        k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X",
-            (int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]);
-    }
-    mac[sizeof(mac)-1]='\0';
-
-    printf("\n");
-    printf("name:    %s\n",ifr.ifr_name);
-    printf("address: %s\n",addr);
-    printf("netmask: %s\n",mask);
-    printf("macaddr: %s\n",mac);
-    printf("\n");
-
-    close(sock);
-    return 1;
-} // getMACAddress
-#endif
-
-#ifdef __APPLE__
-bool getMACAddress(const string& _interface, char* _buf, const int _bufLen) {
-  struct ifaddrs *pIfAddrs = NULL;
-  if(getifaddrs(&pIfAddrs) == 0) {
-    struct ifaddrs* pCurrent = pIfAddrs;
-    while(pCurrent != NULL) {
-      cout << pCurrent->ifa_name << endl;
-      if(!((pCurrent->ifa_flags & IFF_LOOPBACK) == IFF_LOOPBACK)) {
-        if(_interface.empty() || _interface == pCurrent->ifa_name) {
-          bcopy(pCurrent->ifa_addr, _buf, 6);
-          freeifaddrs(pIfAddrs);
-          return true;
-        }
-      }
-      pCurrent = pCurrent->ifa_next;
-    }
-  }
-  freeifaddrs(pIfAddrs);
-  return false;
-}
-#endif
-
-void SensornestDiscovery::execute() {
-  Poco::Net::SocketAddress bindAddr("0.0.0.0", 3333);
-  Poco::Net::DatagramSocket socket;
-
-  char receiveBuffer[256];
-  socket.bind(bindAddr);
-
-  string intf = dss::DSS::getInstance()->getPropertySystem().getStringValue("/config/sensornest/interface");
-  if(intf.empty()) {
-#ifdef linux
-    intf = "eth0";
-#else
-    intf = "en0";
-#endif
-  }
-
-  char macAddr[6];
-  if(!getMACAddress(intf, macAddr, sizeof(macAddr))) {
-    cerr << "Could not get MAC address" << endl;
-    return;
-  }
-
-  cout << "Running SensornestDiscovery Execute ..." << endl;
-
-  while(!m_Terminated) {
-    Poco::Net::SocketAddress addr("0.0.0.0", 3333);
-    int len = socket.receiveFrom(receiveBuffer, sizeof(receiveBuffer), addr);
-    cout << "\n" << addr.host().toString() << endl;
-    cout << "\nlen:" << len << endl;
-    for(int iByte = 0; iByte < len; iByte++) {
-      cout << " " << hex << ((int)receiveBuffer[iByte] & 0x00ff) << dec;
-      flush(cout);
-    }
-    if(len > 7) {
-      if(receiveBuffer[0] != 'M') {
-        continue;
-      }
-      switch(receiveBuffer[7]) {
-      case '?':
-        cout << "?" << endl;
-        if(memcmp(macAddr, &receiveBuffer[0] + 8, 6) == 0) {
-          cout << "For me" << endl;
-          receiveBuffer[8] = receiveBuffer[1];
-          receiveBuffer[9] = receiveBuffer[2];
-          receiveBuffer[10] = receiveBuffer[3];
-          receiveBuffer[11] = receiveBuffer[4];
-          receiveBuffer[12] = receiveBuffer[5];
-          receiveBuffer[13] = receiveBuffer[6];
-
-          receiveBuffer[0] = 'M';
-          receiveBuffer[1] = macAddr[0];
-          receiveBuffer[2] = macAddr[1];
-          receiveBuffer[3] = macAddr[2];
-          receiveBuffer[4] = macAddr[3];
-          receiveBuffer[5] = macAddr[4];
-          receiveBuffer[6] = macAddr[5];
-          receiveBuffer[7] = '!';
-
-          socket.sendTo(receiveBuffer, 14, addr);
-        }
-        break;
-      case '$':
-        cout << "$" << endl;
-        if(receiveBuffer[8] == 'H') {
-          cout << "H" << endl;
-          receiveBuffer[8] = receiveBuffer[1];
-          receiveBuffer[9] = receiveBuffer[2];
-          receiveBuffer[10] = receiveBuffer[3];
-          receiveBuffer[11] = receiveBuffer[4];
-          receiveBuffer[12] = receiveBuffer[5];
-          receiveBuffer[13] = receiveBuffer[6];
-
-          receiveBuffer[0] = 'M';
-          receiveBuffer[1] = macAddr[0];
-          receiveBuffer[2] = macAddr[1];
-          receiveBuffer[3] = macAddr[2];
-          receiveBuffer[4] = macAddr[3];
-          receiveBuffer[5] = macAddr[4];
-          receiveBuffer[6] = macAddr[5];
-          receiveBuffer[7] = '&';
-          receiveBuffer[14] = 'd';
-          receiveBuffer[15] = 'S';
-          receiveBuffer[16] = 'S';
-          receiveBuffer[17] = 'L';
-          receiveBuffer[18] = 0;
-
-          socket.sendTo(receiveBuffer, 19, addr);
-        }
-        break;
-      }
-    }
-  }
-} // execute
-
-//=============================================== SensornestSlave
-
-void SensornestSlave::setMAC(const char* _pMAC) {
-  memcpy(m_MAC, _pMAC, 6);
-} // setMAC
-
-bool SensornestSlave::hasMAC(const char* _pMAC) {
-  return memcmp(_pMAC, m_MAC, 6) == 0;
-} // hasMAC
-
-void SensornestSlave::initialize() {
-  DSIDSim::initialize();
-  string macString = getConfigParameter("mac");
-  if(!macString.empty()) {
-    std::vector<string> bytes = dss::splitString(macString, ':', true);
-    int iByte = 0;
-    cout << "\ngot MAC: ";
-    foreach(string byte, bytes) {
-      m_MAC[iByte++] = dss::strToInt("0x" + byte);
-      cout << hex << ((int)m_MAC[iByte-1] & 0x00ff) << dec;
-    }
-    cout << endl;
-  }
-} // initialize
-
-void SensornestSlave::callScene(const int _sceneNr) {
-  cout << "SensornestSlave::callScene(" << _sceneNr << ")" << endl;
-  if(_sceneNr == dss::SceneBell) {
-    broadcastSignal(1,0);
-    cout << "scene bell" << endl;
-  } else if(_sceneNr == dss::SceneAlarm) {
-    broadcastGroupState(dss::GroupIDYellow, 1, 0);
-    broadcastGroupState(dss::GroupIDCyan, 0, 0);
-    broadcastSignal(2,0);
-    cout << "scene alarm" << endl;
-  } else if(_sceneNr == dss::ScenePanic) {
-    broadcastGroupState(dss::GroupIDYellow, 1, 0);
-    broadcastGroupState(dss::GroupIDCyan, 0, 0);
-    cout << "scene panic" << endl;
-  } else if(_sceneNr == 45) {
-    broadcastPower(4, getZoneID());
-    cout << "scene == 45" << endl;
-  } else if(_sceneNr == 46) {
-    broadcastPower(6, getZoneID());
-    cout << "scene == 46" << endl;
-  } else if(_sceneNr == 47) {
-    broadcastPower(2, getZoneID());
-    cout << "scene == 47" << endl;
-  } else if(_sceneNr == dss::SceneStandBy || _sceneNr == dss::SceneDeepOff) {
-    broadcastOffScene(_sceneNr, getZoneID());
-    broadcastSignal(5, getZoneID());
-        cout << "broacast" << endl;
-  } else if(_sceneNr < 5) {
-    cout << "scene < 5" << endl;
-    broadcastGroupState(m_SelectedColor, 0, getZoneID());
-  } else if(_sceneNr < 32) {
-    cout << "Scene < 32" << endl;
-    broadcastGroupState(m_SelectedColor, 1, getZoneID());
-  } else {
-    cout << "&&&&&&&&&&&&&& no action" << endl;
-  }
-} // callScene
-
-void SensornestSlave::send(const char* _buf, const int _len) {
-  if(m_pConnection != NULL) {
-    m_pConnection->send(_buf, _len);
-  }
-} // send
-
-void SensornestSlave::broadcastSignal(const int _signal, const int _zoneID) {
-    char message[5];
-    message[0] = 3;
-    message[1] = 'B';
-    message[2] = 's';
-    message[3] = _signal;
-    SensornestServer::sendToAll(message, 4, _zoneID);
-} // broadcastSignal
-
-void SensornestSlave::broadcastGroupState(const int _groupID, const int _state, const int _zoneID) {
-    char message[5];
-    message[0] = 4;
-    message[1] = 'E';
-    message[2] = 'g';
-    message[3] = _groupID;
-    message[4] = _state;
-    SensornestServer::sendToAll(message, 5, _zoneID);
-} // broadcastGroupState
-
-void SensornestSlave::broadcastPower(const int _color, const int _zoneID) {
-    char message[5];
-    message[0] = 3;
-    message[1] = 'B';
-    message[2] = 'p';
-    message[3] = _color;
-    SensornestServer::sendToAll(message, 4, _zoneID);
-} // broadcastPower
-
-void SensornestSlave::broadcastOffScene(const int _sceneID, const int _zoneID) {
-    char message[5];
-    message[0] = 3;
-    message[1] = 'E';
-    message[2] = 'o';
-    message[3] = _sceneID;
-    SensornestServer::sendToAll(message, 4, _zoneID);
-} // broadcastOffScene
-
-dss::DSIDInterface* DSIDSimSensornestCreator::createDSID(const dss::dsid_t _dsid, const dss::devid_t _shortAddress, const dss::DSModulatorSim& _modulator) {
-  SensornestSlave* slave = new SensornestSlave(_modulator, _dsid, _shortAddress);
-  SensornestServer::onNewSlave(slave);
-  cout << "New Sensornest: " << _shortAddress << endl;
-  return slave;
-} // createDSID
-

Deleted: dss/branches/0.5/external/slaves/sensornest.h
===================================================================
--- dss/branches/0.5/external/slaves/sensornest.h	2009-10-06 08:06:15 UTC (rev 8823)
+++ dss/branches/0.5/external/slaves/sensornest.h	2009-10-06 08:34:27 UTC (rev 8824)
@@ -1,101 +0,0 @@
-/*
-    Copyright (c) 2009 digitalSTROM.org, Zurich, Switzerland
-    Copyright (c) 2009 futureLAB AG, Winterthur, Switzerland
-
-    This file is part of digitalSTROM Server.
-
-    digitalSTROM Server 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.
-
-    digitalSTROM Server 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 digitalSTROM Server. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef SENSORNEST_H_
-#define SENSORNEST_H_
-
-#include "core/thread.h"
-#include "core/sim/dssim.h"
-#include "core/sim/dsidsim.h"
-
-class SensornestServer;
-class SensornestConnection;
-
-class SensornestSlave : public dss::DSIDSim {
-private:
-  int m_SelectedColor;
-  int m_HandleCounter;
-  SensornestServer* m_pServer;
-  SensornestConnection* m_pConnection;
-  char m_MAC[6];
-public:
-  SensornestSlave(const dss::DSModulatorSim& _simulator, const dss::dsid_t _dsid, const dss::devid_t _shortAddress)
-  : DSIDSim(_simulator, _dsid, _shortAddress),
-    m_SelectedColor(1),
-    m_HandleCounter(0),
-    m_pServer(NULL),
-    m_pConnection(NULL)
-  { }
-
-  void setSelectedColor(const int _value) { m_SelectedColor = _value; }
-  int getSelectedColor() const { return m_SelectedColor; }
-
-  void setHandleCounter(const int _value) { m_HandleCounter = _value; }
-  int getHandleCounter() const { return m_HandleCounter; }
-
-  void setMAC(const char* _pMAC);
-  bool hasMAC(const char* _pMAC);
-
-  virtual void initialize();
-  virtual void callScene(const int _sceneNr);
-
-  void setServer(SensornestServer* _value) { m_pServer = _value; }
-  void setConnection(SensornestConnection* _value) { m_pConnection = _value; }
-
-  void send(const char* _buf, const int _len);
-
-  void broadcastSignal(const int _signal, const int _zoneID);
-  void broadcastGroupState(const int _groupID, const int _state, const int _zoneID);
-  void broadcastPower(const int _color, const int _zoneID);
-  void broadcastOffScene(const int _sceneID, const int _zoneID);
-}; // SensornestSlave
-
-class SensornestServer : public dss::Thread {
-private:
-  static SensornestServer* m_Instance;
-  std::vector<SensornestSlave*> m_Slaves;
-public:
-  SensornestServer();
-  virtual void execute();
-  SensornestSlave* getSensornestFor(const char* _mac);
-  static void onNewSlave(SensornestSlave* _pSlave);
-
-  static void sendToAll(const char* _buf, const int _len, const int _zoneID);
-}; // SensornestServer
-
-class SensornestDiscovery : public dss::Thread {
-public:
-  virtual void execute();
-}; // SensornestSlave
-
-class DSIDSimSensornestCreator : public dss::DSIDCreator {
-public:
-  DSIDSimSensornestCreator()
-  : dss::DSIDCreator("aizo.sensornest")
-  {}
-
-  virtual ~DSIDSimSensornestCreator() {};
-
-  virtual dss::DSIDInterface* createDSID(const dss::dsid_t _dsid, const dss::devid_t _shortAddress, const dss::DSModulatorSim& _modulator);
-};
-
-
-#endif /* SENSORNEST_H_ */



More information about the dss-commits mailing list