1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<UserControl x:Class="Plugin.DeviceDebug.Panels.CanDebugPanel"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ui="clr-namespace:HMI.UI;assembly=HMI.UI"
             xmlns:dp="clr-namespace:HMI.UI.DpUtil;assembly=HMI.UI"
             mc:Ignorable="d" 
             d:DesignHeight="700" d:DesignWidth="700">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/HMI.UI;component/Style/PanuonListView.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
 
    <Grid dp:GridHelper.Space="10" Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
 
        <!-- 标题 -->
        <Border Grid.Row="0" Background="#FF9800" CornerRadius="4" Padding="12,8">
            <TextBlock Text="CAN 通讯调试面板" FontSize="16" FontWeight="Bold" Foreground="White"/>
        </Border>
 
        <!-- 模拟器连接控制区 -->
        <Border Grid.Row="1" BorderBrush="#DDD" BorderThickness="1" CornerRadius="4" Padding="12" Background="#FAFAFA">
            <Grid dp:GridHelper.Space="8">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80"/>
                    <ColumnDefinition Width="150"/>
                    <ColumnDefinition Width="80"/>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
 
                <!-- 第一行:总线名称和节点编号 -->
                <TextBlock Grid.Row="0" Grid.Column="0" Text="总线名称:" VerticalAlignment="Center" FontWeight="SemiBold"/>
                <TextBox Grid.Row="0" Grid.Column="1" x:Name="busNameInput" 
                         VerticalContentAlignment="Center" Padding="6,4" Text="CAN_BUS_1"/>
 
                <TextBlock Grid.Row="0" Grid.Column="2" Text="节点编号:" VerticalAlignment="Center" FontWeight="SemiBold" Margin="8,0,0,0"/>
                <TextBox Grid.Row="0" Grid.Column="3" x:Name="nodeIndexInput" 
                         VerticalContentAlignment="Center" Padding="6,4" Text="0"/>
 
                <Button Grid.Row="0" Grid.Column="5" x:Name="connectBtn" Content="连接" Width="80" Height="30"
                        Click="ConnectBtn_Click" 
                        Background="#4CAF50" Foreground="White" BorderThickness="0" Cursor="Hand" FontWeight="SemiBold"/>
 
                <!-- 第二行:状态显示和控制按钮 -->
                <TextBlock Grid.Row="1" Grid.Column="0" Text="状态:" VerticalAlignment="Center" FontWeight="SemiBold"/>
                <StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" VerticalAlignment="Center">
                    <Ellipse x:Name="statusIndicator" Width="12" Height="12" Fill="#9E9E9E" Margin="0,0,6,0"/>
                    <TextBlock x:Name="statusText" Text="未连接" VerticalAlignment="Center"/>
                </StackPanel>
 
                <TextBlock Grid.Row="1" Grid.Column="3" Text="统计:" VerticalAlignment="Center" FontWeight="SemiBold" Margin="8,0,0,0"/>
                <TextBlock Grid.Row="1" Grid.Column="4" x:Name="statsText" Text="TX: 0  RX: 0" 
                           VerticalAlignment="Center" Foreground="#666"/>
 
                <StackPanel Grid.Row="1" Grid.Column="5" Orientation="Horizontal">
                    <ToggleButton x:Name="autoResponseToggleBtn" Content="自动响应: 关" Width="100" Height="28" Margin="0,0,4,0"
                                  Click="AutoResponseToggleBtn_Click" IsEnabled="False" IsChecked="False"
                                  Background="#9E9E9E" Foreground="White" BorderThickness="0" Cursor="Hand" FontWeight="SemiBold"/>
                    <ToggleButton x:Name="maintenanceToggleBtn" Content="维护模式: 开" Width="100" Height="28" Margin="0,0,4,0"
                                  Click="MaintenanceToggleBtn_Click" IsEnabled="False" IsChecked="True"
                                  Background="#4CAF50" Foreground="White" BorderThickness="0" Cursor="Hand" FontWeight="SemiBold"/>
                    <Button x:Name="disconnectBtn" Content="断开" Width="60" Height="28" Margin="0,0,4,0"
                            Click="DisconnectBtn_Click" IsEnabled="False"
                            Background="#F44336" Foreground="White" BorderThickness="0" Cursor="Hand"/>
                    <Button x:Name="promiscuousBtn" Content="混杂模式" Width="80" Height="28"
                            Click="PromiscuousBtn_Click" IsEnabled="False"
                            Background="#2196F3" Foreground="White" BorderThickness="0" Cursor="Hand"/>
                </StackPanel>
            </Grid>
        </Border>
 
        <!-- 发送区 -->
        <Border Grid.Row="2" BorderBrush="#DDD" BorderThickness="1" CornerRadius="4" Padding="12">
            <Grid dp:GridHelper.Space="8">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
 
                <!-- 帧ID -->
                <TextBlock Grid.Row="0" Grid.Column="0" Text="帧 ID:" VerticalAlignment="Center" FontWeight="Bold"/>
                <TextBox Grid.Row="0" Grid.Column="1" x:Name="frameIdInput"
                         IsEnabled="{Binding IsMaintenanceMode, RelativeSource={RelativeSource AncestorType=UserControl}}"
                         VerticalContentAlignment="Center" Padding="6,4" Text="0x100"/>
 
                <!-- 数据 -->
                <TextBlock Grid.Row="1" Grid.Column="0" Text="数据(Hex):" VerticalAlignment="Center" FontWeight="Bold"/>
                <TextBox Grid.Row="1" Grid.Column="1" x:Name="dataInput"
                         IsEnabled="{Binding IsMaintenanceMode, RelativeSource={RelativeSource AncestorType=UserControl}}"
                         VerticalContentAlignment="Center" Padding="6,4" Text="00 00 00 00 00 00 00 00"/>
 
                <!-- 发送按钮 -->
                <Button Grid.Row="1" Grid.Column="2" x:Name="sendBtn" Content="发送" Width="80" Height="30"
                        IsEnabled="{Binding IsMaintenanceMode, RelativeSource={RelativeSource AncestorType=UserControl}}"
                        Click="SendBtn_Click" 
                        Background="#FF9800" Foreground="White" BorderThickness="0" Cursor="Hand" FontWeight="SemiBold"/>
            </Grid>
        </Border>
 
        <!-- 接收区 -->
        <Border Grid.Row="3" BorderBrush="#DDD" BorderThickness="1" CornerRadius="4">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
 
                <DockPanel Grid.Row="0" Margin="8,6">
                    <Button x:Name="clearBtn" Content="清空" Padding="12,4" DockPanel.Dock="Right"
                            Click="ClearBtn_Click"
                            Background="#9E9E9E" Foreground="White" BorderThickness="0" Cursor="Hand"/>
                    <TextBlock Text="接收记录" FontWeight="Bold" FontSize="14" VerticalAlignment="Center"/>
                </DockPanel>
 
                <ListView Grid.Row="1" x:Name="receiveList"
                          Style="{StaticResource DefaultListTable}"
                          VirtualizingPanel.IsVirtualizing="True"
                          VirtualizingPanel.VirtualizationMode="Standard">
                    <ListView.View>
                        <GridView AllowsColumnReorder="False">
                            <GridViewColumn Width="90" Header="时间">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource CellBorder}">
                                            <TextBlock Style="{StaticResource ListTableTextBlock}" 
                                                       Text="{Binding Timestamp, StringFormat=HH:mm:ss.fff}"/>
                                        </Border>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="80" Header="帧ID">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource CellBorder}">
                                            <TextBlock Style="{StaticResource ListTableTextBlock}" 
                                                       Text="{Binding FrameId}"/>
                                        </Border>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="50" Header="DLC">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource CellBorder}">
                                            <TextBlock Style="{StaticResource ListTableTextBlock}" 
                                                       Text="{Binding Dlc}"/>
                                        </Border>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="200" Header="数据">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource CellBorder}">
                                            <TextBlock Style="{StaticResource ListTableTextBlock}" 
                                                       Text="{Binding Data}" FontFamily="Consolas"/>
                                        </Border>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="50" Header="方向">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource CellBorder}">
                                            <TextBlock Text="{Binding Direction}">
                                                <TextBlock.Style>
                                                    <Style TargetType="TextBlock" BasedOn="{StaticResource ListTableTextBlock}">
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding Direction}" Value="TX">
                                                                <Setter Property="Foreground" Value="#2196F3"/>
                                                            </DataTrigger>
                                                            <DataTrigger Binding="{Binding Direction}" Value="RX">
                                                                <Setter Property="Foreground" Value="#4CAF50"/>
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </TextBlock.Style>
                                            </TextBlock>
                                        </Border>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="100" Header="来源">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource CellBorder}">
                                            <TextBlock Style="{StaticResource ListTableTextBlock}" 
                                                       Text="{Binding Source}"/>
                                        </Border>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>
        </Border>
    </Grid>
</UserControl>