Array() public method

Returs data as byte array.
public Array ( ) : byte[]
return byte[]
Exemplo n.º 1
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         return this.CurrentAverageValue;
     }
     if (e.Index == 3)
     {
         return this.LastAverageValue;
     }
     if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(settings, data, DataType.Int8, _scaler);
         GXCommon.SetData(settings, data, DataType.Enum, Unit);
         return data.Array();
     }
     if (e.Index == 5)
     {
         return this.Status;
     }
     if (e.Index == 6)
     {
         return CaptureTime;
     }
     if (e.Index == 7)
     {
         return StartTimeCurrent;
     }
     if (e.Index == 8)
     {
         return Period;
     }
     if (e.Index == 9)
     {
         return NumberOfPeriods;
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Generates data notification message.
 /// </summary>
 /// <param name="date">Date time. Set To Min or Max if not added</param>
 /// <param name="data">Notification body.</param>
 /// <returns>Generated data notification message(s).</returns>
 public byte[][] GetDataNotificationMessage(DateTime date, GXByteBuffer data)
 {
     return(GetDataNotificationMessage(date, data.Array()));
 }
Exemplo n.º 3
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         return MBusPortReference;
     }
     if (e.Index == 3)
     {
         GXByteBuffer buff = new GXByteBuffer();
         buff.Add((byte)DataType.Array);
         GXCommon.SetObjectCount(CaptureDefinition.Count, buff);
         foreach (KeyValuePair<string, string> it in CaptureDefinition)
         {
             buff.Add((byte)DataType.Structure);
             buff.Add(2);
             GXCommon.SetData(settings, buff, DataType.UInt8, it.Key);
             GXCommon.SetData(settings, buff, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(it.Value));
         }
         return buff.Array();
     }
     if (e.Index == 4)
     {
         return CapturePeriod;
     }
     if (e.Index == 5)
     {
         return PrimaryAddress;
     }
     if (e.Index == 6)
     {
         return IdentificationNumber;
     }
     if (e.Index == 7)
     {
         return ManufacturerID;
     }
     if (e.Index == 8)
     {
         return DataHeaderVersion;
     }
     if (e.Index == 9)
     {
         return DeviceType;
     }
     if (e.Index == 10)
     {
         return AccessNumber;
     }
     if (e.Index == 11)
     {
         return Status;
     }
     if (e.Index == 12)
     {
         return Alarm;
     }
     if (Version > 0)
     {
         if (e.Index == 13)
         {
             return Configuration;
         }
         if (e.Index == 14)
         {
             return EncryptionKeyStatus;
         }
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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.OctetString);
 }
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (Entries == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             int cnt = Entries.Length;
             //Add count
             GXCommon.SetObjectCount(cnt, data);
             if (cnt != 0)
             {
                 foreach (GXDLMSSpecialDay it in Entries)
                 {
                     data.SetUInt8((byte)DataType.Structure);
                     data.SetUInt8((byte)3); //Count
                     GXCommon.SetData(settings, data, DataType.UInt16, it.Index);
                     GXCommon.SetData(settings, data, DataType.OctetString, it.Date);
                     GXCommon.SetData(settings, data, DataType.UInt8, it.DayId);
                 }
             }
         }
         return data.Array();
     }
     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)
     {
         Mode = (IecTwistedPairSetupMode)e.Value;
     }
     else if (e.Index == 3)
     {
         Speed = (BaudRate)e.Value;
     }
     else if (e.Index == 4)
     {
         GXByteBuffer list = new GXByteBuffer();
         foreach (object it in (object[])e.Value)
         {
             list.Add((byte)it);
         }
         PrimaryAddresses = list.Array();
     }
     else if (e.Index == 5)
     {
         List<sbyte> list = new List<sbyte>();
         foreach (object it in (object[])e.Value)
         {
             list.Add((sbyte)it);
         }
         Tabis = list.ToArray();
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Convert HDLC address to bytes.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="size">Address size in bytes.</param>
 /// <returns></returns>
 private static byte[] GetHdlcAddressBytes(int value, byte size)
 {
     Object tmp = GetHhlcAddress(value, size);
     GXByteBuffer bb = new GXByteBuffer();
     if (tmp is byte)
     {
         bb.SetUInt8((byte)tmp);
     }
     else if (tmp is UInt16)
     {
         bb.SetUInt16((UInt16)tmp);
     }
     else if (tmp is UInt32)
     {
         bb.SetUInt32((UInt32)tmp);
     }
     else
     {
         throw new ArgumentException("Invalid address type.");
     }
     return bb.Array();
 }
Exemplo n.º 9
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     else if (e.Index == 2)
     {
         return InitiatorElectricalPhase;
     }
     else if (e.Index == 3)
     {
         return DeltaElectricalPhase;
     }
     else if (e.Index == 4)
     {
         return MaxReceivingGain;
     }
     else if (e.Index == 5)
     {
         return MaxTransmittingGain;
     }
     else if (e.Index == 6)
     {
         return SearchInitiatorThreshold;
     }
     else if (e.Index == 7)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8(DataType.Structure);
         bb.SetUInt8(2);
         GXCommon.SetData(settings, bb, DataType.UInt32, MarkFrequency);
         GXCommon.SetData(settings, bb, DataType.UInt32, SpaceFrequency);
         return bb.Array();
     }
     else if (e.Index == 8)
     {
         return MacAddress;
     }
     else if (e.Index == 9)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8(DataType.Array);
         if (MacGroupAddresses == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(MacGroupAddresses.Length, bb);
             foreach (UInt16 it in MacGroupAddresses)
             {
                 GXCommon.SetData(settings, bb, DataType.UInt16, it);
             }
         }
         return bb.Array();
     }
     else if (e.Index == 10)
     {
         return Repeater;
     }
     else if (e.Index == 11)
     {
         return RepeaterStatus;
     }
     else if (e.Index == 12)
     {
         return MinDeltaCredit;
     }
     else if (e.Index == 13)
     {
         return InitiatorMacAddress;
     }
     else if (e.Index == 14)
     {
         return SynchronizationLocked;
     }
     else if (e.Index == 15)
     {
         return TransmissionSpeed;
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Get all Short Name messages. Client uses this to generate messages.
 /// </summary>
 /// <param name="settings">DLMS settings.</param>
 /// <param name="command">DLMS command.</param>
 /// <param name="count">Attribute descriptor.</param>
 /// <param name="data">Data.</param>
 /// <returns>Generated messages.</returns>
 internal static byte[][] GetSnMessages(GXDLMSSNParameters p)
 {
     GXByteBuffer reply = new GXByteBuffer();
     List<byte[]> messages = new List<byte[]>();
     byte frame = 0x0;
     if (p.command == Command.Aarq)
     {
         frame = 0x10;
     }
     else if (p.command == Command.None)
     {
         frame = p.settings.NextSend();
     }
     do
     {
         GetSNPdu(p, reply);
         if (p.command != Command.Aarq && p.command != Command.Aare)
         {
             System.Diagnostics.Debug.Assert(!(p.settings.MaxPduSize < reply.Size));
         }
         //Command is not add to next PDUs.
         while (reply.Position != reply.Size)
         {
             if (p.settings.InterfaceType == Enums.InterfaceType.WRAPPER)
             {
                 messages.Add(GXDLMS.GetWrapperFrame(p.settings, reply));
             }
             else if (p.settings.InterfaceType == Enums.InterfaceType.HDLC)
             {
                 messages.Add(GXDLMS.GetHdlcFrame(p.settings, frame, reply));
                 frame = 0;
             }
             else if (p.settings.InterfaceType == Enums.InterfaceType.PDU)
             {
                 messages.Add(reply.Array());
                 frame = 0;
                 break;
             }
             else
             {
                 throw new ArgumentOutOfRangeException("InterfaceType");
             }
         }
         reply.Clear();
     } while (p.data != null && p.data.Position != p.data.Size);
     return messages.ToArray();
 }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="p"></param>
        /// <param name="reply"></param>
        internal static void GetSNPdu(GXDLMSSNParameters p, GXByteBuffer reply)
        {
            bool ciphering = p.settings.Cipher != null && p.settings.Cipher.Security != Gurux.DLMS.Enums.Security.None;
            if (!ciphering && p.settings.InterfaceType == InterfaceType.HDLC)
            {
                if (p.settings.IsServer)
                {
                    reply.Set(GXCommon.LLCReplyBytes);
                }
                else if (reply.Size == 0)
                {
                    reply.Set(GXCommon.LLCSendBytes);
                }
            }
            int cnt = 0, cipherSize = 0;
            if (ciphering)
            {
                cipherSize = CipheringHeaderSize;
                /*
                if (p.settings.Cipher.Security == Security.Encryption)
                {
                    cipherSize = 7;
                }
                else if (p.settings.Cipher.Security == Security.Authentication)
                {
                    cipherSize = 19;
                }
                else if (p.settings.Cipher.Security == Security.AuthenticationEncryption)
                {
                    cipherSize = 7;
                }
                 * */
            }
            if (p.data != null)
            {
                cnt = p.data.Size - p.data.Position;
            }
            // Add command.
            if (p.command != Command.Aarq && p.command != Command.Aare)
            {
                reply.SetUInt8((byte)p.command);
                if (p.count != 0xFF)
                {
                    GXCommon.SetObjectCount(p.count, reply);
                }
                if (p.requestType != 0xFF)
                {
                    reply.SetUInt8(p.requestType);
                }
                reply.Set(p.attributeDescriptor);

                if (!p.multipleBlocks)
                {
                    p.multipleBlocks = reply.Size + cipherSize + cnt > p.settings.MaxPduSize;
                    //If reply data is not fit to one PDU.
                    if (p.multipleBlocks)
                    {
                        //Remove command.
                        GXByteBuffer tmp = new GXByteBuffer();
                        int offset = 1;
                        if (!ciphering && p.settings.InterfaceType == InterfaceType.HDLC)
                        {
                            offset = 4;
                        }
                        tmp.Set(reply.Data, offset, reply.Size - offset);
                        reply.Size = 0;
                        if (!ciphering && p.settings.InterfaceType == InterfaceType.HDLC)
                        {
                            if (p.settings.IsServer)
                            {
                                reply.Set(GXCommon.LLCReplyBytes);
                            }
                            else if (reply.Size == 0)
                            {
                                reply.Set(GXCommon.LLCSendBytes);
                            }
                        }
                        if (p.command == Command.WriteRequest)
                        {
                            p.requestType = (byte)VariableAccessSpecification.WriteDataBlockAccess;
                        }
                        else if (p.command == Command.ReadRequest)
                        {
                            p.requestType = (byte)VariableAccessSpecification.ReadDataBlockAccess;
                        }
                        else if (p.command == Command.ReadResponse)
                        {
                            p.requestType = (byte)SingleReadResponse.DataBlockResult;
                        }
                        else
                        {
                            throw new ArgumentException("Invalid command.");
                        }
                        reply.SetUInt8((byte)p.command);
                        //Set object count.
                        reply.SetUInt8(1);
                        if (p.requestType != 0xFF)
                        {
                            reply.SetUInt8(p.requestType);
                        }
                        cnt = GXDLMS.AppendMultipleSNBlocks(p, tmp, reply);
                    }
                }
                else
                {
                    cnt = GXDLMS.AppendMultipleSNBlocks(p, null, reply);
                }
            }
            // Add data.
            reply.Set(p.data, cnt);
            //Af all data is transfered.
            if (p.data != null && p.data.Position == p.data.Size)
            {
                p.settings.Index = p.settings.Count = 0;
            }
            // If Ciphering is used.
            if (ciphering && p.command != Command.Aarq && p.command != Command.Aare)
            {
                byte[] tmp = p.settings.Cipher.Encrypt((byte)GetGloMessage(p.command), p.settings.Cipher.SystemTitle, reply.Array());
                System.Diagnostics.Debug.Assert(!(p.settings.MaxPduSize < tmp.Length));
                reply.Size = 0;
                if (p.settings.InterfaceType == InterfaceType.HDLC)
                {
                    if (p.settings.IsServer)
                    {
                        reply.Set(GXCommon.LLCReplyBytes);
                    }
                    else if (reply.Size == 0)
                    {
                        reply.Set(GXCommon.LLCSendBytes);
                    }
                }
                reply.Set(tmp);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 ///  Get all Logical name messages. Client uses this to generate messages.
 /// </summary>
 /// <param name="p">LN settings.</param>
 /// <returns>Generated messages.</returns>
 internal static byte[][] GetLnMessages(GXDLMSLNParameters p)
 {
     GXByteBuffer reply = new GXByteBuffer();
     List<byte[]> messages = new List<byte[]>();
     byte frame = 0;
     if (p.command == Command.Aarq)
     {
         frame = 0x10;
     }
     do
     {
         GetLNPdu(p, reply);
         p.lastBlock = true;
         if (p.attributeDescriptor == null)
         {
             ++p.settings.BlockIndex;
         }
         if (p.command == Command.Aarq && p.command == Command.GetRequest)
         {
             System.Diagnostics.Debug.Assert(!(p.settings.MaxPduSize < reply.Size));
         }
         while (reply.Position != reply.Size)
         {
             if (p.settings.InterfaceType == Enums.InterfaceType.WRAPPER)
             {
                 messages.Add(GXDLMS.GetWrapperFrame(p.settings, reply));
             }
             else if (p.settings.InterfaceType == Enums.InterfaceType.HDLC)
             {
                 messages.Add(GXDLMS.GetHdlcFrame(p.settings, frame, reply));
                 frame = 0;
             }
             else if (p.settings.InterfaceType == Enums.InterfaceType.PDU)
             {
                 messages.Add(reply.Array());
                 frame = 0;
                 break;
             }
             else
             {
                 throw new ArgumentOutOfRangeException("InterfaceType");
             }
         }
         reply.Clear();
     }
     while (p.data != null && p.data.Position != p.data.Size);
     return messages.ToArray();
 }
Exemplo n.º 13
0
        /// <summary>
        /// Get next logical name PDU.
        /// </summary>
        /// <param name="p">LN parameters.</param>
        /// <param name="reply">Generated message.</param>
        internal static void GetLNPdu(GXDLMSLNParameters p, GXByteBuffer reply)
        {
            bool ciphering = p.settings.Cipher != null && p.settings.Cipher.Security != Gurux.DLMS.Enums.Security.None;
            int len = 0;
            if (!ciphering && p.settings.InterfaceType == InterfaceType.HDLC)
            {
                AddLLCBytes(p.settings, reply);
            }
            if (p.command == Command.Aarq)
            {
                reply.Set(p.attributeDescriptor);
            }
            else
            {
                if (p.settings.LnSettings.GeneralBlockTransfer)
                {
                    reply.SetUInt8((byte)Command.GeneralBlockTransfer);
                    MultipleBlocks(p, reply, ciphering);
                    // Is last block
                    if (!p.lastBlock)
                    {
                        reply.SetUInt8(0);
                    }
                    else
                    {
                        reply.SetUInt8(0x80);
                    }
                    // Set block number sent.
                    reply.SetUInt8(0);
                    // Set block number acknowledged
                    reply.SetUInt8((byte)p.blockIndex);
                    ++p.blockIndex;
                    // Add APU tag.
                    reply.SetUInt8(0);
                    // Add Addl fields
                    reply.SetUInt8(0);
                }
                // Add command.
                reply.SetUInt8((byte)p.command);

                if (p.command == Command.DataNotification ||
                        p.command == Command.AccessRequest ||
                        p.command == Command.AccessResponse)
                {
                    // Add Long-Invoke-Id-And-Priority
                    reply.SetUInt32(GetLongInvokeIDPriority(p.settings));
                    // Add date time.
                    if (p.time == null || p.time.Value.DateTime == DateTime.MinValue || p.time.Value.DateTime == DateTime.MaxValue ||
                            p.time.Value.LocalDateTime == DateTime.MinValue || p.time.Value.LocalDateTime == DateTime.MaxValue)
                    {
                        reply.SetUInt8(DataType.None);
                    }
                    else
                    {
                        // Data is send in octet string. Remove data type.
                        int pos = reply.Size;
                        GXCommon.SetData(p.settings, reply, DataType.OctetString, p.time);
                        reply.Move(pos + 1, pos, reply.Size - pos - 1);
                    }
                }
                else
                {
                    //Get request size can be bigger than PDU size.
                    if (p.command != Command.GetRequest &&
                            p.data != null && p.data.Size != 0)
                    {
                        MultipleBlocks(p, reply, ciphering);
                    }
                    //Change Request type if Set request and multiple blocks is needed.
                    if (p.command == Command.SetRequest)
                    {
                        if (p.multipleBlocks)
                        {
                            if (p.requestType == 1)
                            {
                                p.requestType = 2;
                            }
                            else if (p.requestType == 2)
                            {
                                p.requestType = 3;
                            }
                        }
                    }
                    //Change request type If get response and multiple blocks is needed.
                    if (p.command == Command.GetResponse)
                    {
                        if (p.multipleBlocks)
                        {
                            if (p.requestType == 1)
                            {
                                p.requestType = 2;
                            }
                        }
                    }
                    reply.SetUInt8(p.requestType);
                    // Add Invoke Id And Priority.
                    reply.SetUInt8(GetInvokeIDPriority(p.settings));
                }

                //Add attribute descriptor.
                reply.Set(p.attributeDescriptor);
                if (p.command != Command.DataNotification && !p.settings.LnSettings.GeneralBlockTransfer)
                {
                    //If multiple blocks.
                    if (p.multipleBlocks)
                    {
                        // Is last block.
                        if (p.lastBlock)
                        {
                            reply.SetUInt8(1);
                            p.settings.Count = p.settings.Index = 0;
                        }
                        else
                        {
                            reply.SetUInt8(0);
                        }
                        // Block index.
                        reply.SetUInt32(p.blockIndex);
                        ++p.blockIndex;
                        //Add status if reply.
                        if (p.status != 0xFF)
                        {
                            if (p.status != 0 && p.command == Command.GetResponse)
                            {
                                reply.SetUInt8(1);
                            }
                            reply.SetUInt8(p.status);
                        }
                        //Block size.
                        if (p.data != null)
                        {
                            len = p.data.Size - p.data.Position;
                        }
                        else
                        {
                            len = 0;
                        }
                        int totalLength = len + reply.Size;
                        if (ciphering)
                        {
                            totalLength += CipheringHeaderSize;
                        }

                        if (totalLength > p.settings.MaxPduSize)
                        {
                            len = p.settings.MaxPduSize - reply.Size - p.data.Position;
                            if (ciphering)
                            {
                                len -= CipheringHeaderSize;
                            }
                            len -= GXCommon.GetObjectCountSizeInBytes(len);
                        }
                        GXCommon.SetObjectCount(len, reply);
                        reply.Set(p.data, len);
                    }
                }
                //Add data that fits to one block.
                if (len == 0)
                {
                    //Add status if reply.
                    if (p.status != 0xFF)
                    {
                        if (p.status != 0 && p.command == Command.GetResponse)
                        {
                            reply.SetUInt8(1);
                        }
                        reply.SetUInt8(p.status);
                    }
                    if (p.data != null && p.data.Size != 0)
                    {
                        len = p.data.Size - p.data.Position;
                        //Get request size can be bigger than PDU size.
                        if (p.command != Command.GetRequest && len + reply.Size > p.settings.MaxPduSize)
                        {
                            len = p.settings.MaxPduSize - reply.Size;
                        }
                        reply.Set(p.data, len);
                    }
                }
                if (ciphering)
                {
                    byte[] tmp = p.settings.Cipher.Encrypt((byte)GetGloMessage(p.command),
                                                           p.settings.Cipher.SystemTitle, reply.Array());
                    reply.Size = 0;
                    if (p.settings.InterfaceType == InterfaceType.HDLC)
                    {
                        AddLLCBytes(p.settings, reply);
                    }
                    if (p.command == Command.DataNotification)
                    {
                        // Add command.
                        reply.SetUInt8(tmp[0]);
                        // Add system title.
                        GXCommon.SetObjectCount(
                            p.settings.Cipher.SystemTitle.Length,
                            reply);
                        reply.Set(p.settings.Cipher.SystemTitle);
                        // Add data.
                        reply.Set(tmp, 1, tmp.Length - 1);
                    }
                    else
                    {
                        reply.Set(tmp);
                    }
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Get HDLC frame for data.
        /// </summary>
        /// <param name="settings">DLMS settings.</param>
        /// <param name="frame">Frame ID. If zero new is generated.</param>
        /// <param name="data">Data to add.</param>
        /// <returns>HDLC frames.</returns>
        internal static byte[] GetHdlcFrame(GXDLMSSettings settings, byte frame, GXByteBuffer data)
        {
            GXByteBuffer bb = new GXByteBuffer();
            int frameSize, len = 0;
            byte[] primaryAddress, secondaryAddress;
            if (settings.IsServer)
            {
                primaryAddress = GetHdlcAddressBytes(settings.ClientAddress, 0);
                secondaryAddress = GetHdlcAddressBytes(settings.ServerAddress, settings.ServerAddressSize);
            }
            else
            {
                primaryAddress = GetHdlcAddressBytes(settings.ServerAddress, settings.ServerAddressSize);
                secondaryAddress = GetHdlcAddressBytes(settings.ClientAddress, 0);
            }
            // Add BOP
            bb.SetUInt8(GXCommon.HDLCFrameStartEnd);
            frameSize = Convert.ToInt32(settings.Limits.MaxInfoTX);
            // If no data
            if (data == null || data.Size == 0)
            {
                bb.SetUInt8(0xA0);
            }
            else if (data.Size - data.Position <= frameSize)
            {
                // Is last packet.
                bb.SetUInt8(0xA0);
                len = data.Size - data.Position;
            }
            else
            {
                // More data to left.
                bb.SetUInt8(0xA8);
                len = frameSize;
            }
            //Frame len.
            if (len == 0)
            {
                bb.SetUInt8((byte)(5 + primaryAddress.Length + secondaryAddress.Length + len));
            }
            else
            {
                bb.SetUInt8((byte)(7 + primaryAddress.Length + secondaryAddress.Length + len));
            }
            // Add primary address.
            bb.Set(primaryAddress);
            // Add secondary address.
            bb.Set(secondaryAddress);

            //Add frame ID.
            if (frame == 0)
            {
                frame = settings.NextSend();
            }
            bb.SetUInt8(frame);
            // Add header CRC.
            UInt16 crc = GXFCS16.CountFCS16(bb.Data, 1, bb.Size - 1);
            bb.SetUInt16(crc);
            if (len != 0)
            {
                //Add data.
                bb.Set(data, len);
                // Add data CRC.
                crc = GXFCS16.CountFCS16(bb.Data, 1, bb.Size - 1);
                bb.SetUInt16(crc);
            }
            // Add EOP
            bb.SetUInt8(GXCommon.HDLCFrameStartEnd);
            if (data != null)
            {
                //Remove sent data in server side.
                if (settings.IsServer)
                {
                    if (data.Size == data.Position)
                    {
                        data.Clear();
                    }
                    else
                    {
                        data.Move(data.Position, 0, data.Size - data.Position);
                        data.Position = 0;
                    }
                }
            }
            return bb.Array();
        }
Exemplo n.º 15
0
 /// <summary>
 /// Split DLMS PDU to wrapper frames.
 /// </summary>
 /// <param name="settings">DLMS settings.</param>
 /// <param name="data"> Wrapped data.</param>
 /// <returns>Wrapper frames</returns>
 internal static byte[] GetWrapperFrame(GXDLMSSettings settings, GXByteBuffer data)
 {
     GXByteBuffer bb = new GXByteBuffer();
     // Add version.
     bb.SetUInt16(1);
     if (settings.IsServer)
     {
         bb.SetUInt16((UInt16)settings.ServerAddress);
         bb.SetUInt16((UInt16)settings.ClientAddress);
     }
     else
     {
         bb.SetUInt16((UInt16)settings.ClientAddress);
         bb.SetUInt16((UInt16)settings.ServerAddress);
     }
     if (data == null)
     {
         // Data length.
         bb.SetUInt16(0);
     }
     else
     {
         // Data length.
         bb.SetUInt16((UInt16)data.Size);
         // Data
         bb.Set(data);
     }
     //Remove sent data in server side.
     if (settings.IsServer)
     {
         if (data.Size == data.Position)
         {
             data.Clear();
         }
         else
         {
             data.Move(data.Position, 0, data.Size - data.Position);
             data.Position = 0;
         }
     }
     return bb.Array();
 }
Exemplo n.º 16
0
        object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                return this.LogicalName;
            }
            if (e.Index == 2)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                //LN
                if (Target != null)
                {
                    GXCommon.SetData(settings, data, DataType.OctetString, Target.LogicalName);
                }
                else
                {
#pragma warning disable CS0618
                    GXCommon.SetData(settings, data, DataType.OctetString, ExecutedScriptLogicalName);
#pragma warning restore CS0618
                }
                GXCommon.SetData(settings, data, DataType.UInt16, ExecutedScriptSelector);
                return data.Array();
            }
            if (e.Index == 3)
            {
                return this.Type;
            }
            if (e.Index == 4)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Array);
                if (ExecutionTime == null)
                {
                    GXCommon.SetObjectCount(0, data);
                }
                else
                {
                    GXCommon.SetObjectCount(ExecutionTime.Length, data);
                    foreach (GXDateTime it in ExecutionTime)
                    {
                        data.SetUInt8((byte)DataType.Structure);
                        //Count
                        data.SetUInt8((byte)2);
                        //Time
                        GXCommon.SetData(settings, data, DataType.OctetString, new GXTime(it));
                        //Date
                        GXCommon.SetData(settings, data, DataType.OctetString, new GXDate(it));
                    }
                }
                return data.Array();
            }
            e.Error = ErrorCode.ReadWriteDenied;
            return null;
        }
Exemplo n.º 17
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         return ImageBlockSize;
     }
     if (e.Index == 3)
     {
         return ImageTransferredBlocksStatus;
     }
     if (e.Index == 4)
     {
         return ImageFirstNotTransferredBlockNumber;
     }
     if (e.Index == 5)
     {
         return ImageTransferEnabled;
     }
     if (e.Index == 6)
     {
         return ImageTransferStatus;
     }
     if (e.Index == 7)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (ImageActivateInfo == null)
         {
             GXCommon.SetObjectCount(0, data);
         }
         else
         {
             GXCommon.SetObjectCount(ImageActivateInfo.Length, data);
             foreach (GXDLMSImageActivateInfo it in ImageActivateInfo)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8(3);
                 GXCommon.SetData(settings, data, DataType.UInt32, it.Size);
                 GXCommon.SetData(settings, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(Convert.ToString(it.Identification)));
                 if (it.Signature == null || it.Signature.Length == 0)
                 {
                     GXCommon.SetData(settings, data, DataType.OctetString, null);
                 }
                 else
                 {
                     GXCommon.SetData(settings, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(it.Signature));
                 }
             }
         }
         return data.Array();
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Load XML commands from the file.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public List <GXDLMSXmlMessage> Load(string fileName)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(File.ReadAllText(fileName));
            List <GXDLMSXmlMessage> actions = new List <GXDLMSXmlMessage>();

            foreach (XmlNode m1 in doc.ChildNodes)
            {
                if (m1.NodeType == XmlNodeType.Element)
                {
                    foreach (XmlNode node in m1.ChildNodes)
                    {
                        if (node.NodeType == XmlNodeType.Element)
                        {
                            List <byte[]>     messages = new List <byte[]>();
                            GXDLMSXmlSettings s        = new GXDLMSXmlSettings(translator.OutputType, translator.Hex, translator.ShowStringAsHex, translator.tagsByName);;
                            s.settings.ClientAddress = Settings.ClientAddress;
                            s.settings.ServerAddress = Settings.ServerAddress;
                            GXByteBuffer reply = new GXByteBuffer(translator.XmlToPdu(node.OuterXml, s));
                            if (s.command == Command.Snrm)
                            {
                                messages.Add(reply.Array());
                            }
                            else if (s.command == Command.Ua)
                            {
                                Settings.Limits.MaxInfoTX    = s.settings.Limits.MaxInfoTX;
                                Settings.Limits.MaxInfoRX    = s.settings.Limits.MaxInfoRX;
                                Settings.Limits.WindowSizeRX = s.settings.Limits.WindowSizeRX;
                                Settings.Limits.WindowSizeTX = s.settings.Limits.WindowSizeTX;
                                messages.Add(reply.Array());
                            }
                            else if (s.command == Command.DisconnectRequest)
                            {
                                messages.Add(GXDLMS.GetHdlcFrame(Settings, (byte)Command.DisconnectRequest, reply));
                            }
                            else
                            {
                                while (reply.Position != reply.Size)
                                {
                                    if (Settings.InterfaceType == Enums.InterfaceType.WRAPPER)
                                    {
                                        messages.Add(GXDLMS.GetWrapperFrame(Settings, reply));
                                    }
                                    else if (Settings.InterfaceType == Enums.InterfaceType.HDLC)
                                    {
                                        byte frame = 0;
                                        if (s.command == Command.Aarq)
                                        {
                                            frame = 0x10;
                                        }
                                        else if (s.command == Command.Aare)
                                        {
                                            frame = 0x30;
                                        }
                                        else if (s.command == Command.EventNotification)
                                        {
                                            frame = 0x13;
                                        }
                                        messages.Add(GXDLMS.GetHdlcFrame(Settings, frame, reply));
                                        if (reply.Position != reply.Size)
                                        {
                                            if (Settings.IsServer || s.command == Command.SetRequest)
                                            {
                                                frame = 0;
                                            }
                                            else
                                            {
                                                frame = Settings.NextSend(false);
                                            }
                                        }
                                    }
                                    else if (Settings.InterfaceType == Enums.InterfaceType.PDU)
                                    {
                                        messages.Add(reply.Array());
                                        break;
                                    }
                                    else
                                    {
                                        throw new ArgumentOutOfRangeException("InterfaceType");
                                    }
                                }
                            }
                            actions.Add(new GXDLMSXmlMessage(s.command, node, messages.ToArray()));
                        }
                    }
                }
            }
            return(actions);
        }
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         return (byte)Mode;
     }
     if (e.Index == 3)
     {
         return (byte)Speed;
     }
     if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (PrimaryAddresses == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)PrimaryAddresses.Length);
             foreach (byte it in PrimaryAddresses)
             {
                 data.SetUInt8((byte)DataType.UInt8);
                 data.SetUInt8(it);
             }
         }
         return data.Array();
     }
     if (e.Index == 5)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (Tabis == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)Tabis.Length);
             foreach (sbyte it in Tabis)
             {
                 data.SetUInt8((byte)DataType.UInt8);
                 data.SetUInt8((byte)it);
             }
         }
         return data.Array();
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8(DataType.Structure);
         bb.SetUInt8(3);
         GXCommon.SetData(settings, bb, DataType.OctetString, SystemTitle);
         GXCommon.SetData(settings, bb, DataType.UInt16, MacAddress);
         GXCommon.SetData(settings, bb, DataType.UInt8, LSapSelector);
         return bb.Array();
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Exemplo n.º 21
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         int cnt = 0;
         if (SapAssignmentList != null)
         {
             cnt = SapAssignmentList.Count;
         }
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         //Add count
         GXCommon.SetObjectCount(cnt, data);
         if (cnt != 0)
         {
             foreach (var it in SapAssignmentList)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8((byte)2); //Count
                 GXCommon.SetData(settings, data, DataType.UInt16, it.Key);
                 GXCommon.SetData(settings, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(it.Value));
             }
         }
         return data.Array();
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Exemplo n.º 22
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);
 }
