-
Notifications
You must be signed in to change notification settings - Fork 310
/
metadata_populate.go
81 lines (78 loc) · 2.28 KB
/
metadata_populate.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
// Copyright © 2019 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ttnpb
import (
pbtypes "github.com/gogo/protobuf/types"
)
func NewPopulatedRxMetadata(r randyMetadata, easy bool) *RxMetadata {
this := &RxMetadata{}
v1 := NewPopulatedGatewayIdentifiers(r, easy)
this.GatewayIdentifiers = *v1
if r.Intn(2) == 0 {
this.PacketBroker = NewPopulatedPacketBrokerMetadata(r, easy)
}
this.AntennaIndex = r.Uint32()
if r.Intn(10) != 0 {
this.Time = pbtypes.NewPopulatedStdTime(r, easy)
}
this.Timestamp = r.Uint32()
this.FineTimestamp = uint64(r.Uint32())
v2 := r.Intn(100)
this.EncryptedFineTimestamp = make([]byte, v2)
for i := 0; i < v2; i++ {
this.EncryptedFineTimestamp[i] = byte(r.Intn(256))
}
this.EncryptedFineTimestampKeyID = randStringMetadata(r)
this.RSSI = float32(r.Float32())
if r.Intn(2) == 0 {
this.RSSI *= -1
}
this.ChannelRSSI = float32(r.Float32())
if r.Intn(2) == 0 {
this.ChannelRSSI *= -1
}
this.RSSIStandardDeviation = float32(r.Float32())
if r.Intn(2) == 0 {
this.RSSIStandardDeviation *= -1
}
this.SNR = float32(r.Float32())
if r.Intn(2) == 0 {
this.SNR *= -1
}
this.FrequencyOffset = r.Int63()
if r.Intn(2) == 0 {
this.FrequencyOffset *= -1
}
if r.Intn(10) != 0 {
this.Location = NewPopulatedLocation(r, easy)
}
this.DownlinkPathConstraint = DownlinkPathConstraint([]int32{0, 1, 2}[r.Intn(3)])
v3 := r.Intn(100)
this.UplinkToken = make([]byte, v3)
for i := 0; i < v3; i++ {
this.UplinkToken[i] = byte(r.Intn(256))
}
if r.Intn(2) == 0 {
this.SignalRSSI = &pbtypes.FloatValue{
Value: -r.Float32(),
}
}
this.ChannelIndex = uint32(r.Intn(256))
if r.Intn(10) != 0 {
this.Advanced = pbtypes.NewPopulatedStruct(r, easy)
}
if !easy && r.Intn(10) != 0 {
}
return this
}