These dmrgo docs are built from main and can describe changes that no release has yet. No release of dmrgo has these docs.

  1. DMRHub
  2. dmrgo
  3. Get started
  4. Follow a voice call

Follow a voice call

On this page

This step feeds the bursts of the same capture to a voice.Receiver, which turns them into the events of a call: its start, its voice bursts, its end and the end of its session.

Why a state machine

One burst does not give a call. A radio can join a call late, a burst can be lost, and a call ends at a terminator or when its bursts stop. A voice.Receiver holds the state of the call on one logical channel and returns an event for each change. (ETSI TS 102 361-1 clause 5.1.2, Annex G, ETSI TS 102 361-2 clause 5.2)

The Receiver does no I/O and reads no clock. You give it the time of each burst, and it appends its events to a slice that you give it. I/O-free services gives this rule for every machine of the library.

The code

The capture holds no time stamps, so the example puts the bursts of the time slot 60 ms apart, as they are on air:

func ExampleReceiver() {
    data, err := os.ReadFile("../layer2/testdata/parrot_kerchunk.bin")
    if err != nil {
        fmt.Println(err)
        return
    }
    rx, err := voice.NewReceiver(nil)
    if err != nil {
        fmt.Println(err)
        return
    }
    events := make([]voice.Event, 0, voice.MaxEvents)
    var now time.Duration
    voiceBursts := 0
    for off := 0; off+33 <= len(data); off += 33 {
        raw := layer2.RawBurst(data[off : off+33])
        now += 60 * time.Millisecond
        events = rx.Burst(now, &raw, layer2.Hint{}, events[:0])
        for _, e := range events {
            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:
            }
        }
    }
    if at, ok := rx.Deadline(); ok {
        for _, e := range rx.Tick(at, events[:0]) {
            fmt.Println(e.Kind, "at", at)
        }
    }
}

Run it from the v2 directory:

go test -run '^ExampleReceiver$' -v ./voice

It prints:

call from 3009999 to 9990 (Header)
end: Terminator after 840ms, 13 voice bursts
SessionEnd at 3.9s

What the code does

  • voice.NewReceiver(nil) makes a Receiver with the default config. voice.ReceiverConfig sets the color code, the timers and the other options.
  • rx.Burst(now, &raw, layer2.Hint{}, events[:0]) takes one 33-byte burst. The layer2.Hint holds the data of a transport about the burst besides its bits, such as the slot, the burst kind and a sequence number. A capture of bare bursts has none of these, so the hint is empty.
  • events has the capacity voice.MaxEvents, so the slice never grows and the call does not allocate. See Allocation.
  • EventCallStart carries the Call: the source, the target and the origin of the call identity. Here the origin is the Voice LC Header. On a late entry it is the embedded LC of the voice bursts.
  • EventVoice comes once for each voice burst, with its superframe position and its AMBE+2 frames. A codec, such as a DVSI chip or a software codec, turns the frames into speech. See the package vocoder.
  • EventCallEnd carries the reason and the statistics of the call.
  • After the call, rx.Deadline() returns the time of the next timer. rx.Tick(at, ...) at that time ends the hang time of the session with EventSessionEnd.

The voice.Receiver page gives the states, the config and the timers of the machine.

Next: Send an SMS.

Edit this page on GitHub