Added BaseMessages with messageid
This commit is contained in:
parent
09e2afe329
commit
73a7c8469a
@ -27,7 +27,7 @@ type ProtoMessage struct {
|
||||
type ProtoMessagePayload struct {
|
||||
Name string `json:"name"`
|
||||
DataType string `json:"type"`
|
||||
ArrayLength int `json:"array,omitempty"`
|
||||
ArrayLength int `json:"array,omitempty"` // optional falls kein array
|
||||
}
|
||||
|
||||
type Proto struct {
|
||||
|
||||
@ -31,6 +31,20 @@ typedef union {
|
||||
} PayloadUnion;
|
||||
{{end}}
|
||||
|
||||
{{define "basemessage"}}
|
||||
typdef struct {
|
||||
uint8_t version;
|
||||
MessageID {{.CenumPCTOESP.EnumName}};
|
||||
PayloadUnion payload;
|
||||
} PCTOESPBaseMessage;
|
||||
|
||||
typdef struct {
|
||||
uint8_t version;
|
||||
MessageID {{.CenumESPTOPC.EnumName}};
|
||||
PayloadUnion payload;
|
||||
} ESPTOPCBaseMessage;
|
||||
{{end}}
|
||||
|
||||
{{define "handler"}}
|
||||
{{- range . }}
|
||||
void (*on_{{ .Name | snake }})({{ .Name }}Payload*) = NULL;
|
||||
@ -55,7 +69,7 @@ void dispatch_message(uint8_t msg_id, void* payload) {
|
||||
{{define "send_functions"}}
|
||||
{{- range .}}
|
||||
{{ $argLen := len .Payload }}
|
||||
void send_{{.Name | snake}}({{- range $i, $p := .Payload}}{{$p.DataType}} {{$p.Name}} {{- if not (isLast $argLen $i) }}, {{ end}} {{- end}}) {
|
||||
void send_{{.Name | snake}}({{- range $i, $p := .Payload}}{{$p.DataType}} {{if .ArrayLength}}*{{end}}{{$p.Name}} {{- if not (isLast $argLen $i) }}, {{ end}} {{- end}}) {
|
||||
{{.Name}}Payload payload;
|
||||
|
||||
// Payload-Daten zuweisen
|
||||
|
||||
@ -11,5 +11,7 @@
|
||||
|
||||
{{ block "union" .PayloadStructs }} {{ end }}
|
||||
|
||||
{{ block "basemessage" . }} {{ end }}
|
||||
|
||||
#endif
|
||||
{{- end -}}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user