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;
|
2020-09-07 10:25:53 +02:00
|
|
|
import java.util.List;
|
2020-09-01 20:52:26 +02:00
|
|
|
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
2020-09-07 10:24:43 +02:00
|
|
|
import org.openmuc.jmbus.DataRecord;
|
|
|
|
import org.openmuc.jmbus.MBusMessage;
|
|
|
|
import org.openmuc.jmbus.VariableDataStructure;
|
2020-09-01 20:52:26 +02:00
|
|
|
|
|
|
|
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-07 13:39:22 +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-07 13:39:22 +02:00
|
|
|
MbusDevice[] devices = {
|
|
|
|
new FinderThreePhasePowerMeter("Total Electricity", (byte)80, 0),
|
|
|
|
new FinderOnePhasePowerMeter("Dryer", (byte)81, 0),
|
|
|
|
new FinderOnePhasePowerMeter("Laundry", (byte)82, 0),
|
|
|
|
new FinderOnePhasePowerMeter("Dishwasher", (byte)83, 0),
|
|
|
|
new FinderOnePhasePowerMeter("Light", (byte)84, 0),
|
|
|
|
new FinderOnePhasePowerMeter("Computer", (byte)85, 0),
|
|
|
|
new FinderOnePhasePowerMeter("Freezer", (byte)86, 0),
|
|
|
|
new FinderOnePhasePowerMeter("Fridge", (byte)87, 0)
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-09-02 22:05:43 +02:00
|
|
|
int cnt = 0;
|
2020-09-05 18:48:07 +02:00
|
|
|
int errCnt = 0;
|
|
|
|
int successCnt = 0;
|
2020-09-02 22:05:43 +02:00
|
|
|
while (! stopSignal) {
|
|
|
|
cnt++;
|
2020-09-07 13:39:22 +02:00
|
|
|
for (MbusDevice device : devices) {
|
|
|
|
System.out.println("Querying " + device.getName() + " meter");
|
2020-09-02 22:05:43 +02:00
|
|
|
try {
|
2020-09-07 13:39:22 +02:00
|
|
|
mbusgw.sendRequest((byte)0x5b, device.getAddress());
|
2020-09-02 22:05:43 +02:00
|
|
|
byte[] frame = mbusgw.collectResponse();
|
2020-09-07 13:39:22 +02:00
|
|
|
device.parse(frame);
|
2020-09-07 10:24:43 +02:00
|
|
|
|
2020-09-07 13:39:22 +02:00
|
|
|
System.out.println(device);
|
2020-09-07 10:24:43 +02:00
|
|
|
|
2020-09-05 18:48:07 +02:00
|
|
|
successCnt++;
|
2020-09-02 22:05:43 +02:00
|
|
|
} catch (IOException e) {
|
2020-09-05 18:48:07 +02:00
|
|
|
errCnt++;
|
2020-09-07 13:39:22 +02:00
|
|
|
logger.error("Error " + e.toString() + " in Meterbus dialog for device " + device.shortString());
|
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;
|
|
|
|
//}
|
2020-09-07 13:39:22 +02:00
|
|
|
System.out.println("--- " + cnt + " - " + successCnt + " - " + errCnt + " ---------------------------------------------------");
|
2020-09-05 18:48:07 +02:00
|
|
|
Thread.sleep(5*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
|
|
|
|
|
|
|
}
|
|
|
|
}
|