GitHub - DownerCase/ecal-go: Go bindings for eclipse eCAL (original) (raw)
Go-eCAL
Go bindings and CLI tools for eCAL 6 (currently unreleased). Inspired from Blutkoete/golang-ecal.
Usage
Go binding demo
go run .
Go version of eCAL monitor
go run ./cmd/monitor
Features
- eCAL 6 compatible (unreleased)
- Pure cgo; no SWIG dependency
- Custom C interface implementation
- Direct deserialization from subscriber buffer to Go types
- Rewrite of eCAL monitor using bubbletea
Provides Go interfaces for:
- Configuration (partial, expanded as required)
- Publisher & Subscriber
- Message Types: Custom/binary, String, Protobuf
- Logging
- Monitoring ("slow" API for detailed information)
- Registration ("fast" API for basic topic name and datatype information)
- Topic event (added/removed publisher/subscriber) callbacks
- Services
Example
package main
import ( "fmt" "time"
"github.com/DownerCase/ecal-go/ecal")
func main() { // Initialize eCAL ecal.Initialize( ecal.NewConfig(ecal.WithConsoleLogging(true), ecal.WithConsoleLogAll()), "Go eCAL!", ecal.CDefault, ) defer ecal.Finalize() // Shutdown eCAL at the end of the program
// Send messages
go func() {
publisher, err := ecal.NewStringPublisher("string topic")
if err != nil {
panic("Failed to make string publisher")
}
defer publisher.Delete()
for idx := 0; true; idx++ {
publisher.Send(fmt.Sprint("This is message ", idx))
time.Sleep(time.Second)
}
}()
// Receive messages
subscriber, err := ecal.NewStringSubscriber("string topic")
if err != nil {
panic("Failed to Create string subscriber")
}
defer subscriber.Delete()
for ecal.Ok() {
msg, err := subscriber.Receive(time.Second * 2)
if err == nil {
fmt.Println("Received:", msg)
} else {
fmt.Println(err)
}
}}
CLI Tools
Monitor
Features:
All the basic functionality from the upstream TUI monitor but:
- More efficient use of space; use the whole screen to view your messages!
- Easily send stop commands to eCAL processes (make
eCAL::Ok()returnfalse)
Non-system installations
If eCAL is not installed in a default search path or you wish to use a specific install of eCAL there is a helper CMake project to generate a package_user.gowith the correct cgo flags.
cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/cmake/install go run .
Development
To help write the C and C++ wrapper use the CMake project to generate acompile_commands.json.