Exemplo n.º 23
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.OctetString);
 }
Exemplo n.º 24
0
        object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                return this.LogicalName;
            }
            else if (e.Index == 2)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(3);
                if (MonitoredValue == null)
                {
                    GXCommon.SetData(settings, data, DataType.Int16, 0);
                    GXCommon.SetData(settings, data, DataType.OctetString, "0.0.0.0.0.0");
                    GXCommon.SetData(settings, data, DataType.UInt8, 0);
                }
                else
                {
                    GXCommon.SetData(settings, data, DataType.Int16, MonitoredValue.ObjectType);
                    GXCommon.SetData(settings, data, DataType.OctetString, MonitoredValue.LogicalName);
                    GXCommon.SetData(settings, data, DataType.UInt8, MonitoredAttributeIndex);

                }
                return data.Array();
            }
            else if (e.Index == 3)
            {
                return ThresholdActive;
            }
            else if (e.Index == 4)
            {
                return ThresholdNormal;
            }
            else if (e.Index == 5)
            {
                return ThresholdEmergency;
            }
            else if (e.Index == 6)
            {
                return MinOverThresholdDuration;
            }
            else if (e.Index == 7)
            {
                return MinUnderThresholdDuration;
            }
            else if (e.Index == 8)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(3);
                GXCommon.SetData(settings, data, DataType.UInt16, EmergencyProfile.ID);
                GXCommon.SetData(settings, data, DataType.OctetString, EmergencyProfile.ActivationTime);
                GXCommon.SetData(settings, data, DataType.UInt32, EmergencyProfile.Duration);
                return data.Array();
            }
            else if (e.Index == 9)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Array);
                if (EmergencyProfileGroupIDs == null)
                {
                    data.SetUInt8(0);
                }
                else
                {
                    data.SetUInt8((byte)EmergencyProfileGroupIDs.Length);
                    foreach (object it in EmergencyProfileGroupIDs)
                    {
                        GXCommon.SetData(settings, data, DataType.UInt16, it);
                    }
                }

                return data.Array();
            }
            else if (e.Index == 10)
            {
                return EmergencyProfileActive;
            }
            else if (e.Index == 11)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                GXCommon.SetData(settings, data, DataType.OctetString, ActionOverThreshold.LogicalName);
                GXCommon.SetData(settings, data, DataType.UInt16, ActionOverThreshold.ScriptSelector);
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                GXCommon.SetData(settings, data, DataType.OctetString, ActionUnderThreshold.LogicalName);
                GXCommon.SetData(settings, data, DataType.UInt16, ActionUnderThreshold.ScriptSelector);
                return data.Array();
            }
            e.Error = ErrorCode.ReadWriteDenied;
            return null;
        }
