|
|
using BatCharging.Model;
|
|
|
|
|
|
namespace BatCharging.Service.Encoder.New
|
|
|
{
|
|
|
public class MsgAuxiliaryPowerControlEncoder
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] GetAuxiliaryPowerControl(byte[] destAddr, byte onAuxiliaryFlag)
|
|
|
{
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
ASDU headASDU = new ASDU();
|
|
|
headASDU.FrameTypeNo = 45; //帧类型号
|
|
|
headASDU.MsgBodyCount = 1; //信息体个数
|
|
|
headASDU.TransReason = 3; //传送原因
|
|
|
headASDU.PublicAddr = 0; //公共地址
|
|
|
headASDU.MsgBodyAddr = new byte[] { 0, 0, 0 }; //信息体地址
|
|
|
|
|
|
AuxiliaryPowerControlData auxiliaryPowerControlData = new AuxiliaryPowerControlData();
|
|
|
auxiliaryPowerControlData.OnAuxiliaryFlag = onAuxiliaryFlag;
|
|
|
headASDU.MsgBodyContents = GetMsgContents(auxiliaryPowerControlData); //信息体
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
|
|
|
private byte[] GetMsgContents(AuxiliaryPowerControlData auxiliaryPowerControlData)
|
|
|
{
|
|
|
byte[] results = null;
|
|
|
if (auxiliaryPowerControlData != null)
|
|
|
{
|
|
|
List<byte> lstContent = new List<byte>();
|
|
|
lstContent.Add(auxiliaryPowerControlData.RecordType);
|
|
|
lstContent.Add((auxiliaryPowerControlData.OnAuxiliaryFlag));
|
|
|
results = lstContent.ToArray();
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
class AuxiliaryPowerControlData
|
|
|
{
|
|
|
public byte RecordType { get; set; } = 9;
|
|
|
|
|
|
//打开辅助电源标志 1:电池包辅助电源导通 0:电池包辅助电源断开
|
|
|
public byte OnAuxiliaryFlag { get; set; }
|
|
|
}
|
|
|
}
|
|
|
} |