added options and example
parent
cfe7772b7d
commit
afd1b58560
@ -1,2 +1,35 @@
|
||||
Go port of the POCSAG::Encode Perl module.
|
||||
|
||||
Example usage
|
||||
```
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/kgolding/go-pocsagencode"
|
||||
)
|
||||
|
||||
func main() {
|
||||
messages := []*pocsagencode.Message{
|
||||
&pocsagencode.Message{1300100, "Hello Pager!"},
|
||||
}
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
addr := uint32(1200000 + i*100)
|
||||
messages = append(messages, &pocsagencode.Message{addr, fmt.Sprintf("Hello pager number %d", addr)})
|
||||
}
|
||||
|
||||
log.Println("Sending", len(messages), "messages")
|
||||
var burst pocsagencode.Burst
|
||||
for len(messages) > 0 {
|
||||
burst, messages = pocsagencode.Generate(messages)
|
||||
// Options can be set as below for MaxLen and PreambleBits
|
||||
// burst, messages = pocsagencode.Generate(messages, pocsagencode.OptionPreambleBits(250))
|
||||
log.Println("Burst", burst.String())
|
||||
// Send Burst to the FSK modem here...
|
||||
}
|
||||
log.Println("Done")
|
||||
}
|
||||
```
|
Binary file not shown.
@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/kgolding/go-pocsagencode"
|
||||
)
|
||||
|
||||
func main() {
|
||||
messages := []*pocsagencode.Message{
|
||||
&pocsagencode.Message{1300100, "Hello Pager!"},
|
||||
}
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
addr := uint32(1200000 + i*100)
|
||||
messages = append(messages, &pocsagencode.Message{addr, fmt.Sprintf("Hello pager number %d", addr)})
|
||||
}
|
||||
|
||||
log.Println("Sending", len(messages), "messages")
|
||||
var burst pocsagencode.Burst
|
||||
for len(messages) > 0 {
|
||||
burst, messages = pocsagencode.Generate(messages)
|
||||
// Options can be set as below for MaxLen and PreambleBits
|
||||
// burst, messages = pocsagencode.Generate(messages, pocsagencode.OptionPreambleBits(250))
|
||||
log.Println("Burst", burst.String())
|
||||
// Send Burst to the FSK modem here...
|
||||
}
|
||||
log.Println("Done")
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package pocsagencode
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Burst []uint32
|
||||
|
||||
// String return a formated multiline string with the
|
||||
func (b Burst) String() string {
|
||||
s := ""
|
||||
preambleCount := 0
|
||||
preambleOver := false
|
||||
for _, w := range b {
|
||||
if !preambleOver {
|
||||
if w == pocsagPreambleWord {
|
||||
preambleCount++
|
||||
continue
|
||||
} else {
|
||||
s += fmt.Sprintf("[%d bits of 1010101010... (0xAA) preamble] ", preambleCount*32)
|
||||
preambleOver = true
|
||||
}
|
||||
}
|
||||
if w == pocsagFrameSyncWord {
|
||||
s += "[Batch start/sync] "
|
||||
}
|
||||
s += fmt.Sprintf("%X ", w)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Bytes returns a []byte
|
||||
func (b Burst) Bytes() []byte {
|
||||
buf := make([]byte, len(b)*4)
|
||||
for i, w := range b {
|
||||
binary.BigEndian.PutUint32(buf[i*4:], w)
|
||||
}
|
||||
return buf
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package pocsagencode
|
||||
|
||||
type Options struct {
|
||||
MaxLen int
|
||||
PreambleBits int
|
||||
}
|
||||
|
||||
type OptionFn func(*Options)
|
||||
|
||||
func OptionMaxLen(v int) OptionFn {
|
||||
return func(o *Options) {
|
||||
o.MaxLen = v
|
||||
}
|
||||
}
|
||||
|
||||
func OptionPreambleBits(v int) OptionFn {
|
||||
return func(o *Options) {
|
||||
o.PreambleBits = v
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue