Skip to content

Commit 9820218

Browse files
committed
Generate some more clusters
1 parent 4e4f5e6 commit 9820218

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+10281
-40
lines changed

Generator/ClusterGenerator.cs

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void Generate()
3737
if (cluster == null)
3838
throw new IOException("Failed to parse cluster " + clusterxml);
3939
if (!string.IsNullOrEmpty(cluster.clusterIds.clusterId.id))
40-
clusterBase.WriteLine($" case {cluster.name.Replace(" ", "").Replace('/', '_')}.CLUSTER_ID:\n return new {cluster.name.Replace(" ", "").Replace('/', '_')}(endPoint);");
40+
clusterBase.WriteLine($" case {GeneratorUtil.SanitizeClassName(cluster.name)}.CLUSTER_ID:\n return new {GeneratorUtil.SanitizeClassName(cluster.name)}(endPoint);");
4141
WriteClass(cluster);
4242
}
4343
}
@@ -95,7 +95,7 @@ private static void WriteClass(Cluster cluster, TextWriter writer)
9595
if (string.IsNullOrEmpty(cluster.classification.baseCluster) && !string.IsNullOrEmpty(cluster.clusterIds.clusterId.id))
9696
writer.WriteLine($" /// <inheritdoc />\n protected {GeneratorUtil.SanitizeClassName(cluster.name)}(uint cluster, ushort endPoint) : base(cluster, endPoint) {{ }}");
9797
writer.WriteLine();
98-
if (cluster.dataTypes?.@enum != null || (cluster.features != null && cluster.features.Length > 0))
98+
if (cluster.dataTypes?.@enum != null || cluster.dataTypes?.bitmap != null || (cluster.features != null && cluster.features.Length > 0))
9999
{
100100
writer.WriteLine(" #region Enums");
101101
bool firstEnum=true;
@@ -174,7 +174,7 @@ private static void WriteClass(Cluster cluster, TextWriter writer)
174174
WriteCommands(cluster, writer);
175175
}
176176

