func GetStatsID(v *gw.GatewayStats) uuid.UUID {
	var statsID uuid.UUID
	if v != nil {
		copy(statsID[:], v.GetStatsId())
	}
	return statsID
}
GetStatsID returns the typed stats ID.
package helpers
import (
	"context"
	"fmt"
	"github.com/brocaar/chirpstack-network-server/v3/internal/backend/applicationserver"
	"github.com/brocaar/chirpstack-network-server/v3/internal/storage"
	"github.com/brocaar/lorawan"
	"github.com/gofrs/uuid"
	"github.com/brocaar/chirpstack-api/go/v3/as"
	"github.com/brocaar/chirpstack-api/go/v3/common"
	"github.com/brocaar/chirpstack-api/go/v3/gw"
	"github.com/brocaar/lorawan/band"
	"github.com/pkg/errors"
)
const defaultCodeRate = "4/5"
type GatewayIDGetter interface {
	GetGatewayId() []byte
}
type DownlinkIDGetter interface {
	GetDownlinkId() []byte
}
type DataRateGetter interface {
	GetModulation() common.Modulation
	GetLoraModulationInfo() *gw.LoRaModulationInfo
	GetFskModulationInfo() *gw.FSKModulationInfo
	GetLrFhssModulationInfo() *gw.LRFHSSModulationInfo
}
func SetDownlinkTXInfoDataRate(txInfo *gw.DownlinkTXInfo, dr int, b band.Band) error {
	dataRate, err := b.GetDataRate(dr)
	if err != nil {
		return errors.Wrap(err, "get data-rate error")
	}
	switch dataRate.Modulation {
	case band.LoRaModulation:
		txInfo.Modulation = common.Modulation_LORA
		txInfo.ModulationInfo = &gw.DownlinkTXInfo_LoraModulationInfo{
			LoraModulationInfo: &gw.LoRaModulationInfo{
				SpreadingFactor:       uint32(dataRate.SpreadFactor),
				Bandwidth:             uint32(dataRate.Bandwidth),
				CodeRate:              defaultCodeRate,
				PolarizationInversion: true,
			},
		}
	case band.FSKModulation:
		txInfo.Modulation = common.Modulation_FSK
		txInfo.ModulationInfo = &gw.DownlinkTXInfo_FskModulationInfo{
			FskModulationInfo: &gw.FSKModulationInfo{
				Datarate:           uint32(dataRate.BitRate),
				FrequencyDeviation: uint32(dataRate.BitRate / 2),  
			},
		}
	default:
		return fmt.Errorf("unexpected modulation: %s", dataRate.Modulation)
	}
	return nil
}
func SetUplinkTXInfoDataRate(txInfo *gw.UplinkTXInfo, dr int, b band.Band) error {
	dataRate, err := b.GetDataRate(dr)
	if err != nil {
		return errors.Wrap(err, "get data-rate error")
	}
	switch dataRate.Modulation {
	case band.LoRaModulation:
		txInfo.Modulation = common.Modulation_LORA
		txInfo.ModulationInfo = &gw.UplinkTXInfo_LoraModulationInfo{
			LoraModulationInfo: &gw.LoRaModulationInfo{
				SpreadingFactor:       uint32(dataRate.SpreadFactor),
				Bandwidth:             uint32(dataRate.Bandwidth),
				CodeRate:              defaultCodeRate,
				PolarizationInversion: true,
			},
		}
	case band.FSKModulation:
		txInfo.Modulation = common.Modulation_FSK
		txInfo.ModulationInfo = &gw.UplinkTXInfo_FskModulationInfo{
			FskModulationInfo: &gw.FSKModulationInfo{
				Datarate: uint32(dataRate.BitRate),
			},
		}
	case band.LRFHSSModulation:
		txInfo.Modulation = common.Modulation_LR_FHSS
		txInfo.ModulationInfo = &gw.UplinkTXInfo_LrFhssModulationInfo{
			LrFhssModulationInfo: &gw.LRFHSSModulationInfo{
				OperatingChannelWidth: uint32(dataRate.OccupiedChannelWidth),
				CodeRate:              dataRate.CodingRate,
			},
		}
	default:
		return fmt.Errorf("unknown modulation: %s", dataRate.Modulation)
	}
	return nil
}
func GetGatewayID(v GatewayIDGetter) lorawan.EUI64 {
	var gatewayID lorawan.EUI64
	copy(gatewayID[:], v.GetGatewayId())
	return gatewayID
}
func GetUplinkID(v *gw.UplinkRXInfo) uuid.UUID {
	var msgID uuid.UUID
	if v != nil {
		copy(msgID[:], v.GetUplinkId())
	}
	return msgID
}