133 lines
4.0 KiB
C#
133 lines
4.0 KiB
C#
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 System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
public class Program
|
|
{
|
|
public static void Main()
|
|
{
|
|
foreach (var property in typeof(Pam).GetFields(BindingFlags.Public | BindingFlags.Static))
|
|
{
|
|
Console.WriteLine($"{property.Name}: {property.GetValue(null)}");
|
|
}
|
|
|
|
//var client = new SIRTClient("COM6");
|
|
|
|
//client.OpenConnection();
|
|
//Console.ReadKey();
|
|
//client.CloseConnection();
|
|
}
|
|
}
|
|
|
|
public class SIRTClient
|
|
{
|
|
private readonly ConcurrentDictionary<uint, EregisterTask> activateable;
|
|
private readonly ConcurrentDictionary<uint, EregisterTask> tasks;
|
|
private readonly SIRTBroadcaster broadcaster;
|
|
|
|
public SIRTClient(string comPort)
|
|
{
|
|
this.activateable = new ConcurrentDictionary<uint, EregisterTask>(new Dictionary<uint, EregisterTask>
|
|
{
|
|
// 433
|
|
{ 875770417, null },
|
|
{ 4291267283, null },
|
|
{ 4291317405, null },
|
|
// 868
|
|
// { 4291631647, null },
|
|
});
|
|
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));
|
|
|
|
foreach (var kvp in this.activateable)
|
|
{
|
|
this.tasks.GetOrAdd(kvp.Key, _ =>
|
|
{
|
|
var task = new EregisterTask(433, 3000)
|
|
{
|
|
Cmd = SIRTMessage.W_PAM,
|
|
P1 = new P811
|
|
{
|
|
DelPamSemi = true,
|
|
},
|
|
Data = new OpticalTelegram
|
|
{
|
|
Minutes = 1
|
|
}.Append(new ProvidePin
|
|
{
|
|
AuthLevel = AuthLevel.III
|
|
}),
|
|
RequestAddress = kvp.Key
|
|
};
|
|
|
|
task.Completed += this.Task_Completed;
|
|
|
|
this.broadcaster.EnqueueTask(task);
|
|
|
|
return task;
|
|
});
|
|
}
|
|
}
|
|
|
|
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
|
|
{
|
|
Formatting = Formatting.Indented
|
|
}));
|
|
}
|
|
}
|
|
} |