Skip to content

Commit

Permalink
Merge branch 'system/caravel' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
paulosousadias committed Jan 18, 2025
2 parents e7716b4 + 1161d47 commit f1d016a
Show file tree
Hide file tree
Showing 33 changed files with 3,764 additions and 920 deletions.
1 change: 1 addition & 0 deletions plugins-dev/caravel-env/plugins.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pt.lsts.neptus.plugins.caravelenv.CaravelDataPlotter

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingWorker;
import javax.swing.border.EmptyBorder;

import com.google.common.eventbus.Subscribe;
Expand Down Expand Up @@ -251,10 +252,17 @@ public void actionPerformed(ActionEvent e) {

synchronized (OperationLimitsSubPanel.this) {
lastMD5 = msg.payloadMD5();
boolean ret = send(msg);
if (ret) {
send(new GetOperationalLimits());
}
SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
@Override
protected Boolean doInBackground() throws Exception {
boolean ret = send(msg);
if (ret) {
send(new GetOperationalLimits());
}
return ret;
}
};
worker.execute();
}
}
};
Expand All @@ -273,7 +281,13 @@ public void actionPerformed(ActionEvent e) {
updateAction.putValue(AbstractAction.SMALL_ICON, ICON_UPDATE_REQUEST);
}
updateAction.putValue(AbstractAction.SHORT_DESCRIPTION, TEXT_REQUEST_RESPONSE_WAITING);
send(IMCDefinition.getInstance().create("GetOperationalLimits"));
SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
@Override
protected Boolean doInBackground() throws Exception {
return send(IMCDefinition.getInstance().create("GetOperationalLimits"));
}
};
worker.execute();
}
};

