( cmd *cobra.Command, forUp func(*ttnpb.UplinkMessage) error, forDown func(*ttnpb.DownlinkMessage) error, )
| 71 | } |
| 72 | |
| 73 | func startSimulation( |
| 74 | cmd *cobra.Command, forUp func(*ttnpb.UplinkMessage) error, forDown func(*ttnpb.DownlinkMessage) error, |
| 75 | ) error { |
| 76 | gtwID, err := getGatewayID(cmd.Flags(), nil, true) |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | |
| 81 | var uplinkParams ttnpb.SimulateMetadataParams |
| 82 | if _, err := uplinkParams.SetFromFlags(simulateUplinkFlags, ""); err != nil { |
| 83 | return err |
| 84 | } |
| 85 | if err := simulate.SetDefaults(&uplinkParams); err != nil { |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | upMsg := &ttnpb.UplinkMessage{ |
| 90 | Settings: &ttnpb.TxSettings{ |
| 91 | DataRate: &ttnpb.DataRate{ |
| 92 | Modulation: &ttnpb.DataRate_Lora{ |
| 93 | Lora: &ttnpb.LoRaDataRate{ |
| 94 | Bandwidth: uplinkParams.Bandwidth, |
| 95 | SpreadingFactor: uplinkParams.SpreadingFactor, |
| 96 | CodingRate: band.Cr4_5, |
| 97 | }, |
| 98 | }, |
| 99 | }, |
| 100 | Frequency: uplinkParams.Frequency, |
| 101 | Timestamp: uplinkParams.Timestamp, |
| 102 | Time: uplinkParams.Time, |
| 103 | }, |
| 104 | RxMetadata: []*ttnpb.RxMetadata{ |
| 105 | { |
| 106 | GatewayIds: gtwID, |
| 107 | Time: uplinkParams.Time, |
| 108 | Timestamp: uplinkParams.Timestamp, |
| 109 | Rssi: uplinkParams.Rssi, |
| 110 | ChannelRssi: uplinkParams.Rssi, |
| 111 | Snr: uplinkParams.Snr, |
| 112 | }, |
| 113 | }, |
| 114 | } |
| 115 | |
| 116 | if err = forUp(upMsg); err != nil { |
| 117 | return err |
| 118 | } |
| 119 | |
| 120 | if dryRun, _ := cmd.Flags().GetBool("dry-run"); dryRun { |
| 121 | return io.Write(os.Stdout, config.OutputFormat, upMsg) |
| 122 | } |
| 123 | |
| 124 | gs, err := api.Dial(ctx, config.GatewayServerGRPCAddress) |
| 125 | if err != nil { |
| 126 | return err |
| 127 | } |
| 128 | timeout, _ := cmd.Flags().GetDuration("timeout") |
| 129 | linkCtx, cancel := context.WithTimeout(ctx, timeout) |
| 130 | defer cancel() |
no test coverage detected