1
1
package main
2
2
3
3
import (
4
- "fmt"
5
- "net/http"
6
4
"encoding/json"
7
- "time "
5
+ "fmt "
8
6
"log"
9
7
"net"
10
- "sync "
8
+ "net/http "
11
9
"strings"
10
+ "sync"
11
+ "time"
12
12
)
13
13
14
14
type bmServerData struct {
15
15
Network string
16
- Name string
17
- Host string
18
- }
19
-
20
- type bmReflectorData struct {
21
- Active int
16
+ Name string
17
+ Host string
22
18
}
23
19
24
20
type bmSubscription struct {
25
- Talkgroup int
21
+ Talkgroup string
26
22
}
27
23
28
24
type bmClientData struct {
29
- Reflector bmReflectorData
30
- StaticSubscriptions []bmSubscription
25
+ StaticSubscriptions []bmSubscription
31
26
DynamicSubscriptions []bmSubscription
32
27
}
33
28
34
29
type bmServerIP string
30
+
35
31
var bmServerIPHosts = make (map [bmServerIP ]bmServerData )
36
32
var bmServerIPHostsMutex = & sync.Mutex {}
37
33
38
34
func getJson (url string , target interface {}) error {
39
- var httpClient = & http.Client { Timeout : 2000 * time .Millisecond }
35
+ var httpClient = & http.Client {Timeout : 2000 * time .Millisecond }
40
36
r , err := httpClient .Get (url )
41
37
if err != nil {
42
38
return err
@@ -47,7 +43,7 @@ func getJson(url string, target interface{}) error {
47
43
}
48
44
49
45
func BMGetClientData (clientId uint32 , result * bmClientData , finished chan bool ) {
50
- url := fmt .Sprintf ("https://api.brandmeister.network/v1.0/repeater/?action=PROFILE&q=%d " , clientId )
46
+ url := fmt .Sprintf ("https://api.brandmeister.network/v2/device/%d/profile " , clientId )
51
47
err := getJson (url , result )
52
48
if err != nil {
53
49
log .Println ("getjson error: " , err )
@@ -58,12 +54,11 @@ func BMGetClientData(clientId uint32, result *bmClientData, finished chan bool)
58
54
59
55
func BMGenerateCodeStrFromClientData (cd * bmClientData , sd * bmServerData , shortened bool ) string {
60
56
var networkIDStr string
61
- var refStr string
62
57
var stgStr string
63
58
var dtgStr string
64
59
65
60
if lastIndex := strings .LastIndex (sd .Name , "/" ); lastIndex >= 0 {
66
- for i := lastIndex + 1 ; i < len (sd .Name ); i ++ {
61
+ for i := lastIndex + 1 ; i < len (sd .Name ); i ++ {
67
62
networkIDStr += "0" + string (sd .Name [i ])
68
63
}
69
64
}
@@ -79,7 +74,7 @@ func BMGenerateCodeStrFromClientData(cd *bmClientData, sd *bmServerData, shorten
79
74
if i > 0 {
80
75
stgStr += "ND"
81
76
}
82
- tg := fmt . Sprintf ( "%d" , cd .StaticSubscriptions [i ].Talkgroup )
77
+ tg := cd .StaticSubscriptions [i ].Talkgroup
83
78
for j := 0 ; j < len (tg ); j ++ {
84
79
stgStr += "0" + string (tg [j ])
85
80
}
@@ -89,34 +84,26 @@ func BMGenerateCodeStrFromClientData(cd *bmClientData, sd *bmServerData, shorten
89
84
if len (cd .DynamicSubscriptions ) > 0 {
90
85
if len (cd .DynamicSubscriptions ) > 1 {
91
86
dtgStr = "LKDNGS"
92
- } else if cd .DynamicSubscriptions [0 ].Talkgroup != 4000 {
87
+ } else if cd .DynamicSubscriptions [0 ].Talkgroup != " 4000" {
93
88
dtgStr = "LKDNTG"
94
89
}
95
90
for i := 0 ; i < len (cd .DynamicSubscriptions ); i ++ {
96
- if cd .DynamicSubscriptions [i ].Talkgroup == 4000 {
91
+ if cd .DynamicSubscriptions [i ].Talkgroup == " 4000" {
97
92
continue
98
93
}
99
94
100
95
if i > 0 {
101
96
dtgStr += "ND"
102
97
}
103
- tg := fmt . Sprintf ( "%d" , cd .DynamicSubscriptions [i ].Talkgroup )
98
+ tg := cd .DynamicSubscriptions [i ].Talkgroup
104
99
for j := 0 ; j < len (tg ); j ++ {
105
100
dtgStr += "0" + string (tg [j ])
106
101
}
107
102
}
108
103
}
109
-
110
- if cd .Reflector .Active != 4000 && cd .Reflector .Active != 0 {
111
- refStr = "LKRF"
112
- ref := fmt .Sprintf ("%d" , cd .Reflector .Active )
113
- for i := 0 ; i < len (ref ); i ++ {
114
- refStr += "0" + string (ref [i ])
115
- }
116
- }
117
104
}
118
105
119
- return "BM" + networkIDStr + stgStr + dtgStr + refStr
106
+ return "BM" + networkIDStr + stgStr + dtgStr
120
107
}
121
108
122
109
func BMGetServerDataForServerIP (addr string ) (bmServerData , bool ) {
0 commit comments