-
Notifications
You must be signed in to change notification settings - Fork 133
Added option to prefix serial monitor messages with a timestamp. #1189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3e9d337
8b208ec
bebfb1b
7199670
c167aa1
9617374
8f73472
b15f437
83c230d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteOrder; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.LocalTime; | ||
| import java.time.format.DateTimeFormatter; | ||
|
|
||
| import org.eclipse.core.runtime.IStatus; | ||
| import org.eclipse.core.runtime.Status; | ||
|
|
@@ -16,6 +18,7 @@ | |
| @SuppressWarnings({"unused"}) | ||
| public class SerialListener implements MessageConsumer { | ||
| private static boolean myPlotterFilterFlag = false; | ||
| static boolean showTimestamps = false; | ||
| SerialMonitor theMonitor; | ||
| boolean isDisposed = false; | ||
| int theColorIndex; | ||
|
|
@@ -122,16 +125,49 @@ public void dispose() { | |
| public class TxtUpdater implements Runnable { | ||
| private boolean running = false; | ||
| private String additionalSerialData = new String(); | ||
| private StringBuilder lineBuffer = new StringBuilder(); | ||
|
|
||
| private DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); //$NON-NLS-1$ | ||
| private static final String arduinoEOL = "\r\n"; //$NON-NLS-1$ | ||
|
||
| private final int eolLength = arduinoEOL.length(); | ||
|
|
||
| public synchronized void addData(String event) { | ||
| if (!event.isEmpty()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this line should not be deleted?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about that! I've pushed a commit to fix it, but even better would be to just throw away all changes to SerialListener as you suggest. But I don't know enough about git to do that - how would I do it? |
||
| this.additionalSerialData = this.additionalSerialData + event; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't it be easier to have something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that but it wasn't reliable. I can't tell you why because it looks like it should work but it didn't. I still got line breaks in weird places, it was like they were being added by something else but I can't think what. It made no sense, but it didn't work. The code in the pull request is the only one of 3 or 4 different algorithms I tried that seems to work consistently.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about this.... I think it is way better to add this code in the monitor itself to |
||
| if (!this.running || this.additionalSerialData.length() > 500) { | ||
| Display.getDefault().asyncExec(this); | ||
| this.running = true; | ||
| if (SerialListener.showTimestamps) { | ||
| boolean atLeastOneLine = false; | ||
| String ts = LocalTime.now().format(timeFormatter) + ": "; //$NON-NLS-1$ | ||
|
|
||
| int begin = 0; | ||
| while (true) { | ||
| int idx = event.indexOf(arduinoEOL, begin); | ||
| if (idx >= 0) { | ||
| lineBuffer.append(event.substring(begin, idx + eolLength)); | ||
| additionalSerialData += ts; | ||
| additionalSerialData += lineBuffer.toString(); | ||
|
|
||
| lineBuffer.setLength(0); | ||
| begin = idx + eolLength; | ||
| atLeastOneLine = true; | ||
| } else { | ||
| lineBuffer.append(event.substring(begin)); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (atLeastOneLine) { | ||
| Display.getDefault().asyncExec(this); | ||
| this.running = true; | ||
| } | ||
| } else { | ||
| this.additionalSerialData = this.additionalSerialData + event; | ||
| if (!this.running || this.additionalSerialData.length() > 500) { | ||
| Display.getDefault().asyncExec(this); | ||
| this.running = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private synchronized void synchronizedrun() { | ||
| try { | ||
| if (!SerialListener.this.isDisposed) { | ||
|
|
@@ -155,11 +191,13 @@ public void run() { | |
| @Override | ||
| public void event(String event) { | ||
| this.textUpdater.addData(event); | ||
|
|
||
| } | ||
|
|
||
| public static void setPlotterFilter(boolean selection) { | ||
| myPlotterFilterFlag = selection; | ||
| } | ||
|
|
||
| public static void setShowTimestamps(boolean showTimestamps) { | ||
| SerialListener.showTimestamps = showTimestamps; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.