Expand Down Expand Up @@ -365,8 +379,7 @@ public boolean send(IMCMessage message) {
if (userAproveRequest) {
lastRequest = new Date();
}
sendViaIridium(destination, message);
return true;
return sendViaIridium(destination, message);
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.common.eventbus.Subscribe;
import net.miginfocom.swing.MigLayout;
import pt.lsts.imc.EntityState;
import pt.lsts.imc.IMCMessage;
import pt.lsts.imc.RemoteActions;
import pt.lsts.imc.RemoteActionsRequest;
import pt.lsts.imc.VehicleState;
Expand All @@ -50,14 +51,19 @@
import pt.lsts.neptus.plugins.Popup;
import pt.lsts.neptus.plugins.update.Periodic;
import pt.lsts.neptus.util.MathMiscUtils;
import pt.lsts.neptus.util.PropertiesLoader;
import pt.lsts.neptus.util.conf.ConfigFetch;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -70,6 +76,7 @@
description = "This plugin listen for non motion related remote actions and displays its controls.")
@Popup(name = "Remote Actions Extra", width = 300, height = 200, pos = Popup.POSITION.BOTTOM, accelerator = KeyEvent.VK_3)
public class RemoteActionsExtra extends ConsolePanel implements MainVehicleChangeListener, ConfigurationListener {
public static final String REMOTE_ACTIONS_EXTRA_PROPERTIES_FILE = ".cache/db/remote-actions-extra.properties";

static final boolean DEFAULT_AXIS_DECIMAL_VAL = false;
private static final int DECIMAL_HOUSES_FOR_DECIMAL_AXIS = 6;
Expand Down Expand Up @@ -129,6 +136,44 @@ enum ActionTypeEnum {

private final TakeControlMonitor takeControlMonitor;

private static PropertiesLoader properties = null;
static {
String propertiesFile = ConfigFetch.resolvePathBasedOnConfigFile(REMOTE_ACTIONS_EXTRA_PROPERTIES_FILE);
if (!new File(propertiesFile).exists()) {
String testFile = ConfigFetch.resolvePathBasedOnConfigFile("../" + REMOTE_ACTIONS_EXTRA_PROPERTIES_FILE);
if (new File(testFile).exists())
propertiesFile = testFile;
}
new File(propertiesFile).getParentFile().mkdirs();
properties = new PropertiesLoader(propertiesFile, PropertiesLoader.PROPERTIES);

Enumeration<Object> it = properties.keys();
while (it.hasMoreElements()) {
String key = it.nextElement().toString();
String value = properties.getProperty(key);
setRemoteActionsExtra(key, value, false);
}
}

private static void saveProperties() {
try {
properties.store("RemoteActionsExtra properties");
}
catch (IOException e) {
NeptusLog.pub().error("saveProperties", e);
}
}

private static void setRemoteActionsExtra(String system, String actionsStr, boolean save) {
if (save) {
String old = properties.getProperty(system);
if (old == null || !old.equals(actionsStr)) {
properties.setProperty(system, actionsStr);
saveProperties();
}
}
}

@NeptusProperty(name = "OBS Entity Name", userLevel = NeptusProperty.LEVEL.ADVANCED,
description = "Used to check the state of the OBS take control status.")
public String obsEntityName = "OBS Broker";
Expand All @@ -145,6 +190,7 @@ public RemoteActionsExtra(ConsoleLayout console, boolean usedInsideAnotherConsol

@Override
public void initSubPanel() {
updateForMainSystems();
resetUIWithActions();
}

Expand All @@ -165,64 +211,66 @@ private synchronized void resetUIWithActions() {
removeAll();
setLayout(new MigLayout("insets 10px"));

if (extraActionsTypesMap.isEmpty()) {
add(new JLabel("No actions available", SwingConstants.CENTER), "dock center");
invalidate();
validate();
repaint(100);
return;
}

// Let us process the actions list
List<List<String>> groupedActions = groupActionsBySimilarity(extraActionsTypesMap.keySet(), true);
groupedActions = processActions(groupedActions, 2, false);

int grpIdx = 0;
for (List<String> grp1 : groupedActions) {
grpIdx++;
String lastAct = grp1.get(grp1.size() - 1);
for (String action : grp1) {
String wrapLay = "";
if (lastAct.equals(action)) {
wrapLay = "wrap";
}
synchronized (extraActionsTypesMap) {
if (extraActionsTypesMap.isEmpty()) {
add(new JLabel("No actions available", SwingConstants.CENTER), "dock center");
invalidate();
validate();
repaint(100);
return;
}

boolean provideLock = false;
if (curState.extraActionsLocksMap.containsKey(action)) {
Boolean v = curState.extraActionsLocksMap.get(action);
if (v != null && v) {
provideLock = true;
// Let us process the actions list
List<List<String>> groupedActions = groupActionsBySimilarity(extraActionsTypesMap.keySet(), true);
groupedActions = processActions(groupedActions, 2, false);

int grpIdx = 0;
for (List<String> grp1 : groupedActions) {
grpIdx++;
String lastAct = grp1.get(grp1.size() - 1);
for (String action : grp1) {
String wrapLay = "";
if (lastAct.equals(action)) {
wrapLay = "wrap";
}
}

switch (extraActionsTypesMap.get(action)) {
case BUTTON:
boolean isToProvideLock = provideLock || isActionForLock(action);
JButton button = isToProvideLock ? new HoldFillButton(action, 2000) : new JButton(action);
button.addActionListener(e -> {
curState.changeButtonActionValue(action, 1);
});
String lay = "dock center, sg grp" + grpIdx;
lay += ", " + wrapLay;
add(button, lay);
if (isToProvideLock) {
extraLockableButtons.add(button);
boolean provideLock = false;
if (curState.extraActionsLocksMap.containsKey(action)) {
Boolean v = curState.extraActionsLocksMap.get(action);
if (v != null && v) {
provideLock = true;
}
if ("Take Control".equalsIgnoreCase(action)) {
takeControlMonitor.setButton(button);
takeControlMonitor.askedControl();
}
break;
case AXIS:
// TODO
case SLIDER:
// TODO
case HALF_SLIDER:
// TODO
break;
}
}
}
}

switch (extraActionsTypesMap.get(action)) {
case BUTTON:
boolean isToProvideLock = provideLock || isActionForLock(action);
JButton button = isToProvideLock ? new HoldFillButton(action, 2000) : new JButton(action);
button.addActionListener(e -> {
curState.changeButtonActionValue(action, 1);
});
String lay = "dock center, sg grp" + grpIdx;
lay += ", " + wrapLay;
add(button, lay);
if (isToProvideLock) {
extraLockableButtons.add(button);
}
if ("Take Control".equalsIgnoreCase(action)) {
takeControlMonitor.setButton(button);
takeControlMonitor.askedControl();
}
break;
case AXIS:
// TODO
case SLIDER:
// TODO
case HALF_SLIDER:
// TODO
break;
}
}
}
}

invalidate();
validate();
Expand All @@ -232,9 +280,22 @@ private synchronized void resetUIWithActions() {
@Subscribe
public void on(ConsoleEventMainSystemChange evt) {
configureActions("", DEFAULT_AXIS_DECIMAL_VAL, false);
updateForMainSystems();
takeControlMonitor.on(evt);
}

private void updateForMainSystems() {
String actionsString = "";
try {
if (properties.containsKey(getConsole().getMainSystem())) {
actionsString = (String) properties.get(getConsole().getMainSystem());
}
} catch (Exception e) {
NeptusLog.pub().error(e.getMessage());
}
configureActions(actionsString, DEFAULT_AXIS_DECIMAL_VAL, false);
}

@Subscribe
public void on(RemoteActionsRequest msg) {
if (!msg.getSourceName().equals(getMainVehicleId())) {
Expand All @@ -243,7 +304,8 @@ public void on(RemoteActionsRequest msg) {

if (msg.getOp() != RemoteActionsRequest.OP.REPORT) return;

configureActions(msg.getAsString("actions"), DEFAULT_AXIS_DECIMAL_VAL, false);
setRemoteActionsExtra(msg.getSourceName(), IMCMessage.encodeTupleList(msg.getActions()), true);
configureActions(msg.getActions(), DEFAULT_AXIS_DECIMAL_VAL, false);
}

@Subscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ public void run() {

@Override
public int compare(String sdf1, String sdf2) {
if (sdf1 == null && sdf2 == null) {
return 0;
}
else if (sdf1 == null) {
return -1;
}
else if (sdf2 == null) {
return 1;
}

SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS dd-MM-yyyy 'Z'");
sdf1 = sdf1.replaceAll("V ", "");
sdf2 = sdf2.replaceAll("V ", "");
Expand Down
Loading

0 comments on commit f1d016a

Please sign in to comment.