Package com.gmv.its.deepsy.hal.gnss

Classes

interface  Gnss
 Gnss. More...
 
interface  GnssEvent
 Gnss event. More...
 
interface  GnssInfo
 Gnss information. More...
 
class  GnssLowLevelException
 Gnss low level exception. More...
 
interface  GnssManager
 Gnss Manager. More...
 
class  GnssNotAvailableException
 Gnss not available exception. More...
 
class  GnssObserver
 Gnss observer. More...
 
interface  GnssPosition
 Gnss position. More...
 
interface  GnssPowerStatus
 Gnss Power status. More...
 
enum  GnssQualityIndicator
 
class  GnssStatus
 indicates gnss status More...
 
enum  GnssSwResetType
 indicates gnss software reset type More...
 
interface  NewPositionEvent
 New position event. More...
 
interface  PeriodicStatusEvent
 Periodic status event. More...
 

Detailed Description

To work with Deepsy gnss service it is necessary to use DeepsyGnssManager located in com.gmv.its.deepsy.gnss for getting the initial GnssManager object.

GnssManager gnssManager = DeepsyGnssManager.getInstance();


DeepsyGnssManager.getInstance has an optional parameter indicating the ip address of remote service. For instance:

GnssManager gnssManager = DeepsyGnssManager.getInstance("192.168.1.10");


GnssManager is an AutoCloseable interface. An object that may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur. To obtain a Gnss object:

try (GnssManager gnssManager = DeepsyGnssManager.getInstance("192.168.1.10")){
Gnss gnss = gnssManager.getGnss();
} catch (GnssNotAvailableException e) {
e.printStackTrace();
} catch (GnssLowLevelException e) {
e.printStackTrace();
}


If this object is not inside a try with resources block, it is recommended to call to gnssManager.close() in order to finalize properly;

gnssManager.close();

Service availability

To detect service availability the DeepsyGnssManager implements Manager interface which provides methods for getting availability and subscribing to availability events.

class MyManagerObserver implements ManagerObserver{
public void notify(ManagerConnectionEvent event) {
System.out.println(event.getManager().getName() + " in "+ event.getManager().getIp() + " "+ event.getAction().toString());
}
}
public class App {
public static void main(String[] args) {
ManagerObserver observer = new MyManagerObserver();
try (GnssManager gnssManager = DeepsyGnssManager.getInstance()){
gnssManager.subscribe(observer);
} catch (CannotSubscribeException e1) {
e1.printStackTrace();
}
}
}


Examples

Get Gnss Position and Date

package com.gmv.its.dpyjavaexamples.gnss;
import com.gmv.its.deepsy.gnss.DeepsyGnssManager;
import com.gmv.its.deepsy.hal.gnss.*;
import java.time.Instant;
public class GetPositionApp {
public static void main(String[] args) {
try (GnssManager gnssManager = DeepsyGnssManager.getInstance("192.168.0.144")) {
Gnss gnss = gnssManager.getGnss();
Instant date = gnss.getInstant();
System.out.println(date.toString());
GnssPosition position = gnss.getLastPosition();
System.out.println(position.getLatitude() + ", " + position.getLongitude());
} catch (GnssNotAvailableException e) {
e.printStackTrace();
} catch (GnssLowLevelException e) {
e.printStackTrace();
}
}
}


Get Gnss Status

package com.gmv.its.dpyjavaexamples.gnss;
import java.time.Instant;
import com.gmv.its.deepsy.gnss.DeepsyGnssManager;
import com.gmv.its.deepsy.hal.gnss.*;
public class GetGnssStatusApp {
public static void main(String[] args) {
try (GnssManager gnssManager = DeepsyGnssManager.getInstance("192.168.0.144")) {
Gnss gnss = gnssManager.getGnss();
GnssStatus status = gnss.getStatus();
System.out.println("Quality: " + "--> " + status.getQuality().value());
System.out.println("AntennaStatus: " + "--> " + status.getAntennaStatus().value());
System.out.println("PowerStatus: " + "--> " + status.getPowerStatus().value());
System.out.println("SimulationModeActive: " + "--> " + status.getSimulationModeActive());
} catch (GnssNotAvailableException e) {
e.printStackTrace();
} catch (GnssLowLevelException e) {
e.printStackTrace();
}
}
}


Get Gnss Information

