3.183.18ydh充电机发送

master
CZ 8 months ago
commit 9e43d4d526

@ -22,6 +22,9 @@ namespace BatCharging.Model
public UInt16 LengthDomain { get; set; } public UInt16 LengthDomain { get; set; }
/// <summary> /// <summary>
/// 信息域 /// 信息域
///
/// 除了 CMD=1202 加密能用 RSA 加密方式,
/// 其他报文若是加密,全部是采用 AES方式加密。
/// <para>bit0-3 当前协议是V2.6值填0x02</para> /// <para>bit0-3 当前协议是V2.6值填0x02</para>
/// </summary> /// </summary>
public byte infoDomain { get; set; } public byte infoDomain { get; set; }

File diff suppressed because it is too large Load Diff

@ -1,5 +1,6 @@
using BatCharging.Model; using BatCharging.Model;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -35,10 +36,73 @@ namespace BatCharging.Service
lstResult.AddRange(packSrcs); lstResult.AddRange(packSrcs);
//数据域 //数据域
lstResult.AddRange(baseApci.dataDomain); lstResult.AddRange(baseApci.dataDomain);
baseApci.checksumDomain = checksumDomain(lstResult.ToArray());
//校验和域 //校验和域
lstResult.Add(baseApci.checksumDomain); lstResult.Add(baseApci.checksumDomain);
} }
return lstResult; return lstResult;
} }
public static byte checksumDomain(byte[] data)
{
int checksum = 0;
for (int i = 8; i < data.Count(); i++)//这里没校验域所以不减一
{
checksum += data[i];
}
//foreach (byte b in data)
//{
// checksum += b;
//}
// 取校验和的低8位
return (byte)(checksum & 0xFF);
}
public static bool checksumDomainReceive(byte[] data)
{
bool bResult = false;
int checksum = 0;
for (int i = 8; i < data.Count() - 1; i++)//这里有校验域所以减一
{
checksum += data[i];
}
//foreach (byte b in data)
//{
// checksum += b;
//}
// 取校验和的低8位
if (data[data.Count()-1] == (byte)(checksum & 0xFF))
bResult = true;
return bResult;
}
public static ushort ComputeHeaderIpChecksum(byte[] header, int start, int length)
{
ushort word16;
long sum = 0;
for (int i = start; i < (length + start); i += 2)
{
word16 = (ushort)(((header[i] << 8) & 0xFF00)
+ (header[i + 1] & 0xFF));
sum += (long)word16;
}
while ((sum >> 16) != 0)
{
sum = (sum & 0xFFFF) + (sum >> 16);
}
sum = ~sum;
return (ushort)sum;
}
} }
} }

@ -1060,7 +1060,7 @@ namespace BatCharging.Service.DataRlt
CMD1501.value01 = ByteUtils.DToUInt16(data, 8); CMD1501.value01 = ByteUtils.DToUInt16(data, 8);
CMD1501.value02 = ByteUtils.DToUInt16(data, 10); CMD1501.value02 = ByteUtils.DToUInt16(data, 10);
CMD1501.value03 = Encoding.ASCII.GetString(data, 12, 32); CMD1501.value03 = Encoding.ASCII.GetString(data, 12, 32);
CMD1501.value04 = Encoding.ASCII.GetString(data, 44, 32); CMD1501.value04 = Encoding.ASCII.GetString(data, 44, 128);
} }
return CMD1501; return CMD1501;
} }

@ -1839,7 +1839,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;

@ -10,6 +10,7 @@
/// </summary> /// </summary>
public Dictionary<uint, ushort> cmd3StartAddress = new Dictionary<uint, ushort>(); public Dictionary<uint, ushort> cmd3StartAddress = new Dictionary<uint, ushort>();
//public Dictionary<>
public void SetCmd3StartAddress() public void SetCmd3StartAddress()
{ {
@ -36,5 +37,64 @@
} }
public static byte checksumDomain(byte[] data)
{
int checksum = 0;
for (int i = 8; i < data.Count(); i++)//这里没校验域所以不减一
{
checksum += data[i];
}
//foreach (byte b in data)
//{
// checksum += b;
//}
// 取校验和的低8位
return (byte)(checksum & 0xFF);
}
public static bool checksumDomainReceive(byte[] data)
{
bool bResult = false;
int checksum = 0;
for (int i = 8; i < data.Count() - 1; i++)//这里有校验域所以减一
{
checksum += data[i];
}
//foreach (byte b in data)
//{
// checksum += b;
//}
// 取校验和的低8位
if (data[data.Count() - 1] == (byte)(checksum & 0xFF))
bResult = true;
return bResult;
}
public static ushort ComputeHeaderIpChecksum(byte[] header, int start, int length)
{
ushort word16;
long sum = 0;
for (int i = start; i < (length + start); i += 2)
{
word16 = (ushort)(((header[i] << 8) & 0xFF00)
+ (header[i + 1] & 0xFF));
sum += (long)word16;
}
while ((sum >> 16) != 0)
{
sum = (sum & 0xFFFF) + (sum >> 16);
}
sum = ~sum;
return (ushort)sum;
}
} }
} }

@ -338,7 +338,7 @@ namespace Module.Socket.Tool
{ {
readByte = ClientStream.Read(FixedBuffer, 0, BufferSize); readByte = ClientStream.Read(FixedBuffer, 0, BufferSize);
if (readByte == 0) break; if (readByte == 0) break;
else if (readByte >= 24) else if (readByte >= 9)
{ {
bytesResult = GetReadResult(FixedBuffer, readByte); bytesResult = GetReadResult(FixedBuffer, readByte);
} }
@ -387,7 +387,27 @@ namespace Module.Socket.Tool
Thread.Sleep(20); Thread.Sleep(20);
} }
} }
public bool checksumDomainReceive(byte[] data)
{
bool bResult = false;
int checksum = 0;
for (int i = 8; i < data.Count() - 1; i++)//这里有校验域所以减一
{
checksum += data[i];
}
//foreach (byte b in data)
//{
// checksum += b;
//}
// 取校验和的低8位
byte b1 = (byte)(checksum & 0xFF);
byte b2 = data[data.Count() - 1];
if (data[data.Count() - 1] == (byte)(checksum & 0xFF))
bResult = true;
return bResult;
}
private List<byte[]> GetReadResult(byte[] bytes, int readLen) private List<byte[]> GetReadResult(byte[] bytes, int readLen)
{ {
List<byte[]> lstResult = new List<byte[]>(); List<byte[]> lstResult = new List<byte[]>();
@ -415,7 +435,10 @@ namespace Module.Socket.Tool
// 使用Array.Copy方法将原始数组中的一部分复制到新数组 // 使用Array.Copy方法将原始数组中的一部分复制到新数组
Array.Copy(bytesCppy, i, newBytes, 0, leng); Array.Copy(bytesCppy, i, newBytes, 0, leng);
lstResult.Add(newBytes);
//校验域是否正确
if (checksumDomainReceive(newBytes))
lstResult.Add(newBytes);
} }
} }
} }

Loading…
Cancel
Save