Search in sources :

Example 1 with PositionService

use of org.eclipse.kura.position.PositionService 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 2 with PositionService

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

the class GpsClockSyncProvider method init.

@Override
public void init(Map<String, Object> properties, ClockSyncListener listener) throws KuraException {
    s_logger.debug("initiing the GPS clock sync provider");
    this.m_properties = properties;
    this.m_listener = listener;
    this.m_waitForLocked = false;
    this.m_refreshInterval = 0;
    if (this.m_properties.containsKey("clock.ntp.refresh-interval")) {
        this.m_refreshInterval = (Integer) this.m_properties.get("clock.ntp.refresh-interval");
    }
    try {
        // looking for a valid PositionService from SCR
        BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
        ServiceReference<PositionService> scrServiceRef = bundleContext.getServiceReference(PositionService.class);
        this.m_positionService = bundleContext.getService(scrServiceRef);
        // install event listener for GPS locked event
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        String[] topic = { PositionLockedEvent.POSITION_LOCKED_EVENT_TOPIC };
        props.put(EventConstants.EVENT_TOPIC, topic);
        bundleContext.registerService(EventHandler.class.getName(), this, props);
    } catch (Exception e) {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Failed to initialize the GpsClockSyncProvider", e);
    }
    s_logger.debug("done initiing the GPS clock sync provider");
}
Also used : PositionService(org.eclipse.kura.position.PositionService) Hashtable(java.util.Hashtable) KuraException(org.eclipse.kura.KuraException) EventHandler(org.osgi.service.event.EventHandler) KuraException(org.eclipse.kura.KuraException) BundleContext(org.osgi.framework.BundleContext)

Example 3 with PositionService

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

the class GwtStatusServiceImpl method getPositionStatus.

private List<GwtGroupedNVPair> getPositionStatus() throws GwtKuraException {
    List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
    try {
        PositionService positionService = ServiceLocator.getInstance().getService(PositionService.class);
        if (positionService != null) {
            pairs.add(new GwtGroupedNVPair("positionStatus", "Longitude", Double.toString(Math.toDegrees(positionService.getPosition().getLongitude().getValue()))));
            pairs.add(new GwtGroupedNVPair("positionStatus", "Latitude", Double.toString(Math.toDegrees(positionService.getPosition().getLatitude().getValue()))));
            pairs.add(new GwtGroupedNVPair("positionStatus", "Altitude", positionService.getPosition().getAltitude().toString()));
        }
    } catch (GwtKuraException e) {
        s_logger.warn("Get position status failed", e);
        throw e;
    }
    return pairs;
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) PositionService(org.eclipse.kura.position.PositionService) ArrayList(java.util.ArrayList) GwtGroupedNVPair(org.eclipse.kura.web.shared.model.GwtGroupedNVPair)

Example 4 with PositionService

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

the class GpsClockSyncProvider method init.

@Override
public void init(Map<String, Object> properties, ClockSyncListener listener) throws KuraException {
    s_logger.debug("initiing the GPS clock sync provider");
    this.m_properties = properties;
    this.m_listener = listener;
    this.m_waitForLocked = false;
    this.m_refreshInterval = 0;
    if (this.m_properties.containsKey("clock.ntp.refresh-interval")) {
        this.m_refreshInterval = (Integer) this.m_properties.get("clock.ntp.refresh-interval");
    }
    try {
        // looking for a valid PositionService from SCR
        BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
        ServiceReference<PositionService> scrServiceRef = bundleContext.getServiceReference(PositionService.class);
        this.m_positionService = bundleContext.getService(scrServiceRef);
        // install event listener for GPS locked event
        Dictionary props = new Hashtable<String, String>();
        String[] topic = { PositionLockedEvent.POSITION_LOCKED_EVENT_TOPIC };
        props.put(EventConstants.EVENT_TOPIC, topic);
        bundleContext.registerService(EventHandler.class.getName(), this, props);
    } catch (Exception e) {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Failed to initialize the GpsClockSyncProvider", e);
    }
    s_logger.debug("done initiing the GPS clock sync provider");
}
Also used : Dictionary(java.util.Dictionary) PositionService(org.eclipse.kura.position.PositionService) Hashtable(java.util.Hashtable) KuraException(org.eclipse.kura.KuraException) EventHandler(org.osgi.service.event.EventHandler) KuraException(org.eclipse.kura.KuraException) BundleContext(org.osgi.framework.BundleContext)

Aggregations

PositionService (org.eclipse.kura.position.PositionService)4 Hashtable (java.util.Hashtable)2 KuraException (org.eclipse.kura.KuraException)2 BundleContext (org.osgi.framework.BundleContext)2 EventHandler (org.osgi.service.event.EventHandler)2 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)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 NmeaPosition (org.eclipse.kura.position.NmeaPosition)1 SystemAdminService (org.eclipse.kura.system.SystemAdminService)1 SystemService (org.eclipse.kura.system.SystemService)1 GwtKuraException (org.eclipse.kura.web.shared.GwtKuraException)1 GwtGroupedNVPair (org.eclipse.kura.web.shared.model.GwtGroupedNVPair)1