-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from bobjacobsen/oir-corrected
Unknown MTI to node will now reply with OIR
- Loading branch information
Showing
8 changed files
with
153 additions
and
10 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.openlcb; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
// For annotations | ||
import net.jcip.annotations.Immutable; | ||
import net.jcip.annotations.ThreadSafe; | ||
|
||
/** | ||
* Message with unknown/unrecognized/unprocessed MTI | ||
* Only relevant for addressed case; unrecognized globals are ignored in proessing. | ||
* | ||
* @author Bob Jacobsen Copyright 2024 | ||
*/ | ||
@Immutable | ||
@ThreadSafe | ||
public class UnknownMtiMessage extends AddressedPayloadMessage { | ||
public UnknownMtiMessage(NodeID source, NodeID dest, int originalMTI, byte[] content) { | ||
super(source, dest, content); | ||
this.originalMTI = originalMTI; | ||
} | ||
|
||
int originalMTI; | ||
|
||
public int getOriginalMTI() { | ||
return originalMTI; | ||
} | ||
|
||
/** | ||
* To be equal, messages have to have the same type and content. | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (o instanceof UnknownMtiMessage) { | ||
return equals((UnknownMtiMessage) o); | ||
} | ||
return false; | ||
} | ||
|
||
public boolean equals(UnknownMtiMessage o) { | ||
if ((o == null) || (this.originalMTI != o.getOriginalMTI()) ) { | ||
return false; | ||
} | ||
return super.equals(o); | ||
} | ||
|
||
/** | ||
* Implement message-type-specific processing when this message is received by a node. | ||
* <p> | ||
* Default is to do nothing. | ||
*/ | ||
@Override | ||
public void applyTo(MessageDecoder decoder, Connection sender) { | ||
decoder.handleUnknownMTI(this, sender); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder value = new StringBuilder(super.toString()); | ||
value.append(" Unknown MTI message for MTI 0x"); | ||
value.append(Integer.toHexString(getOriginalMTI()&0xFFF).toUpperCase()); | ||
return new String(value); | ||
} | ||
|
||
@Override | ||
public MessageTypeIdentifier getEMTI() { | ||
return MessageTypeIdentifier.UnknownMTI; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.openlcb.protocols; | ||
|
||
import org.openlcb.Connection; | ||
import org.openlcb.Message; | ||
import org.openlcb.MessageDecoder; | ||
import org.openlcb.NodeID; | ||
import org.openlcb.OlcbInterface; | ||
import org.openlcb.UnknownMtiMessage; | ||
import org.openlcb.OptionalIntRejectedMessage; | ||
|
||
/** | ||
* Handler for unknown MTI requests to the local node. | ||
* <p> | ||
* Created by Bob Jacobsen 2/2024 from VerifyNodeIdHandler | ||
*/ | ||
public class UnknownMtiHandler extends MessageDecoder { | ||
private final OlcbInterface iface; | ||
private final NodeID id; | ||
|
||
/** | ||
* Instantiates the handler. | ||
* | ||
* @param id is the Node ID on behalf which to reply to messages. | ||
* @param iface is where to send replies to, and where to listen for incoming messages. | ||
*/ | ||
public UnknownMtiHandler(NodeID id, OlcbInterface iface) { | ||
this.iface = iface; | ||
this.id = id; | ||
iface.registerMessageListener(this); | ||
} | ||
|
||
@Override | ||
public void handleUnknownMTI(UnknownMtiMessage msg, Connection sender) { | ||
/* | ||
* This is an unknown MTI message that could be to anybody | ||
*/ | ||
|
||
// Only reply if addressed to this node | ||
if (msg.getDestNodeID() == this.id) { | ||
int mti = msg.getOriginalMTI(); | ||
int code = 0x1040; // See message std 3.5.5; permanent error, not implemented | ||
Message omsg = new OptionalIntRejectedMessage(this.id, msg.getSourceNodeID(), mti, code); | ||
iface.getOutputConnection().put(omsg, this); | ||
} | ||
} | ||
} |
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