|
|
|
@ -10,6 +10,7 @@ using Newtonsoft.Json;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using DotNetty.Transport.Channels;
|
|
|
|
|
using HybirdFrameworkServices.Netty;
|
|
|
|
|
using HybirdFrameworkServices.Charger.BatCharging.Service;
|
|
|
|
|
|
|
|
|
|
namespace HybirdFrameworkServices
|
|
|
|
|
{
|
|
|
|
@ -100,6 +101,24 @@ namespace HybirdFrameworkServices
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 线程是否启动
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool _thread_start;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 线程是否启动
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool F_ThreadStart
|
|
|
|
|
{
|
|
|
|
|
get { return _thread_start; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (lockObj)
|
|
|
|
|
{
|
|
|
|
|
_thread_start = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否与充电机已经鉴权
|
|
|
|
@ -573,16 +592,7 @@ namespace HybirdFrameworkServices
|
|
|
|
|
|
|
|
|
|
#region 通讯线程
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 充电机心跳线程和断线线程
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ChargerNetHeartBeatThread()
|
|
|
|
|
{
|
|
|
|
|
Thread chrgConnectedThread = new Thread(ChargerHeartBeatFunc);
|
|
|
|
|
chrgConnectedThread.IsBackground = true;
|
|
|
|
|
chrgConnectedThread.Start();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 充电机判断是否断线线程
|
|
|
|
|
/// 充电机线程启动
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ChargerNetCheckThread()
|
|
|
|
|
{
|
|
|
|
@ -590,30 +600,19 @@ namespace HybirdFrameworkServices
|
|
|
|
|
chargerThread.IsBackground = true;
|
|
|
|
|
chargerThread.Start();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 充电机的心跳方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ChargerHeartBeatFunc()
|
|
|
|
|
{
|
|
|
|
|
while (F_IsAuthed)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
byte[] bytes = Send101(F_Accumulation);
|
|
|
|
|
|
|
|
|
|
if (Server != null)
|
|
|
|
|
{
|
|
|
|
|
Server.Send(bytes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 充电机判断是否断线线程.充电机在连接情况下,30秒未收到信息,则认为断线,需要重新连接
|
|
|
|
|
/// 读取发送到此充电机的报文
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ChargerNetCheckFunc()
|
|
|
|
|
{
|
|
|
|
|
while (F_IsAuthed)
|
|
|
|
|
while (F_ThreadStart)
|
|
|
|
|
{
|
|
|
|
|
//if (F_IsAuthed)//是否鉴权
|
|
|
|
|
// if (F_NetConnected)//是否连接
|
|
|
|
|
if (F_NetConnected)//是否连接
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
|
|
|
@ -622,32 +621,22 @@ namespace HybirdFrameworkServices
|
|
|
|
|
if (seconds >= _net_check_time_out)
|
|
|
|
|
{
|
|
|
|
|
//ChargerDisConnect();
|
|
|
|
|
Server.Disconnect(F_IPAddr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion 通讯线程
|
|
|
|
|
|
|
|
|
|
#region 数据接收
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void decode(string IP, string port, byte[] data)
|
|
|
|
|
public void decode(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
switch (IP)
|
|
|
|
|
{
|
|
|
|
|
case "1":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "2":
|
|
|
|
|
break;
|
|
|
|
|
case "3":
|
|
|
|
|
break;
|
|
|
|
|
case "4":
|
|
|
|
|
break;
|
|
|
|
|
case "5":
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
int func = (ushort)(data[6] + (data[6 + 1] << 8));
|
|
|
|
|
F_RecvingDataTime = DateTime.Now;
|
|
|
|
|
if (func == 106 || F_IsAuthed)
|
|
|
|
|
switch (func)
|
|
|
|
|
{
|
|
|
|
|
#region 设置/查询工作参数和命令
|
|
|
|
@ -712,7 +701,7 @@ namespace HybirdFrameworkServices
|
|
|
|
|
|
|
|
|
|
if (Server != null)
|
|
|
|
|
{
|
|
|
|
|
Server.Send(bytes);
|
|
|
|
|
Send(bytes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@ -726,16 +715,52 @@ namespace HybirdFrameworkServices
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 106:
|
|
|
|
|
//106签到鉴权
|
|
|
|
|
{
|
|
|
|
|
CMD106 CMD106 = ConCMD106(data);
|
|
|
|
|
string result = "(CMD=10)充电桩签到信息上报 - 接收字节内容:" + ByteUtils.BytesToHexStr(data) + ";";
|
|
|
|
|
result += "\r\n" + "(CMD=10)充电桩签到信息上报对象:" + JsonConvert.SerializeObject(CMD106);
|
|
|
|
|
//Log.LogInstance.WriteLog(result, LogType.Information, "Charger" + "充电机编码");
|
|
|
|
|
if (CMD106 != null)
|
|
|
|
|
{
|
|
|
|
|
//回复106签到报文
|
|
|
|
|
{
|
|
|
|
|
F_EqmCode = CMD106.ASCIINum;
|
|
|
|
|
F_Sign = CMD106.Sign == 1 ? true : false;
|
|
|
|
|
F_IsAuthed = true;
|
|
|
|
|
CMD105 CMD = new CMD105();
|
|
|
|
|
CMD.NumResponse = (uint)new Random().Next();
|
|
|
|
|
CMD.LoginVerify = 0;
|
|
|
|
|
CMD.EncryptionFlag = 0;
|
|
|
|
|
CMD.RSAComModule = "";
|
|
|
|
|
CMD.RSAComSecret = 0;
|
|
|
|
|
CMD.RSAComSecret = 0;
|
|
|
|
|
CMD.StSign = 0;
|
|
|
|
|
CMD.BCDTime = (ulong)BcdTimeConverter.ConvertToBcdTime(DateTime.Now);
|
|
|
|
|
CMD.MessageUpload = 0;
|
|
|
|
|
CMD.AESSecretKey = "";
|
|
|
|
|
|
|
|
|
|
byte[] bytes = Send105(CMD);
|
|
|
|
|
|
|
|
|
|
if (Server != null)
|
|
|
|
|
{
|
|
|
|
|
Server.Send(bytes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//CMD3对时报文
|
|
|
|
|
{
|
|
|
|
|
byte type = 1;//0-查询 1-设置
|
|
|
|
|
uint startAddress = 2;//设置/查询参数启始地址
|
|
|
|
|
|
|
|
|
|
byte[] setData = new byte[8];//设置数据
|
|
|
|
|
setData = BcdTimeConverter.ConvertToBcdTimeByte(DateTime.Now);
|
|
|
|
|
byte[] bytes = Send3(type, startAddress, setData);
|
|
|
|
|
|
|
|
|
|
if (Server != null)
|
|
|
|
|
{
|
|
|
|
|
Server.Send(bytes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@ -1019,6 +1044,10 @@ namespace HybirdFrameworkServices
|
|
|
|
|
#endregion 数据接收
|
|
|
|
|
|
|
|
|
|
#region 数据发送
|
|
|
|
|
public void Send(byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
Server.Send(bytes, ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 服务器向充电桩设置/查询工作参数和命令
|
|
|
|
|
/// <summary>
|
|
|
|
|