充电机遥测数据上报

zw
smartwyy 6 months ago
parent 16a5a7a84d
commit b87337b8d9

@ -89,6 +89,19 @@ public class RedisHelper : IDisposable
return db.StringGet(key); return db.StringGet(key);
} }
/// <summary>
/// 先进先出队列
/// </summary>
/// <param name="topic"></param>
/// <param name="value"></param>
/// <returns></returns>
public void PublishAsync(string topic, string value)
{
ISubscriber sub = GetConnect().GetSubscriber();
sub.PublishAsync(topic, value);
}
/// <summary> /// <summary>
/// 获取Redis中的值异步版本 /// 获取Redis中的值异步版本
/// </summary> /// </summary>
@ -107,7 +120,7 @@ public class RedisHelper : IDisposable
/// <param name="value">值</param> /// <param name="value">值</param>
/// <param name="expiry">值</param> /// <param name="expiry">值</param>
/// <returns>操作是否成功</returns> /// <returns>操作是否成功</returns>
public bool SetKeyValueStr(string key, string value, TimeSpan? expiry = default(TimeSpan?)) public bool SetKeyValueStr(string key, string value, TimeSpan? expiry = default(TimeSpan?))
{ {
var db = GetConnect().GetDatabase(_defaultDB); var db = GetConnect().GetDatabase(_defaultDB);
return db.StringSet(key, value, expiry); return db.StringSet(key, value, expiry);
@ -124,6 +137,7 @@ public class RedisHelper : IDisposable
var db = GetConnect().GetDatabase(_defaultDB); var db = GetConnect().GetDatabase(_defaultDB);
return await db.StringSetAsync(key, value); return await db.StringSetAsync(key, value);
} }
public bool Remove(string key) public bool Remove(string key)
{ {
var db = GetConnect().GetDatabase(_defaultDB); var db = GetConnect().GetDatabase(_defaultDB);

@ -1,14 +1,10 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Redis;
using log4net; using log4net;
using Newtonsoft.Json;
using Service.Charger.Client; using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Charger.Req;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Service.Charger.Handler namespace Service.Charger.Handler
{ {
@ -21,13 +17,17 @@ namespace Service.Charger.Handler
public class UploadTelemetryDataHandler : SimpleChannelInboundHandler<UploadTelemetryData>, IBaseHandler public class UploadTelemetryDataHandler : SimpleChannelInboundHandler<UploadTelemetryData>, IBaseHandler
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(UploadTelemetryDataHandler)); private static readonly ILog Log = LogManager.GetLogger(typeof(UploadTelemetryDataHandler));
public RedisHelper RedisHelper { get; set; }
protected override void ChannelRead0(IChannelHandlerContext ctx, UploadTelemetryData msg) protected override void ChannelRead0(IChannelHandlerContext ctx, UploadTelemetryData msg)
{ {
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{ {
//存储日志 msg.ChargerNo = sn;
Log.Info($"receive {msg} from {sn}"); Log.Info($"receive {msg} from {sn}");
RedisHelper.PublishAsync("UploadTelemetryData", JsonConvert.SerializeObject(msg));
client.UploadTelemetryData = msg; client.UploadTelemetryData = msg;
//充电机实时充电功率 //充电机实时充电功率
client.RealTimeChargePower = msg.HighVoltageAcquisitionCurrent * msg.HighVoltageAcquisitionVoltage; client.RealTimeChargePower = msg.HighVoltageAcquisitionCurrent * msg.HighVoltageAcquisitionVoltage;

@ -193,6 +193,11 @@ namespace Service.Charger.Msg.Charger.Req
/// </summary> /// </summary>
[Property(392 + 8, 32, PropertyReadConstant.Bit, 0.01, 2)] [Property(392 + 8, 32, PropertyReadConstant.Bit, 0.01, 2)]
public float ACMeterCurrentBatteryValue { get; set; } public float ACMeterCurrentBatteryValue { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public string ChargerNo { get; set; }
} }
} }

@ -1,8 +1,11 @@
using System.Text; using System.Text;
using Autofac; using Autofac;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Redis;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Service.Charger.Client; using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.System; using Service.System;
namespace WebStarter.Controllers.Test; namespace WebStarter.Controllers.Test;
@ -31,12 +34,9 @@ public class WeatherForecastController : ControllerBase
{ {
_logger.LogInformation("this is a hello world"); _logger.LogInformation("this is a hello world");
RedisHelper redisHelper = AppInfo.Container.Resolve<RedisHelper>();
redisHelper.PublishAsync("UploadTelemetryData", JsonConvert.SerializeObject(new UploadTelemetryData()));
ChargerClient client = AppInfo.Container.Resolve<ChargerClient>();
client.InitBootstrap("127.0.0.1", 9998);
client.BaseConnect();
client.SessionAttr("1", "3");
client.Channel.WriteAndFlushAsync(Encoding.ASCII.GetBytes("ddddddddddd"));
_logger.LogInformation("this is two hello world"); _logger.LogInformation("this is two hello world");
return Enumerable.Range(1, 5).Select(index => new WeatherForecast return Enumerable.Range(1, 5).Select(index => new WeatherForecast

Loading…
Cancel
Save