Examples of ProtocolBindingProvider


Examples of org.openhab.binding.tcp.protocol.ProtocolBindingProvider

  @Override
  protected boolean internalReceiveChanneledCommand(String itemName,
      Command command, Channel sChannel, String commandAsString) {

    ProtocolBindingProvider provider = findFirstMatchingBindingProvider(itemName);

    if(command != null ){   
     
      String transformedMessage = transformResponse(provider.getProtocolCommand(itemName, command),commandAsString);
      String tcpCommandName = preAmble + transformedMessage + postAmble ;

      ByteBuffer outputBuffer = null;
      try {
        outputBuffer = ByteBuffer.allocate(tcpCommandName.getBytes(charset).length);
        outputBuffer.put(tcpCommandName.getBytes(charset));
      } catch (UnsupportedEncodingException e) {
        logger.warn("Exception while attempting an unsupported encoding scheme");
      }

      // send the buffer in an asynchronous way
      ByteBuffer result = null;
      try {
        result = writeBuffer(outputBuffer,sChannel,blocking,timeOut);
      } catch (Exception e) {
        logger.error("An exception occurred while writing a buffer to a channel: {}",e.getMessage());
      }

      if(result!=null && blocking) {
        String resultString = "";
        try {
          resultString = new String(result.array(), charset).split("\0")[0];
        } catch (UnsupportedEncodingException e) {
          logger.warn("Exception while attempting an unsupported encoding scheme");
        }
       
        logger.info("Received {} from the remote end {}", resultString, sChannel.toString());
        String transformedResponse = transformResponse(provider.getProtocolCommand(itemName, command), resultString);

        // if the remote-end does not send a reply in response to the string we just sent, then the abstract superclass will update
        // the openhab status of the item for us. If it does reply, then an additional update is done via parseBuffer.
        // since this TCP binding does not know about the specific protocol, there might be two state updates (the command, and if
        // the case, the reply from the remote-end)

        if(updateWithResponse) {

          List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName,command);
          State newState = createStateFromString(stateTypeList,transformedResponse);

          if(newState != null) {
            eventPublisher.postUpdate(itemName, newState);                               
          } else {
View Full Code Here

Examples of org.openhab.binding.tcp.protocol.ProtocolBindingProvider

      theUpdate = new String(byteBuffer.array(), charset).split("\0")[0];
    } catch (UnsupportedEncodingException e) {
      logger.warn("Exception while attempting an unsupported encoding scheme");
    }

    ProtocolBindingProvider provider = findFirstMatchingBindingProvider(itemName);

    List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName,aCommand);
   
    String transformedResponse = transformResponse(provider.getProtocolCommand(itemName, aCommand),theUpdate);
    State newState = createStateFromString(stateTypeList,transformedResponse);

    if(newState != null) {
      eventPublisher.postUpdate(itemName, newState);                                 
    } else {
View Full Code Here

Examples of org.openhab.binding.tcp.protocol.ProtocolBindingProvider

  @Override
  protected boolean internalReceiveChanneledCommand(String itemName,
      Command command, Channel sChannel, String commandAsString) {

    ProtocolBindingProvider provider = findFirstMatchingBindingProvider(itemName);

    if(command != null ){   
     
      String transformedMessage = transformResponse(provider.getProtocolCommand(itemName, command),commandAsString);
      String UDPCommandName = preAmble + transformedMessage + postAmble ;

      ByteBuffer outputBuffer = null;
      try {
        outputBuffer = ByteBuffer.allocate(UDPCommandName.getBytes(charset).length);
        outputBuffer.put(UDPCommandName.getBytes(charset));
      } catch (UnsupportedEncodingException e) {
        logger.warn("Exception while attempting an unsupported encoding scheme");
      }

      // send the buffer in an asynchronous way
      ByteBuffer result = null;
      try {
        result = writeBuffer(outputBuffer,sChannel,blocking,timeOut);
      } catch (Exception e) {
        logger.error("An exception occurred while writing a buffer to a channel: {}",e.getMessage());
      }

      if(result!=null && blocking) {
        String resultString = "";
        try {
          resultString = new String(result.array(), charset);
        } catch (UnsupportedEncodingException e) {
          logger.warn("Exception while attempting an unsupported encoding scheme");
        }
       
        logger.info("Received {} from the remote end {}", resultString, sChannel.toString());
        String transformedResponse = transformResponse(provider.getProtocolCommand(itemName, command), resultString);

        // if the remote-end does not send a reply in response to the string we just sent, then the abstract superclass will update
        // the openhab status of the item for us. If it does reply, then an additional update is done via parseBuffer.
        // since this TCP binding does not know about the specific protocol, there might be two state updates (the command, and if
        // the case, the reply from the remote-end)

        if(updateWithResponse) {

          List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName,command);
          State newState = createStateFromString(stateTypeList,transformedResponse);

          if(newState != null) {
            eventPublisher.postUpdate(itemName, newState);                               
          } else {
View Full Code Here

Examples of org.openhab.binding.tcp.protocol.ProtocolBindingProvider

      theUpdate = new String(byteBuffer.array(), charset);
    } catch (UnsupportedEncodingException e) {
      logger.warn("Exception while attempting an unsupported encoding scheme");
    }
   
    ProtocolBindingProvider provider = findFirstMatchingBindingProvider(itemName);

    List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName,aCommand);

    String transformedResponse = transformResponse(provider.getProtocolCommand(itemName, aCommand),theUpdate);
    State newState = createStateFromString(stateTypeList,transformedResponse);

    if(newState != null) {
      eventPublisher.postUpdate(itemName, newState);                                 
    } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.