Exemplo n.º 25
0
 /// <summary>
 /// Get sertificates as byte buffer.
 /// </summary>
 /// <returns></returns>
 private byte[] GetSertificates()
 {
     GXByteBuffer bb = new GXByteBuffer();
     bb.SetUInt8((byte)DataType.Array);
     GXCommon.SetObjectCount(Certificates.Count, bb);
     foreach (GXDLMSCertificateInfo it in Certificates)
     {
         bb.SetUInt8((byte)DataType.Structure);
         GXCommon.SetObjectCount(6, bb);
         bb.SetUInt8((byte)DataType.Enum);
         bb.SetUInt8((byte)it.Entity);
         bb.SetUInt8((byte)DataType.Enum);
         bb.SetUInt8((byte)it.Type);
         GXCommon.AddString(it.SerialNumber, bb);
         GXCommon.AddString(it.Issuer, bb);
         GXCommon.AddString(it.Subject, bb);
         GXCommon.AddString(it.SubjectAltName, bb);
     }
     return bb.Array();
 }
Exemplo n.º 26
0
        object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                return this.LogicalName;
            }
            if (e.Index == 2)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Array);
                data.SetUInt8((byte)Entries.Count);
                /*
                foreach (GXScheduleEntry it in Entries)
                {
                    data.SetUInt8((byte)DataType.Structure);
                    data.SetUInt8(10);
                    //Add index.
                    data.SetUInt8((byte)DataType.UInt8);
                    data.SetUInt8(it.Index);
                    //Add enable.
                    data.SetUInt8((byte)DataType.Boolean);
                    data.SetUInt8((byte) (it.Enable ? 1 : 0));

                    //Add logical Name.
                    data.SetUInt8((byte)DataType.OctetString);
                    data.SetUInt8((byte) it.LogicalName.Length);
                    //TODO: data.SetUInt8((byte)it.LogicalName.Length);

                    //Add script selector.
                    data.SetUInt8((byte)DataType.UInt8);
                    data.SetUInt8(it.ScriptSelector);

                    //Add switch time.
                    ret = var_setDateTime(&tmp, &se->switchTime);
                    if (ret != 0)
                    {
                        var_clear(&tmp);
                        break;
                    }
                    ret = var_getBytes(&tmp, &value->byteArr);
                    var_clear(&tmp);
                    if (ret != 0)
                    {
                        break;
                    }
                    //Add validity window.
                    data.SetUInt8((byte)DataType.UInt8);
                    data.SetUInt8(it.ValidityWindow);

                    //Add exec week days.
                    ba_setUInt8(&value->byteArr, DLMS_DATA_TYPE_BIT_STRING);
                    setObjectCount(se->execWeekdays.size, &value->byteArr);
                    ba_addRange(&value->byteArr, se->execWeekdays.data, bit_getByteCount(se->execWeekdays.size));

                    //Add exec spec days.
                    ba_setUInt8(&value->byteArr, DLMS_DATA_TYPE_BIT_STRING);
                    setObjectCount(se->execSpecDays.size, &value->byteArr);
                    ba_addRange(&value->byteArr, se->execSpecDays.data, bit_getByteCount(se->execSpecDays.size));

                    //Add begin date.
                    ret = var_setDateTime(&tmp, &se->beginDate);
                    if (ret != 0)
                    {
                        var_clear(&tmp);
                        break;
                    }
                    ret = var_getBytes(&tmp, &value->byteArr);
                    var_clear(&tmp);
                    if (ret != 0)
                    {
                        break;
                    }
                    //Add end date.
                    ret = var_setDateTime(&tmp, &se->endDate);
                    if (ret != 0)
                    {
                        var_clear(&tmp);
                        break;
                    }
                    ret = var_getBytes(&tmp, &value->byteArr);
                    var_clear(&tmp);
                    if (ret != 0)
                    {
                        break;
                    }
                }
                 * */
                return data.Array();
            }
            e.Error = ErrorCode.ReadWriteDenied;
            return null;
        }
