Skip to content

Commit

Permalink
Allow customizing all them ISOTP options
Browse files Browse the repository at this point in the history
  • Loading branch information
pschichtel committed Aug 12, 2020
1 parent 89c4383 commit 3d5f01a
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private IsotpCanSocketOptions() {}
public static final SocketOption<IsotpOptions> OPTS = new CanSocketOption<>("OPTS", IsotpOptions.class, new LinuxSocketOptionHandler<IsotpOptions>() {
@Override
public void set(int sock, IsotpOptions val) throws IOException {
SocketCAN.setIsotpOpts(sock, val.getFlags(), val.getFrameTransmissionTime(), val.getExtendedTransmissionAddress(), val.getTransmissionPadding(), val.getReceivePadding(), val.getExtendedReceiveAddress());
SocketCAN.setIsotpOpts(sock, val.getRawFlags(), val.getFrameTransmissionTime(), val.getExtendedTransmissionAddress(), val.getTransmissionPadding(), val.getReceivePadding(), val.getExtendedReceiveAddress());
}

@Override
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/tel/schich/javacan/IsotpFlowControlOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
* This class represents ISOTP's flow control options.
*/
public class IsotpFlowControlOptions {

public static final IsotpFlowControlOptions DEFAULT = new IsotpFlowControlOptions(
(byte) 0,
(byte) 0x00,
(byte) 0
);

private final byte blockSize;
private final byte minimumSeparationTime;
private final byte maximumWaitFrameTransmission;
Expand All @@ -45,14 +52,50 @@ public byte getBlockSize() {
return blockSize;
}

public IsotpFlowControlOptions withBlockSize(byte blockSize) {
return new IsotpFlowControlOptions(
blockSize,
minimumSeparationTime,
maximumWaitFrameTransmission
);
}

public IsotpFlowControlOptions withBlockSize(int blockSize) {
return withBlockSize((byte) blockSize);
}

public byte getMinimumSeparationTime() {
return minimumSeparationTime;
}

public IsotpFlowControlOptions withMinimumSeparationTime(byte minimumSeparationTime) {
return new IsotpFlowControlOptions(
blockSize,
minimumSeparationTime,
maximumWaitFrameTransmission
);
}

public IsotpFlowControlOptions withMinimumSeparationTime(int minimumSeparationTime) {
return withMinimumSeparationTime((byte) minimumSeparationTime);
}

public byte getMaximumWaitFrameTransmission() {
return maximumWaitFrameTransmission;
}

public IsotpFlowControlOptions withMaximumWaitFrameTransmission(byte maximumWaitFrameTransmission) {
return new IsotpFlowControlOptions(
blockSize,
minimumSeparationTime,
maximumWaitFrameTransmission
);
}

public IsotpFlowControlOptions withMaximumWaitFrameTransmission(int maximumWaitFrameTransmission) {
return withMaximumWaitFrameTransmission((byte) maximumWaitFrameTransmission);
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/tel/schich/javacan/IsotpLinkLayerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
* This class represents ISOTP's link layer options.
*/
public class IsotpLinkLayerOptions {

public static final IsotpLinkLayerOptions DEFAULT = new IsotpLinkLayerOptions(
(byte) RawCanChannel.MTU,
(byte) CanFrame.MAX_DATA_LENGTH,
(byte) 0
);

private final byte maximumTransmissionUnit;
private final byte transmissionDataLength;
private final byte transmissionFlags;
Expand All @@ -45,14 +52,50 @@ public byte getMaximumTransmissionUnit() {
return maximumTransmissionUnit;
}

public IsotpLinkLayerOptions withMaximumTransmissionUnit(byte maximumTransmissionUnit) {
return new IsotpLinkLayerOptions(
maximumTransmissionUnit,
transmissionDataLength,
transmissionFlags
);
}

public IsotpLinkLayerOptions withMaximumTransmissionUnit(int maximumTransmissionUnit) {
return withMaximumTransmissionUnit((byte) maximumTransmissionUnit);
}

public byte getTransmissionDataLength() {
return transmissionDataLength;
}

public IsotpLinkLayerOptions withTransmissionDataLength(byte transmissionDataLength) {
return new IsotpLinkLayerOptions(
maximumTransmissionUnit,
transmissionDataLength,
transmissionFlags
);
}

public IsotpLinkLayerOptions withTransmissionDataLength(int transmissionDataLength) {
return withTransmissionDataLength((byte) transmissionDataLength);
}

public byte getTransmissionFlags() {
return transmissionFlags;
}

public IsotpLinkLayerOptions withTransmissionFlags(byte transmissionFlags) {
return new IsotpLinkLayerOptions(
maximumTransmissionUnit,
transmissionDataLength,
transmissionFlags
);
}

public IsotpLinkLayerOptions withTransmissionFlags(int transmissionFlags) {
return withTransmissionFlags((byte) transmissionFlags);
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down
Loading

0 comments on commit 3d5f01a

Please sign in to comment.