|
|
|
@ -6,6 +6,7 @@ using IoT.Shared.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
@ -99,10 +100,12 @@ namespace IoTNode.DeviceServices.LiChuang
|
|
|
|
|
private CancellationToken _cancellationToken;
|
|
|
|
|
|
|
|
|
|
private string _mac;
|
|
|
|
|
private readonly ILogger<LCDAUE800DService> _logger;
|
|
|
|
|
|
|
|
|
|
public LCDAUE800DService(IServiceProvider applicationServices, IWebHostEnvironment env)
|
|
|
|
|
public LCDAUE800DService(IServiceProvider applicationServices, IWebHostEnvironment env, ILogger<LCDAUE800DService> logger)
|
|
|
|
|
: base(applicationServices, env)
|
|
|
|
|
{
|
|
|
|
|
this._logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task StartAsync(CancellationToken cancellationToken)
|
|
|
|
@ -462,39 +465,45 @@ namespace IoTNode.DeviceServices.LiChuang
|
|
|
|
|
var gateway_id = doc.SelectSingleNode("//gateway_id").InnerText.Trim();
|
|
|
|
|
var time = doc.SelectSingleNode("//time").InnerText.Trim();
|
|
|
|
|
|
|
|
|
|
var meters = doc.SelectNodes("//meter");
|
|
|
|
|
foreach (XmlNode meter in meters)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var deviceNo = meter.SelectSingleNode("//functionex");
|
|
|
|
|
var equipidex = deviceNo.Attributes["equipidex"].Value.Trim();
|
|
|
|
|
var tpex = deviceNo.Attributes["tpex"].Value.Trim();
|
|
|
|
|
var functions = meter.SelectNodes("//function");
|
|
|
|
|
foreach (XmlNode function in functions)
|
|
|
|
|
var meters = doc.SelectNodes("//meter");
|
|
|
|
|
foreach (XmlNode meter in meters)
|
|
|
|
|
{
|
|
|
|
|
var key = function.Attributes["id"].Value.Trim();
|
|
|
|
|
var name = Keys[key];
|
|
|
|
|
var value = function.InnerText.Trim();
|
|
|
|
|
this._env.Debug($"type:{type},time:{time},equipidex:{equipidex},item:{name},value:{value}");
|
|
|
|
|
//add for iotnode start
|
|
|
|
|
if (!string.IsNullOrEmpty(this._mac))
|
|
|
|
|
var deviceNo = meter.SelectSingleNode("//functionex");
|
|
|
|
|
var equipidex = deviceNo.Attributes["equipidex"].Value.Trim();
|
|
|
|
|
var tpex = deviceNo.Attributes["tpex"].Value.Trim();
|
|
|
|
|
var functions = meter.SelectNodes("//function");
|
|
|
|
|
foreach (XmlNode function in functions)
|
|
|
|
|
{
|
|
|
|
|
var timestamp = (type == "report" ? DateTimeOffset.Now : DateTime.ParseExact(time, "yyyyMMddHHmmss", CultureInfo.InvariantCulture)).ToUnixTimeMilliseconds();
|
|
|
|
|
using var scope = _applicationServices.CreateScope();
|
|
|
|
|
var deviceRepo = scope.ServiceProvider.GetService<IRepository<IoTDevice>>();
|
|
|
|
|
var dataRepo = scope.ServiceProvider.GetService<IRepository<IoTData>>();
|
|
|
|
|
var deviceId = this.GetIoTDeviceId(this._mac);
|
|
|
|
|
if (deviceId.HasValue)
|
|
|
|
|
var key = function.Attributes["id"].Value.Trim();
|
|
|
|
|
var name = Keys[key];
|
|
|
|
|
var value = function.InnerText.Trim();
|
|
|
|
|
this._logger.LogDebug($"type:{type},time:{time},equipidex:{equipidex},item:{name},value:{value}");
|
|
|
|
|
//add for iotnode start
|
|
|
|
|
if (!string.IsNullOrEmpty(this._mac))
|
|
|
|
|
{
|
|
|
|
|
var dataKey = GetKey(equipidex);
|
|
|
|
|
var unit = this.GetUnit(name)?.ToString();
|
|
|
|
|
var dataName = $"{dataKey.GetDisplayName():unit}";
|
|
|
|
|
this.UpdateIoTData(deviceId.Value, dataKey, value, name: dataName, unit: unit);
|
|
|
|
|
var timestamp = (type == "report" ? DateTimeOffset.Now : DateTime.ParseExact(time, "yyyyMMddHHmmss", CultureInfo.InvariantCulture)).ToUnixTimeMilliseconds();
|
|
|
|
|
using var scope = _applicationServices.CreateScope();
|
|
|
|
|
var deviceRepo = scope.ServiceProvider.GetService<IRepository<IoTDevice>>();
|
|
|
|
|
var dataRepo = scope.ServiceProvider.GetService<IRepository<IoTData>>();
|
|
|
|
|
var deviceId = this.GetIoTDeviceId(this._mac);
|
|
|
|
|
if (deviceId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var dataKey = GetKey(key);
|
|
|
|
|
var unit = this.GetUnit(name)?.ToString();
|
|
|
|
|
var dataName = $"{dataKey.GetDisplayName():unit}";
|
|
|
|
|
this.UpdateIoTData(deviceId.Value, dataKey, value, name: dataName, unit: unit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//add for iotnode end
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add for iotnode end
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this._logger.LogError(ex, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
//上传数据响应
|
|
|
|
|
var doc2 = new XmlDocument();
|
|
|
|
|
var xml2 = @$"<?xml version=""1.0"" encoding=""UTF-8"" ?><root><common><building_id>{building_id}</building_id><gateway_id>{gateway_id}</gateway_id><type>report_ack</type></common><report_config operation=""report_ack""><report_ack>pass</report_ack></report_config></root>";
|
|
|
|
@ -504,7 +513,7 @@ namespace IoTNode.DeviceServices.LiChuang
|
|
|
|
|
|
|
|
|
|
private DataKeys GetKey(string equipidex)
|
|
|
|
|
{
|
|
|
|
|
var value = $"设备{equipidex}";
|
|
|
|
|
var value = $"Device{equipidex}";
|
|
|
|
|
return Enum.Parse<DataKeys>(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|