rot finished
This commit is contained in:
35
internal/devices/command_id.go
Normal file
35
internal/devices/command_id.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package devices
|
||||
|
||||
import "sync"
|
||||
|
||||
// CommandIDManager manages the global command ID counter for 4O3A devices
|
||||
// All 4O3A devices share the same command ID sequence
|
||||
type CommandIDManager struct {
|
||||
mu sync.Mutex
|
||||
counter int
|
||||
}
|
||||
|
||||
var globalCommandID = &CommandIDManager{
|
||||
counter: 0,
|
||||
}
|
||||
|
||||
// GetNextID returns the next command ID and increments the counter
|
||||
func (m *CommandIDManager) GetNextID() int {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
m.counter++
|
||||
return m.counter
|
||||
}
|
||||
|
||||
// Reset resets the counter to 0 (useful for testing or restart)
|
||||
func (m *CommandIDManager) Reset() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.counter = 0
|
||||
}
|
||||
|
||||
// GetGlobalCommandID returns the global command ID manager
|
||||
func GetGlobalCommandID() *CommandIDManager {
|
||||
return globalCommandID
|
||||
}
|
||||
Reference in New Issue
Block a user