From 7ac13d8e4733329be20ae52d6a08c8614367ed69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Rudowicz?= Date: Wed, 6 Mar 2024 19:22:45 +0100 Subject: [PATCH] Poll for partition alarms --- commands.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ get_name.go | 6 +++--- satel.go | 21 +++++++++++-------- 3 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 commands.go diff --git a/commands.go b/commands.go new file mode 100644 index 0000000..1d2b470 --- /dev/null +++ b/commands.go @@ -0,0 +1,58 @@ +package satel + +const ( + SatelCommand_zonesViolation = 0x00 + SatelCommand_zonesTamper = 0x01 + SatelCommand_zonesAlarm = 0x02 + SatelCommand_zonesTamperAlarm = 0x03 + SatelCommand_zonesAlarmMemory = 0x04 + SatelCommand_zonesTamperAlarmMemory = 0x05 + SatelCommand_zonesBypass = 0x06 + SatelCommand_zonesNoViolationTrouble = 0x07 + SatelCommand_zonesLongViolationTrouble = 0x08 + SatelCommand_armedPartitionsSuppressed = 0x09 + SatelCommand_armedPartitionsReally = 0x0A + SatelCommand_partitionsArmedOnMode2 = 0x0B + SatelCommand_partitionsArmedOnMode3 = 0x0C + SatelCommand_partitionsWith1stCodeEntered = 0x0D + SatelCommand_partitionsEntryTime = 0x0E + SatelCommand_partitionsExitTimeMoreThan10s = 0x0F + SatelCommand_partitionsExitTimeLessThan10s = 0x10 + SatelCommand_partitionsTemporaryBlocked = 0x11 + SatelCommand_partitionsBlockedForGuardRound = 0x12 + SatelCommand_partitionsAlarm = 0x13 + SatelCommand_partitionsFireAlarm = 0x14 + SatelCommand_partitionsAlarmMemory = 0x15 + SatelCommand_partitionsFireAlarmMemory = 0x16 + SatelCommand_outputsState = 0x17 + SatelCommand_doorsOpened = 0x18 + SatelCommand_doorsOpenedLong = 0x19 + SatelCommand_RTCAndBasicStatusBits = 0x1A + SatelCommand_troublesPart1 = 0x1B + SatelCommand_troublesPart2 = 0x1C + SatelCommand_troublesPart3 = 0x1D + SatelCommand_troublesPart4 = 0x1E + SatelCommand_troublesPart5 = 0x1F + SatelCommand_troublesMemoryPart1 = 0x20 + SatelCommand_troublesMemoryPart2 = 0x21 + SatelCommand_troublesMemoryPart3 = 0x22 + SatelCommand_troublesMemoryPart4 = 0x23 + SatelCommand_troublesMemoryPart5 = 0x24 + SatelCommand_partitionsWithViolatedZones = 0x25 + SatelCommand_zonesIsolate = 0x26 + SatelCommand_partitionsWithVerifiedAlarms = 0x27 + SatelCommand_zonesMasked = 0x28 + SatelCommand_zonesMaskedMemory = 0x29 + SatelCommand_partitionsArmedOnMode1 = 0x2A + SatelCommand_partitionsWithWarningAlarms = 0x2B + SatelCommand_troublesPart6 = 0x2C + SatelCommand_troublesPart7 = 0x2D + SatelCommand_troublesMemoryPart6 = 0x2E + SatelCommand_troublesMemoryPart7 = 0x2F + SatelCommand_troublesPart8 = 0x30 + SatelCommand_troublesMemoryPart8 = 0x31 + + SatelCommand_ReadDeviceName = 0xEE + + Satel_Result = 0xEF +) diff --git a/get_name.go b/get_name.go index caccb50..67417f7 100644 --- a/get_name.go +++ b/get_name.go @@ -59,7 +59,7 @@ func (s *Satel) GetName(devType DeviceType, devIndex byte) (*NameEvent, error) { resultChan := make(chan getNameResult) s.commandQueue <- func() { - err := s.sendCmd(0xEE, byte(devType), devIndex) + err := s.sendCmd(SatelCommand_ReadDeviceName, byte(devType), devIndex) if err != nil { resultChan <- getNameResult{nil, errors.New("Could not send Satel read device name")} return @@ -72,9 +72,9 @@ func (s *Satel) GetName(devType DeviceType, devIndex byte) (*NameEvent, error) { } cmd := bytes[0] bytes = bytes[1 : len(bytes)-2] - if cmd == 0xEF { + if cmd == Satel_Result { resultChan <- getNameResult{nil, errors.New(fmt.Sprint("Received an error instead of a name: ", hex.Dump(bytes)))} - } else if cmd == 0xEE { + } else if cmd == SatelCommand_ReadDeviceName { name, err := makeNameEvent(bytes) resultChan <- getNameResult{name, err} } else { diff --git a/satel.go b/satel.go index 80794cc..5fc72c8 100644 --- a/satel.go +++ b/satel.go @@ -38,6 +38,16 @@ func New(conn net.Conn) *Satel { return NewConfig(conn, Config{}) } +func callCommandAndRetrieveResult(cmd byte, s *Satel) func() { + return func() { + err := s.sendCmd(cmd) + if err != nil { + return + } + s.readRawEvents() + } +} + func NewConfig(conn net.Conn, config Config) *Satel { s := &Satel{ conn: conn, @@ -59,13 +69,8 @@ func NewConfig(conn net.Conn, config Config) *Satel { } go func() { for { - s.commandQueue <- func() { - err = s.sendCmd(0x0A) - if err != nil { - return - } - s.readRawEvents() - } + s.commandQueue <- callCommandAndRetrieveResult(SatelCommand_armedPartitionsReally, s) + s.commandQueue <- callCommandAndRetrieveResult(SatelCommand_partitionsAlarm, s) time.Sleep(config.PoolingInterval) } }() @@ -127,7 +132,7 @@ func (s *Satel) readRawEvents() { var bytes = <-s.rawEvents cmd := bytes[0] bytes = bytes[1 : len(bytes)-2] - if cmd == 0xEF { + if cmd == Satel_Result { return } basicElements := make([]BasicEventElement, 0)