-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_options.go
165 lines (157 loc) · 3.32 KB
/
list_options.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package soumuradio
import (
"fmt"
"net/url"
"strconv"
"time"
"github.com/tomato3713/soumuradio/prefecture"
"github.com/tomato3713/soumuradio/radiotype"
)
// ListOpts is Options of List Information API
type ListOpts struct {
// add detail informations
DA bool
// start count
SC int
// DC is data count
DC int
// ST is station target
ST TargetInfo
// OW is Type of radio station
OW radiotype.RadioStationType
// OW2 is only ST=2, Planning of radio station equipment
// TODO: make structure
OW2 string
// Comprehensive communication station
IT prefecture.Prefecture
// only ST=1, Prefecture / city
// Reference: http://www.soumu.go.jp/main_content/000632830.pdf
HCV string
// aim of radio
MK string
// only ST=1, Communication matters
TSNJK string
// only ST=1, Types of basic broadcasting
KHS string
// frequency (start)
// kHz: Integer part 10 digits, decimal part 6 digits or less
// MHz: Integer part 7 digits, decimal part 9 digits or less
// GHz: Integer part 4 digits, decimal part 12 digits or less
FF string
// frequency (final)
TF string
// Unit, kHz, MHz, GHz
HZ string
// name
// max length is 100 characters
NA string
// only ST=1, call sign
MA string
// only ST=1, Ship aircraft name
AS string
// licensed date (start)
DF time.Time
// licensed date (final)
DT time.Time
// SK is Sorting Key
SK SortingKey
}
// NewLicenseListOptions returns an initialized ListOpts structure.
func NewLicenseListOptions(ow radiotype.RadioStationType, da bool) ListOpts {
opts := ListOpts{}
opts.ST = License
opts.DA = da
opts.SC = 1
opts.DC = 1
opts.OW = ow
return opts
}
// NewRegistrationListOptions returns an initialized ListOpts structure.
func NewRegistrationListOptions(ow2 string, da bool) ListOpts {
opts := ListOpts{}
opts.ST = Registration
opts.DA = da
opts.SC = 1
opts.DC = 1
opts.OW2 = ow2
return opts
}
func (opt ListOpts) encodeOption() url.Values {
params := url.Values{}
if opt.DA {
params.Add("DA", "1")
} else {
params.Add("DA", "0")
}
params.Add("SC", strconv.Itoa(opt.SC))
params.Add("DC", strconv.Itoa(opt.DC))
params.Add("ST", strconv.Itoa(int(opt.ST)))
if opt.OW != "" {
params.Add("OW", string(opt.OW))
}
if opt.IT != "" {
params.Add("IT", string(opt.IT))
}
if opt.MK != "" {
params.Add("MK", opt.MK)
}
if opt.FF != "" {
params.Add("FF", opt.FF)
}
if opt.TF != "" {
params.Add("TF", opt.TF)
}
if opt.HZ != "" {
params.Add("HZ", opt.HZ)
}
if opt.NA != "" {
params.Add("NA", opt.NA)
}
if !opt.DT.IsZero() {
params.Add("DT", opt.DT.Format("20060102"))
}
if !opt.DF.IsZero() {
params.Add("DF", opt.DF.Format("20060102")) // only ST == 1 options
}
if opt.ST == 1 {
if opt.HCV != "" {
params.Add("HCV", opt.HCV)
}
if opt.TSNJK != "" {
params.Add("TSNJK", opt.TSNJK)
}
if opt.KHS != "" {
params.Add("KHS", opt.KHS)
}
if opt.MA != "" {
params.Add("MA", opt.MA)
}
if opt.AS != "" {
params.Add("AS", opt.AS)
}
}
if opt.ST == 2 {
// only ST=2, Planning of radio station equipment
if opt.OW2 != "" {
params.Add("OW2", opt.OW2)
}
}
return params
}
func getDigit(num int) int {
digit := 0
for num != 0 {
num /= 10
digit++
}
return num
}
func (opt *ListOpts) SetStartCount(sc int) error {
if sc != 0 {
if getDigit(sc) > 10 {
return fmt.Errorf("start count must be under 10 digits")
}
}
opt.SC = sc
return nil
}