/
mode.go
99 lines (72 loc) · 2.58 KB
/
mode.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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package helpers
import (
"strings"
"unicode"
"3e8.eu/go/dsl/models"
)
func ParseMode(str string) models.Mode {
str = strings.Map(func(r rune) rune {
if unicode.IsSpace(r) || r == '_' {
return -1
}
return unicode.ToLower(r)
}, str)
var mode models.Mode
switch {
case strings.Contains(str, "adsl"), strings.Contains(str, "g.dmt"), strings.Contains(str, "g.992"):
if strings.Contains(str, "adsl2+") || strings.Contains(str, "adsl2p") || strings.Contains(str, "g.992.5") {
mode.Type = models.ModeTypeADSL2Plus
} else if strings.Contains(str, "adsl2") || strings.Contains(str, "g.992.3") {
mode.Type = models.ModeTypeADSL2
} else {
mode.Type = models.ModeTypeADSL
}
switch {
case strings.Contains(str, "annexa"):
mode.Subtype = models.ModeSubtypeAnnexA
case strings.Contains(str, "annexb"):
mode.Subtype = models.ModeSubtypeAnnexB
case strings.Contains(str, "annexi"):
mode.Subtype = models.ModeSubtypeAnnexI
case strings.Contains(str, "annexj"):
mode.Subtype = models.ModeSubtypeAnnexJ
case strings.Contains(str, "annexl"):
mode.Subtype = models.ModeSubtypeAnnexL
case strings.Contains(str, "annexm"):
mode.Subtype = models.ModeSubtypeAnnexM
}
case strings.Contains(str, "8a"):
mode.Type = models.ModeTypeVDSL2
mode.Subtype = models.ModeSubtypeProfile8a
case strings.Contains(str, "8b"):
mode.Type = models.ModeTypeVDSL2
mode.Subtype = models.ModeSubtypeProfile8b
case strings.Contains(str, "8c"):
mode.Type = models.ModeTypeVDSL2
mode.Subtype = models.ModeSubtypeProfile8c
case strings.Contains(str, "8d"):
mode.Type = models.ModeTypeVDSL2
mode.Subtype = models.ModeSubtypeProfile8d
case strings.Contains(str, "12a"):
mode.Type = models.ModeTypeVDSL2
mode.Subtype = models.ModeSubtypeProfile12a
case strings.Contains(str, "12b"):
mode.Type = models.ModeTypeVDSL2
mode.Subtype = models.ModeSubtypeProfile12b
case strings.Contains(str, "17a"):
mode.Type = models.ModeTypeVDSL2
mode.Subtype = models.ModeSubtypeProfile17a
case strings.Contains(str, "30a"):
mode.Type = models.ModeTypeVDSL2
mode.Subtype = models.ModeSubtypeProfile30a
case strings.Contains(str, "35b"):
mode.Type = models.ModeTypeVDSL2
mode.Subtype = models.ModeSubtypeProfile35b
case strings.Contains(str, "vdsl2"), strings.Contains(str, "g.993.2"), strings.Contains(str, "g.993.5"):
mode.Type = models.ModeTypeVDSL2
}
return mode
}