-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fineoffsetweatherstation] Improve tracing
Signed-off-by: Andreas Berger <[email protected]>
- Loading branch information
Showing
8 changed files
with
148 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../main/java/org/openhab/binding/fineoffsetweatherstation/internal/domain/DebugDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.fineoffsetweatherstation.internal.domain; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.openhab.binding.fineoffsetweatherstation.internal.Utils; | ||
|
||
public class DebugDetails { | ||
final byte[] data; | ||
|
||
private final Map<Integer, DebugSegment> segments = new TreeMap<>(); | ||
|
||
public DebugDetails(byte[] data, Command command, Protocol protocol) { | ||
this.data = data; | ||
addDebugDetails(0, 2, "header"); | ||
addDebugDetails(2, 1, "command: " + command.name()); | ||
addDebugDetails(3, command.getSizeBytes(), "size"); | ||
if (protocol == Protocol.ELV) { | ||
addDebugDetails(data.length - 2, 1, "ELV checksum"); | ||
} | ||
addDebugDetails(data.length - 1, 1, "checksum"); | ||
} | ||
|
||
public void addDebugDetails(int start, int length, String description) { | ||
segments.put(start, new DebugSegment(start, length, description)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
int padding = segments.values().stream().mapToInt(value -> value.length).max().orElse(0) * 2; | ||
return "0x" + Utils.toHexString(data, data.length, "") + "\n" + segments.values().stream() | ||
.map(debugSegment -> debugSegment.toDebugString(padding)).collect(Collectors.joining("\n")); | ||
} | ||
|
||
private class DebugSegment { | ||
final int start; | ||
final int length; | ||
final String description; | ||
|
||
DebugSegment(int start, int length, String description) { | ||
this.start = start; | ||
this.length = length; | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toDebugString(0); | ||
} | ||
|
||
private String toDebugString(int padding) { | ||
String result = "0x"; | ||
String hexString = Utils.toHexString(Arrays.copyOfRange(data, start, start + length), length, ""); | ||
result += StringUtils.rightPad(hexString, padding, " "); | ||
result += ": " + description; | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters