Skip to content

Commit

Permalink
feat(api): add getSupportedGpsModes() to modem status API (#5414)
Browse files Browse the repository at this point in the history
* feat(api): add getSupportedGpsModes() to modem status API

* feat(nm): populate newly introduced property

* build: fix rest.network.status.provider build

* test: add test for newly introduced property

* docs: add "since" annotation
mattdibi authored Oct 4, 2024
1 parent a847bfd commit 893fb10
Showing 7 changed files with 77 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ Export-Package: org.eclipse.kura;version="1.7.0",
org.eclipse.kura.net.status;version="1.1.0",
org.eclipse.kura.net.status.ethernet;version="1.0.0",
org.eclipse.kura.net.status.loopback;version="1.0.0",
org.eclipse.kura.net.status.modem;version="1.0.0",
org.eclipse.kura.net.status.modem;version="1.1.0",
org.eclipse.kura.net.status.vlan;version="1.0.0",
org.eclipse.kura.net.status.wifi;version="1.0.0",
org.eclipse.kura.net.vlan;version="1.0.0",
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
******************************************************************************/

package org.eclipse.kura.net.status.modem;

/*
* The GPS mode supported by the modem.
*
* @since 2.8
*/
public enum ModemGpsMode {
/*
* Unmanaged GPS mode. In this mode the GPS device of the modem will be setup but not directly managed, therefore
* freeing the serial port for other services to use.
*/
UNMANAGED,
/*
* Managed GPS mode. In this mode the GPS device of the modem will be setup and directly managed (typically by
* ModemManager) therefore the serial port won't be available for other services to use.
*/
MANAGED_GPS
}
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ public class ModemInterfaceStatus extends NetworkInterfaceStatus {
private final Set<ModemBand> supportedBands;
private final Set<ModemBand> currentBands;
private final boolean gpsSupported;
private final Set<ModemGpsMode> supportedGpsModes;
private final List<Sim> availableSims;
private final boolean simLocked;
private final List<Bearer> bearers;
@@ -75,6 +76,7 @@ private ModemInterfaceStatus(ModemInterfaceStatusBuilder builder) {
this.supportedBands = builder.supportedBands;
this.currentBands = builder.currentBands;
this.gpsSupported = builder.gpsSupported;
this.supportedGpsModes = builder.supportedGpsModes;
this.availableSims = builder.availableSims;
this.simLocked = builder.simLocked;
this.bearers = builder.bearers;
@@ -147,6 +149,13 @@ public Boolean isGpsSupported() {
return this.gpsSupported;
}

/*
* @since 2.8
*/
public Set<ModemGpsMode> getSupporteGpsModes() {
return this.supportedGpsModes;
}

public List<Sim> getAvailableSims() {
return this.availableSims;
}
@@ -209,6 +218,7 @@ public static class ModemInterfaceStatusBuilder extends NetworkInterfaceStatusBu
private Set<ModemBand> supportedBands = EnumSet.of(ModemBand.UNKNOWN);
private Set<ModemBand> currentBands = EnumSet.of(ModemBand.UNKNOWN);
private boolean gpsSupported = false;
private Set<ModemGpsMode> supportedGpsModes = Collections.emptySet();
private List<Sim> availableSims = Collections.emptyList();
private boolean simLocked = false;
private List<Bearer> bearers = Collections.emptyList();
@@ -296,6 +306,11 @@ public ModemInterfaceStatusBuilder withGpsSupported(Boolean gpsSupported) {
return getThis();
}

public ModemInterfaceStatusBuilder withSupportedGpsModes(Set<ModemGpsMode> supportedGpsModes) {
this.supportedGpsModes = supportedGpsModes;
return getThis();
}

public ModemInterfaceStatusBuilder withAvailableSims(List<Sim> availableSims) {
this.availableSims = availableSims;
return getThis();
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.nm/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ Import-Package: javax.xml.bind;version="2.3.3",
org.eclipse.kura.net.status;version="[1.1,1.2)",
org.eclipse.kura.net.status.ethernet;version="[1.0,2.0)",
org.eclipse.kura.net.status.loopback;version="[1.0,2.0)",
org.eclipse.kura.net.status.modem;version="[1.0,2.0)",
org.eclipse.kura.net.status.modem;version="[1.1,2.0)",
org.eclipse.kura.net.status.vlan;version="[1.0,2.0)",
org.eclipse.kura.net.status.wifi;version="[1.0,2.0)",
org.eclipse.kura.net.wifi;version="[2.4,3.0]",
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@
import org.eclipse.kura.net.status.modem.ESimStatus;
import org.eclipse.kura.net.status.modem.ModemBand;
import org.eclipse.kura.net.status.modem.ModemCapability;
import org.eclipse.kura.net.status.modem.ModemGpsMode;
import org.eclipse.kura.net.status.modem.ModemInterfaceStatus;
import org.eclipse.kura.net.status.modem.ModemInterfaceStatus.ModemInterfaceStatusBuilder;
import org.eclipse.kura.net.status.modem.ModemMode;
@@ -618,6 +619,7 @@ private static void setModemStatus(ModemInterfaceStatusBuilder builder, Optional
builder.withSupportedBands(getModemBands(properties, "SupportedBands"));
builder.withCurrentBands(getModemBands(properties, "CurrentBands"));
builder.withGpsSupported(isGpsSupported(properties));
builder.withSupportedGpsModes(getSupportedGpsModes(properties));
builder.withSimLocked(isSimLocked(properties));
builder.withConnectionStatus(MMModemState.toModemState(properties.Get(MM_MODEM_BUS_NAME, STATE)));
builder.withAccessTechnologies(MMModemAccessTechnology
@@ -704,6 +706,29 @@ private static boolean isGpsSupported(Properties properties) {
}
}

private static Set<ModemGpsMode> getSupportedGpsModes(Properties properties) {
try {
UInt32 locationSources = properties.Get(MM_MODEM_LOCATION_BUS_NAME, "Capabilities");
Set<MMModemLocationSource> modemLocationSources = MMModemLocationSource
.toMMModemLocationSourceFromBitMask(locationSources);

Set<ModemGpsMode> gpsModes = new HashSet<>();
if (modemLocationSources.contains(MMModemLocationSource.MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) {
gpsModes.add(ModemGpsMode.UNMANAGED);
}

if (modemLocationSources.contains(MMModemLocationSource.MM_MODEM_LOCATION_SOURCE_GPS_NMEA)
&& modemLocationSources.contains(MMModemLocationSource.MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
gpsModes.add(ModemGpsMode.MANAGED_GPS);
}

return gpsModes;
} catch (DBusExecutionException e) {
logger.debug("Cannot retrieve location object", e);
return Collections.emptySet();
}
}

private static boolean isSimLocked(Properties properties) {
boolean simLocked = true;
UInt32 simStatus = properties.Get(MM_MODEM_BUS_NAME, "UnlockRequired");
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ Import-Package: javax.annotation.security;version="1.2.0",
org.eclipse.kura.net.modem;version="[2.4,3.0)",
org.eclipse.kura.net.status;version="[1.1,1.2)",
org.eclipse.kura.net.status.ethernet;version="[1.0,1.1)",
org.eclipse.kura.net.status.modem;version="[1.0,1.1)",
org.eclipse.kura.net.status.modem;version="[1.1,1.2)",
org.eclipse.kura.net.status.wifi;version="[1.0,1.1)",
org.eclipse.kura.request.handler.jaxrs;version="[1.0,2.0)",
org.eclipse.kura.request.handler.jaxrs.annotation;version="[1.0,2.0)",
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@
import org.eclipse.kura.net.status.modem.ModemBand;
import org.eclipse.kura.net.status.modem.ModemCapability;
import org.eclipse.kura.net.status.modem.ModemConnectionStatus;
import org.eclipse.kura.net.status.modem.ModemGpsMode;
import org.eclipse.kura.net.status.modem.ModemInterfaceStatus;
import org.eclipse.kura.net.status.modem.ModemMode;
import org.eclipse.kura.net.status.modem.ModemModePair;
@@ -1704,6 +1705,7 @@ private void thenModemStatusHasCorrectValues(boolean hasBearers, boolean hasSims
assertTrue(modemStatus.getCurrentBands().contains(ModemBand.EUTRAN_10));
assertTrue(modemStatus.getCurrentBands().contains(ModemBand.EUTRAN_39));
assertTrue(modemStatus.isGpsSupported());
assertEquals(EnumSet.of(ModemGpsMode.UNMANAGED, ModemGpsMode.MANAGED_GPS), modemStatus.getSupporteGpsModes());
assertFalse(modemStatus.isSimLocked());
assertEquals(ModemConnectionStatus.REGISTERED, modemStatus.getConnectionStatus());
assertEquals(1, modemStatus.getAccessTechnologies().size());

0 comments on commit 893fb10

Please sign in to comment.