Search in sources :

Example 1 with NmeaPosition

use of org.eclipse.kura.position.NmeaPosition in project kura by eclipse.

the class PositionServiceImpl method updateGps.

private void updateGps() {
    s_logger.debug("GPS Emulator index: {}", this.index);
    if (this.index + 1 == this.gpsPoints.length) {
        s_logger.debug("GPS Emulator - wrapping index");
        this.index = 0;
    }
    Measurement latitude = new Measurement(java.lang.Math.toRadians(this.gpsPoints[this.index].getLatitude()), Unit.rad);
    Measurement longitude = new Measurement(java.lang.Math.toRadians(this.gpsPoints[this.index].getLongitude()), Unit.rad);
    Measurement altitude = new Measurement(this.gpsPoints[this.index].getAltitude(), Unit.m);
    s_logger.debug("Updating lat/long/altitude: " + latitude + "/" + longitude + "/" + altitude);
    // Measurement lat, Measurement lon, Measurement alt, Measurement speed, Measurement track
    this.currentTime = new Date();
    this.currentPosition = new Position(latitude, longitude, altitude, null, null);
    this.currentNmeaPosition = new NmeaPosition(this.gpsPoints[this.index].getLatitude(), this.gpsPoints[this.index].getLongitude(), this.gpsPoints[this.index].getAltitude(), 0, 0);
    this.index++;
    return;
}
Also used : Measurement(org.osgi.util.measurement.Measurement) NmeaPosition(org.eclipse.kura.position.NmeaPosition) NmeaPosition(org.eclipse.kura.position.NmeaPosition) Position(org.osgi.util.position.Position) Date(java.util.Date)

Example 2 with NmeaPosition

use of org.eclipse.kura.position.NmeaPosition in project kura by eclipse.

the class LifeCyclePayloadBuilder method buildDeviceProfile.

public KuraDeviceProfile buildDeviceProfile() {
    SystemService systemService = this.m_cloudServiceImpl.getSystemService();
    SystemAdminService sysAdminService = this.m_cloudServiceImpl.getSystemAdminService();
    NetworkService networkService = this.m_cloudServiceImpl.getNetworkService();
    PositionService positionService = this.m_cloudServiceImpl.getPositionService();
    // 
    // get the network information
    StringBuilder sbConnectionIp = null;
    StringBuilder sbConnectionInterface = null;
    try {
        List<NetInterface<? extends NetInterfaceAddress>> nis = networkService.getActiveNetworkInterfaces();
        if (!nis.isEmpty()) {
            sbConnectionIp = new StringBuilder();
            sbConnectionInterface = new StringBuilder();
            for (NetInterface<? extends NetInterfaceAddress> ni : nis) {
                List<? extends NetInterfaceAddress> nias = ni.getNetInterfaceAddresses();
                if (nias != null && !nias.isEmpty()) {
                    sbConnectionInterface.append(buildConnectionInterface(ni)).append(",");
                    sbConnectionIp.append(buildConnectionIp(ni)).append(",");
                }
            }
            // Remove trailing comma
            sbConnectionIp.deleteCharAt(sbConnectionIp.length() - 1);
            sbConnectionInterface.deleteCharAt(sbConnectionInterface.length() - 1);
        }
    } catch (Exception se) {
        s_logger.warn("Error while getting ConnetionIP and ConnectionInterface", se);
    }
    String connectionIp = sbConnectionIp != null ? sbConnectionIp.toString() : "UNKNOWN";
    String connectionInterface = sbConnectionInterface != null ? sbConnectionInterface.toString() : "UNKNOWN";
    // 
    // get the network information
    // String primaryNetInterface = systemService.getPrimaryNetworkInterfaceName();
    // String connectionIp = UNKNOWN;
    // String connectionInterface = UNKNOWN;
    // try {
    // List<NetInterface<? extends NetInterfaceAddress>> nis = networkService.getActiveNetworkInterfaces();
    // if (!nis.isEmpty()) {
    // 
    // // look for the primary network interface first
    // for (NetInterface<? extends NetInterfaceAddress> ni : nis) {
    // if (ni.getName().equals(primaryNetInterface)) {
    // List<? extends NetInterfaceAddress> nias = ni.getNetInterfaceAddresses();
    // if (nias != null && !nias.isEmpty()) {
    // connectionInterface = buildConnectionInterface(ni);
    // connectionIp = buildConnectionIp(ni);
    // break;
    // }
    // }
    // }
    // 
    // // if not resolved, loop through all network interfaces until we find one with an address
    // if (UNKNOWN.equals(connectionIp) || UNKNOWN.equals(connectionInterface)) {
    // s_logger.warn("Unresolved connectionIp for primary Network Interface. Looping through all interfaces...");
    // for (NetInterface<? extends NetInterfaceAddress> ni : nis) {
    // List<? extends NetInterfaceAddress> nias = ni.getNetInterfaceAddresses();
    // if (nias != null && !nias.isEmpty()) {
    // connectionInterface = buildConnectionInterface(ni);
    // connectionIp = buildConnectionIp(ni);
    // break;
    // }
    // }
    // }
    // }
    // 
    // if (UNKNOWN.equals(connectionIp) || UNKNOWN.equals(connectionInterface)) {
    // s_logger.warn("Unresolved NetworkService reference or IP address. Defaulting to JVM Networking
    // Information.");
    // InetAddress addr = NetUtil.getCurrentInetAddress();
    // if (addr != null) {
    // connectionIp = addr.getHostAddress();
    // NetworkInterface netInterface = NetworkInterface.getByInetAddress(addr);
    // if (netInterface != null) {
    // connectionInterface = NetUtil.hardwareAddressToString(netInterface.getHardwareAddress());
    // }
    // }
    // }
    // }
    // catch (Exception se) {
    // s_logger.warn("Error while getting ConnetionIP and ConnectionInterface", se);
    // }
    // 
    // get the position information
    double latitude = 0.0;
    double longitude = 0.0;
    double altitude = 0.0;
    if (positionService != null) {
        NmeaPosition position = positionService.getNmeaPosition();
        if (position != null) {
            latitude = position.getLatitude();
            longitude = position.getLongitude();
            altitude = position.getAltitude();
        } else {
            s_logger.warn("Unresolved PositionService reference.");
        }
    }
    // 
    // build the profile
    KuraDeviceProfile KuraDeviceProfile = new KuraDeviceProfile(sysAdminService.getUptime(), systemService.getDeviceName(), systemService.getModelName(), systemService.getModelId(), systemService.getPartNumber(), systemService.getSerialNumber(), systemService.getFirmwareVersion(), systemService.getBiosVersion(), systemService.getOsName(), systemService.getOsVersion(), systemService.getJavaVmName(), systemService.getJavaVmVersion() + " " + systemService.getJavaVmInfo(), systemService.getJavaVendor() + " " + systemService.getJavaVersion(), systemService.getKuraVersion(), connectionInterface, connectionIp, latitude, longitude, altitude, String.valueOf(systemService.getNumberOfProcessors()), String.valueOf(systemService.getTotalMemory()), systemService.getOsArch(), systemService.getOsgiFwName(), systemService.getOsgiFwVersion());
    return KuraDeviceProfile;
}
Also used : SystemAdminService(org.eclipse.kura.system.SystemAdminService) NmeaPosition(org.eclipse.kura.position.NmeaPosition) PositionService(org.eclipse.kura.position.PositionService) SystemService(org.eclipse.kura.system.SystemService) NetInterface(org.eclipse.kura.net.NetInterface) KuraDeviceProfile(org.eclipse.kura.core.message.KuraDeviceProfile) NetInterfaceAddress(org.eclipse.kura.net.NetInterfaceAddress) NetworkService(org.eclipse.kura.net.NetworkService)

