feat: enable empty telegrams
This commit is contained in:
parent
ce3f0d21b7
commit
c1a847c700
2
pom.xml
2
pom.xml
|
@ -7,7 +7,7 @@
|
|||
|
||||
<groupId>de.swingbe.ifleet</groupId>
|
||||
<artifactId>tgp</artifactId>
|
||||
<version>0.0.4</version>
|
||||
<version>0.0.6</version>
|
||||
|
||||
<description>
|
||||
This project is a library for parsing ifleet telegrams in Java.
|
||||
|
|
|
@ -20,10 +20,12 @@ public class Communication {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Communication{" +
|
||||
"header=" + header +
|
||||
", telegram=" + telegram +
|
||||
'}';
|
||||
String ccString = "Communication{";
|
||||
ccString += header != null ? "header=" + header : "";
|
||||
ccString += telegram != null ? "telegram=" + telegram : "";
|
||||
ccString += '}';
|
||||
return ccString;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,17 +61,18 @@ public class Entity {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Entity{" +
|
||||
"date='" + date + '\'' +
|
||||
", time='" + time + '\'' +
|
||||
", logLevel='" + logLevel + '\'' +
|
||||
", addressPartA='" + addressPartA + '\'' +
|
||||
", addressPartB='" + addressPartB + '\'' +
|
||||
", peer='" + peer + '\'' +
|
||||
", addressNext='" + addressNext + '\'' +
|
||||
", direction='" + direction + '\'' +
|
||||
", cc=" + cc +
|
||||
'}';
|
||||
String eString = "Entity{";
|
||||
eString += date != null ? "date='" + date + '\'' : "";
|
||||
eString += time != null ? ", time='" + time + '\'' : "";
|
||||
eString += logLevel != null ? ", logLevel='" + logLevel + '\'' : "";
|
||||
eString += addressPartA != null ? ", addressPartA='" + addressPartA + '\'' : "";
|
||||
eString += addressPartB != null ? ", addressPartB='" + addressPartB + '\'' : "";
|
||||
eString += peer != null ? ", peer='" + peer + '\'' : "";
|
||||
eString += addressNext != null ? ", addressNext='" + addressNext + '\'' : "";
|
||||
eString += direction != null ? ", direction='" + direction + '\'' : "";
|
||||
eString += cc != null ? ", cc=" + cc : "";
|
||||
eString += '}';
|
||||
return eString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,9 +20,10 @@ public class Header {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Header{" +
|
||||
"sender=" + sender +
|
||||
", receiver=" + receiver +
|
||||
'}';
|
||||
String hString = "Header{";
|
||||
hString += sender != null ? "sender=" + sender : "";
|
||||
hString += receiver != null ? ", receiver=" + receiver : "";
|
||||
hString += '}';
|
||||
return hString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,9 @@ public class LocationMessage {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LocationMessage{" +
|
||||
"position=" + position +
|
||||
'}';
|
||||
String positionString = "LocationMessage{";
|
||||
positionString += position != null ? "position=" + position : "";
|
||||
positionString += '}';
|
||||
return positionString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,9 @@ public class Receiver {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Receiver{" +
|
||||
"receiver='" + receiver + '\'' +
|
||||
'}';
|
||||
String rString = "Receiver{";
|
||||
rString += receiver != null ? "receiver='" + receiver + '\'' : "";
|
||||
rString += '}';
|
||||
return rString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,9 @@ public class Sender {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Sender{" +
|
||||
"sender='" + sender + '\'' +
|
||||
'}';
|
||||
String sString = "Sender{";
|
||||
sString += sender != null ? "sender='" + sender + '\'' : "";
|
||||
sString += '}';
|
||||
return sString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,10 @@ public class Telegram {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Telegram{" +
|
||||
"teleHeader=" + teleHeader +
|
||||
", locationMessage=" + locationMessage +
|
||||
'}';
|
||||
String telegramString = "Telegram{";
|
||||
telegramString += teleHeader != null ? "teleHeader=" + teleHeader : "";
|
||||
telegramString += locationMessage != null ? ", locationMessage=" + locationMessage : "";
|
||||
telegramString += '}';
|
||||
return telegramString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ class ComParserImpl implements ComParser {
|
|||
@Override
|
||||
public Communication parse(final String input) {
|
||||
|
||||
Communication com = null;
|
||||
Header header = null;
|
||||
Telegram telegram = null;
|
||||
|
||||
|
@ -59,12 +58,6 @@ class ComParserImpl implements ComParser {
|
|||
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;
|
||||
return new Communication(header, telegram);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ class EntityParserImpl implements EntityParser {
|
|||
@Override
|
||||
public Entity parse(final String input) {
|
||||
|
||||
Entity entity = null;
|
||||
String[] splits = input.split(" ");
|
||||
|
||||
//parse date
|
||||
|
@ -39,13 +38,14 @@ class EntityParserImpl implements EntityParser {
|
|||
//parse addressPartA
|
||||
String addressPartA = null;
|
||||
if (splits.length > 4) {
|
||||
addressPartA = splits[4];
|
||||
addressPartA = splits[4].replaceFirst("\\[", "");
|
||||
}
|
||||
|
||||
//parse addressPartB
|
||||
String addressPartB = null;
|
||||
if (splits.length > 5) {
|
||||
addressPartB = splits[5];
|
||||
addressPartB = splits[5].replaceFirst("/", "")
|
||||
.replaceFirst("\\]", "");
|
||||
}
|
||||
|
||||
//parse peer
|
||||
|
@ -56,7 +56,7 @@ class EntityParserImpl implements EntityParser {
|
|||
//parse address next
|
||||
String addressNext = null;
|
||||
if (splits.length > 7) {
|
||||
addressNext = splits[7];
|
||||
addressNext = splits[7].replaceFirst("/", "");
|
||||
}
|
||||
//parse direction
|
||||
String direction = null;
|
||||
|
@ -71,10 +71,7 @@ class EntityParserImpl implements EntityParser {
|
|||
communication = ComParserFactory.createComParser().parse(inputSup);
|
||||
}
|
||||
|
||||
if (date != null && time != null && logLevel != null && addressPartA != null && addressPartB != null && peer != null && addressNext != null && direction != null && communication != null) {
|
||||
entity = new Entity(date, time, logLevel, addressPartA, addressPartB, peer, addressNext, direction, communication);
|
||||
}
|
||||
|
||||
return entity;
|
||||
return new Entity(date, time, logLevel, addressPartA, addressPartB, peer,
|
||||
addressNext, direction, communication);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,20 +13,14 @@ class HeaderParserImpl implements HeaderParser {
|
|||
|
||||
public Header parse(final String input) {
|
||||
|
||||
Header header = null;
|
||||
Sender sender;
|
||||
Receiver receiver;
|
||||
|
||||
//parse Sender
|
||||
sender = SenderParserFactory.createSenderParser().parse(input);
|
||||
|
||||
//parse Receiver
|
||||
String inputPop = popFieldFromCom(input, 2);
|
||||
receiver = ReceiverParserFactory.createReceiverParser().parse(inputPop);
|
||||
|
||||
if (sender != null && receiver != null) {
|
||||
header = new Header(sender, receiver);
|
||||
}
|
||||
return header;
|
||||
return new Header(sender, ReceiverParserFactory.createReceiverParser().parse(inputPop));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,10 @@
|
|||
package de.swingbe.ifleet.parser;
|
||||
|
||||
import de.swingbe.ifleet.model.LocationMessage;
|
||||
import de.swingbe.ifleet.model.Position;
|
||||
|
||||
class LocationMsgParserImpl implements LocationMsgParser {
|
||||
|
||||
public LocationMessage parse(String input) {
|
||||
|
||||
LocationMessage locationMessage = null;
|
||||
|
||||
Position position = PositionParserFactory.createPositionParser().parse(input);
|
||||
if (position != null) {
|
||||
locationMessage = new LocationMessage(position);
|
||||
}
|
||||
|
||||
return locationMessage;
|
||||
|
||||
return new LocationMessage(PositionParserFactory.createPositionParser().parse(input));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,41 +21,47 @@ public class PositionParserImpl implements PositionParser {
|
|||
//parse NetPoint
|
||||
//parse RelPosition
|
||||
//parse lat
|
||||
String lat = null;
|
||||
String lat = "";
|
||||
if (splits.length > 2) {
|
||||
lat = splits[2];
|
||||
} else {
|
||||
LOG.warn("lat unavailable");
|
||||
}
|
||||
|
||||
//parse lon
|
||||
String lon = null;
|
||||
String lon = "";
|
||||
if (splits.length > 3) {
|
||||
lon = splits[3];
|
||||
} else {
|
||||
LOG.warn("lon unavailable");
|
||||
}
|
||||
|
||||
//parse vel
|
||||
String vel = null;
|
||||
String vel = "";
|
||||
if (splits.length > 4) {
|
||||
vel = splits[4];
|
||||
} else {
|
||||
LOG.warn("vel unavailable");
|
||||
}
|
||||
|
||||
//parse hdg
|
||||
String hdg = null;
|
||||
String hdg = "";
|
||||
if (splits.length > 5) {
|
||||
hdg = splits[5];
|
||||
} else {
|
||||
LOG.warn("hdg unavailable");
|
||||
}
|
||||
|
||||
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);
|
||||
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()));
|
||||
}
|
||||
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;
|
||||
|
|
|
@ -47,9 +47,12 @@ class TelegramHdrParserImpl implements TelegramHdrParser {
|
|||
|
||||
if (typeIsNumeric && idIsNumeric) {
|
||||
try {
|
||||
teleHeader = new TelegramHdr(Integer.parseInt(type), version, Integer.parseInt(id));
|
||||
teleHeader = new TelegramHdr(Integer.parseInt(type), version,
|
||||
Integer.parseInt(id));
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.error("parsing telegram header failed, message: " + e.getMessage() + ", trace: " + Arrays.toString(e.getStackTrace()));
|
||||
LOG.error("parsing telegram header failed, message: "
|
||||
+ e.getMessage() + ", trace: "
|
||||
+ Arrays.toString(e.getStackTrace()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.swingbe.ifleet.parser;
|
||||
|
||||
import de.swingbe.ifleet.model.LocationMessage;
|
||||
import de.swingbe.ifleet.model.Telegram;
|
||||
import de.swingbe.ifleet.model.TelegramHdr;
|
||||
|
||||
|
@ -13,17 +12,12 @@ class TelegramParserImpl implements TelegramParser {
|
|||
|
||||
public Telegram parse(final String input) {
|
||||
|
||||
Telegram telegram = null;
|
||||
TelegramHdr teleHeader = TelegramHdrParserFactory.createTelegramHdrParser().parse(input);
|
||||
|
||||
String inputNew = popFieldFromCom(input, 3);
|
||||
|
||||
LocationMessage locationMessage = LocationMsgParserFactory.createLocationMsgParer().parse(inputNew);
|
||||
|
||||
if (teleHeader != null && locationMessage != null) {
|
||||
telegram = new Telegram(teleHeader, locationMessage);
|
||||
}
|
||||
return telegram;
|
||||
return new Telegram(teleHeader,
|
||||
LocationMsgParserFactory.createLocationMsgParer().parse(inputNew));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue