Skip to content

Commit 8c072a1

Browse files
committed
feat: New protocol serial via Kitty
# Conflicts: # Ui/Model/Protocol/Serial.cs
1 parent c304478 commit 8c072a1

File tree

5 files changed

+129
-29
lines changed

5 files changed

+129
-29
lines changed

Ui/Model/Protocol/Serial.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using Newtonsoft.Json;
34
using _1RM.Model.Protocol.Base;
45
using _1RM.Utils.KiTTY;
@@ -66,6 +67,59 @@ public string BitRate
6667
set => SetAndNotifyIfChanged(ref _bitRate, value);
6768
}
6869

70+
71+
public string[] DataBitsCollection => new[] { "5", "6", "7", "8" };
72+
private string _dataBits = "8";
73+
public string DataBits
74+
{
75+
get => _dataBits;
76+
set => SetAndNotifyIfChanged(ref _dataBits, value);
77+
}
78+
79+
80+
public string[] StopBitsCollection => new[] { "1", "2" };
81+
private string _stopBits = "1";
82+
public string StopBits
83+
{
84+
get => _stopBits;
85+
set => SetAndNotifyIfChanged(ref _stopBits, value);
86+
}
87+
88+
public string[] ParityCollection => new[] { "NONE", "ODD", "EVEN", "MARK", "SPACE" };
89+
private string _parity = "NONE";
90+
public string Parity
91+
{
92+
get => _parity;
93+
set => SetAndNotifyIfChanged(ref _parity, value);
94+
}
95+
96+
public string GetParityFlag()
97+
{
98+
if (string.IsNullOrWhiteSpace(_parity))
99+
return "N";
100+
// ‘n’ for none, ‘o’ for odd, ‘e’ for even, ‘m’ for mark and ‘s’ for space.
101+
//string[] ParityFlagCollection = new[] { "n", "o", "e", "m", "s" };
102+
return _parity[0].ToString().ToUpper();
103+
}
104+
105+
106+
public string[] FlowControlCollection => new[] { "NONE", "XON/XOFF", "RTS/CTS", "DSR/DTR" };
107+
private string _flowControl = "XON/XOFF";
108+
public string FlowControl
109+
{
110+
get => _flowControl;
111+
set => SetAndNotifyIfChanged(ref _flowControl, value);
112+
}
113+
114+
public string GetFlowControlFlag()
115+
{
116+
// ‘N’ for none, ‘X’ for XON/XOFF, ‘R’ for RTS/CTS and ‘D’ for DSR/DTR.
117+
if (string.IsNullOrWhiteSpace(_flowControl))
118+
return "N";
119+
return _flowControl[0].ToString().ToUpper();
120+
}
121+
// TODO 数据位、校验位、停止位
122+
69123
private string _startupAutoCommand = "";
70124
public string StartupAutoCommand
71125
{
@@ -86,9 +140,16 @@ public string ExternalKittySessionConfigPath
86140
public string GetExeArguments(string sessionName)
87141
{
88142
// https://stackoverflow.com/questions/35411927/putty-command-line-automate-serial-commands-from-file
143+
// https://documentation.help/PuTTY/using-cmdline-sercfg.html
144+
// Any single digit from 5 to 9 sets the number of data bits.
145+
// ‘1’, ‘1.5’ or ‘2’ sets the number of stop bits.
146+
// Any other numeric string is interpreted as a baud rate.
147+
// A single lower-case letter specifies the parity: ‘n’ for none, ‘o’ for odd, ‘e’ for even, ‘m’ for mark and ‘s’ for space.
148+
// A single upper-case letter specifies the flow control: ‘N’ for none, ‘X’ for XON/XOFF, ‘R’ for RTS/CTS and ‘D’ for DSR/DTR.
149+
// For example, ‘-sercfg 19200,8,n,1,N’ denotes a baud rate of 19200, 8 data bits, no parity, 1 stop bit and no flow control.
89150
var serial = (this.Clone() as Serial)!;
90151
serial.ConnectPreprocess();
91-
return $@" -load ""{sessionName}"" -serial {serial.SerialPort} -sercfg {serial.BitRate}";
152+
return $@" -load ""{sessionName}"" -serial {serial.SerialPort} -sercfg {serial.BitRate},{DataBits},{GetParityFlag()},{StopBits},{GetFlowControlFlag()}";
92153
}
93154
}
94155
}

