commit for sync
This commit is contained in:
@@ -1,98 +1,10 @@
|
||||
namespace CommonConsole
|
||||
{
|
||||
using Common.Hardware.WaterMeter.OmniPlus;
|
||||
using Common.Hardware.WaterMeter.OmniPlus.Features;
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var connection = new OmniConnection();
|
||||
connection.UseUniPro("COM9");
|
||||
|
||||
var _params = connection.Set(new ConfigurationParametersSet
|
||||
{
|
||||
AlarmPercistancePeriodDays = 8,
|
||||
BuildInfo = "816234014680",
|
||||
DataLogIntervalMinutes = 60,
|
||||
DeviceID = "OMNI-02",
|
||||
FactoryID = "98944637",
|
||||
ManifacturingTime = (UInt32)new DateTime(2023, 01, 01, 12, 0, 0).TimeOfDay.TotalSeconds,
|
||||
NumberOfReadingDigits = 8,
|
||||
OptionalUniDirFields = 12,
|
||||
ProgrammableID = "95061881",
|
||||
ReadingPreset = "00000010",
|
||||
RebootCount = 0,
|
||||
SystemTime = Epoch20000101.UTCNow
|
||||
});
|
||||
|
||||
|
||||
connection.Disconnect();
|
||||
|
||||
//var econnector = new EregisterConnector.EregisterConnector();
|
||||
|
||||
//econnector.InitInspection();
|
||||
}
|
||||
|
||||
//var payloadLength = 32;
|
||||
//var payload = new Byte[payloadLength];
|
||||
|
||||
//for (var i = 0; i < 32; i++)
|
||||
//{
|
||||
// payload[i] = (Byte)(i + 1);
|
||||
//}
|
||||
|
||||
//var withAddress = new Byte[payloadLength + 4];
|
||||
|
||||
//Array.Copy(payload, 0, withAddress, 4, payloadLength);
|
||||
|
||||
//var keyLength = 16;
|
||||
//var key = new Byte[keyLength];
|
||||
|
||||
//for (var i = 0; i < keyLength; i++)
|
||||
//{
|
||||
// payload[i] = (Byte)(keyLength - i);
|
||||
//}
|
||||
|
||||
//Console.WriteLine(BitConverter.ToString(key));
|
||||
//Console.WriteLine(BitConverter.ToString(withAddress));
|
||||
//Console.WriteLine(BitConverter.ToString(Encrypt(payload, key, 0)));
|
||||
|
||||
static Byte[] Encrypt(Byte[] bytes, Byte[] key, Int32 address)
|
||||
{
|
||||
var requestBytesList = new List<Byte>(bytes);
|
||||
var addressBytes = address.ToBigEndianBytes();
|
||||
requestBytesList.InsertRange(9, addressBytes);
|
||||
|
||||
var bytesToEncryptCount = requestBytesList.Count; // 4(address) + 2(crc)
|
||||
var keyByte = Byte.MaxValue;
|
||||
var reference = address;
|
||||
|
||||
for (Int32 encryptIndex = 0; encryptIndex < bytesToEncryptCount; encryptIndex++, encryptIndex++)
|
||||
{
|
||||
// Update KeyDefinition for this byte
|
||||
keyByte += (Byte)(((reference >> ((keyByte & 0x3) << 3)) & 0xFF) >> ((keyByte >> 6) & 1));
|
||||
|
||||
// Update the unencrypted reference before the byte gets encrypted
|
||||
reference = reference << 8;
|
||||
reference += requestBytesList[encryptIndex];
|
||||
|
||||
// Encrypt the data by applying the resepective key
|
||||
requestBytesList[encryptIndex] ^= key[(keyByte >> 2) & 0x0F];
|
||||
|
||||
// Check if data has to be inverted
|
||||
if (keyByte > 127)
|
||||
{
|
||||
requestBytesList[encryptIndex] = (Byte)~requestBytesList[encryptIndex];
|
||||
}
|
||||
}
|
||||
|
||||
return requestBytesList.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user