Skip to content

Commit

Permalink
v1.0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-heyns committed May 1, 2022
1 parent b04c9b9 commit 741fcec
Show file tree
Hide file tree
Showing 11 changed files with 508 additions and 507 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Terminal2 - v1.0.3.2
## !Quite usable now!
# Terminal2 - v1.0.4.0
## !With better accuracy on timestamps

Terminal emulator for Embedded Engineers with Serial and TCP socket capabilities

Expand All @@ -19,7 +19,7 @@ With Terminal2, you can define colorful profiles and quickly switch between sess
Terminal Emulator, Baud rate, Parity, Stop bits, Handshaking, TCP Client, TCP Server, ASCII, HEX, Line feed, Carriage return, Log files, Profiles, Fonts, Macros

## Building Terminal2
1. Windows 10, 11 with .NET 4.6.1 or later
1. Windows 10, 11 with .NET 4.7.2 or later
2. Visual Studio (2019 or later) with C#.
3. Load the solution (.sln file).
4. Build (Debug or Release).
Expand All @@ -33,8 +33,8 @@ Here is an example from Scotty's emulator on Enterprise (NCC-1701-B)
![Terminal2](https://user-images.githubusercontent.com/4144679/161002983-ad6ed0a3-b791-414c-8569-b2b6feb4a0ce.png)

### The name
The name "Terminal2" was chosen to allow existing users of the very useful (but unmaintained) "Terminal" program (by Br@dy++) to adapt quickly.
The name "Terminal2" was chosen to allow existing users of the very useful (now unmaintained) "Terminal" program to adapt quickly.
It will definitely change some time in the future.

## Feedback
Constructive feedback welcome.
Constructive feedback very welcome.
144 changes: 142 additions & 2 deletions Terminal2/Comms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,146 @@ internal class Comms
private TcpClient _client = null;
private Socket _socket = null;
private Profile _profile;
private Embelishments _embelishments;

private Thread _tcpThread = null;
private Thread _serialThread = null;
private static int _localThreadCount = 0;

private bool _ignoreNextLF = false;
private bool _showTimestamp = false;
private int _hexColumn = 0;

private void Enqueue(string str)
{
string embelished = string.Empty;

foreach (char c in str)
{
if (c == '\r')
{
if (_embelishments.ShowASCII)
{
if (_showTimestamp)
{
embelished += Utils.Timestamp();
_showTimestamp = false;
}

if (_embelishments.ShowCR)
embelished += "{CR}";

embelished += "\n";
}

if (_embelishments.ShowHEX)
{
if (!_embelishments.ShowASCII && _hexColumn == 0)
embelished += Utils.Timestamp();

byte b = Convert.ToByte(c);
embelished += $"{b:X2} ";

if (!_embelishments.ShowASCII)
{
_hexColumn++;
if (_hexColumn == 8 || _hexColumn == 16 || _hexColumn == 24)
{
embelished += " - ";
}
else if (_hexColumn == 32)
{
embelished += "\n";
_hexColumn = 0;
}
}
}

_ignoreNextLF = true;

if (_embelishments.ShowTimestamp)
_showTimestamp = true;
}
else if (c == '\n')
{
if (_embelishments.ShowASCII && _embelishments.ShowLF)
embelished += "{LF}";

if (!_ignoreNextLF)
{
if (_embelishments.ShowASCII)
{
if (_showTimestamp)
{
embelished += Utils.Timestamp();
_showTimestamp = false;
}
embelished += "\n";
}
}
if (_embelishments.ShowHEX)
{
if (!_embelishments.ShowASCII && _hexColumn == 0)
embelished += Utils.Timestamp();

byte b = Convert.ToByte(c);
embelished += $"{b:X2} ";

if (!_embelishments.ShowASCII)
{
_hexColumn++;
if (_hexColumn == 8 || _hexColumn == 16 || _hexColumn == 24)
{
embelished += " - ";
}
else if (_hexColumn == 32)
{
embelished += "\n";
_hexColumn = 0;
}
}
}
_ignoreNextLF = false;
}
else
{
if (_embelishments.ShowASCII && _showTimestamp)
{
embelished += Utils.Timestamp();
_showTimestamp = false;
}

if (_embelishments.ShowASCII)
embelished += c;

if (_embelishments.ShowHEX)
{
if (!_embelishments.ShowASCII && _hexColumn == 0)
embelished += Utils.Timestamp();

byte b = Convert.ToByte(c);
embelished += $"{b:X2} ";

if (!_embelishments.ShowASCII)
{
_hexColumn++;
if (_hexColumn == 8 || _hexColumn == 16 || _hexColumn == 24)
{
embelished += " - ";
}
else if (_hexColumn == 32)
{
embelished += "\n";
_hexColumn = 0;
}
}
}
_ignoreNextLF = false;
}
}
_inputQueue.Enqueue(embelished);
}

private void SerialReaderThread()
{
_localThreadCount++;
Expand All @@ -42,7 +177,7 @@ private void SerialReaderThread()
if (count > 0)
{
string str = _com.ReadExisting();
_inputQueue.Enqueue(str);
Enqueue(str);
}
else
{
Expand Down Expand Up @@ -74,7 +209,7 @@ private void TCPReaderThread()
_socket.Receive(tcp_data);
str = System.Text.Encoding.Default.GetString(tcp_data);
}
_inputQueue.Enqueue(str);
Enqueue(str);
}
else
{
Expand All @@ -97,6 +232,11 @@ public Comms(Label[] leds, Label[] controls, EventQueue inputQueue)
control.Visible = false;
}

public void SetEmbelishments(Embelishments embelishments)
{
_embelishments = embelishments;
}

private enum CommType
{ cNONE, ctSERIAL, ctSERVER, ctCLIENT };

Expand Down
50 changes: 23 additions & 27 deletions Terminal2/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,20 @@ public static bool SaveProfile(Profile profile, string filename)

data += "[Profile]\n";
data += $"Name={profile.name}\n";
data += $"ShowCR={profile.showCurlyCR}\n";
data += $"ShowLF={profile.showCurlyLF}\n";
data += $"ShowASCII={profile.ascii}\n";
data += $"TranslateCR={profile.translateCR}\n";
data += $"TranslateLF={profile.translateLF}\n";
data += $"SendCR={profile.sendCR}\n";
data += $"SendLF={profile.sendLF}\n";
data += $"ClearCMD={profile.clearCMD}\n";
data += $"OnTop={profile.stayontop}\n";
data += $"TimeInput={profile.timestampInput}\n";
data += $"TimeOutput={profile.displayOptions.timestampOutputLines}\n";
data += $"MaxLines={profile.displayOptions.maxLines}\n";
data += $"CutLines={profile.displayOptions.cutXtraLines}\n";

data += $"ShowCR={profile.embelishments.ShowCR}\n";
data += $"ShowLF={profile.embelishments.ShowLF}\n";
data += $"ShowASCII={profile.embelishments.ShowASCII}\n";
data += $"ShowHEX={profile.embelishments.ShowHEX}\n";
data += $"TimeInput={profile.embelishments.ShowTimestamp}\n";

if (!Directory.Exists(profile.logOptions.Directory))
{
Directory.CreateDirectory(profile.logOptions.Directory);
Expand Down Expand Up @@ -325,26 +325,6 @@ public static Profile ReadProfile(string name)
{
profile.name = line.Substring(5);
}
else if (line.StartsWith("ShowCR="))
{
profile.showCurlyCR = line.Contains("True");
}
else if (line.StartsWith("ShowLF="))
{
profile.showCurlyLF = line.Contains("True");
}
else if (line.StartsWith("ShowASCII="))
{
profile.ascii = line.Contains("True");
}
else if (line.StartsWith("TranslateCR="))
{
profile.translateCR = Utils.Int(line.Substring(12));
}
else if (line.StartsWith("TranslateLF="))
{
profile.translateLF = Utils.Int(line.Substring(12));
}
else if (line.StartsWith("SendCR="))
{
profile.sendCR = line.Contains("True");
Expand All @@ -361,9 +341,25 @@ public static Profile ReadProfile(string name)
{
profile.stayontop = line.Contains("True");
}
else if (line.StartsWith("ShowCR="))
{
profile.embelishments.ShowCR = line.Contains("True");
}
else if (line.StartsWith("ShowLF="))
{
profile.embelishments.ShowLF = line.Contains("True");
}
else if (line.StartsWith("ShowASCII="))
{
profile.embelishments.ShowASCII = line.Contains("True");
}
else if (line.StartsWith("ShowHEX="))
{
profile.embelishments.ShowHEX = line.Contains("True");
}
else if (line.StartsWith("TimeInput="))
{
profile.timestampInput = line.Contains("True");
profile.embelishments.ShowTimestamp = line.Contains("True");
}
else if (line.StartsWith("OutFont="))
{
Expand Down
Loading

0 comments on commit 741fcec

Please sign in to comment.