Compare commits

..

2 Commits

Author SHA1 Message Date
高国正 1281b1c854 init 2023-02-25 15:33:03 +08:00
高国正 e98fbeadfd init 2023-02-24 16:13:56 +08:00
26 changed files with 193955 additions and 0 deletions

Binary file not shown.

32
DianBiao/App.config Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="SysAppender" />
</root>
<logger name="WebLogger">
<level value="DEBUG" />
</logger>
<appender name="SysAppender" type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value="App_Data/" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="&quot;Logs_&quot;yyyyMMdd&quot;.txt&quot;" />
<param name="StaticLogFileName" value="false" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
<param name="Header" value=" ------------------------------------------------&#xD;&#xA;" />
<param name="Footer" value=" ------------------------------------------------&#xD;&#xA;" />
</layout>
</appender>
<appender name="consoleApp" type="log4net.Appender.ConsoleAppender,log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
</log4net>
</configuration>

58
DianBiao/DianBiao.csproj Normal file
View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>DianBiao</RootNamespace>
<AssemblyName>DianBiao</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ToolKit.cs" />
<Compile Include="Dianbiao.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

25
DianBiao/DianBiao.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32929.386
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DianBiao", "DianBiao.csproj", "{CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CD5CE7DD-0001-4A60-AE34-8E91E74534F4}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("DianBiao")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DianBiao")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("ca663f4f-3d66-454e-9c4a-1c1ed2a7b8c0")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

382
DianBiao/ToolKit.cs Normal file
View File

