public static void Main()
Console.WriteLine("Start! ");
string vstupA = " 810100200F000F00";
string vstupB = " 00A60000101E0100";
string l7_vstupA = " 800075087C250B26";
string l7_vstupB = " 00290B2600000000";
_DateTimeFrom = new DateTime(2020, 3, 23, 0, 0, 0);
_DateTimeFrom = new DateTime(_DateTimeFrom.Year, _DateTimeFrom.Month, _DateTimeFrom.Day, 0, 0, 0, 0).AddDays((double)(-dni + 1)).AddMinutes(-3);
int flags = Convert.ToByte(vstupA.Substring(2, 2), 16); ;
bool IsActive = Convert.ToBoolean((int)(flags & 128));
int RecordLength = (int)Math.Pow(2.0, (double)(((flags & 112) >> 4) + 2));
int MaxRecordCount = Convert.ToUInt16(vstupA.Substring(8, 2) + vstupA.Substring(6, 2), 16);
int RecordPeriod = Convert.ToUInt16(vstupA.Substring(12, 2) + vstupA.Substring(10, 2), 16);
string DataAddress = vstupB.Substring(8, 2) + vstupB.Substring(6, 2) + vstupB.Substring(4, 2) + vstupB.Substring(2, 2);
int ProfileID = Convert.ToByte(vstupB.Substring(10, 2), 16);
int UnitID = Convert.ToByte(vstupB.Substring(12, 2), 16);
int UnitBase = Convert.ToByte(vstupB.Substring(14, 2), 16);
int UnitExponent = Convert.ToByte(vstupB.Substring(16, 2), 16);
int l7_flag = Convert.ToByte("80", 16);
bool l7_IsProfileEmpty = Convert.ToBoolean((int)(l7_flag & 32));
bool l7_IsProfileAreaFull = Convert.ToBoolean((int)(l7_flag & 64));
int l7_LastRecordIndex = Convert.ToUInt16(l7_vstupA.Substring(8, 2) + l7_vstupA.Substring(6, 2), 16);
uint l7_LastRecordTimestamp = Convert.ToUInt32(l7_vstupA.Substring(16, 2) + l7_vstupA.Substring(14, 2) + l7_vstupA.Substring(12, 2) + l7_vstupA.Substring(10, 2), 16);
uint l7_LastRecordTimestamp2 = Convert.ToUInt32(l7_vstupB.Substring(8, 2) + l7_vstupB.Substring(6, 2) + l7_vstupB.Substring(4, 2) + l7_vstupB.Substring(2, 2), 16);
DateTime dateTime2 = new DateTime(2000, 1, 1, 0, 0, 0, 0 );
DateTime l7_LastRecordDateTime = dateTime2.AddSeconds(l7_LastRecordTimestamp);
DateTimeOffset ZERO = new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero);
DateTime now = _DateTimeFrom;
TimeSpan timeSpan = l7_LastRecordDateTime - now;
if (timeSpan.TotalMinutes > 10.0)
Console.WriteLine("kontrola datumu a casu profilu");
Console.WriteLine("Profil je prazdny! {0}", l7_IsProfileEmpty);
int num = Convert.ToInt32(DataAddress, 16);
int num2 = (int)MaxRecordCount * RecordLength;
int num8 = (int)l7_LastRecordIndex * RecordLength;
string address2 = string.Format("{0:x8}", num9).ToUpper();
string text2 = string.Format("{0:x4}", num + num2 - num9).ToUpper();
long num10 = Convert.ToInt64(TimeSpan.FromTicks(new DateTime(2000, 1, 1).Ticks).TotalSeconds);
long num11 = Convert.ToInt64(TimeSpan.FromTicks(_DateTimeFrom.Ticks).TotalSeconds);
Console.WriteLine("Krok 1");
num11 = Convert.ToInt64(TimeSpan.FromSeconds((double)(num11 - num10)).TotalSeconds);
if (num11 > (long)(l7_LastRecordTimestamp))
Console.WriteLine("Krok 2");
Console.WriteLine("Datum od neho su pozadovane data je mimo rozsah profilu!");
Console.WriteLine("Krok 3");
long num12 = (long)((ulong)l7_LastRecordTimestamp - (ulong)num11); ;
long num13 = num12 / ((long)(RecordPeriod * 60) + 1L);
num14 = num13 * (long)RecordLength;
if ((long)Convert.ToInt32(text2, 16) >= num14)
Console.WriteLine("Krok 4");
num14 = (long)(MaxRecordCount * RecordLength);
Console.WriteLine("Krok 5 - address2, text2");
num14 = Convert.ToInt32(text2, 16);
Console.WriteLine("Krok 6 - address2, num14");
Console.WriteLine("\nVystup:\n Adresa: {0}\n text2: {1}\n num14: {2:x4}\n num11: {3:x8}\n Hladana: {4:x4}", address2, text2, num14, num11, hladana);
Console.WriteLine("Datum: {0} -> {1}", ZERO.AddSeconds((double)num11), ZERO.AddSeconds((double)num11).ToUnixTimeSeconds());
Console.WriteLine("\nlist4:\n RecordLength: {0}\n MaxRecordCount: {1}\n RecordPeriod: {2}\n ProfileID: {3}\n", RecordLength, MaxRecordCount, RecordPeriod, ProfileID);
Console.WriteLine("list7: \n l7_IsProfileEmpty: {0}\n l7_IsProfileAreaFull: {1}\n l7_LastRecordIndex: {2}", l7_IsProfileEmpty, l7_IsProfileAreaFull, l7_LastRecordIndex);
Console.WriteLine(" LastRecordTimestamp {0} -> {1} -> {2}", l7_LastRecordTimestamp, ZERO.AddSeconds(l7_LastRecordTimestamp).ToUnixTimeSeconds(), ZERO.AddSeconds(l7_LastRecordTimestamp));
Console.WriteLine(" LastRecordTimestamp2 {0} -> {1} -> {2}", l7_LastRecordTimestamp2, ZERO.AddSeconds(l7_LastRecordTimestamp2).ToUnixTimeSeconds(), ZERO.AddSeconds(l7_LastRecordTimestamp2));
Console.WriteLine("Vystupne data: {0}({1})", address2, num14);