eol. 2.8.2
This commit is contained in:
@@ -20,12 +20,12 @@
|
||||
public const byte LEN_IX = 8;
|
||||
public const byte DATA_IX = 9;
|
||||
|
||||
public static byte AKN_ANS = 0x12;
|
||||
public static byte FROM_AIR = 0x11;
|
||||
public const byte AKN_ANS = 0x12;
|
||||
public const byte FROM_AIR = 0x11;
|
||||
|
||||
public static byte LAT = 0x01;
|
||||
public static byte BUP = 0x00;
|
||||
public static byte DEBUG = 0x0B;
|
||||
public static byte SEMI = 0x08;
|
||||
public const byte LAT = 0x01;
|
||||
public const byte BUP = 0x00;
|
||||
public const byte DEBUG = 0x0B;
|
||||
public const byte SEMI = 0x08;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,13 +596,27 @@
|
||||
return value;
|
||||
}
|
||||
|
||||
public static ushort GetCrc(this byte[] bytes, int index)
|
||||
public static ushort GetCrc(this byte[] bytes, int index = -1)
|
||||
{
|
||||
var value = default(ushort);
|
||||
var _index = index;
|
||||
|
||||
value ^= (ushort)(bytes[_index++] << 8);
|
||||
value ^= bytes[_index];
|
||||
if (bytes != null)
|
||||
{
|
||||
var length = bytes.Length;
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
index = length - 2;
|
||||
}
|
||||
|
||||
var _index = index;
|
||||
|
||||
if (_index >= 0)
|
||||
{
|
||||
value ^= (ushort)(bytes[_index++] << 8);
|
||||
value ^= bytes[_index];
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -667,5 +681,88 @@
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
public static byte[] DecryptResponse(this byte[] encryptedData, byte[] encryptionKey)
|
||||
{
|
||||
if (encryptionKey?.Length != 16)
|
||||
{
|
||||
return encryptedData;
|
||||
}
|
||||
|
||||
var length = encryptedData?.Length ?? 0;
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
return encryptedData;
|
||||
}
|
||||
|
||||
var decryptedData = new byte[length];
|
||||
|
||||
Array.Copy(encryptedData, 0, decryptedData, 0, length);
|
||||
|
||||
var token = decryptedData[1];
|
||||
|
||||
for (var x = 6; x < length; x++)
|
||||
{
|
||||
token += (byte)(decryptedData[x - (token & 0x3) - 1] >> ((token >> 6) & 0x1));
|
||||
|
||||
decryptedData[x] ^= encryptionKey[(token >> 2) & 0x0F];
|
||||
|
||||
if (token >= 0x80)
|
||||
{
|
||||
decryptedData[x] = (byte)~decryptedData[x];
|
||||
}
|
||||
}
|
||||
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
public static byte[] EncryptRequest(this byte[] plainData, byte[] encryptionKey, uint address)
|
||||
{
|
||||
if (plainData?.Length <= 0 || encryptionKey?.Length != 16 || address <= 0)
|
||||
{
|
||||
return plainData;
|
||||
}
|
||||
|
||||
var dataLength = plainData.Length;
|
||||
var telegramLength = dataLength + 2;
|
||||
var encryptedData = new byte[telegramLength];
|
||||
|
||||
Array.Copy(plainData, 0, encryptedData, 0, dataLength);
|
||||
|
||||
var telegramForCRCLength = telegramLength + 4;
|
||||
var telegramForCRC = new byte[telegramForCRCLength];
|
||||
|
||||
telegramForCRC[0] = (byte)(address >> 24);
|
||||
telegramForCRC[1] = (byte)(address >> 16);
|
||||
telegramForCRC[2] = (byte)(address >> 8);
|
||||
telegramForCRC[3] = (byte)(address >> 0);
|
||||
|
||||
Array.Copy(encryptedData, 0, telegramForCRC, 4, telegramLength);
|
||||
|
||||
var telegramCRC = telegramForCRC.CRCCCITT(1, telegramForCRCLength - 2);
|
||||
encryptedData[telegramLength - 2] = (byte)(telegramCRC >> 8);
|
||||
encryptedData[telegramLength - 1] = (byte)(telegramCRC >> 0);
|
||||
|
||||
var reference = address;
|
||||
var token = (byte)0xFF;
|
||||
|
||||
for (var i = 0; i < telegramLength; i++)
|
||||
{
|
||||
token += (byte)(((reference >> ((token & 0x3) << 3)) & 0xFF) >> ((token >> 6) & 1));
|
||||
|
||||
reference <<= 8;
|
||||
reference += encryptedData[i];
|
||||
|
||||
encryptedData[i] ^= encryptionKey[(token >> 2) & 0x0F];
|
||||
|
||||
if (token >= 0x80)
|
||||
{
|
||||
encryptedData[i] = (byte)~encryptedData[i];
|
||||
}
|
||||
}
|
||||
|
||||
return encryptedData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,13 +97,8 @@
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
var crc = this.bytes.CRCCCITT(1, this.bytes.Length - 3);
|
||||
|
||||
if (this.Direction == PC_SIRT)
|
||||
{
|
||||
this.Crc = crc;
|
||||
this.End = MSG_END;
|
||||
}
|
||||
this.Crc = this.bytes.CRCCCITT(1, this.bytes.Length - 3);
|
||||
this.End = MSG_END;
|
||||
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
@@ -7,11 +7,32 @@
|
||||
public class WritePamTask : SIRTTask
|
||||
{
|
||||
protected P811 p811;
|
||||
private event Action<SIRTMessage> AKNReceived;
|
||||
private event Action<SIRTMessage> BUPReceived;
|
||||
private event Action<SIRTMessage> LATReceived;
|
||||
private event Action<SIRTMessage> DEBUGReceived;
|
||||
private event Action<SIRTMessage> SEMIReceived;
|
||||
private event Action<SIRTMessage> UnknownReceived;
|
||||
|
||||
public bool IsEncrypted { get; set; }
|
||||
|
||||
public byte[] EncryptionKey { get; set; }
|
||||
|
||||
public WritePamTask()
|
||||
{
|
||||
this.request.Command = SIRTConstants.W_PAM;
|
||||
this.p811 = this.request.P1;
|
||||
this.AKNReceived += OnAKNReceived;
|
||||
//this.BUPReceived += OnBUPReceived;
|
||||
//this.LATReceived += OnLATReceived;
|
||||
//this.DEBUGReceived += OnDEBUGReceived;
|
||||
//this.SEMIReceived += OnSEMIReceived;
|
||||
//this.UnknownReceived += OnUnknownReceived;
|
||||
}
|
||||
|
||||
protected virtual void OnAKNReceived(SIRTMessage akn)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool WakeUpModul
|
||||
@@ -62,19 +83,95 @@
|
||||
set => this.request.Payload = value;
|
||||
}
|
||||
|
||||
public bool AnyTelegramReceived { get; protected set; }
|
||||
|
||||
public override void Push(SIRTMessage response)
|
||||
{
|
||||
if (response.Command == SIRTConstants.AKN_ANS)
|
||||
{
|
||||
this.AKNReceived?.Invoke(response);
|
||||
}
|
||||
else if (response.Command == SIRTConstants.FROM_AIR)
|
||||
{
|
||||
var payload = response.Payload;
|
||||
|
||||
if (payload != null && payload.Length > 0)
|
||||
{
|
||||
var type = payload[0];
|
||||
var crc = payload.GetCrc();
|
||||
|
||||
this.IsEncrypted = crc != default(ushort);
|
||||
|
||||
if (this.IsEncrypted)
|
||||
{
|
||||
response.Payload = payload.DecryptResponse(this.EncryptionKey);
|
||||
}
|
||||
|
||||
if (type == SIRTConstants.BUP)
|
||||
{
|
||||
this.BUPReceived?.Invoke(response);
|
||||
}
|
||||
else if (type == SIRTConstants.LAT)
|
||||
{
|
||||
this.LATReceived?.Invoke(response);
|
||||
}
|
||||
else if (type == SIRTConstants.DEBUG)
|
||||
{
|
||||
this.DEBUGReceived?.Invoke(response);
|
||||
}
|
||||
else if (type == SIRTConstants.SEMI)
|
||||
{
|
||||
this.SEMIReceived?.Invoke(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.UnknownReceived?.Invoke(response);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.UnknownReceived?.Invoke(response);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.UnknownReceived?.Invoke(response);
|
||||
}
|
||||
}
|
||||
|
||||
public override byte[] Start()
|
||||
{
|
||||
var requestPayload = this.request.Payload;
|
||||
var payloadLength = requestPayload.Length;
|
||||
var payload = new byte[payloadLength];
|
||||
|
||||
Array.Copy(requestPayload, 0, payload, 0, payloadLength);
|
||||
|
||||
if (this.IsEncrypted)
|
||||
{
|
||||
payload = payload.EncryptRequest(this.EncryptionKey, this.RequestAddress);
|
||||
}
|
||||
|
||||
this.SetRunning();
|
||||
|
||||
return new SIRTMessage
|
||||
{
|
||||
Direction = this.request.Direction,
|
||||
Command = this.request.Command,
|
||||
P1 = this.request.P1,
|
||||
P2 = this.request.P2,
|
||||
Address = this.request.Address,
|
||||
Payload = payload,
|
||||
Frequency = this.Frequency,
|
||||
|
||||
}.GetBytes();
|
||||
}
|
||||
|
||||
private void SetP811(Action<P811> p811Setter)
|
||||
{
|
||||
p811Setter.Invoke(this.p811);
|
||||
|
||||
this.request.P1 = this.p811;
|
||||
}
|
||||
|
||||
public override void Push(SIRTMessage response)
|
||||
{
|
||||
if (response.Length > 0 && response.Payload[0] == SIRTConstants.SEMI)
|
||||
{
|
||||
this.SetCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-7
@@ -118,11 +118,13 @@
|
||||
if (task.ErrorMessage != null)
|
||||
{
|
||||
var error = task.ErrorMessage;
|
||||
var result = MessageBox.Show(error.Text + $"{Environment.NewLine}{Environment.NewLine}Möchten Sie fortfahren?", error.Title, MessageBoxButtons.YesNo);
|
||||
var message = $"{error.Text}{Environment.NewLine}{Environment.NewLine}Möchten Sie fortfahren?";
|
||||
var result = MessageBox.Show(message, error.Title, MessageBoxButtons.YesNo);
|
||||
|
||||
if (result == DialogResult.No)
|
||||
{
|
||||
task.SetCancelled();
|
||||
|
||||
stopProgramming = true;
|
||||
|
||||
break;
|
||||
@@ -132,18 +134,18 @@
|
||||
|
||||
task.MessageReceived -= this.history.Push;
|
||||
|
||||
if (stopProgramming)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (task.FactoryState == FactoryState.Shipment && !this.runningTasks.IsEmpty)
|
||||
if (task.FactoryState == FactoryState.Shipment)
|
||||
{
|
||||
task.Label = "GESCHLOSSEN";
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (stopProgramming)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
this.UpdateTasksStateInTheQueue(task);
|
||||
|
||||
if (task.State == SIRTTaskState.Completed)
|
||||
@@ -230,6 +232,7 @@
|
||||
SerialNr = features.SerialNr,
|
||||
DelPamTx = true,
|
||||
WakeUpCmd = true,
|
||||
WakeUpModul = true,
|
||||
RequestAddress = features.RequestAddress,
|
||||
ResponseAddress = features.ResponseAddress,
|
||||
EncryptionKey = features.EncryptionKey,
|
||||
|
||||
+11
-4
@@ -33,6 +33,7 @@
|
||||
if (this.State == SIRTTaskState.Completed)
|
||||
{
|
||||
this.ErrorMessage = default(ErrorMessage);
|
||||
var hasValidConfiguration = true;
|
||||
var message = new StringBuilder();
|
||||
message.AppendLine();
|
||||
message.AppendLine();
|
||||
@@ -47,12 +48,14 @@
|
||||
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Das Rechenwerk ist um {over:0.0000} Tage älter als erlaubt. Bitte informieren Sie die Linienleitung und QS.");
|
||||
hasValidConfiguration = false;
|
||||
}
|
||||
|
||||
if (this.SEMIMessage.BatteryRemainingYears <= this.parameters.MinBatteryRemainingYears)
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Die Batterielaufzeit ({this.SEMIMessage.BatteryRemainingYears}) liegt unter dem angegebenen Minimum von ({this.parameters.MinBatteryRemainingYears}). ");
|
||||
message.AppendLine($"- Die Batterielaufzeit ({this.SEMIMessage.BatteryRemainingYears}) liegt unter dem angegebenen Minimum von ({this.parameters.MinBatteryRemainingYears}).");
|
||||
hasValidConfiguration = false;
|
||||
}
|
||||
|
||||
// Min metrology FW version (>= 1108) CSD dependent
|
||||
@@ -67,6 +70,7 @@
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Die Metrologische FW Version ({curFW}) liegt unter dem angegebenen Minimum von ({minFW}).");
|
||||
hasValidConfiguration = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,12 +81,14 @@
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Die Metrologische FW Version ({this.DEBUGMessage.MetrologyFWVersion}) ist nicht für Produktion freigegeben. ");
|
||||
hasValidConfiguration = false;
|
||||
}
|
||||
|
||||
if (!this.parameters.FWVersionsList.Contains(this.DEBUGMessage.RadioFWVersion))
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Die Radio FW Version ({this.DEBUGMessage.RadioFWVersion}) ist nicht für Produktion freigegeben. ");
|
||||
hasValidConfiguration = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,16 +96,17 @@
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Der rechenwerk wurde mehr als {this.parameters.MaxRebootCount} mal rebooted.");
|
||||
hasValidConfiguration = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (message.Length > 10)
|
||||
if (!hasValidConfiguration)
|
||||
{
|
||||
message.Insert(0, $"Am Einbauplatz: {this.SlotNr}, "
|
||||
+ $"eingebaute E-Register mit Funkadressen: {this.RequestAddress} | {this.ResponseAddress}, "
|
||||
+ $"sind folgenden Fehler sind aufgetreten:");
|
||||
+ $"sind folgenden Fehler aufgetreten:");
|
||||
message.AppendLine();
|
||||
message.AppendLine("Linienleitung informieren!");
|
||||
message.AppendLine("Linienleitung und QS informieren!");
|
||||
|
||||
this.ErrorMessage = new ErrorMessage
|
||||
{
|
||||
|
||||
+5
-11
@@ -66,12 +66,6 @@
|
||||
|
||||
public SEMI SEMIMessage { get; protected set; }
|
||||
|
||||
public bool AnyTelegramReceived { get; private set; }
|
||||
|
||||
public bool IsEncrypted { get; set; }
|
||||
|
||||
public byte[] EncryptionKey { get; set; }
|
||||
|
||||
public FactoryState FactoryState { get; set; }
|
||||
|
||||
public int? RadioFWVersion { get; set; }
|
||||
@@ -204,14 +198,14 @@
|
||||
|
||||
if (pamStatus == PAMStatus.OK)
|
||||
{
|
||||
if (this.request.Length > 0 && this.request.Payload[0] == Pam.GetDebug && this.DEBUGMessage == null)
|
||||
{
|
||||
this.Label = "!DEBUG";
|
||||
}
|
||||
else if (this.LATMessage is null)
|
||||
if (this.LATMessage is null)
|
||||
{
|
||||
this.Label = "!LAT";
|
||||
}
|
||||
else if (this.request.Length > 0 && this.request.Payload[0] == Pam.GetDebug && this.DEBUGMessage == null)
|
||||
{
|
||||
this.Label = "!DEBUG";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SetCompleted();
|
||||
|
||||
+2
@@ -83,5 +83,7 @@
|
||||
|
||||
return alarmMaskBuilder.ToString().Trim();
|
||||
}
|
||||
|
||||
public static implicit operator byte(AlarmsMask alarmMask) => alarmMask.bits.GetByteLE();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-36
@@ -19,14 +19,14 @@
|
||||
{
|
||||
cmd = bytes[cmdIX];
|
||||
_ = cmdLengths.TryGetValue(cmd, out cmdLength);
|
||||
_ = cmdAvailableAfterSeal.TryGetValue(cmd, out available);
|
||||
available = !cmdUnavailableAfterSeal.ContainsKey(cmd);
|
||||
|
||||
if (cmd == Pam.SetPowerLevel && bytes[cmdIX + 1] > 127)
|
||||
{
|
||||
available = false;
|
||||
}
|
||||
|
||||
if (available)
|
||||
if (cmd == Pam.ProvidePin || available)
|
||||
{
|
||||
index = cmdIX + 1;
|
||||
|
||||
@@ -49,46 +49,13 @@
|
||||
|
||||
public static implicit operator byte[] (EregisterAvailableParametersParser parser) => parser.ToArray();
|
||||
|
||||
private static readonly IDictionary<byte, bool> cmdAvailableAfterSeal = new Dictionary<byte, bool>
|
||||
private static readonly IDictionary<byte, bool> cmdUnavailableAfterSeal = new Dictionary<byte, bool>
|
||||
{
|
||||
{ 0, true },
|
||||
{ 1, false },
|
||||
{ 2, true },
|
||||
{ 3, false },
|
||||
{ 4, true },
|
||||
{ 5, true },
|
||||
{ 6, true },
|
||||
{ 7, true },
|
||||
{ 10, true },
|
||||
{ 11, true },
|
||||
{ 12, false },
|
||||
{ 14, true },
|
||||
{ 16, true },
|
||||
{ 17, true },
|
||||
{ 19, true },
|
||||
{ 20, true },
|
||||
{ 21, true },
|
||||
{ 22, false },
|
||||
{ 31, true },
|
||||
{ 32, true },
|
||||
{ 33, true },
|
||||
{ 48, false },
|
||||
{ 49, false },
|
||||
{ 50, false },
|
||||
{ 51, true },
|
||||
{ 52, true },
|
||||
{ 53, true },
|
||||
{ 54, false },
|
||||
{ 64, true },
|
||||
{ 65, true },
|
||||
{ 66, true },
|
||||
{ 67, true },
|
||||
{ 68, true },
|
||||
{ 69, true },
|
||||
{ 72, true },
|
||||
{ 73, true },
|
||||
{ 80, true },
|
||||
{ 108, true },
|
||||
{ 146, false },
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user