@ -0,0 +1,382 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ToolKitlib
{
#region ToolKit
/// <summary>
/// 转换工具包
/// </summary>
internal class ToolKit
{
/// <summary>
/// 16进制转字符串(十进制)**
/// </summary>
/// <param name="hexStr"></param>
/// <returns></returns>
public static string hexStr2Str(String hexStr)
{
String str = "0123456789ABCDEF";
char[] hexs = hexStr.ToCharArray();
byte[] bytes = new byte[hexStr.Length / 2];
int n;
for (int i = 0; i < bytes.Length; i++)
{
n = str.IndexOf(hexs[2 * i]) * 16;
n += str.IndexOf(hexs[2 * i + 1]);
bytes[i] = (byte)(n & 0xff);
}
StringBuilder stringBuilder = new StringBuilder("");
for (int i = 0; i < bytes.Length; i++)
{
stringBuilder.Append(bytes[i]);
}
return stringBuilder.ToString();
}
/// <summary>
/// 16进制转ASCII码**
/// </summary>
/// <param name="hexStr">16进制字符</param>
/// <returns></returns>
public static StringBuilder hexToASCII(string hexStr)
{
String str = "0123456789ABCDEF";
char[] hexs = hexStr.ToCharArray();
byte[] bytes = new byte[hexStr.Length / 2];
int n;
for (int i = 0; i < bytes.Length; i++)
{
n = str.IndexOf(hexs[2 * i]) * 16;
n += str.IndexOf(hexs[2 * i + 1]);
bytes[i] = (byte)(n & 0xff);
}
StringBuilder VersionNumber = new StringBuilder("");
for (int i = 0; i < bytes.Length; i++)
{
VersionNumber.Append((char)bytes[i]);
}
return VersionNumber;
}
/// <summary>
/// 获取高四位**
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static int getHeight4(byte data)
{
int height;
height = ((data & 0xf0) >> 4);
return height;
}
/// <summary>
/// 获取低四位**
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static int getLow4(byte data)
{
int low;
low = (data & 0x0f);
return low;
}
/// <summary>
/// byte数组转string
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string byteArrayToString(byte[] data, Encoding encoding)
{
return encoding.GetString(data);
}
/// <summary>
/// 将列表 转为byte[]
/// </summary>
/// <param name="matrix"></param>
/// <returns></returns>
public static byte[] listToBytes(List<byte> matrix)
{
if (matrix == null)
{
return new byte[0];
}
using (MemoryStream stream = new MemoryStream())
{
BinaryWriter bw = new BinaryWriter(stream);
foreach (var item in matrix)
{
bw.Write(item);
}
return stream.ToArray();
}
}
/// <summary>
/// string转 byte数组
/// </summary>
/// <param name="data"></param>
/// <param name="fromBase">传入数据进制</param>
/// <returns></returns>
public static byte[] stringToByteArray(string data, int fromBase)
{
if (data.Length < 2 || data.Length % 2 != 0) return null;
byte[] bytes = new byte[(data.Length) / 2];
for (int i = 0; i < data.Length; i++)
{
if (i != 0 && i % 2 != 0)
{
ushort a = (ushort)Convert.ToInt16((data[i - 1].ToString() + data[i].ToString()).ToString(), fromBase);
bytes[(i - 1) / 2] = (byte)(a);
}
}
return bytes;
}
/// <summary>
/// string转byte数组--针对校验位
/// </summary>
/// <param name="str"></param>
/// <returns>[0]--高位;[1]地位--</returns>
public static byte[] stringToByteArray(string str)
{
//var a = "332A";
ushort u = (ushort)Convert.ToInt16(str, 16);//0x332A
byte g = (byte)(u / 256);//0x33 高位
byte d = (byte)(u % 256);//0x2A 地位
return new byte[] { g, d };
}
/// <summary>
/// byte数组转16进制字符串
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string byteArrayToHexString(byte[] data)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
builder.Append(string.Format("{0:X2} ", data[i]));
}
return builder.ToString().Trim();
}
/// <summary>
/// byte数组转16进制字符串--接收
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string byteArrayToHexString(byte[] data, int length = 0)
{
int dataLength = 0;
if (length != 0) dataLength = length;
else dataLength = data.Length;
StringBuilder builder = new StringBuilder();
for (int i = 0; i < dataLength; i++)
{
builder.Append(string.Format("{0:X2} ", data[i]));
}
return builder.ToString().Trim();
}
/// <summary>
/// 16进制字符串转byte数组
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] hexStringToByteArray(string data)
{
string[] chars = data.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
byte[] returnBytes = new byte[chars.Length];
//逐个字符变为16进制字节数据
for (int i = 0; i < chars.Length; i++)
{
returnBytes[i] = Convert.ToByte(chars[i], 16);
}
return returnBytes;
}
/// <summary>
/// byte数组转10进制字符串
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string byteArrayToDecString(byte[] data)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
builder.Append(data[i] + " ");
}
return builder.ToString().Trim();
}
/// <summary>
/// 10进制字符串转byte数组
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] decStringToByteArray(string data)
{
string[] chars = data.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
byte[] returnBytes = new byte[chars.Length];
//逐个字符变为10进制字节数据
for (int i = 0; i < chars.Length; i++)
{
returnBytes[i] = Convert.ToByte(chars[i], 10);
}
return returnBytes;
}
/// <summary>
/// byte数组转八进制字符串
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string byteArrayToOtcString(byte[] data)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
builder.Append(Convert.ToString(data[i], 8) + " ");
}
return builder.ToString().Trim();
}
/// <summary>
/// 八进制字符串转byte数组
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] otcStringToByteArray(string data)
{
string[] chars = data.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
byte[] returnBytes = new byte[chars.Length];
//逐个字符变为8进制字节数据
for (int i = 0; i < chars.Length; i++)
{
returnBytes[i] = Convert.ToByte(chars[i], 8);
}
return returnBytes;
}
/// <summary>
/// 二进制字符串转byte数组
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] binStringToByteArray(string data)
{
string[] chars = data.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
byte[] returnBytes = new byte[chars.Length];
//逐个字符变为2进制字节数据
for (int i = 0; i < chars.Length; i++)
{
returnBytes[i] = Convert.ToByte(chars[i], 2);
}
return returnBytes;
}
/// <summary>
/// byte数组转二进制字符串
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string byteArrayToBinString(byte[] data)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
builder.Append(Convert.ToString(data[i], 2) + " ");
}
return builder.ToString().Trim();
}
/// <summary>
/// 每8bit高低位互换
/// </summary>
/// <param name="j">起始</param>
/// <param name="k">终止</param>
/// <param name="message">需要转换的16进制数据</param>
/// <returns>新的16进制数据</returns>
public static string interconvert(int j, int k, string message, bool exchange = true)
{
StringBuilder parityBitCS = new StringBuilder("");//互换后的值
string[] strings = new string[4] { message[0].ToString() + message[1].ToString(), message[2].ToString() + message[3].ToString(), message[4].ToString() + message[5].ToString(), message[6].ToString() + message[7].ToString() };
for (int i = strings.Length - 1; i >= 0; i--)
{
parityBitCS.Append(strings[i].ToString());
}
return Convert.ToInt32(parityBitCS.ToString(), 16).ToString();
}
/// <summary>
/// byte[]直接转Float**
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static float byteToFloat(string message)
{
byte[] bFxianOrg = new byte[4];
var a = Encoding.Default.GetBytes(message);
StringBuilder zz = new StringBuilder("");
StringBuilder _zz = new StringBuilder("");
string[] s = new string[4];
int x = 0;
for (int i = 0; i < a.Length; i++)
{
if (x != 0 && i % 2 == 0)
{
zz.Append(int.Parse(hexStr2Str(_zz.ToString())).ToString()).Append("-");
_zz.Clear();
x = 0;
}
_zz.Append(((char)a[i]).ToString());
if (i == a.Length - 1)
{
zz.Append(int.Parse(hexStr2Str(_zz.ToString())).ToString()).Append("-");
_zz.Clear();
}
x++;
}
s = zz.ToString().Split('-');
byte a0 = byte.Parse(s[0].ToString());
byte a1 = byte.Parse(s[1].ToString());
byte a2 = byte.Parse(s[2].ToString());
byte a3 = byte.Parse(s[3].ToString());
bFxianOrg = new byte[4] { a0, a1, a2, a3 };
var b = BitConverter.ToSingle(bFxianOrg, 0);
return b;
}
/// <summary>
/// string[]转string**
/// </summary>
/// <param name="vs"></param>
/// <returns></returns>
public static string strsTostring(string[] vs)
{
return String.Join("", vs);//引号中可加字符串分隔符
}
}
#endregion
}

