From cd7d9e5c3a20afc9723741d881abdf9a6db3cd0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Tr=C3=B6ger?= Date: Thu, 25 Jan 2024 07:52:05 +0100 Subject: [PATCH] no message --- ONVIF Digital Input/module.php | 62 +++++----- ONVIF Digital Output/module.php | 80 +++++++------ ONVIF Events/module.php | 40 +++---- ONVIF Image Grabber/module.php | 62 +++++----- ONVIF Media Stream/module.php | 195 ++++++++++++++++---------------- libs/ONVIFModuleBase.php | 2 +- 6 files changed, 213 insertions(+), 228 deletions(-) diff --git a/ONVIF Digital Input/module.php b/ONVIF Digital Input/module.php index 838392d..59706d8 100644 --- a/ONVIF Digital Input/module.php +++ b/ONVIF Digital Input/module.php @@ -14,39 +14,6 @@ public function Create(): void parent::Create(); $this->RegisterAttributeArray(\ONVIF\Input\Attribute::DigitalInputs, []); } - public function ApplyChanges(): void - { - //Never delete this line! - parent::ApplyChanges(); - if (IPS_GetKernelRunlevel() != KR_READY) { - return; - } - if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { - $this->SetStatus(IS_INACTIVE); - return; - } - if ($this->HasActiveParent()) { - $Capabilities = @$this->GetCapabilities(); - if (!$Capabilities) { - $this->SetStatus(IS_EBASE + 1); - return; - } - $this->WriteAttributeArray(\ONVIF\Input\Attribute::DigitalInputs, $Capabilities['DigitalInputs']); - foreach ($Capabilities['DigitalInputs'] as $Name => $DigitalInput) { - $Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name); - $Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident); - $this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0); - } - - $Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic)); - $this->SendDebug('EventConfig', $Events, 0); - if (count($Events) != 1) { - $this->SetStatus(IS_EBASE + 1); - } else { - $this->SetStatus(IS_ACTIVE); - } - } - } public function ReceiveData(string $JSONString): string { @@ -120,4 +87,33 @@ public function GetConfigurationForm(): string return json_encode($Form); } + protected function InitFilterAndEvents(): void + { + parent::InitFilterAndEvents(); + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { + $this->SetStatus(IS_INACTIVE); + return; + } + if ($this->HasActiveParent()) { + $Capabilities = @$this->GetCapabilities(); + if (!$Capabilities) { + $this->SetStatus(IS_EBASE + 1); + return; + } + $this->WriteAttributeArray(\ONVIF\Input\Attribute::DigitalInputs, $Capabilities['DigitalInputs']); + foreach ($Capabilities['DigitalInputs'] as $Name => $DigitalInput) { + $Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name); + $Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident); + $this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0); + } + + $Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic)); + $this->SendDebug('EventConfig', $Events, 0); + if (count($Events) != 1) { + $this->SetStatus(IS_EBASE + 1); + } else { + $this->SetStatus(IS_ACTIVE); + } + } + } } diff --git a/ONVIF Digital Output/module.php b/ONVIF Digital Output/module.php index 7dfa9fe..953a9f5 100644 --- a/ONVIF Digital Output/module.php +++ b/ONVIF Digital Output/module.php @@ -20,48 +20,6 @@ public function Create(): void $this->RegisterAttributeArray(\ONVIF\Output\Attribute::RelayOutputs, []); } - public function ApplyChanges(): void - { - //Never delete this line! - parent::ApplyChanges(); - if (IPS_GetKernelRunlevel() != KR_READY) { - return; - } - if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { - $this->SetStatus(IS_INACTIVE); - return; - } - if ($this->HasActiveParent()) { - $Capabilities = @$this->GetCapabilities(); - if (!$Capabilities) { - $this->SetStatus(IS_EBASE + 1); - return; - } - if ($Capabilities['XAddr'][\ONVIF\NS::DeviceIO]) { - $this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::DeviceIO]; - $this->wsdl = \ONVIF\WSDL::DeviceIO; - } else { - $this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::Management]; - $this->wsdl = \ONVIF\WSDL::Management; - } - $this->WriteAttributeArray(\ONVIF\Output\Attribute::RelayOutputs, $Capabilities['RelayOutputs']); - foreach ($Capabilities['RelayOutputs'] as $Name => $RelayOutput) { - $Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name); - $Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident); - $this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0); - $this->EnableAction($Ident); - } - $Events = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); - if (count($Events) != 1) { - $this->SetStatus(IS_EBASE + 1); - } else { - $this->SetStatus(IS_ACTIVE); - } - return; - } - $this->SetStatus(IS_ACTIVE); - } - public function SetRelayOutputState(string $Ident, bool $Value): bool { if (!array_key_exists($Ident, $this->ReadAttributeArray(\ONVIF\Output\Attribute::RelayOutputs))) { @@ -201,4 +159,42 @@ public function GetConfigurationForm(): string return json_encode($Form); } + + protected function InitFilterAndEvents(): void + { + parent::InitFilterAndEvents(); + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { + $this->SetStatus(IS_INACTIVE); + return; + } + if ($this->HasActiveParent()) { + $Capabilities = @$this->GetCapabilities(); + if (!$Capabilities) { + $this->SetStatus(IS_EBASE + 1); + return; + } + if ($Capabilities['XAddr'][\ONVIF\NS::DeviceIO]) { + $this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::DeviceIO]; + $this->wsdl = \ONVIF\WSDL::DeviceIO; + } else { + $this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::Management]; + $this->wsdl = \ONVIF\WSDL::Management; + } + $this->WriteAttributeArray(\ONVIF\Output\Attribute::RelayOutputs, $Capabilities['RelayOutputs']); + foreach ($Capabilities['RelayOutputs'] as $Name => $RelayOutput) { + $Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name); + $Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident); + $this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0); + $this->EnableAction($Ident); + } + $Events = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); + if (count($Events) != 1) { + $this->SetStatus(IS_EBASE + 1); + } else { + $this->SetStatus(IS_ACTIVE); + } + return; + } + $this->SetStatus(IS_ACTIVE); + } } diff --git a/ONVIF Events/module.php b/ONVIF Events/module.php index 59250a5..d9dbb54 100644 --- a/ONVIF Events/module.php +++ b/ONVIF Events/module.php @@ -7,29 +7,6 @@ class ONVIFEvents extends ONVIFModuleBase { public const wsdl = ''; - public function Create(): void - { - parent::Create(); - } - public function ApplyChanges(): void - { - //Never delete this line! - parent::ApplyChanges(); - if (IPS_GetKernelRunlevel() != KR_READY) { - return; - } - if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { - $this->SetStatus(IS_INACTIVE); - } else { - $Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic)); - $this->SendDebug('EventConfig', $Events, 0); - if (count($Events) == 0) { - $this->SetStatus(IS_INACTIVE); - } else { - $this->SetStatus(IS_ACTIVE); - } - } - } public function ReceiveData(string $JSONString): string { @@ -56,4 +33,21 @@ public function GetConfigurationForm(): string $this->SendDebug('FORM', json_last_error_msg(), 0); return json_encode($Form); } + + protected function InitFilterAndEvents(): void + { + parent::InitFilterAndEvents(); + + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { + $this->SetStatus(IS_INACTIVE); + } else { + $Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic)); + $this->SendDebug('EventConfig', $Events, 0); + if (count($Events) == 0) { + $this->SetStatus(IS_INACTIVE); + } else { + $this->SetStatus(IS_ACTIVE); + } + } + } } diff --git a/ONVIF Image Grabber/module.php b/ONVIF Image Grabber/module.php index 1706028..5b0d4c2 100644 --- a/ONVIF Image Grabber/module.php +++ b/ONVIF Image Grabber/module.php @@ -22,37 +22,6 @@ public function Create(): void $this->RegisterTimer(\ONVIF\ImageGrabber\Timer::UpdateImage, 0, 'ONVIF_UpdateImage(' . $this->InstanceID . ');'); $this->ImageURL = false; } - public function ApplyChanges(): void - { - //Never delete this line! - parent::ApplyChanges(); - $MediaId = $this->GetMediaId(); - IPS_SetMediaCached($MediaId, $this->ReadPropertyBoolean(\ONVIF\ImageGrabber\Property::UseCaching)); - - if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == '') { - $this->SetStatus(IS_INACTIVE); - $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); - return; - } - if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) == '') { - $this->SetStatus(IS_INACTIVE); - $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); - return; - } - if (IPS_GetKernelRunlevel() != KR_READY) { - return; - } - - $this->ImageURL = $SnapshotURL = $this->GetSnapshotUri(); - if ($SnapshotURL) { - $this->SetStatus(IS_ACTIVE); - $this->UpdateImage(); - $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, $this->ReadPropertyInteger(\ONVIF\ImageGrabber\Property::Interval) * 1000); - } else { - $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); - $this->SetStatus(IS_EBASE + 1); - } - } public function UpdateImage(): bool { $URL = $this->ImageURL; @@ -344,6 +313,37 @@ public function RequestAction(string $Ident, mixed $Value, bool &$done = false): return; } } + + protected function InitFilterAndEvents(): void + { + parent::InitFilterAndEvents(); + $MediaId = $this->GetMediaId(); + IPS_SetMediaCached($MediaId, $this->ReadPropertyBoolean(\ONVIF\ImageGrabber\Property::UseCaching)); + + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == '') { + $this->SetStatus(IS_INACTIVE); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); + return; + } + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) == '') { + $this->SetStatus(IS_INACTIVE); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); + return; + } + if (IPS_GetKernelRunlevel() != KR_READY) { + return; + } + + $this->ImageURL = $SnapshotURL = $this->GetSnapshotUri(); + if ($SnapshotURL) { + $this->SetStatus(IS_ACTIVE); + $this->UpdateImage(); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, $this->ReadPropertyInteger(\ONVIF\ImageGrabber\Property::Interval) * 1000); + } else { + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); + $this->SetStatus(IS_EBASE + 1); + } + } protected function IOChangeState(int $State): void { parent::IOChangeState($State); diff --git a/ONVIF Media Stream/module.php b/ONVIF Media Stream/module.php index 890b6c3..cc436ba 100644 --- a/ONVIF Media Stream/module.php +++ b/ONVIF Media Stream/module.php @@ -127,104 +127,6 @@ public function Destroy(): void parent::Destroy(); } - public function ApplyChanges(): void - { - //Never delete this line! - parent::ApplyChanges(); - - $this->PTZ_token = ''; - $this->PTZ_xAddr = ''; - $this->PTZ_Presets = []; - $this->PTZ_HasHome = false; - $this->PTZ_MaxPresets = 0; - $this->PresetTokenList = []; - $this->AuthorizationKey = ''; - - if ($this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource) == '') { - $this->SetStatus(IS_INACTIVE); - $this->SetMedia(''); - return; - } - if ($this->ReadPropertyString(\ONVIF\Stream\Property::Profile) == '') { - $this->SetStatus(IS_INACTIVE); - $this->SetMedia(''); - return; - } - if (IPS_GetKernelRunlevel() != KR_READY) { - return; - } - - $StreamURL = $this->GetStreamUri(); - if ($StreamURL) { - $this->SetMedia($StreamURL); - $this->SetStatus(IS_ACTIVE); - } else { - $this->SetMedia(''); - $this->SetStatus(IS_EBASE + 1); - } - - if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltHTML) || $this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableZoomHTML)) { - $this->RegisterHook('/hook/ONVIF/PTZ/' . $this->InstanceID); - $this->WritePTZInHTMLBox(); - } else { - $this->UnregisterHook('/hook/ONVIF/PTZ/' . $this->InstanceID); - $this->UnregisterVariable('PTZControlHtml'); - } - if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltVariable)) { - $this->RegisterVariableInteger('PT', $this->Translate('Move'), 'ONVIF.PanTilt', 3); - $this->SetValueInteger('PT', 2); - $this->EnableAction('PT'); - } else { - $this->UnregisterVariable('PT'); - } - if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableZoomVariable)) { - $this->RegisterVariableInteger('ZOOM', $this->Translate('Zoom'), 'ONVIF.Zoom', 4); - $this->SetValueInteger('ZOOM', 1); - $this->EnableAction('ZOOM'); - } else { - $this->UnregisterVariable('ZOOM'); - } - if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableSpeedVariable)) { - $this->RegisterVariableFloat('SPEED', $this->Translate('Speed'), 'ONVIF.Speed', 1); - $this->SetValueFloat('SPEED', 0); - $this->EnableAction('SPEED'); - } else { - $this->UnregisterVariable('SPEED'); - } - if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableTimeVariable)) { - $this->RegisterVariableFloat('TIME', $this->Translate('Time'), 'ONVIF.Time', 2); - $this->SetValueFloat('TIME', 0); - $this->EnableAction('TIME'); - } else { - $this->UnregisterVariable('TIME'); - } - $PresetProfileName = 'ONVIF.Preset.' . $this->InstanceID; - if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePresetVariable)) { - $UsePresetName = $this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePresetProfile); - $Presets = json_decode($this->ReadPropertyString(\ONVIF\Stream\Property::PresetProfile)); - $PresetTokenList = []; - $PresetAssociations = []; - foreach ($Presets as $Preset) { - $PresetTokenList[$Preset->VariableValue] = $Preset->PresetToken; - if ($Preset->PresetActive) { - $PresetAssociations[] = [ - $Preset->VariableValue, - $UsePresetName ? ($Preset->PresetName == '' ? $Preset->VariableValue : $Preset->PresetName) : $Preset->VariableValue, - '', - -1 - ]; - } - } - $this->PresetTokenList = $PresetTokenList; - $this->RegisterProfileIntegerEx($PresetProfileName, 'Move', '', '', $PresetAssociations); - $this->RegisterVariableInteger('PRESET', $this->Translate('Pre-position'), $PresetProfileName, 5); - $this->EnableAction('PRESET'); - } else { - $this->UnregisterVariable('PRESET'); - $this->UnregisterProfile($PresetProfileName); - } - } - public function GetConfigurationForm(): string { $Form = json_decode(file_get_contents(__DIR__ . '/form.json'), true); @@ -985,6 +887,103 @@ public function ReceiveData(string $JSONString): string return ''; } + protected function InitFilterAndEvents(): void + { + parent::InitFilterAndEvents(); + + $this->PTZ_token = ''; + $this->PTZ_xAddr = ''; + $this->PTZ_Presets = []; + $this->PTZ_HasHome = false; + $this->PTZ_MaxPresets = 0; + $this->PresetTokenList = []; + $this->AuthorizationKey = ''; + + if ($this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource) == '') { + $this->SetStatus(IS_INACTIVE); + $this->SetMedia(''); + return; + } + if ($this->ReadPropertyString(\ONVIF\Stream\Property::Profile) == '') { + $this->SetStatus(IS_INACTIVE); + $this->SetMedia(''); + return; + } + if (IPS_GetKernelRunlevel() != KR_READY) { + return; + } + + $StreamURL = $this->GetStreamUri(); + if ($StreamURL) { + $this->SetMedia($StreamURL); + $this->SetStatus(IS_ACTIVE); + } else { + $this->SetMedia(''); + $this->SetStatus(IS_EBASE + 1); + } + + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltHTML) || $this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableZoomHTML)) { + $this->RegisterHook('/hook/ONVIF/PTZ/' . $this->InstanceID); + $this->WritePTZInHTMLBox(); + } else { + $this->UnregisterHook('/hook/ONVIF/PTZ/' . $this->InstanceID); + $this->UnregisterVariable('PTZControlHtml'); + } + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltVariable)) { + $this->RegisterVariableInteger('PT', $this->Translate('Move'), 'ONVIF.PanTilt', 3); + $this->SetValueInteger('PT', 2); + $this->EnableAction('PT'); + } else { + $this->UnregisterVariable('PT'); + } + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableZoomVariable)) { + $this->RegisterVariableInteger('ZOOM', $this->Translate('Zoom'), 'ONVIF.Zoom', 4); + $this->SetValueInteger('ZOOM', 1); + $this->EnableAction('ZOOM'); + } else { + $this->UnregisterVariable('ZOOM'); + } + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableSpeedVariable)) { + $this->RegisterVariableFloat('SPEED', $this->Translate('Speed'), 'ONVIF.Speed', 1); + $this->SetValueFloat('SPEED', 0); + $this->EnableAction('SPEED'); + } else { + $this->UnregisterVariable('SPEED'); + } + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableTimeVariable)) { + $this->RegisterVariableFloat('TIME', $this->Translate('Time'), 'ONVIF.Time', 2); + $this->SetValueFloat('TIME', 0); + $this->EnableAction('TIME'); + } else { + $this->UnregisterVariable('TIME'); + } + $PresetProfileName = 'ONVIF.Preset.' . $this->InstanceID; + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePresetVariable)) { + $UsePresetName = $this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePresetProfile); + $Presets = json_decode($this->ReadPropertyString(\ONVIF\Stream\Property::PresetProfile)); + $PresetTokenList = []; + $PresetAssociations = []; + foreach ($Presets as $Preset) { + $PresetTokenList[$Preset->VariableValue] = $Preset->PresetToken; + if ($Preset->PresetActive) { + $PresetAssociations[] = [ + $Preset->VariableValue, + $UsePresetName ? ($Preset->PresetName == '' ? $Preset->VariableValue : $Preset->PresetName) : $Preset->VariableValue, + '', + -1 + ]; + } + } + $this->PresetTokenList = $PresetTokenList; + $this->RegisterProfileIntegerEx($PresetProfileName, 'Move', '', '', $PresetAssociations); + $this->RegisterVariableInteger('PRESET', $this->Translate('Pre-position'), $PresetProfileName, 5); + $this->EnableAction('PRESET'); + } else { + $this->UnregisterVariable('PRESET'); + $this->UnregisterProfile($PresetProfileName); + } + } + protected function IOChangeState(int $State): void { parent::IOChangeState($State); diff --git a/libs/ONVIFModuleBase.php b/libs/ONVIFModuleBase.php index 1bc61c1..6d3c508 100644 --- a/libs/ONVIFModuleBase.php +++ b/libs/ONVIFModuleBase.php @@ -95,7 +95,7 @@ public function MessageSink(int $TimeStamp, int $SenderID, int $Message, array $ break; } } - protected function InitFilterAndEvents() + protected function InitFilterAndEvents(): void { $EventTopic = $this->ReadPropertyString(\ONVIF\Device\Property::EventTopic); $SyncEvents = ($EventTopic != $this->EventTopic);