From ca22cc501ef4e177b2a732ce25ff4d50f86f99fc Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 27 Apr 2025 15:07:54 +0200 Subject: [PATCH] Reorderd hook stubs in header file and fixed up some spacing --- templates/blocks.tmpl | 69 ++++++++++++++++++++++++-------------- templates/cpartHeader.tmpl | 25 +++++++++++--- templates/cpartSource.tmpl | 12 +++++-- 3 files changed, 73 insertions(+), 33 deletions(-) diff --git a/templates/blocks.tmpl b/templates/blocks.tmpl index f636957..d3cec17 100644 --- a/templates/blocks.tmpl +++ b/templates/blocks.tmpl @@ -20,8 +20,8 @@ typedef struct { {{- end}} {{- end }} } {{ .Name }}Payload; -{{ end }} {{end}} +{{- end}} {{define "union"}} typedef union { @@ -32,24 +32,24 @@ typedef union { {{end}} {{define "basemessage"}} -typdef struct { - uint8_t version; - MessageID {{.CenumPCTOESP.EnumName}}; - uint8_t length; - PayloadUnion payload; +typedef struct { + uint8_t Version; + {{.CenumPCTOESP.EnumName}} MessageID; + uint8_t Length; + PayloadUnion Payload; } PCTOESPBaseMessage; -typdef struct { - uint8_t version; - MessageID {{.CenumESPTOPC.EnumName}}; - uint8_t length; - PayloadUnion payload; +typedef struct { + uint8_t Version; + {{.CenumESPTOPC.EnumName}} MessageID; + uint8_t Length; + PayloadUnion Payload; } ESPTOPCBaseMessage; {{end}} {{define "handler"}} {{- range . }} -void (*on_{{ .Name | snake }})({{ .Name }}Payload*) = NULL; +void (*on_{{ .Name | snake }})({{ .Name }}Payload*); {{- end}} {{end}} @@ -68,19 +68,38 @@ void dispatch_message(uint8_t msg_id, void *payload) { } {{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 .}} -{{ $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; - - // Payload-Daten zuweisen - {{- range .Payload}} - payload.{{.Name}} = {{.Name}}; - {{- end}} - - // Nachricht senden - send_message({{.Name}}, &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}}); {{- 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; + + // Payload-Daten zuweisen + {{- range .Payload}} + {{- if .ArrayLength }} + memcpy(payload.{{.Name}}, {{.Name}}, {{.ArrayLength}}); + {{- else }} + payload.{{.Name}} = {{.Name}}; + {{- end}} + {{- end}} + + // Nachricht senden + send_message({{.Name}}, (PayloadUnion *)&payload); +} +{{end}} +{{end}} diff --git a/templates/cpartHeader.tmpl b/templates/cpartHeader.tmpl index 46d1586..50e8fb8 100644 --- a/templates/cpartHeader.tmpl +++ b/templates/cpartHeader.tmpl @@ -4,14 +4,29 @@ #ifndef _PROTO_HEADER #define _PROTO_HEADER -{{ block "cenum" .CenumPCTOESP }} {{ end }} -{{ block "cenum" .CenumESPTOPC }} {{ end }} +#include -{{ 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 {{- end -}} diff --git a/templates/cpartSource.tmpl b/templates/cpartSource.tmpl index ef15d82..74a706a 100644 --- a/templates/cpartSource.tmpl +++ b/templates/cpartSource.tmpl @@ -1,9 +1,15 @@ {{- define "cpartSource" -}} // AUTO GENERATED DO NOT EDIT!!! -{{ block "handler" .MessagesPCtoESP}} {{ end }} +#include "uart_prot.h" +#include -{{ 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 -}}