starting the foundation for multiple types of telemetry data
This commit is contained in:
@@ -12,17 +12,21 @@ without having to be playing the game while doing it (fans are noisy).
|
|||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
To start replaying:
|
To start replaying:
|
||||||
`BeamNGMockOg replay [--loop] -a 127.0.0.1 -p 4443 -i sunburstManual.bin`
|
`telemetrymockserver beamng replay [--loop] -a 127.0.0.1 -p 4443 -i sunburstManual.bin`
|
||||||
- `loop` allows the replay functionality to keep replaying the same data file
|
- `loop` allows the replay functionality to keep replaying the same data file
|
||||||
|
|
||||||
|
|
||||||
To start recording:
|
To start recording:
|
||||||
`BeamNGMockOg record -a 127.0.0.1 -p 4443 -o sunburstDCT.bin`
|
`BeamNGMockOg beamng record -a 127.0.0.1 -p 4443 -o sunburstDCT.bin`
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
Use `tcpdump` to listen to the socket and check if data is coming through:
|
Use `tcpdump` to listen to the socket and check if data is coming through:
|
||||||
`tcpdump -i any udp port <port> -X`
|
`tcpdump -i any udp port <port> -X`
|
||||||
|
|
||||||
|
### TODO:
|
||||||
|
- [ ] Create the auto completion file and add it to `$FPATH`
|
||||||
|
- [ ] Create a shortcut so we don't have to type out `telemetrymockserver` everytime
|
||||||
|
|
||||||
|
|
||||||
### Benchmark
|
### Benchmark
|
||||||
Run with:
|
Run with:
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
beamng "github.com/ESilva15/TelemetryMockserver/internal/mockservers/beamng"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// beamNGCmd is the parent command for the BeamNG agent actions
|
||||||
|
var beamNGCmd = &cobra.Command{
|
||||||
|
Use: "beamng",
|
||||||
|
Short: "record -o <path-to-bin-file>",
|
||||||
|
Long: "record will store the data from the given UDP server to the " +
|
||||||
|
"filepath given by -i",
|
||||||
|
Args: nil,
|
||||||
|
// Run: beamngAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
var beamNGRecordCMD = &cobra.Command{
|
||||||
|
Use: "record",
|
||||||
|
Short: "record -o <path-to-output-file>",
|
||||||
|
Long: `record will store the data from the given UDP server to the
|
||||||
|
filepath given by -o`,
|
||||||
|
Args: nil,
|
||||||
|
Run: recordAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
var beamNGReplayCMD = &cobra.Command{
|
||||||
|
Use: "replay",
|
||||||
|
Short: "replay -i <path-to-input-file>",
|
||||||
|
Long: "replay will replay the data on the given filepath on a UDP server",
|
||||||
|
Args: nil,
|
||||||
|
Run: replayAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
func recordAction(cmd *cobra.Command, args []string) {
|
||||||
|
outputFile, _ := cmd.Flags().GetString("output")
|
||||||
|
address, _ := cmd.Flags().GetString("address")
|
||||||
|
port, _ := cmd.Flags().GetInt("port")
|
||||||
|
|
||||||
|
recorder, err := beamng.NewRecorder(outputFile, address, port)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to create new BeamNG recorder: %+v", err))
|
||||||
|
}
|
||||||
|
defer recorder.Close()
|
||||||
|
|
||||||
|
// NOTE: is this doing anything at all??
|
||||||
|
ctx := context.Background()
|
||||||
|
if err := recorder.Record(ctx); err != nil {
|
||||||
|
fmt.Printf("Something went wrong while recording the file: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func replayAction(cmd *cobra.Command, args []string) {
|
||||||
|
inputFile, _ := cmd.Flags().GetString("input")
|
||||||
|
address, _ := cmd.Flags().GetString("address")
|
||||||
|
port, _ := cmd.Flags().GetInt("port")
|
||||||
|
loop, _ := cmd.Flags().GetBool("loop")
|
||||||
|
|
||||||
|
replayer, err := beamng.NewReplayer(address, port, inputFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Something went wrong setting up the player: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: is this doing anything at all??
|
||||||
|
ctx := context.Background()
|
||||||
|
if err := replayer.Replay(ctx, loop); err != nil {
|
||||||
|
fmt.Printf("Something went wrong while playing the file: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// Beamng commnad flags
|
||||||
|
beamNGCmd.PersistentFlags().StringP("address", "a", "127.0.0.1", "Address for the UDP server")
|
||||||
|
beamNGCmd.MarkFlagRequired("address")
|
||||||
|
beamNGCmd.PersistentFlags().IntP("port", "p", 4444, "Port for the UDP server")
|
||||||
|
beamNGCmd.MarkFlagRequired("port")
|
||||||
|
|
||||||
|
// Record command flags
|
||||||
|
beamNGRecordCMD.Flags().StringP("output", "o", "output.bin", "output file for recording")
|
||||||
|
beamNGRecordCMD.MarkFlagRequired("output")
|
||||||
|
|
||||||
|
// Replay command flags
|
||||||
|
beamNGReplayCMD.Flags().BoolP("loop", "l", false, "whether to loop the recording")
|
||||||
|
beamNGReplayCMD.Flags().StringP("input", "i", "input.bin", "input file for reading")
|
||||||
|
beamNGReplayCMD.MarkFlagRequired("input")
|
||||||
|
|
||||||
|
rootCmd.AddCommand(beamNGCmd)
|
||||||
|
beamNGCmd.AddCommand(beamNGRecordCMD, beamNGReplayCMD)
|
||||||
|
}
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/ESilva15/TelemetryMockserver/mockserver"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
func recordAction(cmd *cobra.Command, args []string) {
|
|
||||||
outputFile, _ := cmd.Flags().GetString("output")
|
|
||||||
address, _ := cmd.Flags().GetString("address")
|
|
||||||
port, _ := cmd.Flags().GetInt("port")
|
|
||||||
|
|
||||||
recorder, err := mockserver.NewRecorder(outputFile, address, port)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("failed to create new BeamNG recorder: %+v", err))
|
|
||||||
}
|
|
||||||
defer recorder.Close()
|
|
||||||
|
|
||||||
// NOTE: is this doing anything at all??
|
|
||||||
ctx := context.Background()
|
|
||||||
if err := recorder.Record(ctx); err != nil {
|
|
||||||
fmt.Printf("Something went wrong while recording the file: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// shelf
|
|
||||||
var recordCmd = &cobra.Command{
|
|
||||||
Use: "record",
|
|
||||||
Short: "record -o <path-to-bin-file>",
|
|
||||||
Long: `record will store the data from the given UDP server to the
|
|
||||||
filepath given by -i`,
|
|
||||||
Args: nil,
|
|
||||||
Run: recordAction,
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rootCmd.AddCommand(recordCmd)
|
|
||||||
|
|
||||||
recordCmd.PersistentFlags().StringP("output", "o", "output.bin", "output file for recording")
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/ESilva15/TelemetryMockserver/mockserver"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
func replayAction(cmd *cobra.Command, args []string) {
|
|
||||||
inputFile, _ := cmd.Flags().GetString("input")
|
|
||||||
address, _ := cmd.Flags().GetString("address")
|
|
||||||
port, _ := cmd.Flags().GetInt("port")
|
|
||||||
loop, _ := cmd.Flags().GetBool("loop")
|
|
||||||
|
|
||||||
replayer, err := mockserver.NewReplayer(address, port, inputFile)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Something went wrong setting up the player: %+v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: is this doing anything at all??
|
|
||||||
ctx := context.Background()
|
|
||||||
if err := replayer.Replay(ctx, loop); err != nil {
|
|
||||||
fmt.Printf("Something went wrong while playing the file: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// shelf
|
|
||||||
var replayCmd = &cobra.Command{
|
|
||||||
Use: "replay",
|
|
||||||
Short: "replay -i <path-to-bin-file>",
|
|
||||||
Long: `replay will replay the data on the given filepath on a UDP server`,
|
|
||||||
Args: nil,
|
|
||||||
Run: replayAction,
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rootCmd.AddCommand(replayCmd)
|
|
||||||
|
|
||||||
replayCmd.PersistentFlags().StringP("input", "i", "nofile.bin", "input file for serving")
|
|
||||||
replayCmd.PersistentFlags().BoolP("loop", "l", false, "loop replay after finishing")
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user