Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bmalinowsky committed Feb 9, 2024
1 parent eafbd44 commit 8b4f420
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 73 deletions.
8 changes: 3 additions & 5 deletions src/io/calimero/tools/BaosClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Calimero 2 - A library for KNX network access
Copyright (c) 2019, 2023 B. Malinowsky
Copyright (c) 2019, 2024 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
Expand Down Expand Up @@ -515,14 +515,12 @@ private static String fromDptName(final String id) {
case "blinds" -> "3.008";
case "string" -> "16.001";
case "temp" -> "9.001";
case "float" -> "9.002";
case "float2" -> "9.002";
case "float", "float2" -> "9.002";
case "float4" -> "14.005";
case "ucount" -> "5.010";
case "int" -> "13.001";
case "angle" -> "5.003";
case "percent" -> "5.001";
case "%" -> "5.001";
case "percent", "%" -> "5.001";
default -> {
if (!"-".equals(id) && !Character.isDigit(id.charAt(0)))
throw new KnxRuntimeException("unrecognized DPT '" + id + "'");
Expand Down
9 changes: 6 additions & 3 deletions src/io/calimero/tools/DatapointImporter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Calimero 2 - A library for KNX network access
Copyright (c) 2019, 2023 B. Malinowsky
Copyright (c) 2019, 2024 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
Expand Down Expand Up @@ -144,8 +144,11 @@ private XmlWriter createXmlWriter() {
}

private void importAddressesFromCsv(final String file) throws IOException {
Files.lines(Path.of(file), StandardCharsets.UTF_8).map(line -> line.split("\"[\t;]\""))
.map(DatapointImporter::parseDatapoint).flatMap(Optional::stream).forEach(datapoints::add);
try (var lines = Files.lines(Path.of(file), StandardCharsets.UTF_8)) {
lines.map(line -> line.split("\"[\t;]\""))
.map(DatapointImporter::parseDatapoint)
.flatMap(Optional::stream).forEach(datapoints::add);
}
}

private void importAddressesFromXml(final String uri) {
Expand Down
42 changes: 21 additions & 21 deletions src/io/calimero/tools/DeviceInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Calimero 2 - A library for KNX network access
Copyright (c) 2011, 2023 B. Malinowsky
Copyright (c) 2011, 2024 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
Expand Down Expand Up @@ -799,9 +799,8 @@ private static String supportedCommModes(final byte[] commModes) {
final boolean raw = (modes & 0x04) == 0x04;
final boolean bm = (modes & 0x02) == 0x02;
final boolean dll = (modes & 0x01) == 0x01;
final String s = "Transport layer local " + tll + ", Data link layer modes: normal " + dll + ", busmonitor "
return "Transport layer local " + tll + ", Data link layer modes: normal " + dll + ", busmonitor "
+ bm + ", raw mode " + raw;
return s;
}

private static String commMode(final byte[] data) {
Expand Down Expand Up @@ -983,7 +982,7 @@ private void readPL110Bcu1() throws InterruptedException
{
final int addrDoA = 0x0102; // length 2

readMem(addrDoA, 2, "DoA ", true, CommonParameter.DomainAddress);
readMem(addrDoA, 2, true, CommonParameter.DomainAddress);
readBcuInfo(true);
}

Expand All @@ -996,7 +995,7 @@ private void readTP1Bcu1() throws InterruptedException
// final int addrConfigDesc = 0x0110;
// final int addrAssocTablePtr = 0x0111;

readMem(addrManufactData, 3, "KNX manufacturer data ", true, CommonParameter.ManufacturerData);
readMem(addrManufactData, 3, true, CommonParameter.ManufacturerData);

readBcuInfo(true);
}
Expand All @@ -1017,7 +1016,7 @@ private void readTP1Bcu2() throws InterruptedException {
// final int addrPeiInterface = 0x00c4; // if used
// final int addrPeiInfo = 0x00c5; // if used

readMem(addrManufacturer, 2, "KNX manufacturer ", Main::manufacturer, CommonParameter.Manufacturer);
readMem(addrManufacturer, 2, Main::manufacturer, CommonParameter.Manufacturer);
final long appId = readMemLong(addrAppId, 5);
final String appMf = manufacturer((int) appId >> (3 * 8));
final long swDev = (appId >> 8) & 0xff;
Expand All @@ -1035,21 +1034,21 @@ private void readTP1Bcu2() throws InterruptedException {
private void readBcuInfo(final boolean bcu1) throws InterruptedException
{
if (bcu1) {
readMem(addrManufact, 1, "KNX manufacturer ", Main::manufacturer, CommonParameter.Manufacturer);
readMem(addrDevType, 2, "Device type number ", true, CommonParameter.DeviceTypeNumber);
readMem(addrManufact, 1, Main::manufacturer, CommonParameter.Manufacturer);
readMem(addrDevType, 2, true, CommonParameter.DeviceTypeNumber);
}
readMem(addrVersion, 1, "SW version ", i -> version(new byte[] { (byte) (int) i }), CommonParameter.SoftwareVersion);
readMem(addrVersion, 1, i -> version(new byte[] { (byte) (int) i }), CommonParameter.SoftwareVersion);
// mechanical PEI type required by the application SW
readMem(addrPeiType, 1, "Hardware PEI type ", DeviceInfo::toPeiTypeString, CommonParameter.RequiredPeiType);
readMem(addrRunError, 1, "Run error 0x", DeviceInfo::decodeRunError, CommonParameter.RunError);
readMem(addrPeiType, 1, DeviceInfo::toPeiTypeString, CommonParameter.RequiredPeiType);
readMem(addrRunError, 1, DeviceInfo::decodeRunError, CommonParameter.RunError);

readSystemState();

readMem(addrRoutingCnt, 1, "Routing count ", v -> Integer.toString((v >> 4) & 0x7),
readMem(addrRoutingCnt, 1, v -> Integer.toString((v >> 4) & 0x7),
CommonParameter.RoutingCount);
// realization type 1
// Location of group object table
readMem(addrGroupObjTablePtr, 1, "Group object table location ", true, CommonParameter.GroupObjTableLocation);
readMem(addrGroupObjTablePtr, 1, true, CommonParameter.GroupObjTableLocation);
readGroupAddresses();

// Location of user program 0x100 + progptr
Expand Down Expand Up @@ -1086,13 +1085,13 @@ else if (ifObjects.containsKey(addresstableObject)) {

// realization type 1
final int lengthSize = isSystemB ? 2 : 1;
final int entries = readMem(memLocation, lengthSize, "Group address table entries ", false,
final int entries = readMem(memLocation, lengthSize, false,
CommonParameter.GroupAddressTableEntries);

int startAddr = memLocation + lengthSize;
if (!isSystemB && entries > 0) {
// address of device address
readMem(startAddr, 2, "", v -> new IndividualAddress(v & 0x7fff).toString(), CommonParameter.DeviceAddress);
readMem(startAddr, 2, v -> new IndividualAddress(v & 0x7fff).toString(), CommonParameter.DeviceAddress);
startAddr += 2;
}

Expand Down Expand Up @@ -1222,12 +1221,13 @@ private Optional<byte[]> readFunctionPropertyState(final Parameter p, final int
}

private byte[] readFunctionPropertyState(final Parameter p, final int objectType, final int propertyId,
final int service, final byte... info) throws InterruptedException {
final int service, final byte... info) throws InterruptedException {
if (mc == null)
return null;

final int oinstance = 1;
out.log(DEBUG, "read function property state {0}({1})|{2} service {3}", objectType, oinstance, propertyId, service);
out.log(DEBUG, "read {0} function property state {1}({2})|{3} service {4}", p.friendlyName(), objectType,
oinstance, propertyId, service);
try {
return mc.readFunctionPropertyState(d, objectType, oinstance, propertyId, service, info);
}
Expand Down Expand Up @@ -1331,8 +1331,8 @@ private void readUnsigned(final int objectIndex, final int pid, final boolean he
}
}

private int readMem(final int startAddr, final int bytes, final String prefix, final boolean hex, final Parameter p)
throws InterruptedException
private int readMem(final int startAddr, final int bytes, final boolean hex, final Parameter p)
throws InterruptedException
{
out.log(DEBUG, "read 0x{0}..0x{1} {2}", Long.toHexString(startAddr), Long.toHexString(startAddr + bytes), p.friendlyName());
final long v = readMemLong(startAddr, bytes);
Expand All @@ -1341,8 +1341,8 @@ private int readMem(final int startAddr, final int bytes, final String prefix, f
return (int) v;
}

private void readMem(final int startAddr, final int bytes, final String prefix,
final Function<Integer, String> representation, final Parameter p) throws InterruptedException
private void readMem(final int startAddr, final int bytes, final Function<Integer, String> representation,
final Parameter p) throws InterruptedException
{
final int v = readMem(startAddr, bytes);
putResult(p, representation.apply(v), v);
Expand Down
11 changes: 4 additions & 7 deletions src/io/calimero/tools/Discover.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Calimero 2 - A library for KNX network access
Copyright (c) 2006, 2023 B. Malinowsky
Copyright (c) 2006, 2024 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
Expand Down Expand Up @@ -102,7 +102,7 @@
public class Discover implements Runnable
{
private static final String tool = "Discover";
private static final String sep = System.getProperty("line.separator");
private static final String sep = System.lineSeparator();

private static final Logger out = LogService.getLogger(Discoverer.LOG_SERVICE);

Expand All @@ -116,11 +116,8 @@ public class Discover implements Runnable
* Creates a new Discover instance using the supplied options; see {@link #main(String[])} for a list of options.
*
* @param args list with options
* @throws KNXException on instantiation problems
* @throws KNXIllegalArgumentException on unknown/invalid options
*/
public Discover(final String[] args) throws KNXException
{
public Discover(final String[] args) {
// read in user-supplied command line options
try {
parseOptions(args);
Expand Down Expand Up @@ -323,7 +320,7 @@ private static String formatResponse(final Result<?> r, final HPAI controlEp, fi

String basic = sb.toString().replaceAll(", ", sep);
if (serviceFamilies != null)
basic += "Supported services: " + serviceFamilies.toString();
basic += "Supported services: " + serviceFamilies;

final var joiner = new StringJoiner(sep);
joiner.add(basic);
Expand Down
10 changes: 5 additions & 5 deletions src/io/calimero/tools/IPConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class IPConfig implements Runnable
{
private static final String tool = "IPConfig";

private static final String sep = System.getProperty("line.separator");
private static final String sep = System.lineSeparator();
private static final int IPObjType = 11;

private static final Logger out = LogService.getLogger("io.calimero.tools");
Expand Down Expand Up @@ -407,11 +407,11 @@ private static String getIPAssignment(final byte[] value)
if ((bitset & 0x01) != 0)
s = "manual";
if ((bitset & 0x02) != 0)
s += (s.length() == 0 ? "" : div) + "Bootstrap Protocol";
s += (s.isEmpty() ? "" : div) + "Bootstrap Protocol";
if ((bitset & 0x04) != 0)
s += (s.length() == 0 ? "" : div) + "DHCP";
s += (s.isEmpty() ? "" : div) + "DHCP";
if ((bitset & 0x08) != 0)
s += (s.length() == 0 ? "" : div) + "Auto IP";
s += (s.isEmpty() ? "" : div) + "Auto IP";
return s;
}

Expand Down Expand Up @@ -485,7 +485,7 @@ private void parseOptions(final String[] args)
// remove empty arguments
final List<String> l = new ArrayList<>(Arrays.asList(args));
l.removeAll(List.of(""));
if (l.size() == 0)
if (l.isEmpty())
return;

// add defaults
Expand Down
13 changes: 7 additions & 6 deletions src/io/calimero/tools/NetworkMonitor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Calimero 2 - A library for KNX network access
Copyright (c) 2006, 2023 B. Malinowsky
Copyright (c) 2006, 2024 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
Expand Down Expand Up @@ -107,7 +107,7 @@
public class NetworkMonitor implements Runnable
{
private static final String tool = "NetworkMonitor";
private static final String sep = System.getProperty("line.separator");
private static final String sep = System.lineSeparator();

private static final Logger out = LogService.getLogger("io.calimero.tools");

Expand Down Expand Up @@ -485,12 +485,13 @@ protected static String decodeLteFrame(final int extFormat, final KNXAddress dst
if (pid == 0xff) {
final int companyCode = ((asdu[4] & 0xff) << 8) | (asdu[5] & 0xff);
final int privatePid = asdu[6] & 0xff;
sb.append("IOT " + iot + " OI " + ioi + " Company " + companyCode + " PID " + privatePid + ": "
+ HexFormat.of().formatHex(asdu, 7, asdu.length));
sb.append("IOT ").append(iot).append(" OI ").append(ioi).append(" Company ").append(companyCode)
.append(" PID ").append(privatePid).append(": ").append(HexFormat.of()
.formatHex(asdu, 7, asdu.length));
}
else
sb.append("IOT " + iot + " OI " + ioi + " PID " + pid + ": "
+ HexFormat.of().formatHex(asdu, 4, asdu.length));
sb.append("IOT ").append(iot).append(" OI ").append(ioi).append(" PID ").append(pid).append(": ")
.append(HexFormat.of().formatHex(asdu, 4, asdu.length));

return sb.toString();
}
Expand Down
9 changes: 5 additions & 4 deletions src/io/calimero/tools/ProcComm.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Calimero 2 - A library for KNX network access
Copyright (c) 2006, 2023 B. Malinowsky
Copyright (c) 2006, 2024 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
Expand Down Expand Up @@ -162,7 +162,7 @@
public class ProcComm implements Runnable
{
private static final String tool = "ProcComm";
private static final String sep = System.getProperty("line.separator");
private static final String sep = System.lineSeparator();
private static final String toolDatapointsFile = "." + tool.toLowerCase() + "_dplist.xml";

private static final Logger out = LogService.getLogger("io.calimero.tools." + tool);
Expand Down Expand Up @@ -740,10 +740,11 @@ private String decodeLteFrame(final int svcCode, final int extFormat, final Grou
if (pid == 0xff) {
final int companyCode = ((asdu[4] & 0xff) << 8) | (asdu[5] & 0xff);
final int privatePid = asdu[6] & 0xff;
sb.append("IOT " + iot + " OI " + ioi + " Company " + companyCode + " PID " + privatePid + v);
sb.append("IOT ").append(iot).append(" OI ").append(ioi).append(" Company ").append(companyCode)
.append(" PID ").append(privatePid).append(v);
}
else
sb.append("IOT " + iot + " OI " + ioi + " PID " + pid + v);
sb.append("IOT ").append(iot).append(" OI ").append(ioi).append(" PID ").append(pid).append(v);

return sb.toString();
}
Expand Down
4 changes: 2 additions & 2 deletions src/io/calimero/tools/ProgMode.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Calimero 2 - A library for KNX network access
Copyright (c) 2015, 2023 B. Malinowsky
Copyright (c) 2015, 2024 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
Expand Down Expand Up @@ -65,7 +65,7 @@
public class ProgMode implements Runnable
{
private static final String tool = "ProgMode";
private static final String sep = System.getProperty("line.separator");
private static final String sep = System.lineSeparator();

/** Contains tool options after parsing command line. */
private final Map<String, Object> options = new HashMap<>();
Expand Down
29 changes: 13 additions & 16 deletions src/io/calimero/tools/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
public class Property implements Runnable
{
private static final String tool = "Property";
private static final String sep = System.getProperty("line.separator");
private static final String sep = System.lineSeparator();

static Logger out = LogService.getLogger("io.calimero.tools");

Expand Down Expand Up @@ -358,10 +358,10 @@ protected void onDescription(final Description d)
else
buf.append(new String(new char[33]).replace('\0', ' ')).append("(n/a)");
final String pdtDef = p != null ? Integer.toString(p.pdt()) : "-";
buf.append(", PDT " + (d.pdt() == -1 ? pdtDef : Integer.toString(d.pdt())));
buf.append(", curr. elems " + d.currentElements());
buf.append(", max. " + d.maxElements());
buf.append(", r/w access " + d.readLevel() + "/" + d.writeLevel());
buf.append(", PDT ").append(d.pdt() == -1 ? pdtDef : Integer.toString(d.pdt()));
buf.append(", curr. elems ").append(d.currentElements());
buf.append(", max. ").append(d.maxElements());
buf.append(", r/w access ").append(d.readLevel()).append("/").append(d.writeLevel());
buf.append(d.writeEnabled() ? ", w.enabled" : ", r.only");
System.out.println(buf);
}
Expand Down Expand Up @@ -426,7 +426,7 @@ private PropertyAdapter createAdapter() throws KNXException, InterruptedExceptio
throw new KnxRuntimeException("secure local device management requires user 1 (management user)");
return Main.newLocalDeviceMgmtIP(options, this::adapterClosed);
}
return createRemoteAdapter(host);
return createRemoteAdapter();
}

/**
Expand All @@ -443,13 +443,11 @@ private PropertyAdapter createUsbAdapter(final String device) throws KNXExceptio
* Creates the KNX network link and remote property service adapter for one device in the KNX
* network. The adapter uses a KNX network link for access, also is created by this method.
*
* @param host remote host
* @return remote property service adapter
* @throws KNXException on adapter creation problem
* @throws InterruptedException on interrupted thread
*/
private PropertyAdapter createRemoteAdapter(final String host) throws KNXException,
InterruptedException
private PropertyAdapter createRemoteAdapter() throws KNXException, InterruptedException
{
link = Main.newLink(options);
final IndividualAddress remote = (IndividualAddress) options.get("remote");
Expand Down Expand Up @@ -760,13 +758,12 @@ else if (cnt == 3 && args[2].equals("all"))

private static void showCommandList()
{
final StringBuilder buf = new StringBuilder();
buf.append("commands: get | set | desc | scan (append ? for help)" + sep);
buf.append("get - read property value(s)" + sep);
buf.append("set - write property value(s)" + sep);
buf.append("desc - read one property description" + sep);
buf.append("scan - read property descriptions");
out(buf.toString());
out("""
commands: get | set | desc | scan (append ? for help)
get - read property value(s)
set - write property value(s)
desc - read one property description
scan - read property descriptions""");
}

private static void printHelp(final String help)
Expand Down
Loading

0 comments on commit 8b4f420

Please sign in to comment.