-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RFC 2217 support by incorporating the jvser library (see http:/…
- Loading branch information
Showing
27 changed files
with
3,165 additions
and
1 deletion.
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
185 changes: 185 additions & 0 deletions
185
nrjavaserial/src/main/java/gnu/io/rfc2217/AbstractComPortCommandSwitch.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,185 @@ | ||
|
||
/* | ||
* Copyright (C) 2010 Archie L. Cobbs. All rights reserved. | ||
* | ||
* $Id: AbstractComPortCommandSwitch.java 6 2010-11-20 23:37:06Z archie.cobbs $ | ||
*/ | ||
|
||
package gnu.io.rfc2217; | ||
|
||
/** | ||
* Adapter class for {@link ComPortCommandSwitch} implementations. | ||
* | ||
* @see ComPortCommandSwitch | ||
* @see ComPortCommand#visit | ||
*/ | ||
public class AbstractComPortCommandSwitch implements ComPortCommandSwitch { | ||
|
||
/** | ||
* Visit method invoked by {@link SignatureCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseSignature(SignatureCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link BaudRateCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseBaudRate(BaudRateCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link DataSizeCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseDataSize(DataSizeCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link ParityCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseParity(ParityCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link StopSizeCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseStopSize(StopSizeCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link ControlCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseControl(ControlCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link NotifyLineStateCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseNotifyLineState(NotifyLineStateCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link NotifyModemStateCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseNotifyModemState(NotifyModemStateCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link FlowControlSuspendCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseFlowControlSuspend(FlowControlSuspendCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link FlowControlResumeCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseFlowControlResume(FlowControlResumeCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link LineStateMaskCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseLineStateMask(LineStateMaskCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link ModemStateMaskCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void caseModemStateMask(ModemStateMaskCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Visit method invoked by {@link PurgeDataCommand} instances. | ||
* | ||
* <p> | ||
* The implementation in {@link AbstractComPortCommandSwitch} delegates to {@link #caseDefault}. | ||
* </p> | ||
*/ | ||
@Override | ||
public void casePurgeData(PurgeDataCommand command) { | ||
caseDefault(command); | ||
} | ||
|
||
/** | ||
* Default handler. | ||
* | ||
* <p> | ||
* All other methods in {@link AbstractComPortCommandSwitch} delegate to this method; | ||
* the implementation in {@link AbstractComPortCommandSwitch} does nothing. | ||
* </p> | ||
*/ | ||
protected void caseDefault(ComPortCommand command) { | ||
} | ||
} | ||
|
78 changes: 78 additions & 0 deletions
78
nrjavaserial/src/main/java/gnu/io/rfc2217/BaudRateCommand.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,78 @@ | ||
|
||
/* | ||
* Copyright (C) 2010 Archie L. Cobbs. All rights reserved. | ||
* | ||
* $Id: BaudRateCommand.java 39 2011-03-22 17:21:53Z archie.cobbs $ | ||
*/ | ||
|
||
package gnu.io.rfc2217; | ||
|
||
import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; | ||
import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; | ||
import static gnu.io.rfc2217.RFC2217.SET_BAUDRATE; | ||
|
||
/** | ||
* RFC 2217 {@code SET-BAUDRATE} command. | ||
* | ||
* @see <a href="http://tools.ietf.org/html/rfc2217">RFC 2217</a> | ||
*/ | ||
public class BaudRateCommand extends ComPortCommand { | ||
|
||
private int baudRate; | ||
|
||
/** | ||
* Decoding constructor. | ||
* | ||
* @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte | ||
* @throws NullPointerException if {@code bytes} is null | ||
* @throws IllegalArgumentException if {@code bytes} has length that is too short or too long | ||
* @throws IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} | ||
* @throws IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#SET_BAUDRATE} (client or server) | ||
*/ | ||
public BaudRateCommand(int[] bytes) { | ||
super("SET-BAUDRATE", SET_BAUDRATE, bytes); | ||
this.baudRate = ((bytes[2] & 0xff) << 24) | ((bytes[3] & 0xff) << 16) | ((bytes[4] & 0xff) << 8) | (bytes[5] & 0xff); | ||
} | ||
|
||
/** | ||
* Encoding constructor. | ||
* | ||
* @param baudRate baud rate | ||
* @param client true for the client-to-server command, false for the server-to-client command | ||
*/ | ||
public BaudRateCommand(boolean client, int baudRate) { | ||
this(new int[] { | ||
COM_PORT_OPTION, | ||
client ? SET_BAUDRATE : SET_BAUDRATE + SERVER_OFFSET, | ||
(baudRate >> 24) & 0xff, | ||
(baudRate >> 16) & 0xff, | ||
(baudRate >> 8) & 0xff, | ||
baudRate & 0xff, | ||
}); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getName() + " " + this.baudRate; | ||
} | ||
|
||
@Override | ||
public void visit(ComPortCommandSwitch sw) { | ||
sw.caseBaudRate(this); | ||
} | ||
|
||
public int getBaudRate() { | ||
return this.baudRate; | ||
} | ||
|
||
@Override | ||
int getMinPayloadLength() { | ||
return 4; | ||
} | ||
|
||
@Override | ||
int getMaxPayloadLength() { | ||
return 4; | ||
} | ||
} | ||
|
Oops, something went wrong.