Skip to content

Commit

Permalink
Merge pull request #34 from crea-doo/rfc2217
Browse files Browse the repository at this point in the history
RFC 2217 support
  • Loading branch information
madhephaestus committed Sep 13, 2015
2 parents cd66222 + a7327d3 commit 4d1a035
Show file tree
Hide file tree
Showing 27 changed files with 3,165 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -20,6 +20,8 @@ Removal of partially implemented code to streamline the lib for just serial port

Full Eclipse integration, for testing application code against sources.

RFC 2217 support provided by incorporating the jvser library (see http://github.com/archiecobbs/jvser)

##And a bunch of bug fixes##

Fixed the memory access error that causes OSX to crash the JVM when serial.close() is called
Expand Down
13 changes: 12 additions & 1 deletion nrjavaserial/pom.xml
Expand Up @@ -39,12 +39,23 @@
</developer>
</developers>

<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/c/resources/</directory>
<excludes>
<exclude>**/.svn/</exclude>
<exclude>**/.svn/</exclude>
</excludes>
</resource>
</resources>
Expand Down
@@ -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 nrjavaserial/src/main/java/gnu/io/rfc2217/BaudRateCommand.java
@@ -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;
}
}

0 comments on commit 4d1a035

Please sign in to comment.