Big Gotool Refactoring

- Added Event Bus
- Reworked Package Parsing
- Rewokred Frame Parsing
This commit is contained in:
2026-01-27 16:23:51 +01:00
parent 9efef034f0
commit 0767ddac38
12 changed files with 657 additions and 930 deletions
+48
View File
@@ -0,0 +1,48 @@
package testrunner
import (
"context"
"fmt"
"time"
"alox.tool/api"
"alox.tool/eventbus"
"alox.tool/uart"
)
type TestRunner struct {
bus eventbus.EventBus
com *uart.Com
}
func New(bus eventbus.EventBus, com *uart.Com) *TestRunner {
return &TestRunner{
bus: bus,
com: com,
}
}
func (tr *TestRunner) Expect(idToSend byte, payload []byte, expectedID byte, timeout time.Duration) (*api.Frame, error) {
rxChan := tr.bus.Subscribe(api.TopicUARTRx)
defer tr.bus.Unsubscribe(api.TopicUARTRx, rxChan)
if err := tr.com.Send(idToSend, payload); err != nil {
return nil, fmt.Errorf("send error: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
for {
select {
case <-ctx.Done():
return nil, fmt.Errorf("timeout waiting for ID 0x%02X", expectedID)
case frame := <-rxChan:
f := frame.(api.Frame)
if f.ID == expectedID {
return &f, nil
}
// Ignore other IDs and Messages on the Bus
}
}
}
+21
View File
@@ -0,0 +1,21 @@
package testrunner
import (
"fmt"
"time"
"alox.tool/api"
)
func (tr *TestRunner) RunVersionTest() error {
fmt.Println("Starte Version Test...")
// Sende VersionRequest (0x02), erwarte VersionResponse (0x02)
frame, err := tr.Expect(api.CmdVersion, nil, api.CmdVersion, 1*time.Second)
if err != nil {
return err
}
fmt.Printf("Test bestanden! Hardware Version ist: %s\n", string(frame.Data))
return nil
}