package com.gmv.its.dpyjavaexamples.gnss;
import java.time.Instant;
import com.gmv.its.deepsy.gnss.DeepsyGnssManager;
import com.gmv.its.deepsy.hal.gnss.*;
public class GetGnssInfoApp {
public static void main(String[] args) {
try (GnssManager gnssManager = DeepsyGnssManager.getInstance("192.168.0.144")) {
Gnss gnss = gnssManager.getGnss();
String manufacturer = gnss.getModuleInfo(GnssInfo.MANUFACTURER);
System.out.println("MANUFACTURER: " + "--> " + manufacturer);
String model = gnss.getModuleInfo(GnssInfo.MODEL);
System.out.println("MODEL: " + "--> " + model);
String fwVersion = gnss.getModuleInfo(GnssInfo.FW_VERSION);
System.out.println("FW VERSION: " + "--> " + fwVersion);
String protocolVersion = gnss.getModuleInfo(GnssInfo.PROTOCOL_VERSION);
System.out.println("PROTOCOL VERSION: " + "--> " + protocolVersion);
} catch (GnssNotAvailableException e) {
e.printStackTrace();
} catch (GnssLowLevelException e) {
e.printStackTrace();
}
}
}


Subscribe to Gnss positions and status

package com.gmv.its.dpyjavaexamples.gnss;
import com.gmv.its.deepsy.gnss.DeepsyGnssManager;
import com.gmv.its.deepsy.hal.gnss.*;
class MyGnssObserver extends GnssObserver {
@Override
public void notifyNewPosition(NewPositionEvent event) {
GnssPosition position = ((NewPositionEvent) event).getPosition();
System.out.println("->" + position.getLatitude() + ", " + position.getLongitude());
}
@Override
public void notifyPeriodicStatus(PeriodicStatusEvent event) {
GnssStatus status = ((PeriodicStatusEvent) event).getStatus();
System.out.println("->" + status.getQuality() + ", " + status.getAntennaStatus() + ", "
+ status.getAntennaStatus() + ", " + status.getPowerStatus() + ", " + status.getSimulationModeActive());
}
}
public class PositionEventsApp {
public static void main(String[] args) {
try (GnssManager gnssManager = DeepsyGnssManager.getInstance("192.168.0.144")){
Gnss gnss = gnssManager.getGnss();
gnss.subscribe(new MyGnssObserver());
Thread.sleep(10000);
} catch (GnssNotAvailableException e) {
e.printStackTrace();
} catch (GnssLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}


Perform a cold start

package com.gmv.its.dpyjavaexamples.gnss;
import java.time.Instant;
import com.gmv.its.deepsy.gnss.DeepsyGnssManager;
import com.gmv.its.deepsy.hal.gnss.*;
public class PerformColdStart {
public static void main(String[] args) {
try (GnssManager gnssManager = DeepsyGnssManager.getInstance("192.168.0.125")) {
Gnss gnss = gnssManager.getGnss();
gnss.performSoftwareReset(GnssSwResetType.COLDSTART);
System.out.println("SoftwareReset operation successfully finished");
} catch (GnssNotAvailableException e) {
e.printStackTrace();
} catch (GnssLowLevelException e) {
e.printStackTrace();
}
}
}


Create a virual odometer

package com.gmv.its.dpyjavaexamples.gnss;
import com.gmv.its.deepsy.gnss.DeepsyGnssManager;
import com.gmv.its.deepsy.hal.gnss.*;
class VirtualOdometer extends GnssObserver {
private static final double EARTH_RADIUS_KM = 6371.0;
private static final double M_PI = 3.141592;
private static double lastLon=0, lastLat=0;
private double distance = 0;
double getDistance(){
return distance;
}
void resetDistance(){
distance = 0;
lastLat=0;
lastLon=0;
}
double distanceEarth(double lat1, double lon1, double lat2, double lon2)
{
double lat1r, lon1r, lat2r, lon2r, u, v;
lat1r = lat1 * M_PI / 180;
lon1r = lon1 * M_PI / 180;
lat2r = lat2 * M_PI / 180;
lon2r = lon2 * M_PI / 180;
u = Math.sin((lat2r - lat1r) / 2);
v = Math.sin((lon2r - lon1r) / 2);
return 2.0 * EARTH_RADIUS_KM * Math.asin(Math.sqrt(u * u + Math.cos(lat1r) * Math.cos(lat2r) * v * v)) * 1000;
}
@Override
public void notifyNewPosition(NewPositionEvent event) {
GnssPosition position = ((NewPositionEvent) event).getPosition();
if(position.getQuality() != GnssQualityIndicator.NOFIX){
if(lastLat!=0 && lastLon!=0){
double d = distanceEarth(lastLat,lastLon,position.getLatitude(),position.getLongitude());
if(d > 20){ //20 meters for avoiding GPS bouncing
distance += d;
}
}
lastLat=position.getLatitude();
lastLon=position.getLongitude();
}
}
@Override
public void notifyPeriodicStatus(PeriodicStatusEvent event) {
}
}
public class OdometerApp {
public static void main(String[] args) {
try (GnssManager gnssManager = DeepsyGnssManager.getInstance("192.168.0.144")){
Gnss gnss = gnssManager.getGnss();
VirtualOdometer odom = new VirtualOdometer();
gnss.subscribe(odom);
Thread.sleep(30000);
System.out.println("Distance traveled last 30 seconds " + odom.getDistance() + " meters.");
} catch (Exception e) {
e.printStackTrace();
}
}
}