using Autofac; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Redis; using log4net; using Repository.Station; using Service.Init; namespace Service.Cloud.Client; [Scope("SingleInstance")] public class CloudClientMgr { private static readonly ILog Log = LogManager.GetLogger(typeof(CloudClientMgr)); public static CloudClient? CloudClient { get; set; } public static void Init() { CloudClient = AppInfo.Container.Resolve(); CloudClient.MqttVersion = StaticStationInfo.CloudServerMqttVersion; CloudClient.ServerIp = StaticStationInfo.CloudServerIp; CloudClient.ServerPort = StaticStationInfo.CloudServerPort; CloudClient.ClientId = StaticStationInfo.CloudClientId; CloudClient.Username = StaticStationInfo.CloudUsername; CloudClient.Password = StaticStationInfo.CloudPassword; CloudClient.SubTopic = StaticStationInfo.CloudSubTopic; CloudClient.PubTopic = StaticStationInfo.CloudPubTopic; CloudClient.StationNo = StaticStationInfo.StationNo; CloudClient.AutoReConnect = true; CloudClient.InitHandler(); Task.Run(() => CloudClient.Connect()); RedisHelper? redisHelper = AppInfo.Container.Resolve(); BinInfoRepository binInfoRepository = AppInfo.Container.Resolve(); /*redisHelper?.GetSubscriber().Subscribe("UploadTelemetryData", (channel, value) => { try { Log.Info($"receive UploadTelemetryData={value}"); if (value.HasValue) { UploadTelemetryData? data = JsonConvert.DeserializeObject(value.ToString()); if (data != null) { BinInfo? binInfo = binInfoRepository.QueryByClause(it => it.ChargerNo == data.ChargerNo); ChargeDevDataInfo req = new ChargeDevDataInfo() { sn = StaticStationInfo.StationNo, en = data.ChargerNo, sd = "A"+int.Parse(data.ChargerNo), mtp = StaticStationInfo.ChargePower, mcr = 1, hb = binInfo?.Exists??0, el = 0, cno = int.Parse(data.ChargerNo), cs = binInfo.ChargeStatus??0, fs = 0, @as = 0, //fc = data., //st = data., ct = data.ChargingTime, //ssoc = data., csoc = data.CurrentSoc, //ssoe = data., //csoe = data., cvot = data.BmsChargingVoltage, ccur = data.BmsChargingCurrent, nvot = data.BmsNeedVoltage, ncur = data.BmsNeedCurrent, lsv = data.SingleBatteryMinVoltage, hsv = data.SingleBatteryMaxVoltage, lst = data.MinBatteryTemp, hst = data.MaxBatteryTemp, ws = 0xFF, it = 0xFF, ot = 0xFF, bt = DateTime.Now }; CloudClient?.SendChargeDevDataInfo(req); } } } catch (Exception e) { Log.Info("error", e); } });*/ } }