add local mode
This commit is contained in:
parent
bf58adc064
commit
139c3f8673
|
@ -3,8 +3,9 @@
|
||||||
internal class Config
|
internal class Config
|
||||||
{
|
{
|
||||||
public int mode = 0;
|
public int mode = 0;
|
||||||
public string sn = "";
|
|
||||||
public string disk0 = "";
|
public string disk0 = "";
|
||||||
public string disk1 = "";
|
public string disk1 = "";
|
||||||
|
public string sn = "";
|
||||||
|
public string ip = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Topuino_Client_Windows
|
||||||
|
{
|
||||||
|
internal class LocalConnector
|
||||||
|
{
|
||||||
|
internal LocalConnector(string addr)
|
||||||
|
{
|
||||||
|
client = new UdpClient();
|
||||||
|
client.Connect(addr, 32737);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UdpClient client;
|
||||||
|
|
||||||
|
internal void Send(byte[] data)
|
||||||
|
{
|
||||||
|
byte[] buff = new byte[data.Length + 4];
|
||||||
|
Array.Copy(data, 0, buff, 4, data.Length);
|
||||||
|
buff[0] = 0x19;
|
||||||
|
buff[1] = 0x26;
|
||||||
|
buff[2] = 0x08;
|
||||||
|
buff[3] = 0x17;
|
||||||
|
|
||||||
|
client.Send(buff, buff.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Dispose()
|
||||||
|
{
|
||||||
|
client.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,24 +6,25 @@
|
||||||
xmlns:local="clr-namespace:Topuino_Client_Windows"
|
xmlns:local="clr-namespace:Topuino_Client_Windows"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Closing="Window_Closing"
|
Closing="Window_Closing"
|
||||||
Title="Topuino 客户端" Height="180" Width="400">
|
Title="Topuino 客户端" Height="270" Width="400">
|
||||||
<Grid>
|
<Grid Margin="5,0">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="5">
|
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="5">
|
||||||
<Label Content="运行模式:" VerticalAlignment="Center" />
|
<Label Content="运行模式:" VerticalAlignment="Center" FontWeight="Bold" />
|
||||||
<RadioButton x:Name="RadioButton_UsbMode" VerticalAlignment="Center" Margin="5,0" IsChecked="True">USB 模式</RadioButton>
|
<RadioButton x:Name="RadioButton_UsbMode" VerticalAlignment="Center" Margin="5,0" IsChecked="True">USB 模式</RadioButton>
|
||||||
<RadioButton x:Name="RadioButton_OnlineMode" VerticalAlignment="Center" Margin="5,0">在线模式</RadioButton>
|
<RadioButton x:Name="RadioButton_OnlineMode" VerticalAlignment="Center" Margin="5,0">在线模式</RadioButton>
|
||||||
<RadioButton x:Name="RadioButton_LocalMode" VerticalAlignment="Center" Margin="5,0" IsEnabled="False">本地模式</RadioButton>
|
<RadioButton x:Name="RadioButton_LocalMode" VerticalAlignment="Center" Margin="5,0">本地模式</RadioButton>
|
||||||
</StackPanel>
|
|
||||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5">
|
|
||||||
<TextBlock Text="设备 SN:" VerticalAlignment="Center"/>
|
|
||||||
<TextBox x:Name="TextBox_DeviceSn" Width="80" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
<TextBlock Grid.Row="1" Text="通用配置:" FontSize="16" FontWeight="DemiBold" VerticalAlignment="Bottom" />
|
||||||
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5">
|
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5">
|
||||||
<TextBlock Text="0 号磁盘:" VerticalAlignment="Center"/>
|
<TextBlock Text="0 号磁盘:" VerticalAlignment="Center"/>
|
||||||
<ComboBox x:Name="ComboBox_Disk0" Height="20" Width="60" VerticalAlignment="Center"/>
|
<ComboBox x:Name="ComboBox_Disk0" Height="20" Width="60" VerticalAlignment="Center"/>
|
||||||
|
@ -31,7 +32,17 @@
|
||||||
<TextBlock Text="1 号磁盘:" VerticalAlignment="Center"/>
|
<TextBlock Text="1 号磁盘:" VerticalAlignment="Center"/>
|
||||||
<ComboBox x:Name="ComboBox_Disk1" Height="20" Width="60" VerticalAlignment="Center"/>
|
<ComboBox x:Name="ComboBox_Disk1" Height="20" Width="60" VerticalAlignment="Center"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="5">
|
<TextBlock Grid.Row="3" Text="在线模式配置:" FontSize="16" FontWeight="DemiBold" VerticalAlignment="Bottom" />
|
||||||
|
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5">
|
||||||
|
<TextBlock Text="设备 SN:" VerticalAlignment="Center"/>
|
||||||
|
<TextBox x:Name="TextBox_DeviceSn" Width="80" VerticalAlignment="Center" />
|
||||||
|
</StackPanel>
|
||||||
|
<TextBlock Grid.Row="5" Text="本地模式配置:" FontSize="16" FontWeight="DemiBold" VerticalAlignment="Bottom" />
|
||||||
|
<StackPanel Grid.Row="6" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5">
|
||||||
|
<TextBlock Text="IP 地址:" VerticalAlignment="Center"/>
|
||||||
|
<TextBox x:Name="TextBox_DeviceIp" Width="120" VerticalAlignment="Center" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Grid.Row="7" Orientation="Horizontal" HorizontalAlignment="Right" Margin="5">
|
||||||
<TextBlock Text="状态:" VerticalAlignment="Center"/>
|
<TextBlock Text="状态:" VerticalAlignment="Center"/>
|
||||||
<TextBlock x:Name="TextBlock_Status" Text="未连接" Foreground="Red" VerticalAlignment="Center" />
|
<TextBlock x:Name="TextBlock_Status" Text="未连接" Foreground="Red" VerticalAlignment="Center" />
|
||||||
<Separator Width="10" Background="Transparent" />
|
<Separator Width="10" Background="Transparent" />
|
||||||
|
|
|
@ -62,6 +62,7 @@ namespace Topuino_Client_Windows
|
||||||
|
|
||||||
private int mode = 0;
|
private int mode = 0;
|
||||||
private string sn = "";
|
private string sn = "";
|
||||||
|
private string ipAddr = "";
|
||||||
private List<DriveInfo> allDrives;
|
private List<DriveInfo> allDrives;
|
||||||
private DriveInfo drive0;
|
private DriveInfo drive0;
|
||||||
private DriveInfo drive1;
|
private DriveInfo drive1;
|
||||||
|
@ -73,6 +74,7 @@ namespace Topuino_Client_Windows
|
||||||
|
|
||||||
private OnlineConnector? onlineConnector = null;
|
private OnlineConnector? onlineConnector = null;
|
||||||
private UsbConnector? usbConnector = null;
|
private UsbConnector? usbConnector = null;
|
||||||
|
private LocalConnector? localConnector = null;
|
||||||
|
|
||||||
private void LoadConfig()
|
private void LoadConfig()
|
||||||
{
|
{
|
||||||
|
@ -138,6 +140,7 @@ namespace Topuino_Client_Windows
|
||||||
}
|
}
|
||||||
|
|
||||||
TextBox_DeviceSn.Text = initConfig.sn;
|
TextBox_DeviceSn.Text = initConfig.sn;
|
||||||
|
TextBox_DeviceIp.Text = initConfig.ip;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -288,7 +291,44 @@ namespace Topuino_Client_Windows
|
||||||
|
|
||||||
private void LocalRun(MonitorData data)
|
private void LocalRun(MonitorData data)
|
||||||
{
|
{
|
||||||
|
if (localConnector == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
localConnector = new LocalConnector(ipAddr);
|
||||||
|
ShowConnected();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
localConnector = null;
|
||||||
|
ShowDisconnected();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int size = Marshal.SizeOf(data);
|
||||||
|
byte[] bin = new byte[size];
|
||||||
|
IntPtr ptr = IntPtr.Zero;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ptr = Marshal.AllocHGlobal(size);
|
||||||
|
Marshal.StructureToPtr(data, ptr, true);
|
||||||
|
Marshal.Copy(ptr, bin, 0, size);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Marshal.FreeHGlobal(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
localConnector.Send(bin);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
localConnector.Dispose();
|
||||||
|
localConnector = null;
|
||||||
|
ShowDisconnected();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -319,10 +359,13 @@ namespace Topuino_Client_Windows
|
||||||
{
|
{
|
||||||
mode = 2;
|
mode = 2;
|
||||||
}
|
}
|
||||||
sn = TextBox_DeviceSn.Text;
|
|
||||||
|
|
||||||
drive0 = ComboBox_Disk0.SelectedItem as DriveInfo;
|
drive0 = ComboBox_Disk0.SelectedItem as DriveInfo;
|
||||||
drive1 = ComboBox_Disk1.SelectedItem as DriveInfo;
|
drive1 = ComboBox_Disk1.SelectedItem as DriveInfo;
|
||||||
|
|
||||||
|
sn = TextBox_DeviceSn.Text;
|
||||||
|
|
||||||
|
ipAddr = TextBox_DeviceIp.Text;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -360,9 +403,10 @@ namespace Topuino_Client_Windows
|
||||||
{
|
{
|
||||||
Config newConfig = new Config();
|
Config newConfig = new Config();
|
||||||
newConfig.mode = mode;
|
newConfig.mode = mode;
|
||||||
newConfig.sn = sn;
|
|
||||||
newConfig.disk0 = drive0.Name;
|
newConfig.disk0 = drive0.Name;
|
||||||
newConfig.disk1 = drive1.Name;
|
newConfig.disk1 = drive1.Name;
|
||||||
|
newConfig.sn = sn;
|
||||||
|
newConfig.ip = ipAddr;
|
||||||
await File.WriteAllTextAsync("Config.json", JsonConvert.SerializeObject(newConfig, Formatting.Indented));
|
await File.WriteAllTextAsync("Config.json", JsonConvert.SerializeObject(newConfig, Formatting.Indented));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,6 +414,7 @@ namespace Topuino_Client_Windows
|
||||||
{
|
{
|
||||||
usbConnector?.Dispose();
|
usbConnector?.Dispose();
|
||||||
onlineConnector?.Dispose();
|
onlineConnector?.Dispose();
|
||||||
|
localConnector?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Button_Save_Click(object sender, RoutedEventArgs e)
|
private void Button_Save_Click(object sender, RoutedEventArgs e)
|
||||||
|
|
2
pack.iss
2
pack.iss
|
@ -2,7 +2,7 @@
|
||||||
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
|
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
|
||||||
|
|
||||||
#define MyAppName "TopuinoClient"
|
#define MyAppName "TopuinoClient"
|
||||||
#define MyAppVersion "0.2"
|
#define MyAppVersion "0.3"
|
||||||
#define MyAppPublisher "VVZERO"
|
#define MyAppPublisher "VVZERO"
|
||||||
#define MyAppURL "https://iot.vvzero.com"
|
#define MyAppURL "https://iot.vvzero.com"
|
||||||
#define MyAppExeName "Topuino_Client_Windows.exe"
|
#define MyAppExeName "Topuino_Client_Windows.exe"
|
||||||
|
|
Loading…
Reference in New Issue