laatzen/Common/CommonConsole/Program.cs
2024-09-16 11:11:52 +02:00

552 lines
12 KiB
C#

namespace CommonConsole
{
using System;
public class Program
{
public static void Main()
{
int value = 333333333;
var bytes1 = BitConverter.GetBytes(value);
Array.Reverse(bytes1);
Console.WriteLine(BitConverter.ToString(bytes1).Replace('-', ' '));
var hex = string.Empty;
while (value > 0)
{
hex = $"{value % 256:X2}{hex}";
value /= 256;
}
Console.WriteLine(hex);
}
/// <summary>
/// 0B
/// D0
/// FF C6 25 F3
/// 00
/// 0A
/// 11 08
/// 11 08
///
/// 04 01 C7 47 9F 77 17 00 6A 00 08 08 00 00 00 00 05 68 46 89 02 01 01 16 00 0A 00 00 02 71 02 71 00 00 00 00 00 00 00 08
/// </summary>
//var bytes = new[] { 0x08, 0x11 };
//var bits = new Byte[16];
//var x = 0;
//foreach (var @byte in bytes)
//{
// for (var i = 0; i< 8; i++, x++)
// {
// bits[x] = (Byte) ((@byte >> i) & 1);
// }
//}
//Array.Reverse(bits);
//var type = bits[15] == 0 ? 'B' : 'R';
//var majorBits = new Byte[8];
//majorBits[0] = bits[14];
//majorBits[1] = bits[13];
//majorBits[2] = bits[12];
//var major = 0;
//for (var i = 0; i< 8; i++)
//{
// major |= majorBits[i] << i;
//}
//var minorBits = new Byte[8];
//majorBits[0] = bits[11];
//majorBits[1] = bits[10];
//majorBits[2] = bits[9];
//majorBits[2] = bits[8];
//var minor = 0;
//for (var i = 0; i< 8; i++)
//{
// minor |= minorBits[i] << i;
//}
//Console.WriteLine($"{type}{major}.{minor}.{0x08}");
//var programmingBatch = new JusteRegisterProgrammingBatch();
//if (programmingBatch.StartOnCOMPort("COM6"))
//{
// var task = new JusteRegisterProgrammingTask
// {
// Cmd = JustSirtMessage.W_PAM,
// P1 = new P811
// {
// DelPamSemi = true
// },
// Address = 319020415,
// Data = new Byte[]
// {
// // Metrology parameters
// 0x92, 0x10, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x71, 0x02, 0x00, 0x00,
// // Provide Pin Auth Level III
// 0x43, 0x03, 0x63, 0x93, 0x73, 0x22,
// }
// };
// programmingBatch.Run(task);
// Console.ReadKey();
// programmingBatch.Stop();
//}
//else
//{
// Console.WriteLine("Not connected!");
//}
// 01020304050607081112131415161718
// E6C88800DEB868C0D6A84880CE982840
//var encryptionKey = new Byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18 };
//var task = new JusteRegisterProgrammingTask
//{
// Cmd = JustSirtMessage.W_PAM,
// P1 = new P811
// {
// DelPamSemi = true,
// WakeUpCmd = true
// },
// Address = 4291305226,
// // Address = 319020415,
// Data = new Byte[]
// {
// // Change Key
// // 0x6C, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
// // LED on
// // 0x1F, 0x01, 0x08,
// // Reboot
// 0x0E, 0x00,
// // Provide Pin Auth Level I
// // 0x43, 0x01, 0x14, 0x30, 0x68, 0xD0,
// // Provide Pin Auth Level II
// // 0x43, 0x02, 0x14, 0x0E, 0x80, 0x40,
// // Provide Pin Auth Level III
// 0x43, 0x03, 0x63, 0x93, 0x73, 0x22,
// // Reset credits
// // 0x1F, 0x01, 0x03,
// },
// EncryptionKey = encryptionKey
//};
//programmingBatch.Run(task);
//task.Wait();
// 55 81 14 00 FF C8 1F 0A 0B 07 FA E3 AA EA 8A 7B 7B D9 A7 D7 D5 B8 16
// 55 81 14 00 FF C8 1F 0A 0B 07 FA E3 AA EA 8A 7B 7B D9 A7 D7 D5 B8 16
//var task = new JusteRegisterTask
//{
// Cmd = JustSirtMessage.W_PAM,
// P1 = new P811
// {
// DelPamSemi = true
// },
// Address = 319020415,
// Data = new Byte[]
// {
// // WUP stay awake
// 0x00, 0x00,
// // LAT
// 0x02, 0x00,
// // MBUS 7
// 0x05, 0x07,
// // TX
// 0x10, 0x00, 0x03,
// // Provide Pin Auth Level I
// // 0x43, 0x01, 0x14, 0x30, 0x68, 0xD0,
// // Provide Pin Auth Level II
// 0x43, 0x02, 0x14, 0x0E, 0x80, 0x40,
// // Provide Pin Auth Level III
// // 0x43, 0x03, 0x63, 0x93, 0x73, 0x22,
// // Reset credits
// // 0x1F, 0x01, 0x03,
// }
//};
//programmingBatch.Run(task);
//task.Wait();
//task = new JusteRegisterTask
//{
// Cmd = JustSirtMessage.W_PAM,
// P1 = new P811
// {
// DelPamSemi = true
// },
// Address = 319020415,
// Data = new Byte[]
// {
// // Parametersatz
// // Provide Pin Auth Level I
// // 0x43, 0x01, 0x14, 0x30, 0x68, 0xD0,
// // Provide Pin Auth Level II
// 0x43, 0x02, 0x14, 0x0E, 0x80, 0x40,
// // Provide Pin Auth Level III
// // 0x43, 0x03, 0x63, 0x93, 0x73, 0x22,
// // Reset credits
// // 0x1F, 0x01, 0x03,
// }
//};
//programmingBatch.Run(task);
//task.Wait();
//public static byte[] Decrypt(Byte[] key, params Byte[] message)
//{
// var decryptLength = message.Length;
// var decryptedBytes = new Byte[decryptLength];
// for (int i = 0; i < decryptLength; i++)
// {
// decryptedBytes[i] = message[i];
// }
// var start = 14;
// var end = start + decryptedBytes[7] 6;
// var token = decryptedBytes[9];
// for (var i = start; i < end; i++)
// {
// token += (Byte)(decryptedBytes[i (token & 0x3) 1] >> ((token >> 6) & 0x1));
// decryptedBytes[i] ^= key[(token >> 2) & 0x0F];
// if (token > 127)
// {
// decryptedBytes[i] = (Byte)~decryptedBytes[i];
// }
// }
// return decryptedBytes;
//}
//public static byte[] Encrypt(Byte[] key, UInt32 address, params Byte[] telegramBytes)
//{
// Console.WriteLine(address);
// Console.WriteLine(BitConverter.ToString(key));
// Console.WriteLine(BitConverter.ToString(telegramBytes));
// var telegramLength = telegramBytes.Length;
// var telegramIndex = 0;
// var encryptedBytes = new Byte[telegramLength + 6];
// var encryptLength = encryptedBytes.Length;
// var index = 0;
// encryptedBytes[index++] = (Byte)(address >> 24);
// encryptedBytes[index++] = (Byte)(address >> 16);
// encryptedBytes[index++] = (Byte)(address >> 8);
// encryptedBytes[index++] = (Byte)(address >> 0);
// foreach (var _byte in telegramBytes)
// {
// encryptedBytes[index++] = telegramBytes[telegramIndex++];
// }
// var telegramCRC = CalculateCrc(encryptedBytes, 1, (UInt16)(encryptLength 3));
// encryptedBytes[index++] = (Byte)(telegramCRC >> 8);
// encryptedBytes[index++] = (Byte)(telegramCRC >> 0);
// Console.WriteLine(BitConverter.ToString(encryptedBytes));
// var token = (Byte)0xFF;
// var reference = address;
// for (var i = 0; i < encryptLength; i++)
// {
// // Update pKeyDefinition for this byte
// token += (Byte)(((reference >> ((token & 0x3) << 3)) & 0xFF) >> ((token >> 6) & 1));
// // Update the unencrypted reference before the byte gets encrypted
// reference = (reference << 8);
// reference += encryptedBytes[i];
// // Encrypt the data by applying the resepective key
// encryptedBytes[i] ^= key[((token >> 2) & 0x0F)];
// // Check if data has to be inverted
// if (token > 127)
// {
// encryptedBytes[i] = (Byte)~encryptedBytes[i];
// }
// }
// Console.WriteLine(BitConverter.ToString(encryptedBytes));
// Console.WriteLine();
// return encryptedBytes;
//}
//public static ushort CalculateCrc(byte[] data, ushort start, ushort length)
//{
// byte zeichen, test;
// ushort crc_result;
// ushort ui_index;
// byte h;
// crc_result = 0xFFFF;
// ui_index = start;
// if (data.Length >= length + start)
// {
// while (ui_index < length + start)
// {
// zeichen = data[ui_index];
// ui_index++;
// for (h = 0; h < 8; h++)
// {
// test = 0;
// if ((crc_result & 0x8000) != 0)
// {
// test = 0x80;
// }
// crc_result <<= 1;
// if (((zeichen & 0x80) ^ test) != 0)
// {
// crc_result ^= 0x1021;
// }
// zeichen <<= 1;
// }
// }
// }
// return crc_result;
//}
}
}
//var connector = EregisterConnector.CreateNew("COM6", 1000);
//connector.Add(1, 0319020415, 0319020415);//433
//connector.AddHexCommand(1, "00 00");
//connector.Add(2, 0319020441, "4291317405", "4291317405", null, false); // 433
//connector.InitInspection();
//connector.Add(3, 4291317405, 4291317405);//433
//connector.AddHexCommand(3, "00 00");
// connector.RunCommands();
//var connector = EregisterConnector.CreateNew("COM6", 1000);
//connector.Add(1, 0319020415, 0319020415);//433
//connector.AddHexCommand(1, "00 00");
//connector.Add(2, 0319020441, 0319020441);//433
//connector.AddHexCommand(2, "00 00");
//connector.Add(3, 4291317405, 4291317405);//433
//connector.AddHexCommand(3, "00 00");
//connector.InitInspection();
//var connection = new OmniConnection();
//connection.UseUniPro("COM16");
//var system = connection.ViewSystemParameters();
//connection.Disconnect();
// 0x08, 0x0E, 0x13, 0x03, 0xEE, 0xAC, 0x00, 0x00, 0x01, 0xF4, 0x00, 0x00, 0x92, 0x0A, 0x00, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x13, 0x13, 0x03, 0xEE, 0xAC, 0x07, 0x0E, 0x10, 0xA0, 0x57, 0x4E, 0xDA, 0xC0, 0x00, 0x00, 0x7F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x03, 0x05, 0xA0, 0x0C, 0x03, 0x01, 0x2E, 0x46, 0x7C, 0x76, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x25, 0x14, 0x3B
// 0x0B, 0x10, 0x13, 0x03, 0xEE, 0xAC, 0x00, 0x0A, 0x11, 0x0B, 0x11, 0x08, 0x04, 0x02, 0xC8, 0xF4, 0xFB, 0xA7, 0x18, 0x00, 0x65, 0x00, 0x35, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0xEE, 0x34, 0x02, 0x01, 0x01, 0x16, 0x00, 0x25, 0x02, 0x71, 0x00, 0x00, 0x82, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x08, 0xC3