feature description in enums

This commit is contained in:
Stoyan Zlatev
2023-10-17 16:50:28 +02:00
parent 7cf842929d
commit fe1f529b5e
8 changed files with 327 additions and 23 deletions
+46 -21
View File
@@ -13,37 +13,62 @@ namespace OmniPlus.Connections
/// <returns>Two bytes array from the calculated CRC16 in LSB0.</returns>
public static byte[] CalculateCRC(this byte[] message, int start, int length)
{
var test = default(byte);
var zeichen = default(byte);
var crcSum = ushort.MaxValue;
var messageLength = length - start;
var crc = 0xFFFF;
while (start < messageLength)
for (int i = 0; i < length; i++)
{
zeichen = message[start];
start++;
//copy data byte to lower word because of LSB will be XORed
var dataWord = (UInt16)(message[i] & 0x00FF);
for (byte h = 0; h < 8; h++)
for (var b = 0; b < 8; b++)
{
test = 0;
if ((crcSum & 0x8000) != 0)
//test if CRC lowest bit is XORed set to one
if (0x0001 == ((crc ^ dataWord) & 0x0001))
{
test = 0x80;
crc >>= 1;
//apply generator polynomial
crc ^= 0x8408;
}
else
{
crc >>= 1;
}
crcSum <<= 1;
if (((zeichen & 0x80) ^ test) != 0)
{
crcSum ^= 0x1021;
}
zeichen <<= 1;
dataWord >>= 1;
}
}
return BitConverter.GetBytes(crcSum);
//var test = default(byte);
//var zeichen = default(byte);
//var crcSum = ushort.MaxValue;
//var messageLength = length - start;
//while (start < messageLength)
//{
// zeichen = message[start];
// start++;
// for (byte h = 0; h < 8; h++)
// {
// test = 0;
// if ((crcSum & 0x8000) != 0)
// {
// test = 0x80;
// }
// crcSum <<= 1;
// if (((zeichen & 0x80) ^ test) != 0)
// {
// crcSum ^= 0x1021;
// }
// zeichen <<= 1;
// }
//}
return BitConverter.GetBytes(crc);
}
public static byte[] CalculateCheckSum16(this byte[] bytes, int length)
@@ -43,6 +43,7 @@
this.Write(irdaRequest);
#region Temporary
// TODO: remove for real connections
this.stream = new System.Collections.Concurrent.ConcurrentQueue<byte>(
new byte[] { 0xFF, 0x01, 0x25, 0x00, 0x80, 0x9B, 0x33, 0x04, 0x0D, 0x05, 0x08, 0x0C, 0xFF, 0x01, 0x25, 0x00, 0x80, 0x88 });
this.SerialPortConnection_Read();
@@ -0,0 +1,139 @@
namespace OmniPlus.Features.Enums
{
public enum PredefinedAlarms : byte
{
/// <summary>
/// Set when the unit is in a mode that is updating the firmware.
/// <para>
/// Trigger Condition: Alarm is set when the device begins to receive firmware image blocks.
/// It is marked as no longer occurring before executing the flasher app as the last part of a firmware upgrade.
/// Upon booting into the upgraded image, the alarm is in persistent state with start time associated with the reception of Load Start command
/// and stop time associated with the reception of Flash Start command.
/// If after loading the new image, the CRC fails, the Alarm condition is maintained until a Reset Firmware Image is received
/// or a new image is attempted to be loaded.
/// </para>
/// </summary>
UpgradeMode = 0x00,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// SevereHardwareFailure = 0x01,
/// <summary>
/// NV memory error alarm becomes active when an NV memory location fails a checksum check.
/// <para>
/// Alarm is triggered whenever a checksum check of any of the above modules and log entries fails.
/// </para>
/// </summary>
NVMemoryError = 0x02,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// DeadBattery = 0x03,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// EmptyPipe = 0x04,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// MagneticTamper = 0x05,
/// <summary>
/// Omni+ presently does not have the hardware capability to detect a cut or broken wire,
/// however the Alarm should be supported through the system so that once hardware is capable that no changes in the system have to be made to support the alarm.
/// <para>
/// Trigger Condition: Detection of a broken or cut wire going to the sensor.
/// </para>
/// </summary>
MeterDisconnectTamper = 0x06,
/// <summary>
/// Register has reached the end of its operational life.
/// <para>
/// Trigger Condition: For a 10 year battery device, Near End of Life alarm becomes active 10.5 years from date of manufacture or 9.5 years from Date of Activation whichever is less.
/// Alarm-specific additional data field indicates number of days remaining before meter reaches end-of-life. Alarm is updated once a day at midnight.
/// </para>
/// </summary>
NearEndOfLife = 0x07,
/// <summary>
/// NV memory error alarm becomes active when an NV memory location fails a checksum check.
/// <para>
/// Trigger Condition: For a 10 year battery device, End-of-life alarm becomes active 11 years from date of manufacture or 10 years from Date of Activation whichever is less.
/// Alarm-specific additional data field indicates number of days elapsed after meter reached end-of-life. Alarm is updated once a day at midnight.
/// </para>
/// </summary>
BeyondEndOfLife = 0x08,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// CommunicationsFailure = 0x09,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// CriticalHardwareWarning = 0x10,
/// <summary>
/// This is a one-shot alarm. Its start and stop time are the same. For that reason, this alarm is never reported as active. It persists for the persistence period.
/// <para>
/// Trigger Condition: Reboot alarm is triggered when the register has rebooted.
/// </para>
/// </summary>
Reboot = 0x11,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// EMFRange = 0x12,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// LowField = 0x13,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// HighCurrent = 0x14,
/// <summary>
/// Update Interval: Battery voltage is measured every 15 minutes
/// <para>
/// Trigger Condition: Battery low voltage alarm becomes active when the battery voltage is below 2.7 V for an 4 consecutive 15 sample periods.
/// </para>
/// </summary>
LowPrimaryBattery = 0x15,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// LowSecondaryBattery = 0x16,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// GlideSlope = 0x17,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// HighTemperature = 0x18,
/// <summary>
/// Reason for this alarm: uint32LE bitmap indicating which calibration factors/factory required parameters are missing:
/// Factory seal not set: bit 15 of the additional data.
/// <para>
/// Trigger Conditions: Configuration error alarm becomes active when factory seal is not set. Alarm is checked once an hour.
/// </para>
/// </summary>
ConfigError = 0x19,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// ActuatorFailure = 0x20,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// HumiditySensorRead = 0x21
}
}
@@ -0,0 +1,9 @@
namespace OmniPlus.Features.Enums
{
public enum StatusCodes : byte
{
CommandCompleted = 0x01,
UnableToExecute = 0x02,
Sealed = 0x05
}
}
@@ -0,0 +1,127 @@
namespace OmniPlus.Features.Enums
{
public enum UI1236Commands : byte
{
/// <summary>
/// Available after seal: Yes
/// </summary>
GetFactoryID = 0x01,
/// <summary>
/// Available after seal: No
/// </summary>
SetFactoryID = 0x02,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetProgrammableID = 0x03,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetProgrammableID = 0x04,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetVersionandType = 0x05,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetCustomerText = 0x07,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetCustomerText = 0x08,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetNumberofReadingDigits = 0x09,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetNumberofReadingDigits = 0x0A,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetReadingUnits = 0x0B,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetReadingUnits = 0x0C,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetRateUnits = 0x0D,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetRateUnits = 0x0E,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetReadingResolution = 0x0F,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetRateResolution = 0x11,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetReading = 0x13,
/// <summary>
/// Note1: Conditional
/// </summary>
SetReadingPreset = 0x14,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetReadingMode = 0x15,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetReadingMode = 0x16,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetBuildInformation = 0x17,
/// <summary>
/// Available after seal: No
/// </summary>
SetBuildInformation = 0x18,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetMetrologyAlarmSettings1F = 0x1F,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetMetrologyAlarmSettings = 0x20,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetMetrologyAlarmSettings21 = 0x21,
/// <summary>
/// Available after seal: Yes
/// </summary>
ClearMetrologyAlarms = 0x22,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetAlarmPersistencePeriod = 0x25,
/// <summary>
/// Available after seal: Yes
SetAlarmPersistencePeriod = 0x26,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetOptionalUniDirectionalFields = 0x27,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetOptionalUniDirectionalFields = 0x28,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetUniDirectionalString = 0x29
}
}
+3
View File
@@ -54,6 +54,9 @@
<Compile Include="Connection\SerialPortMessage.cs" />
<Compile Include="Connection\SerialPortOptions.cs" />
<Compile Include="Connection\Enums\DataBits.cs" />
<Compile Include="Features\Enums\StatusCodes.cs" />
<Compile Include="Features\Enums\PredefinedAlarms.cs" />
<Compile Include="Features\Enums\UI1236Commands.cs" />
<Compile Include="Messages\SystemParameters.cs" />
<Compile Include="Messages\FixedMessages.cs" />
<Compile Include="Messages\SetInputVolume.cs" />
+2
View File
@@ -24,6 +24,8 @@ namespace OmniPlus
this.uniProConnection?.Close();
this.irdaConnection?.Open();
this.messageHandler = this.irdaConnection.Write;
var bytes = this.messageHandler?.Invoke(new byte[] { 0xFD, 0xC6 }, 3000, 300);
}
public void ActivateUniPro()
-2
View File
@@ -6,8 +6,6 @@
{
var omniRegister = new OmniRegister("COM1");
omniRegister.ActivateIrda();
var systemParameters = omniRegister.GetSystemParameters();
}
}
}