Compare commits

...

11 Commits

Author SHA1 Message Date
e6cb5430ef revert 0ae998f0fb
revert Merge branch 'Sergey' into main
2025-04-03 20:38:44 +00:00
114522ad0a игнор 2025-04-03 20:38:44 +00:00
a74b5d1ab9 игнор 2025-04-03 20:38:44 +00:00
3975f5c6ed Перенос в общую репу 2025-04-03 20:38:44 +00:00
2c08331bbe ненуна тут 2025-04-03 20:38:44 +00:00
215236fa15 Починин Socket 2025-04-03 20:38:44 +00:00
d5e4c08527 игнор 2025-04-03 20:38:44 +00:00
b19fb44822 убивать 2025-04-03 20:38:44 +00:00
e1eb3bd73f игнор 2025-04-03 20:38:44 +00:00
38be80788b игнор 2025-04-03 20:38:44 +00:00
d8deec303a мусор 2025-04-03 20:38:44 +00:00
106 changed files with 356 additions and 1162 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.vs/
obj/
bin/

Binary file not shown.

View File

@ -1,12 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}

View File

@ -1,53 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|d:\\cpl\\simulator\\droneclient\\droneclient\\formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|solutionrelative:formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|d:\\cpl\\simulator\\droneclient\\droneclient\\formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form",
"RelativeMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|solutionrelative:formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 0,
"Children": [
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "FormMain.cs",
"DocumentMoniker": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs",
"RelativeDocumentMoniker": "FormMain.cs",
"ToolTip": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs",
"RelativeToolTip": "FormMain.cs",
"ViewState": "AgIAACEAAAAAAAAAAAAYwCYAAAAOAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-03-27T13:11:11.045Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "FormMain.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]",
"DocumentMoniker": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs",
"RelativeDocumentMoniker": "FormMain.cs",
"ToolTip": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]",
"RelativeToolTip": "FormMain.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-03-27T13:11:01.471Z",
"EditorCaption": " [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]"
}
]
}
]
}
]
}

View File

@ -31,6 +31,7 @@ namespace DroneSimulator
public byte[] buffer = new byte[size];
}
private bool Connected = false;
private Socket? ServerSocket = null;
private ServerData DataServer = new ServerData();
@ -43,10 +44,11 @@ namespace DroneSimulator
public ClientState Connect(string Addr, int Port, ClientCallback Connection, ClientCallback Receive)
{
if (ServerSocket != null)
if (Connected)
{
ServerSocket.Close();
ServerSocket = null;
try { ServerSocket?.Shutdown(SocketShutdown.Both); } catch { }
ServerSocket?.Close();
Connected = false;
return ClientState.Stop;
}
@ -56,24 +58,26 @@ namespace DroneSimulator
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(Addr), Port);
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
ServerSocket.Connect(ep);
}
catch { ServerSocket.Close(); ServerSocket = null; return ClientState.Error; }
try { ServerSocket.Connect(ep); }
catch { ServerSocket.Close(); return ClientState.Error; }
Connected = true;
ConnectionCallback(new ConnectData { Connect = true, Server = ServerSocket });
ReceiveData receiveData = new ReceiveData { Buffer = DataServer.buffer, Size = ServerData.size, Server = ServerSocket };
ServerSocket.BeginReceive(DataServer.buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), receiveData);
try { ServerSocket.BeginReceive(DataServer.buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), receiveData); }
catch { }
return ClientState.Connected;
}
public void Close()
{
try { ServerSocket?.Shutdown(SocketShutdown.Both); } catch { }
ServerSocket?.Close();
ServerSocket = null;
Connected = false;
}
public void ReadCallback(IAsyncResult ar)
@ -82,23 +86,23 @@ namespace DroneSimulator
if (cd == null) return;
int bytes = 0;
try { bytes = ServerSocket.EndReceive(ar); }
catch { }
try { bytes = ServerSocket.EndReceive(ar); } catch { }
if (bytes == 0)
{
ServerSocket?.Close();
if (ServerSocket != null) ConnectionCallback(new ConnectData { Connect = false, Server = null });
Connected = false;
ServerSocket = null;
if (ServerSocket != null) ConnectionCallback(new ConnectData { Connect = false, Server = null });
return;
}
ReceiveCallback(new ReceiveData { Buffer = cd.Buffer, Size = bytes, Server = ServerSocket });
ServerSocket?.BeginReceive(cd.Buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), cd);
try { ServerSocket?.BeginReceive(cd.Buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), cd); }
catch { }
}
}
}

