package device import ( "FRMS/internal/pkg/manager" "fmt" "sync" "time" "github.com/spf13/viper" ) // base device manager type Manager interface { // core manager Start() error Exit() error IsActive() int HeartBeat(chan struct{}, int, int, time.Duration) } func NewManager() Manager { // no timeouts needed return manager.New(0) } type DeviceManager struct { // for device agnostic fields/methods Address int `mapstructure:"address"` Bus int // i2c bus // mutable infoMu sync.RWMutex Name string `mapstructure:"name"` defaultName string // base manager Manager // config Config *viper.Viper // gRPC server pb.UnimplementedDeviceServer } func NewDeviceManager(bus, addr int, config *viper.Viper, defaultName string) *DeviceManager { // new base dm m := NewManager() dm := &DeviceManager{ Address: addr, Bus: bus, defaultName: defaultName, Manager: m, Config: config, } return dm } func (m *DeviceManager) LoadConfig() error { // setting default name mainKey := fmt.Sprintf("devices.%d", m.Address) nameKey := fmt.Sprintf("%s.name", mainKey) if !m.Config.IsSet(nameKey) { m.Config.Set(nameKey, m.defaultName) } return nil } func (m *DeviceManager) Start() error { // start return m.Manager.Start() }