This commit is contained in:
2021-07-07 16:36:28 +05:00
parent a2fef8a2a4
commit 066c0187f2
30 changed files with 637 additions and 36 deletions

Binary file not shown.

View File

@@ -5,11 +5,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using NLog;
namespace DataClient
{
public static class ByteConverter
{
private static Logger log = LogManager.GetCurrentClassLogger();
public static TechCycle[] BytesToTechcycles(byte[] arr)
{
var res = new List<TechCycle>();
@@ -66,12 +68,51 @@ namespace DataClient
}
catch { throw; }
}
public static (DateTime date, byte[] bytes)[] BytesToTimeLine(byte[] arr, DateTime date)
public static (DateTime date, byte?[] bytes)[] BytesToTimeLine(byte[] arr, DateTime date)
{
var res = new List<(DateTime date, byte[] bytes)>();
var res = new List<(DateTime date, byte?[] bytes)>();
var matrix = new List<byte?>();
var currdate = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
var cursor = 0;
var halfseconds = 0;
try
{
while (cursor < arr.Length)
{
switch (arr[cursor])
{
case 0xfb:
halfseconds = BitConverter.ToInt32(arr, ++cursor);
cursor += 4;
break;
case 0xfc:
for (var i = 0; i < matrix.Count; i++) matrix[i] = null;
res.Add((currdate.AddSeconds(++halfseconds / 2D), matrix.ToArray()));
halfseconds = BitConverter.ToInt32(arr, ++cursor);
cursor += 4;
break;
case 0xfe:
halfseconds += BitConverter.ToInt16(arr, ++cursor);
cursor += 2;
break;
case 0xff:
res.Add((currdate.AddSeconds(halfseconds / 2D), matrix.ToArray()));
cursor++;
halfseconds++;
break;
default:
while (matrix.Count < arr[cursor]) matrix.Add(null);
matrix[arr[cursor]] = arr[cursor + 1];
cursor += 2;
break;
}
}
}
catch(Exception e)
{
log.Warn(e, "Error in structure AD file.");
return res.ToArray();
}
return res.ToArray();
}
}

View File

