Reorderd hook stubs in header file and fixed up some spacing
This commit is contained in:
parent
49bfccfbd8
commit
ca22cc501e
@ -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}}) {
|
||||
{{- $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}}, &payload);
|
||||
send_message({{.Name}}, (PayloadUnion *)&payload);
|
||||
}
|
||||
{{- end }}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
@ -4,14 +4,29 @@
|
||||
#ifndef _PROTO_HEADER
|
||||
#define _PROTO_HEADER
|
||||
|
||||
{{ block "cenum" .CenumPCTOESP }} {{ end }}
|
||||
{{ block "cenum" .CenumESPTOPC }} {{ end }}
|
||||
#include <stdint.h>
|
||||
|
||||
{{ 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 -}}
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
{{- define "cpartSource" -}}
|
||||
// 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 -}}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user