@@ -14,6 +14,7 @@ import (
1414 "github.com/brocaar/chirpstack-api/go/v3/common"
1515 "github.com/brocaar/chirpstack-api/go/v3/gw"
1616 "github.com/brocaar/lorawan"
17+ "github.com/brocaar/lorawan/gps"
1718)
1819
1920// loRaDataRateRegex contains a regexp for parsing the LoRa data-rate string.
@@ -202,6 +203,29 @@ func getUplinkFrame(gatewayID []byte, rxpk RXPK, FakeRxInfoTime bool) (gw.Uplink
202203 frame .RxInfo .TimeSinceGpsEpoch = ptypes .DurationProto (d )
203204 }
204205
206+ // Plain fine-timestamp (SX1302 / SX1303)
207+ if rxpk .Tmms != nil && rxpk .FTime != nil {
208+ d := time .Duration (* rxpk .Tmms ) * time .Millisecond
209+
210+ // take the seconds from the gps time
211+ d = d - (d % time .Second )
212+ // add the nanos from the fine-timestamp
213+ d = d + (time .Duration (* rxpk .FTime ) * time .Nanosecond )
214+
215+ t := time .Time (gps .NewTimeFromTimeSinceGPSEpoch (d ))
216+ tProto , err := ptypes .TimestampProto (t )
217+ if err != nil {
218+ return frame , errors .Wrap (err , "backend/semtechudp/packets: could not convert timestamp to proto timestamp" )
219+ }
220+
221+ frame .RxInfo .FineTimestampType = gw .FineTimestampType_PLAIN
222+ frame .RxInfo .FineTimestamp = & gw.UplinkRXInfo_PlainFineTimestamp {
223+ PlainFineTimestamp : & gw.PlainFineTimestamp {
224+ Time : tProto ,
225+ },
226+ }
227+ }
228+
205229 // LoRa data-rate
206230 if rxpk .DatR .LoRa != "" {
207231 frame .TxInfo .Modulation = common .Modulation_LORA
@@ -315,24 +339,25 @@ type Stat struct {
315339
316340// RXPK contain a RF packet and associated metadata.
317341type RXPK struct {
318- Time * CompactTime `json:"time"` // UTC time of pkt RX, us precision, ISO 8601 'compact' format (e.g. 2013-03-31T16:21:17.528002Z)
319- Tmms * int64 `json:"tmms"` // GPS time of pkt RX, number of milliseconds since 06.Jan.1980
320- Tmst uint32 `json:"tmst"` // Internal timestamp of "RX finished" event (32b unsigned)
321- AESK uint8 `json:"aesk"` //AES key index used for encrypting fine timestamps
322- Chan uint8 `json:"chan"` // Concentrator "IF" channel used for RX (unsigned integer)
323- RFCh uint8 `json:"rfch"` // Concentrator "RF chain" used for RX (unsigned integer)
324- Stat int8 `json:"stat"` // CRC status: 1 = OK, -1 = fail, 0 = no CRC
325- Freq float64 `json:"freq"` // RX central frequency in MHz (unsigned float, Hz precision)
326- Brd uint32 `json:"brd"` // Concentrator board used for RX (unsigned integer)
327- RSSI int16 `json:"rssi"` // RSSI in dBm (signed integer, 1 dB precision)
328- Size uint16 `json:"size"` // RF packet payload size in bytes (unsigned integer)
329- DatR DatR `json:"datr"` // LoRa datarate identifier (eg. SF12BW500) || FSK datarate (unsigned, in bits per second)
330- Modu string `json:"modu"` // Modulation identifier "LORA" or "FSK"
331- CodR string `json:"codr"` // LoRa ECC coding rate identifier
332- 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.
334- Data []byte `json:"data"` // Base64 encoded RF packet payload, padded
335- RSig []RSig `json:"rsig"` // Received signal information, per antenna (Optional)
342+ Time * CompactTime `json:"time"` // UTC time of pkt RX, us precision, ISO 8601 'compact' format (e.g. 2013-03-31T16:21:17.528002Z)
343+ Tmms * int64 `json:"tmms"` // GPS time of pkt RX, number of milliseconds since 06.Jan.1980
344+ Tmst uint32 `json:"tmst"` // Internal timestamp of "RX finished" event (32b unsigned)
345+ FTime * uint32 `json:"ftime"` // Fine timestamp, number of nanoseconds since last PPS [0..999999999] (Optional)
346+ AESK uint8 `json:"aesk"` // AES key index used for encrypting fine timestamps
347+ Chan uint8 `json:"chan"` // Concentrator "IF" channel used for RX (unsigned integer)
348+ RFCh uint8 `json:"rfch"` // Concentrator "RF chain" used for RX (unsigned integer)
349+ Stat int8 `json:"stat"` // CRC status: 1 = OK, -1 = fail, 0 = no CRC
350+ Freq float64 `json:"freq"` // RX central frequency in MHz (unsigned float, Hz precision)
351+ Brd uint32 `json:"brd"` // Concentrator board used for RX (unsigned integer)
352+ RSSI int16 `json:"rssi"` // RSSI in dBm (signed integer, 1 dB precision)
353+ Size uint16 `json:"size"` // RF packet payload size in bytes (unsigned integer)
354+ DatR DatR `json:"datr"` // LoRa datarate identifier (eg. SF12BW500) || FSK datarate (unsigned, in bits per second)
355+ Modu string `json:"modu"` // Modulation identifier "LORA" or "FSK"
356+ CodR string `json:"codr"` // LoRa ECC coding rate identifier
357+ LSNR float64 `json:"lsnr"` // Lora SNR ratio in dB (signed float, 0.1 dB precision)
358+ HPW uint8 `json:"hpw"` // LR-FHSS hopping grid number of steps.
359+ Data []byte `json:"data"` // Base64 encoded RF packet payload, padded
360+ RSig []RSig `json:"rsig"` // Received signal information, per antenna (Optional)
336361}
337362
338363// RSig contains the received signal information per antenna.
0 commit comments