private static void LoadClusters(JObject root) { foreach (JObject cluster in root.Values()) { ZclCluster cl = new ZclCluster(); cl.Name = cluster.Path; cl.Id = cluster["id"].Value <ushort>(); var attributes = cluster["attrId"]; foreach (JProperty attr in attributes) { ZclAttribute zclAttribute = new ZclAttribute(); zclAttribute.Name = attr.Name; foreach (JObject info in attr) { zclAttribute.Id = info.GetValue("id").Value <ushort>(); zclAttribute.DataType = (DataType)info.GetValue("type").Value <int>(); } cl.Attributes.Add(zclAttribute); } JToken reqCmds = cluster["cmd"]; foreach (JProperty cmd in reqCmds) { ZclClusterCommand fc = ClusterCommands.SingleOrDefault(f => f.ClusterName == cl.Name && f.Name == cmd.Name && f.Direction == Direction.ClientToServer); if (fc != null) { fc.Id = cmd.Value.Value <byte>(); fc.Cluster = cl; cl.Requests.Add(fc); } } var rspCmds = cluster["cmdRsp"]; foreach (JProperty cmd in rspCmds) { ZclClusterCommand fc = ClusterCommands.SingleOrDefault(f => f.ClusterName == cl.Name && f.Name == cmd.Name && f.Direction == Direction.ServerToClient); if (fc != null) { fc.Id = cmd.Value.Value <byte>(); fc.Cluster = cl; cl.Responses.Add(fc); } } _clusters.Add(cl); } }
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); } } } }