changes
This commit is contained in:
parent
ffe3ff249f
commit
6d87ca1ee3
@ -11,7 +11,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
public class MbusMaster {
|
public class MbusMaster {
|
||||||
static final String PROPS_FILENAME = "mbusMaster.props";
|
static final String PROPS_FILENAME = "mbusMaster.props";
|
||||||
static final Logger logger = LogManager.getRootLogger();
|
static final Logger logger = LogManager.getRootLogger();
|
||||||
|
static boolean stopSignal = false;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
logger.info("MbusMaster starting");
|
logger.info("MbusMaster starting");
|
||||||
@ -24,12 +24,26 @@ public class MbusMaster {
|
|||||||
logger.debug("Configuration loaded");
|
logger.debug("Configuration loaded");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
stopSignal = true;
|
||||||
|
}));
|
||||||
|
logger.debug("Shutdown hook added");
|
||||||
|
*/
|
||||||
|
|
||||||
MbusgwChild mbusgw = new MbusgwChild(false);
|
MbusgwChild mbusgw = new MbusgwChild(false);
|
||||||
mbusgw.start();
|
mbusgw.start();
|
||||||
|
|
||||||
|
byte[] devices = { (byte)80, (byte)81, (byte)82, (byte)83, (byte)84, (byte)85, (byte)86, (byte)87 };
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
|
while (! stopSignal) {
|
||||||
|
System.out.println("--- " + cnt + " ----------------------------------------------------");
|
||||||
|
cnt++;
|
||||||
|
for (byte device : devices) {
|
||||||
|
System.out.println("Querying device " + device);
|
||||||
try {
|
try {
|
||||||
mbusgw.sendRequest((byte)0x5b, (byte)80);
|
mbusgw.sendRequest((byte)0x5b, device);
|
||||||
|
|
||||||
byte[] frame = mbusgw.collectResponse();
|
byte[] frame = mbusgw.collectResponse();
|
||||||
for (byte x : frame) {
|
for (byte x : frame) {
|
||||||
@ -37,10 +51,16 @@ public class MbusMaster {
|
|||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Error in Meterbus dialog: " + e.toString() + ", " + e.getMessage());
|
logger.error("Error " + e.toString() + ", " + e.getMessage() + " in Meterbus dialog for device " + device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (cnt >= 10) {
|
||||||
|
// break;
|
||||||
|
//}
|
||||||
|
Thread.sleep(15*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Stopping mbusgw process");
|
logger.info("Stopping mbusgw process");
|
||||||
mbusgw.stop();
|
mbusgw.stop();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,9 +63,10 @@ public class MbusgwChild {
|
|||||||
logger.debug("stderrToLog thread started");
|
logger.debug("stderrToLog thread started");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() throws InterruptedException {
|
public void stop() throws InterruptedException, IOException {
|
||||||
logger.info("About to stop mbusgw child process");
|
logger.info("About to stop mbusgw child process");
|
||||||
this.mbusgwProcess.destroy();
|
this.sendRequest((byte)0, (byte)0);
|
||||||
|
// this.mbusgwProcess.destroy();
|
||||||
this.mbusgwProcess.waitFor();
|
this.mbusgwProcess.waitFor();
|
||||||
logger.info("Process stopped");
|
logger.info("Process stopped");
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
</File>
|
</File>
|
||||||
</Appenders>
|
</Appenders>
|
||||||
<Loggers>
|
<Loggers>
|
||||||
<Root level="debug">
|
<Root level="error">
|
||||||
<AppenderRef ref="ConsoleAppender"/>
|
<AppenderRef ref="ConsoleAppender"/>
|
||||||
<AppenderRef ref="FileAppender"/>
|
<AppenderRef ref="FileAppender"/>
|
||||||
</Root>
|
</Root>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user