feat: added parsing impl
This commit is contained in:
parent
15c8313cb1
commit
de42d5ef2a
|
@ -0,0 +1,68 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static de.swingbe.ifleet.model.HeaderParser.parseHeader;
|
||||||
|
import static de.swingbe.ifleet.model.TeleParser.parseTelegram;
|
||||||
|
|
||||||
|
public class ComParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(ComParser.class);
|
||||||
|
|
||||||
|
public static Communication parseCc(final String input) {
|
||||||
|
LOG.debug("input: {}", input);
|
||||||
|
|
||||||
|
Communication com = null;
|
||||||
|
Header header = null;
|
||||||
|
Telegram telegram = null;
|
||||||
|
|
||||||
|
if (input.contains("<")) {
|
||||||
|
|
||||||
|
String inputSup = input.substring(input.indexOf("<") + 1,
|
||||||
|
input.lastIndexOf(">"));
|
||||||
|
|
||||||
|
//parse Header
|
||||||
|
header = parseHeader(input);
|
||||||
|
|
||||||
|
//parse Telegram
|
||||||
|
String inputSupPop = popFieldFromCom(inputSup, 4);
|
||||||
|
LOG.debug("inputSupPop: " + inputSupPop);
|
||||||
|
telegram = parseTelegram(inputSupPop);
|
||||||
|
} else {
|
||||||
|
LOG.warn("telegram NOT included");
|
||||||
|
}
|
||||||
|
|
||||||
|
//create Communication
|
||||||
|
if (telegram != null && header != null) {
|
||||||
|
com = new Communication(header, telegram);
|
||||||
|
} else {
|
||||||
|
LOG.warn("telegram NOT available");
|
||||||
|
}
|
||||||
|
return com;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String popFieldFromCom(final String com, final int numberOfFields) {
|
||||||
|
String comNew = com;
|
||||||
|
String comSup = null;
|
||||||
|
for (int i = 0; i < numberOfFields; i++) {
|
||||||
|
//TODO Method call indexOf may produce NullPointerException!
|
||||||
|
int indexChar;
|
||||||
|
if (comNew != null) {
|
||||||
|
indexChar = comNew.indexOf('#');
|
||||||
|
LOG.debug("indexChar: " + indexChar);
|
||||||
|
try {
|
||||||
|
comSup = comNew.substring(indexChar + 1);
|
||||||
|
LOG.debug("comSup: " + comSup);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
LOG.error("poping field from communication failed, message: " + e.getMessage() + ", trace: " + Arrays.toString(e.getStackTrace()));
|
||||||
|
}
|
||||||
|
comNew = comSup;
|
||||||
|
} else {
|
||||||
|
LOG.error("input unavailable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return comNew;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
public class Communication {
|
||||||
|
|
||||||
|
private static final String SEP = "#";
|
||||||
|
private static final String END = System.getProperty("line.separator");
|
||||||
|
private final Header header;
|
||||||
|
private final Telegram telegram;
|
||||||
|
|
||||||
|
public Communication(Header header, Telegram telegram) {
|
||||||
|
this.header = header;
|
||||||
|
this.telegram = telegram;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Communication{" +
|
||||||
|
"header=" + header +
|
||||||
|
", telegram=" + telegram +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public Header getHeader() {
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Telegram getTelegram() {
|
||||||
|
return telegram;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum PeerType {
|
||||||
|
I,
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
K,
|
||||||
|
G,
|
||||||
|
R
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
public class Entity {
|
||||||
|
public String getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLogLevel() {
|
||||||
|
return logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddressPartA() {
|
||||||
|
return addressPartA;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddressPartB() {
|
||||||
|
return addressPartB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPeer() {
|
||||||
|
return peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddressNext() {
|
||||||
|
return addressNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDirection() {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Communication getCc() {
|
||||||
|
return cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String date;
|
||||||
|
private final String time;
|
||||||
|
private final String logLevel;
|
||||||
|
private final String addressPartA;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Entity{" +
|
||||||
|
"date='" + date + '\'' +
|
||||||
|
", time='" + time + '\'' +
|
||||||
|
", logLevel='" + logLevel + '\'' +
|
||||||
|
", addressPartA='" + addressPartA + '\'' +
|
||||||
|
", addressPartB='" + addressPartB + '\'' +
|
||||||
|
", peer='" + peer + '\'' +
|
||||||
|
", addressNext='" + addressNext + '\'' +
|
||||||
|
", direction='" + direction + '\'' +
|
||||||
|
", cc=" + cc +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entity(String date, String time, String logLevel, String addressPartA, String addressPartB, String peer, String addressNext, String direction, Communication cc) {
|
||||||
|
this.date = date;
|
||||||
|
this.time = time;
|
||||||
|
this.logLevel = logLevel;
|
||||||
|
this.addressPartA = addressPartA;
|
||||||
|
this.addressPartB = addressPartB;
|
||||||
|
this.peer = peer;
|
||||||
|
this.addressNext = addressNext;
|
||||||
|
this.direction = direction;
|
||||||
|
this.cc = cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String addressPartB;
|
||||||
|
private final String peer;
|
||||||
|
private final String addressNext;
|
||||||
|
private final String direction;
|
||||||
|
private final Communication cc;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static de.swingbe.ifleet.model.ComParser.parseCc;
|
||||||
|
|
||||||
|
public class EntityParser {
|
||||||
|
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(EntityParser.class);
|
||||||
|
|
||||||
|
public static Entity parseLogEntry(String input) {
|
||||||
|
LOG.debug("input: {}", input);
|
||||||
|
|
||||||
|
Entity logEntry = null;
|
||||||
|
String[] splits = input.split(" ");
|
||||||
|
LOG.debug("splits: " + splits.length);
|
||||||
|
|
||||||
|
//parse date
|
||||||
|
String date = null;
|
||||||
|
if (splits.length > 0) {
|
||||||
|
date = splits[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse time
|
||||||
|
String time = null;
|
||||||
|
if (splits.length > 1) {
|
||||||
|
time = splits[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse log level
|
||||||
|
String logLevel = null;
|
||||||
|
if (splits.length > 2) {
|
||||||
|
logLevel = splits[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
//index three is empty
|
||||||
|
|
||||||
|
//parse addressPartA
|
||||||
|
String addressPartA = null;
|
||||||
|
if (splits.length > 4) {
|
||||||
|
addressPartA = splits[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse addressPartB
|
||||||
|
String addressPartB = null;
|
||||||
|
if (splits.length > 5) {
|
||||||
|
addressPartB = splits[5];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse peer
|
||||||
|
String peer = null;
|
||||||
|
if (splits.length > 6) {
|
||||||
|
peer = splits[6];
|
||||||
|
}
|
||||||
|
//parse address next
|
||||||
|
String addressNext = null;
|
||||||
|
if (splits.length > 7) {
|
||||||
|
addressNext = splits[7];
|
||||||
|
}
|
||||||
|
//parse direction
|
||||||
|
String direction = null;
|
||||||
|
if (splits.length > 8) {
|
||||||
|
direction = splits[8];
|
||||||
|
}
|
||||||
|
//parse communication
|
||||||
|
Communication communication = null;
|
||||||
|
if (splits.length > 9) {
|
||||||
|
String[] splitsSup = Arrays.copyOfRange(splits, 9, splits.length);
|
||||||
|
String inputSup = String.join(" ", splitsSup);
|
||||||
|
communication = parseCc(inputSup);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (date != null && time != null && logLevel != null && addressPartA != null && addressPartB != null && peer != null && addressNext != null && direction != null && communication != null) {
|
||||||
|
logEntry = new Entity(date, time, logLevel, addressPartA, addressPartB, peer, addressNext, direction, communication);
|
||||||
|
}
|
||||||
|
|
||||||
|
return logEntry;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
public class Header {
|
||||||
|
|
||||||
|
private final Sender sender;
|
||||||
|
private final Receiver receiver;
|
||||||
|
|
||||||
|
public Header(Sender sender, Receiver receiver) {
|
||||||
|
this.sender = sender;
|
||||||
|
this.receiver = receiver;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Header{" +
|
||||||
|
"sender=" + sender +
|
||||||
|
", receiver=" + receiver +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sender getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Receiver getReceiver() {
|
||||||
|
return receiver;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static de.swingbe.ifleet.model.ComParser.popFieldFromCom;
|
||||||
|
import static de.swingbe.ifleet.model.ReceiverParser.parseReceiver;
|
||||||
|
import static de.swingbe.ifleet.model.SenderParser.parseSender;
|
||||||
|
|
||||||
|
public class HeaderParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(HeaderParser.class);
|
||||||
|
|
||||||
|
public static Header parseHeader(final String input) {
|
||||||
|
LOG.debug("input: {}", input);
|
||||||
|
|
||||||
|
Header header = null;
|
||||||
|
Sender sender;
|
||||||
|
Receiver receiver;
|
||||||
|
|
||||||
|
//parse Sender
|
||||||
|
sender = parseSender(input);
|
||||||
|
|
||||||
|
//parse Receiver
|
||||||
|
String inputPop = popFieldFromCom(input, 2);
|
||||||
|
LOG.debug("inputPop: " + inputPop);
|
||||||
|
receiver = parseReceiver(inputPop);
|
||||||
|
|
||||||
|
if (sender != null && receiver != null) {
|
||||||
|
header = new Header(sender, receiver);
|
||||||
|
}
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
public class LocationMessage {
|
||||||
|
private final Position position;
|
||||||
|
|
||||||
|
public LocationMessage(Position position) {
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "LocationMessage{" +
|
||||||
|
"position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static de.swingbe.ifleet.model.PositionParser.parsePosition;
|
||||||
|
|
||||||
|
public class LocationMessageParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(LocationMessageParser.class);
|
||||||
|
|
||||||
|
public static LocationMessage parseLocationMessage(String input) {
|
||||||
|
LOG.debug("input: {}", input);
|
||||||
|
|
||||||
|
LocationMessage locationMessage = null;
|
||||||
|
|
||||||
|
Position position = parsePosition(input);
|
||||||
|
if (position != null) {
|
||||||
|
locationMessage = new LocationMessage(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
return locationMessage;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
public class Position {
|
||||||
|
|
||||||
|
private final long longitude;
|
||||||
|
private final long latitude;
|
||||||
|
private final int velocity;
|
||||||
|
private final int heading;
|
||||||
|
|
||||||
|
public Position(long longitude, long latitude, int velocity, int heading) {
|
||||||
|
this.longitude = longitude;
|
||||||
|
this.latitude = latitude;
|
||||||
|
this.velocity = velocity;
|
||||||
|
this.heading = heading;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Position{" +
|
||||||
|
"longitude=" + longitude +
|
||||||
|
", latitude=" + latitude +
|
||||||
|
", velocity=" + velocity +
|
||||||
|
", heading=" + heading +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLongitude() {
|
||||||
|
return longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLatitude() {
|
||||||
|
return latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVelocity() {
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeading() {
|
||||||
|
return heading;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static de.swingbe.ifleet.model.TeleHeaderParser.isNumeric;
|
||||||
|
|
||||||
|
public class PositionParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(PositionParser.class);
|
||||||
|
|
||||||
|
public static Position parsePosition(String input) {
|
||||||
|
LOG.debug("input: {}", input);
|
||||||
|
|
||||||
|
Position position = null;
|
||||||
|
|
||||||
|
String[] splits = input.split("#");
|
||||||
|
LOG.debug("splits: " + splits.length);
|
||||||
|
|
||||||
|
//parse NetPoint
|
||||||
|
//parse RelPosition
|
||||||
|
//parse lat
|
||||||
|
String lat = null;
|
||||||
|
if (splits.length > 2) {
|
||||||
|
lat = splits[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//parse lon
|
||||||
|
String lon = null;
|
||||||
|
if (splits.length > 3) {
|
||||||
|
lon = splits[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//parse vel
|
||||||
|
String vel = null;
|
||||||
|
if (splits.length > 4) {
|
||||||
|
vel = splits[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//parse hdg
|
||||||
|
String hdg = null;
|
||||||
|
if (splits.length > 5) {
|
||||||
|
hdg = splits[5];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lat != null && lon != null && vel != null && hdg != null) {
|
||||||
|
boolean latIsNumeric = isNumeric(lat);
|
||||||
|
boolean lonIsNumeric = isNumeric(lon);
|
||||||
|
boolean velIsNumeric = isNumeric(vel);
|
||||||
|
boolean hdgIsNumeric = isNumeric(hdg);
|
||||||
|
|
||||||
|
if (latIsNumeric && lonIsNumeric && velIsNumeric && hdgIsNumeric) {
|
||||||
|
try {
|
||||||
|
position = new Position(Long.parseLong(lat), Long.parseLong(lon), Integer.parseInt(vel), Integer.parseInt(hdg));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
LOG.error("parsing position failed, message: " + e.getMessage() + ", trace: " + Arrays.toString(e.getStackTrace()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
public class Receiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Receiver{" +
|
||||||
|
"receiver='" + receiver + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReceiver() {
|
||||||
|
return receiver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReceiver(String receiver) {
|
||||||
|
this.receiver = receiver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Receiver(String receiver) {
|
||||||
|
this.receiver = receiver;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String receiver;
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class ReceiverParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(ReceiverParser.class);
|
||||||
|
|
||||||
|
public static Receiver parseReceiver(final String input) {
|
||||||
|
LOG.debug("input: {}", input);
|
||||||
|
|
||||||
|
Receiver receiver = null;
|
||||||
|
String[] splits = input.split("#");
|
||||||
|
LOG.debug("splits: " + splits.length);
|
||||||
|
|
||||||
|
//parse receiver part A
|
||||||
|
String receiverPartA = null;
|
||||||
|
if (splits.length > 0) {
|
||||||
|
receiverPartA = splits[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse receiver part A
|
||||||
|
String receiverPartB = null;
|
||||||
|
if (splits.length > 1) {
|
||||||
|
receiverPartB = splits[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (receiverPartA != null && receiverPartB != null) {
|
||||||
|
receiver = new Receiver(receiverPartA + "#" + receiverPartB);
|
||||||
|
}
|
||||||
|
return receiver;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
public class Sender {
|
||||||
|
|
||||||
|
private String sender;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Sender{" +
|
||||||
|
"sender='" + sender + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSender(String sender) {
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sender(String sender) {
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class SenderParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(SenderParser.class);
|
||||||
|
|
||||||
|
public static Sender parseSender(final String input) {
|
||||||
|
LOG.debug("input: {}", input);
|
||||||
|
|
||||||
|
Sender sender = null;
|
||||||
|
|
||||||
|
String[] splits = input.split("#");
|
||||||
|
LOG.debug("splits: " + splits.length);
|
||||||
|
|
||||||
|
//parse sender part A
|
||||||
|
String senderPartA = null;
|
||||||
|
if (splits.length > 0) {
|
||||||
|
senderPartA = splits[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse sender part A
|
||||||
|
String senderPartB = null;
|
||||||
|
if (splits.length > 1) {
|
||||||
|
senderPartB = splits[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (senderPartA != null && senderPartB != null) {
|
||||||
|
sender = new Sender(senderPartA + "#" + senderPartB);
|
||||||
|
}
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
public class TeleHeader {
|
||||||
|
|
||||||
|
private final int teleType;
|
||||||
|
private final String teleVersion;
|
||||||
|
private final int teleId;
|
||||||
|
|
||||||
|
public TeleHeader(int teleType, String teleVersion, int teleId) {
|
||||||
|
this.teleType = teleType;
|
||||||
|
this.teleVersion = teleVersion;
|
||||||
|
this.teleId = teleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTeleType() {
|
||||||
|
return teleType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTeleVersion() {
|
||||||
|
return teleVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTeleId() {
|
||||||
|
return teleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TeleHeader{" +
|
||||||
|
"teleType=" + teleType +
|
||||||
|
", teleVersion='" + teleVersion + '\'' +
|
||||||
|
", teleId=" + teleId +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class TeleHeaderParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(TeleHeaderParser.class);
|
||||||
|
|
||||||
|
public static TeleHeader parseTeleHeader(String input) {
|
||||||
|
LOG.debug("input: {}", input);
|
||||||
|
|
||||||
|
TeleHeader teleHeader = null;
|
||||||
|
|
||||||
|
String[] splits = input.split("#");
|
||||||
|
LOG.debug("splits: " + splits.length);
|
||||||
|
|
||||||
|
//parse id
|
||||||
|
String type = null;
|
||||||
|
if (splits.length > 0) {
|
||||||
|
type = splits[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse version
|
||||||
|
String version = null;
|
||||||
|
if (splits.length > 1) {
|
||||||
|
version = splits[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse ID
|
||||||
|
String id = null;
|
||||||
|
if (splits.length > 2) {
|
||||||
|
id = splits[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type != null && version != null && id != null) {
|
||||||
|
boolean typeIsNumeric = isNumeric(type);
|
||||||
|
boolean idIsNumeric = isNumeric(id);
|
||||||
|
|
||||||
|
if (typeIsNumeric && idIsNumeric) {
|
||||||
|
try {
|
||||||
|
teleHeader = new TeleHeader(Integer.parseInt(type), version, Integer.parseInt(id));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
LOG.error("parsing telegram header failed, message: " + e.getMessage() + ", trace: " + Arrays.toString(e.getStackTrace()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return teleHeader;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNumeric(String str) {
|
||||||
|
return str != null && str.matches("[0-9.]+");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static de.swingbe.ifleet.model.ComParser.popFieldFromCom;
|
||||||
|
import static de.swingbe.ifleet.model.LocationMessageParser.parseLocationMessage;
|
||||||
|
import static de.swingbe.ifleet.model.TeleHeaderParser.parseTeleHeader;
|
||||||
|
|
||||||
|
public class TeleParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(TeleParser.class);
|
||||||
|
|
||||||
|
public static Telegram parseTelegram(final String input) {
|
||||||
|
LOG.debug("input: {}", input);
|
||||||
|
|
||||||
|
Telegram telegram = null;
|
||||||
|
TeleHeader teleHeader = parseTeleHeader(input);
|
||||||
|
|
||||||
|
String inputNew = popFieldFromCom(input, 3);
|
||||||
|
LOG.debug("inputNew: " + inputNew);
|
||||||
|
|
||||||
|
LocationMessage locationMessage = parseLocationMessage(inputNew);
|
||||||
|
|
||||||
|
if (teleHeader != null && locationMessage != null) {
|
||||||
|
telegram = new Telegram(teleHeader, locationMessage);
|
||||||
|
}
|
||||||
|
return telegram;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
public class Telegram {
|
||||||
|
|
||||||
|
private final TeleHeader teleHeader;
|
||||||
|
private final LocationMessage locationMessage;
|
||||||
|
|
||||||
|
public Telegram(TeleHeader teleHeader, LocationMessage locationMessage) {
|
||||||
|
this.teleHeader = teleHeader;
|
||||||
|
this.locationMessage = locationMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TeleHeader getTeleHeader() {
|
||||||
|
return teleHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocationMessage getLocationMessage() {
|
||||||
|
return locationMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Telegram{" +
|
||||||
|
"teleHeader=" + teleHeader +
|
||||||
|
", locationMessage=" + locationMessage +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue