Skip to content

Commit

Permalink
example CP24Time2a reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
pascaldekloe committed Jul 14, 2024
1 parent 32bbbe2 commit 7b107ab
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package part5_test

import (
"io"
"log"
"os"
"testing"
"time"

"github.com/pascaldekloe/part5"
"github.com/pascaldekloe/part5/info"
)

func TestMain(m *testing.M) {
// Logging documents intend in examples.
// Not interested in the output though.
log.SetOutput(io.Discard)

os.Exit(m.Run())
}

// Time tag reconstruction with some leeway comes recommended.
func ExampleCP24Time2a_WithinHourBefore() {
m := part5.NewMonitor[info.Cause8, info.ComAddr16, info.Addr16]()

// Listener to short floating-points with time tag.
m.FloatWithTime = func(u info.DataUnit[info.Cause8, info.ComAddr16, info.Addr16],
addr info.Addr16, f float32, q info.Qual, tag part5.CP24Time2a) {
// The time tag is relative to the now.
received := time.Now()

// Allow up to 5 seconds into the future to
// account for time synchronisation issues.
const leeway = 5 * time.Second

t := tag.WithinHourBefore(received.Add(leeway))
log.Println("timestamp reconstructed to", t)
}
// Output:
}

0 comments on commit 7b107ab

Please sign in to comment.