3
DroneClient/README.md Normal file
View File

@ -0,0 +1,3 @@
# Client
Образец клиента для подключения к симулятору.

View File

@ -1,23 +0,0 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"DroneClient/1.0.0": {
"runtime": {
"DroneClient.dll": {}
}
}
}
},
"libraries": {
"DroneClient/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

View File

@ -1,19 +0,0 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "9.0.0"
}
],
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false
}
}
}

View File

@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]

View File

@ -1,25 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("DroneClient")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("DroneClient")]
[assembly: System.Reflection.AssemblyTitleAttribute("DroneClient")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Runtime.Versioning.TargetPlatformAttribute("Windows7.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows7.0")]
// Создано классом WriteCodeFragment MSBuild.

View File

@ -1 +0,0 @@
372de9fd6d36597e50cdb2250f48b9cb0d5e8e1a2d1e568b83e287afe9580301

View File

@ -1,22 +0,0 @@
is_global = true
build_property.ApplicationManifest =
build_property.StartupObject =
build_property.ApplicationDefaultFont =
build_property.ApplicationHighDpiMode =
build_property.ApplicationUseCompatibleTextRendering =
build_property.ApplicationVisualStyles =
build_property.TargetFramework = net9.0-windows
build_property.TargetPlatformMinVersion = 7.0
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = DroneClient
build_property.ProjectDir = D:\CPL\Simulator\DroneClient\DroneClient\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.CsWinRTUseWindowsUIXamlProjections = false
build_property.EffectiveAnalysisLevelStyle = 9.0
build_property.EnableCodeStyleSeverity =

View File

@ -1,10 +0,0 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.Drawing;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using global::System.Windows.Forms;

View File

@ -1 +0,0 @@
01e86f1c7bc139724ab77bc57845e8da30f3f593b41b11317ce8867d8fb43c28

View File

@ -1,32 +0,0 @@
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.GenerateResource.cache
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.GeneratedMSBuildEditorConfig.editorconfig
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfoInputs.cache
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfo.cs
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.CoreCompileInputs.cache
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.exe
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.deps.json
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.runtimeconfig.json
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.dll
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.pdb
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.dll
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\refint\DroneClient.dll
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.pdb
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.genruntimeconfig.cache
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\ref\DroneClient.dll
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.exe
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.deps.json
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.runtimeconfig.json
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.dll
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.pdb
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.GenerateResource.cache
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.GeneratedMSBuildEditorConfig.editorconfig
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfoInputs.cache
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfo.cs
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.CoreCompileInputs.cache
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.dll
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\refint\DroneClient.dll
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.pdb
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.genruntimeconfig.cache
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\ref\DroneClient.dll

View File

@ -1,11 +0,0 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {}
},
"libraries": {}
}

View File

@ -1,25 +0,0 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "9.0.0"
}
],
"additionalProbingPaths": [
"C:\\Users\\Дана\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Дана\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false,
"Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
}
}
}

View File

@ -1 +0,0 @@
812e26f7e032de5fb2d5301fec24f483552f39e0a38ac0c052cba2ffa3a73bbd

View File

