-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgeneric_telem.go
58 lines (56 loc) · 1.13 KB
/
generic_telem.go
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
53
54
55
56
57
58
package sitlgen
import (
"log"
"net"
/**
"encoding/binary"
"fmt"
"io"
"os"
"time"
**/)
func GenericTelemReader(name string, tconn net.Conn) {
inp := make([]byte, 256)
conn, err := net.ListenPacket("udp", ":0")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
loc := tconn.LocalAddr().String()
dst, err := net.ResolveUDPAddr("udp", loc)
if err != nil {
log.Fatal(err)
}
/*****************
var start time.Time
w, err := os.Create(fmt.Sprintf("/tmp/%s-telem.log", name))
if err == nil {
defer w.Close()
w.Write([]byte("v2\n"))
} else {
return
}
**********************************/
for {
nb, err := tconn.Read(inp)
if err == nil {
conn.WriteTo(inp[0:nb], dst)
/********************
if start.IsZero() {
start = time.Now()
}
diff := float64(time.Now().Sub(start)) / 1000000000.0
var header = struct {
offset float64
size uint16
dirn byte
}{offset: diff, size: uint16(nb), dirn: 'i'}
binary.Write(w, binary.LittleEndian, header)
w.Write(inp[0:nb])
************/
} else {
tconn.Close()
return
}
}
}