diff --git a/Makefile b/Makefile index abbb6df..dd77caa 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ all: clean test build install build/$(APPNAME): @echo $(TS) Building $(APPAME) ... - @go build -ldflags $(LDFLAGS) -o build/$(APPNAME) platform/main/main.go + @go build -ldflags $(LDFLAGS) -o build/$(APPNAME) main.go @echo $(TS) Done. build: build/$(APPNAME) @@ -20,7 +20,7 @@ install: @echo $(TS) Installing $(APPNAME) ... @cp build/$(APPNAME) $(GOPATH)/bin/ @mkdir -p $(HOME)/esp32/ - @cp infrastructure/ino/mapping.json $(HOME)/esp32/mapping.json + @cp mapping.json $(HOME)/esp32/mapping.json @echo $(TS) Done. packages: diff --git a/business/transpiler/transpiler.go b/api/transpiler/transpiler.go similarity index 100% rename from business/transpiler/transpiler.go rename to api/transpiler/transpiler.go diff --git a/api/worker/mapping.go b/api/worker/mapping.go new file mode 100644 index 0000000..1fe54a9 --- /dev/null +++ b/api/worker/mapping.go @@ -0,0 +1,7 @@ +package worker + +// Mapping specifies the api logic to apply transformation to a specific identifier. +type Mapping interface { + Apply(ident string) string + Read() error +} diff --git a/business/worker/source.go b/api/worker/source.go similarity index 100% rename from business/worker/source.go rename to api/worker/source.go diff --git a/business/worker/target.go b/api/worker/target.go similarity index 100% rename from business/worker/target.go rename to api/worker/target.go diff --git a/api/worker/worker.go b/api/worker/worker.go new file mode 100644 index 0000000..610a4b7 --- /dev/null +++ b/api/worker/worker.go @@ -0,0 +1,6 @@ +package worker + +// Worker specifies the api logic of transforming a source code format into another target format. +type Worker interface { + Start() error +} diff --git a/business/worker/mapping.go b/business/worker/mapping.go deleted file mode 100644 index e59f63b..0000000 --- a/business/worker/mapping.go +++ /dev/null @@ -1,7 +0,0 @@ -package worker - -// Mapping specifies the business logic to apply transformation to a specific identifier. -type Mapping interface { - Apply(ident string) string - Read() error -} diff --git a/business/worker/worker.go b/business/worker/worker.go deleted file mode 100644 index 8e651d5..0000000 --- a/business/worker/worker.go +++ /dev/null @@ -1,6 +0,0 @@ -package worker - -// Worker specifies the business logic of transforming a source code format into another target format. -type Worker interface { - Start() error -} diff --git a/application/transpile/transpile.go b/impl/transpile/transpile.go similarity index 82% rename from application/transpile/transpile.go rename to impl/transpile/transpile.go index cd9986d..d611696 100644 --- a/application/transpile/transpile.go +++ b/impl/transpile/transpile.go @@ -2,8 +2,8 @@ package transpile import ( "fmt" - "github.com/andygeiss/esp32-transpiler/business/transpiler" - "github.com/andygeiss/esp32-transpiler/business/worker" + "github.com/andygeiss/esp32-transpiler/api/transpiler" + "github.com/andygeiss/esp32-transpiler/api/worker" ) // Transpiler uses a given worker to main source code. diff --git a/application/transpile/transpile_test.go b/impl/transpile/transpile_test.go similarity index 85% rename from application/transpile/transpile_test.go rename to impl/transpile/transpile_test.go index a77cd8b..0ad072b 100644 --- a/application/transpile/transpile_test.go +++ b/impl/transpile/transpile_test.go @@ -3,8 +3,8 @@ package transpile_test import ( "bytes" . "github.com/andygeiss/assert" - "github.com/andygeiss/esp32-transpiler/application/transpile" - "github.com/andygeiss/esp32-transpiler/business/worker" + "github.com/andygeiss/esp32-transpiler/impl/transpile" + "github.com/andygeiss/esp32-transpiler/api/worker" "io" "testing" ) diff --git a/infrastructure/ino/mapping.go b/impl/worker/mapping.go similarity index 81% rename from infrastructure/ino/mapping.go rename to impl/worker/mapping.go index e4ccac7..eaa3590 100644 --- a/infrastructure/ino/mapping.go +++ b/impl/worker/mapping.go @@ -1,12 +1,12 @@ -package ino +package worker import ( "encoding/json" - "github.com/andygeiss/esp32-transpiler/business/worker" + "github.com/andygeiss/esp32-transpiler/api/worker" "io/ioutil" ) -// Mapping specifies the business logic to apply transformation to a specific Golang identifier by reading simple JSON map. +// Mapping specifies the api logic to apply transformation to a specific Golang identifier by reading simple JSON map. type Mapping struct { Filename string `json:"filename"` Rules map[string]string `json:"rules"` diff --git a/infrastructure/ino/mapping.json b/impl/worker/mapping.json similarity index 100% rename from infrastructure/ino/mapping.json rename to impl/worker/mapping.json diff --git a/infrastructure/ino/worker.go b/impl/worker/worker.go similarity index 97% rename from infrastructure/ino/worker.go rename to impl/worker/worker.go index bafcf88..bc1bfdc 100644 --- a/infrastructure/ino/worker.go +++ b/impl/worker/worker.go @@ -1,8 +1,8 @@ -package ino +package worker import ( "fmt" - "github.com/andygeiss/esp32-transpiler/business/worker" + "github.com/andygeiss/esp32-transpiler/api/worker" "go/ast" "go/parser" "go/token" @@ -19,7 +19,7 @@ const ( var mapping worker.Mapping -// Worker specifies the business logic of transforming a source code format into another target format. +// Worker specifies the api logic of transforming a source code format into another target format. type Worker struct { in io.Reader out io.Writer diff --git a/infrastructure/ino/worker_test.go b/impl/worker/worker_test.go similarity index 87% rename from infrastructure/ino/worker_test.go rename to impl/worker/worker_test.go index 5c24468..d851098 100644 --- a/infrastructure/ino/worker_test.go +++ b/impl/worker/worker_test.go @@ -1,9 +1,8 @@ -package ino_test +package worker import ( "bytes" . "github.com/andygeiss/assert" - "github.com/andygeiss/esp32-transpiler/infrastructure/ino" "strings" "testing" ) @@ -21,10 +20,10 @@ func Trim(s string) string { // The Worker will be started and used to transform the source into an Arduino sketch format. func Validate(source, expected string, t *testing.T) { var in, out bytes.Buffer - mapping := ino.NewMapping("mapping.json") + mapping := NewMapping("mapping.json") Assert(t, mapping.Read(), IsNil()) in.WriteString(source) - worker := ino.NewWorker(&in, &out, mapping) + worker := NewWorker(&in, &out, mapping) Assert(t, worker.Start(), IsNil()) code := out.String() tcode, texpected := Trim(code), Trim(expected) @@ -222,10 +221,10 @@ func TestFunctionWithFunctionParam(t *testing.T) { func TestPackageImport(t *testing.T) { source := `package test - import "github.com/andygeiss/esp32-mqtt/business/controller" - import "github.com/andygeiss/esp32-mqtt/business/controller/serial" - import "github.com/andygeiss/esp32/business/controller/timer" - import wifi "github.com/andygeiss/esp32/business/controller/wifi" + import "github.com/andygeiss/esp32-mqtt/api/controller" + import "github.com/andygeiss/esp32-mqtt/api/controller/serial" + import "github.com/andygeiss/esp32/api/controller/timer" + import wifi "github.com/andygeiss/esp32/api/controller/wifi" ` expected := ` #include @@ -236,9 +235,9 @@ func TestPackageImport(t *testing.T) { func TestPackageImport_ButIgnoreController(t *testing.T) { source := `package test import controller "github.com/andygeiss/esp32-controller" - import "github.com/andygeiss/esp32-mqtt/business/controller/serial" - import "github.com/andygeiss/esp32/business/controller/timer" - import wifi "github.com/andygeiss/esp32/business/controller/wifi" + import "github.com/andygeiss/esp32-mqtt/api/controller/serial" + import "github.com/andygeiss/esp32/api/controller/timer" + import wifi "github.com/andygeiss/esp32/api/controller/wifi" ` expected := ` #include diff --git a/platform/main/main.go b/main.go similarity index 81% rename from platform/main/main.go rename to main.go index 910b4e1..2eec211 100644 --- a/platform/main/main.go +++ b/main.go @@ -1,11 +1,11 @@ -package main +package esp32_transpiler import ( "flag" "fmt" - "github.com/andygeiss/esp32-transpiler/application/transpile" - "github.com/andygeiss/esp32-transpiler/infrastructure/ino" - "github.com/andygeiss/log" + "github.com/andygeiss/esp32-transpiler/impl/transpile" + "github.com/andygeiss/esp32-transpiler/impl/worker" + log "github.com/andygeiss/log/impl" "os" ) @@ -36,7 +36,7 @@ func printUsage() { flag.PrintDefaults() fmt.Print("\n") fmt.Print("Example:\n") - fmt.Printf("\tesp32 -source application/blink/controller.go -target application/blink/controller.ino\n\n") + fmt.Printf("\tesp32 -source impl/blink/controller.go -target impl/blink/controller.worker\n\n") } func safeTranspile(mapping, source, target string) { @@ -53,11 +53,11 @@ func safeTranspile(mapping, source, target string) { log.Fatal("Arduino sketch file [%s] could not be opened! %v", target, err) } // Transpiles the Golang source into Arduino sketch. - m := ino.NewMapping(mapping) + m := worker.NewMapping(mapping) if err := m.Read(); err != nil { log.Fatal("%v", err) } - worker := ino.NewWorker(in, out, m) + worker := worker.NewWorker(in, out, m) trans := transpile.NewTranspiler(worker) if err := trans.Transpile(); err != nil { log.Fatal("%v", err) diff --git a/mapping.json b/mapping.json new file mode 100644 index 0000000..081ab06 --- /dev/null +++ b/mapping.json @@ -0,0 +1,47 @@ +{ + "digital.Low": "LOW", + "digital.High": "HIGH", + "digital.ModeInput": "INPUT", + "digital.ModeOutput": "OUTPUT", + "digital.PinMode": "pinMode", + "digital.Write": "digitalWrite", + "random.Num": "random", + "random.NumBetween": "random", + "random.Seed": "randomSeed", + "serial.Available": "Serial.available", + "serial.BaudRate300": "300", + "serial.BaudRate600": "600", + "serial.BaudRate1200": "1200", + "serial.BaudRate2400": "2400", + "serial.BaudRate4800": "4800", + "serial.BaudRate9600": "9600", + "serial.BaudRate14400": "14400", + "serial.BaudRate28800": "28800", + "serial.BaudRate38400": "38400", + "serial.BaudRate57600": "57600", + "serial.BaudRate115200": "115200", + "serial.Begin": "Serial.begin", + "serial.Print": "Serial.print", + "serial.Println": "Serial.println", + "timer.Delay": "delay", + "wifi": "WiFi", + "wifi.Begin": "WiFi.begin", + "wifi.BeginEncrypted": "WiFi.begin", + "wifi.BSSID": "WiFi.BSSID", + "wifi.Disconnect": "WiFi.disconnect", + "wifi.EncryptionType": "WiFi.encryptionType", + "wifi.EncryptionTypeAuto": "8", + "wifi.EncryptionTypeCCMP": "4", + "wifi.EncryptionTypeNone": "7", + "wifi.EncryptionTypeTKIP": "2", + "wifi.EncryptionTypeWEP": "5", + "wifi.LocalIP": "WiFi.localIP", + "wifi.RSSI": "WiFi.RSSI", + "wifi.ScanNetworks": "WiFi.scanNetworks", + "wifi.SetDNS": "WiFi.setDNS", + "wifi.SSID": "WiFi.SSID", + "wifi.StatusConnected": "WL_CONNECTED", + "wifi.StatusIdle": "WL_IDLE", + "Loop": "void loop", + "Setup": "void setup" +} \ No newline at end of file