Compare commits
3 Commits
df2338b6f1
...
ac5c660583
| Author | SHA1 | Date | |
|---|---|---|---|
| ac5c660583 | |||
| 853fda9814 | |||
| aff454c277 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
alox.protogen
|
||||
alox.protogen.exe
|
||||
build/
|
||||
|
||||
8
Makefile
Normal file
8
Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
build:
|
||||
go build .
|
||||
|
||||
build_win:
|
||||
GOOS=windows go build .
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
39
main.go
39
main.go
@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
@ -14,7 +16,12 @@ import (
|
||||
var appConfig = koanf.New(".")
|
||||
|
||||
func main() {
|
||||
if err := appConfig.Load(file.Provider("testdata/conf.yaml"), yaml.Parser()); err != nil {
|
||||
confPath := flag.String("c", "testdata/conf.yaml", "Config File")
|
||||
outFileName := flag.String("o", "", "Name of the Output File")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if err := appConfig.Load(file.Provider(*confPath), yaml.Parser()); err != nil {
|
||||
log.Printf("error loading config: %v", err)
|
||||
} else {
|
||||
log.Printf("CONF: %v", appConfig)
|
||||
@ -24,17 +31,43 @@ func main() {
|
||||
var cfg proto.Proto
|
||||
json.Unmarshal(file, &cfg)
|
||||
|
||||
// if outFileName is set use it, if is not set set it to default value
|
||||
if *outFileName != "" {
|
||||
cfg.FileName = *outFileName
|
||||
} else {
|
||||
*outFileName = "proto"
|
||||
}
|
||||
|
||||
// If filename not set in json take it from cli or default
|
||||
if cfg.FileName != "" {
|
||||
cfg.FileName = *outFileName
|
||||
}
|
||||
|
||||
proto.InitTemplates()
|
||||
|
||||
header, err := proto.CreateCStyleHeader(&cfg)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %v", err)
|
||||
}
|
||||
log.Printf("TEMPLATE HEADER: \n%v", header)
|
||||
err = os.MkdirAll("build", 0755)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile(fmt.Sprintf("build/%s.h", *outFileName), []byte(header), 0666)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
source, err := proto.CreateCStyleSource(&cfg)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %v", err)
|
||||
}
|
||||
log.Printf("TEMPLATE SOURCE: \n%v", source)
|
||||
err = os.WriteFile(fmt.Sprintf("build/%s.c", *outFileName), []byte(source), 0666)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ type Proto struct {
|
||||
ProtocolHeader ProtocolHeader `json:"protocol"`
|
||||
ESP_TO_PC []ProtoMessage `json:"messages_esp_to_pc"`
|
||||
PC_TO_ESP []ProtoMessage `json:"messages_pc_to_esp"`
|
||||
FileName string `json:"filename,omitempty"`
|
||||
}
|
||||
|
||||
func (h *HexByte) UnmarshalJSON(data []byte) error {
|
||||
@ -62,6 +63,7 @@ type PayloadStruct struct {
|
||||
}
|
||||
|
||||
type CStyleData struct {
|
||||
FileName string
|
||||
CenumPCTOESP Cenum
|
||||
CenumESPTOPC Cenum
|
||||
PayloadStructs []PayloadStruct
|
||||
@ -105,6 +107,7 @@ func CreateCStyleHeader(proto *Proto) (string, error) {
|
||||
}
|
||||
|
||||
var data = CStyleData{
|
||||
FileName: proto.FileName,
|
||||
CenumPCTOESP: Cenum{
|
||||
EnumName: "PC_TO_ESP_MESSAGE_IDS",
|
||||
Entries: proto.PC_TO_ESP,
|
||||
@ -148,6 +151,7 @@ func CreateCStyleSource(proto *Proto) (string, error) {
|
||||
}
|
||||
|
||||
var data = CStyleData{
|
||||
FileName: proto.FileName,
|
||||
CenumPCTOESP: Cenum{
|
||||
EnumName: "PC_TO_ESP_MESSAGE_IDS",
|
||||
Entries: proto.PC_TO_ESP,
|
||||
|
||||
@ -86,7 +86,7 @@ Each message is described as:
|
||||
- [x] Hook-Funktionen
|
||||
- [x] Message-Dispatcher (Switch-Case)
|
||||
- [x] Send-Funktionen
|
||||
- [ ] Generate Header and Source File
|
||||
- [x] Generate Header and Source File
|
||||
---
|
||||
|
||||
## To-Do
|
||||
@ -119,7 +119,7 @@ Each message is described as:
|
||||
### Tooling
|
||||
- [ ] CLI interface (`--input`, `--output`, `--language`, ...)
|
||||
- [ ] Logging / verbose mode
|
||||
- [ ] Build script / Makefile
|
||||
- [x] Build script / Makefile
|
||||
|
||||
### Testing
|
||||
- [ ] Unit tests for generator
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{{- define "cpartSource" -}}
|
||||
// AUTO GENERATED DO NOT EDIT!!!
|
||||
|
||||
#include "uart_prot.h"
|
||||
#include "{{.FileName}}.h"
|
||||
#include <string.h>
|
||||
|
||||
// Message Dispatcher
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user