@@ -1,13 +1,368 @@
[
{
"deleteAll": true,
"delete": [],
"add": [
{
"id": 0,
"name": "Test",
"short_name": "Test",
"measure": "kg",
"precision": 1,
"min": -100,
"max": 100,
"default": 0,
"logarithm": false
"name": "<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>",
"sname": "I <20>",
"measure": "<EFBFBD><EFBFBD>",
"mul": 0.1,
"byteId": [ 0, 1 ]
},
{
"id": 1,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>",
"sname": "U <20>",
"measure": "<22>",
"mul": 0.1,
"byteId": [ 2, 3 ]
},
{
"id": 2,
"name": "<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "I <20><>",
"measure": "<22>",
"mul": 0.1,
"byteId": [4,5]
},
{
"id": 3,
"name": "U <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "U <20><>",
"measure": "<22>",
"mul": 0.1,
"byteId": [6,7]
},
{
"id": 4,
"name": "<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "I <20><><EFBFBD>",
"measure": "<22>",
"mul": 0.1,
"byteId": [8,9]
},
{
"id": 5,
"name": "U <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "U <20><><EFBFBD>",
"measure": "<22>",
"mul": 0.1,
"byteId": [10,11]
},
{
"id": 6,
"name": "<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "I <20><>",
"measure": "<22><>",
"mul": 0.1,
"byteId": [12,13]
},
{
"id": 7,
"name": "t <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>",
"sname": "t <20><>.<2E><><EFBFBD>",
"measure": "<22><>.<2E>",
"byteId": [14,15]
},
{
"id": 8,
"name": "t <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "t <20><>.<2E><>",
"measure": "<22><>.<2E>",
"byteId": [16,17]
},
{
"id": 9,
"name": "t <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "t <20><><EFBFBD>-<2D><><EFBFBD>",
"measure": "<22><>.<2E>",
"byteId": [18,19]
},
{
"id": 10,
"name": "t <20><><EFBFBD><EFBFBD><EFBFBD>",
"sname": "t <20><>",
"measure": "<22><>.<2E>",
"byteId": [20,21]
},
{
"id": 11,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0.1",
"sname": "S <20><>",
"measure": "<22><>",
"mul": 0.1,
"byteId": [22,23]
},
{
"id": 12,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "S <20><>",
"measure": "<22><>",
"byteId": [24,25]
},
{
"id": 13,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"measure": "<22><><EFBFBD>.<2E><>.<2E><>",
"mul": -1,
"byteId": [26,27]
},
{
"id": 14,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "R <20><>-<2D><>",
"measure": "<22>",
"mul": 0.1,
"byteId": [28,29]
},
{
"id": 15,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "R <20><>-<2D><><EFBFBD>",
"measure": "<22>",
"mul": 0.1,
"byteId": [30,31]
},
{
"id": 16,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>",
"sname": "Q <20>.<2E><>",
"measure": "<22>^3/<2F>",
"byteId": [ 32, 33 ]
},
{
"id": 17,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "<22><><EFBFBD>.<2E><><EFBFBD>.",
"mul": 0.01,
"byteId": [34,35]
},
{
"id": 18,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>",
"sname": "<22><><EFBFBD>.<2E><><EFBFBD>.",
"mul": 0.1,
"byteId": [36,37]
},
{
"id": 19,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "Q<>. <20><>.",
"measure": "<22>^3/<2F>",
"mul": 0.01,
"byteId": [38,39]
},
{
"id": 20,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>",
"sname": "Q<>. <20><>.",
"measure": "<22>^3/<2F>",
"mul": 0.01,
"byteId": [40,41]
},
{
"id": 21,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>.+1,5",
"sname": "P <20>.<2E><>",
"measure": "<22><><EFBFBD>/<2F><>^2",
"mul": 0.01,
"byteId": [42,43]
},
{
"id": 22,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "Q<>. <20><><EFBFBD>.",
"measure": "<22>^3/<2F>",
"mul": 0.01,
"byteId": [44,45]
},
{
"id": 23,
"name": "<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD>)",
"sname": "I <20>.<2E><><EFBFBD> <20><><EFBFBD>",
"measure": "<22><>",
"mul": 0.1,
"byteId": [58,59]
},
{
"id": 25,
"name": "<22><><EFBFBD>-<2D><><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "<22><><EFBFBD>-<2D><><EFBFBD>",
"measure": "<22>",
"mul": 0.1,
"byteId": [62,63]
},
{
"id": 26,
"name": "<22><><EFBFBD>-<2D><><EFBFBD>. <20><><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "<22><><EFBFBD>-<2D><><EFBFBD><EFBFBD>",
"measure": "<22>",
"mul": 0.1,
"byteId": [64,65]
},
{
"id": 27,
"name": "t <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "t <20><>.",
"measure": "<22><>.<2E>",
"byteId": [66,67]
},
{
"id": 28,
"name": "t <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "t <20><><EFBFBD>.",
"measure": "<22><>.<2E>",
"byteId": [68,69]
},
{
"id": 29,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "Q<>. <20><><EFBFBD>.",
"measure": "<22>^3/<2F>",
"mul": 0.01,
"byteId": [70,71]
},
{
"id": 30,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "<22><><EFBFBD>. <20><><EFBFBD>.",
"measure": "<22>",
"mul": 0.1,
"byteId": [72,73]
},
{
"id": 31,
"name": "<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.)",
"sname": "I <20>.<2E><><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD>.",
"measure": "<22><>",
"mul": 0.1,
"byteId": [74,75]
},
{
"id": 33,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-1200",
"sname": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-1200",
"measure": "<22><>.<2E><>.<2E><>",
"mul": 0.1,
"byteId": [78,79]
},
{
"id": 34,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-18,75",
"sname": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-18,25",
"measure": "<22><>.<2E><>.<2E><>",
"mul": 0.001,
"byteId": [80,81]
},
{
"id": 35,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "P <20>.<2E><><EFBFBD><EFBFBD>.",
"measure": "<22><><EFBFBD>/<2F><>^2",
"mul": 0.1,
"byteId": [82,83]
},
{
"id": 36,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "P <20>.<2E><><EFBFBD><EFBFBD>.",
"measure": "<22><><EFBFBD>/<2F><>^2",
"byteId": [84,85]
},
{
"id": 37,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (<28><><EFBFBD>)",
"sname": "<22><><EFBFBD>.I, <20><><EFBFBD>",
"measure": "<22><>",
"mul": 0.1,
"byteId": [86,87]
},
{
"id": 38,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "<22><><EFBFBD>.<2E><>.<2E><><EFBFBD>.<2E><>",
"measure": "<22>",
"mul": 0.01,
"byteId": [88,89]
},
{
"id": 39,
"name": "<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ARPW",
"sname": "I <20><>. ARPW",
"measure": "<22>",
"mul": 0.01,
"byteId": [90,91]
},
{
"id": 40,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "<22><>.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>",
"measure": "<22><><EFBFBD>",
"mul": 0.1,
"byteId": []
},
{
"id": 41,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>. <20><> 1 <20><><EFBFBD>.",
"sname": "U <20><>. 1<><31><EFBFBD>, <20>",
"measure": "<22>",
"mul": 0.1,
"byteId": [92,93]
},
{
"id": 42,
"name": "<22><><EFBFBD>: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1",
"sname": "I <20><><EFBFBD>1 <20><><EFBFBD>",
"measure": "<22>",
"byteId": [94,95]
},
{
"id": 43,
"name": "<22><><EFBFBD>: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2",
"sname": "I <20><><EFBFBD>2 <20><><EFBFBD>",
"measure": "<22>",
"byteId": [96,97]
},
{
"id": 44,
"name": "<22><><EFBFBD>: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3",
"sname": "I <20><><EFBFBD>3 <20><><EFBFBD>",
"measure": "<22>",
"byteId": [98,99]
},
{
"id": 45,
"name": "<22><><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"sname": "<22><><EFBFBD><EFBFBD>. <20><><EFBFBD>",
"measure": "<22><>",
"mul": 0.1,
"byteId": [100,101]
},
{
"id": 46,
"name": "<22><><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>p",
"mul": 0.01,
"byteId": [102,103]
},
{
"id": 47,
"name": "<22><><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>i",
"mul": 0.01,
"byteId": [104,105]
},
{
"id": 49,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"byteId": [106,107]
},
{
"id": 50,
"name": "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> U <20><><EFBFBD>",
"measure": "<22>",
"mul": 0.1,
"byteId": [108,109]
}
]
]
}

