コード例 #1
0
        /// <summary>
        /// Reserved for internal use.
        /// </summary>
        internal void EncodeData(byte[] data, ref int index)
        {
            int tag = data[index++];

            if (tag != 0xBE)
            {
                throw new Exception("Invalid tag.");
            }
            int len = data[index++];

            if (data.Length - index < len)
            {
                throw new Exception("Not enough data.");
            }
            //Excoding the choice for user information
            tag = data[index++];
            if (tag != 0x4)
            {
                throw new Exception("Invalid tag.");
            }
            len = data[index++];
            //Tag for xDLMS-Initate.response
            tag = data[index++];
            bool response = tag == GXCommon.InitialResponce;

            if (response)
            {
                //Optional usage field of the negotiated quality of service component
                tag = data[index++];
                if (tag != 0)//Skip if used.
                {
                    len    = data[index++];
                    index += len;
                }
            }
            else if (tag == GXCommon.InitialRequest)
            {
                //Optional usage field of the negotiated quality of service component
                tag = data[index++];
                if (tag != 0)//Skip if used.
                {
                    len    = data[index++];
                    index += len;
                }
                //Optional usage field of the negotiated quality of service component
                tag = data[index++];
                if (tag != 0)//Skip if used.
                {
                    len    = data[index++];
                    index += len;
                }
                //Optional usage field of the negotiated quality of service component
                tag = data[index++];
                if (tag != 0)//Skip if used.
                {
                    len    = data[index++];
                    index += len;
                }
            }
            else
            {
                throw new Exception("Invalid tag.");
            }
            //Get DLMS version number.
            DLMSVersioNumber = data[index++];
            //Tag for conformance block
            tag = data[index++];
            if (tag != 0x5F)
            {
                throw new Exception("Invalid tag.");
            }
            //Old Way...
            if (data[index] == 0x1F)
            {
                ++index;
            }
            len = data[index++];
            //The number of unused bits in the bit string.
            tag = data[index++];
            Array.Copy(data, index, ConformanceBlock, 0, 3);
            index            += 3;
            MaxReceivePDUSize = GXCommon.GetUInt16(data, ref index);
            if (response)
            {
                //VAA Name
                tag = data[index++];
                tag = data[index++];
            }
        }
