Skip to content

Commit 10f753a

Browse files
committed
basicstation: Fix tx acknowledgement and set Class-A RX2 params.
The BasicStation does not send a dntxed when the DevEUI is set to "00-00-00-00-00-00-00-00".
1 parent d26a298 commit 10f753a

File tree

3 files changed

+68
-7
lines changed

3 files changed

+68
-7
lines changed

internal/backend/basicstation/backend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (ts *BackendTestSuite) TestSendDownlinkFrame() {
344344

345345
assert.Equal(structs.DownlinkFrame{
346346
MessageType: structs.DownlinkMessage,
347-
DevEui: "00-00-00-00-00-00-00-00",
347+
DevEui: "01-01-01-01-01-01-01-01",
348348
DC: 0,
349349
DIID: 1234,
350350
Priority: 1,

internal/backend/basicstation/structs/downlink_message.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ func DownlinkFrameFromProto(loraBand band.Band, pb gw.DownlinkFrame) (DownlinkFr
4141
return DownlinkFrame{}, errors.New("items must contain at least one item")
4242
}
4343

44-
// TODO: implement for rx1 and rx2 parameters when there are two downlink items.
44+
// We assume this is for RX1
4545
item := pb.Items[0]
4646

4747
out := DownlinkFrame{
4848
MessageType: DownlinkMessage,
4949
Priority: 1, // not (yet) available through gw.DownlinkFrame
50-
DevEui: "00-00-00-00-00-00-00-00", // set to blank EUI
50+
DevEui: "01-01-01-01-01-01-01-01", // set to fake DevEUI (setting it to 0 causes the BasicStation to not send acks, see https://github.com/lorabasics/basicstation/issues/71).
5151
DIID: pb.Token,
5252
PDU: hex.EncodeToString(item.PhyPayload),
5353
}
@@ -137,5 +137,39 @@ func DownlinkFrameFromProto(loraBand band.Band, pb gw.DownlinkFrame) (DownlinkFr
137137
return out, fmt.Errorf("unexpected downlink timing: %s", item.GetTxInfo().Timing)
138138
}
139139

140+
// We assume this is the RX2.
141+
if len(pb.Items) == 2 {
142+
item := pb.Items[1]
143+
144+
if item.GetTxInfo().GetDelayTimingInfo() != nil {
145+
if modInfo := item.GetTxInfo().GetLoraModulationInfo(); modInfo != nil {
146+
dr, err := loraBand.GetDataRateIndex(false, band.DataRate{
147+
Modulation: band.LoRaModulation,
148+
SpreadFactor: int(modInfo.SpreadingFactor),
149+
Bandwidth: int(modInfo.Bandwidth),
150+
})
151+
if err != nil {
152+
return out, errors.Wrap(err, "get data-rate index error")
153+
}
154+
155+
out.RX2Freq = &item.GetTxInfo().Frequency
156+
out.RX2DR = &dr
157+
}
158+
159+
if modInfo := item.GetTxInfo().GetFskModulationInfo(); modInfo != nil {
160+
dr, err := loraBand.GetDataRateIndex(false, band.DataRate{
161+
Modulation: band.FSKModulation,
162+
BitRate: int(modInfo.Datarate),
163+
})
164+
if err != nil {
165+
return out, errors.Wrap(err, "get data-rate index error")
166+
}
167+
168+
out.RX2Freq = &item.GetTxInfo().Frequency
169+
out.RX2DR = &dr
170+
}
171+
}
172+
}
173+
140174
return out, nil
141175
}

internal/backend/basicstation/structs/downlink_message_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import (
1414

1515
func TestDownlinkFrameFromProto(t *testing.T) {
1616
delay1 := 1
17+
dr1 := 1
1718
dr2 := 2
1819
dr7 := 7
1920
freq := uint32(868100000)
21+
freq2 := uint32(868200000)
2022
rCtx := uint64(3)
2123
xTime := uint64(4)
2224
gpsTime := uint64(time.Second / time.Microsecond)
@@ -56,11 +58,34 @@ func TestDownlinkFrameFromProto(t *testing.T) {
5658
Context: []byte{0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4},
5759
},
5860
},
61+
{
62+
PhyPayload: []byte{1, 2, 3, 4},
63+
TxInfo: &gw.DownlinkTXInfo{
64+
Frequency: 868200000,
65+
Power: 14,
66+
Modulation: common.Modulation_LORA,
67+
ModulationInfo: &gw.DownlinkTXInfo_LoraModulationInfo{
68+
LoraModulationInfo: &gw.LoRaModulationInfo{
69+
Bandwidth: 125,
70+
SpreadingFactor: 11,
71+
CodeRate: "4/5",
72+
PolarizationInversion: true,
73+
},
74+
},
75+
Timing: gw.DownlinkTiming_DELAY,
76+
TimingInfo: &gw.DownlinkTXInfo_DelayTimingInfo{
77+
DelayTimingInfo: &gw.DelayTimingInfo{
78+
Delay: ptypes.DurationProto(time.Second * 2),
79+
},
80+
},
81+
Context: []byte{0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4},
82+
},
83+
},
5984
},
6085
},
6186
Out: DownlinkFrame{
6287
MessageType: DownlinkMessage,
63-
DevEui: "00-00-00-00-00-00-00-00",
88+
DevEui: "01-01-01-01-01-01-01-01",
6489
DC: 0,
6590
DIID: 1234,
6691
Priority: 1,
@@ -70,6 +95,8 @@ func TestDownlinkFrameFromProto(t *testing.T) {
7095
RxDelay: &delay1,
7196
RX1DR: &dr2,
7297
RX1Freq: &freq,
98+
RX2DR: &dr1,
99+
RX2Freq: &freq2,
73100
},
74101
},
75102
{
@@ -102,7 +129,7 @@ func TestDownlinkFrameFromProto(t *testing.T) {
102129
},
103130
Out: DownlinkFrame{
104131
MessageType: DownlinkMessage,
105-
DevEui: "00-00-00-00-00-00-00-00",
132+
DevEui: "01-01-01-01-01-01-01-01",
106133
DC: 0,
107134
DIID: 1234,
108135
Priority: 1,
@@ -147,7 +174,7 @@ func TestDownlinkFrameFromProto(t *testing.T) {
147174
},
148175
Out: DownlinkFrame{
149176
MessageType: DownlinkMessage,
150-
DevEui: "00-00-00-00-00-00-00-00",
177+
DevEui: "01-01-01-01-01-01-01-01",
151178
DC: 1,
152179
DIID: 1234,
153180
Priority: 1,
@@ -187,7 +214,7 @@ func TestDownlinkFrameFromProto(t *testing.T) {
187214
},
188215
Out: DownlinkFrame{
189216
MessageType: DownlinkMessage,
190-
DevEui: "00-00-00-00-00-00-00-00",
217+
DevEui: "01-01-01-01-01-01-01-01",
191218
DC: 2,
192219
DIID: 1234,
193220
Priority: 1,

0 commit comments

Comments
 (0)