-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.go
More file actions
52 lines (44 loc) · 1.15 KB
/
send.go
File metadata and controls
52 lines (44 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Copyright (c) 2020-2022 by Eric Jacksch VE3XEJ
*/
package main
import (
"log"
"dmrcmd/bytes"
)
// Send NAC to repeater (MSTNAK + id)
func sendNAK(dg *datagram) {
log.Printf("Sending RPTNAK to %d @ %s\n", dg.hotspot.Uint32(), safeAddrString(dg.addr))
reply := bytes.New()
reply.AppendString("MSTNAK")
reply.Append(dg.hotspot)
sendUDP(dg, reply)
}
// Send ACK to repeater (RPTACK + id)
func sendACK(dg *datagram) {
log.Printf("Sending RPTACK to %d @ %s\n", dg.hotspot.Uint32(), safeAddrString(dg.addr))
reply := bytes.New()
reply.AppendString("RPTACK")
reply.Append(dg.hotspot)
sendUDP(dg, reply)
}
// Send ping reply (pong) to repeater
func sendPONG(dg *datagram) {
log.Printf("Pong to %d @ %s\n", dg.hotspot.Uint32(), safeAddrString(dg.addr))
reply := bytes.New()
reply.AppendString("MSTPONG")
reply.Append(dg.hotspot)
sendUDP(dg, reply)
}
// Send UDP datagram
func sendUDP(dg *datagram, buf bytes.Bytes) {
n, err := dg.pc.WriteTo(buf, dg.addr)
if err != nil {
log.Printf("error sending UDP datagram to %s\n", safeAddrString(dg.addr))
return
}
if config.Debug {
log.Printf("Sent %d bytes to %s", n, safeAddrString(dg.addr))
dump(buf)
}
}