Exemplo n.º 27
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         return PHYReference;
     }
     if (e.Index == 3)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (LCPOptions == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)IPCPOptions.Length);
             foreach (GXDLMSPppSetupLcpOption it in LCPOptions)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8((byte)3);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Type);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Length);
                 GXCommon.SetData(settings, data, GXCommon.GetValueType(it.Data), it.Data);
             }
         }
         return data.Array();
     }
     if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (IPCPOptions == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)IPCPOptions.Length);
             foreach (GXDLMSPppSetupIPCPOption it in IPCPOptions)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8((byte)3);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Type);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Length);
                 GXCommon.SetData(settings, data, GXCommon.GetValueType(it.Data), it.Data);
             }
         }
         return data.Array();
     }
     else if (e.Index == 5)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(settings, data, DataType.OctetString, UserName);
         GXCommon.SetData(settings, data, DataType.OctetString, Password);
         return data.Array();
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Exemplo n.º 28
0
 public byte[][] ImageTransferInitiate(GXDLMSClient client, string 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, ASCIIEncoding.ASCII.GetBytes(imageIdentifier));
     GXCommon.SetData(client.Settings, data, DataType.UInt32, imageSize);
     return client.Method(this, 1, data.Array(), DataType.Array);
 }
Exemplo n.º 29
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         return Value;
     }
     if (e.Index == 3)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(settings, data, DataType.Int8, scaler);
         GXCommon.SetData(settings, data, DataType.Enum, Unit);
         return data.Array();
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Exemplo n.º 30
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)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8((byte)2);
         GXCommon.SetData(client.Settings, 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(client.Settings, data, DataType.OctetString, tmp);
         packets.AddRange(client.Method(this, 2, data.Array(), DataType.Array));
     }
     return packets.ToArray();
 }
