Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide debug output when an alias is seen on another Node ID #252

Merged
merged 8 commits into from
Feb 23, 2024
15 changes: 14 additions & 1 deletion src/org/openlcb/can/AliasMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.openlcb.NodeID;

import java.util.ArrayList;
import java.util.logging.Logger;

/**
* Maintains a 2-way map between nodes and CAN node ID aliases.
Expand All @@ -19,7 +20,8 @@ public AliasMap() {
java.util.HashMap<NodeID, Integer> iMap = new java.util.HashMap<NodeID, Integer>();
java.util.HashMap<Integer, NodeID> nMap = new java.util.HashMap<Integer, NodeID>();
java.util.List<Watcher> watchers = new ArrayList<>();

private final static Logger logger = Logger.getLogger(AliasMap.class.getName());

/// This interface allows an external component to watch for newly discovered aliases.
public interface Watcher {
/// Called when a new alias was discovered.
Expand Down Expand Up @@ -47,6 +49,17 @@ public void processFrame(OpenLcbCanFrame f) {

public void insert(int alias, NodeID nid) {
synchronized (this) {
if (nMap.containsKey(alias) && nid.toLong() != nMap.get(alias).toLong()) {
logger.warning("map contains alias "
+String.format("0x%03X", alias & 0xFFF)
+" for node "+nMap.get(alias)+" change to "+nid);
}
if (iMap.containsKey(nid) && alias != iMap.get(nid)) {
logger.warning("map contains nodeID "+nid+" for alias "
+String.format("0x%03X", iMap.get(nid) & 0xFFF)
+" change to "
+String.format("0x%03X", alias & 0xFFF));
}
nMap.put(alias, nid);
iMap.put(nid, alias);
}
Expand Down
Loading