Ui/Utils/KiTTY/IKittyConnectable.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ public static void ConfigKitty(this IKittyConnectable iKittyConnectable, string
7575
//SerialParity\0\
7676
//SerialFlowControl\1\
7777
puttyOption.Set(EnumKittyConfigKey.SerialLine, serial.SerialPort);
78-
puttyOption.Set(EnumKittyConfigKey.SerialSpeed, serial.GetBitRate());
79-
puttyOption.Set(EnumKittyConfigKey.SerialDataBits, 8);
80-
puttyOption.Set(EnumKittyConfigKey.SerialStopHalfbits, 2);
81-
puttyOption.Set(EnumKittyConfigKey.SerialParity, 0);
82-
puttyOption.Set(EnumKittyConfigKey.SerialFlowControl, 1);
78+
//puttyOption.Set(EnumKittyConfigKey.SerialSpeed, serial.GetBitRate());
79+
//puttyOption.Set(EnumKittyConfigKey.SerialDataBits, 8);
80+
//puttyOption.Set(EnumKittyConfigKey.SerialStopHalfbits, 2);
81+
//puttyOption.Set(EnumKittyConfigKey.SerialParity, 0);
82+
//puttyOption.Set(EnumKittyConfigKey.SerialFlowControl, 1);
8383
}
8484

8585
// set theme

Ui/View/Editor/Forms/RdpForm.xaml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:attachProperty="clr-namespace:Shawn.Utils.WpfResources.Theme.AttachProperty;assembly=Shawn.Utils.WpfResources"
76
xmlns:controls="clr-namespace:_1RM.Controls"
87
xmlns:controls1="clr-namespace:Shawn.Utils.Wpf.Controls;assembly=Shawn.Utils.Wpf"
98
xmlns:forms="clr-namespace:_1RM.View.Editor.Forms"
@@ -12,7 +11,7 @@
1211
xmlns:alternativeCredential="clr-namespace:_1RM.View.Editor.Forms.AlternativeCredential"
1312
mc:Ignorable="d"
1413
d:DataContext="{d:DesignInstance protocol:RDP}"
15-
d:DesignHeight="1450" d:DesignWidth="800">
14+
d:DesignHeight="1850" d:DesignWidth="800">
1615
<StackPanel>
1716

1817
<StackPanel>
@@ -381,10 +380,8 @@
381380
<StackPanel>
382381
<Grid Style="{StaticResource EditorRowGrid}">
383382
<StackPanel Orientation="Horizontal">
384-
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource 'Additional settings'}" VerticalAlignment="Top"></TextBlock>
383+
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource 'Additional settings'}" VerticalAlignment="Top" Margin="0 7 0 0"></TextBlock>
385384
<Grid Style="{StaticResource EditorRowGridInput}">
386-
387-
388385
<Border>
389386
<Border.Style>
390387
<Style TargetType="Border">
@@ -409,15 +406,14 @@
409406
</Style>
410407
</Border.Style>
411408
</Border>
412-
<controls:BindableAvalonEditor
413-
Margin="8 0 4 0"
414-
Padding="0 5 0 5"
415-
x:Name="TextEditor"
416-
WordWrap="False"
417-
ShowLineNumbers="True"
418-
Text="{Binding RdpFileAdditionalSettings}"
419-
SyntaxHighlighting="PowerShell"
420-
FontSize="{DynamicResource TextFontSize}">
409+
<controls:BindableAvalonEditor Margin="8 0 4 0"
410+
Padding="0 5 0 5"
411+
x:Name="TextEditor"
412+
WordWrap="False"
413+
ShowLineNumbers="True"
414+
Text="{Binding RdpFileAdditionalSettings}"
415+
SyntaxHighlighting="PowerShell"
416+
FontSize="{DynamicResource TextFontSize}">
421417
<controls:BindableAvalonEditor.Resources>
422418
<VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.3" Stretch="None" AlignmentX="Left">
423419
<VisualBrush.Visual>

Ui/View/Editor/Forms/SerialForm.xaml

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,75 @@
1616

1717
<Grid Style="{StaticResource EditorRowGrid}">
1818
<StackPanel Orientation="Horizontal">
19-
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="TXT: COM"></TextBlock>
20-
<Grid Style="{StaticResource EditorRowGridInput}">
19+
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="Serial port"></TextBlock>
20+
<Grid Style="{StaticResource EditorRowGridInput}" Width="100">
2121
<TextBox Text="{Binding SerialPort, UpdateSourceTrigger=PropertyChanged}" Tag="e.g. COM1"></TextBox>
2222
</Grid>
23-
<TextBlock Style="{StaticResource EditorRowGridTitle}" Width="60" Text="TXT: Speed"></TextBlock>
23+
<TextBlock Style="{StaticResource EditorRowGridTitle}" Width="70" Text="Speed(bps)"></TextBlock>
2424
<Grid Style="{StaticResource EditorRowGridInput}">
2525
<TextBox Text="{Binding BitRate, UpdateSourceTrigger=PropertyChanged,ValidatesOnExceptions=True,NotifyOnValidationError=True}"
26-
MinWidth="50" HorizontalAlignment="Left"
26+
Width="100" HorizontalAlignment="Left"
2727
InputMethod.IsInputMethodEnabled="False"
2828
InputScope="Number"
29-
></TextBox>
29+
Tag="e.g. 9600"/>
3030
</Grid>
3131
</StackPanel>
3232
</Grid>
3333
</StackPanel>
3434