View File

@@ -0,0 +1,19 @@
{
"deleteAll": true,
"delete": [],
"add": [
{
"id": 0,
"name": "Test",
"sname": "Test",
"measure": "kg",
"mul": 1,
"min": -100,
"max": 100,
"zero": 0,
"logarithm": false,
"byteId": [ 1, 12, 3 ]
}
]
}

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataClient.Struct;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
namespace DataClient
{
public static class Configuration
{
private static Logger log = LogManager.GetCurrentClassLogger();
public static Dictionary<int,ConfAnalog[]> InitAnalogList(string confDir, int[] listVdp)
{
var res = new Dictionary<int, ConfAnalog[]>();
string jsonString;
var confFile = Path.Combine(confDir, "default.json");
try { jsonString = File.ReadAllText(confFile); }
catch (Exception e) { log.Error(e, "Can't read config file from " + confDir + "."); throw; }
var subres = InitAnalogVdp(confDir);
foreach(var vdp in listVdp)
{
if (res.ContainsKey(vdp)) continue;
var tmp = InitAnalogVdp(confDir, vdp, subres);
res.Add(vdp, tmp);
}
return res;
}
public static ConfAnalog[] InitAnalogVdp(string confDir, int vdp = -1, ConfAnalog[] analogs = null)
{
if (analogs == null) analogs = Array.Empty<ConfAnalog>();
var res = new List<ConfAnalog>(analogs);
var searchPattern = vdp == -1 ? "*default.json" : "*" + vdp.ToString() + "*.json";
var files = Directory.GetFiles(confDir, searchPattern);
foreach (var file in files)
{
//check file
if (vdp != -1)
if (!int.TryParse(Path.GetFileNameWithoutExtension(file), out int fVdp) || fVdp != vdp)
continue;
//check JSON
string jsonString;
try { jsonString = File.ReadAllText(file); }
catch (Exception e) { log.Warn(e, "Can't read config file from " + confDir + "."); continue; }
//try json
var conf = (JObject)JsonConvert.DeserializeObject(jsonString);
if (!conf.HasValues) { continue; };
//check deleteAll
if (conf["deleteAll"].Type == JTokenType.Boolean && (bool)conf["deleteAll"])
res.Clear();
//check deleteIdAnalog
if (conf["delete"].Type == JTokenType.Array)
foreach (var idAnalog in conf["delete"])
if (idAnalog.Type == JTokenType.Integer)
res.RemoveAll(x => x.id == (int)idAnalog);
//check add
if (conf["add"].Type == JTokenType.Array)
foreach (var a in conf["add"])
{
var ca = new ConfAnalog();
if (a["id"].Type != JTokenType.Integer || (int)a["id"] < 0) continue;
else ca.id = (int)a["id"];
if (a["name"].Type == JTokenType.String) ca.name = (string)a["name"];
if (a["sname"].Type == JTokenType.String) ca.sname = (string)a["sname"];
else ca.sname = ca.name;
if (a["measure"].Type == JTokenType.String) ca.measure = (string)a["measure"];
if (a["mul"].Type == JTokenType.Integer || a["mul"].Type == JTokenType.Float) ca.mul = (float)a["mul"];
if (a["min"].Type == JTokenType.Integer || a["min"].Type == JTokenType.Float) ca.min = (float)a["min"];
if (a["max"].Type == JTokenType.Integer || a["max"].Type == JTokenType.Float) ca.max = (float)a["max"];
if (a["zero"].Type == JTokenType.Integer || a["zero"].Type == JTokenType.Float) ca.zero = (float)a["zero"];
if (a["logarithm"].Type == JTokenType.Boolean) ca.logarithm = (bool)a["logarithm"];
var bi = new List<int>();
if (a["byteId"].Type == JTokenType.Array)
foreach (var b in a["byteId"])
if (b.Type == JTokenType.Integer)
bi.Add((int)b);
ca.byteId = bi.ToArray();
res.RemoveAll(x => x.id == ca.id);
res.Add(ca);
}
}
return res.ToArray();
}
}
}

