Finished up Send Message generation
This commit is contained in:
parent
2e081d7690
commit
f8577dc3dc
@ -71,7 +71,8 @@ type CStyleData struct {
|
||||
|
||||
func CreateCStyle(proto *Proto) (string, error) {
|
||||
funcs := template.FuncMap{
|
||||
"snake": toSnakeCase,
|
||||
"snake": toSnakeCase,
|
||||
"isLast": isLast,
|
||||
}
|
||||
|
||||
tmpl, err := template.New("all").Funcs(funcs).ParseGlob("templates/*.tmpl")
|
||||
@ -134,3 +135,8 @@ func toSnakeCase(str string) string {
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ Each message is described as:
|
||||
- [x] Union-Typen
|
||||
- [x] Hook-Funktionen
|
||||
- [x] Message-Dispatcher (Switch-Case)
|
||||
- [ ] Send-Funktionen
|
||||
- [x] Send-Funktionen
|
||||
- [ ] Generate Header and Source File
|
||||
---
|
||||
|
||||
|
||||
@ -54,7 +54,8 @@ void dispatch_message(uint8_t msg_id, void* payload) {
|
||||
|
||||
{{define "send_functions"}}
|
||||
{{- 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;
|
||||
|
||||
// Payload-Daten zuweisen
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user