@ -1,25 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("DroneSimulator")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("DroneSimulator")]
[assembly: System.Reflection.AssemblyTitleAttribute("DroneSimulator")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Runtime.Versioning.TargetPlatformAttribute("Windows7.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows7.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -1 +0,0 @@
7f461f329c2aabe3c068a957f4f02cdcdb168c359c556cd0c46598798ec3c65d

View File

@ -1,22 +0,0 @@
is_global = true
build_property.ApplicationManifest =
build_property.StartupObject =
build_property.ApplicationDefaultFont =
build_property.ApplicationHighDpiMode =
build_property.ApplicationUseCompatibleTextRendering =
build_property.ApplicationVisualStyles =
build_property.TargetFramework = net9.0-windows
build_property.TargetPlatformMinVersion = 7.0
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = DroneSimulator
build_property.ProjectDir = D:\Files\Main\Projects\Fly\DroneClient\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.CsWinRTUseWindowsUIXamlProjections = false
build_property.EffectiveAnalysisLevelStyle = 9.0
build_property.EnableCodeStyleSeverity =

View File

@ -1,10 +0,0 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.Drawing;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using global::System.Windows.Forms;

View File

@ -1 +0,0 @@
051ffb89f1ee627ab3b9aaef920afd665a18f0f3c3fe82852812d5c6608dcb30

View File

@ -1,32 +0,0 @@
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.exe
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.deps.json
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.runtimeconfig.json
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.dll
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.pdb
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.Form1.resources
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.GenerateResource.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.GeneratedMSBuildEditorConfig.editorconfig
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfoInputs.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfo.cs
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.CoreCompileInputs.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.dll
R:\DroneSimulator\obj\Debug\net9.0-windows\refint\DroneSimulator.dll
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.pdb
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.genruntimeconfig.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\ref\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.exe
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.deps.json
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.runtimeconfig.json
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.pdb
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.GenerateResource.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.GeneratedMSBuildEditorConfig.editorconfig
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfoInputs.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfo.cs
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.CoreCompileInputs.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\refint\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.pdb
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.genruntimeconfig.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\ref\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources

View File

@ -1,11 +0,0 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {}
},
"libraries": {}
}

View File

@ -1,25 +0,0 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "9.0.0"
}
],
"additionalProbingPaths": [
"C:\\Users\\USER\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\USER\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false,
"Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
}
}
}

View File

@ -1 +0,0 @@
42c9c47684404b6458665b5db1d77e8e1563e0e910b9607df810cd1011407bfc

View File

@ -1,76 +0,0 @@
{
"format": 1,
"restore": {
"D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj": {}
},
"projects": {
"D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"projectName": "DroneClient",
"projectPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"packagesPath": "C:\\Users\\Дана\\.nuget\\packages\\",
"outputPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Дана\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net9.0-windows"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.200"
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
},
"Microsoft.WindowsDesktop.App.WindowsForms": {
"privateAssets": "none"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.201/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Дана\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.13.2</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Дана\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@ -1,76 +0,0 @@
{
"format": 1,
"restore": {
"D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj": {}
},
"projects": {
"D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj",
"projectName": "DroneSimulator",
"projectPath": "D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj",
"packagesPath": "C:\\Users\\USER\\.nuget\\packages\\",
"outputPath": "D:\\Files\\Main\\Projects\\Fly\\DroneClient\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\USER\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net9.0-windows"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.200"
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
},
"Microsoft.WindowsDesktop.App.WindowsForms": {
"privateAssets": "none"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.201/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\USER\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.13.2</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\USER\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@ -1,82 +0,0 @@
{
"version": 3,
"targets": {
"net9.0-windows7.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net9.0-windows7.0": []
},
"packageFolders": {
"C:\\Users\\Дана\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"projectName": "DroneClient",
"projectPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"packagesPath": "C:\\Users\\Дана\\.nuget\\packages\\",
"outputPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Дана\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net9.0-windows"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.200"
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
},
"Microsoft.WindowsDesktop.App.WindowsForms": {
"privateAssets": "none"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.201/PortableRuntimeIdentifierGraph.json"
}
}
}
}

View File

@ -1,8 +0,0 @@
{
"version": 2,
"dgSpecHash": "ddOSNwF62rQ=",
"success": true,
"projectFilePath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"expectedPackageFiles": [],
"logs": []
}

View File

@ -1,12 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}

View File

@ -1,37 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneSimulator.csproj|d:\\cpl\\simulator\\dronesimulator\\dronesimulator\\screen2d.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneSimulator.csproj|solutionrelative:screen2d.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 0,
"Children": [
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "Screen2D.cs",
"DocumentMoniker": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\Screen2D.cs",
"RelativeDocumentMoniker": "Screen2D.cs",
"ToolTip": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\Screen2D.cs",
"RelativeToolTip": "Screen2D.cs",
"ViewState": "AgIAAIgAAAAAAAAAAAAwwAAAAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-03-27T13:13:30.215Z",
"EditorCaption": ""
}
]
}
]
}
]
}

