//go:build linux package app import ( "fmt" "time" "hth/internal/backend" "hth/internal/config" "hth/internal/profile" "hth/internal/thermalbackend" ) func newSerialBackend(cfg *config.Config, p *profile.Profile) (backend.Backend, error) { inter := p.InterByteTimeout() if cfg.Serial.InterByteTimeoutMS > 0 { inter = time.Duration(cfg.Serial.InterByteTimeoutMS) * time.Millisecond } resp := p.GetResponseTimeout() if cfg.Serial.ResponseTimeoutMS > 0 { resp = time.Duration(cfg.Serial.ResponseTimeoutMS) * time.Millisecond } return backend.NewSerial(cfg.Serial.Path, inter, resp), nil } func newThermalBackend(cfg *config.Config) (thermalbackend.Backend, error) { switch cfg.Backend { case config.BackendMock: return thermalbackend.NewMock(cfg.Thermal.FirmwareProfile, cfg.Thermal.MockScenario), nil case config.BackendReplay: return thermalbackend.NewReplay(cfg.Replay.Path, cfg.Thermal.FirmwareProfile), nil case config.BackendSerial: return thermalbackend.NewSerial(cfg.Serial.Path, cfg.Thermal.FirmwareProfile, cfg.ThermalTimeout(), cfg.ThermalRetries()), nil default: return nil, fmt.Errorf("unknown thermal backend %s", cfg.Backend) } }