Example 3 with NmeaPosition

use of org.eclipse.kura.position.NmeaPosition in project kura by eclipse.

the class PositionServiceImpl method initializeDefaultPosition.

private void initializeDefaultPosition(double lat, double lon, double alt) {
    Measurement l_latitude = new Measurement(java.lang.Math.toRadians(lat), Unit.rad);
    Measurement l_longitude = new Measurement(java.lang.Math.toRadians(lon), Unit.rad);
    Measurement l_altitude = new Measurement(alt, Unit.m);
    // conversion speed in knots to m/s : 1 m/s = 1.94384449
    Measurement l_speed = new Measurement(0, Unit.m_s);
    // knots
    Measurement l_track = new Measurement(java.lang.Math.toRadians(0), Unit.rad);
    double l_latitudeNmea = lat;
    double l_longitudeNmea = lon;
    double l_altitudeNmea = alt;
    double l_speedNmea = 0;
    double l_trackNmea = 0;
    int l_fixQuality = 0;
    int l_nrSatellites = 0;
    double l_DOP = 0;
    double l_PDOP = 0;
    double l_HDOP = 0;
    double l_VDOP = 0;
    int l_3Dfix = 0;
    this.m_defaultPosition = new Position(l_latitude, l_longitude, l_altitude, l_speed, l_track);
    this.m_defaultNmeaPosition = new NmeaPosition(l_latitudeNmea, l_longitudeNmea, l_altitudeNmea, l_speedNmea, l_trackNmea, l_fixQuality, l_nrSatellites, l_DOP, l_PDOP, l_HDOP, l_VDOP, l_3Dfix);
    this.m_GpsdPosition = new Position(l_latitude, l_longitude, l_altitude, l_speed, l_track);
    this.m_GpsdNmeaPosition = new NmeaPosition(l_latitudeNmea, l_longitudeNmea, l_altitudeNmea, l_speedNmea, l_trackNmea, l_fixQuality, l_nrSatellites, l_DOP, l_PDOP, l_HDOP, l_VDOP, l_3Dfix);
}
Also used : Measurement(org.osgi.util.measurement.Measurement) NmeaPosition(org.eclipse.kura.position.NmeaPosition) NmeaPosition(org.eclipse.kura.position.NmeaPosition) Position(org.osgi.util.position.Position)

Aggregations

NmeaPosition (org.eclipse.kura.position.NmeaPosition)3 Measurement (org.osgi.util.measurement.Measurement)2 Position (org.osgi.util.position.Position)2 Date (java.util.Date)1 KuraDeviceProfile (org.eclipse.kura.core.message.KuraDeviceProfile)1 NetInterface (org.eclipse.kura.net.NetInterface)1 NetInterfaceAddress (org.eclipse.kura.net.NetInterfaceAddress)1 NetworkService (org.eclipse.kura.net.NetworkService)1 PositionService (org.eclipse.kura.position.PositionService)1 SystemAdminService (org.eclipse.kura.system.SystemAdminService)1 SystemService (org.eclipse.kura.system.SystemService)1