backend_linux.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //go:build linux
  2. package app
  3. import (
  4. "fmt"
  5. "time"
  6. "hth/internal/backend"
  7. "hth/internal/config"
  8. "hth/internal/profile"
  9. "hth/internal/thermalbackend"
  10. )
  11. func newSerialBackend(cfg *config.Config, p *profile.Profile) (backend.Backend, error) {
  12. inter := p.InterByteTimeout()
  13. if cfg.Serial.InterByteTimeoutMS > 0 {
  14. inter = time.Duration(cfg.Serial.InterByteTimeoutMS) * time.Millisecond
  15. }
  16. resp := p.GetResponseTimeout()
  17. if cfg.Serial.ResponseTimeoutMS > 0 {
  18. resp = time.Duration(cfg.Serial.ResponseTimeoutMS) * time.Millisecond
  19. }
  20. return backend.NewSerial(cfg.Serial.Path, inter, resp), nil
  21. }
  22. func newThermalBackend(cfg *config.Config) (thermalbackend.Backend, error) {
  23. switch cfg.Backend {
  24. case config.BackendMock:
  25. return thermalbackend.NewMock(cfg.Thermal.FirmwareProfile, cfg.Thermal.MockScenario), nil
  26. case config.BackendReplay:
  27. return thermalbackend.NewReplay(cfg.Replay.Path, cfg.Thermal.FirmwareProfile), nil
  28. case config.BackendSerial:
  29. return thermalbackend.NewSerial(cfg.Serial.Path, cfg.Thermal.FirmwareProfile, cfg.ThermalTimeout(), cfg.ThermalRetries()), nil
  30. default:
  31. return nil, fmt.Errorf("unknown thermal backend %s", cfg.Backend)
  32. }
  33. }