83
DianBiao/dianbiao.cs Normal file
View File

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using ToolKitlib;
using System.Net.Sockets;
using System.Net;
namespace DianBiao
{
class Dianbiao
{
static log4net.ILog log;//日志插件
public static Socket udpServer;//udp服务器
public static bool memberReply;//是否回复消息
public static int length = 0;//接收数据长度
public static EndPoint serverEnd; //服务端
public static IPEndPoint ipEnd; //发送消息服务端
public static Socket socket; //目标socket
public static Thread connectThread; //连接线程
public static byte[] sendData;//发送的数据
static void Main(string[] args)
{
//初始化日志
log4net.Config.XmlConfigurator.Configure();
log = log4net.LogManager.GetLogger("loginfo");
init();
while (true)
{
Thread.Sleep(10000);
}
}
private static void init()
{
try
{
//var IP = "111.229.30.246";
var IP = "172.17.0.9";
//string IP = "172.16.1.49";
int Port = 12302;
//建立udp服务器参数2udp协议以数据报的方式传输参数3UDP协议
udpServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
//为服务器绑定IP
IPAddress ip = IPAddress.Parse(IP);
EndPoint ep = new IPEndPoint(ip, Port);
udpServer.Bind(ep);
//接收数据
EndPoint endP = new IPEndPoint(IPAddress.Any, 0);
string message;
byte[] data = new byte[1024 * 1024 * 2];
length = 0;
//把数据的来源放到第二个参数上
while (true)
{
length = udpServer.ReceiveFrom(data, ref endP);
//message = Encoding.Default.GetString(data, 0, length);
message = ToolKit.byteArrayToHexString(data, length);
log.Info("接收到 " + endP.ToString() + ": " + message);
message = message.Replace(" ", "");
}
}
catch (Exception e)
{
Console.WriteLine("接收初始化:" + e.Message);
}
}
}
}

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]

4
DianBiao/packages.config Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.8" targetFramework="net472" />
</packages>

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.