3535
<StackPanel>
3636
<TextBlock Style="{StaticResource EditorGroupTextBlockTitle}" Text="{DynamicResource server_editor_group_title_advantage}"></TextBlock>
37-
<Grid Style="{StaticResource EditorRowGrid}">
37+
<!--<Grid Style="{StaticResource EditorRowGrid}">
3838
<StackPanel Orientation="Horizontal">
3939
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_advantage_ssh_startup_auto_command}"></TextBlock>
4040
<Grid Style="{StaticResource EditorRowGridInput}">
4141
<TextBox Text="{Binding StartupAutoCommand, UpdateSourceTrigger=PropertyChanged}"
4242
Tag="e.g. cd /home/user/Desktop/"></TextBox>
4343
</Grid>
4444
</StackPanel>
45+
</Grid>-->
46+
47+
48+
49+
50+
<Grid Style="{StaticResource EditorRowGrid}">
51+
<StackPanel Orientation="Horizontal">
52+
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="Data bits"></TextBlock>
53+
<Grid Style="{StaticResource EditorRowGridInput}">
54+
<ComboBox SelectedItem="{Binding DataBits}" ItemsSource="{Binding DataBitsCollection}">
55+
</ComboBox>
56+
</Grid>
57+
</StackPanel>
58+
</Grid>
59+
60+
<Grid Style="{StaticResource EditorRowGrid}">
61+
<StackPanel Orientation="Horizontal">
62+
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="Stop bits"></TextBlock>
63+
<Grid Style="{StaticResource EditorRowGridInput}">
64+
<ComboBox SelectedItem="{Binding StopBits}" ItemsSource="{Binding StopBitsCollection}">
65+
</ComboBox>
66+
</Grid>
67+
</StackPanel>
68+
</Grid>
69+
70+
<Grid Style="{StaticResource EditorRowGrid}">
71+
<StackPanel Orientation="Horizontal">
72+
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="Parity"></TextBlock>
73+
<Grid Style="{StaticResource EditorRowGridInput}">
74+
<ComboBox SelectedItem="{Binding Parity}" ItemsSource="{Binding ParityCollection}">
75+
</ComboBox>
76+
</Grid>
77+
</StackPanel>
78+
</Grid>
79+
80+
<Grid Style="{StaticResource EditorRowGrid}">
81+
<StackPanel Orientation="Horizontal">
82+
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="Flow control"></TextBlock>
83+
<Grid Style="{StaticResource EditorRowGridInput}">
84+
<ComboBox SelectedItem="{Binding FlowControl}" ItemsSource="{Binding FlowControlCollection}">
85+
</ComboBox>
86+
</Grid>
87+
</StackPanel>
4588
</Grid>
4689
</StackPanel>
4790
</StackPanel>

Ui/View/Editor/Forms/SshForm.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_advantage_ssh_startup_auto_command}"></TextBlock>
140140
<Grid Style="{StaticResource EditorRowGridInput}">
141141
<TextBox Text="{Binding StartupAutoCommand, UpdateSourceTrigger=PropertyChanged}"
142-
Tag="e.g. cd /home/user/Desktop/"></TextBox>
142+
Tag="e.g. cd /home/user/Desktop/"></TextBox>
143143
</Grid>
144144
</StackPanel>
145145
</Grid>
@@ -148,9 +148,9 @@
148148
<TextBlock Style="{StaticResource EditorRowGridTitle}" Text="KiTTY Session"></TextBlock>
149149
<Grid Style="{StaticResource EditorRowGridInput}">
150150
<TextBox Text="{Binding ExternalKittySessionConfigPath, UpdateSourceTrigger=PropertyChanged}"
151-
ToolTip="{DynamicResource server_editor_advantage_ssh_startup_auto_kitty_session_tip}"
151+
ToolTip="{DynamicResource server_editor_advantage_ssh_startup_auto_kitty_session_tip}"
152152
Tag="{DynamicResource server_editor_advantage_ssh_startup_auto_kitty_session_tip}"
153-
></TextBox>
153+
></TextBox>
154154
</Grid>
155155
<Button VerticalAlignment="Stretch" Style="{StaticResource ButtonPrimaryStyle}" Margin="5 0 0 0" Content="{DynamicResource Select}" Click="ButtonSelectSessionConfigFile_OnClick"></Button>
156156
</StackPanel>

0 commit comments

Comments
 (0)