View File

@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.AxHost;
namespace DroneSimulator
{
@ -33,7 +27,46 @@ namespace DroneSimulator
private static int CounterID = 0;
public static byte[] getBytes(object data)
{
int size = Marshal.SizeOf(data);
byte[] arr = new byte[size];
IntPtr ptr = IntPtr.Zero;
try
{
ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(data, ptr, true);
Marshal.Copy(ptr, arr, 0, size);
}
finally
{
Marshal.FreeHGlobal(ptr);
}
return arr;
}
public static object fromBytes(byte[] arr, Type type)
{
object mem = new object();
int size = Marshal.SizeOf(type);
IntPtr ptr = IntPtr.Zero;
try
{
ptr = Marshal.AllocHGlobal(size);
Marshal.Copy(arr, 0, ptr, size);
mem = Marshal.PtrToStructure(ptr, type);
}
finally
{
Marshal.FreeHGlobal(ptr);
}
return mem;
}
public struct DataOut
{
@ -41,52 +74,23 @@ namespace DroneSimulator
public float GyrX, GyrY, GyrZ;
public float PosX, PosY;
public float LaserRange;
public byte[] getBytes()
{
int size = Marshal.SizeOf(this);
byte[] arr = new byte[size];
IntPtr ptr = IntPtr.Zero;
try
{
ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(this, ptr, true);
Marshal.Copy(ptr, arr, 0, size);
}
finally
{
Marshal.FreeHGlobal(ptr);
}
return arr;
}
}
public struct DataIn
{
public float MotorUL, MotorUR, MotorDL, MotorDR;
}
public void fromBytes(byte[] arr)
{
DataIn mem = new DataIn();
public struct DataVisual
{
public int ID; // Идентификатор
public float W, X, Y, Z; // Кватернион вращения
public float PosX, PosY, PosZ; // Координаты в пространстве
}
int size = Marshal.SizeOf(mem);
IntPtr ptr = IntPtr.Zero;
try
{
ptr = Marshal.AllocHGlobal(size);
Marshal.Copy(arr, 0, ptr, size);
mem = (DataIn)Marshal.PtrToStructure(ptr, mem.GetType());
}
finally
{
Marshal.FreeHGlobal(ptr);
}
this = mem;
}
public DataVisual GetVisual()
{
return new DataVisual() { ID = this.ID, W = this.Quat.W, X = this.Quat.X, Y = this.Quat.Y, Z = this.Quat.Z, PosX = this.PosXYZ.X, PosY = this.PosXYZ.Y, PosZ = this.PosXYZ.Z };
}
private void ThreadFunction()

View File

@ -38,6 +38,10 @@
tabControl_Menu = new TabControl();
tabPage_Main = new TabPage();
groupBox_Visual = new GroupBox();
numericUpDown_Visual_Limit = new NumericUpDown();
label1 = new Label();
label_Visual_Num = new Label();
label3 = new Label();
button_Visual_Start = new Button();
numericUpDown_Visual_Port = new NumericUpDown();
label_Visual_Port = new Label();
@ -63,6 +67,7 @@
tabControl_Menu.SuspendLayout();
tabPage_Main.SuspendLayout();
groupBox_Visual.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Limit).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Port).BeginInit();
groupBox_Clients.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Limit).BeginInit();
@ -144,18 +149,61 @@
//
// groupBox_Visual
//
groupBox_Visual.Controls.Add(numericUpDown_Visual_Limit);
groupBox_Visual.Controls.Add(label1);
groupBox_Visual.Controls.Add(label_Visual_Num);
groupBox_Visual.Controls.Add(label3);
groupBox_Visual.Controls.Add(button_Visual_Start);
groupBox_Visual.Controls.Add(numericUpDown_Visual_Port);
groupBox_Visual.Controls.Add(label_Visual_Port);
groupBox_Visual.Dock = DockStyle.Top;
groupBox_Visual.Location = new Point(3, 83);
groupBox_Visual.Name = "groupBox_Visual";
groupBox_Visual.Size = new Size(204, 62);
groupBox_Visual.Size = new Size(204, 91);
groupBox_Visual.TabIndex = 2;
groupBox_Visual.TabStop = false;
groupBox_Visual.Tag = "#visual";
groupBox_Visual.Text = "Visual";
//
// numericUpDown_Visual_Limit
//
numericUpDown_Visual_Limit.Location = new Point(44, 57);
numericUpDown_Visual_Limit.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
numericUpDown_Visual_Limit.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
numericUpDown_Visual_Limit.Name = "numericUpDown_Visual_Limit";
numericUpDown_Visual_Limit.Size = new Size(42, 23);
numericUpDown_Visual_Limit.TabIndex = 13;
numericUpDown_Visual_Limit.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(6, 59);
label1.Name = "label1";
label1.Size = new Size(37, 15);
label1.TabIndex = 12;
label1.Tag = "#clients_limit";
label1.Text = "Limit:";
//
// label_Visual_Num
//
label_Visual_Num.AutoSize = true;
label_Visual_Num.Location = new Point(161, 59);
label_Visual_Num.Name = "label_Visual_Num";
label_Visual_Num.Size = new Size(13, 15);
label_Visual_Num.TabIndex = 11;
label_Visual_Num.Text = "0";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(112, 59);
label3.Name = "label3";
label3.Size = new Size(43, 15);
label3.TabIndex = 10;
label3.Tag = "#clients_count";
label3.Text = "Count:";
//
// button_Visual_Start
//
button_Visual_Start.Location = new Point(112, 22);
@ -165,6 +213,7 @@
button_Visual_Start.Tag = "#visual_start";
button_Visual_Start.Text = "Start";
button_Visual_Start.UseVisualStyleBackColor = true;
button_Visual_Start.Click += button_Visual_Start_Click;
//
// numericUpDown_Visual_Port
//
@ -376,6 +425,7 @@
tabPage_Main.ResumeLayout(false);
groupBox_Visual.ResumeLayout(false);
groupBox_Visual.PerformLayout();
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Limit).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Port).EndInit();
groupBox_Clients.ResumeLayout(false);
groupBox_Clients.PerformLayout();
@ -416,5 +466,9 @@
private Panel panel1;
private ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.Timer timer_Test;
private NumericUpDown numericUpDown_Visual_Limit;
private Label label1;
private Label label_Visual_Num;
private Label label3;
}
}