コード例 #2
0
 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)
     {
         ObjectList.Clear();
         if (value != null)
         {
             foreach (Object[] item in (Object[])value)
             {
                 ObjectType   type    = (ObjectType)Convert.ToInt32(item[0]);
                 int          version = Convert.ToInt32(item[1]);
                 String       ln      = GXDLMSObject.toLogicalName((byte[])item[2]);
                 GXDLMSObject obj     = null;
                 if (Parent != null)
                 {
                     obj = Parent.FindByLN(type, ln);
                 }
                 if (obj == null)
                 {
                     obj             = Gurux.DLMS.GXDLMSClient.CreateObject(type);
                     obj.LogicalName = ln;
                     obj.Version     = version;
                 }
                 //Unknown objects are not shown.
                 if (obj is IGXDLMSBase)
                 {
                     UpdateAccessRights(obj, (Object[])item[3]);
                     ObjectList.Add(obj);
                 }
             }
         }
     }
     else if (index == 3)
     {
         ClientSAP = Convert.ToByte(((Object[])value)[0]);
         ServerSAP = Convert.ToUInt16(((Object[])value)[1]);
     }
     else if (index == 4)
     {
         //Value of the object identifier encoded in BER
         if (value is byte[])
         {
             int    pos = -1;
             byte[] arr = value as byte[];
             if (arr[0] == 0x60)
             {
                 ApplicationContextName.JointIsoCtt = 0;
                 ++pos;
                 ApplicationContextName.Country = 0;
                 ++pos;
                 ApplicationContextName.CountryName = 0;
                 ++pos;
                 ApplicationContextName.IdentifiedOrganization = arr[++pos];
                 ApplicationContextName.DlmsUA             = arr[++pos];
                 ApplicationContextName.ApplicationContext = arr[++pos];
                 ApplicationContextName.ContextId          = arr[++pos];
             }
             else
             {
                 //Get Tag and Len.
                 if (arr[++pos] != (int)GXBer.IntegerTag && arr[++pos] != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.JointIsoCtt = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.Country = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.CountryName = GXCommon.GetUInt16(arr, ref pos);
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.IdentifiedOrganization = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.DlmsUA = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ApplicationContext = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ContextId = arr[++pos];
             }
         }
         else
         {
             Object[] arr = (Object[])value;
             ApplicationContextName.JointIsoCtt            = Convert.ToByte(arr[0]);
             ApplicationContextName.Country                = Convert.ToByte(arr[1]);
             ApplicationContextName.CountryName            = Convert.ToUInt16(arr[2]);
             ApplicationContextName.IdentifiedOrganization = Convert.ToByte(arr[3]);
             ApplicationContextName.DlmsUA             = Convert.ToByte(arr[4]);
             ApplicationContextName.ApplicationContext = Convert.ToByte(arr[5]);
             ApplicationContextName.ContextId          = Convert.ToByte(arr[6]);
         }
     }
     else if (index == 5)
     {
         Object[] arr = (Object[])value;
         XDLMSContextInfo.Conformance       = arr[0].ToString();
         XDLMSContextInfo.MaxReceivePduSize = Convert.ToUInt16(arr[1]);
         XDLMSContextInfo.MaxSendPpuSize    = Convert.ToUInt16(arr[2]);
         XDLMSContextInfo.DlmsVersionNumber = Convert.ToByte(arr[3]);
         XDLMSContextInfo.QualityOfService  = Convert.ToSByte(arr[4]);
         XDLMSContextInfo.CypheringInfo     = (byte[])arr[5];
     }
     else if (index == 6)
     {
         //Value of the object identifier encoded in BER
         if (value is byte[])
         {
             int    pos = -1;
             byte[] arr = value as byte[];
             if (arr[0] == 0x60)
             {
                 AuthenticationMechanismMame.JointIsoCtt = 0;
                 ++pos;
                 AuthenticationMechanismMame.Country = 0;
                 ++pos;
                 AuthenticationMechanismMame.CountryName = 0;
                 ++pos;
                 AuthenticationMechanismMame.IdentifiedOrganization = arr[++pos];
                 AuthenticationMechanismMame.DlmsUA = arr[++pos];
                 AuthenticationMechanismMame.AuthenticationMechanismName = arr[++pos];
                 AuthenticationMechanismMame.MechanismId = (Authentication)arr[++pos];
             }
             else
             {
                 //Get Tag and Len.
                 if (arr[++pos] != (int)GXBer.IntegerTag && arr[++pos] != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.JointIsoCtt = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.Country = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.CountryName = GXCommon.GetUInt16(arr, ref pos);
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.IdentifiedOrganization = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.DlmsUA = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.AuthenticationMechanismName = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.MechanismId = (Authentication)arr[++pos];
             }
         }
         else
         {
             Object[] arr = (Object[])value;
             AuthenticationMechanismMame.JointIsoCtt            = Convert.ToByte(arr[0]);
             AuthenticationMechanismMame.Country                = Convert.ToByte(arr[1]);
             AuthenticationMechanismMame.CountryName            = Convert.ToUInt16(arr[2]);
             AuthenticationMechanismMame.IdentifiedOrganization = Convert.ToByte(arr[3]);
             AuthenticationMechanismMame.DlmsUA = Convert.ToByte(arr[4]);
             AuthenticationMechanismMame.AuthenticationMechanismName = Convert.ToByte(arr[5]);
             AuthenticationMechanismMame.MechanismId = (Authentication)Convert.ToByte(arr[6]);
         }
     }
     else if (index == 7)
     {
         Secret = (byte[])value;
     }
     else if (index == 8)
     {
         if (value == null)
         {
             AssociationStatus = AssociationStatus.NonAssociated;
         }
         else
         {
             AssociationStatus = (AssociationStatus)Convert.ToInt32(value);
         }
     }
     else if (index == 9)
     {
         SecuritySetupReference = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }