Package org.openhab.binding.nibeheatpump.protocol

Examples of org.openhab.binding.nibeheatpump.protocol.NibeHeatPumpConnector


    @Override
    public void run() {
      logger.debug("Nibe heatpump message listener started");

      NibeHeatPumpConnector connector;
     
      if (simulateHeatPump == true) {
        connector = new NibeHeatPumpSimulator();
      } else if (serialPort != null) {
        connector = new NibeHeatPumpSerialConnector(serialPort);
      } else {
        connector = new NibeHeatPumpUDPConnector(udpPort);
      }
     
      try {
        connector.connect();
      } catch (NibeHeatPumpException e) {
        logger.error("Error occured when connecting to heat pump", e);
       
        logger.warn("Closing Nibe heatpump message listener");

        // exit
        interrupted = true;
      }

      // as long as no interrupt is requested, continue running
      while (!interrupted) {
        try {
          // Wait a packet (blocking)
          byte[] data = connector.receiveDatagram();

          logger.debug("Received data (len={}): {}", data.length, DatatypeConverter.printHexBinary(data));

          Hashtable<Integer, Short> regValues = NibeHeatPumpDataParser.ParseData(data);

          if (regValues != null) {

            Enumeration<Integer> keys = regValues.keys();

            while (keys.hasMoreElements()) {

              int key = keys.nextElement();
              double value = regValues.get(key);

              VariableInformation variableInfo = NibeHeatPumpDataParser.VARIABLE_INFO_F1145_F1245
                  .get(key);

              if (variableInfo == null) {
                logger.debug("Unknown variable {}", key);
              } else {
                value = value / variableInfo.factor;
                org.openhab.core.types.State state = convertNibeValueToState(
                    variableInfo.dataType, value);

                logger.debug("{}={}", key + ":"
                    + variableInfo.variable, value);

                for (NibeHeatPumpBindingProvider provider : providers) {
                  for (String itemName : provider
                      .getItemNames()) {
                    int itemId = provider
                        .getItemId(itemName);
                    if (key == itemId) {
                      eventPublisher.postUpdate(itemName,
                          state);
                    }
                  }
                }
              }
            }

          }
        } catch (NibeHeatPumpException e) {
          logger.error("Error occured when received data from heat pump", e);
        }
      }
     
      try {
        connector.disconnect();
      } catch (NibeHeatPumpException e) {
        logger.error("Error occured when disconnecting form heat pump", e);
      }
    }
View Full Code Here

TOP

Related Classes of org.openhab.binding.nibeheatpump.protocol.NibeHeatPumpConnector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.