laatzen/Common/CommonConsole/Program.cs

148 lines
4.5 KiB
C#
Raw Normal View History

2024-11-27 09:54:01 +00:00
namespace CommonConsole
2024-09-26 13:55:58 +00:00
{
2024-12-06 14:18:49 +00:00
using Common.Hardware.WaterMeter.eRegister;
2024-11-27 09:54:01 +00:00
using Common.Hardware.WaterMeter.eRegister.Features;
2025-01-24 11:10:40 +00:00
using Common.Hardware.WaterMeter.eRegister.Models;
2024-11-27 09:54:01 +00:00
using System;
2025-01-24 11:10:40 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
2024-11-27 09:54:01 +00:00
2025-01-24 11:10:40 +00:00
public static class Program
2023-08-25 13:23:57 +00:00
{
2025-01-24 11:10:40 +00:00
public class FeatureDictionary : SortedDictionary<string, PropertyInfo>
{
public PropertyInfo FeatureInfo { get; set; }
}
2024-09-16 09:11:52 +00:00
public static void Main()
{
2025-01-24 11:10:40 +00:00
var features = new SortedDictionary<bool, SortedDictionary<string, SortedDictionary<string, FeatureDictionary>>>();
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
void ParseType(Type type)
{
2025-01-24 11:10:40 +00:00
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
2025-01-24 11:10:40 +00:00
var propertyType = property.PropertyType;
2025-01-24 11:10:40 +00:00
if (!typeof(Pam).IsAssignableFrom(propertyType))
{
continue;
}
2025-01-24 11:10:40 +00:00
var pamAttribute = property.GetCustomAttribute<PamAttribute>();
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
if (pamAttribute is null)
{
continue;
}
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
var isSingleCmd = pamAttribute.IsSingleCmd;
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
if (!features.ContainsKey(isSingleCmd))
{
features[isSingleCmd] = new SortedDictionary<string, SortedDictionary<string, FeatureDictionary>>();
}
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
var _features = features[isSingleCmd];
var authBytes = pamAttribute.AuthLevel.AuthBytes();
var authLevel = $"{authBytes.LastOrDefault():X2}";
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
if (authBytes.Length > 0)
{
authLevel = $"{authBytes[1]:X2}";
}
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
if (!_features.ContainsKey(authLevel))
2024-12-06 14:18:49 +00:00
{
2025-01-24 11:10:40 +00:00
_features[authLevel] = new SortedDictionary<string, FeatureDictionary>();
}
var __features = _features[authLevel];
var pam = Activator.CreateInstance(property.PropertyType) as Pam;
var cmdHex = pam.CmdHex;
if (cmdHex.Length == 2)
2024-12-17 09:38:42 +00:00
{
2025-01-24 11:10:40 +00:00
cmdHex = $"00-{cmdHex}";
}
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
if (!__features.ContainsKey(cmdHex))
2024-12-17 09:38:42 +00:00
{
2025-01-24 11:10:40 +00:00
__features[cmdHex] = new FeatureDictionary();
}
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
var ___features = __features[cmdHex];
___features.FeatureInfo = property;
2024-12-17 09:38:42 +00:00
2025-01-24 11:10:40 +00:00
foreach (var _property in propertyType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (_property.CanWrite && _property.PropertyType != typeof(byte[]))
{
___features[_property.Name] = _property;
}
}
}
}
2024-12-17 09:38:42 +00:00
2025-01-24 11:10:40 +00:00
ParseType(typeof(EregisterFeatures));
ParseType(typeof(EregisterDebugFeatures));
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
var types = new HashSet<string>();
2024-12-17 09:38:42 +00:00
2025-01-24 11:10:40 +00:00
foreach (var kvp in features)
{
Console.WriteLine(kvp.Key ? "Single PAM:" : "Combined PAM:");
2024-12-17 09:38:42 +00:00
2025-01-24 11:10:40 +00:00
foreach (var _kvp in kvp.Value)
{
Console.WriteLine($" Auth level {_kvp.Key}:");
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
foreach (var __kvp in _kvp.Value)
{
Console.WriteLine($" {__kvp.Key} {__kvp.Value.FeatureInfo.Name}");
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
foreach (var ___kvp in __kvp.Value)
{
Console.WriteLine($"\t\t{___kvp.Key} - {___kvp.Value.PropertyType.Name}");
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
types.Add(___kvp.Value.PropertyType.Name);
}
}
}
}
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
Console.WriteLine();
var _types = types.ToList();
_types.Sort();
2024-12-06 14:18:49 +00:00
2025-01-24 11:10:40 +00:00
foreach (var type in _types)
2024-12-06 14:18:49 +00:00
{
2025-01-24 11:10:40 +00:00
Console.WriteLine(type);
}
Console.WriteLine();
}
2024-03-06 11:48:08 +00:00
}
2025-01-24 11:10:40 +00:00
}
//AuthLevel
//Boolean
//Byte
//DecimalPointLocations
//FactoryState
//Int32
//MBusModes
//MessurementUnits
//MeterTypes
//Options
//OTAMode
//RegisterMode
//ResetMode
//String
//Types
//UInt16
//UInt32
//WakeUpMode