You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BatCharging.Model;
namespace BatCharging.Service
{
/// <summary>
///监控平台应答充电启动完成帧- 4.1.7
/// </summary>
internal class MsgStartFsdResEncoder
{
/// <summary>
/// 获取监控平台应答充电启动完成帧字节列表
/// </summary>
/// <param name="resResult">成功标识.0:成功1:失败</param>
/// <param name="failReason">失败原因.0:成功 1:交易流水号数据异常 2:充电方式数据异常 </param>
/// <returns>监控平台应答充电启动完成帧字节列表</returns>
public byte[] GetStartChargingFinishedRes(byte[] destAddr,byte resResult, byte failReason)
{
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 = 45; //帧类型号
headASDU.MsgBodyCount = 1; //信息体个数
headASDU.TransReason = 4; //传送原因
headASDU.PublicAddr = 0; //公共地址
headASDU.MsgBodyAddr = new byte[] { 0, 0, 0 }; //信息体地址
ChargingStartFsdRes startFsdRes = new ChargingStartFsdRes();
startFsdRes.RecordType = 0x02;
startFsdRes.Result = resResult;
startFsdRes.FailReason = failReason;
headASDU.MsgBodyContents = GetMsgContents(startFsdRes); //信息体
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="startFsdRes">启动完成帧应答信息</param>
/// <returns>启动完成帧信息体字节数组</returns>
private byte[] GetMsgContents(ChargingStartFsdRes startFsdRes)
{
byte[] results = null;
if (startFsdRes != null)
{
List<byte> lstContent = new List<byte>();
lstContent.Add(startFsdRes.RecordType);
lstContent.Add(startFsdRes.Result);
lstContent.Add(startFsdRes.FailReason);
results = lstContent.ToArray();
}
return results;
}
}
}