namespace CommonConsole { using Common.Hardware.SIRT; using Common.Hardware.SIRT.Tasks; using Common.Hardware.WaterMeter.eRegister.Features; using LaaPackages.SqlClient; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Runtime.Serialization; public static partial class Program { static void Main() { } public class Apps : Dictionary { private readonly Dictionary apps = new Dictionary(); [OnDeserialized] private void OnDeserialized(StreamingContext _) { foreach (var kvp in this) { var app = kvp.Value; app.Name = kvp.Key; this.apps[app.Id] = app; } } internal object GetAppName(int appId) { if (this.apps.TryGetValue(appId, out var app)) { return app.Name; } return default(object); } internal object GetRegName(int appId, int regId) { if (this.apps.TryGetValue(appId, out var app)) { return app.GetRegName(regId); } return default(object); } } public class App { public int Id { get; set; } public string Name { get; set; } public Registers Registers { get; set; } = new Registers(); internal object GetRegName(int regId) => this.Registers.GetRegName(regId); } public class Registers : Dictionary { private readonly Dictionary registers = new Dictionary(); internal object GetRegName(int regId) { if (this.registers.TryGetValue(regId, out var reg)) { return reg.Name; } return default(object); } [OnDeserialized] private void OnDeserialized(StreamingContext _) { foreach (var kvp in this) { var register = kvp.Value; register.Name = kvp.Key; this.registers[register.Id] = register; } } } public class Register { public int Id { get; set; } public string Name { get; set; } } static void Main_RegHistory() { var json = File.ReadAllText(@"..\..\all.json"); var apps = JsonConvert.DeserializeObject(json); var csv = new List>(); csv.Add(new List { "PcbId", "AppId", "AppName", "RegId", "RegName", "Value", "Date" }); SqlConnection .CreateSqlConnection("Server=DELAZ1SQL01.world.fluidtechnology.net; Database=Auftrag; User ID=sa; Password=sqlserver;") .CreateCommand(@" SELECT x.PcbId , CONVERT(INT, CONVERT(VARBINARY, LEFT(x.Address, 2), 2)) AS App , CONVERT(INT, CONVERT(VARBINARY, RIGHT(x.Address, 2), 2)) AS Reg , x.Value , FORMAT(x.date, 'yyyy-MM-dd HH:mm:ss') AS Date FROM (SELECT PcbId , Address , Value , date , ROW_NUMBER() OVER (PARTITION BY Address ORDER BY date DESC) AS RowNr FROM GenesisMeterRegisterHistory WHERE PcbId = '254620052' AND Value <> 'NULL') AS x WHERE x.RowNr = 1") .ExecuteReader(x => { var pcbId = x.GetValue(0); var appId = x.GetValue(1); var appName = apps.GetAppName(appId); var regId = x.GetValue(2); var regName = apps.GetRegName(appId, regId); var value = x.GetValue(3); var date = x.GetValue(4); csv.Add(new List { pcbId, appId, appName, regId, regName, value, date }); }); File.WriteAllLines(@"..\..\254620052.csv", csv.Select(x => string.Join(";", x))); } static void Main_Pwd() { //var Url = $"{ServiceUrls.KeyServerCustom()}keysetkeys/"; //var Url = "https://nodes.sms-esaap.com/keygenproxy/api/v3/custom/keysets/devices"; //var header = new Dictionary(); //header.Add("Cache-Control", "no-cache"); //header.Add("X-Node-Token", Token);//"d5b8c0b2-81f6-4421-80d0-44eb2093e616"); //string postData = $"[{{\"setId\":\"{KeySetID}\", \"orderNumber\":\"{orderNumber}\", \"radioAdress\":\"{radioAdress}\"}}]"; //var postData = new MapKeySetItem() //{ orderNumber = MeterOrderNumber.ToString(), radioAdress = MeterPassowrdIdent.ToString(), setId = KeySetID }; //var helpArray = new List() { postData }; // return LocalWebRequest.PostRequestAsyncAndGetContent(url: Url, header: header, json: helpArray.ToArray(), timeoutMs: 20000); //using (var httpRequest = new HttpRequestMessage(HttpMethod.Post, "https://nodes.sms-esaap.com/keygenproxy/api/v3/custom/keysets/devices")) //{ // httpRequest.Headers.Add("Cache-Control", "no-cache"); // httpRequest.Headers.Add("X-Node-Token", "d5b8c0b2-81f6-4421-80d0-44eb2093e616"); // httpRequest.Content = new StringContent(JsonConvert.SerializeObject(units)); // httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // using (var httpResponse = new HttpClient().SendAsync(httpRequest).Result) // { // using (var httpContent = httpResponse.Content) // { // var content = httpContent.ReadAsStringAsync().Result; // } // } //} // 43280002E023 // 0ED6EE109B27B7C02E6A351C0F66B155649938996D7B45475F67A568CCBEC34E // A15088A4B476B3F47A5F14F0D8DCDAE4F42D3279FD9B6D9AC995389251D0AEB6 // 449E0701B6C2 // 0B34274BE517CD86B7A378AD197D3AA0FC2C262C0B09ED4A530FAED7E52615CC // 42ED98391C30EECA5CC500A3086BD4B0A20ACF387BB41613057FF476D7E4D822 // 8C5FD08CC8D720344243D4059AD34982F2452C5123F42D7E417DB03B3C59D1D8 // E18AFAF87B9301A5FF5F3539752BADA03389F1A1E9470EF99FC64F313351C485 // F87DD657D1A11D1EBD3A8F21779DD2E60B4B8B4F5203A6680A5EBCE72DC7F771 // 528B13015F205316381018A5CD16264266B58BB3F1A1DE09EB88D75132694834 // C0E9DBBD18F1101F8AABC3C48B71996768E8F8C30E91E402A10627D42B8F734B // 73C8A7C67600F91C66512FBED68610A25BBF2F2A5AFED40CDEA0C33C71F15535 // 4B3DEEBFE79E1594BAF13A743CD252295B0D1C8200BD03C1F904850768FD145B // A1F4FA7C71A5EAC60257480FF5DCE1FF5B076BF134DD67B13FF11A9309009E90 var units = new List { new { orderNumber = 3251029, radioAdress = 10402023451, setId = "8d98dfc7-27ab-4a7b-b3e1-44206fe122c3" }, // 4B3DEEBFE79E new { orderNumber = 3251029, radioAdress = 10402023470, setId = "2698c112-eb85-4408-a1b4-4bc1e64cbfc3" }, // A1F4FA7C71A5 new { orderNumber = 3251029, radioAdress = 10402023476, setId = "5744f62e-f2d9-47be-8d9f-b25b9801de92" }, // 73C8A7C67600 new { orderNumber = 3251029, radioAdress = 10402023479, setId = "67a66322-c19b-4b18-a24a-ada3e5c7f659" }, // C0E9DBBD18F1 new { orderNumber = 3251029, radioAdress = 10402023480, setId = "438dc338-0c78-42fa-9436-1a9ad21c4e29" }, // 528B13015F20 }.ToArray(); using (var httpRequest = new HttpRequestMessage(HttpMethod.Get, "https://nodes.sms-esaap.com:8081/api/v3/custom/keysetkeys?orderNumber=0&radioAdress=10402023480")) { httpRequest.Headers.Add("Cache-Control", "no-cache"); httpRequest.Headers.Add("X-Node-Token", "d5b8c0b2-81f6-4421-80d0-44eb2093e616"); using (var httpResponse = new HttpClient().SendAsync(httpRequest).Result) { using (var httpContent = httpResponse.Content) { var content = httpContent.ReadAsStringAsync().Result; Console.WriteLine(JsonConvert.SerializeObject(JsonConvert.DeserializeObject(content), Formatting.Indented)); } } } } static void Main_SIRT() { //var _semiStr = "08F5126B8061000001F40000830C00FF0000000000000009130197DB65070E10A87716DACA00007FFF0004000000000000000000000000000000000000000000000403003C0003013140EF511D00000000000000000000050005300000"; //var semiStr = "083D126B8061000002020000BF0C00FF0000000000000009130197DB65050E10A87716DAC900007FFF015A000000000000000000000000000000000000000000000403003C00030131413F6C1D000000000000000000015B015B300000"; //var semiBytes = semiStr.GetBytes(); //var semi = new SEMI(semiBytes, 868, 0); //var debugStr = "0B00126B8061000C010B0106050151F5A57213006800202000000000002C543E02010116003002710000827100000000000005A000"; //var debugBytes = debugStr.GetBytes(); //var debug = new DEBUG(debugBytes, 0); //var logfile = @"..\..\log.txt"; SIRTLogger.Message += Console.WriteLine; var hub = new SIRTHub(); hub.TryOpen("COM6", out var id1, out var mhz1); hub.TryOpen("COM7", out var id2, out var mhz2); var task = new WritePamTask { Timeout = 15000, WakeUpCmd = true, WakeUpModul = true, DelPamSemi = true, Frequency = 868, ResponseAddress = 309035105, RequestAddress = 309035105, EncryptionKeyI = "5DD3EF5233B4DAA6836721F2866182DA".GetBytes(), Data = new SetMeterType { Type = MeterTypes.Residential__0x0B } .Append(new ProvidePin(AuthLevel.III)) }; while (task.State != SIRTTaskState.Completed) { if (hub.Start(task)) { task.Wait(); } } hub.CloseAll(); } static void Main__CSD_Config() { var alarmMask = 1 << AlarmMask.ALARM_REBOOT | 1 << AlarmMask.ALARM_LOW_BATTERY | 0 << AlarmMask.ALARM_VERY_LOW_BATTERY | 0 << AlarmMask.ALARM_CONFIG_ERROR | 1 << AlarmMask.ALARM_EMPTY_PIPE | 0 << AlarmMask.ALARM_MAGNETIC_TAMPER | 1 << AlarmMask.ALARM_REVERSE_FLOW | 1 << AlarmMask.ALARM_SUSPECT_LEAK | 1 << AlarmMask.ALARM_BROKEN_PIPE | 1 << AlarmMask.ALARM_LOW_PRESSURE | 1 << AlarmMask.ALARM_HIGH_PRESSURE | 1 << AlarmMask.ALARM_LOW_TEMPERATURE | 1 << AlarmMask.ALARM_HIGH_TEMPERATURE | 0 << AlarmMask.ALARM_RADIO_ERROR | 0 << AlarmMask.ALARM_METROLOGY_PARAMS | 0 << AlarmMask.ALARM_METROLOGY_MEASURE | 0 << AlarmMask.ALARM_MAX; var alarmBytes = BitConverter.GetBytes(alarmMask); Array.Reverse(alarmBytes); Console.WriteLine($"{"VAM:",5} {alarmMask,11} {BitConverter.ToString(alarmBytes).Replace("-", "")}"); uint content = (uint)1 << LogContentBits.AlarmStatus // ALWAYS ON | (uint)1 << LogContentBits.BillingCounter // ALWAYS ON | (uint)1 << LogContentBits.ReverseCounter // | (uint)1 << LogContentBits.MaxFlow // | (uint)1 << LogContentBits.MaxFlowTime // | (uint)0 << LogContentBits.PeakFlow // | (uint)0 << LogContentBits.PeakFlowTime // | (uint)0 << LogContentBits.AvgFlow // | (uint)0 << LogContentBits.BrokenPipe // | (uint)0 << LogContentBits.BrokenPipeTime // | (uint)1 << LogContentBits.MinFlow // | (uint)0 << LogContentBits.MinFlowTime // | (uint)0 << LogContentBits.ForwardCounter // | (uint)1 << LogContentBits._UTC32 // ALWAYS ON | (uint)0 << LogContentBits._MaskSelector_1_1 // X | (uint)0 << LogContentBits._MaskSelector_1_2 // X | (uint)0 << LogContentBits.MinPress // | (uint)0 << LogContentBits.MinPressTime // | (uint)1 << LogContentBits.MaxPress // | (uint)1 << LogContentBits.MaxPressTime // | (uint)0 << LogContentBits.MinTemp // | (uint)0 << LogContentBits.MinTempTime // | (uint)0 << LogContentBits.MaxTemp // | (uint)0 << LogContentBits.MaxTempTime // | (uint)0 << LogContentBits.CurrentPress // | (uint)0 << LogContentBits.CurrentTemp // | (uint)1 << LogContentBits.ExtendedAlarm // ALWAYS ON | (uint)1 << LogContentBits._RecordCheckSum; // ALWAYS ON var contentBytes = BitConverter.GetBytes(content); Array.Reverse(contentBytes); Console.WriteLine($"{"DLG:",5} {content,11} {BitConverter.ToString(contentBytes).Replace("-", "")}"); uint fdr = (uint)1 << LogContentBits.AlarmStatus // ALWAYS ON | (uint)1 << LogContentBits.BillingCounter // ALWAYS ON | (uint)1 << LogContentBits.ReverseCounter // | (uint)0 << LogContentBits.MaxFlow // | (uint)0 << LogContentBits.MaxFlowTime // | (uint)0 << LogContentBits.PeakFlow // | (uint)0 << LogContentBits.PeakFlowTime // | (uint)0 << LogContentBits.AvgFlow // | (uint)0 << LogContentBits.BrokenPipe // | (uint)0 << LogContentBits.BrokenPipeTime // | (uint)0 << LogContentBits.MinFlow // | (uint)0 << LogContentBits.MinFlowTime // | (uint)0 << LogContentBits.ForwardCounter // | (uint)1 << LogContentBits._UTC32 // ALWAYS ON | (uint)0 << LogContentBits._MaskSelector_1_1 // X | (uint)0 << LogContentBits._MaskSelector_1_2 // X | (uint)0 << LogContentBits.MinPress // | (uint)0 << LogContentBits.MinPressTime // | (uint)0 << LogContentBits.MaxPress // | (uint)0 << LogContentBits.MaxPressTime // | (uint)0 << LogContentBits.MinTemp // | (uint)0 << LogContentBits.MinTempTime // | (uint)0 << LogContentBits.MaxTemp // | (uint)0 << LogContentBits.MaxTempTime // | (uint)0 << LogContentBits.CurrentPress // | (uint)0 << LogContentBits.CurrentTemp // | (uint)1 << LogContentBits.ExtendedAlarm // ALWAYS ON | (uint)1 << LogContentBits._RecordCheckSum; // ALWAYS ON var fdrBytes = BitConverter.GetBytes(fdr); Array.Reverse(fdrBytes); Console.WriteLine($"{"FDR:",5} {fdr,11} {BitConverter.ToString(fdrBytes).Replace("-", "")}"); Console.WriteLine(); } class LogContentBits { public const byte AlarmStatus = 0; // 0x00000001 ;The active alarm information at UTC32  public const byte BillingCounter = 1; // 0x00000002 ;The billing counter at UTC32  public const byte ReverseCounter = 2; // 0x00000004 ;The reverse counter at UTC32  public const byte MaxFlow = 3; // 0x00000008 ;The maximum flow of the current FDR period UTC32n … UTC32n1  public const byte MaxFlowTime = 4; // 0x00000010 ;The Date/Time information when Qmax happened in the FDR period  public const byte PeakFlow = 5; // 0x00000020 ;The peak flow of the current FDR period  public const byte PeakFlowTime = 6; // 0x00000040 ;The Date/Time information when Qpeak happened in the FDR period  public const byte AvgFlow = 7; // 0x00000080 ;The average flow rate in the current FDR period  public const byte BrokenPipe = 8; // 0x00000100 ;The weak flow in the current FDR period   public const byte BrokenPipeTime = 9; // 0x00000200 ;The Date/Time information when Qweak happened in the FDR period  public const byte MinFlow = 10; // 0x00000400 ;The minimum flow in the current FDR period  public const byte MinFlowTime = 11; // 0x00000800 ;The Date/Time information when Qmin happened in the FDR period  public const byte ForwardCounter = 12; // 0x00001000 ;The forward counter at UTC32  public const byte _UTC32 = 13; // 0x00002000 ;Date/Time information when the record was stored.  public const byte _MaskSelector_1_1 = 14; // 0x00004000 ;Two selector bits to switch the bitmask of the RFcommunication between the internal pages  public const byte _MaskSelector_1_2 = 15; // 0x00008000 ;Two selector bits to switch the bitmask of the RFcommunication between the internal pages public const byte MinPress = 16; // 0x00010000 ;The minimum pressure in the current LOG period  public const byte MinPressTime = 17; // 0x00020000 ;The number of 1second intervals when Pmin happened in the LOG period  public const byte MaxPress = 18; // 0x00040000 ;The maximum pressure in the current LOG period  public const byte MaxPressTime = 19; // 0x00080000 ;The number of 1second intervals when Pmax happened in the LOG period  public const byte MinTemp = 20; // 0x00100000 ;The minimum temperature in the current LOG period  public const byte MinTempTime = 21; // 0x00200000 ;The number of 1second intervals when Tmin happened in the LOG period  public const byte MaxTemp = 22; // 0x00400000 ;The maximum temperature in the current LOG period  public const byte MaxTempTime = 23; // 0x00800000 ;The number of 1second intervals when Tmax happened in the LOG period  public const byte CurrentPress = 24; // 0x01000000 ;The last measured instantaneous pressure at RTC32  public const byte CurrentTemp = 25; // 0x02000000 ;The last measured instantaneous temperature at RTC32   public const byte ExtendedAlarm = 26; // 0x04000000 ;Similar to the AlarmStatus; P and T related Alarms.  public const byte _RecordCheckSum = 27; // 0x08000000 ;A Checksum across the entire record  public const byte _Reserved_1 = 28; // 0x10000000 ;A reserved mask for a further item  public const byte _Reserved_2 = 29; // 0x20000000 ;A reserved mask for a further item  public const byte _MaskSelector_2_1 = 30; // 0x40000000 ;The mirror of the MaskSelector_1  public const byte _MaskSelector_2_2 = 31; // 0x80000000 ;The mirror of the MaskSelector_2  public static string[] BitMask = new string[] { "AlarmStatus", "BillingCounter", "ReverseCounter", "MaxFlow", "MaxFlowTime", "PeakFlow", "PeakFlowTime", "AvgFlow", "BrokenPipe", "BrokenPipeTime", "MinFlow", "MinFlowTime", "ForwardCounter", "_UTC32", "_MaskSelector_1_1", "_MaskSelector_1_2", "MinPress", "MinPressTime", "MaxPress", "MaxPressTime", "MinTemp", "MinTempTime", "MaxTemp", "MaxTempTime", "CurrentPress", "CurrentTemp", "ExtendedAlarm", "_RecordCheckSum", "_Reserved_1", "_Reserved_2", "_MaskSelector_2_1", "_MaskSelector_2_2", }; } class AlarmMask { public const byte ALARM_REBOOT = 0; // immer An public const byte ALARM_LOW_BATTERY = 1; public const byte ALARM_VERY_LOW_BATTERY = 2; /* For consistency with st_alarm_bit_t only */ public const byte ALARM_CONFIG_ERROR = 3; public const byte ALARM_EMPTY_PIPE = 4; public const byte ALARM_MAGNETIC_TAMPER = 5; /* For consistency with st_alarm_bit_t only */ public const byte ALARM_REVERSE_FLOW = 6; public const byte ALARM_SUSPECT_LEAK = 7; public const byte ALARM_BROKEN_PIPE = 8; public const byte ALARM_LOW_PRESSURE = 9; public const byte ALARM_HIGH_PRESSURE = 10; public const byte ALARM_LOW_TEMPERATURE = 11; public const byte ALARM_HIGH_TEMPERATURE = 12; public const byte ALARM_RADIO_ERROR = 13; public const byte ALARM_METROLOGY_PARAMS = 14; public const byte ALARM_METROLOGY_MEASURE = 15; public const byte ALARM_MAX = 16; public static string[] BitMask = new string[] { "ALARM_REBOOT", "ALARM_LOW_BATTERY", "ALARM_VERY_LOW_BATTERY", "ALARM_CONFIG_ERROR", "ALARM_EMPTY_PIPE", "ALARM_MAGNETIC_TAMPER", "ALARM_REVERSE_FLOW", "ALARM_SUSPECT_LEAK", "ALARM_BROKEN_PIPE", "ALARM_LOW_PRESSURE", "ALARM_HIGH_PRESSURE", "ALARM_LOW_TEMPERATURE", "ALARM_HIGH_TEMPERATURE", "ALARM_RADIO_ERROR", "ALARM_METROLOGY_PARAMS", "ALARM_METROLOGY_MEASURE", "ALARM_MAX", }; }; } }