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.
45 lines
1.4 KiB
45 lines
1.4 KiB
using DotNetty.Buffers;
|
|
using DotNetty.Codecs;
|
|
using DotNetty.Transport.Channels;
|
|
using HybirdFrameworkCore.Utils;
|
|
using HybirdFrameworkDriver.Session;
|
|
using log4net;
|
|
using Newtonsoft.Json;
|
|
using Service.Charger.Common;
|
|
using Service.Charger.Msg;
|
|
|
|
namespace Service.Charger.Codec;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class Encoder : MessageToByteEncoder<APCI>
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(Encoder));
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <param name="obj"></param>
|
|
/// <param name="output"></param>
|
|
protected override void Encode(IChannelHandlerContext context, APCI obj, IByteBuffer output)
|
|
{
|
|
string? s = ChannelUtils.GetAttr(context.Channel, ChargerConst.DestAddr);
|
|
if (s != null)
|
|
{
|
|
byte[] destAddr = s.Split(",").Select(b => Convert.ToByte(b)).ToArray();
|
|
obj.DestAddr = destAddr;
|
|
}
|
|
|
|
byte[] bytes = obj.ToBytes();
|
|
Log.Info($"send {JsonConvert.SerializeObject(obj)}:{BitUtls.BytesToHexStr(bytes)} to {ChannelUtils.GetAttr(context.Channel, ChargerConst.ChargerSn)}");
|
|
//TODO::仅测试使用
|
|
//string ou = string.Empty;
|
|
//for(int i = 0; i < bytes.Length; i++)
|
|
//{
|
|
// ou += bytes[i].ToString("X2") + " ";
|
|
//}
|
|
|
|
output.WriteBytes(bytes);
|
|
}
|
|
} |