NMEA Java Library

Example OSGi Usage

Here is an example taken from a test case. You provide an InputStreamProvider that you may register as service just after you register the actual listener for wind measurements (so you will get notified).
public final class INMEAStreamProviderImplementation implements
		INMEAStreamProvider {

	private final String nmeaString;

	public INMEAStreamProviderImplementation(String nmeaString) {
		this.nmeaString = nmeaString;
	}

	@Override
	public InputStream getInputStream() {
		try {
			return new ByteArrayInputStream(nmeaString.getBytes("UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
}

public void testWind() throws IOException, InterruptedException {

	BundleContext bundleContext = NMEATestActivator.getDefault().getBundle().getBundleContext();
	IWindListener windListener = new IWindListener() {

		@Override
		public void notify(WindMeasurement m) {
			System.out.println(m.getAngle() + " " + m.getReference() + " " + m.getSpeed() + " " + m.getSpeedUnit());			
		}
	};
	ServiceRegistration windRegistration = bundleContext.registerService(
			IWindListener.class.getName(), windListener, new Properties());

	INMEAStreamProvider simpleStreamProvider = new INMEAStreamProviderImplementation(
			"$IIMWV,273,R,24.3,N,A*10\r\n");
	ServiceRegistration streamRegistration = bundleContext.registerService(
			INMEAStreamProvider.class.getName(), simpleStreamProvider,
			new Properties());

	windRegistration.unregister();
	streamRegistration.unregister();
}
	

Introduction
News
Features
Architecture
Downloads
Example
License
References
Legal Info
Sourceforge