Exemplo n.º 31
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         return (byte)Mode;
     }
     if (e.Index == 3)
     {
         return Repetitions;
     }
     if (e.Index == 4)
     {
         return RepetitionDelay;
     }
     if (e.Index == 5)
     {
         int cnt = CallingWindow.Count;
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         //Add count
         GXCommon.SetObjectCount(cnt, data);
         if (cnt != 0)
         {
             foreach (var it in CallingWindow)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8((byte)2); //Count
                 GXCommon.SetData(settings, data, DataType.OctetString, it.Key); //start_time
                 GXCommon.SetData(settings, data, DataType.OctetString, it.Value); //end_time
             }
         }
         return data.Array();
     }
     if (e.Index == 6)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (Destinations == null)
         {
             //Add count
             GXCommon.SetObjectCount(0, data);
         }
         else
         {
             int cnt = Destinations.Length;
             //Add count
             GXCommon.SetObjectCount(cnt, data);
             foreach (string it in Destinations)
             {
                 GXCommon.SetData(settings, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(it)); //destination
             }
         }
         return data.Array();
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     if (e.Index == 2)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (RegisterAssignment == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)RegisterAssignment.Length);
             foreach (GXDLMSObjectDefinition it in RegisterAssignment)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8(2);
                 GXCommon.SetData(settings, data, DataType.UInt16, it.ClassId);
                 GXCommon.SetData(settings, data, DataType.OctetString, it.LogicalName);
             }
         }
         return data.Array();
     }
     if (e.Index == 3)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (MaskList == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)MaskList.Count);
             foreach (KeyValuePair<byte[], byte[]> it in MaskList)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8(2);
                 GXCommon.SetData(settings, data, DataType.OctetString, it.Key);
                 data.SetUInt8((byte)DataType.Array);
                 data.SetUInt8((byte)it.Value.Length);
                 foreach (byte b in it.Value)
                 {
                     GXCommon.SetData(settings, data, DataType.UInt8, b);
                 }
             }
         }
         return data.Array();
     }
     if (e.Index == 4)
     {
         return ActiveMask;
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }