From 18e83f5e87b26324a180750213498ba00ea750ce Mon Sep 17 00:00:00 2001 From: CZ Date: Fri, 15 Mar 2024 16:33:42 +0800 Subject: [PATCH] secound --- BatCharging.Model/客户端发送/CMD1.cs | 2 +- BatCharging.Model/客户端发送/CMD103.cs | 6 +- BatCharging.Model/客户端发送/CMD3.cs | 8 +- BatCharging.Model/客户端发送/CMD5.cs | 2 +- BatCharging.Model/客户端发送/CMD9.cs | 12 +- .../BatCharging.Service.csproj | 1 + BatCharging.Service/ChargerMgrTool.cs | 297 +++++++++--- BatCharging.Service/ChargerSendMsg.cs | 398 +++++++++++----- BatCharging.Service/Common/PublicProgram.cs | 5 + .../发送方法/ChargerSendCMD.cs | 432 +++++------------- ChargeInterfaceTest.sln | 6 + CommonClass/CommonClass.csproj | 9 + CommonClass/PubCommonClass.cs | 40 ++ 13 files changed, 713 insertions(+), 505 deletions(-) create mode 100644 CommonClass/CommonClass.csproj create mode 100644 CommonClass/PubCommonClass.cs diff --git a/BatCharging.Model/客户端发送/CMD1.cs b/BatCharging.Model/客户端发送/CMD1.cs index bfa50d3..3bb78c8 100644 --- a/BatCharging.Model/客户端发送/CMD1.cs +++ b/BatCharging.Model/客户端发送/CMD1.cs @@ -37,7 +37,7 @@ namespace BatCharging.Model /// /// 设置数据 /// - public UInt32 value7 { get; set; } + public byte[] value7 { get; set; } /* diff --git a/BatCharging.Model/客户端发送/CMD103.cs b/BatCharging.Model/客户端发送/CMD103.cs index 6022646..b5d5de8 100644 --- a/BatCharging.Model/客户端发送/CMD103.cs +++ b/BatCharging.Model/客户端发送/CMD103.cs @@ -11,11 +11,11 @@ namespace BatCharging.Model /// /// 预留 /// - public byte value01 { get; set; } + public ushort value01 { get; set; } /// /// 预留 /// - public byte value02 { get; set; } + public ushort value02 { get; set; } /// /// 充电口号(这个字段与 104 报文字段 5 一致) /// @@ -25,6 +25,6 @@ namespace BatCharging.Model /// 0:否 /// 1:是 /// - public byte value04 { get; set; } + public bool value04 { get; set; } } } diff --git a/BatCharging.Model/客户端发送/CMD3.cs b/BatCharging.Model/客户端发送/CMD3.cs index 096b2ca..0905bdd 100644 --- a/BatCharging.Model/客户端发送/CMD3.cs +++ b/BatCharging.Model/客户端发送/CMD3.cs @@ -27,16 +27,12 @@ namespace BatCharging.Model /// public UInt32 value4 { get; set; } /// - /// 设置/查询个数 - /// - public byte value5 { get; set; } - /// /// 设置参数字节数 /// - public UInt16 value6 { get; set; } + public UInt16 value5 { get; set; } /// /// 设置数据 /// - public UInt32 value7 { get; set; } + public byte[] value6 { get; set; } } } diff --git a/BatCharging.Model/客户端发送/CMD5.cs b/BatCharging.Model/客户端发送/CMD5.cs index 34b63fc..b218ed9 100644 --- a/BatCharging.Model/客户端发送/CMD5.cs +++ b/BatCharging.Model/客户端发送/CMD5.cs @@ -35,6 +35,6 @@ namespace BatCharging.Model /// /// 命令参数 /// - public UInt32 value7 { get; set; } + public byte[] value7 { get; set; } } } diff --git a/BatCharging.Model/客户端发送/CMD9.cs b/BatCharging.Model/客户端发送/CMD9.cs index 445d353..d2abb21 100644 --- a/BatCharging.Model/客户端发送/CMD9.cs +++ b/BatCharging.Model/客户端发送/CMD9.cs @@ -12,11 +12,11 @@ namespace BatCharging.Model /// /// 预留 /// - public byte value01 { get; set; } + public ushort value01 { get; set; } /// /// 预留 /// - public byte value02 { get; set; } + public ushort value02 { get; set; } /// /// 充电枪号 /// @@ -24,18 +24,18 @@ namespace BatCharging.Model /// /// 执行结果 /// - public byte value04 { get; set; } + public uint value04 { get; set; } /// /// 命令地址 /// - public byte value05 { get; set; } + public uint value05 { get; set; } /// /// 数据长度 /// - public byte value06 { get; set; } + public uint value06 { get; set; } /// /// 数据 /// - public string value07 { get; set; } + public byte[] value07 { get; set; } } } diff --git a/BatCharging.Service/BatCharging.Service.csproj b/BatCharging.Service/BatCharging.Service.csproj index dc224b0..9ef2a7e 100644 --- a/BatCharging.Service/BatCharging.Service.csproj +++ b/BatCharging.Service/BatCharging.Service.csproj @@ -12,6 +12,7 @@ + diff --git a/BatCharging.Service/ChargerMgrTool.cs b/BatCharging.Service/ChargerMgrTool.cs index 0fe7f7c..99737b4 100644 --- a/BatCharging.Service/ChargerMgrTool.cs +++ b/BatCharging.Service/ChargerMgrTool.cs @@ -1433,8 +1433,81 @@ namespace BatCharging.Service if (CMD1104 != null) { + CMD1103 CMD = new CMD1103(); + CMD.startHour1 = 0; + CMD.startMinute1 = 0; + CMD.endHour1 = 0; + CMD.endMinute1 = 0; + CMD.rate1 = 0; + + CMD.startHour2 = 0; + CMD.startMinute2 = 0; + CMD.endHour2 = 0; + CMD.endMinute2 = 0; + CMD.rate2 = 0; + + CMD.startHour3 = 0; + CMD.startMinute3 = 0; + CMD.endHour3 = 0; + CMD.endMinute3 = 0; + CMD.rate3 = 0; + + CMD.startHour4 = 0; + CMD.startMinute4 = 0; + CMD.endHour4 = 0; + CMD.endMinute4 = 0; + CMD.rate4 = 0; + + CMD.startHour5 = 0; + CMD.startMinute5 = 0; + CMD.endHour5 = 0; + CMD.endMinute5 = 0; + CMD.rate5 = 0; + + CMD.startHour6 = 0; + CMD.startMinute6 = 0; + CMD.endHour6 = 0; + CMD.endMinute6 = 0; + CMD.rate6 = 0; + + CMD.startHour7 = 0; + CMD.startMinute7 = 0; + CMD.endHour7 = 0; + CMD.endMinute7 = 0; + CMD.rate7 = 0; + + CMD.startHour8 = 0; + CMD.startMinute8 = 0; + CMD.endHour8 = 0; + CMD.endMinute8 = 0; + CMD.rate8 = 0; + + CMD.startHour9 = 0; + CMD.startMinute9 = 0; + CMD.endHour9 = 0; + CMD.endMinute9 = 0; + CMD.rate9 = 0; + + CMD.startHour10 = 0; + CMD.startMinute10 = 0; + CMD.endHour10 = 0; + CMD.endMinute10 = 0; + CMD.rate10 = 0; + + CMD.startHour11 = 0; + CMD.startMinute11 = 0; + CMD.endHour11 = 0; + CMD.endMinute11 = 0; + CMD.rate11 = 0; + + CMD.startHour12 = 0; + CMD.startMinute12 = 0; + CMD.endHour12 = 0; + CMD.endMinute12 = 0; + CMD.rate12 = 0; + //(CMD=9)后台服务器应答桩上传命令请求(预留) - CmnChargerParam._CHR00TCPCLIENT.Send1103(); + CmnChargerParam._CHR00TCPCLIENT.Send1103(CMD); } } @@ -1448,8 +1521,93 @@ namespace BatCharging.Service if (CMD1106 != null) { + CMD1105 CMD = new CMD1105(); + CMD.startHour1 = 0; + CMD.startMinute1 = 0; + CMD.endHour1 = 0; + CMD.endMinute1 = 0; + CMD.rate1 = 0; + CMD.reserveRate1 = 0; + + CMD.startHour2 = 0; + CMD.startMinute2 = 0; + CMD.endHour2 = 0; + CMD.endMinute2 = 0; + CMD.rate2 = 0; + CMD.reserveRate2 = 0; + + CMD.startHour3 = 0; + CMD.startMinute3 = 0; + CMD.endHour3 = 0; + CMD.endMinute3 = 0; + CMD.rate3 = 0; + CMD.reserveRate3 = 0; + + CMD.startHour4 = 0; + CMD.startMinute4 = 0; + CMD.endHour4 = 0; + CMD.endMinute4 = 0; + CMD.rate4 = 0; + CMD.reserveRate4 = 0; + + CMD.startHour5 = 0; + CMD.startMinute5 = 0; + CMD.endHour5 = 0; + CMD.endMinute5 = 0; + CMD.rate5 = 0; + CMD.reserveRate5 = 0; + + CMD.startHour6 = 0; + CMD.startMinute6 = 0; + CMD.endHour6 = 0; + CMD.endMinute6 = 0; + CMD.rate6 = 0; + CMD.reserveRate6 = 0; + + CMD.startHour7 = 0; + CMD.startMinute7 = 0; + CMD.endHour7 = 0; + CMD.endMinute7 = 0; + CMD.rate7 = 0; + CMD.reserveRate7 = 0; + + CMD.startHour8 = 0; + CMD.startMinute8 = 0; + CMD.endHour8 = 0; + CMD.endMinute8 = 0; + CMD.rate8 = 0; + CMD.reserveRate8 = 0; + + CMD.startHour9 = 0; + CMD.startMinute9 = 0; + CMD.endHour9 = 0; + CMD.endMinute9 = 0; + CMD.rate9 = 0; + CMD.reserveRate9 = 0; + + CMD.startHour10 = 0; + CMD.startMinute10 = 0; + CMD.endHour10 = 0; + CMD.endMinute10 = 0; + CMD.rate10 = 0; + CMD.reserveRate10 = 0; + + CMD.startHour11 = 0; + CMD.startMinute11 = 0; + CMD.endHour11 = 0; + CMD.endMinute11 = 0; + CMD.rate11 = 0; + CMD.reserveRate11 = 0; + + CMD.startHour12 = 0; + CMD.startMinute12 = 0; + CMD.endHour12 = 0; + CMD.endMinute12 = 0; + CMD.rate12 = 0; + CMD.reserveRate12 = 0; + //(CMD=9)后台服务器应答桩上传命令请求(预留) - CmnChargerParam._CHR00TCPCLIENT.Send1105(); + CmnChargerParam._CHR00TCPCLIENT.Send1105(CMD); } } @@ -1481,8 +1639,28 @@ namespace BatCharging.Service if (CMD1302 != null) { + + CMD1301 CMD = new CMD1301(); + CMD.reserved1 = 0; + CMD.reserved2 = 0; + //CMD.chargingStationCode = chargingStationCode; + //CMD.whitelistType = whitelistType; + //CMD.operation = operation; + //CMD.whitelistVersionNum = whitelistVersionNum; + //CMD.DistributeWhitelistNum = DistributeWhitelistNum; + //CMD.carVinOrChargCardNum01 = carVinOrChargCardNum01; + //CMD.carVinOrChargCardNum02 = carVinOrChargCardNum02; + //CMD.carVinOrChargCardNum03 = carVinOrChargCardNum03; + //CMD.carVinOrChargCardNum04 = carVinOrChargCardNum04; + //CMD.carVinOrChargCardNum05 = carVinOrChargCardNum05; + //CMD.carVinOrChargCardNum06 = carVinOrChargCardNum06; + //CMD.carVinOrChargCardNum07 = carVinOrChargCardNum07; + //CMD.carVinOrChargCardNum08 = carVinOrChargCardNum08; + //CMD.carVinOrChargCardNum09 = carVinOrChargCardNum09; + //CMD.carVinOrChargCardNum10 = carVinOrChargCardNum10; + //(CMD=9)后台服务器应答桩上传命令请求(预留) - CmnChargerParam._CHR00TCPCLIENT.Send1301(); + CmnChargerParam._CHR00TCPCLIENT.Send1301(CMD); } } @@ -1500,7 +1678,7 @@ namespace BatCharging.Service if (CMD1402 != null) { //(CMD=9)后台服务器应答桩上传命令请求(预留) - CmnChargerParam._CHR00TCPCLIENT.Send1401(); + //CmnChargerParam._CHR00TCPCLIENT.Send1401(); } } @@ -1547,20 +1725,20 @@ namespace BatCharging.Service if (CMD1501 != null) { - + PublicProgram.failName01 = CMD1501.value03 + "/" + CMD1501.value04 + "/" + DateTime.Now.ToString("yyyyMMddHHmmss"); //(CMD=9)后台服务器应答桩上传命令请求(预留) - CmnChargerParam._CHR00TCPCLIENT.Send1502(); - - // - /* + CmnChargerParam._CHR00TCPCLIENT.Send1502(0); - 说明:日志保存文件名建议服务器先建立一个按桩号命名的目录,然后使用“字段 4 前缀+ - 时间+字段 4 后缀”,如字段 4 上传的是 charger.xls 文件名,则保存成 - 112233445566/charger202106151625.xls 文件,其中“112233445566/”是按桩号生成的目录路径 - - */ + //获取桌面路径 + string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + // 检查文件夹是否已经存在 + if (!Directory.Exists(folderPath)) + { + // 如果文件夹不存在,则创建它 + Directory.CreateDirectory(folderPath); + } } } break; @@ -1573,13 +1751,17 @@ namespace BatCharging.Service if (CMD1503 != null) { + //要加防止重复(未加) + //要判断是否接收成功 + //(CMD=9)后台服务器应答桩上传命令请求(预留) - CmnChargerParam._CHR00TCPCLIENT.Send1504(); + CmnChargerParam._CHR00TCPCLIENT.Send1504(0, (uint)CMD1503.value04); + Log.LogInstance.WriteLog(CMD1503.value05, LogType.Information, PublicProgram.failName01); } } break; - case 1505: + case 1505://接收完成,要保存关闭 { CMD1505 CMD1505 = new MsgReceiveCMDCom().ConCMD1505(data); string result = "(CMD=10)充电桩上传命令请求(预留) - 接收字节内容:" + ByteUtils.BytesToHexStr(data) + ";"; @@ -1589,22 +1771,7 @@ namespace BatCharging.Service if (CMD1505 != null) { //(CMD=9)后台服务器应答桩上传命令请求(预留) - //CmnChargerParam._CHR00TCPCLIENT.Send9(); - - } - } - break; - case 1506: - { - CMD1506 CMD1506 = new MsgReceiveCMDCom().ConCMD1506(data); - string result = "(CMD=10)充电桩上传命令请求(预留) - 接收字节内容:" + ByteUtils.BytesToHexStr(data) + ";"; - result += "\r\n" + "(CMD=10)充电桩上传命令请求(预留)对象:" + JsonConvert.SerializeObject(CMD1506); - Log.LogInstance.WriteLog(result, LogType.Information, "Charger" + "充电机编码"); - - if (CMD1506 != null) - { - //(CMD=9)后台服务器应答桩上传命令请求(预留) - //CmnChargerParam._CHR00TCPCLIENT.Send9(); + CmnChargerParam._CHR00TCPCLIENT.Send1506(); } } @@ -3053,35 +3220,48 @@ namespace BatCharging.Service #endregion 数据发送 #region 协议格式 + /// + /// (CMD=1)后台服务器下发充电桩整形工作参数 + /// + /// 类型 0-查询/1-设置 + /// 设置/查询参数起始地址 + /// 设置/查询个数 + /// 设置数据 - public void Send1() + public void Send1(byte type,uint startAddress,byte num,byte[] setData) { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send1(_chr_client); + new ChargerSendMsgUtils().Send1(_chr_client,type,startAddress,num, setData); } } } - public void Send3() + /// + /// 后台服务器下发充电桩字符型参数 + /// + /// 类型 0-查询 1-设置 + /// 设置/查询参数起始地址 + /// 设置数据 + public void Send3(byte type, uint startAddress, byte[] setData) { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send3(_chr_client); + new ChargerSendMsgUtils().Send3(_chr_client,type,startAddress,setData); } } } - public void Send5() + public void Send5(byte type, uint startAddress, byte num, byte[] setData) { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send5(_chr_client); + new ChargerSendMsgUtils().Send5(_chr_client,type, startAddress, num, setData); } } } @@ -3255,7 +3435,7 @@ namespace BatCharging.Service } } } - + public void Send303() { if (_chr_client != null) @@ -3377,24 +3557,24 @@ namespace BatCharging.Service } } - public void Send1103() + public void Send1103(CMD1103 CMD) { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send1103(_chr_client); + new ChargerSendMsgUtils().Send1103(_chr_client, CMD); } } } - public void Send1105() + public void Send1105(CMD1105 CMD) { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send1105(_chr_client); + new ChargerSendMsgUtils().Send1105(_chr_client, CMD); } } } @@ -3414,13 +3594,13 @@ namespace BatCharging.Service #region 白名单报文 - public void Send1301() + public void Send1301(CMD1301 CMD) { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send1301(_chr_client); + new ChargerSendMsgUtils().Send1301(_chr_client, CMD); } } } @@ -3429,24 +3609,24 @@ namespace BatCharging.Service #region FTP 远程升级和 FTP 方式日志上传 - public void Send1401() + public void Send1401(CMD1401 CMD) { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send1401(_chr_client); + new ChargerSendMsgUtils().Send1401(_chr_client, CMD); } } } - public void Send1406() + public void Send1406(CMD1406 CMD) { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send1406(_chr_client); + new ChargerSendMsgUtils().Send1406(_chr_client, CMD); } } } @@ -3455,24 +3635,35 @@ namespace BatCharging.Service #region 协议方式日志上传 - public void Send1502() + public void Send1502(ushort responseCode) + { + if (_chr_client != null) + { + if (_chr_client.Connected) + { + new ChargerSendMsgUtils().Send1502(_chr_client, responseCode); + } + } + } + + public void Send1504(uint logo, uint successReservedMessageNum) { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send1502(_chr_client); + new ChargerSendMsgUtils().Send1504(_chr_client, logo, successReservedMessageNum); } } } - public void Send1504() + public void Send1506() { if (_chr_client != null) { if (_chr_client.Connected) { - new ChargerSendMsgUtils().Send1504(_chr_client); + new ChargerSendMsgUtils().Send1506(_chr_client); } } } diff --git a/BatCharging.Service/ChargerSendMsg.cs b/BatCharging.Service/ChargerSendMsg.cs index 37eea26..f04cb6b 100644 --- a/BatCharging.Service/ChargerSendMsg.cs +++ b/BatCharging.Service/ChargerSendMsg.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using System.Xml.Linq; using BatCharging.Model; using BatCharging.Service.Encoder.New; +using CommonClass; using Module.Socket.Tool; using Monitor.LogService; using Newtonsoft.Json; @@ -19,6 +20,8 @@ namespace BatCharging.Service /// internal class ChargerSendMsgUtils { + + PubCommonClass pubCommonClass = new PubCommonClass(); #region #region 充放电启动指令 @@ -285,15 +288,31 @@ namespace BatCharging.Service /// (CMD=1)后台服务器下发充电桩整形工作参数 /// /// - /// - /// - internal void Send1(TcpClientChargerTool tcp_client) + /// + /// + /// + /// + internal void Send1(TcpClientChargerTool tcp_client, byte type, uint startAddress, byte num, byte[] setData) { - byte[] bytes = new ChargerSendCMD().SendRCMD1(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + CMD1 CMD1 = new CMD1(); + CMD1.value1 = 0; + CMD1.value2 = 0; + CMD1.value3 = type; + CMD1.value4 = startAddress; + CMD1.value5 = num; + CMD1.value6 = (ushort)(num * 4); + CMD1.value7 = setData; + + byte[] bytes = new ChargerSendCMD().SendRCMD1(out APDUModel, CMD1); + + if (APDUModel != null) + { + string result = "后台服务器下发充电桩整形工作参数-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } /// @@ -302,172 +321,282 @@ namespace BatCharging.Service /// /// /// - internal void Send3(TcpClientChargerTool tcp_client) + internal void Send3(TcpClientChargerTool tcp_client, byte type, uint startAddress, byte[] setData) { - byte[] bytes = new ChargerSendCMD().SendRCMD3(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + + CMD3 CMD3 = new CMD3(); + CMD3.value1 = 0; + CMD3.value2 = 0; + CMD3.value3 = type; + CMD3.value4 = startAddress; + CMD3.value5 = pubCommonClass.cmd3StartAddress[startAddress]; + CMD3.value6 = setData; + + byte[] bytes = new ChargerSendCMD().SendRCMD3(out APDUModel, CMD3); + + if (APDUModel != null) + { + string result = "后台服务器下发充电桩字符型参数-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } /// - /// (CMD=5) + /// 后台服务器下发充电桩控制命令 /// /// - /// - /// - internal void Send5(TcpClientChargerTool tcp_client) + /// 充电枪口 + /// 启始命令地址 + /// 命令个数 + /// 命令参数 + internal void Send5(TcpClientChargerTool tcp_client, byte chargeMuzzle, uint startAddress, byte num, byte[] setData) { - byte[] bytes = new ChargerSendCMD().SendRCMD5(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + APDUModel APDUModel; + + CMD5 CMD = new CMD5(); + CMD.value3 = chargeMuzzle; + CMD.value4 = startAddress; + CMD.value5 = num; + CMD.value6 = (ushort)(num * 4); + CMD.value7 = setData; + + + byte[] bytes = new ChargerSendCMD().SendRCMD5(out APDUModel, CMD); + + if (APDUModel != null) + { + string result = "后台服务器下发充电桩控制命令-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } + /// - /// (CMD=5) + /// 后台服务器下发充电桩开启充电控制命令 /// /// - /// - /// - internal void Send7(TcpClientChargerTool tcp_client) + /// + internal void Send7(TcpClientChargerTool tcp_client, CMD7 CMD) { - byte[] bytes = new ChargerSendCMD().SendRCMD7(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + byte[] bytes = new ChargerSendCMD().SendRCMD7(out APDUModel, CMD); + if (APDUModel != null) + { + + string result = "后台服务器下发充电桩开启充电控制命令-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } /// - /// (CMD=5) + /// 后台服务器应答桩上传命令请求(预留) /// /// - /// - /// - internal void Send9(TcpClientChargerTool tcp_client) + /// 充电枪号 + /// 执行结果 + /// 命令地址 + /// 数据 + internal void Send9(TcpClientChargerTool tcp_client, byte chargeMuzzle, uint executeResult, uint address, byte[] setData) { - byte[] bytes = new ChargerSendCMD().SendRCMD9(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + CMD9 CMD = new CMD9(); + + CMD.value03 = chargeMuzzle; + CMD.value04 = executeResult; + CMD.value05 = address; + CMD.value06 = 4; + CMD.value07 = null; + + byte[] bytes = new ChargerSendCMD().SendRCMD9(out APDUModel, CMD); + + if (APDUModel != null) + { + string result = "后台服务器应答桩上传命令请求(预留)-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } #endregion #region 充电桩主动上传数据 - /// - /// (CMD=5) + /// 服务器应答心跳包信息 /// /// - /// - /// - internal void Send101(TcpClientChargerTool tcp_client) + /// 心跳应答 + internal void Send101(TcpClientChargerTool tcp_client, ushort heartbeatNum) { - byte[] bytes = new ChargerSendCMD().SendRCMD101(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + CMD101 CMD = new CMD101(); + + CMD.value03 = heartbeatNum; + + byte[] bytes = new ChargerSendCMD().SendRCMD101(out APDUModel, CMD); + if (APDUModel != null) + { + + string result = "服务器应答心跳包信息-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } /// - /// (CMD=5) + /// 服务器应答充电桩状态信息包 /// /// - /// - /// - internal void Send103(TcpClientChargerTool tcp_client) + /// 充电口号 + /// 是否立即上报一次104报文 0-否 、1-是 + internal void Send103(TcpClientChargerTool tcp_client, byte chargeNum, bool reportMessage) { - byte[] bytes = new ChargerSendCMD().SendRCMD103(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + + CMD103 CMD = new CMD103(); + CMD.value03 = chargeNum; + CMD.value04 = reportMessage; + + + byte[] bytes = new ChargerSendCMD().SendRCMD103(out APDUModel, CMD); + if (APDUModel != null) + { + string result = "服务器应答充电桩状态信息包-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } /// - /// (CMD=5) + /// 服务器应答充电桩签到命令 /// /// - /// - /// - internal void Send105(TcpClientChargerTool tcp_client) + /// + internal void Send105(TcpClientChargerTool tcp_client, CMD105 CMD) { - byte[] bytes = new ChargerSendCMD().SendRCMD105(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + byte[] bytes = new ChargerSendCMD().SendRCMD105(out APDUModel, CMD); + if (APDUModel != null) + { + string result = "服务器应答充电桩签到命令-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } /// - /// (CMD=5) + /// 服务器应答充电桩告警信息 /// /// - /// - /// internal void Send107(TcpClientChargerTool tcp_client) { - byte[] bytes = new ChargerSendCMD().SendRCMD107(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + CMD107 CMD = new CMD107(); + + byte[] bytes = new ChargerSendCMD().SendRCMD107(out APDUModel, CMD); + if (APDUModel != null) + { + string result = "服务器应答充电桩告警信息-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } /// - /// (CMD=5) + /// 服务器应答充电桩告警信息 /// /// - /// - /// internal void Send109(TcpClientChargerTool tcp_client) { - byte[] bytes = new ChargerSendCMD().SendRCMD109(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + + + CMD109 CMD = new CMD109(); + + + byte[] bytes = new ChargerSendCMD().SendRCMD109(out APDUModel, CMD); + if (APDUModel != null) + { + string result = "服务器应答充电桩告警信息-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } /// - /// (CMD=5) + /// 服务器应答充电桩上报模块信息(预留) /// /// - /// - /// - internal void Send111(TcpClientChargerTool tcp_client) + /// 报文类型 + internal void Send111(TcpClientChargerTool tcp_client, byte messageType) { - byte[] bytes = new ChargerSendCMD().SendRCMD111(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + + CMD111 CMD = new CMD111(); + + CMD.value03 = messageType; + + + byte[] bytes = new ChargerSendCMD().SendRCMD111(out APDUModel, CMD); + if (APDUModel != null) + { + string result = "服务器应答充电桩上报模块信息(预留)-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } /// - /// (CMD=5) + /// 服务器查询最近一次充电各时段信息 /// /// - /// - /// - internal void Send113(TcpClientChargerTool tcp_client) + /// 充电口号 + /// 标志 + internal void Send113(TcpClientChargerTool tcp_client, byte chargeNum, byte sign) { - byte[] bytes = new ChargerSendCMD().SendRCMD113(out APDUModel APDUModel); - string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + APDUModel APDUModel; - Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); - tcp_client.Write(bytes); + CMD113 CMD = new CMD113(); + + CMD.value03 = chargeNum; + CMD.value04 = sign; + + + byte[] bytes = new ChargerSendCMD().SendRCMD113(out APDUModel, CMD); + if (APDUModel != null) + { + string result = "服务器查询最近一次充电各时段信息-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } } #endregion @@ -728,9 +857,9 @@ namespace BatCharging.Service /// /// /// - internal void Send1103(TcpClientChargerTool tcp_client) + internal void Send1103(TcpClientChargerTool tcp_client, CMD1103 CMD) { - byte[] bytes = new ChargerSendCMD().SendRCMD1103(out APDUModel APDUModel); + byte[] bytes = new ChargerSendCMD().SendRCMD1103(out APDUModel APDUModel, CMD); string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); @@ -742,9 +871,9 @@ namespace BatCharging.Service /// /// /// - internal void Send1105(TcpClientChargerTool tcp_client) + internal void Send1105(TcpClientChargerTool tcp_client, CMD1105 CMD) { - byte[] bytes = new ChargerSendCMD().SendRCMD1105(out APDUModel APDUModel); + byte[] bytes = new ChargerSendCMD().SendRCMD1105(out APDUModel APDUModel,CMD); string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); @@ -774,9 +903,9 @@ namespace BatCharging.Service /// /// /// - internal void Send1301(TcpClientChargerTool tcp_client) + internal void Send1301(TcpClientChargerTool tcp_client, CMD1301 CMD) { - byte[] bytes = new ChargerSendCMD().SendRCMD1301(out APDUModel APDUModel); + byte[] bytes = new ChargerSendCMD().SendRCMD1301(out APDUModel APDUModel, CMD); string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); @@ -790,11 +919,26 @@ namespace BatCharging.Service /// (CMD=5) /// /// - /// - /// - internal void Send1401(TcpClientChargerTool tcp_client) + /// + /// + /// + /// + /// + /// + /// + internal void Send1401(TcpClientChargerTool tcp_client, CMD1401 CMD) { - byte[] bytes = new ChargerSendCMD().SendRCMD1401(out APDUModel APDUModel); + //CMD1401 CMD = new CMD1401(); + //CMD.reserved1 = 0; + //CMD.reserved2 = 0; + //CMD.UpgradeSoftwareFileVersionNum = UpgradeSoftwareFileVersionNum; + //CMD.ftpServerIPaddress = ftpServerIPaddress; + //CMD.ftpUserName = ftpUserName; + //CMD.ftpPassWord = ftpPassWord; + //CMD.ftpDownloadPath = ftpDownloadPath; + //CMD.executeWay = executeWay; + //CMD.nowUpgradeDeviceType = nowUpgradeDeviceType; + byte[] bytes = new ChargerSendCMD().SendRCMD1401(out APDUModel APDUModel, CMD); string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); @@ -806,9 +950,19 @@ namespace BatCharging.Service /// /// /// - internal void Send1406(TcpClientChargerTool tcp_client) + internal void Send1406(TcpClientChargerTool tcp_client, CMD1406 CMD) { - byte[] bytes = new ChargerSendCMD().SendRCMD1406(out APDUModel APDUModel); + //CMD1406 CMD = new CMD1406(); + //CMD.reserved1 = 0; + //CMD.reserved2 = 0; + //CMD.getLogType = 0; + //CMD.ftpServerIPaddress = null; + //CMD.ftpUserName = null; + //CMD.ftpPassWord = null; + //CMD.ftpSavePath = null; + //CMD.executeWay = 0; + + byte[] bytes = new ChargerSendCMD().SendRCMD1406(out APDUModel APDUModel, CMD); string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); @@ -823,12 +977,12 @@ namespace BatCharging.Service /// /// /// - internal void Send1502(TcpClientChargerTool tcp_client ) + internal void Send1502(TcpClientChargerTool tcp_client,ushort responseCode) { CMD1502 CMD = new CMD1502(); CMD.reserved1 = 0; CMD.reserved2 = 0; - CMD.responseCode = 0; + CMD.responseCode = responseCode; byte[] bytes = new ChargerSendCMD().SendRCMD1502(out APDUModel APDUModel, CMD); string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; @@ -838,12 +992,36 @@ namespace BatCharging.Service /// /// (CMD=5) /// - /// - /// - /// - internal void Send1504(TcpClientChargerTool tcp_client) + /// TCP + /// 标识 + /// 已成功接收的报文编号 + /// 这个要与最后一次收到的 1503 报文中的字段 4 一样。 + internal void Send1504(TcpClientChargerTool tcp_client, uint logo,uint successReservedMessageNum) + { + CMD1504 CMD = new CMD1504(); + CMD.reserved1 = 0; + CMD.reserved2 = 0; + CMD.logo = logo; + CMD.successReservedMessageNum = successReservedMessageNum; + byte[] bytes = new ChargerSendCMD().SendRCMD1504(out APDUModel APDUModel, CMD); + string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; + + Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); + tcp_client.Write(bytes); + } + /// + /// (CMD=5) + /// + /// TCP + /// 标识 + /// 已成功接收的报文编号 + /// 这个要与最后一次收到的 1503 报文中的字段 4 一样。 + internal void Send1506(TcpClientChargerTool tcp_client) { - byte[] bytes = new ChargerSendCMD().SendRCMD1504(out APDUModel APDUModel); + CMD1506 CMD = new CMD1506(); + CMD.value01 = 0; + CMD.value01 = 0; + byte[] bytes = new ChargerSendCMD().SendRCMD1506(out APDUModel APDUModel, CMD); string result = "站控响应充放电机上报模块状态-发送字节内容:" + ByteUtils.BytesToHexStr(bytes) + ";"; Log.LogInstance.WriteLog(result, LogType.Information, "SendLog"); diff --git a/BatCharging.Service/Common/PublicProgram.cs b/BatCharging.Service/Common/PublicProgram.cs index b0d5076..fd6909e 100644 --- a/BatCharging.Service/Common/PublicProgram.cs +++ b/BatCharging.Service/Common/PublicProgram.cs @@ -9,6 +9,11 @@ namespace BatCharging.Service { public static class PublicProgram { + public static string failName01 = null; + public static string failName02 = null; + public static string failName03 = null; + public static string failName04 = null; + public static List APCI(APDUModel baseApci) { List lstResult = null; diff --git a/BatCharging.Service/发送方法/ChargerSendCMD.cs b/BatCharging.Service/发送方法/ChargerSendCMD.cs index b06a83b..94cdd8f 100644 --- a/BatCharging.Service/发送方法/ChargerSendCMD.cs +++ b/BatCharging.Service/发送方法/ChargerSendCMD.cs @@ -10,8 +10,9 @@ namespace BatCharging.Service public class ChargerSendCMD { #region 协议格式 - public byte[] SendRCMD1(out APDUModel APDUModel) + public byte[] SendRCMD1(out APDUModel APDUModel, CMD1 t) { + byte[] result = null; APDUModel model = new APDUModel(); @@ -22,16 +23,8 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD1 CMD1 = new CMD1(); - CMD1.value1 = 0; - CMD1.value2 = 0; - CMD1.value3 = 0; - CMD1.value4 = 0; - CMD1.value5 = 1; - CMD1.value6 = 1; - CMD1.value7 = 1; - - model.dataDomain = GetRCMD1DataInfo(CMD1); //数据域 + + model.dataDomain = GetRCMD1DataInfo(t); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 List lstResult = new List(); @@ -58,21 +51,24 @@ namespace BatCharging.Service lstContent.AddRange(BitConverter.GetBytes(CMD1.value2)); lstContent.Add(CMD1.value3); lstContent.AddRange(BitConverter.GetBytes(CMD1.value4)); - lstContent.Add(CMD1.value5); - lstContent.AddRange(BitConverter.GetBytes(CMD1.value7)); + if (CMD1.value3 == 1) { - CMD1.value4 = 1; - CMD1.value7 = 1; - lstContent.AddRange(BitConverter.GetBytes(CMD1.value4)); - lstContent.AddRange(BitConverter.GetBytes(CMD1.value7)); + lstContent.Add(CMD1.value5); + lstContent.AddRange(BitConverter.GetBytes(CMD1.value6)); + lstContent.AddRange(CMD1.value7); } + else + { + + } + results = lstContent.ToArray(); } return results; } - public byte[] SendRCMD3(out APDUModel APDUModel) + public byte[] SendRCMD3(out APDUModel APDUModel, CMD3 CMD3) { byte[] result = null; @@ -84,14 +80,6 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD3 CMD3 = new CMD3(); - CMD3.value1 = 0; - CMD3.value2 = 0; - CMD3.value3 = 0; - CMD3.value4 = 0; - CMD3.value5 = 1; - CMD3.value6 = 1; - CMD3.value7 = 1; model.dataDomain = GetRCMD3DataInfo(CMD3); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -120,20 +108,21 @@ namespace BatCharging.Service lstContent.AddRange(BitConverter.GetBytes(CMD.value2)); lstContent.Add(CMD.value3); lstContent.AddRange(BitConverter.GetBytes(CMD.value4)); - lstContent.Add(CMD.value5); - lstContent.AddRange(BitConverter.GetBytes(CMD.value7)); + lstContent.AddRange(CMD.value6); if (CMD.value3 == 1) { - CMD.value4 = 1; - CMD.value7 = 1; - lstContent.AddRange(BitConverter.GetBytes(CMD.value4)); - lstContent.AddRange(BitConverter.GetBytes(CMD.value7)); + lstContent.AddRange(BitConverter.GetBytes(CMD.value5)); + lstContent.AddRange(CMD.value6); + } + else + { + } results = lstContent.ToArray(); } return results; } - public byte[] SendRCMD5(out APDUModel APDUModel) + public byte[] SendRCMD5(out APDUModel APDUModel, CMD5 cMD5) { byte[] result = null; @@ -145,16 +134,9 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD5 CMD = new CMD5(); - CMD.value1 = 0; - CMD.value2 = 0; - CMD.value3 = 0; - CMD.value4 = 0; - CMD.value5 = 1; - CMD.value6 = 1; - CMD.value7 = 1; - model.dataDomain = GetRCMD5DataInfo(CMD); //数据域 + + model.dataDomain = GetRCMD5DataInfo(cMD5); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 List lstResult = new List(); @@ -196,7 +178,7 @@ namespace BatCharging.Service } - public byte[] SendRCMD7(out APDUModel APDUModel) + public byte[] SendRCMD7(out APDUModel APDUModel, CMD7 CMD) { byte[] result = null; @@ -208,23 +190,7 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD7 CMD = new CMD7(); - CMD.value01 = 0; - CMD.value02 = 0; - CMD.value03 = 0; - CMD.value04 = 0; - CMD.value05 = 1; - CMD.value06 = 1; - CMD.value07 = 1; - CMD.value08 = 1; - CMD.value09 = 1; - CMD.value10 = 1; - CMD.value11 = 1; - CMD.value12 = 1; - CMD.value13 = null; - CMD.value14 = 1; - CMD.value15 = 1; - CMD.value16 = 1; + model.dataDomain = GetRCMD7DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -270,7 +236,7 @@ namespace BatCharging.Service } - public byte[] SendRCMD9(out APDUModel APDUModel) + public byte[] SendRCMD9(out APDUModel APDUModel,CMD9 CMD) { byte[] result = null; @@ -282,14 +248,7 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD9 CMD = new CMD9(); - CMD.value01 = 0; - CMD.value02 = 0; - CMD.value03 = 0; - CMD.value04 = 0; - CMD.value05 = 1; - CMD.value06 = 1; - CMD.value07 = null; + model.dataDomain = GetRCMD9DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -330,7 +289,7 @@ namespace BatCharging.Service #region 充电桩主动上传数据 - public byte[] SendRCMD101(out APDUModel APDUModel) + public byte[] SendRCMD101(out APDUModel APDUModel, CMD101 CMD) { byte[] result = null; @@ -342,10 +301,7 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD101 CMD = new CMD101(); - CMD.value01 = 0; - CMD.value02 = 0; - CMD.value03 = 0; + model.dataDomain = GetRCMD101DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -380,7 +336,7 @@ namespace BatCharging.Service } - public byte[] SendRCMD103(out APDUModel APDUModel) + public byte[] SendRCMD103(out APDUModel APDUModel, CMD103 CMD) { byte[] result = null; @@ -392,11 +348,6 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD103 CMD = new CMD103(); - CMD.value01 = 0; - CMD.value02 = 0; - CMD.value03 = 0; - CMD.value04 = 0; model.dataDomain = GetRCMD103DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -431,7 +382,7 @@ namespace BatCharging.Service return results; } - public byte[] SendRCMD105(out APDUModel APDUModel) + public byte[] SendRCMD105(out APDUModel APDUModel, CMD105 CMD) { byte[] result = null; @@ -443,20 +394,9 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD105 CMD105 = new CMD105(); - CMD105.value1 = 1; - CMD105.value2 = 1; - CMD105.value3 = 1; - CMD105.value4 = 1; - CMD105.value5 = 0; - CMD105.value6 = null; - CMD105.value7 = 1; - CMD105.value8 = 1; - CMD105.value9 = 1; - CMD105.value10 = 0xDE; - CMD105.value11 = null; - - model.dataDomain = GetRCMD105DataInfo(CMD105); //数据域 + + + model.dataDomain = GetRCMD105DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 List lstResult = new List(); @@ -500,7 +440,7 @@ namespace BatCharging.Service } - public byte[] SendRCMD107(out APDUModel APDUModel) + public byte[] SendRCMD107(out APDUModel APDUModel, CMD107 CMD) { byte[] result = null; @@ -512,10 +452,7 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD107 CMD = new CMD107(); - //CMD.value01 = 0; - //CMD.value02 = 0; - //CMD.value03 = 0; + model.dataDomain = GetRCMD107DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -550,7 +487,7 @@ namespace BatCharging.Service } - public byte[] SendRCMD109(out APDUModel APDUModel) + public byte[] SendRCMD109(out APDUModel APDUModel, CMD109 CMD) { byte[] result = null; @@ -562,9 +499,6 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD109 CMD = new CMD109(); - CMD.value01 = 0; - CMD.value02 = 0; model.dataDomain = GetRCMD109DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -598,7 +532,7 @@ namespace BatCharging.Service } - public byte[] SendRCMD111(out APDUModel APDUModel) + public byte[] SendRCMD111(out APDUModel APDUModel, CMD111 CMD) { byte[] result = null; @@ -610,10 +544,6 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD111 CMD = new CMD111(); - CMD.value01 = 0; - CMD.value02 = 0; - CMD.value03 = 0; model.dataDomain = GetRCMD111DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -647,7 +577,7 @@ namespace BatCharging.Service return results; } - public byte[] SendRCMD113(out APDUModel APDUModel) + public byte[] SendRCMD113(out APDUModel APDUModel, CMD113 CMD) { byte[] result = null; @@ -659,11 +589,7 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD113 CMD = new CMD113(); - CMD.value01 = 0; - CMD.value02 = 0; - CMD.value03 = 0; - CMD.value04 = 0; + model.dataDomain = GetRCMD113DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -1486,7 +1412,7 @@ namespace BatCharging.Service #region 与计费策略相关的指令 - public byte[] SendRCMD1101(out APDUModel APDUModel) + public byte[] SendRCMD1101(out APDUModel APDUModel ) { byte[] result = null; @@ -1529,7 +1455,7 @@ namespace BatCharging.Service } - public byte[] SendRCMD1103(out APDUModel APDUModel) + public byte[] SendRCMD1103(out APDUModel APDUModel, CMD1103 CMD) { byte[] result = null; @@ -1541,79 +1467,6 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD1103 CMD = new CMD1103(); - CMD.startHour1 = 0; - CMD.startMinute1 = 0; - CMD.endHour1 = 0; - CMD.endMinute1 = 0; - CMD.rate1 = 0; - - CMD.startHour2 = 0; - CMD.startMinute2 = 0; - CMD.endHour2 = 0; - CMD.endMinute2 = 0; - CMD.rate2 = 0; - - CMD.startHour3 = 0; - CMD.startMinute3 = 0; - CMD.endHour3 = 0; - CMD.endMinute3 = 0; - CMD.rate3 = 0; - - CMD.startHour4 = 0; - CMD.startMinute4 = 0; - CMD.endHour4 = 0; - CMD.endMinute4 = 0; - CMD.rate4 = 0; - - CMD.startHour5 = 0; - CMD.startMinute5 = 0; - CMD.endHour5 = 0; - CMD.endMinute5 = 0; - CMD.rate5 = 0; - - CMD.startHour6 = 0; - CMD.startMinute6 = 0; - CMD.endHour6 = 0; - CMD.endMinute6 = 0; - CMD.rate6 = 0; - - CMD.startHour7 = 0; - CMD.startMinute7 = 0; - CMD.endHour7 = 0; - CMD.endMinute7 = 0; - CMD.rate7 = 0; - - CMD.startHour8 = 0; - CMD.startMinute8 = 0; - CMD.endHour8 = 0; - CMD.endMinute8 = 0; - CMD.rate8 = 0; - - CMD.startHour9 = 0; - CMD.startMinute9 = 0; - CMD.endHour9 = 0; - CMD.endMinute9 = 0; - CMD.rate9 = 0; - - CMD.startHour10 = 0; - CMD.startMinute10 = 0; - CMD.endHour10 = 0; - CMD.endMinute10 = 0; - CMD.rate10 = 0; - - CMD.startHour11 = 0; - CMD.startMinute11 = 0; - CMD.endHour11 = 0; - CMD.endMinute11 = 0; - CMD.rate11 = 0; - - CMD.startHour12 = 0; - CMD.startMinute12 = 0; - CMD.endHour12 = 0; - CMD.endMinute12 = 0; - CMD.rate12 = 0; - model.dataDomain = GetRCMD1103DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -1714,7 +1567,7 @@ namespace BatCharging.Service return results; } - public byte[] SendRCMD1105(out APDUModel APDUModel) + public byte[] SendRCMD1105(out APDUModel APDUModel, CMD1105 CMD) { byte[] result = null; @@ -1726,91 +1579,6 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD1105 CMD = new CMD1105(); - CMD.startHour1 = 0; - CMD.startMinute1 = 0; - CMD.endHour1 = 0; - CMD.endMinute1 = 0; - CMD.rate1 = 0; - CMD.reserveRate1 = 0; - - CMD.startHour2 = 0; - CMD.startMinute2 = 0; - CMD.endHour2 = 0; - CMD.endMinute2 = 0; - CMD.rate2 = 0; - CMD.reserveRate2 = 0; - - CMD.startHour3 = 0; - CMD.startMinute3 = 0; - CMD.endHour3 = 0; - CMD.endMinute3 = 0; - CMD.rate3 = 0; - CMD.reserveRate3 = 0; - - CMD.startHour4 = 0; - CMD.startMinute4 = 0; - CMD.endHour4 = 0; - CMD.endMinute4 = 0; - CMD.rate4 = 0; - CMD.reserveRate4 = 0; - - CMD.startHour5 = 0; - CMD.startMinute5 = 0; - CMD.endHour5 = 0; - CMD.endMinute5 = 0; - CMD.rate5 = 0; - CMD.reserveRate5 = 0; - - CMD.startHour6 = 0; - CMD.startMinute6 = 0; - CMD.endHour6 = 0; - CMD.endMinute6 = 0; - CMD.rate6 = 0; - CMD.reserveRate6 = 0; - - CMD.startHour7 = 0; - CMD.startMinute7 = 0; - CMD.endHour7 = 0; - CMD.endMinute7 = 0; - CMD.rate7 = 0; - CMD.reserveRate7 = 0; - - CMD.startHour8 = 0; - CMD.startMinute8 = 0; - CMD.endHour8 = 0; - CMD.endMinute8 = 0; - CMD.rate8 = 0; - CMD.reserveRate8 = 0; - - CMD.startHour9 = 0; - CMD.startMinute9 = 0; - CMD.endHour9 = 0; - CMD.endMinute9 = 0; - CMD.rate9 = 0; - CMD.reserveRate9 = 0; - - CMD.startHour10 = 0; - CMD.startMinute10 = 0; - CMD.endHour10 = 0; - CMD.endMinute10 = 0; - CMD.rate10 = 0; - CMD.reserveRate10 = 0; - - CMD.startHour11 = 0; - CMD.startMinute11 = 0; - CMD.endHour11 = 0; - CMD.endMinute11 = 0; - CMD.rate11 = 0; - CMD.reserveRate11 = 0; - - CMD.startHour12 = 0; - CMD.startMinute12 = 0; - CMD.endHour12 = 0; - CMD.endMinute12 = 0; - CMD.rate12 = 0; - CMD.reserveRate12 = 0; - model.dataDomain = GetRCMD1105DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -1969,7 +1737,7 @@ namespace BatCharging.Service #region 白名单报文 - public byte[] SendRCMD1301(out APDUModel APDUModel) + public byte[] SendRCMD1301(out APDUModel APDUModel, CMD1301 CMD) { byte[] result = null; @@ -1981,25 +1749,6 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD1301 CMD = new CMD1301(); - CMD.reserved1 = 0; - CMD.reserved2 = 0; - CMD.chargingStationCode = null; - CMD.whitelistType = 0; - CMD.operation = 0; - CMD.whitelistVersionNum = 0; - CMD.DistributeWhitelistNum = 0; - CMD.carVinOrChargCardNum01 = null; - CMD.carVinOrChargCardNum02 = null; - CMD.carVinOrChargCardNum03 = null; - CMD.carVinOrChargCardNum04 = null; - CMD.carVinOrChargCardNum05 = null; - CMD.carVinOrChargCardNum06 = null; - CMD.carVinOrChargCardNum07 = null; - CMD.carVinOrChargCardNum08 = null; - CMD.carVinOrChargCardNum09 = null; - CMD.carVinOrChargCardNum10 = null; - model.dataDomain = GetRCMD1301DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -2048,7 +1797,7 @@ namespace BatCharging.Service #region FTP 远程升级和 FTP 方式日志上传 - public byte[] SendRCMD1401(out APDUModel APDUModel) + public byte[] SendRCMD1401(out APDUModel APDUModel, CMD1401 CMD) { byte[] result = null; @@ -2060,17 +1809,6 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD1401 CMD = new CMD1401(); - CMD.reserved1 = 0; - CMD.reserved2 = 0; - CMD.UpgradeSoftwareFileVersionNum = 0; - CMD.ftpServerIPaddress = null; - CMD.ftpUserName = null; - CMD.ftpPassWord = null; - CMD.ftpDownloadPath = null; - CMD.executeWay = 0; - CMD.nowUpgradeDeviceType = 0; - model.dataDomain = GetRCMD1401DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -2109,7 +1847,7 @@ namespace BatCharging.Service } - public byte[] SendRCMD1406(out APDUModel APDUModel) + public byte[] SendRCMD1406(out APDUModel APDUModel, CMD1406 CMD) { byte[] result = null; @@ -2121,16 +1859,6 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; - CMD1406 CMD = new CMD1406(); - CMD.reserved1 = 0; - CMD.reserved2 = 0; - CMD.getLogType = 0; - CMD.ftpServerIPaddress = null; - CMD.ftpUserName = null; - CMD.ftpPassWord = null; - CMD.ftpSavePath = null; - CMD.executeWay = 0; - model.dataDomain = GetRCMD1406DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -2182,6 +1910,10 @@ namespace BatCharging.Service model.CMD = 1; model.checksumDomain = 0x01; + //CMD1502 CMD = new CMD1502(); + //CMD.reserved1 = 0; + //CMD.reserved2 = 0; + //CMD.responseCode = 0; model.dataDomain = GetRCMD1502DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -2215,22 +1947,23 @@ namespace BatCharging.Service } - public byte[] SendRCMD1504(out APDUModel APDUModel) + public byte[] SendRCMD1504(out APDUModel APDUModel, CMD1504 CMD) { byte[] result = null; APDUModel model = new APDUModel(); model.OriginDomain1 = 0xAA; + model.OriginDomain2 = 0xF5; model.infoDomain = 0x02; model.SerialNumberDomain = 0xff; model.CMD = 1; model.checksumDomain = 0x01; - CMD1504 CMD = new CMD1504(); - CMD.reserved1 = 0; - CMD.reserved2 = 0; - CMD.logo = 0; - CMD.successReservedMessageNum = 0; + //CMD1504 CMD = new CMD1504(); + //CMD.reserved1 = 0; + //CMD.reserved2 = 0; + //CMD.logo = 0; + //CMD.successReservedMessageNum = 0; model.dataDomain = GetRCMD1504DataInfo(CMD); //数据域 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 @@ -2263,6 +1996,55 @@ namespace BatCharging.Service } return results; } + + + public byte[] SendRCMD1506(out APDUModel APDUModel, CMD1506 CMD) + { + byte[] result = null; + + APDUModel model = new APDUModel(); + model.OriginDomain1 = 0xAA; + model.OriginDomain2 = 0xF5; + model.infoDomain = 0x02; + model.SerialNumberDomain = 0xff; + model.CMD = 1; + model.checksumDomain = 0x01; + + //CMD1504 CMD = new CMD1504(); + //CMD.reserved1 = 0; + //CMD.reserved2 = 0; + //CMD.logo = 0; + //CMD.successReservedMessageNum = 0; + + model.dataDomain = GetRCMD1506DataInfo(CMD); //数据域 + model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 + + List lstResult = new List(); + lstResult.AddRange(PublicProgram.APCI(model).ToArray()); + result = lstResult.ToArray(); + + APDUModel = model; + return result; + } + + /// + /// 获取鉴权消息体字节数组 + /// + /// + /// 鉴权消息体字节数组 + private byte[] GetRCMD1506DataInfo(CMD1506 CMD) + { + byte[] results = null; + if (CMD != null) + { + List lstContent = new List(); + lstContent.AddRange(BitConverter.GetBytes(CMD.value01)); + lstContent.AddRange(BitConverter.GetBytes(CMD.value02)); + + results = lstContent.ToArray(); + } + return results; + } #endregion } diff --git a/ChargeInterfaceTest.sln b/ChargeInterfaceTest.sln index 23c77f0..22ee1c7 100644 --- a/ChargeInterfaceTest.sln +++ b/ChargeInterfaceTest.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BatCharging.Service", "BatC EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Module.Socket.Tool", "Module.Socket.Tool\Module.Socket.Tool.csproj", "{5ECD672B-72BD-4A3A-9160-219F17FC9B9C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonClass", "CommonClass\CommonClass.csproj", "{03F698D6-A474-4408-9B92-A0F7977CCCFE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {5ECD672B-72BD-4A3A-9160-219F17FC9B9C}.Debug|Any CPU.Build.0 = Debug|Any CPU {5ECD672B-72BD-4A3A-9160-219F17FC9B9C}.Release|Any CPU.ActiveCfg = Release|Any CPU {5ECD672B-72BD-4A3A-9160-219F17FC9B9C}.Release|Any CPU.Build.0 = Release|Any CPU + {03F698D6-A474-4408-9B92-A0F7977CCCFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03F698D6-A474-4408-9B92-A0F7977CCCFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03F698D6-A474-4408-9B92-A0F7977CCCFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03F698D6-A474-4408-9B92-A0F7977CCCFE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CommonClass/CommonClass.csproj b/CommonClass/CommonClass.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/CommonClass/CommonClass.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/CommonClass/PubCommonClass.cs b/CommonClass/PubCommonClass.cs new file mode 100644 index 0000000..e672e55 --- /dev/null +++ b/CommonClass/PubCommonClass.cs @@ -0,0 +1,40 @@ +namespace CommonClass +{ + /// + /// 公共通用类库参数 + /// + public class PubCommonClass + { + /// + /// + /// + public Dictionary cmd3StartAddress = new Dictionary(); + + + public void SetCmd3StartAddress() + { + cmd3StartAddress.Add(1, 32); + cmd3StartAddress.Add(2, 8); + cmd3StartAddress.Add(3, 8); + cmd3StartAddress.Add(4, 8); + cmd3StartAddress.Add(5, 6); + cmd3StartAddress.Add(6, 16); + cmd3StartAddress.Add(7, 256); + cmd3StartAddress.Add(8, 16); + cmd3StartAddress.Add(9, 16); + cmd3StartAddress.Add(10, 256); + cmd3StartAddress.Add(11, 128); + cmd3StartAddress.Add(12, 12); + cmd3StartAddress.Add(13, 64); + cmd3StartAddress.Add(14, 8); + cmd3StartAddress.Add(15, 256); + cmd3StartAddress.Add(16, 256); + cmd3StartAddress.Add(17, 256); + cmd3StartAddress.Add(18, 256); + cmd3StartAddress.Add(19, 256); + cmd3StartAddress.Add(20, 256); + } + + + } +} \ No newline at end of file