added cli example
This commit is contained in:
parent
cc6b729352
commit
db1fccac30
5 changed files with 45 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
Go port of the POCSAG::Encode Perl module.
|
Go port of the POCSAG::Encode Perl module.
|
||||||
|
|
||||||
Example usage
|
Example usage
|
||||||
|
|
||||||
```
|
```
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
BIN
example/example
BIN
example/example
Binary file not shown.
37
examples/cli/main.go
Normal file
37
examples/cli/main.go
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
pc "github.com/kgolding/go-pocsagencode"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) != 3 {
|
||||||
|
fmt.Printf("Usage: %s <pager addr> <text message>\ne.g. %s 13100100 'Hello world!'\n", os.Args[0], os.Args[0])
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
addr, err := strconv.Atoi(os.Args[1])
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Invalid pager addr - must be a number")
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
messages := []*pc.Message{
|
||||||
|
&pc.Message{
|
||||||
|
Addr: uint32(addr),
|
||||||
|
Content: os.Args[2],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
burst, _ := pc.Generate(messages)
|
||||||
|
|
||||||
|
binStrs := []string{}
|
||||||
|
for _, b := range burst.Bytes() {
|
||||||
|
binStrs = append(binStrs, fmt.Sprintf("0b%b", b))
|
||||||
|
}
|
||||||
|
fmt.Printf("Message: %s\n\n", burst.String())
|
||||||
|
fmt.Printf("Hex bytes: % X\n\n", burst.Bytes())
|
||||||
|
fmt.Printf("Binary: %s\n\n", strings.Join(binStrs, ", "))
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
package pocsagencode
|
package pocsagencode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -35,4 +37,9 @@ func Test_Encode(t *testing.T) {
|
||||||
}
|
}
|
||||||
t.Log(enc)
|
t.Log(enc)
|
||||||
t.Log(enc.Bytes())
|
t.Log(enc.Bytes())
|
||||||
|
binStrs := []string{}
|
||||||
|
for _, b := range enc.Bytes() {
|
||||||
|
binStrs = append(binStrs, fmt.Sprintf("0b%b", b))
|
||||||
|
}
|
||||||
|
t.Log(strings.Join(binStrs, ", "))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue