예제 #1
0
// newRXPacketFromRXPK transforms a Semtech packet into a models.RXPacket.
func newRXPacketFromRXPK(mac lorawan.EUI64, rxpk RXPK) (models.RXPacket, error) {
	var phy lorawan.PHYPayload
	if err := phy.UnmarshalText([]byte(rxpk.Data)); err != nil {
		return models.RXPacket{}, fmt.Errorf("gateway: could not unmarshal PHYPayload: %s", err)
	}

	dataRate, err := newDataRateFromDatR(rxpk.DatR)
	if err != nil {
		return models.RXPacket{}, fmt.Errorf("gateway: could not get DataRate from DatR: %s", err)
	}

	rxPacket := models.RXPacket{
		PHYPayload: phy,
		RXInfo: models.RXInfo{
			MAC:       mac,
			Time:      time.Time(rxpk.Time),
			Timestamp: rxpk.Tmst,
			Frequency: int(rxpk.Freq * 1000000),
			Channel:   int(rxpk.Chan),
			RFChain:   int(rxpk.RFCh),
			CRCStatus: int(rxpk.Stat),
			DataRate:  dataRate,
			CodeRate:  rxpk.CodR,
			RSSI:      int(rxpk.RSSI),
			LoRaSNR:   rxpk.LSNR,
			Size:      int(rxpk.Size),
		},
	}
	return rxPacket, nil
}