- DMRHub
- dmrgo
- Get started
- Receive on a radio
Receive on a radio
This step recovers bursts from the I/Q samples of a software radio with an rf.Receiver, finds the time slot of each burst with an rf.Monitor, and follows the call with the voice.Receiver of step 3.
From samples to bursts
A DMR signal is 4FSK, with two TDMA time slots on one carrier. A repeater sends a CACH between the bursts, which gives the time slot of the next burst. The receiver of package rf does the 4FSK detection, the SYNC search and the slot timing, decodes each FEC field with soft decisions, and returns each burst as the same 33 bytes that steps 2 to 4 use. (ETSI TS 102 361-1 clauses 6 and 10)
The capture
v2/cmd/dmrrf/testdata/xpr8400_bs_voice_weak.cu8 is a weak RTL-SDR capture of the output of a Motorola XPR 8400 repeater, color code 7. It holds a group call to talkgroup 9 on time slot 2. The samples are 8-bit unsigned I/Q, the format that rtl_sdr writes, at the sample rate that the code gives. v2/voice/testdata/xpr8400_bs_voice_weak.txt lists the bursts of the same capture, with the radio ID of the caller replaced by the fictional 3009999.
The code
func ExampleMonitor_capture() {
iq, err := os.ReadFile("../cmd/dmrrf/testdata/xpr8400_bs_voice_weak.cu8")
if err != nil {
fmt.Println(err)
return
}
call, err := voice.NewReceiver(nil)
if err != nil {
fmt.Println(err)
return
}
events := make([]voice.Event, 0, voice.MaxEvents)
var m rf.Monitor
lb := layer2.NewBurst()
voiceBursts := 0
onBursts := func(bs []rf.Burst) {
for i := range bs {
r, err := m.Burst(lb, &bs[i])
if err != nil || r.Hint.Slot != enums.Slot2 {
continue
}
now := time.Duration(math.Round(bs[i].Seconds*1000)) * time.Millisecond
for _, e := range call.Decoded(now, lb, r.Hint, events[:0]) {
switch e.Kind {
case voice.EventCallStart:
fmt.Printf("call from %d to %d (%v)\n", e.Call.Source, e.Call.Target, e.Call.Origin)
case voice.EventVoice:
voiceBursts++
case voice.EventCallEnd:
fmt.Printf("end: %v after %v, %d voice bursts\n", e.Reason, e.Stats.Duration, voiceBursts)
default:
}
}
}
}
rx, err := rf.NewReceiver(&rf.RxConfig{Tier: rf.Tier1, Rate: 256000, Format: rf.IQFormatCU8, OnBursts: onBursts})
if err != nil {
fmt.Println(err)
return
}
if _, err := rx.Write(iq); err != nil {
fmt.Println(err)
return
}
if err := rx.Flush(); err != nil {
fmt.Println(err)
}
}Run it from the v2 directory:
go test -run ExampleMonitor_capture -v ./rfIt prints:
call from 3191868 to 9 (Header)
end: Terminator after 540ms, 6 voice bursts
What the code does
- rf.NewReceiver makes the receiver from an rf.RxConfig: the sample rate, the sample format and the tier. The constructor allocates every buffer, and
WriteandFlushallocate nothing. Tierselects the detection and its compute cost. Tiers compares the four tiers.- With
OnBurstsset, the receiver is in stream mode.rx.Write(iq)takes samples in blocks of any size and callsOnBurstswith the bursts that they complete.rx.Flush()ends the stream. WithOnBurstsnil,rx.AppendBurstsandrx.AppendFlushappend the bursts to a slice. - The bursts in
OnBurstsare valid only during the call. Use them or copy them before the function returns. - An rf.Monitor follows the TDMA channels of the stream, as a scanner does.
m.Burst(lb, &bs[i])decodes the burst into thelayer2.Burstlb, and returns itslayer2.Hintwith the time slot from the CACHs. call.Decodedtakes the burst that the Monitor decoded, with that hint. The example keeps only the bursts of time slot 2. The time of each burst comes fromBurst.Seconds, its time in the stream.
Receive live
Write takes the samples as they come from the radio, so a live receiver is the same code with a reader in place of the file. The command dmrrf rx in v2/cmd/dmrrf reads I/Q or discriminator audio from a file or from standard input and prints each burst that it recovers, its decode, and the LC of each call. For example, with an RTL-SDR (put the frequency of your repeater in place of <Hz>):
rtl_sdr -f <Hz> -s 2048000 - | go run ./cmd/dmrrf rx -i - -format cu8 -rate 2048000An FM radio with a discriminator output also works. rf.NewAudioReceiver takes the samples of the discriminator in place of I/Q.
The Receiver datasheet gives the sensitivity, the compute and the memory of each tier.
Next: Next steps.