nesnes / teleplot-vscode

Teleplot's VSCode extension
MIT License
25 stars 3 forks source link

Text values don't seem to work #8

Open tbaumann opened 1 year ago

tbaumann commented 1 year ago

I love this thing.

But I just noticed that ">name:text|t" values don't seem to work. That works with the upstream Teleplot. But the upstream version doesn't seem to support serial ports. Text could be very useful for me to track the internal state of for example a state machine...

And, while Serial support is really cool, it's not without fail. When using the traditional serial monitor platform.io is clever enough to stop the serial monitor while it uploads code and start it back up once it's done uploading. It would be real cool if it could do the same with Teleport (Disconnect while it's flashing the device)

I shall use UDP at some point (I'm using ESP32, where that will be an option). Once I do that I can have text values and don't have to fight for the port.

tbaumann commented 1 year ago

I created the following workaround.

By intercepting the messages in a Filter module of the Platform.io filter module I can make use of the monitor commands build in disconnect. And I use the latest Teleplot

from platformio.public import DeviceMonitorFilterBase
import socket
import re

class Teleport(DeviceMonitorFilterBase):
    NAME = "teleplot"

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.buffer = ""
        print("--- Teleplot filter. Lines beginning with > are sent to udp:localhost:47269 for plotting")

    def rx(self, text):
        # Append the incoming text to the buffer
        self.buffer += text

        # Split the buffer into lines, preserving newlines at the end of the line strings
        lines = re.split(r'(?<=\n)', self.buffer)

        # Process complete lines that start with '>' and end with a newline
        for line in lines[:-1]:
            if line.startswith('>') and line.endswith('\n'):
                # Send the complete line to Teleport (Without the >)
                self.sock.sendto(str.encode(line[1:]), ("127.0.0.1", 47269))

        # Save any remaining partial line in the buffer
        self.buffer = lines[-1]
        return text

See https://docs.platformio.org/en/latest/core/userguide/device/cmd_monitor.html on how to use Filters.

nesnes commented 1 year ago

Thanks for your message, and the workaround is quite interesting!

About the support of text-based telemetry in the VSCode version of Teleplot, well, it is indeed missing! There are a few features, including 3D telemetry that I still have to port (this is on my todo list ;) ). However, as you mentioned, those features are available in the standalone version of teleplot and on https://teleplot.fr

For the auto-disconnect feature, a few other people also mentionned it but I didn't yet identified a solution to detect that platformIO is about to flash. One of ther solution coluld be to get platformIO itself send a specific UDP packet to teleplot, in the telecmd format. Do you know if there is a mechanism similar to the DeviceMonitorFilter that could help with that? (and even better if it can also send a message to resume the connection!)

tbaumann commented 1 year ago

I am also not sure how it's done. But the logic is in Platform.IO and not in VSCode I'm sure. So it's far from universal.

nesnes commented 1 year ago

Another (a bit too dirty) option would be to monitor the running processes on the PC (if possible from VSCode) and attempt to detect the platformios python commands or the underlying platform-specific tools... But this would be hard to get reliable, fast-enough, and to not generate edge-cases. (ignoring the fact that I'll sleep bad after writing such a code)

nesnes commented 1 year ago

Hi again!

Text format is now available in the VSCode extension :tada: (along with 3D and a few other features)

However I still have no proper idea for auto-releasing the serial port :/