Finished up Send Message generation

This commit is contained in:
simon 2025-04-26 16:44:48 +02:00
parent 2e081d7690
commit f8577dc3dc
4 changed files with 11 additions and 4 deletions

View File

@ -71,7 +71,8 @@ type CStyleData struct {
func CreateCStyle(proto *Proto) (string, error) { func CreateCStyle(proto *Proto) (string, error) {
funcs := template.FuncMap{ funcs := template.FuncMap{
"snake": toSnakeCase, "snake": toSnakeCase,
"isLast": isLast,
} }
tmpl, err := template.New("all").Funcs(funcs).ParseGlob("templates/*.tmpl") tmpl, err := template.New("all").Funcs(funcs).ParseGlob("templates/*.tmpl")
@ -134,3 +135,8 @@ func toSnakeCase(str string) string {
} }
return string(out) return string(out)
} }
// just a helper function, pass the length of your array and your current index
func isLast(datalen int, index int) bool {
return index == datalen-1
}

View File

@ -85,7 +85,7 @@ Each message is described as:
- [x] Union-Typen - [x] Union-Typen
- [x] Hook-Funktionen - [x] Hook-Funktionen
- [x] Message-Dispatcher (Switch-Case) - [x] Message-Dispatcher (Switch-Case)
- [ ] Send-Funktionen - [x] Send-Funktionen
- [ ] Generate Header and Source File - [ ] Generate Header and Source File
--- ---

View File

@ -54,7 +54,8 @@ void dispatch_message(uint8_t msg_id, void* payload) {
{{define "send_functions"}} {{define "send_functions"}}
{{- range .}} {{- range .}}
void send_{{.Name | snake}}({{- range .Payload}}{{.DataType}} {{.Name}}, {{- end}}) { {{ $argLen := len .Payload }}
void send_{{.Name | snake}}({{- range $i, $p := .Payload}}{{$p.DataType}} {{$p.Name}} {{- if not (isLast $argLen $i) }}, {{ end}} {{- end}}) {
{{.Name}}Payload payload; {{.Name}}Payload payload;
// Payload-Daten zuweisen // Payload-Daten zuweisen

View File

@ -5,4 +5,4 @@ in Payload struct it happend already
Need it in: Need it in:
- Send Parameter - Send Parameter
- Also remove trailing "," in send parameter - [x] Also remove trailing "," in send parameter