|
|
|
|
|
using BatCharging.Model;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace BatCharging.Service
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 监控平台远程启动充电-4.1.2
|
|
|
/// </summary>
|
|
|
public class MsgStartChrgEncoder
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取远程开始充电消息包字节列表
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public byte[] GetMsgPackRomoteStartCharging(byte[] destAddr, RemoteStartCharging startChrg)
|
|
|
{
|
|
|
byte[] result = null;
|
|
|
|
|
|
APCI headAPCI = new APCI();
|
|
|
headAPCI.StartChar = CmnChargerConst.APCI_START_CHAR;
|
|
|
headAPCI.PackLen = 0; //临时赋值为零,具体数值看下面的计算结果
|
|
|
headAPCI.CtlArea = 0; //控制域
|
|
|
headAPCI.DestAddr = destAddr;//目的地址
|
|
|
headAPCI.SrcAddr = 0;//源地址,本系统中,源地址统一为:00000000(即为0)
|
|
|
|
|
|
byte randomNum = CmnChargerParam.GetByteRandomNum();
|
|
|
|
|
|
ASDU headASDU = new ASDU();
|
|
|
headASDU.FrameTypeNo = 47; //帧类型号
|
|
|
headASDU.MsgBodyCount = 1; //信息体个数
|
|
|
headASDU.TransReason = 3; //传送原因
|
|
|
headASDU.PublicAddr = 0; //公共地址
|
|
|
headASDU.MsgBodyAddr = new byte[] { 0, 0, 0 }; //信息体地址
|
|
|
|
|
|
//初始化远程启动充电参数
|
|
|
|
|
|
headASDU.MsgBodyContents = GetMsgContents(startChrg); //信息体
|
|
|
|
|
|
headAPCI.PackLen = Convert.ToUInt16(24 + headASDU.MsgBodyContents.Length); //报文长度
|
|
|
|
|
|
List<byte> lstResult = MsgHeadApciEncoder.BuildBaseAPCI(headAPCI);
|
|
|
lstResult.AddRange(MsgHeadAsduEncoder.BuildBaseASDU(headASDU).ToArray());
|
|
|
|
|
|
result = lstResult.ToArray();
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取远程开始充电消息体字节数组
|
|
|
/// </summary>
|
|
|
/// <param name="startChrg"></param>
|
|
|
/// <returns>远程开始充电字节数组</returns>
|
|
|
private byte[] GetMsgContents(RemoteStartCharging startChrg)
|
|
|
{
|
|
|
byte[] results = null;
|
|
|
if (startChrg != null)
|
|
|
{
|
|
|
List<byte> lstContent = new List<byte>();
|
|
|
lstContent.Add(startChrg.SocLimit);
|
|
|
lstContent.Add(startChrg.ChangePowerCmdType);
|
|
|
lstContent.AddRange(BitConverter.GetBytes(startChrg.ChangePower));
|
|
|
results = lstContent.ToArray();
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|