View File

@ -12,6 +12,7 @@ namespace DroneSimulator
Screen2D screen2D = null;
NetServerClients netServerClient = new NetServerClients();
NetServerVisual netServerVisual = new NetServerVisual();
List<Drone> AllDrones = new List<Drone>();
@ -20,7 +21,7 @@ namespace DroneSimulator
InitializeComponent();
}
private void ConnectionCallback(object o)
private void ClientConnectionCallback(object o)
{
NetServerClients.ConnectData data = (NetServerClients.ConnectData)o;
@ -53,7 +54,7 @@ namespace DroneSimulator
}
}
private void ReceiveCallback(object o)
private void ClientReceiveCallback(object o)
{
NetServerClients.ReceiveData data = (NetServerClients.ReceiveData)o;
@ -68,30 +69,29 @@ namespace DroneSimulator
if (drone == null) return;
Drone.DataIn id = new Drone.DataIn();
id.fromBytes(data.Buffer);
Drone.DataIn id = (Drone.DataIn)Drone.fromBytes(data.Buffer, typeof(Drone.DataIn));
drone.SetQadroPow(id.MotorUL, id.MotorUR, id.MotorDL, id.MotorDR);
Drone.DataOut od = new Drone.DataOut();
od.AccX= drone.Acc.X; od.AccY= drone.Acc.Y; od.AccZ= drone.Acc.Z;
od.AccX = drone.Acc.X; od.AccY = drone.Acc.Y; od.AccZ = drone.Acc.Z;
od.GyrX = drone.Gyr.X; od.GyrY = drone.Gyr.Y; od.GyrZ = drone.Gyr.Z;
od.PosX= drone.PosXYZ.X; od.PosY = drone.PosXYZ.Y;
od.PosX = drone.PosXYZ.X; od.PosY = drone.PosXYZ.Y;
od.LaserRange = drone.LaserRange;
data.Client.Send(od.getBytes());
try { data.Client.Send(Drone.getBytes(od)); }
catch { }
}
private void button_Client_Start_Click(object sender, EventArgs e)
{
var done = netServerClient.StartServer((int)numericUpDown_Clients_Port.Value, (int)numericUpDown_Clients_Limit.Value, ConnectionCallback, ReceiveCallback);
var done = netServerClient.StartServer((int)numericUpDown_Clients_Port.Value, (int)numericUpDown_Clients_Limit.Value, ClientConnectionCallback, ClientReceiveCallback);
switch (done)
{
case NetServerClients.ServerState.Error:
{
MessageBox.Show("Error to start server");
MessageBox.Show("Error to start clients server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
case NetServerClients.ServerState.Start:
@ -102,6 +102,7 @@ namespace DroneSimulator
}
case NetServerClients.ServerState.Stop:
{
label_Clients_Num.Text = "0";
button_Client_Start.Text = "Start";
button_Client_Start.BackColor = Color.Transparent;
break;
@ -137,12 +138,70 @@ namespace DroneSimulator
{
screen2D.Move(d.ID, d.PosXYZ, d.GetOrientation());
}
screen2D.DrawScene();
}
private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (Drone d in AllDrones) d.Close();
}
private void VisualConnectionCallback(object o)
{
NetServerVisual.ConnectData data = (NetServerVisual.ConnectData)o;
Invoke((MethodInvoker)delegate
{
label_Clients_Num.Text = data.Count.ToString();
});
if (data.Connect)
{
//---
}
else
{
//---
}
}
private void VisualReceiveCallback(object o)
{
NetServerVisual.ReceiveData data = (NetServerVisual.ReceiveData)o;
foreach (Drone d in AllDrones)
{
Drone.DataVisual v = d.GetVisual();
try { data.Client.Send(Drone.getBytes(v)); }
catch { }
}
}
private void button_Visual_Start_Click(object sender, EventArgs e)
{
var done = netServerVisual.StartServer((int)numericUpDown_Visual_Port.Value, (int)numericUpDown_Visual_Limit.Value, VisualConnectionCallback, VisualReceiveCallback);
switch (done)
{
case NetServerVisual.ServerState.Error:
{
MessageBox.Show("Error to start visual server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
case NetServerVisual.ServerState.Start:
{
button_Visual_Start.Text = "Stop";
button_Visual_Start.BackColor = Color.LimeGreen;
break;
}
case NetServerVisual.ServerState.Stop:
{
label_Visual_Num.Text = "0";
button_Visual_Start.Text = "Start";
button_Visual_Start.BackColor = Color.Transparent;
break;
}
}
}
}
}

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net.Sockets;
using System.Net;
namespace DroneSimulator
@ -38,7 +33,7 @@ namespace DroneSimulator
private int SocketID = 0;
private int SocketLimit;
private Socket? ServerSocket = null;
private Socket? ServerSocket;
private List<ClientData> ClientSockets = new List<ClientData>();
public delegate void ServerCallback(object o);
@ -46,14 +41,21 @@ namespace DroneSimulator
private ServerCallback? ConnectionCallback;
private ServerCallback? ReceiveCallback;
private bool Active = false;
public enum ServerState { Error, Start, Stop };
public ServerState StartServer(int Port, int Limit, ServerCallback Connection, ServerCallback Receive)
{
if (ServerSocket != null)
if (Active)
{
ServerSocket.Close();
foreach (ClientData c in ClientSockets) { c.workSocket?.Shutdown(SocketShutdown.Both); c.workSocket?.Close(); }
ServerSocket?.Close();
foreach (ClientData c in ClientSockets)
{
try { c.workSocket?.Shutdown(SocketShutdown.Both); } catch { }
c.workSocket?.Close();
}
ClientSockets.Clear();
return ServerState.Stop;
}
@ -70,8 +72,9 @@ namespace DroneSimulator
ServerSocket.Bind(ip);
ServerSocket.Listen(10);
ServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), ServerSocket);
Active = true;
}
catch { ServerSocket.Close(); ServerSocket = null; return ServerState.Error; }
catch { ServerSocket.Close(); return ServerState.Error; }
return ServerState.Start;
}
@ -84,7 +87,7 @@ namespace DroneSimulator
Socket handler;
try { handler = listener.EndAccept(ar); }
catch{ ServerSocket?.Close(); ServerSocket = null; return; }
catch{ ServerSocket?.Close(); Active = false; return; }
if (SocketLimit > ClientSockets.Count)
{
@ -127,7 +130,11 @@ namespace DroneSimulator
ReceiveCallback(new ReceiveData { ID = cd.ID, Buffer = cd.buffer, Size = bytes, Client = cd.workSocket });
cd.workSocket?.BeginReceive(cd.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), cd);
try
{
cd.workSocket?.BeginReceive(cd.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), cd);
}
catch { }
}
}
}

