re-established BATParser as proprietary extension, cleanly with the 0.9.0 marineapi

Change-Id: I48bc2de52838e20997ac50dea31dda270277a367
This commit is contained in:
Axel Uhl
2017-04-21 15:54:31 +02:00
parent df3ef78f77
commit 1026fcf044
7 changed files with 300 additions and 1 deletions
@@ -11,3 +11,4 @@ Require-Bundle: com.sap.sailing.domain,
com.sap.sailing.domain.common,
com.sap.sse.common,
net.sf.marineapi
Import-Package: org.osgi.framework
@@ -0,0 +1,61 @@
/*
* MWVSentence.java
* Copyright (C) 2011 Kimmo Tuukkanen
*
* This file is part of Java Marine API.
* <http://sourceforge.net/projects/marineapi/>
*
* Java Marine API is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Java Marine API is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Java Marine API. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sap.sailing.nmeaconnector;
import net.sf.marineapi.nmea.sentence.Sentence;
/**
* BAT sentence. Used for the proprietary NMEA extension of the SailTimer WindVane's battery indicator message.
* The format of the sentence is:<pre>
*
* $WIBAT,a,b*hh
*
* 1) Wind Vane Battery (0= Low, 1= Good)
* 2) Base Unit battery level (0 = Low, 9 = Good)
* 3) Checksum
* </pre>
*/
public interface BATSentence extends Sentence {
public static enum WindVaneBatteryStatus {
LOW(0), GOOD(1);
private final int value;
private WindVaneBatteryStatus(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
WindVaneBatteryStatus getWindVaneBatteryStatus();
void setWindVaneBatteryStatus(WindVaneBatteryStatus status);
/**
* Battery status is reported as value ranve 0..9 where 0 means "Low" and 9 means "Good."
*/
int getBaseUnitBatteryLevel();
void setBaseUnitBatteryLevel(int level);
}
@@ -6,6 +6,7 @@ import com.sap.sailing.domain.common.SpeedWithBearing;
import com.sap.sailing.domain.common.Wind;
import com.sap.sse.common.TimePoint;
import net.sf.marineapi.nmea.parser.SentenceFactory;
import net.sf.marineapi.nmea.sentence.MWVSentence;
import net.sf.marineapi.nmea.util.Units;
@@ -22,4 +23,16 @@ public interface NmeaUtil {
* checksum into a valid checksum again, and an invalid checksum into an invalid checksum.
*/
String replace(String nmeaSentence, String sequenceToFind, String replaceWith);
/**
* Call this to register proprietary parsers provided by this bundle with the
* {@link SentenceFactory} {@link SentenceFactory#getInstance() default instance}.
*/
void registerAdditionalParsers();
/**
* Call this to unregister proprietary parsers provided by this bundle from the
* {@link SentenceFactory} {@link SentenceFactory#getInstance() default instance}.
*/
void unregisterAdditionalParsers();
}
@@ -0,0 +1,27 @@
package com.sap.sailing.nmeaconnector.impl;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import com.sap.sailing.nmeaconnector.NmeaFactory;
import net.sf.marineapi.nmea.parser.SentenceFactory;
/**
* Registers and unregisters additional proprietary NMEA sentence parsers with the {@link SentenceFactory}
* {@link SentenceFactory#getInstance() default instance}.
*
* @author Axel Uhl (d043530)
*
*/
public class Activator implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
NmeaFactory.INSTANCE.getUtil().registerAdditionalParsers();
}
@Override
public void stop(BundleContext context) throws Exception {
NmeaFactory.INSTANCE.getUtil().unregisterAdditionalParsers();
}
}
@@ -0,0 +1,92 @@
/*
* MWVParser.java
* Copyright (C) 2011 Kimmo Tuukkanen
*
* This file is part of Java Marine API.
* <http://sourceforge.net/projects/marineapi/>
*
* Java Marine API is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Java Marine API is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Java Marine API. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sap.sailing.nmeaconnector.impl;
import com.sap.sailing.nmeaconnector.BATSentence;
import net.sf.marineapi.nmea.parser.SentenceParser;
import net.sf.marineapi.nmea.sentence.TalkerId;
/**
* BAT sentence parser. Used for the proprietary NMEA extension of the SailTimer WindVane's battery indicator message.
* The format of the sentence is:<pre>
*
* $WIBAT,a,b*hh
*
* 1) Wind Vane Battery (0= Low, 1= Good)
* 2) Base Unit battery level (0 = Low, 9 = Good)
* 3) Checksum
* </pre>
*
* @author Axel Uhl
*/
public class BATParser extends SentenceParser implements BATSentence {
private static final int WIND_VANE_BATTERY_STATUS = 0;
private static final int BASE_UNIT_BATTERY_LEVEL = 1;
/**
* Creates a new instance of BATParser.
*
* @param nmea MWV sentence String
*/
public BATParser(String nmea) {
super(nmea, /* Proprietary extension for SailTimer WindVane's battery indicator message */ "BAT");
}
/**
* Creates a new empty instance of BATParser.
*
* @param talker Talker id to set
*/
public BATParser(TalkerId talker) {
super(talker, /* Proprietary extension for SailTimer WindVane's battery indicator message */ "BAT", 2);
}
@Override
public WindVaneBatteryStatus getWindVaneBatteryStatus() {
WindVaneBatteryStatus result = null;
final int intValue = getIntValue(WIND_VANE_BATTERY_STATUS);
for (BATSentence.WindVaneBatteryStatus status : BATSentence.WindVaneBatteryStatus.values()) {
if (status.getValue() == intValue) {
result = status;
}
}
return result;
}
@Override
public int getBaseUnitBatteryLevel() {
return getIntValue(BASE_UNIT_BATTERY_LEVEL);
}
@Override
public void setWindVaneBatteryStatus(WindVaneBatteryStatus status) {
setIntValue(WIND_VANE_BATTERY_STATUS, status.getValue());
}
@Override
public void setBaseUnitBatteryLevel(int level) {
if (level < 0 || level > 9) {
throw new IllegalArgumentException("Level must be in the range 0..9 but was "+level);
}
setIntValue(BASE_UNIT_BATTERY_LEVEL, level);
}
}
@@ -14,11 +14,27 @@ import com.sap.sailing.domain.common.impl.WindImpl;
import com.sap.sailing.nmeaconnector.NmeaUtil;
import com.sap.sse.common.TimePoint;
import net.sf.marineapi.nmea.parser.SentenceFactory;
import net.sf.marineapi.nmea.sentence.MWVSentence;
import net.sf.marineapi.nmea.util.Units;
public class NmeaUtilImpl implements NmeaUtil {
@Override
public void registerAdditionalParsers() {
SentenceFactory sentenceFactory = SentenceFactory.getInstance();
if (!sentenceFactory.hasParser("BAT")) {
sentenceFactory.registerParser("BAT", BATParser.class);
}
}
@Override
public void unregisterAdditionalParsers() {
SentenceFactory sentenceFactory = SentenceFactory.getInstance();
if (sentenceFactory.hasParser("BAT")) {
sentenceFactory.unregisterParser(BATParser.class);
}
}
@Override
public Wind getWind(TimePoint timePoint, Position position, MWVSentence mwvSentence) {
return new WindImpl(position, timePoint, new KnotSpeedWithBearingImpl(mwvSentence.getSpeed(),