站外充电机测试

master
CZ 4 months ago
parent 6481d37b8e
commit 4ac43d97f5

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

@ -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, public void SaveChargeGunOrder(string chargeOrder,string chargeOrderNo, string chargerNo, string chargerGunNo,
string outChargerGunNo) string outChargerGunNo)
{ {
ChargeOrder order = new ChargeOrder(); ChargeOrder order = new ChargeOrder();
order.Sn = chargeOrder; order.Sn = chargeOrder;
order.CmdStatus = 0; order.CmdStatus = 0;
order.ChargerNo = chargerNo; order.ChargerNo = chargerNo.Substring(4);
order.ChargerGunNo = chargerGunNo; order.ChargerGunNo = chargerGunNo;
order.OutChargerGunNo = outChargerGunNo; order.OutChargerGunNo = outChargerGunNo;
order.ChargeMode = 1; order.ChargeMode = 1;
order.StartMode = 1; order.StartMode = 1;
order.CloudChargeOrder = chargeOrderNo; order.CloudChargeOrder = chargeOrderNo;
order.CreatedTime = DateTime.Now; order.CreatedTime = DateTime.Now;
Insert(order); Insert(order);
} }

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

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

@ -29,8 +29,9 @@ public class PileStartChargeResHandler : SimpleChannelInboundHandler<PileStartCh
{ {
Log.Info($"receive {msg} from {sn}"); 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) if (chargeOrder == null)
{ {
return; return;
@ -50,9 +51,17 @@ public class PileStartChargeResHandler : SimpleChannelInboundHandler<PileStartCh
chargeRes.rs = "1"; chargeRes.rs = "1";
chargeRes.ec = "0"; chargeRes.ec = "0";
// 9.2.1.2 站控应答开始充电操作 try
{
}
catch (Exception e)
{
HttpUtil.SendPostRequest(chargeRes, "http://127.0.0.1:5034/api/OutCharger/ResStartOutCharger"); HttpUtil.SendPostRequest(chargeRes, "http://127.0.0.1:5034/api/OutCharger/ResStartOutCharger");
} }
// 9.2.1.2 站控应答开始充电操作
}
else else
{ {
chargeRes.rs = "2"; chargeRes.rs = "2";

@ -26,7 +26,8 @@ public class PileStopChargeResHandler : SimpleChannelInboundHandler<PileStopChar
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{ {
Log.Info($"receive {msg} from {sn}"); 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) if (chargeOrder == null)
{ {

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

Loading…
Cancel
Save