View File

@ -0,0 +1,134 @@
using System.Net.Sockets;
using System.Net;
namespace DroneSimulator
{
internal class NetServerVisual
{
public class ConnectData
{
public bool Connect;
public int Count;
public Socket? Client;
}
public class ReceiveData
{
public byte[]? Buffer;
public int Size;
public Socket? Client;
}
private class ClientData
{
public Socket? workSocket = null;
public const int BufferSize = 1024;
public byte[] buffer = new byte[BufferSize];
}
private int SocketLimit;
private Socket? ServerSocket;
private List<ClientData> ClientSockets = new List<ClientData>();
public delegate void ServerCallback(object o);
private ServerCallback? ConnectionCallback;
private ServerCallback? ReceiveCallback;
private bool Active = false;
public enum ServerState { Error, Start, Stop };
public ServerState StartServer(int Port, int Limit, ServerCallback Connection, ServerCallback Receive)
{
if (Active)
{
ServerSocket?.Close();
foreach (ClientData c in ClientSockets)
{
try { c.workSocket?.Shutdown(SocketShutdown.Both); } catch { }
c.workSocket?.Close();
}
ClientSockets.Clear();
return ServerState.Stop;
}
ConnectionCallback = Connection;
ReceiveCallback = Receive;
SocketLimit = Limit;
IPEndPoint ip = new(IPAddress.Any, Port);
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
ServerSocket.Bind(ip);
ServerSocket.Listen(10);
ServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), ServerSocket);
Active = true;
}
catch { ServerSocket.Close(); return ServerState.Error; }
return ServerState.Start;
}
public void AcceptCallback(IAsyncResult ar)
{
Socket listener = (Socket)ar.AsyncState;
if (listener == null) return;
Socket handler;
try { handler = listener.EndAccept(ar); }
catch{ ServerSocket?.Close(); Active = false; return; }
if (SocketLimit > ClientSockets.Count)
{
ClientData clientData = new ClientData();
clientData.workSocket = handler;
ClientSockets.Add(clientData);
ConnectionCallback(new ConnectData { Connect = true, Count = ClientSockets.Count, Client = handler });
handler.BeginReceive(clientData.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), clientData);
}
else handler.Close();
listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
}
public void ReadCallback(IAsyncResult ar)
{
ClientData cd = (ClientData)ar.AsyncState;
if (cd == null) return;
int bytes = 0;
try { bytes = cd.workSocket.EndReceive(ar); }
catch { }
if (bytes == 0)
{
cd.workSocket?.Close();
ClientSockets.Remove(cd);
ConnectionCallback(new ConnectData { Connect = false, Count = ClientSockets.Count, Client = null });
return;
}
ReceiveCallback(new ReceiveData { Buffer = cd.buffer, Size = bytes, Client = cd.workSocket });
try
{
cd.workSocket?.BeginReceive(cd.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), cd);
}
catch { }
}
}
}

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace DroneSimulator
{

View File

@ -1,23 +0,0 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"DroneSimulator/1.0.0": {
"runtime": {
"DroneSimulator.dll": {}
}
}
}
},
"libraries": {
"DroneSimulator/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

View File

@ -1,19 +0,0 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "9.0.0"
}
],
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false
}
}
}

