2020-09-01 20:52:26 +02:00
|
|
|
package de.hottis.mbusMaster;
|
|
|
|
|
2020-09-02 18:43:38 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2020-09-01 20:52:26 +02:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
|
|
|
|
|
|
|
public class MbusMaster {
|
|
|
|
static final String PROPS_FILENAME = "mbusMaster.props";
|
|
|
|
static final Logger logger = LogManager.getRootLogger();
|
2020-09-02 22:05:43 +02:00
|
|
|
static boolean stopSignal = false;
|
2020-09-01 20:52:26 +02:00
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
logger.info("MbusMaster starting");
|
|
|
|
|
|
|
|
/*
|
|
|
|
final Properties config = new Properties();
|
|
|
|
try (FileInputStream propsFileInputStream = new FileInputStream(PROPS_FILENAME)) {
|
|
|
|
config.load(propsFileInputStream);
|
|
|
|
}
|
|
|
|
logger.debug("Configuration loaded");
|
|
|
|
*/
|
|
|
|
|
2020-09-02 22:05:43 +02:00
|
|
|
/*
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
|
stopSignal = true;
|
|
|
|
}));
|
|
|
|
logger.debug("Shutdown hook added");
|
|
|
|
*/
|
2020-09-04 19:35:19 +02:00
|
|
|
|
2020-09-02 18:08:25 +02:00
|
|
|
MbusgwChild mbusgw = new MbusgwChild(false);
|
2020-09-02 15:47:23 +02:00
|
|
|
mbusgw.start();
|
2020-09-01 20:52:26 +02:00
|
|
|
|
2020-09-02 22:05:43 +02:00
|
|
|
byte[] devices = { (byte)80, (byte)81, (byte)82, (byte)83, (byte)84, (byte)85, (byte)86, (byte)87 };
|
2020-09-01 20:52:26 +02:00
|
|
|
|
2020-09-02 22:05:43 +02:00
|
|
|
int cnt = 0;
|
|
|
|
while (! stopSignal) {
|
|
|
|
System.out.println("--- " + cnt + " ----------------------------------------------------");
|
|
|
|
cnt++;
|
|
|
|
for (byte device : devices) {
|
|
|
|
System.out.println("Querying device " + device);
|
|
|
|
try {
|
|
|
|
mbusgw.sendRequest((byte)0x5b, device);
|
2020-09-01 20:52:26 +02:00
|
|
|
|
2020-09-02 22:05:43 +02:00
|
|
|
byte[] frame = mbusgw.collectResponse();
|
|
|
|
for (byte x : frame) {
|
|
|
|
System.out.print(Integer.toHexString(Byte.toUnsignedInt(x)) + " ");
|
|
|
|
}
|
|
|
|
System.out.println();
|
|
|
|
} catch (IOException e) {
|
2020-09-04 19:35:19 +02:00
|
|
|
logger.error("Error " + e.toString() + " in Meterbus dialog for device " + device);
|
2020-09-02 22:05:43 +02:00
|
|
|
}
|
2020-09-02 18:43:38 +02:00
|
|
|
}
|
2020-09-02 22:05:43 +02:00
|
|
|
// if (cnt >= 10) {
|
|
|
|
// break;
|
|
|
|
//}
|
|
|
|
Thread.sleep(15*1000);
|
2020-09-01 20:52:26 +02:00
|
|
|
}
|
|
|
|
|
2020-09-02 22:05:43 +02:00
|
|
|
logger.info("Stopping mbusgw process");
|
2020-09-02 15:47:23 +02:00
|
|
|
mbusgw.stop();
|
2020-09-01 20:52:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|