feat: build vehicle data platform and production pipeline
This commit is contained in:
@@ -14,6 +14,9 @@ const (
|
||||
ProtocolGB32960 Protocol = "gb32960"
|
||||
ProtocolJT808 Protocol = "jt808"
|
||||
ProtocolYutongMQTT Protocol = "yutong-mqtt"
|
||||
|
||||
DefaultJT808PhoneBase int64 = 139000000000
|
||||
maxJT808Phone int64 = 999999999999
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -25,17 +28,21 @@ type Config struct {
|
||||
Duration time.Duration
|
||||
Template string
|
||||
SendFrames bool
|
||||
JT808PhoneBase int64
|
||||
DrainResponses bool
|
||||
}
|
||||
|
||||
type FlagConfig struct {
|
||||
protocol string
|
||||
addr string
|
||||
connections int
|
||||
connectRate int
|
||||
sendInterval time.Duration
|
||||
duration time.Duration
|
||||
template string
|
||||
sendFrames bool
|
||||
protocol string
|
||||
addr string
|
||||
connections int
|
||||
connectRate int
|
||||
sendInterval time.Duration
|
||||
duration time.Duration
|
||||
template string
|
||||
sendFrames bool
|
||||
jt808PhoneBase int64
|
||||
drainResponses bool
|
||||
}
|
||||
|
||||
func RegisterFlags(fs *flag.FlagSet) *FlagConfig {
|
||||
@@ -48,6 +55,8 @@ func RegisterFlags(fs *flag.FlagSet) *FlagConfig {
|
||||
fs.DurationVar(&cfg.duration, "duration", 10*time.Minute, "load test duration")
|
||||
fs.StringVar(&cfg.template, "template", "", "frame template name")
|
||||
fs.BoolVar(&cfg.sendFrames, "send", true, "send protocol frames while connections are open")
|
||||
fs.Int64Var(&cfg.jt808PhoneBase, "jt808-phone-base", DefaultJT808PhoneBase, "first synthetic JT808 phone; one consecutive phone is assigned per connection")
|
||||
fs.BoolVar(&cfg.drainResponses, "drain-responses", true, "continuously read protocol responses while frames are being sent")
|
||||
return cfg
|
||||
}
|
||||
|
||||
@@ -73,6 +82,14 @@ func (c *FlagConfig) Build() (Config, error) {
|
||||
if c.duration <= 0 {
|
||||
return Config{}, errors.New("duration must be positive")
|
||||
}
|
||||
if protocol == ProtocolJT808 {
|
||||
if c.jt808PhoneBase <= 0 || c.jt808PhoneBase > maxJT808Phone {
|
||||
return Config{}, errors.New("jt808-phone-base must be a positive 12-digit-or-shorter number")
|
||||
}
|
||||
if int64(c.connections-1) > maxJT808Phone-c.jt808PhoneBase {
|
||||
return Config{}, errors.New("jt808 synthetic phone range exceeds 12 digits")
|
||||
}
|
||||
}
|
||||
return Config{
|
||||
Protocol: protocol,
|
||||
Addr: strings.TrimSpace(c.addr),
|
||||
@@ -82,5 +99,7 @@ func (c *FlagConfig) Build() (Config, error) {
|
||||
Duration: c.duration,
|
||||
Template: strings.TrimSpace(c.template),
|
||||
SendFrames: c.sendFrames,
|
||||
JT808PhoneBase: c.jt808PhoneBase,
|
||||
DrainResponses: c.drainResponses,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user