View File

@@ -18,6 +18,9 @@
</ItemGroup>
<ItemGroup>
<None Update="Config\analog\default.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Config\config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

View File

@@ -6,6 +6,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using DataClient.Struct;
using System.Net;
using System.Threading.Tasks;
namespace DataClient
{
@@ -16,8 +17,10 @@ namespace DataClient
{
//Переменные
Logger log = LogManager.GetCurrentClassLogger();
string confDir = Path.Combine(Directory.GetCurrentDirectory(), "Config", "config.json");
string confDir = Path.Combine(Directory.GetCurrentDirectory(), "Config");
private List<server> servers = new List<server>();
private Dictionary<int,ConfAnalog[]> confAnalog = new Dictionary<int, ConfAnalog[]>();
private List<(int num, string name)> vdpList = new List<(int num, string name)>();
int serverDefault = -1;
//Геттеры и сеттеры
/// <summary>Номер сервера, используемого по умолчанию.</summary>
@@ -181,9 +184,10 @@ namespace DataClient
private void Config()
{
string jsonString;
var confFile = Path.Combine(confDir, "config.json");
try
{
jsonString = File.ReadAllText(confDir);
jsonString = File.ReadAllText(confFile);
}
catch (Exception e)
{
@@ -212,6 +216,15 @@ namespace DataClient
if (!res)
log.Trace("Can't add or change server #" + count + " from conf file.");
}
//init vdp
for (var i = 0; i < 49; i++)
vdpList.Add(new (i, i == 0 ? "Общие" : "Печь " + i.ToString("D2")));
for (var i = 91; i < 95; i++)
vdpList.Add((i, "Печь " + i.ToString("D2")));
//init analog
var tmpvdp = new List<int>();
foreach (var v in vdpList) tmpvdp.Add(v.num);
confAnalog = Configuration.InitAnalogList(Path.Combine(confDir, "analog"), tmpvdp.ToArray());
}
/// <summary>Создание экземпляра класса.</summary>
public STPClient()
@@ -228,12 +241,42 @@ namespace DataClient
Config();
}
public TechCycle[] GetTechCycle(int vdp, DateTime tS, DateTime tE)
public TechCycle[] GetTechCycles(int vdp, DateTime tS, DateTime tE)
{
//Use File with ID = 3
var res = new List<TechCycle>();
return res.ToArray();
}
public Analog[] GetAnalogs(int vdp, DateTime tS, DateTime tE)
{
var res = new List<Analog>();
var net = new NETClient(servers[serverDefault].ip, servers[serverDefault].port);
if (!net.Connect()) return Array.Empty<Analog>();
var s1 = new List<Task<byte[]>>();
for (var d = new DateTime(tS.Year, tS.Month, tS.Day); d.Year <= tE.Year && d.Month <= tE.Month && d.Day <= tE.Day; d = d.AddDays(1))
{
var t = new Task<byte[]>(() => net.Full_Download(d, vdp, 01));
t.Start();
s1.Add(t);
}
var s2 = new List<Task<Analog[]>>();
while(s1.Count > 0)
{
for(var i = 0; i < s1.Count; i++)
if (s1[i].IsCompleted)
{
var t = new Task<Analog[]>( () => {
if (!s1[i].IsCompletedSuccessfully)
return new Analog[0];
return s1[i].Result
});
}
}
return res.ToArray();
}

View File

@@ -6,23 +6,22 @@ using System.Threading.Tasks;
namespace DataClient.Struct
{
public class ConfAnalog
{
public int id = 0;
public string name = null;
public string sname = null;
public string measure = null;
public double min = double.MinValue;
public double max = double.MaxValue;
public double norm = 0;
public int precision = 0;
public double mul = 1;
public bool log = false;
public int[] byteId = Array.Empty<int>();
}
public class Analog
{
public double? value = null;
public DateTime date = DateTime.Now;
}
public class ConfAnalog
{
public int id = -1;
public string name = null;
public string sname = null;
public string measure = null;
public double min = double.MinValue;
public double max = double.MaxValue;
public double zero = 0;
public double mul = 1;
public bool logarithm = false;
public int[] byteId = Array.Empty<int>();
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataClient
{
static class StructConverter
{
Analog[]
}
}

View File

@@ -0,0 +1,18 @@
{
"deleteAll": true,
"delete": [],
"add": [
{
"id": 0,
"name": "Test",
"short_name": "Test",
"measure": "kg",
"mul": 1,
"min": -100,
"max": 100,
"zero": 0,
"logarithm": false,
"byteId": [ 1, 12, 3 ]
}
]
}

View File

@@ -1 +1 @@
e010c6259d9b17fd3c989d08c8f3519898d03bc0
a35e80ad0f3cac2804cec2e84481a2b816e18b57

View File

@@ -12,3 +12,4 @@ D:\GIT\ASCKU_PC\DataClient\obj\Debug\net5.0\ref\DataClient.dll
D:\GIT\ASCKU_PC\DataClient\obj\Debug\net5.0\DataClient.pdb
D:\GIT\ASCKU_PC\DataClient\bin\Debug\net5.0\DataClient.xml
D:\GIT\ASCKU_PC\DataClient\obj\Debug\net5.0\DataClient.csproj.AssemblyReference.cache
D:\GIT\ASCKU_PC\DataClient\bin\Debug\net5.0\Config\analog\default.json

View File

@@ -22,6 +22,7 @@ namespace Test2
//var t = new Task(() => T1());
//t.Start();
//T1();
var str = new STPClient();
OLD1();
Console.WriteLine("End acc.");
Console.ReadKey();

View File

@@ -0,0 +1,18 @@
{
"deleteAll": true,
"delete": [],
"add": [
{
"id": 0,
"name": "Test",
"short_name": "Test",
"measure": "kg",
"mul": 1,
"min": -100,
"max": 100,
"zero": 0,
"logarithm": false,
"byteId": [ 1, 12, 3 ]
}
]
}

Binary file not shown.

Binary file not shown.

View File

@@ -29,3 +29,4 @@ D:\GIT\ASCKU_PC\Test2\bin\Debug\net5.0\DataClient.dll
D:\GIT\ASCKU_PC\Test2\bin\Debug\net5.0\DataClient.pdb
D:\GIT\ASCKU_PC\Test2\bin\Debug\net5.0\DataClient.xml
D:\GIT\ASCKU_PC\Test2\obj\Debug\net5.0\Test2.csproj.AssemblyReference.cache
D:\GIT\ASCKU_PC\Test2\bin\Debug\net5.0\Config\analog\default.json

Binary file not shown.

Binary file not shown.