Skip to content

Commit

Permalink
Adapt paths for GO module. Make examples simpler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blutkoete committed Jul 7, 2020
1 parent aafacd1 commit fe72314
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 159 deletions.
87 changes: 31 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,24 @@ Sending:
)

func main() {
var pub ecal.PublisherIf
var pubChannel chan<- ecal.Message
var err error
pub, pubChannel, err = ecal.PublisherCreate("Hello", "base:std::string", "", true)
if err != nil {
log.Fatal(err)
}
defer pub.Destroy()

go func() {
count := 1
for ecal.Ok() {
message := ecal.Message{Content: []byte(fmt.Sprintf("Hello World from Go (%d)", count)),
Timestamp: -1}
count += 1
select {
case pubChannel <- message:
log.Printf("Sent \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
<-time.After(250 * time.Millisecond)
}

pub.Stop()
}()

for !pub.IsStopped() {
<-time.After(time.Second)
}

<-time.After(time.Second)
pub, pubChannel, err := ecal.PublisherCreate("Hello", "base:std::string", "", true)
if err != nil {
log.Fatal(err)
}
defer pub.Destroy()

count := 0
for ecal.Ok() {
message := ecal.Message{Content: []byte(fmt.Sprintf("Hello World from Go (%d)", count)),
Timestamp: -1}
count += 1
select {
case pubChannel <- message:
log.Printf("Sent \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
<-time.After(250 * time.Millisecond)
}
}

Receiving:
Expand All @@ -71,29 +58,17 @@ Receiving:
)

func main() {
var sub ecal.SubscriberIf
var subChannel <-chan ecal.Message
var err error
sub, subChannel, err = ecal.SubscriberCreate("Hello", "base:std::string", "", true, 1024)
if err != nil {
log.Fatal(err)
}
defer sub.Destroy()

go func() {
for ecal.Ok() {
select {
case message := <-subChannel:
log.Printf("Received \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
}

sub.Stop()
}()

for !sub.IsStopped() {
<-time.After(time.Second)
}

sub, subChannel, err := ecal.SubscriberCreate("Hello", "base:std::string", "", true, 1024)
if err != nil {
log.Fatal(err)
}
defer sub.Destroy()

for ecal.Ok() {
select {
case message := <-subChannel:
log.Printf("Received \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
}
}
89 changes: 31 additions & 58 deletions ecal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,30 @@ Sending:

import (
"log"
"os"
"time"

"github.com/Blutkoete/golang-ecal/ecal"
)

func main() {
var pub ecal.PublisherIf
var pubChannel chan<- ecal.Message
var err error
pub, pubChannel, err = ecal.PublisherCreate("Hello", "base:std::string", "", true)
if err != nil {
log.Fatal(err)
}
defer pub.Destroy()

go func() {
count := 1
for ecal.Ok() {
message := ecal.Message{Content: []byte(fmt.Sprintf("Hello World from Go (%d)", count)),
Timestamp: -1}
count += 1
select {
case pubChannel <- message:
log.Printf("Sent \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
<-time.After(250 * time.Millisecond)
}

pub.Stop()
}()

for !pub.IsStopped() {
<-time.After(time.Second)
}

<-time.After(time.Second)
pub, pubChannel, err := ecal.PublisherCreate("Hello", "base:std::string", "", true)
if err != nil {
log.Fatal(err)
}
defer pub.Destroy()

count := 0
for ecal.Ok() {
message := ecal.Message{Content: []byte(fmt.Sprintf("Hello World from Go (%d)", count)),
Timestamp: -1}
count += 1
select {
case pubChannel <- message:
log.Printf("Sent \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
<-time.After(250 * time.Millisecond)
}
}

Receiving:
Expand All @@ -66,36 +52,23 @@ Receiving:

import (
"log"
"os"
"time"

"github.com/Blutkoete/golang-ecal/ecal"
)

func main() {
var sub ecal.SubscriberIf
var subChannel <-chan ecal.Message
var err error
sub, subChannel, err = ecal.SubscriberCreate("Hello", "base:std::string", "", true, 1024)
if err != nil {
log.Fatal(err)
}
defer sub.Destroy()

go func() {
for ecal.Ok() {
select {
case message := <-subChannel:
log.Printf("Received \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
}

sub.Stop()
}()

for !sub.IsStopped() {
<-time.After(time.Second)
}

sub, subChannel, err := ecal.SubscriberCreate("Hello", "base:std::string", "", true, 1024)
if err != nil {
log.Fatal(err)
}
defer sub.Destroy()

for ecal.Ok() {
select {
case message := <-subChannel:
log.Printf("Received \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
}
}
2 changes: 1 addition & 1 deletion ecal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"unsafe"

"golang-ecal/ecalc"
"github.com/Blutkoete/golang-ecal/ecalc"
)

const InitPublisher uint = uint(ecalc.ECAL_Init_Publisher)
Expand Down
2 changes: 1 addition & 1 deletion ecal/process.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ecal

import (
"golang-ecal/ecalc"
"github.com/Blutkoete/golang-ecal/ecalc"
)

func ProcessSleepMS(sleepTimeMs int64) {
Expand Down
2 changes: 1 addition & 1 deletion ecal/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"
"unsafe"

"golang-ecal/ecalc"
"github.com/Blutkoete/golang-ecal/ecalc"
)

type PublisherIf interface {
Expand Down
2 changes: 1 addition & 1 deletion ecal/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"
"unsafe"

"golang-ecal/ecalc"
"github.com/Blutkoete/golang-ecal/ecalc"
)

type SubscriberIf interface {
Expand Down
58 changes: 17 additions & 41 deletions golang-ecal_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,43 @@ import (
"os"
"time"

"golang-ecal/ecal"
"github.com/Blutkoete/golang-ecal/ecal"
)

func minimalSnd() {
var pub ecal.PublisherIf
var pubChannel chan<- ecal.Message
var err error
pub, pubChannel, err = ecal.PublisherCreate("Hello", "base:std::string", "", true)
pub, pubChannel, err := ecal.PublisherCreate("Hello", "base:std::string", "", true)
if err != nil {
log.Fatal(err)
}
defer pub.Destroy()

go func() {
count := 1
for ecal.Ok() {
message := ecal.Message{Content: []byte(fmt.Sprintf("Hello World from Go (%d)", count)),
count := 0
for ecal.Ok() {
message := ecal.Message{Content: []byte(fmt.Sprintf("Hello World from Go (%d)", count)),
Timestamp: -1}
count += 1
select {
case pubChannel <- message:
log.Printf("Sent \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
<-time.After(250 * time.Millisecond)
count += 1
select {
case pubChannel <- message:
log.Printf("Sent \"%s\"\n", message.Content)
case <-time.After(time.Second):
}

pub.Stop()
}()

for !pub.IsStopped() {
<-time.After(time.Second)
<-time.After(250 * time.Millisecond)
}

<-time.After(time.Second)
}

func minimalRec() {
var sub ecal.SubscriberIf
var subChannel <-chan ecal.Message
var err error
sub, subChannel, err = ecal.SubscriberCreate("Hello", "base:std::string", "", true, 1024)
sub, subChannel, err := ecal.SubscriberCreate("Hello", "base:std::string", "", true, 1024)
if err != nil {
log.Fatal(err)
}
defer sub.Destroy()

go func() {
for ecal.Ok() {
select {
case message := <-subChannel:
log.Printf("Received \"%s\"\n", message.Content)
case <-time.After(time.Second):
}
for ecal.Ok() {
select {
case message := <-subChannel:
log.Printf("Received \"%s\"\n", message.Content)
case <-time.After(time.Second):
}

sub.Stop()
}()

for !sub.IsStopped() {
<-time.After(time.Second)
}
}

Expand Down

0 comments on commit fe72314

Please sign in to comment.