站外充电机测试

master
CZ 4 months ago
parent 6481d37b8e
commit 4ac43d97f5

@ -21,11 +21,19 @@ public static class HttpUtil
string jsonStr = JsonConvert.SerializeObject(data);
var content = new StringContent(jsonStr, Encoding.UTF8, "application/json");
HttpResponseMessage response = await httpClient.PostAsync(url, content);
try
{
HttpResponseMessage response = await httpClient.PostAsync(url, content);
if (response.IsSuccessStatusCode)
if (response.IsSuccessStatusCode)
{
await response.Content.ReadAsStringAsync();
}
}
catch (Exception e)
{
await response.Content.ReadAsStringAsync();
}
}
}

@ -11,19 +11,28 @@ public class ChargeOrderRepository : BaseRepository<ChargeOrder>
{
}
/// <summary>
/// 创建充电订单
/// </summary>
/// <param name="chargeOrder">订单编号</param>
/// <param name="chargeOrderNo">云平台订单编号</param>
/// <param name="chargerNo">充电机编号</param>
/// <param name="chargerGunNo">充电枪编号</param>
/// <param name="outChargerGunNo">站外充电枪编号站外1枪或2枪</param>
public void SaveChargeGunOrder(string chargeOrder,string chargeOrderNo, string chargerNo, string chargerGunNo,
string outChargerGunNo)
{
ChargeOrder order = new ChargeOrder();
order.Sn = chargeOrder;
order.CmdStatus = 0;
order.ChargerNo = chargerNo;
order.ChargerNo = chargerNo.Substring(4);
order.ChargerGunNo = chargerGunNo;
order.OutChargerGunNo = outChargerGunNo;
order.ChargeMode = 1;
order.StartMode = 1;
order.CloudChargeOrder = chargeOrderNo;
order.CreatedTime = DateTime.Now;
Insert(order);
}

@ -176,18 +176,6 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
{
[1]=new ChargerPile(),
[2]=new ChargerPile(),
[3]=new ChargerPile(),
[4]=new ChargerPile(),
[5]=new ChargerPile(),
[6]=new ChargerPile(),
[7]=new ChargerPile(),
[8]=new ChargerPile(),
[9]=new ChargerPile(),
[10]=new ChargerPile(),
[11]=new ChargerPile(),
[12]=new ChargerPile(),
[13]=new ChargerPile(),
[14]=new ChargerPile(),
};
/// <summary>
@ -596,11 +584,11 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// <param name="pn"></param>
/// <param name="stopReason"></param>
/// <returns></returns>
public Result<string> SendStopOutCharger(byte pn, byte stopReason)
public Result<bool> SendStopOutCharger(byte pn, byte stopReason)
{
if (!Connected)
{
return Result<string>.Fail($"充电机{BinNo}未连接");
return Result<bool>.Fail($"充电机{BinNo}未连接");
}
Log().Info(
@ -608,7 +596,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
PileStopCharge pileStopCharge = new PileStopCharge(pn, stopReason);
this.Channel.WriteAndFlushAsync(pileStopCharge);
return Result<string>.Success();
return Result<bool>.Success();
}
/// <summary>

@ -244,7 +244,7 @@ public class Decoder : ByteToMessageDecoder
51 => recordType switch
{
2 => ModelConvert.Decode<PileStartChargeRes>(bytes),
4 => ModelConvert.Decode<PileStopChargeRes>(bytes),
3 => ModelConvert.Decode<PileStopChargeRes>(bytes),
5 => ModelConvert.Decode<PileStartChargeCompleteReq>(bytes),
7 => ModelConvert.Decode<PileChargeCompleteReq>(bytes),
12 => ModelConvert.Decode<PileUploadTelemetry>(bytes),

@ -29,8 +29,9 @@ public class PileStartChargeResHandler : SimpleChannelInboundHandler<PileStartCh
{
Log.Info($"receive {msg} from {sn}");
string chargeNo = sn.Substring(4);
ChargeOrder? chargeOrder = ChargeOrderRepository.GetLatestChargeGunOrder(msg.Pn.ToString(), sn);
ChargeOrder? chargeOrder = ChargeOrderRepository.GetLatestChargeGunOrder(msg.Pn.ToString(), chargeNo);
if (chargeOrder == null)
{
return;
@ -50,8 +51,16 @@ public class PileStartChargeResHandler : SimpleChannelInboundHandler<PileStartCh
chargeRes.rs = "1";
chargeRes.ec = "0";
try
{
}
catch (Exception e)
{
HttpUtil.SendPostRequest(chargeRes, "http://127.0.0.1:5034/api/OutCharger/ResStartOutCharger");
}
// 9.2.1.2 站控应答开始充电操作
HttpUtil.SendPostRequest(chargeRes, "http://127.0.0.1:5034/api/OutCharger/ResStartOutCharger");
}
else
{

@ -26,7 +26,8 @@ public class PileStopChargeResHandler : SimpleChannelInboundHandler<PileStopChar
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
ChargeOrder? chargeOrder = ChargeOrderRepository.GetLatestChargeGunOrder(msg.pn.ToString(), sn);
string chargeNo = sn.Substring(4);
ChargeOrder? chargeOrder = ChargeOrderRepository.GetLatestChargeGunOrder(msg.pn.ToString(), chargeNo);
if (chargeOrder == null)
{

@ -90,9 +90,7 @@ public class OutChargerController
}
// 下发充电枪停止充电
chargerClient.SendStopOutCharger(chargerGunCode, 0);
return Result<bool>.Success(true);
return chargerClient.SendStopOutCharger(chargerGunCode, 0);
}
/// <summary>

Loading…
Cancel
Save