update emulator

This commit is contained in:
2026-02-19 11:43:40 +01:00
parent 27517bd2ea
commit 5e448a14e2
7 changed files with 109 additions and 22 deletions

View File

@@ -56,6 +56,17 @@ func (s *DeviceState) handleWriteCommand(cmd string) string {
return "ERRORE: I comandi 'W' sono accettati solo in modalità programmazione."
}
// Handle special WNC command
if strings.HasPrefix(cmd, "WNC=") {
valueStr := strings.TrimPrefix(cmd, "WNC=")
value, err := strconv.Atoi(valueStr)
if err != nil || (value != 0 && value != 1) {
return "ERRORE: Valore fuori range per WNC"
}
s.SetNCParam(value == 1)
return fmt.Sprintf("OK: Parametro WNC impostato e salvato: %d", value)
}
// Parse command format: "W<id>=<value>"
parts := strings.SplitN(cmd, "=", 2)
if len(parts) != 2 {
@@ -97,6 +108,15 @@ func (s *DeviceState) handleReadCommand(cmd string) string {
return "ERRORE: I comandi 'W' sono accettati solo in modalità programmazione."
}
// Handle special RNC command
if cmd == "RNC" {
value := 0
if s.GetNCParam() {
value = 1
}
return fmt.Sprintf("PARAM: WNC=%d", value)
}
// Extract parameter ID
idStr := strings.TrimPrefix(cmd, "R")
id, err := strconv.Atoi(idStr)

View File

@@ -19,6 +19,8 @@ type DeviceState struct {
// W4=40 (Time Window), W20=128 (Gain)
params map[int]int
ncParam bool // NC parameter: true = NO (1), false = NC (0), default is NO
sensorValue int // Default 2067 (ideal rest value)
jitterRange int // Default 10 (means ±10)
@@ -41,6 +43,7 @@ func NewDeviceState() *DeviceState {
12: 1000, // W12 - Max Pulse Duration (max)
20: 127, // W20 - Gain (middle of 0-255)
},
ncParam: true, // Default NO mode (1)
sensorValue: 2067,
jitterRange: 10,
connectedClients: 0,
@@ -129,6 +132,7 @@ func (s *DeviceState) ResetToDefaults() {
12: 1000,
20: 127,
}
s.ncParam = true // Default NO mode (1)
s.sensorValue = 2067
s.jitterRange = 10
}
@@ -176,6 +180,20 @@ func (s *DeviceState) GetAlarmState() (bool, string) {
return s.alarmActive, s.alarmType
}
// GetNCParam returns the NC parameter value (true = NO, false = NC)
func (s *DeviceState) GetNCParam() bool {
s.mu.RLock()
defer s.mu.RUnlock()
return s.ncParam
}
// SetNCParam sets the NC parameter value (true = NO, false = NC)
func (s *DeviceState) SetNCParam(value bool) {
s.mu.Lock()
defer s.mu.Unlock()
s.ncParam = value
}
// GetAllParams returns a copy of all parameters
func (s *DeviceState) GetAllParams() map[int]int {
s.mu.RLock()