예제 #1
0
        private static void LoadClusterCommands(JObject root)
        {
            JToken jFunctional = root.GetValue("functional");

            foreach (JProperty cluster in jFunctional)
            {
                string clusterName = cluster.Name;

                foreach (JObject jToken in cluster)
                {
                    foreach (var cmd in jToken)
                    {
                        ZclClusterCommand zclCommand = new ZclClusterCommand();

                        zclCommand.Name        = cmd.Key;
                        zclCommand.ClusterName = cluster.Name;
                        zclCommand.Direction   = (Direction)cmd.Value["dir"].ToObject <int>();

                        var paramCollection = cmd.Value["params"];

                        foreach (JObject pObject in paramCollection)
                        {
                            foreach (var p in pObject)
                            {
                                ZclCommandParam param = new ZclCommandParam()
                                {
                                    Name = p.Key
                                };
                                if (p.Value.Type == JTokenType.Integer)
                                {
                                    param.DataType = (DataType)p.Value.ToObject <int>();
                                }
                                else if (p.Value.Type == JTokenType.String)
                                {
                                    param.SpecialType = p.Value.ToObject <string>();
                                }
                                else
                                {
                                    throw new NotImplementedException($"Param type {p.Value.Type.ToString()} not implemented");
                                }

                                zclCommand.Params.Add(param);
                            }
                        }

                        _clusterCommands.Add(zclCommand);
                    }
                }
            }
        }
예제 #2
0
        private static void LoadGlobalCommands(JObject root)
        {
            JToken jFoundation = root.GetValue("foundation");

            foreach (JProperty command in jFoundation)
            {
                ZclGlobalCommand zclCommand = new ZclGlobalCommand();

                zclCommand.Id          = command.Value["id"].Value <byte>();
                zclCommand.Name        = command.Name;
                zclCommand.KnownBufLen = command.Value["knownBufLen"].Value <int>();

                var paramCollection = command.Value["params"];

                foreach (JObject pObject in paramCollection)
                {
                    foreach (var p in pObject)
                    {
                        ZclCommandParam param = new ZclCommandParam()
                        {
                            Name = p.Key
                        };
                        if (p.Value.Type == JTokenType.Integer)
                        {
                            param.DataType = (DataType)p.Value.ToObject <int>();
                        }
                        else if (p.Value.Type == JTokenType.String)
                        {
                            param.SpecialType = p.Value.ToObject <string>();
                        }
                        else
                        {
                            throw new NotImplementedException($"Param type {p.Value.Type.ToString()} not implemented");
                        }

                        zclCommand.Params.Add(param);
                    }
                }

                GlobalCommands.Add(zclCommand);
            }
        }