laatzen/Common/CommonConsole/Program.cs
2026-03-10 11:16:20 +01:00

297 lines
16 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace CommonConsole
{
using Common.Hardware.SIRT;
using Common.Hardware.SIRT.Tasks;
using Common.Hardware.WaterMeter.eRegister.Features;
using Common.Hardware.WaterMeter.eRegister.Telegrams;
using System;
using System.Net;
using System.Net.Http;
public static partial class Program
{
static void Main_Pwd()
{
//ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
//{
// return true;
//};
using (var httpRequest = new HttpRequestMessage(HttpMethod.Get, "https://nodes.sms-esaap.com:8081/api/v3/custom/keysetkeys?orderNumber=3251950&radioAdress=10402032336"))
{
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;
}
}
}
}
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",
};
};
}
}