Skip to content

Commit

Permalink
Prepare for public release
Browse files Browse the repository at this point in the history
  • Loading branch information
tehmaze committed Dec 16, 2015
1 parent 493e725 commit cba4cf1
Show file tree
Hide file tree
Showing 47 changed files with 889 additions and 28,272 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pdf filter=lfs diff=lfs merge=lfs -text
27 changes: 0 additions & 27 deletions Makefile

This file was deleted.

34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# dmr
Golang Digital Mobile Radio protocols
# go-dmr

Golang Digital Mobile Radio protocols.

## References

The DMR Air Interface protocol is specified in *Electromagnetic compatibility
and Radio spectrum Matters (ERM); Digital Mobile Radio (DMR) Systems; Part 1:
DMR Air Interface (AI) protocol*, [ETSI TS 102 361-1][ETSI TS 102 361-1].

The Brandmeister Homebrew protocol is specified in
[IPSC Protocol Specs for homebrew DMR repeater][homebrew specs]
by [Hans DL5DI](mailto:[email protected]),
[Jonathan Naylor (G4KLXG)](https://twitter.com/g4klx) and Torsten Schultze
(DG1HT).

[ETSI TS 102 361-1]: docs/ts_10236101v010405p.pdf
[homebrew specs]: docs/DMRplus%20IPSC%20Protocol%20for%20HB%20repeater%20(20150726).pdf

## Warning

This implementation is not suitable for commercial use and is for educational
purposes only.

## Acknowledgements

The implementation is possible because of the invaluable help from the
following persons. Thanks for your patience and providing me with sample data
and links to test the protocols.

* Rudy Hardeman (PD0ZRY)
* Artem Prilutskiy (R3ABM)
97 changes: 0 additions & 97 deletions bit/bit.go

This file was deleted.

22 changes: 0 additions & 22 deletions bit/debit.go

This file was deleted.

49 changes: 48 additions & 1 deletion bit/mask.go → bits.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
package bit
package dmr

const (
PayloadBits = 98 + 10 + 48 + 10 + 98
PayloadSize = 33
InfoHalfBits = 98
InfoBits = 2 * InfoHalfBits
SlotTypeHalfBits = 10
SlotTypeBits = 2 * SlotTypeHalfBits
SignalBits = 48
SyncOffsetBits = InfoHalfBits + SlotTypeHalfBits
SyncBits = SignalBits
VoiceHalfBits = 108
VoiceBits = 2 * VoiceHalfBits
EMBHalfBits = 8
EMBBits = 2 * EMBHalfBits
EMBSignallingLCFragmentBits = 32
)

// Because Go doesn't have binary literals ("We've found hex and octal to be sufficient")
const (
Expand Down Expand Up @@ -259,3 +276,33 @@ const (
B11111110
B11111111
)

// BytesToBits converts a byte slice to a byte slice representing the individual data bits.
func BytesToBits(data []byte) []byte {
var bits = make([]byte, len(data)*8)
for i := 0; i < len(data); i++ {
copy(bits[i*8:], toBits(data[i]))
}
return bits
}

func toBits(b byte) []byte {
var o = make([]byte, 8)
for bit, mask := 0, byte(128); bit < 8; bit, mask = bit+1, mask>>1 {
if b&mask != 0 {
o[bit] = 1
}
}
return o
}

// BitsToBytes converts a byte slice of bits to a byte slice.
func BitsToBytes(bits []byte) []byte {
var data = make([]byte, (len(bits)+7)/8)
for i, b := range bits {
if b == 0x01 {
data[i/8] |= (1 << byte(7-(i%8)))
}
}
return data
}
22 changes: 15 additions & 7 deletions bit/bit_test.go → bits_test.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
package bit
package dmr

import "testing"
import (
"bytes"
"testing"
)

func TestBit(t *testing.T) {
var tests = []struct {
Test []byte
Want Bits
Want []byte
}{
{
[]byte{0x2a},
Bits{0, 0, 1, 0, 1, 0, 1, 0},
[]byte{0, 0, 1, 0, 1, 0, 1, 0},
},
{
[]byte{0xbe, 0xef},
Bits{1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1},
[]byte{1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1},
},
}

for _, test := range tests {
got := NewBits(test.Test)
got := BytesToBits(test.Test)
if len(got) != len(test.Want) {
t.Fatalf("expected length %d, got %d [%s]", len(test.Want), len(got), got.String())
t.Fatalf("expected length %d, got %d [%s]", len(test.Want), len(got), string(got))
}
for i, b := range got {
if b != test.Want[i] {
t.Fatalf("bit %d is off: %v != %v", i, got, test.Want)
}
}

rev := BitsToBytes(got)
if !bytes.Equal(rev, test.Test) {
t.Fatalf("reverse bits to bytes failed, %v != %v", rev, test.Test)
}
}
}
14 changes: 7 additions & 7 deletions bptc/bptc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package bptc
import (
"fmt"

"github.com/tehmaze/go-dmr/bit"
"github.com/tehmaze/go-dmr"
"github.com/tehmaze/go-dmr/fec"
)

func Process(info bit.Bits, payload []byte) error {
func Process(info []byte, payload []byte) error {
if len(info) < 196 {
return fmt.Errorf("bptc: info size %d too small, need at least 196 bits", len(info))
}
Expand All @@ -17,8 +17,8 @@ func Process(info bit.Bits, payload []byte) error {

var (
i, j, k uint32
datafr = make(bit.Bits, 196)
extracted = make(bit.Bits, 96)
datafr = make([]byte, 196)
extracted = make([]byte, 96)
)

// Deinterleave bits
Expand All @@ -41,7 +41,7 @@ func Process(info bit.Bits, payload []byte) error {
fec.Hamming15_11_3_Correct(&codeword)
codeword &= 0x01ff
for j = 0; j < 9; j++ {
datafr[j*15+i] = bit.Bit((codeword >> (8 - j)) & 1)
datafr[j*15+i] = byte((codeword >> (8 - j)) & 1)
}
}
for j = 0; j < 9; j++ {
Expand All @@ -52,7 +52,7 @@ func Process(info bit.Bits, payload []byte) error {
}
fec.Hamming15_11_3_Correct(&codeword)
for i = 0; i < 11; i++ {
datafr[j*15+10-i] = bit.Bit((codeword >> i) & 1)
datafr[j*15+10-i] = byte((codeword >> i) & 1)
}
}

Expand All @@ -66,7 +66,7 @@ func Process(info bit.Bits, payload []byte) error {
}
}

copy(payload, extracted.Bytes())
copy(payload, dmr.BitsToBytes(extracted))

return nil
}
Loading

0 comments on commit cba4cf1

Please sign in to comment.