177-
if (cluster.attributes.Length > 0 || (cluster.features != null && cluster.features.Length > 0))
177+
if ((cluster.attributes != null && cluster.attributes.Length > 0) || (cluster.features != null && cluster.features.Length > 0))
178178
{
179179
writer.WriteLine(" #region Attributes");
180180
bool firstAttribute = true;
@@ -183,15 +183,18 @@ private static void WriteClass(Cluster cluster, TextWriter writer)
183183
firstAttribute = false;
184184
WriteFeatureFunctions(writer);
185185
}
186-
foreach (var attribute in cluster.attributes)
186+
if (cluster.attributes != null && cluster.attributes.Length > 0)
187187
{
188-
if (attribute.type != null)
188+
foreach (var attribute in cluster.attributes)
189189
{
190-
if (firstAttribute)
191-
firstAttribute = false;
192-
else
193-
writer.WriteLine();
194-
WriteAttribute(cluster, attribute, writer);
190+
if (attribute.type != null && attribute?.mandatoryConform?.condition?.name != "Zigbee")
191+
{
192+
if (firstAttribute)
193+
firstAttribute = false;
194+
else
195+
writer.WriteLine();
196+
WriteAttribute(cluster, attribute, writer);
197+
}
195198
}
196199
}
197200
writer.WriteLine(" #endregion Attributes");
@@ -231,7 +234,7 @@ private static void WriteStruct(clusterCommand command, bool toServer, TextWrite
231234
if (field.type.EndsWith("Enum"))
232235
writer.WriteLine(" = " + field.type + "." + field.@default + ";");
233236
else
234-
writer.WriteLine(" = " + SanitizeDefault(field.@default, field.type) + ";");
237+
writer.WriteLine(" = " + SanitizeDefault(field.@default, field.type, field.entry?.type) + ";");
235238
}
236239
else
237240
writer.WriteLine();
@@ -375,6 +378,7 @@ private static void WriteStructType(bool optional, bool nullable, string type, s
375378
case "namespace":
376379
case "fabric-idx":
377380
case "action-id":
381+
case "percent":
378382
writer.Write($"{totalIndent}writer.WriteByte({id}, {name}");
379383
if (to != null)
380384
writer.Write($", {to.Value}");
@@ -521,11 +525,13 @@ private static void WriteStructType(bool optional, bool nullable, string type, s
521525
case "ref_IpAdr":
522526
case "ref_Ipv4Adr":
523527
case "ref_Ipv6Adr":
528+
case "ipv6adr":
524529
if (nullable && !optional)
525530
writer.Write($"{totalIndent}if ({name} == null)\n{totalIndent} writer.WriteNull({id});\n{totalIndent}else\n ");
526531
writer.WriteLine($"{totalIndent}writer.WriteBytes({id}, {name}.GetAddressBytes());");
527532
return;
528533
case "Hardware Address":
534+
case "hwadr":
529535
if (nullable && !optional)
530536
writer.Write($"{totalIndent}if ({name} == null)\n{totalIndent} writer.WriteNull({id});\n{totalIndent}else\n ");
531537
writer.WriteLine($"{totalIndent}writer.WriteBytes({id}, {name}.GetAddressBytes());");
@@ -623,6 +629,7 @@ private static void WriteFieldReader(bool optional, bool nullable, string type,
623629
case "namespace":
624630
case "fabric-idx":
625631
case "action-id":
632+
case "percent":
626633
writer.Write($"reader.GetByte({id}");
627634
break;
628635
case "uint16":
@@ -672,9 +679,11 @@ private static void WriteFieldReader(bool optional, bool nullable, string type,
672679
writer.WriteLine($"new IPAddress(reader.GetBytes({id}, {(optional ? "true" : "false")}, 4, 4{(id == "-1" || id == "i" ? ")!))" : ")!)")};");
673680
return;
674681
case "ref_Ipv6Adr":
682+
case "ipv6adr":
675683
writer.WriteLine($"new IPAddress(reader.GetBytes({id}, {(optional ? "true" : "false")}, 16, 16{(id == "-1" || id == "i" ? ")!))" : ")!)")};");
676684
return;
677685
case "Hardware Address":
686+
case "hwadr":
678687
writer.WriteLine($"new PhysicalAddress(reader.GetBytes({id}, {(optional ? "true" : "false")}, 8, 6{(id == "-1" || id == "i" ? ")!))" : ")!)")};");
679688
return;
680689
case "epoch-s":
@@ -764,7 +773,7 @@ private static void WriteFieldReader(bool optional, bool nullable, string type,
764773
else if (id == "i")
765774
writer.WriteLine("(reader.GetStruct(i)!));");
766775
else
767-
writer.WriteLine($"fields[{id}]);");
776+
writer.WriteLine($"((object[])fields[{id}]);");
768777
}
769778
return;
770779
}
@@ -786,7 +795,7 @@ private static void WriteFieldReader(bool optional, bool nullable, string type,
786795

787796
private static bool HasEnum(Cluster cluster, string name)
788797
{
789-
if (cluster.dataTypes.@enum == null)
798+
if (cluster.dataTypes?.@enum == null)
790799
return false;
791800
foreach (clusterDataTypesEnum enumType in cluster.dataTypes.@enum)
792801
{
@@ -798,7 +807,7 @@ private static bool HasEnum(Cluster cluster, string name)
798807

799808
private static bool HasEnumValue(Cluster cluster, string name, string value)
800809
{
801-
if (cluster.dataTypes.@enum == null)
810+
if (cluster.dataTypes?.@enum == null)
802811
return false;
803812
foreach (clusterDataTypesEnum enumType in cluster.dataTypes.@enum)
804813
{
@@ -816,7 +825,7 @@ private static bool HasEnumValue(Cluster cluster, string name, string value)
816825

817826
private static bool HasBitmap(Cluster cluster, string name)
818827
{
819-
if (cluster.dataTypes.bitmap == null)
828+
if (cluster.dataTypes?.bitmap == null)
820829
return false;
821830
foreach (clusterDataTypesBitfield bitfieldType in cluster.dataTypes.bitmap)
822831
{
@@ -828,7 +837,7 @@ private static bool HasBitmap(Cluster cluster, string name)
828837

829838
private static bool HasBitmapValue(Cluster cluster, string name, string value)
830839
{
831-
if (cluster.dataTypes.bitmap == null)
840+
if (cluster.dataTypes?.bitmap == null)
832841
return false;
833842
foreach (clusterDataTypesBitfield bitfieldType in cluster.dataTypes.bitmap)
834843
{
@@ -846,7 +855,7 @@ private static bool HasBitmapValue(Cluster cluster, string name, string value)
846855

847856
private static bool HasStruct(Cluster cluster, string name)
848857
{
849-
if (cluster.dataTypes.@struct == null)
858+
if (cluster.dataTypes?.@struct == null)
850859
return false;
851860
foreach (clusterDataTypesStruct structType in cluster.dataTypes.@struct)
852861
{
@@ -1024,7 +1033,7 @@ private static void WriteRecord(clusterDataTypesStruct structType, Cluster clust
10241033
if (HasEnum(cluster, field.type) || HasBitmap(cluster, field.type))
10251034
writer.WriteLine(" = " + field.type + "." + field.@default + ";");
10261035
else
1027-
writer.WriteLine(" = " + SanitizeDefault(field.@default!, field.type) + ";");
1036+
writer.WriteLine(" = " + SanitizeDefault(field.@default!, field.type, field.entry?.type) + ";");
10281037
}
10291038
else
10301039
writer.WriteLine();
@@ -1079,9 +1088,12 @@ private static void WriteEnum(clusterDataTypesEnum enumType, TextWriter writer)
10791088
writer.WriteLine(" public enum " + GeneratorUtil.SanitizeName(enumType.name) + " {");
10801089
foreach (clusterDataTypesEnumItem item in enumType.item)
10811090
{
1082-
if (item.summary != null)
1083-
writer.WriteLine(" /// <summary>\n /// " + item.summary.Replace("[[ref_", "<see cref=\"").Replace("]]", "\"/>") + "\n /// </summary>");
1084-
writer.WriteLine(" " + item.name + " = " + item.value + ",");
1091+
if (!string.IsNullOrWhiteSpace(item.value))
1092+
{
1093+
if (item.summary != null)
1094+
writer.WriteLine(" /// <summary>\n /// " + item.summary.Replace("[[ref_", "<see cref=\"").Replace("]]", "\"/>") + "\n /// </summary>");
1095+
writer.WriteLine(" " + GeneratorUtil.SanitizeName(item.name) + " = " + item.value + ",");
1096+
}
10851097
}
10861098
writer.WriteLine(" }");
10871099
}
@@ -1097,7 +1109,7 @@ private static void WriteBitfield(clusterDataTypesBitfield enumType, TextWriter
10971109
{
10981110
if (item.summary != null)
10991111
writer.WriteLine(" /// <summary>\n /// " + item.summary.Replace("[[ref_", "<see cref=\"").Replace("]]", "\"/>") + "\n /// </summary>");
1100-
writer.WriteLine(" " + item.name + " = " + (1<<item.bit) + ",");
1112+
writer.WriteLine(" " + GeneratorUtil.SanitizeName(item.name) + " = " + (1<<item.bit) + ",");
11011113
}
11021114
writer.WriteLine(" }");
11031115
}
@@ -1194,7 +1206,7 @@ private static void WriteAttribute(Cluster cluster, clusterAttribute attribute,
11941206
writer.WriteLine(";");
11951207
writer.WriteLine(" }");
11961208
}
1197-
if (attribute?.access?.write == true)
1209+
if (attribute?.access?.write == "true" || attribute?.access?.write == "optional")
11981210
{
11991211
if (attribute.access.read)
12001212
writer.WriteLine();
@@ -1233,6 +1245,7 @@ private static void WriteType(string type, string? entryType, TextWriter writer)
12331245
case "namespace":
12341246
case "fabric-idx":
12351247
case "action-id":
1248+
case "percent":
12361249
writer.Write("byte");
12371250
break;
12381251
case "uint16":
@@ -1317,10 +1330,12 @@ private static void WriteType(string type, string? entryType, TextWriter writer)
13171330
case "ref_IpAdr":
13181331
case "ref_Ipv4Adr":
13191332
case "ref_Ipv6Adr":
1333+
case "ipv6adr":
13201334
includes.Add("System.Net");
13211335
writer.Write("IPAddress");
13221336
break;
13231337
case "Hardware Address":
1338+
case "hwadr": //This is the most non-standard standard i've ever worked with
13241339
includes.Add("System.Net.NetworkInformation");
13251340
writer.Write("PhysicalAddress");
13261341
break;
@@ -1349,7 +1364,7 @@ private static void WriteType(string type, string? entryType, TextWriter writer)
13491364
}
13501365
}
13511366

1352-
private static string SanitizeDefault(string value, string? type = null, string? listType = null)
1367+
private static string SanitizeDefault(string value, string? type, string? listType)
13531368
{
13541369
if (value == "\"")
13551370
return "\"\"";
@@ -1374,6 +1389,8 @@ private static string SanitizeDefault(string value, string? type = null, string?
13741389
return value;
13751390
if (value == "0" && (type == "epoch-s" || type == "epoch-us"))
13761391
return "TimeUtil.EPOCH";
1392+
if (type == "elapsed-s")
1393+
return $"TimeSpan.FromSeconds({value})";
13771394
return value.ToLowerInvariant();
13781395
}
13791396

@@ -1385,6 +1402,8 @@ private static bool DefaultValid(string value)
13851402
return false;
13861403
if (value == "-")
13871404
return false;
1405+
if (value == "PhysicalMinLevel" || value == "PhysicalMaxLevel")
1406+
return false;
13881407
return true;
13891408
}
13901409
}

Generator/Clusters/AirQuality.xml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Copyright (C) Connectivity Standards Alliance (2023). All rights reserved.
4+
The information within this document is the property of the Connectivity
5+
Standards Alliance and its use and disclosure are restricted, except as
6+
expressly set forth herein.
7+
8+
Connectivity Standards Alliance hereby grants you a fully-paid, non-exclusive,
9+
nontransferable, worldwide, limited and revocable license (without the right to
10+
sublicense), under Connectivity Standards Alliance's applicable copyright
11+
rights, to view, download, save, reproduce and use the document solely for your
12+
own internal purposes and in accordance with the terms of the license set forth
13+
herein. This license does not authorize you to, and you expressly warrant that
14+
you shall not: (a) permit others (outside your organization) to use this
15+
document; (b) post or publish this document; (c) modify, adapt, translate, or
16+
otherwise change this document in any manner or create any derivative work
17+
based on this document; (d) remove or modify any notice or label on this
18+
document, including this Copyright Notice, License and Disclaimer. The
19+
Connectivity Standards Alliance does not grant you any license hereunder other
20+
than as expressly stated herein.
21+
22+
Elements of this document may be subject to third party intellectual property
23+
rights, including without limitation, patent, copyright or trademark rights,
24+
and any such third party may or may not be a member of the Connectivity
25+
Standards Alliance. Connectivity Standards Alliance members grant other
26+
Connectivity Standards Alliance members certain intellectual property rights as
27+
set forth in the Connectivity Standards Alliance IPR Policy. Connectivity
28+
Standards Alliance members do not grant you any rights under this license. The
29+
Connectivity Standards Alliance is not responsible for, and shall not be held
30+
responsible in any manner for, identifying or failing to identify any or all
31+
such third party intellectual property rights. Please visit www.csa-iot.org for
32+
more information on how to become a member of the Connectivity Standards
33+
Alliance.
34+
35+
This document and the information contained herein are provided on an “AS IS”
36+
basis and the Connectivity Standards Alliance DISCLAIMS ALL WARRANTIES EXPRESS
37+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO (A) ANY WARRANTY THAT THE USE OF THE
38+
INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OF THIRD PARTIES (INCLUDING
39+
WITHOUT LIMITATION ANY INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENT, COPYRIGHT
40+
OR TRADEMARK RIGHTS); OR (B) ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
41+
FOR A PARTICULAR PURPOSE, TITLE OR NONINFRINGEMENT. IN NO EVENT WILL THE
42+
CONNECTIVITY STANDARDS ALLIANCE BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF
43+
BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF BUSINESS, OR FOR ANY OTHER
44+
DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
45+
DAMAGES OF ANY KIND, IN CONTRACT OR IN TORT, IN CONNECTION WITH THIS DOCUMENT
46+
OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
47+
LOSS OR DAMAGE.
48+
49+
All company, brand and product names in this document may be trademarks that
50+
are the sole property of their respective owners.
51+
52+
This notice and disclaimer must be included on all copies of this document.
53+
54+
Connectivity Standards Alliance
55+
508 Second Street, Suite 206
56+
Davis, CA 95616, USA
57+
58+
:xrefstyle: basic
59+
-->
60+
<cluster xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="types types.xsd cluster cluster.xsd" id="0x005B" name="Air Quality Cluster" revision="1">
61+
<revisionHistory>
62+
<revision revision="1" summary="Initial version of the Air Quality cluster"/>
63+
</revisionHistory>
64+
<clusterIds>
65+
<clusterId id="0x005B" name="Air Quality"/>
66+
</clusterIds>
67+
<classification hierarchy="base" role="application" picsCode="AIRQUAL" scope="Endpoint"/>
68+
<features>
69+
<feature bit="0" code="FAIR" name="Fair" summary="Cluster supports the Fair air quality level">
70+
<optionalConform/>
71+
</feature>
72+
<feature bit="1" code="MOD" name="Moderate" summary="Cluster supports the Moderate air quality level">
73+
<optionalConform/>
74+
</feature>
75+
<feature bit="2" code="VPOOR" name="VeryPoor" summary="Cluster supports the Very poor air quality level">
76+
<optionalConform/>
77+
</feature>
78+
<feature bit="3" code="XPOOR" name="ExtremelyPoor" summary="Cluster supports the Extremely poor air quality level">
79+
<optionalConform/>
80+
</feature>
81+
</features>
82+
<dataTypes>
83+
<enum name="AirQualityEnum">
84+
<item value="0" name="Unknown" summary="The air quality is unknown.">
85+
<mandatoryConform/>
86+
</item>
87+
<item value="1" name="Good" summary="The air quality is good.">
88+
<mandatoryConform/>
89+
</item>
90+
<item value="2" name="Fair" summary="The air quality is fair.">
91+
<mandatoryConform>
92+
<feature name="FAIR"/>
93+
</mandatoryConform>
94+
</item>
95+
<item value="3" name="Moderate" summary="The air quality is moderate.">
96+
<mandatoryConform>
97+
<feature name="MOD"/>
98+
</mandatoryConform>
99+
</item>
100+
<item value="4" name="Poor" summary="The air quality is poor.">
101+
<mandatoryConform/>
102+
</item>
103+
<item value="5" name="VeryPoor" summary="The air quality is very poor.">
104+
<mandatoryConform>
105+
<feature name="VPOOR"/>
106+
</mandatoryConform>
107+
</item>
108+
<item value="6" name="ExtremelyPoor" summary="The air quality is extremely poor.">
109+
<mandatoryConform>
110+
<feature name="XPOOR"/>
111+
</mandatoryConform>
112+
</item>
113+
</enum>
114+
</dataTypes>
115+
<attributes>
116+
<attribute id="0x0000" name="AirQuality" type="AirQualityEnum" default="0">
117+
<access read="true" readPrivilege="view"/>
118+
<mandatoryConform/>
119+
<constraint type="desc"/>
120+
</attribute>
121+
</attributes>
122+
</cluster>

0 commit comments

Comments
 (0)