Ejemplo n.º 1
0
        /// <summary>
        /// Add entry to entries list.
        /// </summary>
        /// <param name="client">DLMS client.</param>
        /// <param name="entry">Schedule entry.</param>
        /// <returns>Action bytes.</returns>
        public byte[][] Insert(GXDLMSClient client, GXScheduleEntry entry)
        {
            GXByteBuffer data = new GXByteBuffer();

            AddEntry(client.Settings, entry, data);
            return(client.Method(this, 2, data.Array(), DataType.Structure));
        }
Ejemplo n.º 2
0
        public byte[][] ImageBlockTransfer(GXDLMSClient client, byte[] imageBlockValue, out int ImageBlockCount)
        {
            ImageBlockCount = (int)(imageBlockValue.Length / ImageBlockSize);
            if (imageBlockValue.Length % ImageBlockSize != 0)
            {
                ++ImageBlockCount;
            }
            List <byte[]> packets = new List <byte[]>();

            for (int pos = 0; pos != ImageBlockCount; ++pos)
            {
                List <byte> data = new List <byte>();
                data.Add((byte)DataType.Structure);
                data.Add((byte)2);
                GXCommon.SetData(data, DataType.UInt32, pos);
                byte[] tmp;
                int    bytes = (int)(imageBlockValue.Length - ((pos + 1) * ImageBlockSize));
                //If last packet
                if (bytes < 0)
                {
                    bytes = (int)(imageBlockValue.Length - (pos * ImageBlockSize));
                    tmp   = new byte[bytes];
                    Array.Copy(imageBlockValue, pos * ImageBlockSize, tmp, 0, bytes);
                }
                else
                {
                    tmp = new byte[ImageBlockSize];
                    Array.Copy(imageBlockValue, (pos * ImageBlockSize), tmp, 0, ImageBlockSize);
                }
                GXCommon.SetData(data, DataType.OctetString, tmp);
                packets.AddRange(client.Method(this, 2, data.ToArray(), DataType.Array));
            }
            return(packets.ToArray());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Shifts the time by n (-900 &lt;= n &lt;= 900) s.
 /// </summary>
 /// <param name="time"></param>
 /// <returns></returns>
 public byte[][] ShiftTime(GXDLMSClient client, int time)
 {
     if (time < -900 || time > 900)
     {
         throw new ArgumentOutOfRangeException("Invalid shift time.");
     }
     return(client.Method(this, 6, time, DataType.Int16));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Add new register.
        /// </summary>
        /// <param name="client">DLMS client.</param>
        /// <param name="script">Register to add.</param>
        /// <returns>Action bytes.</returns>
        public byte[][] AddRegister(GXDLMSClient client, GXDLMSObject target)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(2);
            GXCommon.SetData(null, bb, DataType.UInt16, target.ObjectType);
            GXCommon.SetData(null, bb, DataType.OctetString, GXCommon.LogicalNameToBytes(target.LogicalName));
            return(client.Method(this, 1, bb.Array(), DataType.Array));
        }
 /// <summary>
 /// Deletes an entry from the table.
 /// </summary>
 public byte[][] Delete(GXDLMSClient client, GXDLMSTarget entry)
 {
     GXByteBuffer bb = new GXByteBuffer();
     bb.SetUInt8(DataType.Structure);
     bb.SetUInt8(3);
     GXCommon.SetData(null, bb, DataType.UInt16, entry.Target.ObjectType);
     GXCommon.SetData(null, bb, DataType.OctetString, GXCommon.LogicalNameToBytes(entry.Target.LogicalName));
     GXCommon.SetData(null, bb, DataType.Int8, entry.AttributeIndex);
     return client.Method(this, 2, bb.Array(), DataType.Array);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Removes IP v6 address from the meter.
        /// </summary>
        /// <param name="client">DLMS client.</param>
        /// <param name="type">Address type.</param>
        /// <param name="address">IP v6 Address to remove.</param>
        /// <returns></returns>
        public byte[][] RemoveAddress(GXDLMSClient client, IPv6AddressType type, IPAddress address)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(2);
            GXCommon.SetData(null, bb, DataType.Enum, type);
            GXCommon.SetData(null, bb, DataType.OctetString, address.GetAddressBytes());
            return(client.Method(this, 2, bb.Array(), DataType.Structure));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Request Action.
        /// </summary>
        /// <param name="client">DLMS client.</param>
        /// <returns>Action bytes.</returns>
        public byte[][] RequestAction(GXDLMSClient client, byte actor, string actions)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(2);
            bb.SetUInt8(DataType.UInt8);
            bb.SetUInt8(actor);
            GXCommon.SetData(null, bb, DataType.BitString, actions);
            return(client.Method(this, 1, bb.Array(), DataType.Structure));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Presets the time to a new value (preset_time) and defines a validity_interval within which the new time can be activated.
        /// </summary>
        /// <param name="presetTime"></param>
        /// <param name="validityIntervalStart"></param>
        /// <param name="validityIntervalEnd"></param>
        /// <returns></returns>
        public byte[][] PresetAdjustingTime(GXDLMSClient client, DateTime presetTime, DateTime validityIntervalStart, DateTime validityIntervalEnd)
        {
            List <byte> buff = new List <byte>();

            buff.Add((byte)DataType.Structure);
            buff.Add((byte)3);
            GXCommon.SetData(buff, DataType.DateTime, presetTime);
            GXCommon.SetData(buff, DataType.DateTime, validityIntervalStart);
            GXCommon.SetData(buff, DataType.DateTime, validityIntervalEnd);
            return(client.Method(this, 5, buff.ToArray(), DataType.Array));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Add new SAP item.
        /// </summary>
        /// <param name="client">DLMS client.</param>
        /// <param name="id">SAP ID.</param>
        /// <param name="name">Logical device name.</param>
        /// <returns>Generated bytes sent to the meter.</returns>
        public byte[][] AddSap(GXDLMSClient client, UInt16 id, string name)
        {
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Structure);
            //Add structure size.
            data.SetUInt8(2);
            GXCommon.SetData(null, data, DataType.UInt16, id);
            GXCommon.SetData(null, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(name));
            return(client.Method(this, 1, data.Array(), DataType.Structure));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Presets the time to a new value (preset_time) and defines a validity_interval within which the new time can be activated.
        /// </summary>
        /// <param name="presetTime"></param>
        /// <param name="validityIntervalStart"></param>
        /// <param name="validityIntervalEnd"></param>
        /// <returns></returns>
        public byte[][] PresetAdjustingTime(GXDLMSClient client, DateTime presetTime, DateTime validityIntervalStart, DateTime validityIntervalEnd)
        {
            GXByteBuffer buff = new GXByteBuffer();

            buff.Add((byte)DataType.Structure);
            buff.Add((byte)3);
            GXCommon.SetData(client.Settings, buff, DataType.OctetString, presetTime);
            GXCommon.SetData(client.Settings, buff, DataType.OctetString, validityIntervalStart);
            GXCommon.SetData(client.Settings, buff, DataType.OctetString, validityIntervalEnd);
            return(client.Method(this, 5, buff.Array(), DataType.Array));
        }
        /// <summary>
        /// Inserts a new entry in the table.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <returns>
        ///  If a special day with the same index or with the same date as an already defined day is inserted,
        ///  the old entry will be overwritten.
        /// </returns>
        public byte[][] Insert(GXDLMSClient client, GXDLMSSpecialDay entry)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(3);
            GXCommon.SetData(null, bb, DataType.UInt16, entry.Index);
            GXCommon.SetData(null, bb, DataType.OctetString, entry.Date);
            GXCommon.SetData(null, bb, DataType.UInt8, entry.DayId);
            return(client.Method(this, 1, bb.Array(), DataType.Array));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Remove user from user list.
        /// </summary>
        /// <param name="client">DLMS client.</param>
        /// <param name="id">User ID.</param>
        /// <param name="name">User name.</param>
        /// <returns></returns>
        public byte[][] RemoveUser(GXDLMSClient client, byte id, string name)
        {
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Structure);
            //Add structure size.
            data.SetUInt8(2);
            GXCommon.SetData(null, data, DataType.UInt8, id);
            GXCommon.SetData(null, data, DataType.String, name);
            return(client.Method(this, 6, data.Array(), DataType.Structure));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Move image to the meter.
        /// </summary>
        /// <param name="client">DLMS Client.</param>
        /// <param name="imageBlock">Image</param>
        /// <param name="ImageBlockCount"></param>
        /// <returns></returns>
        public byte[][] ImageBlockTransfer(GXDLMSClient client, byte[] image, out int ImageBlockCount)
        {
            List <byte[]> packets = new List <byte[]>();

            byte[][] blocks = GetImageBlocks(image);
            ImageBlockCount = blocks.Length;
            foreach (byte[] it in blocks)
            {
                packets.AddRange(client.Method(this, 2, it, DataType.Array));
            }
            return(packets.ToArray());
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Remove entry from entries list.
        /// </summary>
        /// <param name="client">DLMS client.</param>
        /// <param name="entry">Schedule entry.</param>
        /// <returns>Action bytes.</returns>
        public byte[][] Delete(GXDLMSClient client, GXScheduleEntry entry)
        {
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Structure);
            //Add structure size.
            data.SetUInt8(2);
            //firstIndex
            GXCommon.SetData(null, data, DataType.UInt16, entry.Index);
            //lastIndex
            GXCommon.SetData(null, data, DataType.UInt16, entry.Index);
            return(client.Method(this, 3, data.Array(), DataType.Structure));
        }
Ejemplo n.º 15
0
        public byte[][] ImageTransferInitiate(GXDLMSClient client, string imageIdentifier, long imageSize)
        {
            if (ImageBlockSize == 0)
            {
                throw new Exception("Invalid image block size");
            }
            List <byte> data = new List <byte>();

            data.Add((byte)DataType.Structure);
            data.Add((byte)2);
            GXCommon.SetData(data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(imageIdentifier));
            GXCommon.SetData(data, DataType.UInt32, imageSize);
            return(client.Method(this, 1, data.ToArray(), DataType.Array));
        }
Ejemplo n.º 16
0
        public byte[][] ImageTransferInitiate(GXDLMSClient client, byte[] imageIdentifier, long imageSize)
        {
            if (ImageBlockSize == 0)
            {
                throw new Exception("Invalid image block size");
            }
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Structure);
            data.SetUInt8((byte)2);
            GXCommon.SetData(client.Settings, data, DataType.OctetString, imageIdentifier);
            GXCommon.SetData(client.Settings, data, DataType.UInt32, imageSize);
            return(client.Method(this, 1, data.Array(), DataType.Array));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Add new register activation mask.
        /// </summary>
        /// <param name="client">DLMS client.</param>
        /// <param name="name">Register activation mask name.</param>
        /// <param name="indexes">Register activation indexes.</param>
        /// <returns>Action bytes.</returns>
        public byte[][] AddMask(GXDLMSClient client, byte[] name, byte[] indexes)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(2);
            GXCommon.SetData(null, bb, DataType.OctetString, name);
            bb.SetUInt8(DataType.Array);
            bb.SetUInt8((byte)indexes.Length);
            foreach (byte it in indexes)
            {
                GXCommon.SetData(null, bb, DataType.UInt8, it);
            }
            return(client.Method(this, 2, bb.Array(), DataType.Array));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Transfers an encryption key to the M-Bus slave device.
        /// </summary>
        /// <param name="client">DLMS client settings.</param>
        /// <param name="encryptionKey">encryption key</param>
        /// <returns>Generated DLMS data.</returns>
        public byte[][] TransferKey(GXDLMSClient client, byte[] encryptionKey)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.OctetString);
            if (encryptionKey == null)
            {
                bb.SetUInt8(0);
            }
            else
            {
                GXCommon.SetObjectCount(encryptionKey.Length, bb);
                bb.Set(encryptionKey);
            }
            return(client.Method(this, 8, bb.Array(), DataType.Array));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Inserts a new entries in the table.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <returns>
        ///  If a special day with the same index or with the same date as an already defined day is inserted,
        ///  the old entry will be overwritten.
        /// </returns>
        public byte[][] Insert(GXDLMSClient client, GXDLMSSpecialDay[] entries)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Array);
            GXCommon.SetObjectCount(entries.Length, bb);
            foreach (GXDLMSSpecialDay entry in entries)
            {
                bb.SetUInt8(DataType.Structure);
                bb.SetUInt8(3);
                GXCommon.SetData(null, bb, DataType.UInt16, entry.Index);
                GXCommon.SetData(null, bb, DataType.OctetString, entry.Date);
                GXCommon.SetData(null, bb, DataType.UInt8, entry.DayId);
            }
            return(client.Method(this, 1, bb.Array()));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Remove object from object list.
        /// </summary>
        /// <param name="client">DLMS client.</param>
        /// <param name="obj">COSEM object.</param>
        /// <returns></returns>
        public byte[][] RemoveObject(GXDLMSClient client, GXDLMSObject obj)
        {
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Structure);
            //Add structure size.
            data.SetUInt8(4);
            //ClassID
            GXCommon.SetData(null, data, DataType.UInt16, obj.ObjectType);
            //Version
            GXCommon.SetData(null, data, DataType.UInt8, obj.Version);
            //LN
            GXCommon.SetData(null, data, DataType.OctetString, GXCommon.LogicalNameToBytes(obj.LogicalName));
            //Access rights.
            GetAccessRights(null, obj, null, data);
            return(client.Method(this, 4, data.Array(), DataType.Structure));
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Updates secret.
 /// </summary>
 /// <param name="client">DLMS client.</param>
 /// <returns>Action bytes.</returns>
 public byte[][] UpdateSecret(GXDLMSClient client)
 {
     if (AuthenticationMechanismName.MechanismId == Authentication.None)
     {
         throw new ArgumentException("Invalid authentication level in MechanismId.");
     }
     if (AuthenticationMechanismName.MechanismId == Authentication.HighGMAC)
     {
         throw new ArgumentException("HighGMAC secret is updated using Security setup.");
     }
     if (AuthenticationMechanismName.MechanismId == Authentication.Low)
     {
         return(client.Write(this, 7));
     }
     //Action is used to update High authentication password.
     return(client.Method(this, 2, Secret, DataType.OctetString));
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Removes X.509 v3 certificate from the server using serial number.
        /// </summary>
        /// <param name="client">DLMS client that is used to generate action.</param>
        /// <param name="serialNumber">Serial number.</param>
        /// <param name="issuer">Issuer.</param>
        /// <returns>Generated action.</returns>
        public byte[][] RemoveCertificateBySerial(GXDLMSClient client, byte[] serialNumber, byte[] issuer)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(2);
            //Add enum
            bb.SetUInt8(DataType.Enum);
            bb.SetUInt8(1);
            //Add certificate_identification_by_entity
            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(2);
            //serialNumber
            GXCommon.SetData(client.Settings, bb, DataType.OctetString, serialNumber);
            //issuer
            GXCommon.SetData(client.Settings, bb, DataType.OctetString, issuer);
            return(client.Method(this, 8, bb.Array(), DataType.Structure));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Agree on one or more symmetric keys using the key agreement algorithm.
        /// </summary>
        /// <param name="client"> DLMS client that is used to generate action.</param>
        /// <param name="list"> List of keys.</param>
        /// <returns>Generated action.</returns>
        public byte[][] keyAgreement(GXDLMSClient client, List <KeyValuePair <GlobalKeyType, byte[]> > list)
        {
            if (list == null || list.Count == 0)
            {
                throw new ArgumentException("Invalid list. It is empty.");
            }
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Array);
            bb.SetUInt8((byte)list.Count);
            foreach (KeyValuePair <GlobalKeyType, byte[]> it in list)
            {
                bb.SetUInt8(DataType.Structure);
                bb.SetUInt8(2);
                GXCommon.SetData(client.Settings, bb, DataType.Enum, it.Key);
                GXCommon.SetData(client.Settings, bb, DataType.OctetString, it.Value);
            }
            return(client.Method(this, 3, bb.Array(), DataType.Array));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Sends data to the M-Bus slave device.
        /// </summary>
        /// <param name="client">DLMS client settings.</param>
        /// <param name="data">data to send</param>
        /// <returns>Generated DLMS data.</returns>
        public byte[][] SendData(GXDLMSClient client, GXMBusClientData[] data)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Array);
            bb.SetUInt8(DataType.Structure);
            GXCommon.SetObjectCount(data.Length, bb);
            foreach (GXMBusClientData it in data)
            {
                bb.SetUInt8(DataType.Structure);
                bb.SetUInt8(3);
                bb.SetUInt8(DataType.OctetString);
                GXCommon.SetObjectCount(it.DataInformation.Length, bb);
                bb.Set(it.DataInformation);
                bb.SetUInt8(DataType.OctetString);
                GXCommon.SetObjectCount(it.ValueInformation.Length, bb);
                bb.Set(it.ValueInformation);
                GXCommon.SetData(client.Settings, bb, GXDLMSConverter.GetDLMSDataType(it.Data), it.Data);
            }
            return(client.Method(this, 6, bb.Array(), DataType.Array));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Removes X.509 v3 certificate from the server using entity.
        /// </summary>
        /// <param name="client">DLMS client that is used to generate action.</param>
        /// <param name="entity">Certificate entity type.</param>
        /// <param name="type">Certificate type.</param>
        /// <param name="systemTitle">System title.</param>
        /// <returns>Generated action.</returns>
        public byte[][] RemoveCertificateByEntity(GXDLMSClient client, CertificateEntity entity, CertificateType type, byte[] systemTitle)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(2);
            //Add enum
            bb.SetUInt8(DataType.Enum);
            bb.SetUInt8(0);
            //Add certificate_identification_by_entity
            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(3);
            //Add certificate_entity
            bb.SetUInt8(DataType.Enum);
            bb.SetUInt8(entity);
            //Add certificate_type
            bb.SetUInt8(DataType.Enum);
            bb.SetUInt8(type);
            //system_title
            GXCommon.SetData(client.Settings, bb, DataType.OctetString, systemTitle);
            return(client.Method(this, 8, bb.Array(), DataType.Structure));
        }
Ejemplo n.º 26
0
 public byte[][] ImageActivate(GXDLMSClient client)
 {
     return(client.Method(this, 4, 0, DataType.Int8));
 }
Ejemplo n.º 27
0
 public byte[][] ImageVerify(GXDLMSClient client)
 {
     return(client.Method(this, 3, 0, DataType.Int8));
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Remove register activation mask.
 /// </summary>
 /// <param name="client">DLMS client.</param>
 /// <param name="name">Register activation mask name.</param>
 /// <returns>Action bytes.</returns>
 public byte[][] RemoveMask(GXDLMSClient client, byte[] name)
 {
     return(client.Method(this, 3, name));
 }
 /// <summary>
 /// This method copies all passive parameter to the active parameter.
 /// </summary>
 /// <param name="client">DLMS client.</param>
 /// <returns>Action bytes.</returns>
 public byte[][] ActivatePassiveCalendar(GXDLMSClient client)
 {
     return(client.Method(this, 1, (sbyte)0));
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Method attribute value.
        /// </summary>
        public void Method(GXDLMSObject it, int attributeIndex, object value, DataType type)
        {
            GXReplyData reply = new GXReplyData();

            ReadDataBlock(Client.Method(it, attributeIndex, value, type), reply);
        }