broadcast tab seems to work now?!

This commit is contained in:
rusefi 2020-07-27 00:48:04 -04:00
parent c0878620c3
commit 6dace7ce0d
8 changed files with 82 additions and 10 deletions

View File

@ -1,6 +1,6 @@
package com.rusefi.autodetect;
import com.rusefi.FileLog;
import com.devexperts.logging.Logging;
import com.rusefi.NamedThreadFactory;
import com.rusefi.io.IoStream;
import com.rusefi.io.LinkManager;
@ -19,19 +19,23 @@ import java.util.function.Function;
* Andrey Belomutskiy, (c) 2013-2020
*/
public class PortDetector {
private final static Logging log = Logging.getLogging(PortDetector.class);
private static final NamedThreadFactory AUTO_DETECT_PORT = new NamedThreadFactory("AutoDetectPort");
/**
* Connect to all serial ports and find out which one respond first
* @param callback
* @return port name on which rusEFI was detected or null if none
*/
@Nullable
public static String autoDetectSerial(Function<IoStream, Void> callback) {
String[] serialPorts = getPortNames();
if (serialPorts.length == 0) {
System.err.println("No serial ports detected");
log.error("No serial ports detected");
return null;
}
FileLog.MAIN.logLine("Trying " + Arrays.toString(serialPorts));
log.info("Trying " + Arrays.toString(serialPorts));
List<Thread> serialFinder = new ArrayList<>();
CountDownLatch portFound = new CountDownLatch(1);
AtomicReference<String> result = new AtomicReference<>();

View File

@ -34,6 +34,10 @@ public class NetworkConnector implements Closeable {
private final static Logging log = Logging.getLogging(NetworkConnector.class);
private boolean isClosed;
public NetworkConnectorResult runNetworkConnector(String authToken, String controllerPort, NetworkConnectorContext context) {
return runNetworkConnector(authToken, controllerPort, context, ReconnectListener.VOID);
}
public NetworkConnectorResult runNetworkConnector(String authToken, String controllerPort, NetworkConnectorContext context, ReconnectListener reconnectListener) {
LinkManager controllerConnector = new LinkManager()
.setCompositeLogicEnabled(false)

View File

@ -5,7 +5,6 @@ import com.rusefi.auth.AutoTokenUtil;
import com.rusefi.autodetect.PortDetector;
import com.rusefi.proxy.NetworkConnector;
import com.rusefi.proxy.NetworkConnectorContext;
import com.rusefi.tools.online.ProxyClient;
import com.rusefi.ui.AuthTokenPanel;
public class NetworkConnectorStartup {
@ -25,7 +24,7 @@ public class NetworkConnectorStartup {
NetworkConnectorContext connectorContext = new NetworkConnectorContext();
NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().runNetworkConnector(authToken, autoDetectedPort, connectorContext, NetworkConnector.ReconnectListener.VOID);
NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().runNetworkConnector(authToken, autoDetectedPort, connectorContext);
log.info("Running with oneTimeToken=" + networkConnectorResult.getOneTimeToken());
}
}

View File

@ -1,15 +1,69 @@
package com.rusefi.ts_plugin;
import com.rusefi.auth.AutoTokenUtil;
import com.rusefi.autodetect.PortDetector;
import com.rusefi.autoupdate.AutoupdateUtil;
import com.rusefi.proxy.NetworkConnector;
import com.rusefi.proxy.NetworkConnectorContext;
import com.rusefi.ui.AuthTokenPanel;
import com.rusefi.ui.util.URLLabel;
import org.putgemin.VerticalFlowLayout;
import javax.swing.*;
/**
* @see PluginEntry
*/
public class BroadcastTab {
private final JComponent content = new JPanel();
private final JComponent content = new JPanel(new VerticalFlowLayout());
private final JLabel help = new URLLabel(RemoteTab.HOWTO_REMOTE_TUNING);
private final JLabel status = new JLabel();
public BroadcastTab() {
// NetworkConnector
JButton broadcast = new JButton("Broadcast");
broadcast.addActionListener(e -> {
String authToken = AuthTokenPanel.getAuthToken();
if (!AutoTokenUtil.isToken(authToken)) {
status.setText("Auth token is required to broadcast ECU");
return;
}
new Thread(() -> {
String autoDetectedPort = PortDetector.autoDetectSerial(null);
SwingUtilities.invokeLater(() -> {
startBroadcasting(authToken, autoDetectedPort);
});
}).start();
});
content.add(broadcast);
content.add(status);
content.add(help);
content.add(new JLabel(PluginEntry.LOGO));
AutoupdateUtil.trueLayout(content);
}
private void startBroadcasting(String authToken, String autoDetectedPort) {
if (autoDetectedPort == null) {
status.setText("<html>rusEFI ECU not detected.<br/>Please make sure that TunerStudio is currently not connected to ECU.</html>");
} else {
status.setText("rusEFI detected at " + autoDetectedPort);
NetworkConnectorContext connectorContext = new NetworkConnectorContext();
new Thread(() -> {
NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().runNetworkConnector(authToken, autoDetectedPort, connectorContext);
SwingUtilities.invokeLater(() -> status.setText("One time password to connect to this ECU: " + networkConnectorResult.getOneTimeToken()));
}).start();
}
AutoupdateUtil.trueLayout(content);
}
public JComponent getContent() {

View File

@ -1,6 +1,7 @@
package com.rusefi.ts_plugin;
import com.efiAnalytics.plugin.ecu.ControllerAccess;
import com.rusefi.autoupdate.AutoupdateUtil;
import com.rusefi.ts_plugin.util.ManifestHelper;
import com.rusefi.tune.xml.Constant;
@ -11,10 +12,17 @@ import java.util.function.Supplier;
/**
* {@link TsPluginLauncher} creates an instance of this class via reflection.
* @see UploadTab upload tune & TODO upload logs
* @see RemoteTab remote ECU access & control
* @see BroadcastTab offer your ECU for remove access & control
* @see PluginBodySandbox
*/
public class PluginEntry implements TsPluginBody {
private final JPanel content = new JPanel(new BorderLayout());
static final ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png");
/**
* the real constructor - this one is invoked via reflection
*/

View File

@ -29,10 +29,14 @@ import java.util.concurrent.atomic.AtomicReference;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
/**
* remote ECU access & control
*
* @see RemoteTabSandbox
* @see PluginEntry
*/
public class RemoteTab {
private static final String APPLICATION_PORT = "application_port";
public static final String HOWTO_REMOTE_TUNING = "https://github.com/rusefi/rusefi/wiki/HOWTO-Remote-Tuning";
private final JComponent content = new JPanel(new BorderLayout());
private final JPanel list = new JPanel(new VerticalFlowLayout());
@ -87,7 +91,7 @@ public class RemoteTab {
topPanel.add(oneTimePasswordControl);
topLines.add(topPanel);
topLines.add(new URLLabel("https://github.com/rusefi/rusefi/wiki/HOWTO-Remote-Tuning"));
topLines.add(new URLLabel(HOWTO_REMOTE_TUNING));
content.add(topLines, BorderLayout.NORTH);
content.add(list, BorderLayout.CENTER);

View File

@ -142,8 +142,7 @@ public class UploadTab {
content.add(uploadView.getContent());
content.add(upload);
ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png");
content.add(new JLabel(LOGO));
content.add(new JLabel(PluginEntry.LOGO));
content.add(tokenPanel.getContent());
content.add(new URLLabel(REO_URL));