Skip to content

Commit

Permalink
Replace with switch statement
Browse files Browse the repository at this point in the history
  • Loading branch information
bmalinowsky committed Jan 31, 2025
1 parent 0d8c011 commit 9d5a165
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions src/io/calimero/link/KNXNetworkMonitorUsb.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Calimero 2 - A library for KNX network access
Copyright (c) 2015, 2024 B. Malinowsky
Copyright (c) 2015, 2025 B. Malinowsky
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -50,7 +50,6 @@
import io.calimero.KNXFormatException;
import io.calimero.KNXListener;
import io.calimero.KNXTimeoutException;
import io.calimero.cemi.CEMI;
import io.calimero.cemi.CEMIDevMgmt;
import io.calimero.link.BcuSwitcher.BcuMode;
import io.calimero.link.medium.KNXMediumSettings;
Expand Down Expand Up @@ -188,23 +187,19 @@ private boolean trySetActiveEmi(final UsbConnection.EmiType active)
return false;
}

private void enterBusmonitor(final boolean extBusmon)
throws KNXPortClosedException, KNXTimeoutException, KNXFormatException, InterruptedException
{
if (activeEmi == Cemi) {
final var frame = BcuSwitcher.commModeRequest(BcuSwitcher.Busmonitor);
conn.send(frame, BlockingMode.Confirmation);
// TODO close monitor if we cannot switch to busmonitor
// check for .con
//findFrame(CEMIDevMgmt.MC_PROPWRITE_CON);
}
else if (activeEmi == Emi1) {
new BcuSwitcher<>(conn, logger)
.enter(extBusmon ? BcuMode.ExtBusmonitor : BcuMode.Busmonitor);
}
else {
final byte[] switchBusmon = { (byte) PEI_SWITCH, (byte) 0x90, 0x18, 0x34, 0x56, 0x78, 0x0A, };
conn.send(switchBusmon, BlockingMode.Confirmation);
private static final byte[] peiSwitchBusmon = {(byte) PEI_SWITCH, (byte) 0x90, 0x18, 0x34, 0x56, 0x78, 0x0A,};
private static final byte[] peiSwitchNormal = {(byte) PEI_SWITCH, 0x1E, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A,};

private void enterBusmonitor(final boolean extBusmon) throws KNXPortClosedException, KNXTimeoutException,
KNXFormatException, InterruptedException {
switch (activeEmi) {
case Cemi -> {
conn.send(BcuSwitcher.commModeRequest(BcuSwitcher.Busmonitor), BlockingMode.Confirmation);
// check for .con
//findFrame(CEMIDevMgmt.MC_PROPWRITE_CON);
}
case Emi1 -> new BcuSwitcher<>(conn, logger).enter(extBusmon ? BcuMode.ExtBusmonitor : BcuMode.Busmonitor);
case Emi2 -> conn.send(peiSwitchBusmon, BlockingMode.Confirmation);
}
}

Expand All @@ -217,18 +212,11 @@ protected void leaveBusmonitor() throws InterruptedException
catch (final KNXPortClosedException | KNXTimeoutException e) {}
}

private void normalMode() throws KNXPortClosedException, KNXTimeoutException, InterruptedException
{
if (activeEmi == Cemi) {
final CEMI frame = new CEMIDevMgmt(CEMIDevMgmt.MC_RESET_REQ);
conn.send(frame.toByteArray(), BlockingMode.Confirmation);
}
else if (activeEmi == Emi1) {
new BcuSwitcher<>(conn, logger).reset();
}
else if (activeEmi == Emi2) {
final byte[] switchNormal = { (byte) PEI_SWITCH, 0x1E, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, };
conn.send(switchNormal, BlockingMode.Confirmation);
private void normalMode() throws KNXPortClosedException, KNXTimeoutException, InterruptedException {
switch (activeEmi) {
case Cemi -> conn.send(new CEMIDevMgmt(CEMIDevMgmt.MC_RESET_REQ).toByteArray(), BlockingMode.Confirmation);
case Emi1 -> new BcuSwitcher<>(conn, logger).reset();
case Emi2 -> conn.send(peiSwitchNormal, BlockingMode.Confirmation);
}
}

Expand Down

0 comments on commit 9d5a165

Please sign in to comment.