-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathntrip_source.go
100 lines (79 loc) · 1.78 KB
/
ntrip_source.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package ntrip_client
import (
"net/url"
"github.com/bezineb5/ntrip-client/input"
"github.com/go-gnss/ntrip"
)
type CasterSource interface {
RegisterMountPoints(Registry) error
}
type ntripSource struct {
input input.SourceTableInput
sourceTable *ntrip.Sourcetable
}
func NewSource(input input.SourceTableInput) CasterSource {
return &ntripSource{
input: input,
}
}
func (s *ntripSource) RegisterMountPoints(registry Registry) error {
if s.sourceTable == nil {
src, err := s.input.SourceTable()
if err != nil {
return err
}
s.sourceTable = &src
}
// Mount points
for _, mountpoint := range s.sourceTable.Mounts {
/*url := url.URL{}
url.Host = caster.Host
if caster.Port != 0 {
url.Host = url.Host + ":" + strconv.Itoa(caster.Port)
}
mountpoint.String()*/
mpUrl, err := buildMountpointUrl(s.input.Url(), mountpoint.Name)
if err != nil {
return err
}
registry.RegisterStation(
mpUrl,
mountpoint)
}
// Other referenced casters
/*for _, casters := range s.sourceTable.Casters {
}*/
return nil
}
func buildMountpointUrl(casterUrl string, mountpoint string) (string, error) {
// Build a URL with the mount point
u, err := url.Parse(casterUrl)
if err != nil {
return casterUrl, err
}
u.Path = url.PathEscape(mountpoint)
return u.String(), nil
}
/*func (s *ntripSource) RegisterCasters(registry Registry) error {
if s.sourceTable == nil {
src, err := s.input.SourceTable()
if err != nil {
return err
}
s.sourceTable = &src
}
for _, caster := range s.sourceTable.Casters {
url := url.URL{}
url.Host = caster.Host
if caster.Port != 0 {
url.Host = url.Host + ":" + strconv.Itoa(caster.Port)
}
registry.Register(
s,
url.String(),
caster.Identifier,
caster.Latitude,
caster.Longitude)
}
return nil
}*/