View File

@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]

View File

@ -1,25 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("DroneSimulator")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("DroneSimulator")]
[assembly: System.Reflection.AssemblyTitleAttribute("DroneSimulator")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Runtime.Versioning.TargetPlatformAttribute("Windows7.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows7.0")]
// Создано классом WriteCodeFragment MSBuild.

View File

@ -1 +0,0 @@
7f461f329c2aabe3c068a957f4f02cdcdb168c359c556cd0c46598798ec3c65d

View File

@ -1,22 +0,0 @@
is_global = true
build_property.ApplicationManifest =
build_property.StartupObject =
build_property.ApplicationDefaultFont =
build_property.ApplicationHighDpiMode =
build_property.ApplicationUseCompatibleTextRendering =
build_property.ApplicationVisualStyles =
build_property.TargetFramework = net9.0-windows
build_property.TargetPlatformMinVersion = 7.0
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = DroneSimulator
build_property.ProjectDir = D:\CPL\Simulator\DroneSimulator\DroneSimulator\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.CsWinRTUseWindowsUIXamlProjections = false
build_property.EffectiveAnalysisLevelStyle = 9.0
build_property.EnableCodeStyleSeverity =

View File

@ -1,10 +0,0 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.Drawing;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using global::System.Windows.Forms;

View File

