Skip to content

Commit

Permalink
2021-07-14T22:37
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta-shimizu committed Jul 14, 2021
1 parent ea073a2 commit b3d0938
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
Binary file modified docs/CliSecsSimulator.jar
Binary file not shown.
Binary file modified docs/SwingSecsSimulator.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,12 @@ private void receivePrimaryMsg(SecsMessage primaryMsg) throws InterruptedExcepti
{
/*** Auto-reply ***/

final SmlMessage reply = autoReply(primaryMsg).orElse(null);
final List<SmlMessage> replys = autoReplys(primaryMsg);

if ( replys.size() == 1 ) {

if ( reply != null ) {
try {
send(primaryMsg, reply);
send(primaryMsg, replys.get(0));
}
catch (SecsSimulatorException ignore) {
}
Expand Down Expand Up @@ -554,7 +555,7 @@ private void receivePrimaryMsg(SecsMessage primaryMsg) throws InterruptedExcepti
}
}

private Optional<SmlMessage> autoReply(SecsMessage primary) {
private List<SmlMessage> autoReplys(SecsMessage primary) {

if (
primary.wbit()
Expand All @@ -571,11 +572,11 @@ private Optional<SmlMessage> autoReply(SecsMessage primary) {
) {

return config.smlAliasPairPool()
.optionalOnlyOneStreamFunction(strm, func + 1);
.getReplyMessages(strm, func + 1);
}
}

return Optional.empty();
return Collections.emptyList();
}

private Optional<LocalSecsMessage> autoReplySxF0(SecsMessage primary) {
Expand All @@ -598,7 +599,7 @@ private Optional<LocalSecsMessage> autoReplySxF0(SecsMessage primary) {

if ( primary.wbit() ) {

if ( ! config.smlAliasPairPool().hasReplyMessages(strm, func) ) {
if ( ! config.smlAliasPairPool().hasReplyMessages(strm, func + 1) ) {

if ( config.smlAliasPairPool().hasReplyMessages(strm) ) {

Expand Down Expand Up @@ -638,7 +639,7 @@ private Optional<LocalSecsMessage> autoReplyS9F3or5(SecsMessage primary) {

if ( strm >= 0 ) {

if ( ! config.smlAliasPairPool().hasReplyMessages(strm, func) ) {
if ( ! config.smlAliasPairPool().hasReplyMessages(strm, func + 1) ) {

if ( config.smlAliasPairPool().hasReplyMessages(strm) ) {

Expand Down
23 changes: 17 additions & 6 deletions src/main/java/com/shimizukenta/secssimulator/SmlAliasPairPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,30 @@ public Optional<SmlMessage> optionalAlias(CharSequence alias) {
*/
public Optional<SmlMessage> optionalOnlyOneStreamFunction(int strm, int func) {

Collection<SmlMessage> smls = pairs.stream()
.map(p -> p.sml())
.filter(sm -> sm.getStream() == strm)
.filter(sm -> sm.getFunction() == func)
.collect(Collectors.toList());
final List<SmlMessage> smls = getReplyMessages(strm, func);

if ( smls.size() == 1 ) {
return smls.stream().findAny();
return Optional.of(smls.get(0));
}

return Optional.empty();
}

/**
* Returns SmlMessages of same Stream and Funcion Number.
*
* @param strm of SmlMessage stream-number
* @param func of SmlMessage function-number
* @return SmlMessages of same Stream and Funcion Number
*/
public List<SmlMessage> getReplyMessages(int strm, int func) {
return pairs.stream()
.map(p -> p.sml())
.filter(sm -> sm.getStream() == strm)
.filter(sm -> sm.getFunction() == func)
.collect(Collectors.toList());
}

/**
* Returns true if has reply-messsages.
*
Expand Down

0 comments on commit b3d0938

Please sign in to comment.