@@ -2,12 +2,16 @@ package packets
2
2
3
3
import (
4
4
"testing"
5
+ "time"
5
6
6
- "github.com/stretchr/testify/assert"
7
+ "github.com/brocaar/loraserver/api/common"
8
+ "github.com/brocaar/loraserver/api/gw"
9
+ "github.com/golang/protobuf/ptypes"
10
+ "github.com/stretchr/testify/require"
7
11
)
8
12
9
13
func TestPullResp (t * testing.T ) {
10
- assert := assert .New (t )
14
+ assert := require .New (t )
11
15
12
16
testTable := []struct {
13
17
Bytes []byte
@@ -38,3 +42,223 @@ func TestPullResp(t *testing.T) {
38
42
assert .Equal (test .PullRespPacket , p )
39
43
}
40
44
}
45
+
46
+ func TestGetPullRespPacket (t * testing.T ) {
47
+ timestamp := uint32 (2000000 )
48
+ timeSinceGPSEpoch := int64 (5 * time .Second / time .Millisecond )
49
+
50
+ tests := []struct {
51
+ Name string
52
+ DownlinkFrame gw.DownlinkFrame
53
+ PullRespPacket PullRespPacket
54
+ Error error
55
+ }{
56
+ {
57
+ Name : "delay timing - lora" ,
58
+ DownlinkFrame : gw.DownlinkFrame {
59
+ PhyPayload : []byte {1 , 2 , 3 , 4 },
60
+ TxInfo : & gw.DownlinkTXInfo {
61
+ GatewayId : []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 },
62
+ Frequency : 868100000 ,
63
+ Power : 14 ,
64
+ Modulation : common .Modulation_LORA ,
65
+ ModulationInfo : & gw.DownlinkTXInfo_LoraModulationInfo {
66
+ LoraModulationInfo : & gw.LoRaModulationInfo {
67
+ SpreadingFactor : 12 ,
68
+ Bandwidth : 125 ,
69
+ PolarizationInversion : true ,
70
+ CodeRate : "4/5" ,
71
+ },
72
+ },
73
+ Board : 1 ,
74
+ Antenna : 2 ,
75
+ Timing : gw .DownlinkTiming_DELAY ,
76
+ TimingInfo : & gw.DownlinkTXInfo_DelayTimingInfo {
77
+ DelayTimingInfo : & gw.DelayTimingInfo {
78
+ Delay : ptypes .DurationProto (time .Second ),
79
+ },
80
+ },
81
+ Context : []byte {0x00 , 0x0f , 0x42 , 0x40 },
82
+ },
83
+ Token : 1234 ,
84
+ },
85
+ PullRespPacket : PullRespPacket {
86
+ ProtocolVersion : ProtocolVersion2 ,
87
+ RandomToken : 1234 ,
88
+ Payload : PullRespPayload {
89
+ TXPK : TXPK {
90
+ Powe : 14 ,
91
+ Ant : 2 ,
92
+ Brd : 1 ,
93
+ Freq : 868.1 ,
94
+ Modu : "LORA" ,
95
+ Tmst : & timestamp ,
96
+ DatR : DatR {
97
+ LoRa : "SF12BW125" ,
98
+ },
99
+ CodR : "4/5" ,
100
+ IPol : true ,
101
+ Size : 4 ,
102
+ Data : []byte {0x01 , 0x02 , 0x03 , 0x04 },
103
+ },
104
+ },
105
+ },
106
+ },
107
+ {
108
+ Name : "delay timing - fsk" ,
109
+ DownlinkFrame : gw.DownlinkFrame {
110
+ PhyPayload : []byte {1 , 2 , 3 , 4 },
111
+ TxInfo : & gw.DownlinkTXInfo {
112
+ GatewayId : []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 },
113
+ Frequency : 868100000 ,
114
+ Power : 14 ,
115
+ Modulation : common .Modulation_FSK ,
116
+ ModulationInfo : & gw.DownlinkTXInfo_FskModulationInfo {
117
+ FskModulationInfo : & gw.FSKModulationInfo {
118
+ Bitrate : 50000 ,
119
+ },
120
+ },
121
+ Board : 1 ,
122
+ Antenna : 2 ,
123
+ Timing : gw .DownlinkTiming_DELAY ,
124
+ TimingInfo : & gw.DownlinkTXInfo_DelayTimingInfo {
125
+ DelayTimingInfo : & gw.DelayTimingInfo {
126
+ Delay : ptypes .DurationProto (time .Second ),
127
+ },
128
+ },
129
+ Context : []byte {0x00 , 0x0f , 0x42 , 0x40 },
130
+ },
131
+ Token : 1234 ,
132
+ },
133
+ PullRespPacket : PullRespPacket {
134
+ ProtocolVersion : ProtocolVersion2 ,
135
+ RandomToken : 1234 ,
136
+ Payload : PullRespPayload {
137
+ TXPK : TXPK {
138
+ Powe : 14 ,
139
+ Ant : 2 ,
140
+ Brd : 1 ,
141
+ Freq : 868.1 ,
142
+ Modu : "FSK" ,
143
+ Tmst : & timestamp ,
144
+ DatR : DatR {
145
+ FSK : 50000 ,
146
+ },
147
+ FDev : 25000 ,
148
+ Size : 4 ,
149
+ Data : []byte {0x01 , 0x02 , 0x03 , 0x04 },
150
+ },
151
+ },
152
+ },
153
+ },
154
+ {
155
+ Name : "immmediately" ,
156
+ DownlinkFrame : gw.DownlinkFrame {
157
+ PhyPayload : []byte {1 , 2 , 3 , 4 },
158
+ TxInfo : & gw.DownlinkTXInfo {
159
+ GatewayId : []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 },
160
+ Frequency : 868100000 ,
161
+ Power : 14 ,
162
+ Modulation : common .Modulation_LORA ,
163
+ ModulationInfo : & gw.DownlinkTXInfo_LoraModulationInfo {
164
+ LoraModulationInfo : & gw.LoRaModulationInfo {
165
+ SpreadingFactor : 12 ,
166
+ Bandwidth : 125 ,
167
+ PolarizationInversion : true ,
168
+ CodeRate : "4/5" ,
169
+ },
170
+ },
171
+ Board : 1 ,
172
+ Antenna : 2 ,
173
+ Timing : gw .DownlinkTiming_IMMEDIATELY ,
174
+ },
175
+ Token : 1234 ,
176
+ },
177
+ PullRespPacket : PullRespPacket {
178
+ ProtocolVersion : ProtocolVersion2 ,
179
+ RandomToken : 1234 ,
180
+ Payload : PullRespPayload {
181
+ TXPK : TXPK {
182
+ Powe : 14 ,
183
+ Ant : 2 ,
184
+ Brd : 1 ,
185
+ Freq : 868.1 ,
186
+ Modu : "LORA" ,
187
+ Imme : true ,
188
+ DatR : DatR {
189
+ LoRa : "SF12BW125" ,
190
+ },
191
+ CodR : "4/5" ,
192
+ IPol : true ,
193
+ Size : 4 ,
194
+ Data : []byte {0x01 , 0x02 , 0x03 , 0x04 },
195
+ },
196
+ },
197
+ },
198
+ },
199
+ {
200
+ Name : "gps epoch" ,
201
+ DownlinkFrame : gw.DownlinkFrame {
202
+ PhyPayload : []byte {1 , 2 , 3 , 4 },
203
+ TxInfo : & gw.DownlinkTXInfo {
204
+ GatewayId : []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 },
205
+ Frequency : 868100000 ,
206
+ Power : 14 ,
207
+ Modulation : common .Modulation_LORA ,
208
+ ModulationInfo : & gw.DownlinkTXInfo_LoraModulationInfo {
209
+ LoraModulationInfo : & gw.LoRaModulationInfo {
210
+ SpreadingFactor : 12 ,
211
+ Bandwidth : 125 ,
212
+ PolarizationInversion : true ,
213
+ CodeRate : "4/5" ,
214
+ },
215
+ },
216
+ Board : 1 ,
217
+ Antenna : 2 ,
218
+ Timing : gw .DownlinkTiming_GPS_EPOCH ,
219
+ TimingInfo : & gw.DownlinkTXInfo_GpsEpochTimingInfo {
220
+ GpsEpochTimingInfo : & gw.GPSEpochTimingInfo {
221
+ TimeSinceGpsEpoch : ptypes .DurationProto (5 * time .Second ),
222
+ },
223
+ },
224
+ },
225
+ Token : 1234 ,
226
+ },
227
+ PullRespPacket : PullRespPacket {
228
+ ProtocolVersion : ProtocolVersion2 ,
229
+ RandomToken : 1234 ,
230
+ Payload : PullRespPayload {
231
+ TXPK : TXPK {
232
+ Powe : 14 ,
233
+ Ant : 2 ,
234
+ Brd : 1 ,
235
+ Freq : 868.1 ,
236
+ Tmms : & timeSinceGPSEpoch ,
237
+ Modu : "LORA" ,
238
+ DatR : DatR {
239
+ LoRa : "SF12BW125" ,
240
+ },
241
+ CodR : "4/5" ,
242
+ IPol : true ,
243
+ Size : 4 ,
244
+ Data : []byte {0x01 , 0x02 , 0x03 , 0x04 },
245
+ },
246
+ },
247
+ },
248
+ },
249
+ }
250
+
251
+ for _ , tst := range tests {
252
+ t .Run (tst .Name , func (t * testing.T ) {
253
+ assert := require .New (t )
254
+
255
+ resp , err := GetPullRespPacket (ProtocolVersion2 , 1234 , tst .DownlinkFrame )
256
+ assert .Equal (tst .Error , err )
257
+ if err != nil {
258
+ return
259
+ }
260
+
261
+ assert .Equal (tst .PullRespPacket , resp )
262
+ })
263
+ }
264
+ }
0 commit comments