initial
This commit is contained in:
commit
39199f0d95
1
mbusMaster.props
Normal file
1
mbusMaster.props
Normal file
@ -0,0 +1 @@
|
||||
mqtt.broker = tcp://172.16.2.16
|
18
mbusMaster.service
Normal file
18
mbusMaster.service
Normal file
@ -0,0 +1,18 @@
|
||||
[Unit]
|
||||
Description=mqttMBusConverter
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
GuessMainPID=yes
|
||||
ExecStart=/usr/bin/java -jar mqttMBusConverter-1.0-SNAPSHOT-jar-with-dependencies.jar
|
||||
ExecStop=kill -SIGINT $mainpid
|
||||
Restart=on-failure
|
||||
WorkingDirectory=/opt/services/mqttMBusConverter
|
||||
|
||||
[Install]
|
||||
Alias=mqttmbusconverter
|
||||
WantedBy=multi-user.target
|
||||
|
67
pom.xml
Normal file
67
pom.xml
Normal file
@ -0,0 +1,67 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.hottis.mbusMaster</groupId>
|
||||
<artifactId>mbusMaster</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>mbusMaster</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.codesnippets4all</groupId>
|
||||
<artifactId>quick-json</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openmuc</groupId>
|
||||
<artifactId>jmbus</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.9.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>de.hottis.mbusMaster.MbusMaster</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
5
readme.md
Normal file
5
readme.md
Normal file
@ -0,0 +1,5 @@
|
||||
To build the jar:
|
||||
|
||||
mvn clean compile assembly:single
|
||||
|
||||
|
66
src/main/java/de/hottis/mbusMaster/MbusMaster.java
Normal file
66
src/main/java/de/hottis/mbusMaster/MbusMaster.java
Normal file
@ -0,0 +1,66 @@
|
||||
package de.hottis.mbusMaster;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.BufferedReader;
|
||||
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();
|
||||
|
||||
|
||||
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");
|
||||
*/
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder("/usr/local/bin/mbusgw", "-l", "-v");
|
||||
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||
Process p = pb.start();
|
||||
System.out.println("Process started");
|
||||
|
||||
|
||||
|
||||
InputStream i = p.getInputStream();
|
||||
OutputStream o = p.getOutputStream();
|
||||
System.out.println("Streams collected");
|
||||
|
||||
byte[] b = { 0x5b, 80 };
|
||||
|
||||
o.write(b);
|
||||
System.out.println("Data written");
|
||||
|
||||
o.flush();
|
||||
System.out.println("Data flushed");
|
||||
|
||||
|
||||
byte[] header = new byte[2];
|
||||
int n = i.read(header, 0, 2);
|
||||
int responseCode = Byte.toUnsignedInt(header[0]);
|
||||
int responseLen = Byte.toUnsignedInt(header[1]);
|
||||
System.out.println("n: " + n + ", h: " + responseCode + ", l: " + responseLen);
|
||||
|
||||
byte[] frame = new byte[responseLen];
|
||||
n = i.read(frame, 0, responseLen);
|
||||
for (byte x : frame) {
|
||||
System.out.print(Integer.toHexString(Byte.toUnsignedInt(x)) + " ");
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
17
src/main/resources/log4j2.xml
Normal file
17
src/main/resources/log4j2.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration debug="false">
|
||||
<Appenders>
|
||||
<Console name="ConsoleAppender" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d [%t, %F, %L] %-5level - %msg%n%throwable"/>
|
||||
</Console>
|
||||
<File name="FileAppender" fileName="/tmp/mqttMBusConverter.log">
|
||||
<PatternLayout pattern="%d [%t, %F, %L] %-5level - %msg%n%throwable"/>
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="ConsoleAppender"/>
|
||||
<AppenderRef ref="FileAppender"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
38
src/test/java/de/hottis/mbusMaster/AppTest.java
Normal file
38
src/test/java/de/hottis/mbusMaster/AppTest.java
Normal file
@ -0,0 +1,38 @@
|
||||
package de.hottis.mbusMaster;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user