All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tuwien.auto.calimero.tools.PropClient Maven / Gradle / Ivy

There is a newer version: 2.6-rc1
Show newest version
/*
    Calimero 2 - A library for KNX network access
    Copyright (c) 2006, 2018 B. Malinowsky

    This program 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 2 of the License, or
    (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Linking this library statically or dynamically with other modules is
    making a combined work based on this library. Thus, the terms and
    conditions of the GNU General Public License cover the whole
    combination.

    As a special exception, the copyright holders of this library give you
    permission to link this library with independent modules to produce an
    executable, regardless of the license terms of these independent
    modules, and to copy and distribute the resulting executable under terms
    of your choice, provided that you also meet, for each linked independent
    module, the terms and conditions of the license of that module. An
    independent module is a module which is not derived from or based on
    this library. If you modify this library, you may extend this exception
    to your version of the library, but you are not obligated to do so. If
    you do not wish to do so, delete this exception statement from your
    version.
*/

package tuwien.auto.calimero.tools;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.nio.charset.Charset;

import tuwien.auto.calimero.KNXIllegalArgumentException;
import tuwien.auto.calimero.log.LogService;
import tuwien.auto.calimero.mgmt.PropertyAdapter;
import tuwien.auto.calimero.mgmt.PropertyClient;

/**
 * A tool for Calimero showing features of the {@link PropertyClient} used for KNX property access.
 * 

* PropClient is a console based tool implementation for reading and writing KNX properties. It * supports network access using a KNXnet/IP, USB, or FT1.2 connection. To start the PropClient, * invoke the main-method of this class. Take a look at the command line options to * configure the tool with the desired communication settings. *

* The main part of this tool implementation interacts with the PropertyClient interface, which * offers high level access to KNX property information. It also shows creation of the * {@link PropertyAdapter}, necessary for a property client to work. All queried property values, as * well as occurring problems are written to System.out * . * * @author B. Malinowsky */ public class PropClient implements Runnable { class PropertyEx extends tuwien.auto.calimero.tools.Property { PropertyEx(final String[] args) { super(args); } @Override protected void runCommand(final String... cmd) throws InterruptedException { // ignore any command supplied on command line options.remove("command"); // show some command info super.runCommand("?"); out("exit - close connection and exit"); runReaderLoop(PropClient.this); } private void runReaderLoop(final PropClient propClient) { // create reader for user input final BufferedReader r = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset())); String[] args; try { while ((args = propClient.readLine(r)) != null) { if (args.length > 0 && !(args.length == 1 && args[0].isEmpty())) { if ("exit".equalsIgnoreCase(args[0])) break; super.runCommand(args); } } } catch (InterruptedException | InterruptedIOException e) { System.out.println("received interrupt, closing ..."); } catch (final IOException e) { System.out.println("I/O error, " + e.getMessage()); } } } private final PropertyEx property; /** * Constructs a new PropClient. *

* * @param args options for the property client tool, see {@link #main(String[])} * @throws KNXIllegalArgumentException on missing or wrong formatted option value */ public PropClient(final String[] args) { property = new PropertyEx(args); } /** * Entry point for running the PropClient. *

* An IP host or port identifier has to be supplied to specify the endpoint for the KNX network * access.
* To show the usage message of this tool on the console, supply the command line option -help * (or -h).
* Command line options are treated case sensitive. Available options for the property client: *

    *
  • --help -h show help message
  • *
  • --version show tool/library version and exit
  • *
  • --verbose -v enable verbose status output
  • *
  • --local -l local device management
  • *
  • --remote -r KNX addr  remote property service
  • *
  • --definitions -d file  use property definition file
  • *
  • --localhost id  local IP/host name
  • *
  • --localport number  local UDP port (default system assigned)
  • *
  • --port -p number  UDP port on host (default 3671)
  • *
  • --nat -n enable Network Address Translation
  • *
  • --ft12 -f use FT1.2 serial communication
  • *
  • --usb -u use KNX USB communication
  • *
  • --tpuart use TP-UART communication
  • *
* For local device management these options are available: *
    *
  • --emulatewriteenable -e check write-enable of a property
  • *
* For remote property service these options are available: *
    *
  • --medium -m id  KNX medium [tp1|p110|knxip|rf] (defaults to tp1)
  • *
  • --domain address  domain address on open KNX medium (PL or RF)
  • *
  • --connect -c connection oriented mode
  • *
  • --authorize -a key  authorize key to access KNX device
  • *
* * @param args command line options for property client */ public static void main(final String[] args) { Property.out = LogService.getLogger("calimero.tools"); try { final PropClient pc = new PropClient(args); pc.run(); } catch (final Throwable t) { Property.out.error("client error", t); } } @Override public void run() { property.run(); } /** * Writes command prompt and waits for a command request from the user. *

* * @param r input reader * @return array with command and command arguments * @throws IOException on I/O error * @throws InterruptedException on interrupted thread */ private String[] readLine(final BufferedReader r) throws IOException, InterruptedException { System.out.print("> "); synchronized (this) { while (!r.ready()) wait(100); } final String line = r.readLine(); return line != null ? line.trim().split("\\s") : null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy