测试发送充电状态

master
zby 1 month ago
parent 8f3bdd6db2
commit beafdab534

@ -343,6 +343,36 @@ public class PlcClient : TcpClient<IBaseHandler, Decoder, Encoder>
}
///// <summary>
///// 发送电池充电状态
///// </summary>
///// <param name="sn">Plc编号</param>
///// <param name="msg">消息</param>
//public Result<bool> SendWhetherChargedResq()
//{
// if (!Connected)
// {
// return Result<bool>.Fail($"Plc{Sn}未连接");
// }
// List<BinInfo> binInfos = _binInfoRepository.Query();
// var configuration = new MapperConfiguration(cfg => cfg.CreateMap<BinInfo, BinInfoResp>());
// var mapper = configuration.CreateMapper();
// List<BinInfoResp> binInfoList = mapper.Map<List<BinInfoResp>>(binInfos);
// byte[] granaries = new byte[8];
// for (int i = 0; i < binInfoList.Count && i < granaries.Length; i++)
// {
// granaries[i] = (binInfoList[i].ChargeStatus == 0 || binInfoList[i].ChargeStatus.Value == 2 || binInfoList[i].ChargeStatus.Value == 4) ? (byte)0 : (byte)1;
// }
// WhetherChargedResq req = new WhetherChargedResq(granaries[0], granaries[1], granaries[2], granaries[3], granaries[4], granaries[5], granaries[6], granaries[7]);
// this.Channel.WriteAndFlushAsync(req);
// return Result<bool>.Success();
//}
///// <summary>
///// 发送参数设置
///// </summary>

@ -1,9 +1,11 @@
using AutoMapper;
using DotNetty.Transport.Channels;
using Entity.Api.Resp;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Repository.Station;
using Service.Charger.Msg.Charger.Req;
namespace Service.Charger.Handler;
@ -14,7 +16,7 @@ namespace Service.Charger.Handler;
[Scope("InstancePerDependency")]
public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<BatteryStatusReportedReq>, IBaseHandler
{
private readonly BinInfoRepository _binInfoRepository;
private static readonly ILog Log =LogManager.GetLogger(typeof(BatteryStatusReportedReqHandler));
public BinInfoRepository BinInfoRepository { get; set; }
@ -25,7 +27,19 @@ public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<Batte
/// </summary>
protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryStatusReportedReq msg)
{
// ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Req.WhetherChargedReq());
List<BinInfo> binInfos = _binInfoRepository.Query();
var configuration = new MapperConfiguration(cfg => cfg.CreateMap<BinInfo, BinInfoResp>());
var mapper = configuration.CreateMapper();
List<BinInfoResp> binInfoList = mapper.Map<List<BinInfoResp>>(binInfos);
byte[] granaries = new byte[8];
for (int i = 0; i < binInfoList.Count && i < granaries.Length; i++)
{
granaries[i] = (binInfoList[i].ChargeStatus == 0 || binInfoList[i].ChargeStatus.Value == 2 || binInfoList[i].ChargeStatus.Value == 4) ? (byte)0 : (byte)1;
}
ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Resp.WhetherChargedResq(granaries[0], granaries[1], granaries[2], granaries[3], granaries[4], granaries[5], granaries[6], granaries[7]));
UpdateBinInfo(msg.granary01, "1");
UpdateBinInfo(msg.granary02, "2");
UpdateBinInfo(msg.granary03, "3");

@ -30,6 +30,7 @@ public class VehicleModelResqHandler : SimpleChannelInboundHandler<VehicleModelR
protected override void ChannelRead0(IChannelHandlerContext ctx, VehicleModelResq msg)
{
Log.Info("Vehicle model Reply");
ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Resp.WarehousCompleteResq());
}
}

@ -5,7 +5,7 @@ using log4net;
using Newtonsoft.Json;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
namespace Service.Charger.Handler;
@ -30,7 +30,7 @@ public class WarehousCompleteReqHandler : SimpleChannelInboundHandler<WarehousCo
protected override void ChannelRead0(IChannelHandlerContext ctx, WarehousCompleteReq msg)
{
Log.Info("Warehousing finish");
ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Resp.WarehousCompleteResq());
}
}

@ -32,5 +32,6 @@ public class WhetherChargedReqHandler : SimpleChannelInboundHandler<WhetherCharg
{
Log.Info("Sends the battery charge status");
}
}

@ -0,0 +1,36 @@
using Autofac;
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Configuration;
using log4net;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Plc.Msg.Host.Req;
using Service.Sound.SoundClient;
namespace Service.Charger.Handler;
/// <summary>
/// 电池包拆卸完成 处理器
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class WhetherChargedResqHandler : SimpleChannelInboundHandler<WhetherChargedResq>, IBaseHandler
{
/// <summary>
///
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(WhetherChargedResqHandler));
/// <summary>
///
/// </summary>
protected override void ChannelRead0(IChannelHandlerContext ctx, WhetherChargedResq msg)
{
Log.Info("Sends the battery charge status");
}
}

@ -0,0 +1,71 @@
using HybirdFrameworkCore.Autofac.Attribute;
using Service.Charger.Msg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Service.Charger.Msg.Host.Resp;
{
public class WhetherChargedResq : ASDU
{
/// <summary>
/// 仓01
/// </summary>
[Property(0, 1)]
public byte granary01 { get; set; }
/// <summary>
/// 仓02
/// </summary>
[Property(1, 1)]
public byte granary02 { get; set; }
/// <summary>
/// 仓03
/// </summary>
[Property(2, 1)]
public byte granary03 { get; set; }
/// <summary>
/// 仓04
/// </summary>
[Property(3, 1)]
public byte granary04 { get; set; }
/// <summary>
/// 仓05
/// </summary>
[Property(4, 1)]
public byte granary05 { get; set; }
/// <summary>
/// 仓06
/// </summary>
[Property(5, 1)]
public byte granary06 { get; set; }
/// <summary>
/// 仓07
/// </summary>
[Property(6, 1)]
public byte granary07 { get; set; }
/// <summary>
/// 仓08
/// </summary>
[Property(7, 1)]
public byte granary08 { get; set; }
public WhetherChargedResq(byte granary01, byte granary02, byte granary03, byte granary04, byte granary05, byte granary06, byte granary07, byte granary08)
{
FrameTypeNo = 122;
MsgBodyCount = 1;
TransReason = 3;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
this.granary01 = granary01;
this.granary02 = granary02;
this.granary03 = granary03;
this.granary04 = granary04;
this.granary05 = granary05;
this.granary06 = granary06;
this.granary07 = granary07;
this.granary08 = granary08;
}
}
}

@ -1,5 +1,7 @@
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkDriver.TcpServer;
using Microsoft.AspNetCore.Mvc;
using Service.Charger.Client;
using Service.Charger.Codec;
using Service.Charger.Handler;
@ -23,6 +25,7 @@ public class PlcServer : TcpServer<IBaseHandler, Decoder,Encoder>
SessionMgr.GetSession(sn)?.Send(msg);
}
/// <summary>
/// 发送出库命令
/// </summary>

@ -53,6 +53,22 @@ public class PlcController : ControllerBase
}
return Result<bool>.Fail("充电机未连接");
}
///// <summary>
///// 发送电池充电状态
///// </summary>
///// <param name="sn">充电机编号</param>
///// <param name="msg">消息</param>
//[HttpGet]
//[Route("SendWhetherChargedReq")]
//public Result<bool> SendWhetherChargedResq()
//{
// Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
// if (chargerClient != null)
// {
// return chargerClient.SendWhetherChargedResq();
// }
// return Result<bool>.Fail("充电机未连接");
//}
///// <summary>

Loading…
Cancel
Save