Skip to content

Commit

Permalink
More work on cluster generation (commissioning is now working)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdomnitz committed Dec 18, 2024
1 parent 346f5e8 commit ea966f0
Show file tree
Hide file tree
Showing 10 changed files with 680 additions and 32 deletions.
43 changes: 26 additions & 17 deletions Generator/ClusterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ private static void WriteClass(Cluster cluster, StreamWriter writer)

writer.WriteLine(" // Attributes");
foreach (var attribute in cluster.attributes)
WriteAttribute(attribute, writer);
{
if (attribute.type != null)
WriteAttribute(attribute, writer);
}

writer.WriteLine(" }");
writer.Write("}");
Expand All @@ -93,10 +96,12 @@ private static void WriteStruct(clusterCommand command, bool toServer, StreamWri
writer.WriteLine($" {(toServer ? "private record" : "public struct")} " + GeneratorUtil.SanitizeName(command.name) + (toServer ? "Payload : TLVPayload {" : " {"));
foreach (clusterCommandField field in command.field)
{
if (field.type == null) //Reserved/removed fields
continue;
writer.Write(" public ");
if (field.optionalConform == null)
writer.Write("required ");
WriteType(field.type, null, writer);
WriteType(field.type, field.entry?.type, writer);
if (field.optionalConform != null)
writer.Write("?");
if (field.name == GeneratorUtil.SanitizeName(command.name))
Expand Down Expand Up @@ -208,9 +213,9 @@ private static void WriteStructType(bool optional, string type, byte id, string
case "uint56":
case "uint64":
case "epoch-us":
case "posix-ms":
case "ref_DataTypePosixMs":
case "systime-us":
case "systime-ms":
case "ref_DataTypeSystemTimeMs":
case "fabric-id":
case "node-id":
case "EUI64":
Expand All @@ -225,11 +230,11 @@ private static void WriteStructType(bool optional, string type, byte id, string
writer.WriteLine($"{totalIndent}writer.WriteDouble({id}, {name});");
break;
case "octstr":
case "ipadr":
case "ipv4adr":
case "ipv6adr":
case "ref_IpAdr":
case "ref_Ipv4Adr":
case "ref_Ipv6Adr":
case "ipv6pre":
case "hwadr":
case "Hardware Address":
writer.WriteLine($"{totalIndent}writer.WriteBytes({id}, {name});");
break;
case "string":
Expand Down Expand Up @@ -274,8 +279,12 @@ private static void WriteCommands(Cluster cluster, StreamWriter writer)
{
foreach (var field in cmd.field)
{
if (field.type == null)
continue;
writer.Write(", ");
WriteType(field.type, null, writer);
WriteType(field.type, field.entry?.type, writer);
if (field.optionalConform != null)
writer.Write('?');
writer.Write(" " + field.name);
}
}
Expand All @@ -290,7 +299,7 @@ private static void WriteCommands(Cluster cluster, StreamWriter writer)
}
else
{
if (cmd.response != "N")
if (cmd.response == "N")
writer.WriteLine(" await InteractionManager.SendCommand(session, endPoint, CLUSTER_ID, " + cmd.id + ");");
else
writer.WriteLine(" InvokeResponseIB resp = await InteractionManager.ExecCommand(session, endPoint, CLUSTER_ID, " + cmd.id + ");");
Expand All @@ -308,7 +317,7 @@ private static void WriteCommands(Cluster cluster, StreamWriter writer)
foreach (var field in response.field)
{
writer.Write(" " + field.name + " = (");
WriteType(field.type, null, writer);
WriteType(field.type, field.entry?.type, writer);
if (field.optionalConform != null)
writer.WriteLine($"?)GetOptionalField(resp, {field.id}),");
else
Expand Down Expand Up @@ -439,9 +448,9 @@ private static void WriteType(string type, string? entryType, StreamWriter write
case "uint56":
case "uint64":
case "epoch-us":
case "posix-ms":
case "ref_DataTypePosixMs":
case "systime-us":
case "systime-ms":
case "ref_DataTypeSystemTimeMs":
case "fabric-id":
case "node-id":
case "EUI64":
Expand Down Expand Up @@ -479,11 +488,11 @@ private static void WriteType(string type, string? entryType, StreamWriter write
writer.Write("float");
break;
case "octstr":
case "ipadr":
case "ipv4adr":
case "ipv6adr":
case "ref_IpAdr":
case "ref_Ipv4Adr":
case "ref_Ipv6Adr":
case "ipv6pre":
case "hwadr":
case "Hardware Address":
writer.Write("byte[]");
break;
case "bool":
Expand Down
Loading

0 comments on commit ea966f0

Please sign in to comment.