Skip to content

Commit

Permalink
feat: add GPS Mode selector in modem UI [backport 5.6.0] (#5435)
Browse files Browse the repository at this point in the history
* feat: add GPS Mode selector

* docs: add tooltips and descriptions

* style: "_" instead of "-"

* feat: correctly apply configuration based on multi-selection list

* fix: correclty enable mode selector

* refactor: simplify code

* refactor: use constants

* fix: correctly enable dropdown from enabled GPS status

* refactor: more readable constants names

* refactor: more consistent style with respect to rest of codebase

* fix: correct reset() method

* fix: correctly update UI on startup

* refactor: simplify dropdown selection and settings conversion

* revert: whitespaces in NetworkConfigurationServiceProperties

* feat: disable options based off MM support

* fix: use correct type

* feat: first working version of dropdown menu

* refactor: invert logic and iterate

* refactor: iterate for improved extensibility

* refactor: improve name STATUS_GPS_MODES -> AVAIL_GPS_MODES

* feat: only show dropdown if isNet2
  • Loading branch information
mattdibi authored Oct 15, 2024
1 parent e3ad041 commit 2f25933
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 18 deletions.
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.web2/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Import-Package: com.eclipsesource.json;version="0.9.5",
org.eclipse.kura.net.modem;version="[2.2,3.0)",
org.eclipse.kura.net.status;version="[1.0,2.0)",
org.eclipse.kura.net.status.ethernet;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.vlan;version="[1.0,2.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void initModemTab(final boolean isNet2) {

private void initModemGpsTab() {
this.modemGpsTabAnchorItem = new AnchorListItem(MSGS.netModemGps());
this.modemGpsTab = new TabModemGpsUi(this.session, this);
this.modemGpsTab = new TabModemGpsUi(this.session, this, isNet2);

this.modemGpsTabAnchorItem.addClickHandler(event -> {
setSelected(NetworkTabsUi.this.modemGpsTabAnchorItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*******************************************************************************/
package org.eclipse.kura.web.client.ui.network;

import java.util.Arrays;
import java.util.List;

import org.eclipse.kura.web.client.messages.Messages;
import org.eclipse.kura.web.client.util.HelpButton;
import org.eclipse.kura.web.shared.model.GwtModemInterfaceConfig;
Expand All @@ -20,6 +23,7 @@
import org.gwtbootstrap3.client.ui.FieldSet;
import org.gwtbootstrap3.client.ui.FormLabel;
import org.gwtbootstrap3.client.ui.InlineRadio;
import org.gwtbootstrap3.client.ui.ListBox;
import org.gwtbootstrap3.client.ui.PanelHeader;
import org.gwtbootstrap3.client.ui.html.Span;

Expand All @@ -39,20 +43,33 @@ interface TabModemGpsUiUiBinder extends UiBinder<Widget, TabModemGpsUi> {

private static final Messages MSGS = GWT.create(Messages.class);

// Note: index of AVAIL_GPS_MODES and CONFIG_GPS_MODES must match!
// Strings used for the dropdown (item text) and that match the ModemGpsMode enum in the Kura API
private static final List<String> AVAIL_GPS_MODES = Arrays.asList("UNMANAGED", "MANAGED_GPS");
// Strings used for the configuration (i.e. that will be written in the sanpshot) and set as dropdown values
private static final List<String> CONFIG_GPS_MODES = Arrays.asList("kuraModemGpsModeUnmanaged",
"kuraModemGpsModeManagedGps");

private final GwtSession session;
private final NetworkTabsUi tabs;
private final boolean isNet2;
private boolean dirty;
GwtModemInterfaceConfig selectedModemIfConfig;
boolean formInitialized;

@UiField
FormLabel labelGps;
@UiField
FormLabel labelGpsMode;

@UiField
InlineRadio radio1;
@UiField
InlineRadio radio2;

@UiField
ListBox gpsMode;

@UiField
PanelHeader helpTitle;

Expand All @@ -65,7 +82,11 @@ interface TabModemGpsUiUiBinder extends UiBinder<Widget, TabModemGpsUi> {
@UiField
HelpButton gpsHelp;

public TabModemGpsUi(GwtSession currentSession, NetworkTabsUi tabs) {
@UiField
HelpButton gpsModeHelp;

public TabModemGpsUi(GwtSession currentSession, NetworkTabsUi tabs, boolean isNet2) {
this.isNet2 = isNet2;
initWidget(uiBinder.createAndBindUi(this));
this.session = currentSession;
this.tabs = tabs;
Expand Down Expand Up @@ -105,9 +126,11 @@ public void getUpdatedNetInterface(GwtNetInterfaceConfig updatedNetIf) {
GwtModemInterfaceConfig updatedModemNetIf = (GwtModemInterfaceConfig) updatedNetIf;
if (this.formInitialized) {
updatedModemNetIf.setGpsEnabled(this.radio1.getValue());
updatedModemNetIf.setGpsMode(this.gpsMode.getSelectedValue());
} else {
// initForm hasn't been called yet
updatedModemNetIf.setGpsEnabled(this.selectedModemIfConfig.isGpsEnabled());
updatedModemNetIf.setGpsMode(this.selectedModemIfConfig.getGpsMode());
}
}

Expand Down Expand Up @@ -146,14 +169,44 @@ private void initForm() {
}
});
this.radio2.addMouseOutHandler(event -> resetHelp());
this.radio1.addValueChangeHandler(event -> setDirty(true));
this.radio2.addValueChangeHandler(event -> setDirty(true));
this.radio1.addValueChangeHandler(event -> {
setDirty(true);
this.gpsMode.setEnabled(this.radio1.getValue());
});
this.radio2.addValueChangeHandler(event -> {
setDirty(true);
this.gpsMode.setEnabled(this.radio1.getValue());
});

this.helpTitle.setText(MSGS.netHelpTitle());
this.radio1.setText(MSGS.trueLabel());
this.radio2.setText(MSGS.falseLabel());
this.radio1.setValue(true);
this.radio2.setValue(false);

// GPS Mode
if (this.isNet2) {
this.labelGpsMode.setText(MSGS.netModemGpsMode());
this.gpsMode.clear();

for (String mode : AVAIL_GPS_MODES) {
this.gpsMode.addItem(mode, CONFIG_GPS_MODES.get(AVAIL_GPS_MODES.indexOf(mode)));
this.gpsMode.getElement().getElementsByTagName("option").getItem(AVAIL_GPS_MODES.indexOf(mode))
.setAttribute("disabled", "disabled");
}

this.gpsMode.addMouseOverHandler(event -> {
TabModemGpsUi.this.helpText.clear();
TabModemGpsUi.this.helpText.add(new Span(MSGS.netModemToolTipGpsMode()));
});
this.gpsMode.addMouseOutHandler(event -> resetHelp());
this.gpsMode.addChangeHandler(event -> setDirty(true));

} else {
this.labelGpsMode.setVisible(false);
this.gpsMode.setVisible(false);
}

this.formInitialized = true;
}

Expand All @@ -164,32 +217,38 @@ private void resetHelp() {

private void update() {
if (this.selectedModemIfConfig != null) {
if (this.selectedModemIfConfig.isGpsEnabled()) {
this.radio1.setValue(true);
this.radio2.setValue(false);
} else {
this.radio1.setValue(false);
this.radio2.setValue(true);
this.radio1.setValue(this.selectedModemIfConfig.isGpsEnabled());
this.radio2.setValue(!this.selectedModemIfConfig.isGpsEnabled());

for (int i = 0; i < this.gpsMode.getItemCount(); i++) {
if (this.gpsMode.getValue(i).equals(this.selectedModemIfConfig.getGpsMode())) {
this.gpsMode.setSelectedIndex(i);
break;
}
}
}
refreshForm();
}

private void refreshForm() {
if (this.selectedModemIfConfig != null) {
if (this.selectedModemIfConfig.isGpsSupported()) {
this.radio1.setEnabled(true);
this.radio2.setEnabled(true);
} else {
this.radio1.setEnabled(false);
this.radio2.setEnabled(false);
this.radio1.setEnabled(this.selectedModemIfConfig.isGpsSupported());
this.radio2.setEnabled(this.selectedModemIfConfig.isGpsSupported());

for (int i = 0; i < this.gpsMode.getItemCount(); i++) {
if (this.selectedModemIfConfig.getSupportedGpsModes().contains(this.gpsMode.getItemText(i))) {
this.gpsMode.getElement().getElementsByTagName("option").getItem(i).removeAttribute("disabled");
}
}
}

this.gpsMode.setEnabled(this.radio1.getValue());
}

private void reset() {
this.radio1.setValue(true);
this.radio2.setValue(false);
this.gpsMode.setSelectedIndex(0); // UNMANAGED
update();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
</g:FlowPanel>
</b:FormGroup>

<b:FormGroup>
<b:FormLabel for="gpsMode" ui:field="labelGpsMode"></b:FormLabel>
<util:HelpButton ui:field="gpsModeHelp" />
<g:FlowPanel>
<b:ListBox b:id="gpsMode" ui:field="gpsMode" />
</g:FlowPanel>
</b:FormGroup>

</b:FieldSet>
</b:Form>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ private void setModemProperties() {
gwtModemConfig.setLcpEchoInterval(this.properties.getModemLpcEchoInterval(this.ifName));
gwtModemConfig.setLcpEchoFailure(this.properties.getModemLpcEchoFailure(this.ifName));
gwtModemConfig.setGpsEnabled(this.properties.getModemGpsEnabled(this.ifName));
gwtModemConfig.setGpsMode(this.properties.getModemGpsMode(ifName));
gwtModemConfig.setDiversityEnabled(this.properties.getModemDiversityEnabled(this.ifName));
gwtModemConfig.setApn(this.properties.getModemApn(this.ifName));
gwtModemConfig.setModemId(this.properties.getUsbProductName(this.ifName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ public void setWifiInfraRadioMode(String ifname, Optional<String> mode) {
private static final String NET_INTERFACE_CONFIG_DIVERSITY_ENABLED = "net.interface.%s.config.diversityEnabled";
private static final String NET_INTERFACE_CONFIG_RESET_TIMEOUT = "net.interface.%s.config.resetTimeout";
private static final String NET_INTERFACE_CONFIG_GPS_ENABLED = "net.interface.%s.config.gpsEnabled";
private static final String NET_INTERFACE_CONFIG_GPS_MODE = "net.interface.%s.config.gpsMode";
private static final String NET_INTERFACE_CONFIG_PERSIST = "net.interface.%s.config.persist";
private static final String NET_INTERFACE_CONFIG_APN = "net.interface.%s.config.apn";
private static final String NET_INTERFACE_CONFIG_DIAL_STRING = "net.interface.%s.config.dialString";
Expand Down Expand Up @@ -718,6 +719,15 @@ public void setModemGpsEnabled(String ifname, boolean isGpsEnabled) {
this.properties.put(String.format(NET_INTERFACE_CONFIG_GPS_ENABLED, ifname), isGpsEnabled);
}

public String getModemGpsMode(String ifname) {
return (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_GPS_MODE, ifname),
"kuraModemGpsModeUnmanaged");
}

public void setModemGpsMode(String ifname, String gpsMode) {
this.properties.put(String.format(NET_INTERFACE_CONFIG_GPS_MODE, ifname), gpsMode);
}

public boolean getModemPersistEnabled(String ifname) {
return (boolean) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_PERSIST, ifname), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ private void setModemGpsProperties() {
GwtModemInterfaceConfig gwtModemConfig = (GwtModemInterfaceConfig) this.gwtConfig;

this.properties.setModemGpsEnabled(this.ifname, gwtModemConfig.isGpsEnabled());
this.properties.setModemGpsMode(this.ifname, gwtModemConfig.getGpsMode());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ private void setModemStateProperties(GwtNetInterfaceConfig gwtConfig, NetworkInt
gwtModemConfig.setManufacturer(ellipsis(modemInterfaceInfo.getManufacturer(), 20));
gwtModemConfig.setModemId(modemInterfaceInfo.getModel());
gwtModemConfig.setGpsSupported(modemInterfaceInfo.isGpsSupported());
gwtModemConfig.setSupportedGpsModes(
modemInterfaceInfo.getSupporteGpsModes().stream().map(Enum::name).collect(Collectors.toList()));
gwtModemConfig.setHwFirmware(modemInterfaceInfo.getFirmwareVersion());
gwtModemConfig.setConnectionType(modemInterfaceInfo.getConnectionType().toString());
gwtModemConfig.setNetworkTechnology(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ public void setGpsEnabled(boolean gpsEnabled) {
set("gpsEnabled", gpsEnabled);
}

public void setGpsMode(String gpsMode) {
set("gpsMode", gpsMode);
}

public String getGpsMode() {
return get("gpsMode");
}

public boolean isGpsSupported() {
if (get("gpsSupported") != null) {
return (Boolean) get("gpsSupported");
Expand All @@ -266,6 +274,14 @@ public void setGpsSupported(boolean gpsSupported) {
set("gpsSupported", gpsSupported);
}

public void setSupportedGpsModes(List<String> list) {
set("gpsSupportedModes", list);
}

public List<String> getSupportedGpsModes() {
return get("gpsSupportedModes");
}

public boolean isDiversityEnabled() {
if (get(DIVERSITY_ENABLED_KEY) != null) {
return (Boolean) get(DIVERSITY_ENABLED_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ netModemInvalidLcpEchoInterval="LCP Echo Interval" must be set to either 0 or po
netModemLcpEchoFailure=LCP Echo Failure
netModemInvalidLcpEchoFailure="LCP Echo Failure" must be set to either 0 or positive integer.
netModemEnableGps=Enable GPS
netModemGpsMode=GPS Mode
netModemToolTipNetworkTopology=Select the appropriate network topology.
netModemToolTipModemIndentifier=Enter a unique name for the modem.
netModemToolTipModemInterfaceNumber=A unique number that identifies a modem interface. For example: <br><br>An Interface # of 0 would name the modem interface ppp0<br><br>An Interface # of 1 would name the modem interface ppp1
Expand All @@ -719,7 +720,8 @@ netModemToolTipIdle=Sets the <i>idle</i> option of the PPP daemon which makes it
netModemToolTipActiveFilter=Sets the <i>active-filter</i> option of the PPP daemon. It specifies a packet filter (filter-expression) to be applied to data packets to determine which packets are to be regarded as link activity, and therefore reset the idle timer.<br><br>The <i>filter-expression</i> syntax is as described for tcpdump(1), except that qualifiers which are inappropriate for a PPP link, such as ether and arp, are not permitted.<br><br>The default value is: <b>inbound</b><br><br>To disable the <i>active-filter</i> option of the PPP daemon, leave it blank.
netModemToolTipLcpEchoInterval=Sets the <i>lcp-echo-interval</i> option of the PPP daemon.<br><br>If set to a positive number, modem will send an LCP echo-request to the peer every specified number of seconds.<br><br>To disable this option, set it to 0.<br><br>This option can be used with the 'LCP Echo Failure' option to detect that the peer is no longer connected.
netModemToolTipLcpEchoFailure=Sets the <i>lcp-echo-failure</i> option of the PPP daemon<br><br>If set to a positive number, modem will presume the peer to be dead if specified number of LCP echo-requests are sent without receiving a valid LCP echo-reply.<br><br>To disable this option, set it to 0.
netModemToolTipEnableGps=Enable GPS from modem.<br><br>If enabled:<br>* One modem port will be dedicated to NMEA data stream.<br>* It will not be possible to send AT commands to this port.<br>* Position Service needs to be enabled as well.<br>* Serial settings of Position Service should not be changed; it will be redirected to the modem GPS port automatically.
netModemToolTipEnableGps=Enable modem GPS.
netModemToolTipGpsMode=Choose GPS mode:<br><br>* <i>UNMANAGED</i> the GPS device of the modem will be setup but not directly managed, therefore freeing the serial port for other services to use.<br>* <i>MANAGED_GPS</i> the GPS device of the modem will be setup and directly managed therefore the serial port will not be available for other services to use.
netModemAntenna=Antenna
netModemEnableCellDiv=LTE Antenna Diversity
netModemToolTipAntenna=Diversity antenna of the LTE modem enabled.<br><br>LTE uses MIMO technology with two antennas port noted "CELL MAIN" and "CELL DIV". When you use only one antenna connected to MAIN port the diversity antenna (CELL DIV) needs to be disabled.<br>In this case select "false".
Expand Down

0 comments on commit 2f25933

Please sign in to comment.