Skip to content

Commit

Permalink
Made tabs consistent, added .editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed May 17, 2020
1 parent 2cc200a commit 53562ab
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 89 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

[*.java]
indent_style = tab
max_line_length = 180
indent_size = 4
ij_continuation_indent_size = 8
trim_trailing_whitespace = true

[*.xml]
indent_style = space
indent_size = 4

26 changes: 13 additions & 13 deletions src/main/java/me/retrodaredevil/io/modbus/ExceptionCode.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package me.retrodaredevil.io.modbus;

public final class ExceptionCode {
private ExceptionCode() { throw new UnsupportedOperationException(); }
// http://www.simplymodbus.ca/exceptions.htm
private ExceptionCode() { throw new UnsupportedOperationException(); }
// http://www.simplymodbus.ca/exceptions.htm

public static int ILLEGAL_FUNCTION = 1;
public static int ILLEGAL_DATA_ACCESS = 2;
public static int ILLEGAL_DATA_VALUE = 3;
public static int SLAVE_DEVICE_FAILURE = 4;
public static int ACKNOWLEDGE = 5;
public static int SLAVE_DEVICE_BUSY = 6;
public static int NEGATIVE_ACKNOWLEDGE = 7;
public static int MEMORY_PARITY_ERROR = 8;
// skip 9 for some reason
public static int GATEWAY_PATH_UNAVAILABLE = 10;
public static int GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11;
public static int ILLEGAL_FUNCTION = 1;
public static int ILLEGAL_DATA_ACCESS = 2;
public static int ILLEGAL_DATA_VALUE = 3;
public static int SLAVE_DEVICE_FAILURE = 4;
public static int ACKNOWLEDGE = 5;
public static int SLAVE_DEVICE_BUSY = 6;
public static int NEGATIVE_ACKNOWLEDGE = 7;
public static int MEMORY_PARITY_ERROR = 8;
// skip 9 for some reason
public static int GATEWAY_PATH_UNAVAILABLE = 10;
public static int GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static ModbusMessage createMessage(int functionCode, int[] data){
}

public static ModbusMessage createExceptionMessage(int functionCode, int exceptionCode) {
return createExceptionMessage((byte) functionCode, (byte) exceptionCode);
return createExceptionMessage((byte) functionCode, (byte) exceptionCode);
}

public static ModbusMessage createExceptionMessage(byte functionCode, byte exceptionCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import me.retrodaredevil.io.modbus.ModbusMessage;

public interface MessageResponseCreator<T> extends MessageHandler<T> {
/**
* Creates a response message with the specified data
* @param data The data to put in the returned response message
* @return A response {@link ModbusMessage} with the specified data
*/
ModbusMessage createResponse(T data);
/**
* Creates a response message with the specified data
* @param data The data to put in the returned response message
* @return A response {@link ModbusMessage} with the specified data
*/
ModbusMessage createResponse(T data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public MultipleWriteHandler(int register, byte[] data8Bit) {
this(register, convert8BitArray(data8Bit));
}
public static MultipleWriteHandler parseFromRequestData(int[] data) throws MessageParseException {
if (data.length % 2 != 1) { // the array's length is not odd // if it is even
throw new MessageParseException("data.length is even! It must be odd! data.length=" + data.length);
if (data.length % 2 != 1) { // the array's length is not odd // if it is even
throw new MessageParseException("data.length is even! It must be odd! data.length=" + data.length);
}
if (data.length <= 5) {
throw new MessageParseException("data.length must be greater than 5 and must be odd! So must be >= 7. data.length=" + data.length);
if (data.length <= 5) {
throw new MessageParseException("data.length must be greater than 5 and must be odd! So must be >= 7. data.length=" + data.length);
}
int register = data[0] << 8 | data[1];
int numberOfRegisters = data[2] << 8 | data[3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public ReadRegistersHandler(int register, int numberOfRegisters) {
this.numberOfRegisters = numberOfRegisters;
}
public static ReadRegistersHandler parseFromRequestData(int[] data) throws MessageParseException {
if (data.length != 4) {
throw new MessageParseException("data.length != 4! data.length=" + data.length);
if (data.length != 4) {
throw new MessageParseException("data.length != 4! data.length=" + data.length);
}
return new ReadRegistersHandler(
data[0] << 8 | data[1],
Expand Down Expand Up @@ -73,7 +73,7 @@ public ModbusMessage createResponse(int[] data16Bit) {
if (data16Bit.length != numberOfRegisters) {
throw new IllegalArgumentException("The array of 16 bit integers passed was not the correct length! numberOfRegisters=" + numberOfRegisters + ". The passed data should have that length.");
}
int[] data = get8BitDataFrom16BitArray(data16Bit);
int[] data = get8BitDataFrom16BitArray(data16Bit);
int byteCount = numberOfRegisters * 2;
if (data.length != byteCount) {
throw new AssertionError("We just checked this. This is a code problem.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package me.retrodaredevil.io.modbus.handling;

public class WriteRegistersException extends WriteException {
public WriteRegistersException() {
}
public WriteRegistersException() {
}

public WriteRegistersException(String message) {
super(message);
}
public WriteRegistersException(String message) {
super(message);
}

public WriteRegistersException(String message, Throwable cause) {
super(message, cause);
}
public WriteRegistersException(String message, Throwable cause) {
super(message, cause);
}

public WriteRegistersException(Throwable cause) {
super(cause);
}
public WriteRegistersException(Throwable cause) {
super(cause);
}

public WriteRegistersException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
public WriteRegistersException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import me.retrodaredevil.io.modbus.handling.SingleWriteHandler;

public class DefaultMessageParser implements MessageParser {
@Override
public MessageHandler<?> parseRequestMessage(ModbusMessage message) throws MessageParseException {
switch(message.getFunctionCode()) {
case FunctionCode.READ_REGISTERS:
return ReadRegistersHandler.parseFromRequestData(message.getData());
case FunctionCode.WRITE_SINGLE_REGISTER:
return SingleWriteHandler.parseFromRequestData(message.getData());
case FunctionCode.WRITE_MULTIPLE_REGISTERS:
return MultipleWriteHandler.parseFromRequestData(message.getData());
}
return null;
}
@Override
public MessageHandler<?> parseRequestMessage(ModbusMessage message) throws MessageParseException {
switch(message.getFunctionCode()) {
case FunctionCode.READ_REGISTERS:
return ReadRegistersHandler.parseFromRequestData(message.getData());
case FunctionCode.WRITE_SINGLE_REGISTER:
return SingleWriteHandler.parseFromRequestData(message.getData());
case FunctionCode.WRITE_MULTIPLE_REGISTERS:
return MultipleWriteHandler.parseFromRequestData(message.getData());
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package me.retrodaredevil.io.modbus.parsing;

public class MessageParseException extends Exception {
public MessageParseException() {
}
public MessageParseException() {
}

public MessageParseException(String message) {
super(message);
}
public MessageParseException(String message) {
super(message);
}

public MessageParseException(String message, Throwable cause) {
super(message, cause);
}
public MessageParseException(String message, Throwable cause) {
super(message, cause);
}

public MessageParseException(Throwable cause) {
super(cause);
}
public MessageParseException(Throwable cause) {
super(cause);
}

public MessageParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
public MessageParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import me.retrodaredevil.io.modbus.handling.MessageHandler;

public interface MessageParser {
/**
* @param message The message from the master
* @return The {@link MessageHandler} if the function is supported, null otherwise
* @throws MessageParseException if the data in {@code message} is not valid.
*/
MessageHandler<?> parseRequestMessage(ModbusMessage message) throws MessageParseException;
/**
* @param message The message from the master
* @return The {@link MessageHandler} if the function is supported, null otherwise
* @throws MessageParseException if the data in {@code message} is not valid.
*/
MessageHandler<?> parseRequestMessage(ModbusMessage message) throws MessageParseException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import java.util.List;

public class MessageParserMultiplexer implements MessageParser {
private final List<MessageParser> messageParsers;
private final List<MessageParser> messageParsers;

public MessageParserMultiplexer(Collection<? extends MessageParser> messageParsers) {
this.messageParsers = Collections.unmodifiableList(new ArrayList<>(messageParsers));
}
public MessageParserMultiplexer(Collection<? extends MessageParser> messageParsers) {
this.messageParsers = Collections.unmodifiableList(new ArrayList<>(messageParsers));
}

@Override
public MessageHandler<?> parseRequestMessage(ModbusMessage message) throws MessageParseException {
for (MessageParser messageParser : messageParsers) {
MessageHandler<?> messageHandler = messageParser.parseRequestMessage(message);
if (messageHandler != null) {
return messageHandler;
}
}
return null;
}
@Override
public MessageHandler<?> parseRequestMessage(ModbusMessage message) throws MessageParseException {
for (MessageParser messageParser : messageParsers) {
MessageHandler<?> messageHandler = messageParser.parseRequestMessage(message);
if (messageHandler != null) {
return messageHandler;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public OutputStream getOutputStream() {
* Contains JSerial specific config settings
*/
public static class Config {
public static final Config DEFAULT = new Config(0, 4096, 4096);
public static final Config DEFAULT = new Config(0, 4096, 4096);

private final int safetySleepTimeMillis;
private final int deviceSendQueueSize;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/me/retrodaredevil/io/modbus/ModbusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void testRTUEncoding(){
ByteArrayInputStream responseStream = new ByteArrayInputStream(new byte[]{
1,
6,
1, 10,
1, 10,
0, 1,
0x69, (byte) 0xF4
});
Expand Down

0 comments on commit 53562ab

Please sign in to comment.