Poll for partition alarms

main
Michał Rudowicz 2024-03-06 19:22:45 +01:00
rodzic 8979c2dd1e
commit 7ac13d8e47
3 zmienionych plików z 74 dodań i 11 usunięć

58
commands.go 100644
Wyświetl plik

@ -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
)

Wyświetl plik

@ -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 {

Wyświetl plik

@ -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)