e-register manual programming

This commit is contained in:
Stoyan Zlatev
2025-01-24 12:10:40 +01:00
parent 828f8631ec
commit 3edc7df3a9
88 changed files with 1805 additions and 2796 deletions
+119 -95
View File
@@ -1,124 +1,148 @@
namespace CommonConsole
{
using Common.Hardware.SIRT;
using Common.Hardware.SIRT.Parameters;
using Common.Hardware.WaterMeter.eRegister;
using Common.Hardware.WaterMeter.eRegister.Features;
using Newtonsoft.Json;
using Common.Hardware.WaterMeter.eRegister.Models;
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Net;
using System.Net.Http;
using static Xylem.Common.Service.MeterProcessState.Controllers.OldPasswordController;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
public class Program
public static class Program
{
public class FeatureDictionary : SortedDictionary<string, PropertyInfo>
{
public PropertyInfo FeatureInfo { get; set; }
}
public static void Main()
{
var features = new SortedDictionary<bool, SortedDictionary<string, SortedDictionary<string, FeatureDictionary>>>();
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
void ParseType(Type type)
{
return true;
};
// $"https://nodes.sms-esaap.com:8081/api/v3/custom/keysetkeys?orderNumber=3229547&radioAdress=241630563"
using (var request = new HttpRequestMessage(HttpMethod.Put, $"https://nodes.sms-esaap.com:8081/api/v3/custom/keysetkeys?orderNumber=3229547&radioAdress=241630563"))
{
request.Headers.Add("Cache-Control", "no-cache");
request.Headers.Add("X-Node-Token", "d5b8c0b2-81f6-4421-80d0-44eb2093e616");
using (var response = new HttpClient().SendAsync(request).Result)
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
var content = response.Content.ReadAsStringAsync().Result;
var x = MeterPw.FromJson(content);
var propertyType = property.PropertyType;
if (!typeof(Pam).IsAssignableFrom(propertyType))
{
continue;
}
var pamAttribute = property.GetCustomAttribute<PamAttribute>();
if (pamAttribute is null)
{
continue;
}
var isSingleCmd = pamAttribute.IsSingleCmd;
if (!features.ContainsKey(isSingleCmd))
{
features[isSingleCmd] = new SortedDictionary<string, SortedDictionary<string, FeatureDictionary>>();
}
var _features = features[isSingleCmd];
var authBytes = pamAttribute.AuthLevel.AuthBytes();
var authLevel = $"{authBytes.LastOrDefault():X2}";
if (authBytes.Length > 0)
{
authLevel = $"{authBytes[1]:X2}";
}
if (!_features.ContainsKey(authLevel))
{
_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)
{
cmdHex = $"00-{cmdHex}";
}
if (!__features.ContainsKey(cmdHex))
{
__features[cmdHex] = new FeatureDictionary();
}
var ___features = __features[cmdHex];
___features.FeatureInfo = property;
foreach (var _property in propertyType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (_property.CanWrite && _property.PropertyType != typeof(byte[]))
{
___features[_property.Name] = _property;
}
}
}
}
//var client = new SIRTClient("COM6");
ParseType(typeof(EregisterFeatures));
ParseType(typeof(EregisterDebugFeatures));
//client.OpenConnection();
//Console.ReadKey();
//client.CloseConnection();
}
}
var types = new HashSet<string>();
public class SIRTClient
{
private readonly ConcurrentDictionary<uint, EregisterTask> tasks;
private readonly SIRTBroadcaster broadcaster;
public SIRTClient(string comPort)
{
this.tasks = new ConcurrentDictionary<uint, EregisterTask>();
this.broadcaster = new SIRTBroadcaster(comPort);
this.broadcaster.Activated += this.Broadcaster_Activated;
this.broadcaster.Connected += this.Broadcaster_Connected;
this.broadcaster.Disconnected += this.Broadcaster_Disconnected;
this.broadcaster.Logging += this.Broadcaster_Logging;
this.broadcaster.MessageReceived += this.Broadcaster_MessageReceived;
}
internal void CloseConnection() => this.broadcaster.Close();
internal void OpenConnection() => this.broadcaster.Open();
private void Broadcaster_Activated()
{
Console.WriteLine(nameof(Broadcaster_Activated));
this.tasks.GetOrAdd(4291796386, _ =>
foreach (var kvp in features)
{
var task = new EregisterTask(868)
Console.WriteLine(kvp.Key ? "Single PAM:" : "Combined PAM:");
foreach (var _kvp in kvp.Value)
{
Cmd = SIRTMessage.W_PAM,
P1 = new P811
Console.WriteLine($" Auth level {_kvp.Key}:");
foreach (var __kvp in _kvp.Value)
{
DelPamSemi = true,
},
Data = new ChangeRadioId
{
Address = 309030150
Console.WriteLine($" {__kvp.Key} {__kvp.Value.FeatureInfo.Name}");
}.Append(new ProvidePin
{
AuthLevel = AuthLevel.III
}),
RequestAddress = 4291796386,
ResponseAddress = 309030150
};
foreach (var ___kvp in __kvp.Value)
{
Console.WriteLine($"\t\t{___kvp.Key} - {___kvp.Value.PropertyType.Name}");
task.Completed += this.Task_Completed;
types.Add(___kvp.Value.PropertyType.Name);
}
}
}
}
this.broadcaster.EnqueueTask(task);
Console.WriteLine();
return task;
});
}
var _types = types.ToList();
_types.Sort();
private void Broadcaster_Connected() => Console.WriteLine(nameof(Broadcaster_Connected));
private void Broadcaster_Disconnected() => Console.WriteLine(nameof(Broadcaster_Disconnected));
private void Broadcaster_Logging(string message)
{
}
private void Broadcaster_MessageReceived(SIRTMessage message)
{
}
private void Task_Completed(SIRTTask task)
{
task.Completed -= this.Task_Completed;
Console.WriteLine($"Task_Completed: {task}");
File.WriteAllText($"..\\..\\Tasks\\{task.RequestAddress}.json", JsonConvert.SerializeObject(task, new JsonSerializerSettings
foreach (var type in _types)
{
Formatting = Formatting.Indented
}));
Console.WriteLine(type);
}
Console.WriteLine();
}
}
}
}
//AuthLevel
//Boolean
//Byte
//DecimalPointLocations
//FactoryState
//Int32
//MBusModes
//MessurementUnits
//MeterTypes
//Options
//OTAMode
//RegisterMode
//ResetMode
//String
//Types
//UInt16
//UInt32
//WakeUpMode