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