void IGXDLMSBase.Load(GXXmlReader reader) { ImageBlockSize = (UInt32)reader.ReadElementContentAsInt("ImageBlockSize"); ImageTransferredBlocksStatus = reader.ReadElementContentAsString("ImageTransferredBlocksStatus"); ImageFirstNotTransferredBlockNumber = reader.ReadElementContentAsLong("ImageFirstNotTransferredBlockNumber"); ImageTransferEnabled = reader.ReadElementContentAsInt("ImageTransferEnabled") != 0; ImageTransferStatus = (ImageTransferStatus)reader.ReadElementContentAsInt("ImageTransferStatus"); List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>(); if (reader.IsStartElement("ImageActivateInfo", true)) { while (reader.IsStartElement("Item", true)) { GXDLMSImageActivateInfo it = new GXDLMSImageActivateInfo(); it.Size = reader.ReadElementContentAsULong("Size"); it.Identification = GXCommon.HexToBytes(reader.ReadElementContentAsString("Identification")); it.Signature = GXCommon.HexToBytes(reader.ReadElementContentAsString("Signature")); list.Add(it); } reader.ReadEndElement("ImageActivateInfo"); } ImageActivateInfo = list.ToArray(); }
private void SetImageActivateInfo(object value) { ImageActivateInfo = null; List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>(); if (value != null) { foreach (object tmp in (IEnumerable <object>)value) { List <object> it; if (tmp is List <object> ) { it = (List <object>)tmp; } else { it = new List <object>((object[])tmp); } GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); item.Size = Convert.ToUInt32(it[0]); item.Identification = (byte[])it[1]; item.Signature = (byte[])it[2]; list.Add(item); } } ImageActivateInfo = list.ToArray(); }
void IGXDLMSBase.SetValue(int index, object value) { if (index == 1) { if (value is string) { LogicalName = value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString(); } } else if (index == 2) { ImageBlockSize = Convert.ToUInt32(value); } else if (index == 3) { ImageTransferredBlocksStatus = (string)value; } else if (index == 4) { ImageFirstNotTransferredBlockNumber = Convert.ToUInt32(value); } else if (index == 5) { ImageTransferEnabled = Convert.ToBoolean(value); } else if (index == 6) { ImageTransferStatus = (ImageTransferStatus)Convert.ToUInt32(value); } else if (index == 7) { ImageActivateInfo = null; List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>(); if (value != null) { foreach (Object it in (Object[])value) { GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); Object[] tmp = (Object[])it; item.Size = Convert.ToUInt32(tmp[0]); item.Identification = ASCIIEncoding.ASCII.GetString((byte[])tmp[1]); item.Signature = ASCIIEncoding.ASCII.GetString((byte[])tmp[2]); list.Add(item); } } ImageActivateInfo = list.ToArray(); } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { if (e.Value is string) { LogicalName = e.Value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString(); } } else if (e.Index == 2) { ImageBlockSize = Convert.ToUInt32(e.Value); } else if (e.Index == 3) { ImageTransferredBlocksStatus = (string)e.Value; } else if (e.Index == 4) { ImageFirstNotTransferredBlockNumber = Convert.ToUInt32(e.Value); } else if (e.Index == 5) { ImageTransferEnabled = Convert.ToBoolean(e.Value); } else if (e.Index == 6) { ImageTransferStatus = (ImageTransferStatus)Convert.ToUInt32(e.Value); } else if (e.Index == 7) { ImageActivateInfo = null; List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>(); if (e.Value != null) { foreach (Object it in (Object[])e.Value) { GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); Object[] tmp = (Object[])it; item.Size = Convert.ToUInt32(tmp[0]); item.Identification = ASCIIEncoding.ASCII.GetString((byte[])tmp[1]); item.Signature = ASCIIEncoding.ASCII.GetString((byte[])tmp[2]); list.Add(item); } } ImageActivateInfo = list.ToArray(); } else { e.Error = ErrorCode.ReadWriteDenied; } }
/// <summary> /// Constructor. /// </summary> /// <param name="ln">Logical Name of the object.</param> public GXDLMSImageTransfer(string ln) : base(ObjectType.ImageTransfer, ln, 0) { ImageBlockSize = 200; ImageFirstNotTransferredBlockNumber = 0; ImageTransferEnabled = true; GXDLMSImageActivateInfo info = new GXDLMSImageActivateInfo(); info.Size = 0; info.Signature = ""; info.Identification = ""; ImageActivateInfo = new GXDLMSImageActivateInfo[] { info }; }
/// <summary> /// Constructor. /// </summary> /// <param name="ln">Logical Name of the object.</param> /// <param name="sn">Short Name of the object.</param> public GXDLMSImageTransfer(string ln, ushort sn) : base(ObjectType.ImageTransfer, ln, 0) { ImageBlockSize = 200; ImageFirstNotTransferredBlockNumber = 0; ImageTransferEnabled = true; GXDLMSImageActivateInfo info = new GXDLMSImageActivateInfo(); info.Size = 0; info.Signature = ""; info.Identification = ""; ImageActivateInfo = new GXDLMSImageActivateInfo[] { info }; }
private void SetImageActivateInfo(object value) { ImageActivateInfo = null; List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>(); if (value != null) { foreach (List <object> it in (List <object>)value) { GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); item.Size = Convert.ToUInt32(it[0]); item.Identification = (byte[])it[1]; item.Signature = (byte[])it[2]; list.Add(item); } } ImageActivateInfo = list.ToArray(); }
private void SetImageActivateInfo(object value) { ImageActivateInfo = null; List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>(); if (value != null) { foreach (Object it in (Object[])value) { GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); Object[] tmp = (Object[])it; item.Size = Convert.ToUInt32(tmp[0]); item.Identification = ASCIIEncoding.ASCII.GetString((byte[])tmp[1]); item.Signature = ASCIIEncoding.ASCII.GetString((byte[])tmp[2]); list.Add(item); } } ImageActivateInfo = list.ToArray(); }
/// <summary> /// Data interface do not have any methods. /// </summary> /// <param name="index"></param> byte[][] IGXDLMSBase.Invoke(object sender, int index, Object parameters) { ImageTransferStatus = ImageTransferStatus.NotInitiated; GXDLMSServerBase s = sender as GXDLMSServerBase; //Image transfer initiate if (index == 1) { ImageFirstNotTransferredBlockNumber = 0; ImageTransferredBlocksStatus = ""; object[] value = (object[])parameters; string ImageIdentifier = ASCIIEncoding.ASCII.GetString((byte[])value[0]); ImageSize = (UInt32)value[1]; ImageTransferStatus = ImageTransferStatus.TransferInitiated; List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>(ImageActivateInfo); GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); item.Size = ImageSize; item.Identification = ImageIdentifier; list.Add(item); ImageActivateInfo = list.ToArray(); StringBuilder sb = new StringBuilder((int)ImageSize); for (uint pos = 0; pos < ImageSize; ++pos) { sb.Append('0'); } ImageTransferredBlocksStatus = sb.ToString(); return(s.Acknowledge(Command.MethodResponse, 0)); } //Image block transfer else if (index == 2) { object[] value = (object[])parameters; uint imageIndex = (uint)value[0]; char[] tmp = ImageTransferredBlocksStatus.ToCharArray(); tmp[(int)imageIndex] = '1'; ImageTransferredBlocksStatus = new string(tmp); ImageFirstNotTransferredBlockNumber = imageIndex + 1; ImageData[imageIndex] = (byte[])value[1]; ImageTransferStatus = ImageTransferStatus.TransferInitiated; return(s.Acknowledge(Command.MethodResponse, 0)); } //Image verify else if (index == 3) { ImageTransferStatus = ImageTransferStatus.VerificationInitiated; //Check that size match. int size = 0; foreach (KeyValuePair <uint, byte[]> it in ImageData) { size += it.Value.Length; } if (size != ImageSize) { //Return HW error. ImageTransferStatus = ImageTransferStatus.VerificationFailed; throw new Exception("Invalid image size."); } ImageTransferStatus = ImageTransferStatus.VerificationSuccessful; return(s.Acknowledge(Command.MethodResponse, 0)); } //Image activate. else if (index == 4) { ImageTransferStatus = ImageTransferStatus.ActivationSuccessful; return(s.Acknowledge(Command.MethodResponse, 0)); } else { throw new ArgumentException("Invoke failed. Invalid attribute index."); } }
byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e) { //Image transfer initiate if (e.Index == 1) { ImageFirstNotTransferredBlockNumber = 0; ImageTransferredBlocksStatus = ""; object[] value = (object[])e.Parameters; byte[] imageIdentifier = (byte[])value[0]; ImageSize = (UInt32)value[1]; ImageTransferStatus = ImageTransferStatus.TransferInitiated; List <GXDLMSImageActivateInfo> list; if (ImageActivateInfo == null) { list = new List <GXDLMSImageActivateInfo>(); } else { list = new List <GXDLMSImageActivateInfo>(ImageActivateInfo); } GXDLMSImageActivateInfo item = null; foreach (GXDLMSImageActivateInfo it in list) { if (it.Identification == imageIdentifier) { item = it; break; } } if (item == null) { item = new Objects.GXDLMSImageActivateInfo(); list.Add(item); } item.Size = ImageSize; item.Identification = imageIdentifier; ImageActivateInfo = list.ToArray(); int cnt = (int)Math.Ceiling((double)ImageSize / ImageBlockSize); StringBuilder sb = new StringBuilder(cnt); for (uint pos = 0; pos < cnt; ++pos) { sb.Append('0'); } ImageTransferredBlocksStatus = sb.ToString(); return(null); } //Image block transfer else if (e.Index == 2) { object[] value = (object[])e.Parameters; uint imageIndex = (uint)value[0]; char[] tmp = ImageTransferredBlocksStatus.ToCharArray(); tmp[(int)imageIndex] = '1'; ImageTransferredBlocksStatus = new string(tmp); ImageFirstNotTransferredBlockNumber = imageIndex + 1; ImageTransferStatus = ImageTransferStatus.TransferInitiated; return(null); } //Image verify else if (e.Index == 3) { return(null); } //Image activate. else if (e.Index == 4) { return(null); } else { e.Error = ErrorCode.ReadWriteDenied; return(null); } }
void IGXDLMSBase.SetValue(int index, object value) { if (index == 1) { if (value is string) { LogicalName = value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString(); } } else if (index == 2) { ImageBlockSize = Convert.ToUInt32(value); } else if (index == 3) { ImageTransferredBlocksStatus = (string)value; } else if (index == 4) { ImageFirstNotTransferredBlockNumber = Convert.ToUInt32(value); } else if (index == 5) { ImageTransferEnabled = Convert.ToBoolean(value); } else if (index == 6) { ImageTransferStatus = (ImageTransferStatus)Convert.ToUInt32(value); } else if (index == 7) { ImageActivateInfo = null; List<GXDLMSImageActivateInfo> list = new List<GXDLMSImageActivateInfo>(); if (value != null) { foreach (Object it in (Object[])value) { GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); Object[] tmp = (Object[])it; item.Size = Convert.ToUInt32(tmp[0]); item.Identification = ASCIIEncoding.ASCII.GetString((byte[])tmp[1]); item.Signature = ASCIIEncoding.ASCII.GetString((byte[])tmp[2]); list.Add(item); } } ImageActivateInfo = list.ToArray(); } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
/// <summary> /// Data interface do not have any methods. /// </summary> /// <param name="index"></param> byte[][] IGXDLMSBase.Invoke(object sender, int index, Object parameters) { ImageTransferStatus = ImageTransferStatus.NotInitiated; GXDLMSServerBase s = sender as GXDLMSServerBase; //Image transfer initiate if (index == 1) { ImageFirstNotTransferredBlockNumber = 0; ImageTransferredBlocksStatus = ""; object[] value = (object[]) parameters; string ImageIdentifier = ASCIIEncoding.ASCII.GetString((byte[]) value[0]); ImageSize = (UInt32)value[1]; ImageTransferStatus = ImageTransferStatus.TransferInitiated; List<GXDLMSImageActivateInfo> list = new List<GXDLMSImageActivateInfo>(ImageActivateInfo); GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); item.Size = ImageSize; item.Identification = ImageIdentifier; list.Add(item); ImageActivateInfo = list.ToArray(); StringBuilder sb = new StringBuilder((int) ImageSize); for (uint pos = 0; pos < ImageSize; ++pos) { sb.Append('0'); } ImageTransferredBlocksStatus = sb.ToString(); return s.Acknowledge(Command.MethodResponse, 0); } //Image block transfer else if (index == 2) { object[] value = (object[])parameters; uint imageIndex = (uint)value[0]; char[] tmp = ImageTransferredBlocksStatus.ToCharArray(); tmp[(int)imageIndex] = '1'; ImageTransferredBlocksStatus = new string(tmp); ImageFirstNotTransferredBlockNumber = imageIndex + 1; ImageData[imageIndex] = (byte[])value[1]; ImageTransferStatus = ImageTransferStatus.TransferInitiated; return s.Acknowledge(Command.MethodResponse, 0); } //Image verify else if (index == 3) { ImageTransferStatus = ImageTransferStatus.VerificationInitiated; //Check that size match. int size = 0; foreach (KeyValuePair<uint, byte[]> it in ImageData) { size += it.Value.Length; } if (size != ImageSize) { //Return HW error. ImageTransferStatus = ImageTransferStatus.VerificationFailed; throw new Exception("Invalid image size."); } ImageTransferStatus = ImageTransferStatus.VerificationSuccessful; return s.Acknowledge(Command.MethodResponse, 0); } //Image activate. else if (index == 4) { ImageTransferStatus = ImageTransferStatus.ActivationSuccessful; return s.Acknowledge(Command.MethodResponse, 0); } else { throw new ArgumentException("Invoke failed. Invalid attribute index."); } }
byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e) { ImageTransferStatus = ImageTransferStatus.NotInitiated; //Image transfer initiate if (e.Index == 1) { ImageFirstNotTransferredBlockNumber = 0; ImageTransferredBlocksStatus = ""; object[] value = (object[])e.Parameters; string ImageIdentifier = ASCIIEncoding.ASCII.GetString((byte[])value[0]); ImageSize = (UInt32)value[1]; ImageTransferStatus = ImageTransferStatus.TransferInitiated; List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>(ImageActivateInfo); GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); item.Size = ImageSize; item.Identification = ImageIdentifier; list.Add(item); ImageActivateInfo = list.ToArray(); StringBuilder sb = new StringBuilder((int)ImageSize); for (uint pos = 0; pos < ImageSize; ++pos) { sb.Append('0'); } ImageTransferredBlocksStatus = sb.ToString(); return(new byte[] { 0 }); } //Image block transfer else if (e.Index == 2) { object[] value = (object[])e.Parameters; uint imageIndex = (uint)value[0]; char[] tmp = ImageTransferredBlocksStatus.ToCharArray(); tmp[(int)imageIndex] = '1'; ImageTransferredBlocksStatus = new string(tmp); ImageFirstNotTransferredBlockNumber = imageIndex + 1; ImageData[imageIndex] = (byte[])value[1]; ImageTransferStatus = ImageTransferStatus.TransferInitiated; return(new byte[] { 0 }); } //Image verify else if (e.Index == 3) { ImageTransferStatus = ImageTransferStatus.VerificationInitiated; //Check that size match. int size = 0; foreach (KeyValuePair <uint, byte[]> it in ImageData) { size += it.Value.Length; } if (size != ImageSize) { //Return HW error. ImageTransferStatus = ImageTransferStatus.VerificationFailed; throw new Exception("Invalid image size."); } ImageTransferStatus = ImageTransferStatus.VerificationSuccessful; return(new byte[] { 0 }); } //Image activate. else if (e.Index == 4) { ImageTransferStatus = ImageTransferStatus.ActivationSuccessful; return(new byte[] { 0 }); } else { e.Error = ErrorCode.ReadWriteDenied; return(null); } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { if (e.Value is string) { LogicalName = e.Value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString(); } } else if (e.Index == 2) { ImageBlockSize = Convert.ToUInt32(e.Value); } else if (e.Index == 3) { ImageTransferredBlocksStatus = (string)e.Value; } else if (e.Index == 4) { ImageFirstNotTransferredBlockNumber = Convert.ToUInt32(e.Value); } else if (e.Index == 5) { ImageTransferEnabled = Convert.ToBoolean(e.Value); } else if (e.Index == 6) { ImageTransferStatus = (ImageTransferStatus)Convert.ToUInt32(e.Value); } else if (e.Index == 7) { ImageActivateInfo = null; List<GXDLMSImageActivateInfo> list = new List<GXDLMSImageActivateInfo>(); if (e.Value != null) { foreach (Object it in (Object[])e.Value) { GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); Object[] tmp = (Object[])it; item.Size = Convert.ToUInt32(tmp[0]); item.Identification = ASCIIEncoding.ASCII.GetString((byte[])tmp[1]); item.Signature = ASCIIEncoding.ASCII.GetString((byte[])tmp[2]); list.Add(item); } } ImageActivateInfo = list.ToArray(); } else { e.Error = ErrorCode.ReadWriteDenied; } }
byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e) { ImageTransferStatus = ImageTransferStatus.NotInitiated; //Image transfer initiate if (e.Index == 1) { ImageFirstNotTransferredBlockNumber = 0; ImageTransferredBlocksStatus = ""; object[] value = (object[])e.Parameters; string ImageIdentifier = ASCIIEncoding.ASCII.GetString((byte[])value[0]); ImageSize = (UInt32)value[1]; ImageTransferStatus = ImageTransferStatus.TransferInitiated; List<GXDLMSImageActivateInfo> list = new List<GXDLMSImageActivateInfo>(ImageActivateInfo); GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo(); item.Size = ImageSize; item.Identification = ImageIdentifier; list.Add(item); ImageActivateInfo = list.ToArray(); StringBuilder sb = new StringBuilder((int)ImageSize); for (uint pos = 0; pos < ImageSize; ++pos) { sb.Append('0'); } ImageTransferredBlocksStatus = sb.ToString(); return new byte[] { 0 }; } //Image block transfer else if (e.Index == 2) { object[] value = (object[])e.Parameters; uint imageIndex = (uint)value[0]; char[] tmp = ImageTransferredBlocksStatus.ToCharArray(); tmp[(int)imageIndex] = '1'; ImageTransferredBlocksStatus = new string(tmp); ImageFirstNotTransferredBlockNumber = imageIndex + 1; ImageData[imageIndex] = (byte[])value[1]; ImageTransferStatus = ImageTransferStatus.TransferInitiated; return new byte[] { 0 }; } //Image verify else if (e.Index == 3) { ImageTransferStatus = ImageTransferStatus.VerificationInitiated; //Check that size match. int size = 0; foreach (KeyValuePair<uint, byte[]> it in ImageData) { size += it.Value.Length; } if (size != ImageSize) { //Return HW error. ImageTransferStatus = ImageTransferStatus.VerificationFailed; throw new Exception("Invalid image size."); } ImageTransferStatus = ImageTransferStatus.VerificationSuccessful; return new byte[] { 0 }; } //Image activate. else if (e.Index == 4) { ImageTransferStatus = ImageTransferStatus.ActivationSuccessful; return new byte[] { 0 }; } else { e.Error = ErrorCode.ReadWriteDenied; return null; } }