Exemplo n.º 1
0
        /// <summary>
        /// Returns collection of push objects.
        /// </summary>
        /// <param name="data">Received data.</param>
        /// <returns>Array of objects and called indexes.</returns>
        public List <KeyValuePair <GXDLMSObject, int> > ParsePushObjects(GXByteBuffer data)
        {
            int          index;
            GXDLMSObject obj;
            object       value;
            DataType     dt;
            GXReplyData  reply = new GXReplyData();

            reply.Data = data;
            List <KeyValuePair <GXDLMSObject, int> > items = new List <KeyValuePair <GXDLMSObject, int> >();

            GXDLMS.GetValueFromData(Settings, reply);
            Object[] list = (Object[])reply.Value;
            GXDLMSObjectCollection objects = new GXDLMSObjectCollection();

            foreach (Object it in (Object[])list[0])
            {
                Object[] tmp     = (Object[])it;
                int      classID = ((UInt16)(tmp[0])) & 0xFFFF;
                if (classID > 0)
                {
                    GXDLMSObject comp;
                    comp = this.Objects.FindByLN((ObjectType)classID, GXDLMSObject.ToLogicalName(tmp[1] as byte[]));
                    if (comp == null)
                    {
                        comp = GXDLMSClient.CreateDLMSObject(classID, 0, 0, tmp[1], null);
                        objects.Add(comp);
                    }
                    if ((comp is IGXDLMSBase))
                    {
                        items.Add(new KeyValuePair <GXDLMSObject, int>(comp, (sbyte)tmp[2]));
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine(string.Format("Unknown object : {0} {1}",
                                                                         classID, GXDLMSObject.ToLogicalName((byte[])tmp[1])));
                    }
                }
            }
            for (int pos = 0; pos < list.Length; ++pos)
            {
                obj   = items[pos].Key as GXDLMSObject;
                value = list[pos];
                index = items[pos].Value;
                if (value is byte[] && (dt = obj.GetUIDataType(index)) != DataType.None)
                {
                    value = GXDLMSClient.ChangeType(value as byte[], dt);
                }
                (obj as IGXDLMSBase).SetValue(Settings, index, value);
            }
            return(items);
        }