master
CZ 8 months ago
commit 3a13d01592

@ -1014,8 +1014,8 @@ namespace BatCharging.Service
if (CMD4 != null)
{
byte type = 0;
uint startAddress = 0;
byte[] setData = null;
uint startAddress = 1;
byte[] setData = new byte[4];
//(CMD=3)后台服务器下发充电桩字符型参数
CmnChargerParam._CHR00TCPCLIENT.Send3(type, startAddress, setData);
@ -1035,7 +1035,7 @@ namespace BatCharging.Service
byte type = 0;
uint startAddress = 0;
byte num = 0;
byte[] setData = null;
byte[] setData = new byte[4];
//(CMD=5)后台服务器下发充电桩控制命令
CmnChargerParam._CHR00TCPCLIENT.Send5(type, startAddress, num, setData);

@ -331,7 +331,7 @@ namespace BatCharging.Service
CMD3.value2 = 0;
CMD3.value3 = type;
CMD3.value4 = startAddress;
CMD3.value5 = pubCommonClass.cmd3StartAddress[startAddress];
CMD3.value5 = PubCommonClass.cmd3StartAddress[startAddress];
CMD3.value6 = setData;
byte[] bytes = new ChargerSendCMD().SendRCMD3(out APDUModel, CMD3);

@ -48,7 +48,7 @@ namespace BatCharging.Service
{
int checksum = 0;
for (int i = 8; i < data.Count(); i++)//这里没校验域所以不减一
for (int i = 6; i < data.Count(); i++)//这里没校验域所以不减一
{
checksum += data[i];
}

@ -17,7 +17,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -74,7 +74,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -128,7 +128,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -182,7 +182,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -240,7 +240,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -293,7 +293,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -340,7 +340,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -386,7 +386,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -444,7 +444,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -491,7 +491,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -536,7 +536,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -581,7 +581,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -631,7 +631,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -684,7 +684,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -741,7 +741,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -790,7 +790,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -846,7 +846,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -897,7 +897,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -943,7 +943,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -990,7 +990,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1039,7 +1039,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1083,7 +1083,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1127,7 +1127,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1171,7 +1171,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1215,7 +1215,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1260,7 +1260,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1304,7 +1304,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1353,7 +1353,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1396,7 +1396,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1508,7 +1508,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1632,7 +1632,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1678,7 +1678,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1738,7 +1738,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;
@ -1788,7 +1788,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5;
model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff;
model.CMD = 1;

@ -8,7 +8,7 @@
/// <summary>
///
/// </summary>
public Dictionary<uint, ushort> cmd3StartAddress = new Dictionary<uint, ushort>();
public static Dictionary<uint, ushort> cmd3StartAddress = new Dictionary<uint, ushort>();
//public Dictionary<>

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Module.Socket.Tool
{
/// <summary>
/// AES加密
/// </summary>
public class AesEncryption
{
private static readonly byte[] Key = Encoding.UTF8.GetBytes("YourSecretKeyHere12345678"); // 必须是32字节256位
private static readonly byte[] Iv = Encoding.UTF8.GetBytes("YourInitializationVectorHere"); // 必须是16字节128位
public static byte[] EncryptStringToBytes(string plainText)
{
if (plainText == null || plainText.Length <= 0)
throw new ArgumentNullException(nameof(plainText));
if (Key == null || Key.Length != 32)
throw new ArgumentNullException(nameof(Key));
if (Iv == null || Iv.Length != 16)
throw new ArgumentNullException(nameof(Iv));
byte[] encrypted;
using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = Key;
aesAlg.IV = Iv;
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(plainText);
}
encrypted = msEncrypt.ToArray();
}
}
return encrypted;
}
public static string DecryptBytesToString(byte[] cipherText)
{
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException(nameof(cipherText));
if (Key == null || Key.Length != 32)
throw new ArgumentNullException(nameof(Key));
if (Iv == null || Iv.Length != 16)
throw new ArgumentNullException(nameof(Iv));
string plaintext = null;
using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = Key;
aesAlg.IV = Iv;
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msDecrypt = new MemoryStream(cipherText))
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
plaintext = srDecrypt.ReadToEnd();
}
}
return plaintext;
}
}
}

@ -42,6 +42,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AesEncryption.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TcpClientChargerTool.cs" />
<Compile Include="ReceivedEventArgs.cs" />

@ -392,7 +392,7 @@ namespace Module.Socket.Tool
bool bResult = false;
int checksum = 0;
for (int i = 8; i < data.Count() - 1; i++)//这里有校验域所以减一
for (int i = 6; i < data.Count() - 1; i++)//这里有校验域所以减一
{
checksum += data[i];
}
@ -438,7 +438,22 @@ namespace Module.Socket.Tool
//校验域是否正确
if (checksumDomainReceive(newBytes))
lstResult.Add(newBytes);
{
var info = newBytes[4];
if ((info & (1 << 1)) != 0)//AES加密
{
List<byte> byteList = newBytes.ToList();
byteList.Remove(8);
byteList.Remove(8);//移除前面两个长度
newBytes= byteList.ToArray();
lstResult.Add(newBytes);
}
else //不加密
{
lstResult.Add(newBytes);
}
}
}
}
}

@ -1,3 +1,4 @@
using CommonClass;
using System;
using System.Collections.Generic;
using System.Linq;
@ -14,6 +15,8 @@ namespace Monitor.ChargeTest
[STAThread]
static void Main()
{
new PubCommonClass().SetCmd3StartAddress();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmChargeResult());

Loading…
Cancel
Save