Exemple #1
0
        public virtual GenericDevice Clone(ISubscribeCollectionFactory iSubscribeCollectionFactory)
        {
            GenericDevice ret = (GenericDevice)MemberwiseClone();

            ret.SpecificDevice = null;
            if (SpecificDevice != null)
            {
                ret.SpecificDevice = iSubscribeCollectionFactory.CreateCollection <SpecificDevice>();
                foreach (var item in SpecificDevice)
                {
                    SpecificDevice c = item.Clone();
                    c.Parent = ret;
                    ret.SpecificDevice.Add(c);
                }
            }
            return(ret);
        }
Exemple #2
0
        private IEnumerable <string> ParameterToString(IList <byte> list, zwParamType type, Collection <Define> defines)
        {
            IList <string> ret   = new List <string>();
            bool           first = true;
            StringBuilder  sb;

            switch (type)
            {
            case zwParamType.CHAR:

                try
                {
                    ret.Add(Encoding.ASCII.GetString(list.ToArray(), 0, list.Count));
                }
                catch (Exception dex)
                {
                    dex.Message._EXLOG();
                }
                break;

            case zwParamType.HEX:
                if (defines == null)
                {
                    ret.Add(Tools.GetHex(list));
                }
                else
                {
                    sb = new StringBuilder();
                    bool isFirst = true;
                    foreach (var itemByte in list)
                    {
                        string str = null;
                        foreach (var dItem in defines)
                        {
                            if (dItem.KeyId == itemByte)
                            {
                                str = dItem.Text;
                            }
                        }
                        if (!isFirst)
                        {
                            sb.Append(" ");
                        }
                        if (str != null)
                        {
                            sb.Append(str);
                            sb.Append("=");
                        }
                        sb.Append(Tools.GetHex(itemByte, true));
                        isFirst = false;
                    }
                    ret.Add(sb.ToString());
                }
                break;

            case zwParamType.NUMBER:
                if (list.Count <= 4)     //int
                {
                    byte[] val = { 0, 0, 0, 0 };
                    Array.Copy(list.Reverse().ToArray(), val, list.Count);
                    int tmp = BitConverter.ToInt32(val, 0);
                    sb = new StringBuilder();
                    if (defines != null)
                    {
                        string str = null;
                        foreach (var dItem in defines)
                        {
                            if (dItem.KeyId == tmp)
                            {
                                str = dItem.Text;
                            }
                        }
                        sb.Append(str ?? tmp.ToString());
                    }
                    else
                    {
                        if (tmp < 100)
                        {
                            sb.Append(tmp.ToString(""));
                        }
                        else
                        {
                            sb.Append(tmp.ToString());
                        }
                    }
                    ret.Add(sb.ToString());
                }
                else     // as HEX
                {
                    ret.Add(Tools.GetHex(list));
                }
                break;

            case zwParamType.NODE_NUMBER:
                sb = new StringBuilder();
                foreach (var item in list)
                {
                    if (!first)
                    {
                        sb.Append(", ");
                    }
                    first = false;
                    sb.Append(item.ToString(""));
                }
                ret.Add(sb.ToString());
                break;

            case zwParamType.BITMASK:
                sb = new StringBuilder();
                for (int i = 0; i < list.Count; i++)
                {
                    byte maskByte = list[i];
                    if (maskByte == 0)
                    {
                        continue;
                    }
                    byte bitMask = 0x01;
                    for (int j = 0; j < 8; j++)
                    {
                        if ((bitMask & maskByte) != 0)
                        {
                            byte bitNumber = (byte)(i * 8 + j);
                            if (!first)
                            {
                                sb.Append(", ");
                            }
                            first = false;
                            if (defines != null)
                            {
                                string str = null;
                                foreach (var dItem in defines)
                                {
                                    if (dItem.KeyId == bitNumber)
                                    {
                                        str = dItem.Text;
                                    }
                                }

                                if (str != null)
                                {
                                    sb.Append(str);
                                    sb.Append("=");
                                    sb.Append(Tools.GetHex(bitNumber, true));
                                }
                                else
                                {
                                    sb.Append(Tools.GetHex(bitNumber, true));
                                }
                            }
                            else
                            {
                                sb.Append((bitNumber + 1).ToString(""));     //nodes starting from 1 in mask bytes array
                            }
                        }
                        bitMask <<= 1;
                    }
                }
                ret.Add(sb.ToString());
                break;

            case zwParamType.BOOLEAN:
                if (list.Count > 0)
                {
                    if (defines == null)
                    {
                        ret.Add(list[0] > 0 ? "true" : "false");
                    }
                    else
                    {
                        string str = null;
                        foreach (var dItem in defines)
                        {
                            if (dItem.KeyId == list[0])
                            {
                                str = dItem.Text;
                            }
                        }
                        if (str != null)
                        {
                            ret.Add(str);
                        }
                        else
                        {
                            ret.Add(list[0] > 0 ? "true" : "false");
                        }
                    }
                }
                else
                {
                    ret.Add("false");
                }
                break;

            case zwParamType.MARKER:
                ret.Add(Tools.GetHex(list));
                break;

            case zwParamType.BAS_DEV_REF:
                foreach (var item in list)
                {
                    BasicDevice bd = BasicDevices.FirstOrDefault(x => x.Key == Tools.GetHex(item, true));
                    if (bd != null)
                    {
                        ret.Add(string.Format("{0} - {1}", Tools.GetHex(item, true), bd.Name));
                    }
                    else
                    {
                        ret.Add(Tools.GetHex(item, true));
                    }
                }
                break;

            case zwParamType.GEN_DEV_REF:
                foreach (var item in list)
                {
                    _genericDevice = GenericDevices.FirstOrDefault(x => x.Key == Tools.GetHex(item, true));
                    if (_genericDevice != null)
                    {
                        ret.Add(string.Format("{0} - {1}", Tools.GetHex(item, true), _genericDevice.Name));
                    }
                    else
                    {
                        ret.Add(Tools.GetHex(item, true));
                    }
                }
                break;

            case zwParamType.SPEC_DEV_REF:
                if (_genericDevice != null)
                {
                    foreach (var item in list)
                    {
                        SpecificDevice bd =
                            _genericDevice.SpecificDevice.FirstOrDefault(x => x.Key == Tools.GetHex(item, true));
                        if (bd != null)
                        {
                            ret.Add(string.Format("{0} - {1}", Tools.GetHex(item, true), bd.Name));
                        }
                        else
                        {
                            ret.Add(Tools.GetHex(item, true));
                        }
                    }
                }
                else
                {
                    ret.Add(Tools.GetHex(list));
                }
                break;

            case zwParamType.CMD_CLASS_REF:
                foreach (var item in list)
                {
                    _commandClass = CommandClasses.FirstOrDefault(x => x.Key == Tools.GetHex(item, true));
                    if (_commandClass != null)
                    {
                        ret.Add(string.Format("{0} - {1}", Tools.GetHex(item, true), _commandClass.Name));
                    }
                    else
                    {
                        ret.Add(Tools.GetHex(item, true));
                    }
                }
                break;

            case zwParamType.CMD_REF:
                if (_commandClass != null)
                {
                    foreach (var item in list)
                    {
                        if (_commandClass.Command != null)
                        {
                            _command = _commandClass.Command.FirstOrDefault(x => x.Key == Tools.GetHex(item, true));
                            if (_command != null)
                            {
                                ret.Add(string.Format("{0} - {1}", Tools.GetHex(item, true), _command.Name));
                            }
                            else
                            {
                                ret.Add(Tools.GetHex(item, true));
                            }
                        }
                        else
                        {
                            ret.Add(Tools.GetHex(item, true));
                        }
                    }
                }
                else
                {
                    ret.Add(Tools.GetHex(list));
                }
                break;

            case zwParamType.CMD_DATA:
                ret.Add(Tools.GetHex(list));
                break;

            case zwParamType.CMD_ENCAP:
                ret.Add(Tools.GetHex(list));
                break;
            }
            return(ret);
        }