Reorderd hook stubs in header file and fixed up some spacing

This commit is contained in:
simon 2025-04-27 15:07:54 +02:00
parent 49bfccfbd8
commit ca22cc501e
3 changed files with 73 additions and 33 deletions

View File

@ -21,7 +21,7 @@ typedef struct {
{{- end }} {{- end }}
} {{ .Name }}Payload; } {{ .Name }}Payload;
{{end}} {{end}}
{{end}} {{- end}}
{{define "union"}} {{define "union"}}
typedef union { typedef union {
@ -32,24 +32,24 @@ typedef union {
{{end}} {{end}}
{{define "basemessage"}} {{define "basemessage"}}
typdef struct { typedef struct {
uint8_t version; uint8_t Version;
MessageID {{.CenumPCTOESP.EnumName}}; {{.CenumPCTOESP.EnumName}} MessageID;
uint8_t length; uint8_t Length;
PayloadUnion payload; PayloadUnion Payload;
} PCTOESPBaseMessage; } PCTOESPBaseMessage;
typdef struct { typedef struct {
uint8_t version; uint8_t Version;
MessageID {{.CenumESPTOPC.EnumName}}; {{.CenumESPTOPC.EnumName}} MessageID;
uint8_t length; uint8_t Length;
PayloadUnion payload; PayloadUnion Payload;
} ESPTOPCBaseMessage; } ESPTOPCBaseMessage;
{{end}} {{end}}
{{define "handler"}} {{define "handler"}}
{{- range . }} {{- range . }}
void (*on_{{ .Name | snake }})({{ .Name }}Payload*) = NULL; void (*on_{{ .Name | snake }})({{ .Name }}Payload*);
{{- end}} {{- end}}
{{end}} {{end}}
@ -68,19 +68,38 @@ void dispatch_message(uint8_t msg_id, void *payload) {
} }
{{end}} {{end}}
{{define "send_functions"}} {{define "send_function_prototype"}}
void send_message(ESP_TO_PC_MESSAGE_IDS msgid, PayloadUnion *payload);
{{end}}
{{define "send_function_source"}}
void send_message(ESP_TO_PC_MESSAGE_IDS msgid, PayloadUnion *payload) {}
{{end}}
{{define "send_functions_prototype"}}
{{- range .}} {{- range .}}
{{ $argLen := len .Payload }} {{- $argLen := len .Payload }}
void send_{{.Name | snake}}({{- range $i, $p := .Payload}}{{$p.DataType}} {{if .ArrayLength}}*{{end}}{{$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}});
{{- end }}
{{end}}
{{define "send_functions_source"}}
{{- range .}}
{{- $argLen := len .Payload }}
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; {{.Name}}Payload payload;
// Payload-Daten zuweisen // Payload-Daten zuweisen
{{- range .Payload}} {{- range .Payload}}
{{- if .ArrayLength }}
memcpy(payload.{{.Name}}, {{.Name}}, {{.ArrayLength}});
{{- else }}
payload.{{.Name}} = {{.Name}}; payload.{{.Name}} = {{.Name}};
{{- end}} {{- end}}
{{- end}}
// Nachricht senden // Nachricht senden
send_message({{.Name}}, &payload); send_message({{.Name}}, (PayloadUnion *)&payload);
} }
{{- end }} {{end}}
{{end}} {{end}}

View File

@ -4,14 +4,29 @@
#ifndef _PROTO_HEADER #ifndef _PROTO_HEADER
#define _PROTO_HEADER #define _PROTO_HEADER
{{ block "cenum" .CenumPCTOESP }} {{ end }} #include <stdint.h>
{{ block "cenum" .CenumESPTOPC }} {{ end }}
{{ block "payloads" .PayloadStructs }} {{ end }} // MessageIDs
{{- block "cenum" .CenumPCTOESP }} {{- end}}
{{- block "cenum" .CenumESPTOPC }} {{- end}}
{{ block "union" .PayloadStructs }} {{ end }} // Payloads for single Messages
{{- block "payloads" .PayloadStructs }} {{- end}}
{{ block "basemessage" . }} {{ end }} // Union for all the Payloads
{{- block "union" .PayloadStructs }} {{- end}}
// Base Message that can hold all Payloads
{{- block "basemessage" . }} {{- end}}
// Generic Send Function Prototype
{{- block "send_function_prototype" .MessagesESPtoPC}} {{- end}}
// Spezific Send Functions Prototype
{{- block "send_functions_prototype" .MessagesESPtoPC}} {{- end}}
// Prototypes for Message Recieve Handler to be set in user code
{{- block "handler" .MessagesPCtoESP}} {{ end }}
#endif #endif
{{- end -}} {{- end -}}

View File

@ -1,9 +1,15 @@
{{- define "cpartSource" -}} {{- define "cpartSource" -}}
// AUTO GENERATED DO NOT EDIT!!! // AUTO GENERATED DO NOT EDIT!!!
{{ block "handler" .MessagesPCtoESP}} {{ end }} #include "uart_prot.h"
#include <string.h>
{{ block "dispatcher" .MessagesPCtoESP}} {{ end }} // Message Dispatcher
{{- block "dispatcher" .MessagesPCtoESP}} {{ end }}
{{ block "send_functions" .MessagesESPtoPC}} {{ end }} //Generic Send Function
{{- block "send_function_source" .MessagesESPtoPC}} {{ end }}
// Sepzific Send Functions
{{- block "send_functions_source" .MessagesESPtoPC}} {{ end }}
{{- end -}} {{- end -}}