@@ -16,9 +16,12 @@ import (
1616 "github.com/brocaar/lorawan"
1717)
1818
19- // loRaDataRateRegex contains a regexp for parsing the data-rate string.
19+ // loRaDataRateRegex contains a regexp for parsing the LoRa data-rate string.
2020var loRaDataRateRegex = regexp .MustCompile (`SF(\d+)BW(\d+)` )
2121
22+ // lrFHSSDataRateRegex contains the regexp for parsing the LR-FHSS data-rate string.
23+ var lrFHSSDataRateRegex = regexp .MustCompile (`M0CW(\d+)` )
24+
2225// PushDataPacket type is used by the gateway mainly to forward the RF packets
2326// received, and associated metadata, to the server.
2427type PushDataPacket struct {
@@ -203,8 +206,8 @@ func getUplinkFrame(gatewayID []byte, rxpk RXPK, FakeRxInfoTime bool) (gw.Uplink
203206 if rxpk .DatR .LoRa != "" {
204207 frame .TxInfo .Modulation = common .Modulation_LORA
205208
206- match := loRaDataRateRegex .FindStringSubmatch (rxpk .DatR .LoRa )
207209 // parse e.g. SF12BW250 into separate variables
210+ match := loRaDataRateRegex .FindStringSubmatch (rxpk .DatR .LoRa )
208211 if len (match ) != 3 {
209212 return frame , errors .New ("backend/semtechudp/packets: could not parse LoRa data-rate" )
210213 }
@@ -229,6 +232,31 @@ func getUplinkFrame(gatewayID []byte, rxpk RXPK, FakeRxInfoTime bool) (gw.Uplink
229232 }
230233 }
231234
235+ // LR-FHSS data-rate
236+ if rxpk .DatR .LRFHSS != "" {
237+ frame .TxInfo .Modulation = common .Modulation_LR_FHSS
238+
239+ // parse M0CW137 into CW (OCW) variable
240+ match := lrFHSSDataRateRegex .FindStringSubmatch (rxpk .DatR .LRFHSS )
241+ if len (match ) != 2 {
242+ return frame , errors .New ("backend/semtechudp/packets: could not parse LR-FHSS data-rate" )
243+ }
244+
245+ // cast variable to int
246+ ocw , err := strconv .Atoi (match [1 ])
247+ if err != nil {
248+ return frame , errors .Wrap (err , "backend/semtechudp/packets: could not convert cw to int" )
249+ }
250+
251+ frame .TxInfo .ModulationInfo = & gw.UplinkTXInfo_LrFhssModulationInfo {
252+ LrFhssModulationInfo : & gw.LRFHSSModulationInfo {
253+ OperatingChannelWidth : uint32 (ocw ) * 1000 , // kHz -> Hz
254+ CodeRate : rxpk .CodR ,
255+ GridSteps : uint32 (rxpk .HPW ),
256+ },
257+ }
258+ }
259+
232260 // FSK data-rate
233261 if rxpk .DatR .FSK != 0 {
234262 frame .TxInfo .Modulation = common .Modulation_FSK
@@ -302,6 +330,7 @@ type RXPK struct {
302330 Modu string `json:"modu"` // Modulation identifier "LORA" or "FSK"
303331 CodR string `json:"codr"` // LoRa ECC coding rate identifier
304332 LSNR float64 `json:"lsnr"` // Lora SNR ratio in dB (signed float, 0.1 dB precision)
333+ HPW uint8 `json:"hpw"` // LR-FHSS hopping grid number of steps.
305334 Data []byte `json:"data"` // Base64 encoded RF packet payload, padded
306335 RSig []RSig `json:"rsig"` // Received signal information, per antenna (Optional)
307336}
0 commit comments