@ -1 +0,0 @@
051ffb89f1ee627ab3b9aaef920afd665a18f0f3c3fe82852812d5c6608dcb30

View File

@ -1,48 +0,0 @@
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.exe
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.deps.json
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.runtimeconfig.json
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.dll
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.pdb
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.Form1.resources
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.GenerateResource.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.GeneratedMSBuildEditorConfig.editorconfig
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfoInputs.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfo.cs
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.CoreCompileInputs.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.dll
R:\DroneSimulator\obj\Debug\net9.0-windows\refint\DroneSimulator.dll
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.pdb
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.genruntimeconfig.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\ref\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.exe
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.deps.json
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.runtimeconfig.json
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.pdb
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.GenerateResource.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.GeneratedMSBuildEditorConfig.editorconfig
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfoInputs.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfo.cs
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.CoreCompileInputs.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\refint\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.pdb
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.genruntimeconfig.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\ref\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources
D:\CPL\Simulator\DroneSimulator\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.exe
D:\CPL\Simulator\DroneSimulator\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.deps.json
D:\CPL\Simulator\DroneSimulator\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.runtimeconfig.json
D:\CPL\Simulator\DroneSimulator\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.dll
D:\CPL\Simulator\DroneSimulator\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.pdb
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.GenerateResource.cache
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.GeneratedMSBuildEditorConfig.editorconfig
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfoInputs.cache
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfo.cs
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.CoreCompileInputs.cache
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.dll
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\refint\DroneSimulator.dll
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.pdb
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.genruntimeconfig.cache
D:\CPL\Simulator\DroneSimulator\DroneSimulator\obj\Debug\net9.0-windows\ref\DroneSimulator.dll

View File

@ -1,11 +0,0 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {}
},
"libraries": {}
}

View File

@ -1,25 +0,0 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "9.0.0"
}
],
"additionalProbingPaths": [
"C:\\Users\\USER\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\USER\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false,
"Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
}
}
}

View File

@ -1 +0,0 @@
77eb2f8d5fd7b96d896def58f5f04d71ddf79c26314f987f4254b0ca5d5a8991

Some files were not shown because too many files have changed in this diff Show More