-
Notifications
You must be signed in to change notification settings - Fork 65
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 #27 from kenta-shimizu/v5
Add SecsMessageBuilder
- Loading branch information
Showing
12 changed files
with
776 additions
and
105 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
61 changes: 61 additions & 0 deletions
61
src/main/java/com/shimizukenta/secs/impl/AbstractSecsMessageBuilder.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,61 @@ | ||
package com.shimizukenta.secs.impl; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import com.shimizukenta.secs.SecsCommunicator; | ||
import com.shimizukenta.secs.SecsMessage; | ||
import com.shimizukenta.secs.secs2.Secs2; | ||
|
||
public abstract class AbstractSecsMessageBuilder<M extends SecsMessage, C extends SecsCommunicator> implements SecsMessageBuilder<M, C> { | ||
|
||
private final AtomicInteger autoNum; | ||
|
||
public AbstractSecsMessageBuilder() { | ||
this.autoNum = new AtomicInteger(0); | ||
} | ||
|
||
// abstract protected boolean isEquip(); | ||
// | ||
// abstract protected byte[] device2Bytes(); | ||
|
||
abstract protected boolean isEquip(C communicator); | ||
|
||
abstract protected byte[] device2Bytes(C communicator); | ||
|
||
protected byte[] system4Bytes(C communicator) { | ||
|
||
final int num = autoNum.incrementAndGet(); | ||
|
||
if (isEquip(communicator)) { | ||
|
||
byte[] dev2bs = this.device2Bytes(communicator); | ||
|
||
return new byte[] { | ||
dev2bs[0], | ||
dev2bs[1], | ||
(byte)(num >> 8), | ||
(byte)num | ||
}; | ||
|
||
} else { | ||
|
||
return new byte[] { | ||
(byte)0x00, | ||
(byte)0x00, | ||
(byte)(num >> 8), | ||
(byte)num | ||
}; | ||
} | ||
} | ||
|
||
@Override | ||
public M build(C communicator, int strm, int func, boolean wbit) { | ||
return this.build(communicator, strm, func, wbit, Secs2.empty()); | ||
} | ||
|
||
@Override | ||
public M build(C communicator, SecsMessage primaryMsg, int strm, int func, boolean wbit) { | ||
return this.build(communicator, primaryMsg, strm, func, wbit, Secs2.empty()); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/shimizukenta/secs/impl/SecsMessageBuilder.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,24 @@ | ||
package com.shimizukenta.secs.impl; | ||
|
||
import com.shimizukenta.secs.SecsCommunicator; | ||
import com.shimizukenta.secs.SecsMessage; | ||
import com.shimizukenta.secs.secs2.Secs2; | ||
|
||
/** | ||
* SsecsMeessageBuilder. | ||
* | ||
* @author kenta-shimizu | ||
* | ||
* @param <M> the Secs-Message extends | ||
* @param <C> the SecsCommunicator extends | ||
*/ | ||
public interface SecsMessageBuilder<M extends SecsMessage, C extends SecsCommunicator> { | ||
|
||
public M build(C communicator, int strm, int func, boolean wbit); | ||
|
||
public M build(C communicator, int strm, int func, boolean wbit, Secs2 body); | ||
|
||
public M build(C communicator, SecsMessage primaryMsg, int strm, int func, boolean wbit); | ||
|
||
public M build(C communicator, SecsMessage primaryMsg, int strm, int func, boolean wbit, Secs2 body); | ||
} |
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
Oops, something went wrong.