From 0de60c5da21d3b289632cbe5e5e53b0d0a441462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Tr=C3=B6ger?= Date: Thu, 31 Aug 2023 15:32:29 +0200 Subject: [PATCH] no message --- .vscode | 2 +- ONVIF Configurator/module.php | 120 ++++--- ONVIF Digital Input/module.php | 16 +- ONVIF Digital Output/module.php | 22 +- ONVIF Discovery/module.php | 38 +-- ONVIF Events/module.php | 10 +- ONVIF IO/module.php | 543 ++++++++++++++++---------------- ONVIF Image Grabber/module.php | 48 +-- ONVIF Media Stream/module.php | 362 +++++++++++---------- README.md | 2 + libs/ONVIFModuleBase.php | 136 ++++---- libs/wsdl.php | 435 +++++++++++++++++-------- 12 files changed, 953 insertions(+), 781 deletions(-) diff --git a/.vscode b/.vscode index fd9b030..672a096 160000 --- a/.vscode +++ b/.vscode @@ -1 +1 @@ -Subproject commit fd9b030d28c11455de1b048cdf2fa1143d4f460d +Subproject commit 672a096abc8fcc6afa43f4aedd47821b5583b4c5 diff --git a/ONVIF Configurator/module.php b/ONVIF Configurator/module.php index 9716e6f..1cc4813 100644 --- a/ONVIF Configurator/module.php +++ b/ONVIF Configurator/module.php @@ -6,12 +6,7 @@ class ONVIFConfigurator extends ONVIFModuleBase { - const wsdl = \ONVIF\WSDL::Management; - const GUID_ONVIF_DIGITAL_INPUT = '{73097230-1ECC-FEEB-5969-C85148DFA76E}'; - const GUID_ONVIF_DIGITAL_OUTPUT = '{A44B3114-1F72-1FD1-96FB-D7E970BD8614}'; - const GUID_ONVIF_MEDIA_STREAM = '{FA889450-38B6-7E20-D4DC-F2C6D0B074FB}'; - const GUID_ONVIF_IMAGE_GRABBER = '{18EA97C1-3CEC-80B7-4CAA-D91F8A2A0599}'; - const GUID_ONVIF_EVENT = '{62584C2E-4542-4EBF-1E92-299F4CF364E4}'; + public const wsdl = \ONVIF\WSDL::Management; public function GetConfigurationForm() { @@ -48,12 +43,13 @@ public function GetConfigurationForm() $this->SendDebug('FORM', json_last_error_msg(), 0); return json_encode($Form); } - $this->SendDebug('VideoSources', $Capabilities['VideoSources'], 0); - $this->SendDebug('HasSnapshotUri', $Capabilities['HasSnapshotUri'], 0); - $this->SendDebug('VideoSourcesJPEG', $Capabilities['VideoSourcesJPEG'], 0); - $this->SendDebug('NbrOfInputs', $Capabilities['NbrOfInputs'], 0); - $this->SendDebug('NbrOfOutputs', $Capabilities['NbrOfOutputs'], 0); - $this->SendDebug('AnalyticsTokens', $Capabilities['AnalyticsTokens'], 0); + $this->SendDebug(\ONVIF\IO\Attribute::HasRTSPStreaming, $Capabilities[\ONVIF\IO\Attribute::HasRTSPStreaming], 0); + $this->SendDebug(\ONVIF\IO\Attribute::VideoSources, $Capabilities[\ONVIF\IO\Attribute::VideoSources], 0); + $this->SendDebug(\ONVIF\IO\Attribute::HasSnapshotUri, $Capabilities[\ONVIF\IO\Attribute::HasSnapshotUri], 0); + $this->SendDebug(\ONVIF\IO\Attribute::VideoSourcesJPEG, $Capabilities[\ONVIF\IO\Attribute::VideoSourcesJPEG], 0); + $this->SendDebug(\ONVIF\IO\Attribute::NbrOfInputs, $Capabilities[\ONVIF\IO\Attribute::NbrOfInputs], 0); + $this->SendDebug(\ONVIF\IO\Attribute::NbrOfOutputs, $Capabilities[\ONVIF\IO\Attribute::NbrOfOutputs], 0); + $this->SendDebug(\ONVIF\IO\Attribute::AnalyticsTokens, $Capabilities[\ONVIF\IO\Attribute::AnalyticsTokens], 0); //Events $OtherEvents = array_keys($this->GetEvents('', 0, [':VideoSource', ':PTZ', '/Relay', '/DigitalInput'])); @@ -70,7 +66,7 @@ public function GetConfigurationForm() } } $EventValues = []; - $IPSEventInstances = $this->GetInstanceList(self::GUID_ONVIF_EVENT, ['EventTopic']); + $IPSEventInstances = $this->GetInstanceList(\ONVIF\GUID::Event, ['EventTopic']); foreach ($Events as $Topic) { $Device = [ @@ -89,7 +85,7 @@ public function GetConfigurationForm() } $Device['create'] = [ - 'moduleID' => self::GUID_ONVIF_EVENT, + 'moduleID' => \ONVIF\GUID::Event, 'configuration' => [ 'EventTopic' => $Topic ], @@ -114,7 +110,7 @@ public function GetConfigurationForm() $InputTopics = []; foreach (array_keys($InputEvents) as $Topic) { $InputTopics[$Topic] = [ - 'moduleID' => self::GUID_ONVIF_DIGITAL_INPUT, + 'moduleID' => \ONVIF\GUID::Input, 'configuration' => [ 'EventTopic' => $Topic ], @@ -124,7 +120,7 @@ public function GetConfigurationForm() if (count($InputTopics) == 1) { $InputTopics = array_shift($InputTopics); } - $InputValues = $this->GetConfigurationArray(self::GUID_ONVIF_DIGITAL_INPUT, $Capabilities['NbrOfInputs'] > 0, $InputTopics); + $InputValues = $this->GetConfigurationArray(\ONVIF\GUID::Input, $Capabilities[\ONVIF\IO\Attribute::NbrOfInputs] > 0, $InputTopics); // Outputs $OutputEvents = $this->GetEvents('relay', 0); @@ -134,7 +130,7 @@ public function GetConfigurationForm() $OutputTopics = []; foreach (array_keys($OutputEvents) as $Topic) { $OutputTopics[$Topic] = [ - 'moduleID' => self::GUID_ONVIF_DIGITAL_OUTPUT, + 'moduleID' => \ONVIF\GUID::Output, 'configuration' => [ 'EventTopic' => $Topic ], @@ -144,60 +140,62 @@ public function GetConfigurationForm() if (count($OutputTopics) == 1) { $OutputTopics = array_shift($OutputTopics); } - $OutputValues = $this->GetConfigurationArray(self::GUID_ONVIF_DIGITAL_OUTPUT, $Capabilities['NbrOfOutputs'] > 0, $OutputTopics); + $OutputValues = $this->GetConfigurationArray(\ONVIF\GUID::Output, $Capabilities[\ONVIF\IO\Attribute::NbrOfOutputs] > 0, $OutputTopics); // Stream H264 $StreamCreateParams = [ - 'moduleID' => self::GUID_ONVIF_MEDIA_STREAM, + 'moduleID' => \ONVIF\GUID::Stream, 'configuration' => [], 'location' => [$this->Translate('ONVIF Devices'), IPS_GetName($this->InstanceID)] ]; $StreamValues = []; - $IPSStreamInstances = $this->GetInstanceList(self::GUID_ONVIF_MEDIA_STREAM, ['Profile', 'VideoSource']); - foreach ($Capabilities['VideoSources'] as $VideoSource) { - foreach ($VideoSource['Profile'] as $ProfileIndex => $Profile) { - $InstanceID = array_search($Profile['token'] . ':' . $VideoSource['VideoSourceToken'], $IPSStreamInstances); - if ($InstanceID !== false) { - unset($IPSStreamInstances[$InstanceID]); + $IPSStreamInstances = $this->GetInstanceList(\ONVIF\GUID::Stream, ['Profile', 'VideoSource']); + if ($Capabilities[\ONVIF\IO\Attribute::HasRTSPStreaming]) { + foreach ($Capabilities[\ONVIF\IO\Attribute::VideoSources] as $VideoSource) { + foreach ($VideoSource['Profile'] as $ProfileIndex => $Profile) { + $InstanceID = array_search($Profile['token'] . ':' . $VideoSource['VideoSourceToken'], $IPSStreamInstances); + if ($InstanceID !== false) { + unset($IPSStreamInstances[$InstanceID]); + $Device = [ + 'instanceID' => $InstanceID, + 'type' => 'Media Stream', + 'VideoSource' => $VideoSource['VideoSourceToken'], + 'name' => IPS_GetName($InstanceID), + 'Location' => stristr(IPS_GetLocation($InstanceID), IPS_GetName($InstanceID), true), + 'create' => $StreamCreateParams, + ]; + $Device['create']['configuration'] = [ + 'VideoSource' => $VideoSource['VideoSourceToken'], + 'Profile' => $Profile['token'] + ]; + unset($VideoSource['Profile'][$ProfileIndex]); + $StreamValues[] = $Device; + } + } + if (count($VideoSource['Profile'])) { // weitere Profile vorhanden, dann nächste Instanz anbieten $Device = [ - 'instanceID' => $InstanceID, + 'instanceID' => 0, 'type' => 'Media Stream', 'VideoSource' => $VideoSource['VideoSourceToken'], - 'name' => IPS_GetName($InstanceID), - 'Location' => stristr(IPS_GetLocation($InstanceID), IPS_GetName($InstanceID), true), - 'create' => $StreamCreateParams, - ]; - $Device['create']['configuration'] = [ - 'VideoSource' => $VideoSource['VideoSourceToken'], - 'Profile' => $Profile['token'] + 'name' => $VideoSource['VideoSourceName'], + 'Location' => '' ]; - unset($VideoSource['Profile'][$ProfileIndex]); + $Create = []; + foreach ($VideoSource['Profile'] as $ProfileIndex => $Profile) { + $Create[$VideoSource['VideoSourceName'] . ' (' . $Profile['Name'] . ')'] = $StreamCreateParams; + $Create[$VideoSource['VideoSourceName'] . ' (' . $Profile['Name'] . ')']['configuration'] = [ + 'VideoSource' => $VideoSource['VideoSourceToken'], + 'Profile' => $Profile['token'] + ]; + } + if (count($Create) == 1) { + $Device['name'] = $VideoSource['VideoSourceName'] . ' (' . $Profile['Name'] . ')'; + $Create = array_shift($Create); + } + $Device['create'] = $Create; $StreamValues[] = $Device; } } - if (count($VideoSource['Profile'])) { // weitere Profile vorhanden, dann nächste Instanz anbieten - $Device = [ - 'instanceID' => 0, - 'type' => 'Media Stream', - 'VideoSource' => $VideoSource['VideoSourceToken'], - 'name' => $VideoSource['VideoSourceName'], - 'Location' => '' - ]; - $Create = []; - foreach ($VideoSource['Profile'] as $ProfileIndex => $Profile) { - $Create[$VideoSource['VideoSourceName'] . ' (' . $Profile['Name'] . ')'] = $StreamCreateParams; - $Create[$VideoSource['VideoSourceName'] . ' (' . $Profile['Name'] . ')']['configuration'] = [ - 'VideoSource' => $VideoSource['VideoSourceToken'], - 'Profile' => $Profile['token'] - ]; - } - if (count($Create) == 1) { - $Device['name'] = $VideoSource['VideoSourceName'] . ' (' . $Profile['Name'] . ')'; - $Create = array_shift($Create); - } - $Device['create'] = $Create; - $StreamValues[] = $Device; - } } foreach ($IPSStreamInstances as $InstanceID => $VideoSource) { $Device = [ @@ -211,14 +209,14 @@ public function GetConfigurationForm() } // Stream JPEG $StreamJPEGCreateParams = [ - 'moduleID' => self::GUID_ONVIF_IMAGE_GRABBER, + 'moduleID' => \ONVIF\GUID::ImageGrabber, 'configuration' => [], 'location' => [$this->Translate('ONVIF Devices'), IPS_GetName($this->InstanceID)] ]; $StreamJPEGValues = []; - $IPSStreamJPEGInstances = $this->GetInstanceList(self::GUID_ONVIF_IMAGE_GRABBER, ['Profile', 'VideoSource']); - if ($Capabilities['HasSnapshotUri']) { - foreach ($Capabilities['VideoSourcesJPEG'] as $VideoSourceJPEG) { + $IPSStreamJPEGInstances = $this->GetInstanceList(\ONVIF\GUID::ImageGrabber, ['Profile', 'VideoSource']); + if ($Capabilities[\ONVIF\IO\Attribute::HasSnapshotUri]) { + foreach ($Capabilities[\ONVIF\IO\Attribute::VideoSourcesJPEG] as $VideoSourceJPEG) { foreach ($VideoSourceJPEG['Profile'] as $ProfileIndex =>$Profile) { $InstanceID = array_search($Profile['token'] . ':' . $VideoSourceJPEG['VideoSourceToken'], $IPSStreamJPEGInstances); if ($InstanceID !== false) { diff --git a/ONVIF Digital Input/module.php b/ONVIF Digital Input/module.php index 9a6ca6b..c7e5866 100644 --- a/ONVIF Digital Input/module.php +++ b/ONVIF Digital Input/module.php @@ -6,13 +6,13 @@ class ONVIFDigitalInput extends ONVIFModuleBase { - const wsdl = \ONVIF\WSDL::Management; - const TopicFilter = 'input'; + public const wsdl = \ONVIF\WSDL::Management; + public const TopicFilter = 'input'; public function Create() { //Never delete this line! parent::Create(); - $this->RegisterAttributeArray('DigitalInputs', []); + $this->RegisterAttributeArray(\ONVIF\Input\Attribute::DigitalInputs, []); } public function ApplyChanges() { @@ -21,7 +21,7 @@ public function ApplyChanges() if (IPS_GetKernelRunlevel() != KR_READY) { return; } - if ($this->ReadPropertyString('EventTopic') == '') { + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { $this->SetStatus(IS_INACTIVE); return; } @@ -31,14 +31,14 @@ public function ApplyChanges() $this->SetStatus(IS_EBASE + 1); return; } - $this->WriteAttributeArray('DigitalInputs', $Capabilities['DigitalInputs']); + $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('EventTopic')); + $Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic)); $this->SendDebug('EventConfig', $Events, 0); if (count($Events) != 1) { $this->SetStatus(IS_EBASE + 1); @@ -53,7 +53,7 @@ public function ReceiveData($JSONString) $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $EventProperties = $this->ReadAttributeArray('EventProperties'); + $EventProperties = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (!array_key_exists($Data['Topic'], $EventProperties)) { return false; } @@ -87,7 +87,7 @@ public function GetConfigurationForm() } $Form['elements'][0] = $this->GetConfigurationFormEventTopic($Form['elements'][0]); $Actions = [['type' => 'TestCenter']]; - $DigitalInputs = $this->ReadAttributeArray('DigitalInputs'); + $DigitalInputs = $this->ReadAttributeArray(\ONVIF\Input\Attribute::DigitalInputs); foreach ($DigitalInputs as $Token => $DigitalInput) { $Expansion = [ 'type' => 'ExpansionPanel', diff --git a/ONVIF Digital Output/module.php b/ONVIF Digital Output/module.php index b78313d..3093c72 100644 --- a/ONVIF Digital Output/module.php +++ b/ONVIF Digital Output/module.php @@ -9,15 +9,15 @@ */ class ONVIFDigitalOutput extends ONVIFModuleBase { - const wsdl = \ONVIF\WSDL::Management; // default, wenn DeviceIO nicht genutzt - const TopicFilter = 'relay'; + public const wsdl = \ONVIF\WSDL::Management; // default, wenn DeviceIO nicht genutzt + public const TopicFilter = 'relay'; public function Create() { //Never delete this line! parent::Create(); - $this->RegisterAttributeArray('RelayOutputs', []); - $this->RegisterPropertyBoolean('EmulateStatus', false); + $this->RegisterPropertyBoolean(\ONVIF\Output\Property::EmulateStatus, false); + $this->RegisterAttributeArray(\ONVIF\Output\Attribute::RelayOutputs, []); } public function ApplyChanges() @@ -27,7 +27,7 @@ public function ApplyChanges() if (IPS_GetKernelRunlevel() != KR_READY) { return; } - if ($this->ReadPropertyString('EventTopic') == '') { + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { $this->SetStatus(IS_INACTIVE); return; } @@ -44,14 +44,14 @@ public function ApplyChanges() $this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::Management]; $this->wsdl = \ONVIF\WSDL::Management; } - $this->WriteAttributeArray('RelayOutputs', $Capabilities['RelayOutputs']); + $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('EventProperties'); + $Events = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (count($Events) != 1) { $this->SetStatus(IS_EBASE + 1); } else { @@ -64,7 +64,7 @@ public function ApplyChanges() public function SetRelayOutputState(string $Ident, bool $Value) { - if (!array_key_exists($Ident, $this->ReadAttributeArray('RelayOutputs'))) { + if (!array_key_exists($Ident, $this->ReadAttributeArray(\ONVIF\Output\Attribute::RelayOutputs))) { set_error_handler([$this, 'ModulErrorHandler']); trigger_error($this->Translate('Invalid Ident'), E_USER_NOTICE); restore_error_handler(); @@ -79,7 +79,7 @@ public function SetRelayOutputState(string $Ident, bool $Value) if ($Result == false) { return false; } - if ($this->ReadPropertyBoolean('EmulateStatus')) { + if ($this->ReadPropertyBoolean(\ONVIF\Output\Property::EmulateStatus)) { $this->SetValueBoolean($Ident, $Value); } return true; @@ -98,7 +98,7 @@ public function ReceiveData($JSONString) $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $Events = $this->ReadAttributeArray('EventProperties'); + $Events = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); $EventProperty = array_pop($Events); $SourceIndex = array_search('tt:ReferenceToken', array_column($EventProperty['Sources'], 'Type')); if ($SourceIndex === false) { @@ -132,7 +132,7 @@ public function GetConfigurationForm() } $Form['elements'][0] = $this->GetConfigurationFormEventTopic($Form['elements'][0]); $Actions = [['type' => 'TestCenter']]; - $RelayOutputs = $this->ReadAttributeArray('RelayOutputs'); + $RelayOutputs = $this->ReadAttributeArray(\ONVIF\Output\Attribute::RelayOutputs); foreach ($RelayOutputs as $Token => $RelayOutput) { $Expansion = [ 'type' => 'ExpansionPanel', diff --git a/ONVIF Discovery/module.php b/ONVIF Discovery/module.php index 3f3ed34..d76154b 100644 --- a/ONVIF Discovery/module.php +++ b/ONVIF Discovery/module.php @@ -24,29 +24,29 @@ class ONVIFDiscovery extends IPSModule use \ONVIFDiscovery\BufferHelper; use \ONVIFDiscovery\DebugHelper; use \ONVIFDiscovery\Semaphore; - const WS_DISCOVERY_MESSAGE = 'uuid:[UUID]urn:schemas-xmlsoap-org:ws:2005:04:discoveryhttp://schemas.xmlsoap.org/ws/2005/04/discovery/Probedn:NetworkVideoTransmitter'; + public const WS_DISCOVERY_MESSAGE = 'uuid:[UUID]urn:schemas-xmlsoap-org:ws:2005:04:discoveryhttp://schemas.xmlsoap.org/ws/2005/04/discovery/Probedn:NetworkVideoTransmitter'; /** * The maximum number of seconds that will be allowed for the discovery request. */ - const WS_DISCOVERY_TIMEOUT = 3; + public const WS_DISCOVERY_TIMEOUT = 3; /** * The multicast address to use in the socket for the discovery request. */ - const WS_DISCOVERY_MULTICAST_ADDRESS = '239.255.255.250'; - const WS_DISCOVERY_MULTICAST_ADDRESSV6 = '[ff02::c]'; + public const WS_DISCOVERY_MULTICAST_ADDRESS = '239.255.255.250'; + public const WS_DISCOVERY_MULTICAST_ADDRESSV6 = '[ff02::c]'; /** * The port that will be used in the socket for the discovery request. */ - const WS_DISCOVERY_MULTICAST_PORT = 3702; + public const WS_DISCOVERY_MULTICAST_PORT = 3702; public function Create() { //Never delete this line! parent::Create(); - $this->RegisterAttributeString('Username', ''); - $this->RegisterAttributeString('Password', ''); + $this->RegisterAttributeString(\ONVIF\Discovery\Attribute::Username, ''); + $this->RegisterAttributeString(\ONVIF\Discovery\Attribute::Password, ''); $this->Devices = []; $this->DevicesError = []; $this->DevicesTotal = 0; @@ -87,8 +87,8 @@ public function GetConfigurationForm() return json_encode($Form); } - $Form['actions'][0]['items'][0]['items'][0]['value'] = $this->ReadAttributeString('Username'); - $Form['actions'][0]['items'][0]['items'][1]['value'] = $this->ReadAttributeString('Password'); + $Form['actions'][0]['items'][0]['items'][0]['value'] = $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username); + $Form['actions'][0]['items'][0]['items'][1]['value'] = $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password); if (!$this->DiscoveryIsRunning) { $ScriptText = 'IPS_RequestAction(' . $this->InstanceID . ', \'StartDiscover\',true);'; IPS_RunScriptText($ScriptText); @@ -103,8 +103,8 @@ public function RequestAction($Ident, $Value) if ($Ident == 'Save') { $this->DiscoveryIsRunning = false; $Data = explode(':', $Value); - $this->WriteAttributeString('Username', urldecode($Data[0])); - $this->WriteAttributeString('Password', urldecode($Data[1])); + $this->WriteAttributeString(\ONVIF\Discovery\Attribute::Username, urldecode($Data[0])); + $this->WriteAttributeString(\ONVIF\Discovery\Attribute::Password, urldecode($Data[1])); $this->EnableErrorPopup = true; $this->UpdateFormField('NotFoundPopup', 'visible', false); $this->UpdateFormField('ProgressPopup', 'visible', true); @@ -126,7 +126,7 @@ public function RequestAction($Ident, $Value) } protected function GetConfigurationValues() { - $InstanceIDListConfigurator = IPS_GetInstanceListByModuleID('{C6A79C49-19D5-8D45-FFE5-5D77165FAEE6}'); + $InstanceIDListConfigurator = IPS_GetInstanceListByModuleID(\ONVIF\GUID::Configurator); $DevicesAddress = []; $DeviceValues = []; foreach ($InstanceIDListConfigurator as $InstanceIDConfigurator) { @@ -160,16 +160,16 @@ protected function GetConfigurationValues() $AddDevice['instanceID'] = $InstanceIDConfigurator; unset($DevicesAddress[$InstanceIDConfigurator]); } else { - $ConfigIo['Username'] = $this->ReadAttributeString('Username'); - $ConfigIo['Password'] = $this->ReadAttributeString('Password'); + $ConfigIo['Username'] = $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username); + $ConfigIo['Password'] = $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password); } $AddDevice['create'][$Device['Name'] . ' (' . $Address . ')'] = [ [ - 'moduleID' => '{C6A79C49-19D5-8D45-FFE5-5D77165FAEE6}', + 'moduleID' => \ONVIF\GUID::Configurator, 'configuration' => new stdClass() ], [ - 'moduleID' => '{F40CA9A7-3B4D-4B26-7214-3A94B6074DFB}', + 'moduleID' => \ONVIF\GUID::IO, 'name' => $Device['Name'], 'configuration' => $ConfigIo ] @@ -324,7 +324,7 @@ protected function DiscoverDevices() protected function ScanDevice(string $IP, array $IpValues) { $UseLogin = false; - if (($this->ReadAttributeString('Username') != '') || ($this->ReadAttributeString('Password') != '')) { + if (($this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username) != '') || ($this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password) != '')) { $UseLogin = true; } $wsdl = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'WSDL' . DIRECTORY_SEPARATOR . \ONVIF\WSDL::Management; @@ -336,8 +336,8 @@ protected function ScanDevice(string $IP, array $IpValues) $this->SendDebug('Request', $IpValue, 0); if ($UseLogin) { $offset = $this->GetTimeOffset($IpValue); - $Header[] = \ONVIF\ONVIF::soapClientWSSecurityHeader($this->ReadAttributeString('Username'), $this->ReadAttributeString('Password'), $offset); - $ONVIFClient = new \ONVIF\ONVIF($wsdl, $IpValue . '/onvif/device_service', $this->ReadAttributeString('Username'), $this->ReadAttributeString('Password'), $Header); + $Header[] = \ONVIF\ONVIF::soapClientWSSecurityHeader($this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username), $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password), $offset); + $ONVIFClient = new \ONVIF\ONVIF($wsdl, $IpValue . '/onvif/device_service', $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username), $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password), $Header); } else { $ONVIFClient = new \ONVIF\ONVIF($wsdl, $IpValue . '/onvif/device_service'); } diff --git a/ONVIF Events/module.php b/ONVIF Events/module.php index 9b463f4..7a3da4a 100644 --- a/ONVIF Events/module.php +++ b/ONVIF Events/module.php @@ -6,7 +6,7 @@ class ONVIFEvents extends ONVIFModuleBase { - const wsdl = ''; + public const wsdl = ''; public function Create() { parent::Create(); @@ -18,10 +18,10 @@ public function ApplyChanges() if (IPS_GetKernelRunlevel() != KR_READY) { return; } - if ($this->ReadPropertyString('EventTopic') == '') { + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { $this->SetStatus(IS_INACTIVE); } else { - $Events = $this->GetEvents($this->ReadPropertyString('EventTopic')); + $Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic)); $this->SendDebug('EventConfig', $Events, 0); if (count($Events) == 0) { $this->SetStatus(IS_INACTIVE); @@ -36,11 +36,11 @@ public function ReceiveData($JSONString) $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $EventProperties = $this->ReadAttributeArray('EventProperties'); + $EventProperties = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (!array_key_exists($Data['Topic'], $EventProperties)) { return false; } - $PreName = str_replace($this->ReadPropertyString('EventTopic'), '', $Data['Topic']); + $PreName = str_replace($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic), '', $Data['Topic']); return $this->SetEventStatusVariable($PreName, $EventProperties[$Data['Topic']], $Data); } diff --git a/ONVIF IO/module.php b/ONVIF IO/module.php index f60525b..b09d9aa 100644 --- a/ONVIF IO/module.php +++ b/ONVIF IO/module.php @@ -43,44 +43,44 @@ public function Create() { //Never delete this line! parent::Create(); - $this->RegisterPropertyBoolean('Open', false); - $this->RegisterPropertyString('Address', ''); - $this->RegisterPropertyString('Username', ''); - $this->RegisterPropertyString('Password', ''); - $this->RegisterPropertyInteger('EventHandler', \ONVIF\EventHandler::Automatic); - $this->RegisterPropertyString('WebHookIP', ''); - $this->RegisterPropertyBoolean('WebHookHTTPS', false); - $this->RegisterPropertyInteger('WebHookPort', 3777); - $this->RegisterPropertyInteger('SubscribeEventTimeout', 10); - $this->RegisterPropertyInteger('SubscribeInitialTerminationTime', 1); - $this->RegisterPropertyInteger('PullPointInitialTerminationTime', 1); - $this->RegisterPropertyInteger('PullPointTimeout', 10); - $this->RegisterPropertyInteger('MessageLimit', 32); - $this->RegisterAttributeArray('VideoSources', []); - $this->RegisterAttributeArray('AudioSources', []); - $this->RegisterAttributeArray('VideoSourcesJPEG', []); - $this->RegisterAttributeArray('AnalyticsTokens', []); - $this->RegisterAttributeArray('RelayOutputs', []); - $this->RegisterAttributeArray('DigitalInputs', []); - $this->RegisterAttributeInteger('Timestamp_Offset', 0); - $this->RegisterAttributeArray('XAddr', []); - $this->RegisterAttributeArray('EventProperties', []); - $this->RegisterAttributeInteger('NbrOfInputs', 0); - $this->RegisterAttributeInteger('NbrOfOutputs', 0); - $this->RegisterAttributeInteger('NbrOfVideoSources', 0); - $this->RegisterAttributeInteger('NbrOfAudioSources', 0); - $this->RegisterAttributeInteger('NbrOfSerialPorts', 0); - $this->RegisterAttributeBoolean('HasSnapshotUri', false); - $this->RegisterAttributeBoolean('HasRTSPStreaming', false); - $this->RegisterAttributeBoolean('RuleSupport', false); - $this->RegisterAttributeBoolean('AnalyticsModuleSupport', false); - $this->RegisterAttributeBoolean('WSSubscriptionPolicySupport', false); - $this->RegisterAttributeBoolean('WSPullPointSupport', false); - $this->RegisterAttributeString('ConsumerAddress', ''); - $this->RegisterAttributeString('SubscriptionReference', ''); - $this->RegisterAttributeString('SubscriptionId', ''); - $this->RegisterAttributeInteger('CapabilitiesVersion', 0); - $this->RegisterTimer('RenewSubscription', 0, 'IPS_RequestAction(' . $this->InstanceID . ',"Renew",true);'); + $this->RegisterPropertyBoolean(\ONVIF\IO\Property::Active, false); + $this->RegisterPropertyString(\ONVIF\IO\Property::Address, ''); + $this->RegisterPropertyString(\ONVIF\IO\Property::Username, ''); + $this->RegisterPropertyString(\ONVIF\IO\Property::Password, ''); + $this->RegisterPropertyInteger(\ONVIF\IO\Property::EventHandler, \ONVIF\EventHandler::Automatic); + $this->RegisterPropertyString(\ONVIF\IO\Property::WebHookIP, ''); + $this->RegisterPropertyBoolean(\ONVIF\IO\Property::WebHookHTTPS, false); + $this->RegisterPropertyInteger(\ONVIF\IO\Property::WebHookPort, 3777); + $this->RegisterPropertyInteger(\ONVIF\IO\Property::SubscribeEventTimeout, 10); + $this->RegisterPropertyInteger(\ONVIF\IO\Property::SubscribeInitialTerminationTime, 1); + $this->RegisterPropertyInteger(\ONVIF\IO\Property::PullPointInitialTerminationTime, 1); + $this->RegisterPropertyInteger(\ONVIF\IO\Property::PullPointTimeout, 10); + $this->RegisterPropertyInteger(\ONVIF\IO\Property::MessageLimit, 32); + $this->RegisterAttributeArray(\ONVIF\IO\Attribute::VideoSources, []); + $this->RegisterAttributeArray(\ONVIF\IO\Attribute::AudioSources, []); + $this->RegisterAttributeArray(\ONVIF\IO\Attribute::VideoSourcesJPEG, []); + $this->RegisterAttributeArray(\ONVIF\IO\Attribute::AnalyticsTokens, []); + $this->RegisterAttributeArray(\ONVIF\IO\Attribute::RelayOutputs, []); + $this->RegisterAttributeArray(\ONVIF\IO\Attribute::DigitalInputs, []); + $this->RegisterAttributeInteger(\ONVIF\IO\Attribute::Timestamp_Offset, 0); + $this->RegisterAttributeArray(\ONVIF\IO\Attribute::XAddr, []); + $this->RegisterAttributeArray(\ONVIF\IO\Attribute::EventProperties, []); + $this->RegisterAttributeInteger(\ONVIF\IO\Attribute::NbrOfInputs, 0); + $this->RegisterAttributeInteger(\ONVIF\IO\Attribute::NbrOfOutputs, 0); + $this->RegisterAttributeInteger(\ONVIF\IO\Attribute::NbrOfVideoSources, 0); + $this->RegisterAttributeInteger(\ONVIF\IO\Attribute::NbrOfAudioSources, 0); + $this->RegisterAttributeInteger(\ONVIF\IO\Attribute::NbrOfSerialPorts, 0); + $this->RegisterAttributeBoolean(\ONVIF\IO\Attribute::HasSnapshotUri, false); + $this->RegisterAttributeBoolean(\ONVIF\IO\Attribute::HasRTSPStreaming, false); + $this->RegisterAttributeBoolean(\ONVIF\IO\Attribute::RuleSupport, false); + $this->RegisterAttributeBoolean(\ONVIF\IO\Attribute::AnalyticsModuleSupport, false); + $this->RegisterAttributeBoolean(\ONVIF\IO\Attribute::WSSubscriptionPolicySupport, false); + $this->RegisterAttributeBoolean(\ONVIF\IO\Attribute::WSPullPointSupport, false); + $this->RegisterAttributeString(\ONVIF\IO\Attribute::ConsumerAddress, ''); + $this->RegisterAttributeString(\ONVIF\IO\Attribute::SubscriptionReference, ''); + $this->RegisterAttributeString(\ONVIF\IO\Attribute::SubscriptionId, ''); + $this->RegisterAttributeInteger(\ONVIF\IO\Attribute::CapabilitiesVersion, 0); + $this->RegisterTimer(\ONVIF\IO\Timer::RenewSubscription, 0, 'IPS_RequestAction(' . $this->InstanceID . ',"Renew",true);'); $this->Host = ''; $this->MyIP = ''; $this->MyPort = 3777; @@ -113,20 +113,20 @@ public function MessageSink($TimeStamp, $SenderID, $Message, $Data) { switch ($Message) { case IPS_KERNELSTARTED: - $this->UnregisterMessage(0, IPS_KERNELSTARTED); - IPS_RequestAction($this->InstanceID, 'KernelReady', true); + $this->UnregisterMessage(0, IPS_KERNELSTARTED); + IPS_RequestAction($this->InstanceID, 'KernelReady', true); break; case FM_CHILDREMOVED: - $this->lock('EventProperties'); - $Events = $this->ReadAttributeArray('EventProperties'); + $this->lock(\ONVIF\IO\Attribute::EventProperties); + $Events = $this->ReadAttributeArray(\ONVIF\IO\Attribute::EventProperties); foreach ($Events as &$Event) { $Index = array_search($Data[0], $Event['Receivers']); if ($Index !== false) { unset($Event['Receivers'][$Index]); } } - $this->WriteAttributeArray('EventProperties', $Events); - $this->unlock('EventProperties'); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::EventProperties, $Events); + $this->unlock(\ONVIF\IO\Attribute::EventProperties); $this->ReloadForm(); break; } @@ -134,7 +134,7 @@ public function MessageSink($TimeStamp, $SenderID, $Message, $Data) public function ApplyChanges() { - $this->SetTimerInterval('RenewSubscription', 0); + $this->SetTimerInterval(\ONVIF\IO\Timer::RenewSubscription, 0); if ($this->GetStatus() == IS_ACTIVE) { // block childs $this->SetStatus(IS_INACTIVE); } @@ -146,32 +146,32 @@ public function ApplyChanges() if (IPS_GetKernelRunlevel() != KR_READY) { return; } - if (!$this->ReadPropertyBoolean('Open')) { + if (!$this->ReadPropertyBoolean(\ONVIF\IO\Property::Active)) { $this->SetStatus(IS_INACTIVE); - $this->LogMessage($this->Translate('Interface closed'), KL_MESSAGE); + $this->LogMessage($this->Translate(\ONVIF\IO\State::INACTIVE), KL_MESSAGE); return; } - $Url = parse_url($this->ReadPropertyString('Address')); + $Url = parse_url($this->ReadPropertyString(\ONVIF\IO\Property::Address)); $Url['port'] = (isset($Url['port']) ? ':' . $Url['port'] : ''); if (!isset($Url['scheme']) && !isset($Url['host'])) { $this->Host = ''; $this->SetStatus(IS_EBASE + 1); $this->SetSummary(''); - $this->WriteAttributeString('ConsumerAddress', ''); + $this->WriteAttributeString(\ONVIF\IO\Attribute::ConsumerAddress, ''); $this->LogMessage($this->Translate('Address is invalid'), KL_ERROR); return; } - $MyIP = $this->ReadPropertyString('WebHookIP'); - $MyPort = $this->ReadPropertyInteger('WebHookPort'); - $MyHTTPS = $this->ReadPropertyBoolean('WebHookHTTPS'); + $MyIP = $this->ReadPropertyString(\ONVIF\IO\Property::WebHookIP); + $MyPort = $this->ReadPropertyInteger(\ONVIF\IO\Property::WebHookPort); + $MyHTTPS = $this->ReadPropertyBoolean(\ONVIF\IO\Property::WebHookHTTPS); $Host = $Url['scheme'] . '://' . $Url['host'] . $Url['port']; $ReloadCapabilities = ($this->Host != $Host); $ReloadCapabilities = $ReloadCapabilities || ($this->MyIP != $MyIP); $ReloadCapabilities = $ReloadCapabilities || ($this->MyPort != $MyPort); $ReloadCapabilities = $ReloadCapabilities || ($this->MyHTTPS != $MyHTTPS); $ReloadCapabilities = $ReloadCapabilities || ($this->GetStatus() == 202); - $ReloadCapabilities = $ReloadCapabilities || ($this->ReadAttributeInteger('CapabilitiesVersion') == 0); //Force on initial update, Version 0 + $ReloadCapabilities = $ReloadCapabilities || ($this->ReadAttributeInteger(\ONVIF\IO\Attribute::CapabilitiesVersion) == 0); //Force on initial update, Version 0 $this->SendDebug('ReloadCapabilities', $ReloadCapabilities, 0); $this->SetSummary($Host); $this->Host = $Host; @@ -184,9 +184,9 @@ public function ApplyChanges() // 2.ONVIF Request GetScopes $Scopes = $this->GetScopes(); // die sagen aus ob G, S oder und T if (!$Scopes && !$Reachable) { // not reachable - $this->UpdateFormField('EventHook', 'caption', $this->ReadAttributeString('ConsumerAddress')); - $this->WriteAttributeString('SubscriptionReference', ''); - $this->WriteAttributeString('SubscriptionId', ''); + $this->UpdateFormField('EventHook', 'caption', $this->ReadAttributeString(\ONVIF\IO\Attribute::ConsumerAddress)); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionReference, ''); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionId, ''); $this->UpdateFormField('SubscriptionReferenceRow', 'visible', false); $this->UpdateFormField('EventHookRow', 'visible', false); $EventList = @$this->GetEventReceiverFormValues(); @@ -208,6 +208,7 @@ public function ApplyChanges() if (!$Scopes) { $Scopes = [\ONVIF\Scopes::ProfileS]; $this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get scopes, device not ONVIF compliant!')]); + $this->LogMessage($this->Translate('Failed to get scopes, device not ONVIF compliant!'), KL_WARNING); } $Profile = new \ONVIF\Profile($Scopes); $this->SendDebug('ProfileBitMask', $Profile->toString(), 0); @@ -215,12 +216,13 @@ public function ApplyChanges() $Profile->Profile = \ONVIF\Profile::S; $this->SendDebug('Fallback ProfileBitMask', $Profile->toString(), 0); $this->Warnings = array_merge($this->Warnings, [$this->Translate('No profile in scopes, device not ONVIF compliant!')]); + $this->LogMessage($this->Translate('No profile in scopes, device not ONVIF compliant!'), KL_WARNING); } $this->lock('Profile'); $this->Profile = $Profile; $this->unlock('Profile'); if ($ReloadCapabilities) { - $this->WriteAttributeInteger('CapabilitiesVersion', 1); // This is Version 1 + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::CapabilitiesVersion, 1); // This is Version 1 // Variablen vorbelegen: $NbrOfVideoSources = 0; $NbrOfAudioSources = 0; @@ -236,24 +238,25 @@ public function ApplyChanges() $HasRTSPStreaming = false; $HasSnapshotUri = false; if ($this->GetCapabilities()) { // besorgt XAddr und einige Attribute Pflicht für Profil S. - $AnalyticsModuleSupport = $this->ReadAttributeBoolean('AnalyticsModuleSupport'); - $RuleSupport = $this->ReadAttributeBoolean('RuleSupport'); - $WSSubscriptionPolicySupport = $this->ReadAttributeBoolean('WSSubscriptionPolicySupport'); - $WSPullPointSupport = $this->ReadAttributeBoolean('WSPullPointSupport'); - $HasRTSPStreaming = $this->ReadAttributeBoolean('HasRTSPStreaming'); - $NbrOfVideoSources = $this->ReadAttributeInteger('NbrOfVideoSources'); - $NbrOfAudioSources = $this->ReadAttributeInteger('NbrOfAudioSources'); - $NbrOfInputs = $this->ReadAttributeInteger('NbrOfInputs'); - $NbrOfOutputs = $this->ReadAttributeInteger('NbrOfOutputs'); + $AnalyticsModuleSupport = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::AnalyticsModuleSupport); + $RuleSupport = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::RuleSupport); + $WSSubscriptionPolicySupport = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::WSSubscriptionPolicySupport); + $WSPullPointSupport = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::WSPullPointSupport); + $HasRTSPStreaming = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::HasRTSPStreaming); + $NbrOfVideoSources = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfVideoSources); + $NbrOfAudioSources = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfAudioSources); + $NbrOfInputs = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfInputs); + $NbrOfOutputs = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfOutputs); } - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); // 3.ONVIF Request GetServices // GetServices besorgt XAddr, Pflicht bei T, selten bei S unterstützt. if (!$this->GetServices() && $this->Profile->HasProfile(\ONVIF\Profile::T)) { $this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get services. Device reported ONVIF T scope, but is not compliant!')]); + $this->LogMessage($this->Translate('Failed to get services. Device reported ONVIF T scope, but is not compliant!'), KL_WARNING); } - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); // 4. ONVIF Request GetServiceCapabilities an \ONVIF\WSDL::Management //$this->GetServiceCapabilities($XAddr[\ONVIF\NS::Management], \ONVIF\WSDL::Management); // noch ohne Funktion.. @@ -304,7 +307,7 @@ public function ApplyChanges() $RelayOutputs = $this->GetRelayOutputs($XAddr[\ONVIF\NS::DeviceIO], \ONVIF\WSDL::DeviceIO); if (!$RelayOutputs) { $XAddr[\ONVIF\NS::DeviceIO] = ''; - $this->WriteAttributeArray('XAddr', $XAddr); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::XAddr, $XAddr); $RelayOutputs = $this->GetRelayOutputs($XAddr[\ONVIF\NS::Management], \ONVIF\WSDL::Management); } if (!$RelayOutputs) { @@ -319,12 +322,13 @@ public function ApplyChanges() } else { if ($this->Profile->HasProfile(\ONVIF\Profile::T)) { //Profile T ist GetServiceCapabilities bei DeviceIO Pflicht $this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get DeviceIO service capabilities. Device reported ONVIF T scope, but is not compliant!')]); + $this->LogMessage($this->Translate('Failed to get DeviceIO service capabilities. Device reported ONVIF T scope, but is not compliant!'), KL_WARNING); } //Fallback für reine Profile S Geräte - $VideoSources = $this->GetVideoSources($XAddr[\ONVIF\NS::Media], \ONVIF\WSDL::Media); // array of Token - if ($VideoSources) { - $NbrOfVideoSources = count($VideoSources['VideoSources']); - } + $VideoSources = $this->GetVideoSources($XAddr[\ONVIF\NS::Media], \ONVIF\WSDL::Media); // array of Token + if ($VideoSources) { + $NbrOfVideoSources = count($VideoSources['VideoSources']); + } $AudioSources = $this->GetAudioSources($XAddr[\ONVIF\NS::Media], \ONVIF\WSDL::Media); // array of Token if ($AudioSources) { $NbrOfAudioSources = count($AudioSources['AudioSources']); @@ -339,29 +343,30 @@ public function ApplyChanges() } } // Variablen in Attribute schreiben: - $this->WriteAttributeInteger('NbrOfVideoSources', $NbrOfVideoSources); - $this->WriteAttributeInteger('NbrOfAudioSources', $NbrOfAudioSources); - $this->WriteAttributeInteger('NbrOfOutputs', $NbrOfOutputs); - $this->WriteAttributeInteger('NbrOfInputs', $NbrOfInputs); - $this->WriteAttributeInteger('NbrOfSerialPorts', $NbrOfSerialPorts); - $this->WriteAttributeArray('RelayOutputs', $RelayOutputs); - $this->WriteAttributeArray('DigitalInputs', $DigitalInputs); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::NbrOfVideoSources, $NbrOfVideoSources); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::NbrOfAudioSources, $NbrOfAudioSources); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::NbrOfOutputs, $NbrOfOutputs); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::NbrOfInputs, $NbrOfInputs); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::NbrOfSerialPorts, $NbrOfSerialPorts); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::RelayOutputs, $RelayOutputs); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::DigitalInputs, $DigitalInputs); // Wenn \ONVIF\WSDL::Media2 unterstützt if ($XAddr[\ONVIF\NS::Media2]) { // 4c.ONVIF Request GetServiceCapabilities an \ONVIF\WSDL::Media2 - $MediaCapabilities = $this->GetServiceCapabilities($XAddr[\ONVIF\NS::Media2], \ONVIF\WSDL::Media2); // noch ohne Funktion.. - if ($MediaCapabilities) { - $Capabilities = $MediaCapabilities['Capabilities']; - $HasRTSPStreaming = $HasRTSPStreaming || $Capabilities['StreamingCapabilities']['RTSPStreaming'] || $Capabilities['StreamingCapabilities']['RTP_RTSP_TCP']; - if (isset($Capabilities['SnapshotUri'])) { - $HasSnapshotUri = $Capabilities['SnapshotUri']; - } - } else { - if ($this->Profile->HasProfile(\ONVIF\Profile::T)) { //Profile T ist GetServiceCapabilities bei Media2 Pflicht - $this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get Media2 service capabilities. Device reported ONVIF T scope, but is not compliant!')]); - } + $MediaCapabilities = $this->GetServiceCapabilities($XAddr[\ONVIF\NS::Media2], \ONVIF\WSDL::Media2); // noch ohne Funktion.. + if ($MediaCapabilities) { + $Capabilities = $MediaCapabilities['Capabilities']; + $HasRTSPStreaming = $HasRTSPStreaming || $Capabilities['StreamingCapabilities']['RTSPStreaming'] || $Capabilities['StreamingCapabilities']['RTP_RTSP_TCP']; + if (isset($Capabilities['SnapshotUri'])) { + $HasSnapshotUri = $Capabilities['SnapshotUri']; + } + } else { + if ($this->Profile->HasProfile(\ONVIF\Profile::T)) { //Profile T ist GetServiceCapabilities bei Media2 Pflicht + $this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get Media2 service capabilities. Device reported ONVIF T scope, but is not compliant!')]); + $this->LogMessage($this->Translate('Failed to get Media2 service capabilities. Device reported ONVIF T scope, but is not compliant!'), KL_WARNING); } + } // 4c.ONVIF Request GetProfiles an \ONVIF\WSDL::Media2 if (!$this->GetProfiles2()) { $this->SetStatus(IS_EBASE + 2); @@ -370,18 +375,19 @@ public function ApplyChanges() } else { // Wenn \ONVIF\WSDL::Media2 NICHT unterstützt // 4c.ONVIF Request GetServiceCapabilities an \ONVIF\WSDL::Media - $MediaCapabilities = $this->GetServiceCapabilities($XAddr[\ONVIF\NS::Media], \ONVIF\WSDL::Media); // noch ohne Funktion.. - if ($MediaCapabilities) { - $Capabilities = $MediaCapabilities['Capabilities']; - $HasRTSPStreaming = $HasRTSPStreaming || $Capabilities['StreamingCapabilities']['RTP_TCP'] || $Capabilities['StreamingCapabilities']['RTP_RTSP_TCP']; - if (isset($Capabilities['SnapshotUri'])) { - $HasSnapshotUri = $Capabilities['SnapshotUri']; - } - } else { - if ($this->Profile->HasProfile(\ONVIF\Profile::T)) { //Profile T ist GetServiceCapabilities bei Media Pflicht - $this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get Media service capabilities. Device reported ONVIF T scope, but is not compliant!')]); - } + $MediaCapabilities = $this->GetServiceCapabilities($XAddr[\ONVIF\NS::Media], \ONVIF\WSDL::Media); // noch ohne Funktion.. + if ($MediaCapabilities) { + $Capabilities = $MediaCapabilities['Capabilities']; + $HasRTSPStreaming = $HasRTSPStreaming || $Capabilities['StreamingCapabilities']['RTP_TCP'] || $Capabilities['StreamingCapabilities']['RTP_RTSP_TCP']; + if (isset($Capabilities['SnapshotUri'])) { + $HasSnapshotUri = $Capabilities['SnapshotUri']; + } + } else { + if ($this->Profile->HasProfile(\ONVIF\Profile::T)) { //Profile T ist GetServiceCapabilities bei Media Pflicht + $this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get Media service capabilities. Device reported ONVIF T scope, but is not compliant!')]); + $this->LogMessage($this->Translate('Failed to get Media service capabilities. Device reported ONVIF T scope, but is not compliant!'), KL_WARNING); } + } // 4c.ONVIF Request GetProfiles an \ONVIF\WSDL::Media if (!$this->GetProfiles()) { @@ -390,8 +396,8 @@ public function ApplyChanges() } } // Variablen in Attribute schreiben: - $this->WriteAttributeBoolean('HasRTSPStreaming', $HasRTSPStreaming); - $this->WriteAttributeBoolean('HasSnapshotUri', $HasSnapshotUri); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::HasRTSPStreaming, $HasRTSPStreaming); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::HasSnapshotUri, $HasSnapshotUri); // Wenn \ONVIF\WSDL::PTZ unterstützt // 4d.ONVIF Request GetNodes an \ONVIF\WSDL::PTZ if ($XAddr[\ONVIF\NS::PTZ]) { @@ -404,6 +410,7 @@ public function ApplyChanges() } else { if ($this->Profile->HasProfile(\ONVIF\Profile::T)) { //Profile T ist GetServiceCapabilities bei Imaging Pflicht $this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get Imaging service capabilities. Device reported ONVIF T scope, but is not compliant!')]); + $this->LogMessage($this->Translate('Failed to get Imaging service capabilities. Device reported ONVIF T scope, but is not compliant!'), KL_WARNING); } } } @@ -421,6 +428,7 @@ public function ApplyChanges() } else { if ($this->Profile->HasProfile(\ONVIF\Profile::T)) { //Profile T ist GetServiceCapabilities bei Event Pflicht $this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get Event service capabilities. Device reported ONVIF T scope, but is not compliant!')]); + $this->LogMessage($this->Translate('Failed to get Event service capabilities. Device reported ONVIF T scope, but is not compliant!'), KL_WARNING); } } //Jetzt Events auslesen @@ -431,9 +439,9 @@ public function ApplyChanges() } } // Variablen in Attribute schreiben: - $this->WriteAttributeBoolean('WSSubscriptionPolicySupport', $WSSubscriptionPolicySupport); - $this->WriteAttributeBoolean('WSPullPointSupport', $WSPullPointSupport); - $AnalyticsTokens = $this->ReadAttributeArray('AnalyticsTokens'); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::WSSubscriptionPolicySupport, $WSSubscriptionPolicySupport); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::WSPullPointSupport, $WSPullPointSupport); + $AnalyticsTokens = $this->ReadAttributeArray(\ONVIF\IO\Attribute::AnalyticsTokens); if ($XAddr[\ONVIF\NS::Analytics]) { $AnalyticsCapabilities = $this->GetServiceCapabilities($XAddr[\ONVIF\NS::Analytics], \ONVIF\WSDL::Analytics); if (isset($AnalyticsCapabilities['Capabilities']['AnalyticsModuleSupport'])) { @@ -455,29 +463,30 @@ public function ApplyChanges() } else { if (count($AnalyticsTokens)) { $this->Warnings = array_merge($this->Warnings, [$this->Translate('Analytics events could not be retrieved. The device reported AnalyticsTokens, but the Analytics namespace and XAddr were not reported!')]); + $this->LogMessage($this->Translate('Analytics events could not be retrieved. The device reported AnalyticsTokens, but the Analytics namespace and XAddr were not reported!'), KL_WARNING); } } // Variablen in Attribute schreiben: - $this->WriteAttributeBoolean('AnalyticsModuleSupport', $AnalyticsModuleSupport); - $this->WriteAttributeBoolean('RuleSupport', $RuleSupport); - $this->lock('EventProperties'); - $this->WriteAttributeArray('EventProperties', $AllEventProperties); - $this->unlock('EventProperties'); - $this->SendDebug('EventProperties', $AllEventProperties, 0); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::AnalyticsModuleSupport, $AnalyticsModuleSupport); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::RuleSupport, $RuleSupport); + $this->lock(\ONVIF\IO\Attribute::EventProperties); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::EventProperties, $AllEventProperties); + $this->unlock(\ONVIF\IO\Attribute::EventProperties); + $this->SendDebug(\ONVIF\IO\Attribute::EventProperties, $AllEventProperties, 0); $EventList = @$this->GetEventReceiverFormValues(); $this->SendDebug('Update form', json_encode($EventList), 0); $this->UpdateFormField('Events', 'values', json_encode($EventList)); $this->UpdateFormField('Events', 'visible', true); } else { - $this->SendDebug('VideoSources H.26x', $this->ReadAttributeArray('VideoSources'), 0); - $this->SendDebug('VideoSources JPEG', $this->ReadAttributeArray('VideoSourcesJPEG'), 0); - $XAddr = $this->ReadAttributeArray('XAddr'); + $this->SendDebug('VideoSources H.26x', $this->ReadAttributeArray(\ONVIF\IO\Attribute::VideoSources), 0); + $this->SendDebug('VideoSources JPEG', $this->ReadAttributeArray(\ONVIF\IO\Attribute::VideoSourcesJPEG), 0); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); } // Start Event Handler if ($XAddr[\ONVIF\NS::Event]) { - $AllowedEventHandler = $this->ReadPropertyInteger('EventHandler'); + $AllowedEventHandler = $this->ReadPropertyInteger(\ONVIF\IO\Property::EventHandler); if ($AllowedEventHandler == \ONVIF\EventHandler::None) { - $this->LogMessage($this->Translate('Interface connected'), KL_MESSAGE); + $this->LogMessage($this->Translate(\ONVIF\IO\State::ACTIVE), KL_MESSAGE); $this->SetStatus(IS_ACTIVE); } else { if ($this->Profile->Profile == \ONVIF\Profile::T) { // Wenn NUR Profile T unterstützt wird, dann PullPoint @@ -496,8 +505,8 @@ public function ApplyChanges() if ($this->GetConsumerAddress()) { // yeah, we can receive events IPS_RunScriptText('IPS_Sleep(1000);IPS_RequestAction(' . $this->InstanceID . ',"Subscribe",true);'); } else { // we cannot receive events :( - $this->WriteAttributeString('SubscriptionReference', ''); - $this->WriteAttributeString('SubscriptionId', ''); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionReference, ''); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionId, ''); $this->UpdateFormField('SubscriptionReference', 'caption', $this->Translate('This device not support events.')); $this->UpdateFormField('SubscriptionReferenceRow', 'visible', true); } @@ -506,7 +515,8 @@ public function ApplyChanges() } } else { $this->Warnings = array_merge($this->Warnings, [$this->Translate('This device does not support ONVIF events, but it is mandatory.')]); - $this->LogMessage($this->Translate('Interface connected'), KL_MESSAGE); + $this->LogMessage($this->Translate('This device does not support ONVIF events, but it is mandatory.'), KL_WARNING); + $this->LogMessage($this->Translate(\ONVIF\IO\State::ACTIVE), KL_MESSAGE); $this->SetStatus(IS_ACTIVE); } } @@ -516,21 +526,22 @@ public function ForwardData($JSONString) $Data = json_decode($JSONString, true); unset($Data['DataID']); if ($Data['Function'] == 'GetCapabilities') { - $Capabilities['VideoSources'] = $this->ReadAttributeArray('VideoSources'); - $Capabilities['VideoSourcesJPEG'] = $this->ReadAttributeArray('VideoSourcesJPEG'); - $Capabilities['RelayOutputs'] = $this->ReadAttributeArray('RelayOutputs'); - $Capabilities['DigitalInputs'] = $this->ReadAttributeArray('DigitalInputs'); - $Capabilities['NbrOfVideoSources'] = $this->ReadAttributeInteger('NbrOfVideoSources'); - $Capabilities['NbrOfAudioSources'] = $this->ReadAttributeInteger('NbrOfAudioSources'); - $Capabilities['NbrOfOutputs'] = $this->ReadAttributeInteger('NbrOfOutputs'); - $Capabilities['NbrOfInputs'] = $this->ReadAttributeInteger('NbrOfInputs'); - $Capabilities['NbrOfSerialPorts'] = $this->ReadAttributeInteger('NbrOfSerialPorts'); - $Capabilities['HasSnapshotUri'] = $this->ReadAttributeBoolean('HasSnapshotUri'); - $Capabilities['HasRTSPStreaming'] = $this->ReadAttributeBoolean('HasRTSPStreaming'); - $Capabilities['AnalyticsModuleSupport'] = $this->ReadAttributeBoolean('AnalyticsModuleSupport'); - $Capabilities['AnalyticsTokens'] = $this->ReadAttributeArray('AnalyticsTokens'); - $Capabilities['RuleSupport'] = $this->ReadAttributeBoolean('RuleSupport'); - $Capabilities['XAddr'] = $this->ReadAttributeArray('XAddr'); + $Capabilities[\ONVIF\IO\Attribute::VideoSources] = $this->ReadAttributeArray(\ONVIF\IO\Attribute::VideoSources); + $Capabilities[\ONVIF\IO\Attribute::AudioSources] = $this->ReadAttributeArray(\ONVIF\IO\Attribute::AudioSources); + $Capabilities[\ONVIF\IO\Attribute::VideoSourcesJPEG] = $this->ReadAttributeArray(\ONVIF\IO\Attribute::VideoSourcesJPEG); + $Capabilities[\ONVIF\IO\Attribute::RelayOutputs] = $this->ReadAttributeArray(\ONVIF\IO\Attribute::RelayOutputs); + $Capabilities[\ONVIF\IO\Attribute::DigitalInputs] = $this->ReadAttributeArray(\ONVIF\IO\Attribute::DigitalInputs); + $Capabilities[\ONVIF\IO\Attribute::NbrOfVideoSources] = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfVideoSources); + $Capabilities[\ONVIF\IO\Attribute::NbrOfAudioSources] = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfAudioSources); + $Capabilities[\ONVIF\IO\Attribute::NbrOfOutputs] = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfOutputs); + $Capabilities[\ONVIF\IO\Attribute::NbrOfInputs] = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfInputs); + $Capabilities[\ONVIF\IO\Attribute::NbrOfSerialPorts] = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfSerialPorts); + $Capabilities[\ONVIF\IO\Attribute::HasSnapshotUri] = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::HasSnapshotUri); + $Capabilities[\ONVIF\IO\Attribute::HasRTSPStreaming] = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::HasRTSPStreaming); + $Capabilities[\ONVIF\IO\Attribute::AnalyticsModuleSupport] = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::AnalyticsModuleSupport); + $Capabilities[\ONVIF\IO\Attribute::AnalyticsTokens] = $this->ReadAttributeArray(\ONVIF\IO\Attribute::AnalyticsTokens); + $Capabilities[\ONVIF\IO\Attribute::RuleSupport] = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::RuleSupport); + $Capabilities[\ONVIF\IO\Attribute::XAddr] = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); return serialize($Capabilities); } if ($Data['Function'] == 'SetSynchronizationPoint') { @@ -543,15 +554,15 @@ public function ForwardData($JSONString) return serialize($this->Host); } if ($Data['Function'] == 'GetCredentials') { - $Credentials['Username'] = $this->ReadPropertyString('Username'); - $Credentials['Password'] = $this->ReadPropertyString('Password'); + $Credentials[\ONVIF\IO\Property::Username] = $this->ReadPropertyString(\ONVIF\IO\Property::Username); + $Credentials[\ONVIF\IO\Property::Password] = $this->ReadPropertyString(\ONVIF\IO\Property::Password); return serialize($Credentials); } if ($Data['Function'] == 'GetEvents') { if ($Data['Instance'] != 0) { - $this->lock('EventProperties'); + $this->lock(\ONVIF\IO\Attribute::EventProperties); } - $Events = $this->ReadAttributeArray('EventProperties'); + $Events = $this->ReadAttributeArray(\ONVIF\IO\Attribute::EventProperties); $SkippedTopics = $Data['SkippedTopics']; $FoundEvents = []; @@ -607,8 +618,8 @@ public function ForwardData($JSONString) } } if ($Data['Instance'] != 0) { - $this->WriteAttributeArray('EventProperties', $Events); - $this->unlock('EventProperties'); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::EventProperties, $Events); + $this->unlock(\ONVIF\IO\Attribute::EventProperties); $EventList = $this->GetEventReceiverFormValues(); $this->UpdateFormField('Events', 'values', json_encode($EventList)); } @@ -630,17 +641,17 @@ public function RequestAction($Ident, $Value) { switch ($Ident) { case 'Subscribe': - $AllowedEventHandler = $this->ReadPropertyInteger('EventHandler'); + $AllowedEventHandler = $this->ReadPropertyInteger(\ONVIF\IO\Property::EventHandler); if (($AllowedEventHandler & \ONVIF\EventHandler::Subscribe) == \ONVIF\EventHandler::Subscribe) { if ($this->Subscribe()) { return; } - $this->WriteAttributeString('ConsumerAddress', ''); + $this->WriteAttributeString(\ONVIF\IO\Attribute::ConsumerAddress, ''); $this->UpdateFormField('EventHookRow', 'visible', false); } - if ($AllowedEventHandler != \ONVIF\EventHandler::Automatic) { - break; - } + if ($AllowedEventHandler != \ONVIF\EventHandler::Automatic) { + break; + } // WSSubscription failed, try PullPointSubscription // No break. Add additional comment above this line if intentional case 'CreatePullPointSubscription': @@ -662,14 +673,14 @@ public function RequestAction($Ident, $Value) case 'Reload': $this->Unsubscribe(); if ($this->GetStatus() == IS_INACTIVE) { - $this->WriteAttributeString('ConsumerAddress', ''); + $this->WriteAttributeString(\ONVIF\IO\Attribute::ConsumerAddress, ''); return; } $this->UpdateFormField('ErrorTitle', 'caption', $this->Translate('Please wait!')); $this->UpdateFormField('ErrorText', 'caption', $this->Translate('Determine abilities of this device')); $this->UpdateFormField('ErrorPopup', 'visible', true); - $this->WriteAttributeString('ConsumerAddress', ''); - $this->WriteAttributeInteger('CapabilitiesVersion', 0); + $this->WriteAttributeString(\ONVIF\IO\Attribute::ConsumerAddress, ''); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::CapabilitiesVersion, 0); $this->ApplyChanges(); $this->ReloadForm(); return; @@ -682,7 +693,7 @@ public function RequestAction($Ident, $Value) case'KernelReady': $this->KernelReady(); return; - case 'EventHandler': + case \ONVIF\IO\Property::EventHandler: switch ((int) $Value) { case \ONVIF\EventHandler::None: $this->UpdateFormField('SubscribeExpansionPanel', 'visible', false); @@ -700,9 +711,9 @@ public function RequestAction($Ident, $Value) $this->UpdateFormField('SubscribeExpansionPanel', 'visible', true); $this->UpdateFormField('PullPointExpansionPanel', 'visible', true); break; - } + } return; - } + } } public function GetConfigurationForm() { @@ -710,7 +721,7 @@ public function GetConfigurationForm() if ($this->GetStatus() == IS_CREATING) { return json_encode($Form); } - $EventHandler = $this->ReadPropertyInteger('EventHandler'); + $EventHandler = $this->ReadPropertyInteger(\ONVIF\IO\Property::EventHandler); switch ($EventHandler) { case \ONVIF\EventHandler::None: $Form['elements'][4]['visible'] = false; @@ -731,7 +742,7 @@ public function GetConfigurationForm() } if ($this->GetStatus() == IS_ACTIVE) { $Form['actions'][1]['items'][0]['items'] = $this->GetDeviceDataForForm(); - $SubscriptionReference = $this->ReadAttributeString('SubscriptionReference'); + $SubscriptionReference = $this->ReadAttributeString(\ONVIF\IO\Attribute::SubscriptionReference); if ($SubscriptionReference == '') { $SubscriptionReference = $this->Translate('This device not support events or they are disabled.'); $Form['actions'][4]['visible'] = false; @@ -742,7 +753,7 @@ public function GetConfigurationForm() $Form['actions'][1]['visible'] = false; $Form['actions'][3]['visible'] = false; } - $ConsumerAddress = $this->ReadAttributeString('ConsumerAddress'); + $ConsumerAddress = $this->ReadAttributeString(\ONVIF\IO\Attribute::ConsumerAddress); if ($ConsumerAddress != '') { $Form['actions'][2]['visible'] = true; } @@ -753,7 +764,7 @@ public function GetConfigurationForm() $Form['actions'][4]['values'] = $EventList; } $Warnings = $this->Warnings; - if (count($Warnings) && $this->ReadPropertyBoolean('Open')) { + if (count($Warnings) && $this->ReadPropertyBoolean(\ONVIF\IO\Property::Active)) { $WarningText = implode("\r\n", $Warnings); $Form['actions'][5]['visible'] = true; $Form['actions'][5]['popup']['items'][0]['caption'] = $this->Translate('Some features will not work properly'); @@ -796,11 +807,11 @@ protected function GetDeviceDataForForm(): array $InfoItems[] = [ 'type' => 'Label', - 'caption' => $this->Translate('Event subscription: ') . ($this->ReadAttributeBoolean('WSSubscriptionPolicySupport') ? $this->Translate('supported') : $this->Translate('not supported')) + 'caption' => $this->Translate('Event subscription: ') . ($this->ReadAttributeBoolean(\ONVIF\IO\Attribute::WSSubscriptionPolicySupport) ? $this->Translate('supported') : $this->Translate('not supported')) ]; $InfoItems[] = [ 'type' => 'Label', - 'caption' => $this->Translate('Event PullPoint: ') . ($this->ReadAttributeBoolean('WSPullPointSupport') ? $this->Translate('supported') : $this->Translate('not supported')) + 'caption' => $this->Translate('Event PullPoint: ') . ($this->ReadAttributeBoolean(\ONVIF\IO\Attribute::WSPullPointSupport) ? $this->Translate('supported') : $this->Translate('not supported')) ]; $InfoItems[] = [ 'type' => 'Label', @@ -812,39 +823,39 @@ protected function GetDeviceDataForForm(): array [ 'width' => '200px', 'type' => 'Label', - 'caption' => $this->Translate('Videosources: ') . $this->ReadAttributeInteger('NbrOfVideoSources') + 'caption' => $this->Translate('Videosources: ') . $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfVideoSources) ], [ 'type' => 'Label', - 'caption' => $this->Translate('Audiosources: ') . $this->ReadAttributeInteger('NbrOfAudioSources') + 'caption' => $this->Translate('Audiosources: ') . $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfAudioSources) ], [ 'type' => 'Label', - 'caption' => $this->Translate('Inputs: ') . $this->ReadAttributeInteger('NbrOfInputs') + 'caption' => $this->Translate('Inputs: ') . $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfInputs) ], [ 'type' => 'Label', - 'caption' => $this->Translate('Outputs: ') . $this->ReadAttributeInteger('NbrOfOutputs') + 'caption' => $this->Translate('Outputs: ') . $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfOutputs) ], [ 'type' => 'Label', - 'caption' => $this->Translate('Serial ports: ') . $this->ReadAttributeInteger('NbrOfSerialPorts') + 'caption' => $this->Translate('Serial ports: ') . $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfSerialPorts) ], [ 'type' => 'Label', - 'caption' => 'RTSP Streaming: ' . ($this->ReadAttributeBoolean('HasRTSPStreaming') ? $this->Translate('supported') : $this->Translate('not supported')) + 'caption' => 'RTSP Streaming: ' . ($this->ReadAttributeBoolean(\ONVIF\IO\Attribute::HasRTSPStreaming) ? $this->Translate('supported') : $this->Translate('not supported')) ], [ 'type' => 'Label', - 'caption' => 'Snapshots: ' . ($this->ReadAttributeBoolean('HasSnapshotUri') ? $this->Translate('supported') : $this->Translate('not supported')) + 'caption' => 'Snapshots: ' . ($this->ReadAttributeBoolean(\ONVIF\IO\Attribute::HasSnapshotUri) ? $this->Translate('supported') : $this->Translate('not supported')) ], [ 'type' => 'Label', - 'caption' => 'Analytics: ' . ($this->ReadAttributeBoolean('AnalyticsModuleSupport') ? $this->Translate('supported') : $this->Translate('not supported')) + 'caption' => 'Analytics: ' . ($this->ReadAttributeBoolean(\ONVIF\IO\Attribute::AnalyticsModuleSupport) ? $this->Translate('supported') : $this->Translate('not supported')) ], [ 'type' => 'Label', - 'caption' => 'Rules: ' . ($this->ReadAttributeBoolean('RuleSupport') ? $this->Translate('supported') : $this->Translate('not supported')) + 'caption' => 'Rules: ' . ($this->ReadAttributeBoolean(\ONVIF\IO\Attribute::RuleSupport) ? $this->Translate('supported') : $this->Translate('not supported')) ] ]; @@ -884,7 +895,7 @@ protected function GetConsumerAddress(): bool if ($ip == '') { $this->SendDebug('NAT enabled ConsumerAddress', 'Invalid', 0); $this->UpdateFormField('EventHook', 'caption', $this->Translate('NATPublicIP is missing in special switches!')); - $this->WriteAttributeString('ConsumerAddress', 'Invalid'); + $this->WriteAttributeString(\ONVIF\IO\Attribute::ConsumerAddress, 'Invalid'); $this->ShowLastError('Error', $this->Translate('NAT support is active, but no public address is set.')); return false; } @@ -905,7 +916,7 @@ protected function GetConsumerAddress(): bool $this->UpdateFormField('EventHookRow', 'visible', true); $this->SendDebug('ConsumerAddress', 'Invalid', 0); $this->UpdateFormField('EventHook', 'caption', $this->Translate('Invalid')); - $this->WriteAttributeString('ConsumerAddress', 'Invalid'); + $this->WriteAttributeString(\ONVIF\IO\Attribute::ConsumerAddress, 'Invalid'); return false; } } @@ -915,18 +926,18 @@ protected function GetConsumerAddress(): bool $this->SendDebug($Debug, $Url, 0); $this->UpdateFormField('EventHookRow', 'visible', true); $this->UpdateFormField('EventHook', 'caption', $Url); - $this->WriteAttributeString('ConsumerAddress', $Url); + $this->WriteAttributeString(\ONVIF\IO\Attribute::ConsumerAddress, $Url); return true; } protected function CreatePullPointSubscription(): bool { - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); if ($XAddr[\ONVIF\NS::Event] == '') { return false; } - $PullPointInitialTerminationTime = $this->ReadPropertyInteger('PullPointInitialTerminationTime'); - $AllowedEventHandler = $this->ReadPropertyInteger('EventHandler'); - $this->lock('EventHandler'); + $PullPointInitialTerminationTime = $this->ReadPropertyInteger(\ONVIF\IO\Property::PullPointInitialTerminationTime); + $AllowedEventHandler = $this->ReadPropertyInteger(\ONVIF\IO\Property::EventHandler); + $this->lock(\ONVIF\IO\Property::EventHandler); $Action = 'http://www.onvif.org/ver10/events/wsdl/EventPortType/CreatePullPointSubscriptionRequest'; $Header = $this->GenerateSOAPHeader($Action, $this->Host . $XAddr[\ONVIF\NS::Event]); $empty = ''; @@ -935,25 +946,25 @@ protected function CreatePullPointSubscription(): bool ]; $CreatePullPointResult = $this->SendData($XAddr[\ONVIF\NS::Event], \ONVIF\WSDL::Event, 'CreatePullPointSubscription', true, $Params, $empty, $Header); if (is_a($CreatePullPointResult, 'SoapFault')) { - $this->unlock('EventHandler'); + $this->unlock(\ONVIF\IO\Property::EventHandler); if ($AllowedEventHandler == \ONVIF\EventHandler::Automatic) { $this->SetStatus(IS_EBASE + 4); } else { $this->SetStatus(IS_EBASE + 3); } - $this->LogMessage($this->Translate('Connection lost'), KL_ERROR); + $this->LogMessage($this->Translate(\ONVIF\IO\State::CONNECTION_LOST), KL_ERROR); /** @var SoapFault $CreatePullPointResult */ $this->ShowLastError($CreatePullPointResult->getMessage()); return false; } if (!is_object($CreatePullPointResult)) { - $this->unlock('EventHandler'); + $this->unlock(\ONVIF\IO\Property::EventHandler); if ($AllowedEventHandler == \ONVIF\EventHandler::Automatic) { $this->SetStatus(IS_EBASE + 4); } else { $this->SetStatus(IS_EBASE + 3); } - $this->LogMessage($this->Translate('Connection lost'), KL_ERROR); + $this->LogMessage($this->Translate(\ONVIF\IO\State::CONNECTION_LOST), KL_ERROR); $this->ShowLastError('No Response'); return false; } @@ -961,29 +972,29 @@ protected function CreatePullPointSubscription(): bool $this->SendDebug('SubscriptionReference', $SubscriptionReference, 0); $ReferenceUrl = parse_url($SubscriptionReference, PHP_URL_HOST); $ReferenceUrl = $ReferenceUrl !== null ? $ReferenceUrl : 'INVALID'; - if (strpos($this->ReadPropertyString('Address'), $ReferenceUrl) === false) { + if (strpos($this->ReadPropertyString(\ONVIF\IO\Property::Address), $ReferenceUrl) === false) { $this->SendDebug('Warning', 'invalid Subscription-Reference, try to fix it', 0); $Url = parse_url($SubscriptionReference); - $Url['host'] = parse_url($this->ReadPropertyString('Address'), PHP_URL_HOST); - $Url['port'] = parse_url($this->ReadPropertyString('Address'), PHP_URL_PORT); + $Url['host'] = parse_url($this->ReadPropertyString(\ONVIF\IO\Property::Address), PHP_URL_HOST); + $Url['port'] = parse_url($this->ReadPropertyString(\ONVIF\IO\Property::Address), PHP_URL_PORT); $SubscriptionReference = self::unparse_url($Url); } - $this->WriteAttributeString('SubscriptionReference', $SubscriptionReference); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionReference, $SubscriptionReference); $this->UpdateFormField('SubscriptionReference', 'caption', $SubscriptionReference); $this->UpdateFormField('SubscriptionReferenceRow', 'visible', true); if (property_exists($CreatePullPointResult->SubscriptionReference, 'ReferenceParameters')) { $SubscriptionId = property_exists($CreatePullPointResult->SubscriptionReference->ReferenceParameters, 'any') ? $CreatePullPointResult->SubscriptionReference->ReferenceParameters->any : ''; $this->SendDebug('SubscriptionId', $SubscriptionId, 0); - $this->WriteAttributeString('SubscriptionId', $SubscriptionId); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionId, $SubscriptionId); } else { - $this->WriteAttributeString('SubscriptionId', ''); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionId, ''); } $this->isSubscribed = true; $this->usedEventHandler = new \ONVIF\EventHandler(\ONVIF\EventHandler::PullPoint); $this->SetRenewInterval($CreatePullPointResult); $this->SetSynchronizationPoint(); - $this->unlock('EventHandler'); - $this->LogMessage($this->Translate('Interface connected'), KL_MESSAGE); + $this->unlock(\ONVIF\IO\Property::EventHandler); + $this->LogMessage($this->Translate(\ONVIF\IO\State::ACTIVE), KL_MESSAGE); $this->SetStatus(IS_ACTIVE); return true; } @@ -993,20 +1004,20 @@ protected function PullMessages(): void // Exit PullMessages loop return; } - $SubscriptionReference = $this->ReadAttributeString('SubscriptionReference'); + $SubscriptionReference = $this->ReadAttributeString(\ONVIF\IO\Attribute::SubscriptionReference); if ($SubscriptionReference == '') { $this->SendDebug('ERROR PullMessages', 'No SubscriptionReference', 0); $this->LogMessage($this->Translate('Call PullMessages with no SubscriptionReference'), KL_ERROR); $this->SetStatus(IS_EBASE + 3); - $this->LogMessage($this->Translate('Connection lost'), KL_ERROR); + $this->LogMessage($this->Translate(\ONVIF\IO\State::CONNECTION_LOST), KL_ERROR); return; } - $Timeout = $this->ReadPropertyInteger('PullPointTimeout'); + $Timeout = $this->ReadPropertyInteger(\ONVIF\IO\Property::PullPointTimeout); $Action = 'http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest'; $Header = $this->GenerateSOAPHeader($Action, $SubscriptionReference); $Params = [ 'Timeout' => 'PT' . (string) $Timeout . 'S', - 'MessageLimit'=> $this->ReadPropertyInteger('MessageLimit') + 'MessageLimit'=> $this->ReadPropertyInteger(\ONVIF\IO\Property::MessageLimit) ]; $Response = ''; $ResponseTime = time() + $Timeout; @@ -1044,18 +1055,18 @@ protected function PullMessages(): void } protected function Subscribe(): bool { - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); if ($XAddr[\ONVIF\NS::Event] == '') { return false; } - $SubscribeInitialTerminationTime = $this->ReadPropertyInteger('SubscribeInitialTerminationTime'); - $AllowedEventHandler = $this->ReadPropertyInteger('EventHandler'); - $this->lock('EventHandler'); + $SubscribeInitialTerminationTime = $this->ReadPropertyInteger(\ONVIF\IO\Property::SubscribeInitialTerminationTime); + $AllowedEventHandler = $this->ReadPropertyInteger(\ONVIF\IO\Property::EventHandler); + $this->lock(\ONVIF\IO\Property::EventHandler); $Action = 'http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest'; $Header = $this->GenerateSOAPHeader($Action, $this->Host . $XAddr[\ONVIF\NS::Event]); $Params = [ 'ConsumerReference' => [ - 'Address' => $this->ReadAttributeString('ConsumerAddress') + 'Address' => $this->ReadAttributeString(\ONVIF\IO\Attribute::ConsumerAddress) ], 'InitialTerminationTime' => 'PT' . (string) $SubscribeInitialTerminationTime . 'M' ]; @@ -1064,10 +1075,10 @@ protected function Subscribe(): bool $SubscribeResult = $this->SendData($XAddr[\ONVIF\NS::Event], \ONVIF\WSDL::Event, 'Subscribe', true, $Params, $Response, $Header); if (is_a($SubscribeResult, 'SoapFault') || (!is_object($SubscribeResult))) { $this->WaitForFirstEvent = false; - $this->unlock('EventHandler'); + $this->unlock(\ONVIF\IO\Property::EventHandler); if ($AllowedEventHandler == \ONVIF\EventHandler::Subscribe) { // nur Subscribe erlaubt $this->SetStatus(IS_EBASE + 3); - $this->LogMessage($this->Translate('Connection lost'), KL_ERROR); + $this->LogMessage($this->Translate(\ONVIF\IO\State::CONNECTION_LOST), KL_ERROR); $this->ShowLastError($SubscribeResult->getMessage()); } return false; @@ -1077,29 +1088,29 @@ protected function Subscribe(): bool $ReferenceUrl = parse_url($SubscriptionReference, PHP_URL_HOST); $ReferenceUrl = $ReferenceUrl !== null ? $ReferenceUrl : 'INVALID'; - if (strpos($this->ReadPropertyString('Address'), $ReferenceUrl) === false) { + if (strpos($this->ReadPropertyString(\ONVIF\IO\Property::Address), $ReferenceUrl) === false) { $this->SendDebug('Warning', 'invalid Subscription-Reference, try to fix it', 0); $Url = parse_url($SubscriptionReference); - $Url['host'] = parse_url($this->ReadPropertyString('Address'), PHP_URL_HOST); - $Url['port'] = parse_url($this->ReadPropertyString('Address'), PHP_URL_PORT); + $Url['host'] = parse_url($this->ReadPropertyString(\ONVIF\IO\Property::Address), PHP_URL_HOST); + $Url['port'] = parse_url($this->ReadPropertyString(\ONVIF\IO\Property::Address), PHP_URL_PORT); $SubscriptionReference = self::unparse_url($Url); } - $this->WriteAttributeString('SubscriptionReference', $SubscriptionReference); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionReference, $SubscriptionReference); $this->UpdateFormField('SubscriptionReference', 'caption', $SubscriptionReference); $this->UpdateFormField('SubscriptionReferenceRow', 'visible', true); if (property_exists($SubscribeResult->SubscriptionReference, 'ReferenceParameters')) { $SubscriptionId = property_exists($SubscribeResult->SubscriptionReference->ReferenceParameters, 'any') ? $SubscribeResult->SubscriptionReference->ReferenceParameters->any : ''; $this->SendDebug('SubscriptionId', $SubscriptionId, 0); - $this->WriteAttributeString('SubscriptionId', $SubscriptionId); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionId, $SubscriptionId); } else { - $this->WriteAttributeString('SubscriptionId', ''); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionId, ''); } $this->isSubscribed = true; $this->usedEventHandler = new \ONVIF\EventHandler(\ONVIF\EventHandler::Subscribe); $this->SetRenewInterval($SubscribeResult); $this->SetSynchronizationPoint(); - $this->unlock('EventHandler'); - $EventTimeout = $this->ReadPropertyInteger('SubscribeEventTimeout') * 1000; + $this->unlock(\ONVIF\IO\Property::EventHandler); + $EventTimeout = $this->ReadPropertyInteger(\ONVIF\IO\Property::SubscribeEventTimeout) * 1000; if ($EventTimeout) { for ($i = 0; $i < $EventTimeout; $i = $i + 50) { if (!$this->WaitForFirstEvent) { @@ -1107,7 +1118,7 @@ protected function Subscribe(): bool $this->UpdateFormField('DeviceDataPanel', 'visible', true); $this->UpdateFormField('DeviceDataPanel', 'expanded', true); $this->UpdateFormField('Events', 'visible', true); - $this->LogMessage($this->Translate('Interface connected'), KL_MESSAGE); + $this->LogMessage($this->Translate(\ONVIF\IO\State::ACTIVE), KL_MESSAGE); $this->SetStatus(IS_ACTIVE); return true; } @@ -1119,7 +1130,7 @@ protected function Subscribe(): bool $this->UpdateFormField('DeviceDataPanel', 'visible', true); $this->UpdateFormField('DeviceDataPanel', 'expanded', true); $this->UpdateFormField('Events', 'visible', true); - $this->LogMessage($this->Translate('Interface connected'), KL_MESSAGE); + $this->LogMessage($this->Translate(\ONVIF\IO\State::ACTIVE), KL_MESSAGE); $this->SetStatus(IS_ACTIVE); return true; } @@ -1127,13 +1138,13 @@ protected function Subscribe(): bool $this->WaitForFirstEvent = false; if ($AllowedEventHandler == \ONVIF\EventHandler::Subscribe) { // nur Subscribe erlaubt $this->SetStatus(IS_EBASE + 4); - $this->LogMessage($this->Translate('Connection lost'), KL_ERROR); + $this->LogMessage($this->Translate(\ONVIF\IO\State::CONNECTION_LOST), KL_ERROR); } return false; } protected function SetSynchronizationPoint(): bool { - $SubscriptionReference = $this->ReadAttributeString('SubscriptionReference'); + $SubscriptionReference = $this->ReadAttributeString(\ONVIF\IO\Attribute::SubscriptionReference); if ($SubscriptionReference == '') { $this->SendDebug('ERROR SetSynchronizationPoint', 'No SubscriptionReference', 0); $this->LogMessage($this->Translate('Call SetSynchronizationPoint with no SubscriptionReference'), KL_ERROR); @@ -1141,7 +1152,7 @@ protected function SetSynchronizationPoint(): bool } $Action = 'http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/SetSynchronizationPointRequest'; $Header = $this->GenerateSOAPHeader($Action, $SubscriptionReference); - $SubscriptionId = $this->ReadAttributeString('SubscriptionId'); + $SubscriptionId = $this->ReadAttributeString(\ONVIF\IO\Attribute::SubscriptionId); if ($SubscriptionId != '') { $xml = new DOMDocument(); $xml->loadXML($SubscriptionId); @@ -1160,21 +1171,21 @@ protected function SetSynchronizationPoint(): bool } protected function Renew(): bool { - $this->SetTimerInterval('RenewSubscription', 0); + $this->SetTimerInterval(\ONVIF\IO\Timer::RenewSubscription, 0); if (!$this->isSubscribed) { return true; } - $this->lock('EventHandler'); - $SubscriptionReference = $this->ReadAttributeString('SubscriptionReference'); + $this->lock(\ONVIF\IO\Property::EventHandler); + $SubscriptionReference = $this->ReadAttributeString(\ONVIF\IO\Attribute::SubscriptionReference); if ($SubscriptionReference == '') { $this->SendDebug('ERROR Renew', 'No SubscriptionReference', 0); $this->LogMessage($this->Translate('Call Renew with no SubscriptionReference'), KL_ERROR); - $this->unlock('EventHandler'); + $this->unlock(\ONVIF\IO\Property::EventHandler); return false; } $Action = 'http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/RenewRequest'; $Header = $this->GenerateSOAPHeader($Action, $SubscriptionReference); - $SubscriptionId = $this->ReadAttributeString('SubscriptionId'); + $SubscriptionId = $this->ReadAttributeString(\ONVIF\IO\Attribute::SubscriptionId); if ($SubscriptionId != '') { $xml = new DOMDocument(); $xml->loadXML($SubscriptionId); @@ -1192,7 +1203,7 @@ protected function Renew(): bool $this->LogMessage($this->Translate('Error Renew Subscription with:') . $RenewResult->getMessage(), KL_ERROR); $this->SetStatus(IS_EBASE + 3); $this->isSubscribed = false; - $this->unlock('EventHandler'); + $this->unlock(\ONVIF\IO\Property::EventHandler); return false; } if (!is_object($RenewResult)) { @@ -1200,11 +1211,11 @@ protected function Renew(): bool $this->LogMessage($this->Translate('Error Renew with no Response'), KL_ERROR); $this->SetStatus(IS_EBASE + 3); $this->isSubscribed = false; - $this->unlock('EventHandler'); + $this->unlock(\ONVIF\IO\Property::EventHandler); return false; } $this->SetRenewInterval($RenewResult); - $this->unlock('EventHandler'); + $this->unlock(\ONVIF\IO\Property::EventHandler); return true; } protected function Unsubscribe(): bool @@ -1213,19 +1224,19 @@ protected function Unsubscribe(): bool if (!$this->isSubscribed) { return true; } - $this->lock('EventHandler'); - $this->SetTimerInterval('RenewSubscription', 0); + $this->lock(\ONVIF\IO\Property::EventHandler); + $this->SetTimerInterval(\ONVIF\IO\Timer::RenewSubscription, 0); $this->isSubscribed = false; $this->UpdateFormField('SubscriptionReference', 'caption', ''); $this->UpdateFormField('SubscriptionReferenceRow', 'visible', false); - $SubscriptionReference = $this->ReadAttributeString('SubscriptionReference'); - $this->WriteAttributeString('SubscriptionReference', ''); - $SubscriptionId = $this->ReadAttributeString('SubscriptionId'); - $this->WriteAttributeString('SubscriptionId', ''); + $SubscriptionReference = $this->ReadAttributeString(\ONVIF\IO\Attribute::SubscriptionReference); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionReference, ''); + $SubscriptionId = $this->ReadAttributeString(\ONVIF\IO\Attribute::SubscriptionId); + $this->WriteAttributeString(\ONVIF\IO\Attribute::SubscriptionId, ''); if ($SubscriptionReference == '') { $this->SendDebug('ERROR Unsubscribe', 'No SubscriptionReference', 0); $this->LogMessage($this->Translate('Call Unsubscribe with no SubscriptionReference'), KL_ERROR); - $this->unlock('EventHandler'); + $this->unlock(\ONVIF\IO\Property::EventHandler); return false; } $Action = 'http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/UnsubscribeRequest'; @@ -1243,12 +1254,12 @@ protected function Unsubscribe(): bool /** @var SoapFault $UnsubscribeResult */ trigger_error($UnsubscribeResult->getMessage(), E_USER_NOTICE); } - $this->unlock('EventHandler'); + $this->unlock(\ONVIF\IO\Property::EventHandler); return true; } protected function GetEventProperties() { - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); if ($XAddr[\ONVIF\NS::Event] == '') { return false; } @@ -1286,7 +1297,7 @@ protected function GetEventProperties() protected function GetProfiles2(string $Token = null, string $ConfigurationEnumeration = \ONVIF\Media2Conf::All): bool { - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); $Params['Type'] = $ConfigurationEnumeration; if ($Token) { $Params['Token'] = $Token; @@ -1335,8 +1346,8 @@ protected function GetProfiles2(string $Token = null, string $ConfigurationEnume } $H264VideoSources = array_values($H264VideoSourcesItems); $this->SendDebug('VideoSources H.26x', $H264VideoSources, 0); - $this->WriteAttributeArray('VideoSources', $H264VideoSources); - $JPEGProfiles = array_filter($Profiles, function ($Profile) + $this->WriteAttributeArray(\ONVIF\IO\Attribute::VideoSources, $H264VideoSources); + $JPEGProfiles = array_filter($Profiles, function (array $Profile) { if (isset($Profile['Configurations']['VideoEncoder']['Encoding'])) { if (strtoupper($Profile['Configurations']['VideoEncoder']['Encoding']) == 'JPEG') { @@ -1369,7 +1380,7 @@ protected function GetProfiles2(string $Token = null, string $ConfigurationEnume } $JPEGVideoSources = array_values($JPEGVideoSourcesItems); $this->SendDebug('VideoSources JPEG', $JPEGVideoSources, 0); - $this->WriteAttributeArray('VideoSourcesJPEG', $JPEGVideoSources); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::VideoSourcesJPEG, $JPEGVideoSources); $AnalyticsTokens = []; $AnalyticsProfiles = array_filter($Profiles, function ($Profile) { @@ -1383,12 +1394,12 @@ protected function GetProfiles2(string $Token = null, string $ConfigurationEnume $AnalyticsTokens[$Token] = $Name; } $this->SendDebug('AnalyticsTokens', $AnalyticsTokens, 0); - $this->WriteAttributeArray('AnalyticsTokens', $AnalyticsTokens); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::AnalyticsTokens, $AnalyticsTokens); return true; } protected function GetProfiles(): bool { - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); $ProfileResult = $this->SendData($XAddr[\ONVIF\NS::Media], \ONVIF\WSDL::Media, 'GetProfiles', true); if (is_a($ProfileResult, 'SoapFault')) { $this->LogMessage($this->lastSOAPError, KL_ERROR); @@ -1433,7 +1444,7 @@ protected function GetProfiles(): bool } $H264VideoSources = array_values($H264VideoSourcesItems); $this->SendDebug('VideoSources H.26x', $H264VideoSources, 0); - $this->WriteAttributeArray('VideoSources', $H264VideoSources); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::VideoSources, $H264VideoSources); $JPEGProfiles = array_filter($Profiles, function ($Profile) { @@ -1464,7 +1475,7 @@ protected function GetProfiles(): bool } $JPEGVideoSources = array_values($JPEGVideoSourcesItems); $this->SendDebug('VideoSources JPEG', $JPEGVideoSources, 0); - $this->WriteAttributeArray('VideoSourcesJPEG', $JPEGVideoSources); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::VideoSourcesJPEG, $JPEGVideoSources); $AnalyticsTokens = []; $AnalyticsProfiles = array_filter($Profiles, function ($Profile) { @@ -1478,7 +1489,7 @@ protected function GetProfiles(): bool $AnalyticsTokens[$Token] = $Name; } $this->SendDebug('AnalyticsTokens', $AnalyticsTokens, 0); - $this->WriteAttributeArray('AnalyticsTokens', $AnalyticsTokens); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::AnalyticsTokens, $AnalyticsTokens); return true; } protected function GetCapabilities(): bool @@ -1567,17 +1578,17 @@ protected function GetCapabilities(): bool } } } - $this->WriteAttributeArray('XAddr', $XAddr); - $this->WriteAttributeBoolean('AnalyticsModuleSupport', $AnalyticsModuleSupport); - $this->WriteAttributeBoolean('RuleSupport', $RuleSupport); - $this->WriteAttributeBoolean('WSSubscriptionPolicySupport', $WSSubscriptionPolicySupport); - $this->WriteAttributeBoolean('WSPullPointSupport', $WSPullPointSupport); - $this->WriteAttributeBoolean('HasSnapshotUri', false); - $this->WriteAttributeBoolean('HasRTSPStreaming', $HasRTSPStreaming); - $this->WriteAttributeInteger('NbrOfVideoSources', $NbrOfVideoSources); - $this->WriteAttributeInteger('NbrOfAudioSources', $NbrOfAudioSources); - $this->WriteAttributeInteger('NbrOfInputs', $NbrOfInputs); - $this->WriteAttributeInteger('NbrOfOutputs', $NbrOfOutputs); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::XAddr, $XAddr); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::AnalyticsModuleSupport, $AnalyticsModuleSupport); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::RuleSupport, $RuleSupport); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::WSSubscriptionPolicySupport, $WSSubscriptionPolicySupport); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::WSPullPointSupport, $WSPullPointSupport); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::HasSnapshotUri, false); + $this->WriteAttributeBoolean(\ONVIF\IO\Attribute::HasRTSPStreaming, $HasRTSPStreaming); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::NbrOfVideoSources, $NbrOfVideoSources); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::NbrOfAudioSources, $NbrOfAudioSources); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::NbrOfInputs, $NbrOfInputs); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::NbrOfOutputs, $NbrOfOutputs); return !is_a($Result, 'SoapFault'); } protected function GetScopes() @@ -1598,7 +1609,7 @@ protected function GetScopes() } protected function GetNodes() { - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); $Nodes = $this->SendData($XAddr[\ONVIF\NS::PTZ], \ONVIF\WSDL::PTZ, 'GetNodes', true); if (is_a($Nodes, 'SoapFault')) { return false; @@ -1627,7 +1638,7 @@ protected function GetAudioSources($Uri, $WSDL) protected function GetSupportedAnalyticsModules(string $AnalyticsToken) { - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); $Params = [ 'ConfigurationToken' => $AnalyticsToken ]; @@ -1640,7 +1651,7 @@ protected function GetSupportedAnalyticsModules(string $AnalyticsToken) } protected function GetSupportedRules(string $AnalyticsToken) { - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); $Params = [ 'ConfigurationToken' => $AnalyticsToken ]; @@ -1685,7 +1696,7 @@ protected function GetServices(): bool return false; } $ServicesResult = json_decode(json_encode($Services), true); - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); /*$XAddr = [ \ONVIF\NS::Management => '/onvif/device_service', \ONVIF\NS::Event => '', @@ -1701,7 +1712,7 @@ protected function GetServices(): bool foreach ($ServicesResult['Service'] as $Service) { $XAddr[$Service['Namespace']] = parse_url($Service['XAddr'], PHP_URL_PATH); } - $this->WriteAttributeArray('XAddr', $XAddr); + $this->WriteAttributeArray(\ONVIF\IO\Attribute::XAddr, $XAddr); return true; } protected function GetServiceCapabilities($Uri, $WSDL) @@ -1754,7 +1765,7 @@ protected function GetDigitalInputs($Uri, $WSDL) } protected function GetDigitalInputConfigurationOptions(string $Token): array { - $XAddr = $this->ReadAttributeArray('XAddr'); + $XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr); $Params['Token'] = $Token; $DigitalInputConfigurationOptionsResponse = $this->SendData($XAddr[\ONVIF\NS::DeviceIO], \ONVIF\WSDL::DeviceIO, 'GetDigitalInputConfigurationOptions', true, $Params); if (is_a($DigitalInputConfigurationOptionsResponse, 'SoapFault')) { @@ -1803,7 +1814,7 @@ protected function GetSystemDateAndTime(): bool { $camera_datetime = $this->SendData('', \ONVIF\WSDL::Management, 'GetSystemDateAndTime'); if (is_a($camera_datetime, 'SoapFault')) { - $this->WriteAttributeInteger('Timestamp_Offset', 0); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::Timestamp_Offset, 0); return false; } if (property_exists($camera_datetime->SystemDateAndTime, 'UTCDateTime')) { @@ -1815,7 +1826,7 @@ protected function GetSystemDateAndTime(): bool $camera_datetime->SystemDateAndTime->UTCDateTime->Date->Day, $camera_datetime->SystemDateAndTime->UTCDateTime->Date->Year ); - $this->WriteAttributeInteger('Timestamp_Offset', time() - $camera_ts); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::Timestamp_Offset, time() - $camera_ts); $this->SendDebug('TimeDiff', time() - $camera_ts, 0); return true; } @@ -1828,7 +1839,7 @@ protected function GetSystemDateAndTime(): bool $camera_datetime->SystemDateAndTime->LocalDateTime->Date->Day, $camera_datetime->SystemDateAndTime->LocalDateTime->Date->Year ); - $this->WriteAttributeInteger('Timestamp_Offset', time() - $camera_ts); + $this->WriteAttributeInteger(\ONVIF\IO\Attribute::Timestamp_Offset, time() - $camera_ts); $this->SendDebug('TimeDiff', time() - $camera_ts, 0); return true; } @@ -1859,11 +1870,11 @@ protected function SendData(string $URI, string $wsdl, string $Function, bool $U $wsdl = dirname(__DIR__) . '/libs/WSDL/' . $wsdl; if ($UseLogin) { if ($this->Profile->HasProfile(\ONVIF\Profile::S) || ($Function == 'GetScopes')) { // Nur Profile S Geräte können WSSecurity - if ($this->ReadPropertyString('Password') != '') { - $Header[] = \ONVIF\ONVIF::soapClientWSSecurityHeader($this->ReadPropertyString('Username'), $this->ReadPropertyString('Password'), $this->ReadAttributeInteger('Timestamp_Offset')); + if ($this->ReadPropertyString(\ONVIF\IO\Property::Password) != '') { + $Header[] = \ONVIF\ONVIF::soapClientWSSecurityHeader($this->ReadPropertyString(\ONVIF\IO\Property::Username), $this->ReadPropertyString(\ONVIF\IO\Property::Password), $this->ReadAttributeInteger(\ONVIF\IO\Attribute::Timestamp_Offset)); } } - $ONVIFClient = new \ONVIF\ONVIF($wsdl, $URI, $this->ReadPropertyString('Username'), $this->ReadPropertyString('Password'), $Header, $Timeout); + $ONVIFClient = new \ONVIF\ONVIF($wsdl, $URI, $this->ReadPropertyString(\ONVIF\IO\Property::Username), $this->ReadPropertyString(\ONVIF\IO\Property::Password), $Header, $Timeout); } else { $ONVIFClient = new \ONVIF\ONVIF($wsdl, $URI, null, null, $Header, $Timeout); } @@ -1887,7 +1898,7 @@ protected function SendData(string $URI, string $wsdl, string $Function, bool $U $this->SendDebug('Soap Response Headers Error', $ONVIFClient->client->__getLastResponseHeaders(), 0); $this->SendDebug('Soap Response Error', $Response, 0); $this->SendDebug('Soap Response Error (' . $e->getCode() . ')', $e->getMessage(), 0); - $this->lastSOAPError = $e->getMessage(); + $this->lastSOAPError = $Function . ': ' . $e->getMessage(); unset($ONVIFClient); return $e; } @@ -1897,7 +1908,7 @@ protected function SendData(string $URI, string $wsdl, string $Function, bool $U protected function GetEventReceiverFormValues(): array { $EventList = []; - $Events = $this->ReadAttributeArray('EventProperties'); + $Events = $this->ReadAttributeArray(\ONVIF\IO\Attribute::EventProperties); foreach ($Events as $Topic => $MessageDescription) { $Receivers = []; foreach ($MessageDescription['Receivers'] as $Receiver) { @@ -1922,7 +1933,7 @@ protected function GetEventReceiverFormValues(): array } protected function ProcessHookData() { - if (($this->ReadPropertyBoolean('Open') == false) || ($this->GetTimerInterval('RenewSubscription') == 0)) { + if (($this->ReadPropertyBoolean(\ONVIF\IO\Property::Active) == false) || ($this->GetTimerInterval(\ONVIF\IO\Timer::RenewSubscription) == 0)) { http_response_code(404); header('Connection: close'); header('Server: Symcon ' . IPS_GetKernelVersion()); @@ -1990,14 +2001,14 @@ protected function DecodeNotificationMessage(string $NotificationMessageXML): bo protected function SendEventDataArrayToChildren(array $EventDataArray): void { foreach ($EventDataArray as $EventData) { - $EventData['DataID'] = '{E23DD2CD-F098-268A-CE49-1CC04FE8060B}'; + $EventData['DataID'] = \ONVIF\DataFlow\GUID::SendEvents; $this->SendDataToChildren(json_encode($EventData)); } } protected function KernelReady(): void { $this->RegisterMessage($this->InstanceID, FM_CHILDREMOVED); - $Url = parse_url($this->ReadPropertyString('Address')); + $Url = parse_url($this->ReadPropertyString(\ONVIF\IO\Property::Address)); $Url['port'] = (isset($Url['port']) ? ':' . $Url['port'] : ''); if (isset($Url['scheme']) && isset($Url['host'])) { $this->Host = $Url['scheme'] . '://' . $Url['host'] . $Url['port']; @@ -2083,6 +2094,6 @@ private function SetRenewInterval(object $Result): void } $this->SendDebug('TerminationTime', $this->TerminationTime, 0); $this->SendDebug('Renew Interval', $Interval - 5, 0); - $this->SetTimerInterval('RenewSubscription', ($Interval - 5) * 1000); + $this->SetTimerInterval(\ONVIF\IO\Timer::RenewSubscription, ($Interval - 5) * 1000); } } diff --git a/ONVIF Image Grabber/module.php b/ONVIF Image Grabber/module.php index 96dad57..a588913 100644 --- a/ONVIF Image Grabber/module.php +++ b/ONVIF Image Grabber/module.php @@ -8,18 +8,18 @@ */ class ONVIFImageGrabber extends ONVIFModuleBase { - const wsdl = \ONVIF\WSDL::Media; //'media-mod'; - const TopicFilter = 'videosource'; + public const wsdl = \ONVIF\WSDL::Media; //'media-mod'; + public const TopicFilter = 'videosource'; public function Create() { //Never delete this line! parent::Create(); - $this->RegisterPropertyString('VideoSource', ''); - $this->RegisterPropertyString('Profile', ''); - $this->RegisterPropertyInteger('Interval', 0); - $this->RegisterPropertyBoolean('UseCaching', true); - $this->RegisterTimer('UpdateImage', 0, 'ONVIF_UpdateImage(' . $this->InstanceID . ');'); + $this->RegisterPropertyString(\ONVIF\ImageGrabber\Property::VideoSource, ''); + $this->RegisterPropertyString(\ONVIF\ImageGrabber\Property::Profile, ''); + $this->RegisterPropertyInteger(\ONVIF\ImageGrabber\Property::Interval, 0); + $this->RegisterPropertyBoolean(\ONVIF\ImageGrabber\Property::UseCaching, true); + $this->RegisterTimer(\ONVIF\ImageGrabber\Timer::UpdateImage, 0, 'ONVIF_UpdateImage(' . $this->InstanceID . ');'); $this->ImageURL = false; } public function ApplyChanges() @@ -27,16 +27,16 @@ public function ApplyChanges() //Never delete this line! parent::ApplyChanges(); $MediaId = $this->GetMediaId(); - IPS_SetMediaCached($MediaId, $this->ReadPropertyBoolean('UseCaching')); + IPS_SetMediaCached($MediaId, $this->ReadPropertyBoolean(\ONVIF\ImageGrabber\Property::UseCaching)); - if ($this->ReadPropertyString('VideoSource') == '') { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == '') { $this->SetStatus(IS_INACTIVE); - $this->SetTimerInterval('UpdateImage', 0); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); return; } - if ($this->ReadPropertyString('Profile') == '') { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) == '') { $this->SetStatus(IS_INACTIVE); - $this->SetTimerInterval('UpdateImage', 0); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); return; } if (IPS_GetKernelRunlevel() != KR_READY) { @@ -47,9 +47,9 @@ public function ApplyChanges() if ($SnapshotURL) { $this->SetStatus(IS_ACTIVE); $this->UpdateImage(); - $this->SetTimerInterval('UpdateImage', $this->ReadPropertyInteger('Interval') * 1000); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, $this->ReadPropertyInteger(\ONVIF\ImageGrabber\Property::Interval) * 1000); } else { - $this->SetTimerInterval('UpdateImage', 0); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); $this->SetStatus(IS_EBASE + 1); } } @@ -92,7 +92,7 @@ public function ReceiveData($JSONString) $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $EventProperties = $this->ReadAttributeArray('EventProperties'); + $EventProperties = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (!array_key_exists($Data['Topic'], $EventProperties)) { return false; } @@ -111,7 +111,7 @@ public function ReceiveData($JSONString) if ($EventProperty['Sources'][$SourceIndex]['Type'] != 'tt:ReferenceToken') { continue; } - if ($Source['Value'] != $this->ReadPropertyString('VideoSource')) { + if ($Source['Value'] != $this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource)) { $SkipEvent = true; continue; } @@ -124,7 +124,7 @@ public function ReceiveData($JSONString) if ($SkipEvent) { return false; } - $PreName = str_replace($this->ReadPropertyString('EventTopic'), '', $Data['Topic']); + $PreName = str_replace($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic), '', $Data['Topic']); return $this->SetEventStatusVariable($PreName, $EventProperties[$Data['Topic']], $Data); } @@ -176,14 +176,14 @@ public function GetConfigurationForm() 'caption' => $VideoSource['VideoSourceName'], 'value' => $VideoSource['VideoSourceToken'] ]; - if ($this->ReadPropertyString('VideoSource') == $VideoSource['VideoSourceToken']) { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == $VideoSource['VideoSourceToken']) { $ActualSources = $VideoSource; foreach ($VideoSource['Profile'] as $Profile) { $ProfileOptions[] = [ 'caption' => $Profile['Name'], 'value' => $Profile['token'] ]; - if ($this->ReadPropertyString('Profile') == $Profile['token']) { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) == $Profile['token']) { $ActualProfile = $Profile; } } @@ -334,7 +334,7 @@ public function RequestAction($Ident, $Value) case 'RefreshProfileForm': $this->RefreshProfileForm($Value); return true; - case 'UpdateImage': + case \ONVIF\ImageGrabber\Timer::UpdateImage: $this->UpdateImage(); if ((bool) $Value) { $this->ReloadForm(); @@ -347,7 +347,7 @@ protected function IOChangeState($State) parent::IOChangeState($State); if ($State == IS_INACTIVE) { - $this->SetTimerInterval('UpdateImage', 0); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); } } protected function RefreshProfileForm($NewVideoSource) @@ -381,9 +381,9 @@ protected function GetSnapshotUri() return false; } foreach ($Capabilities['VideoSourcesJPEG'] as $VideoSource) { - if ($this->ReadPropertyString('VideoSource') == $VideoSource['VideoSourceToken']) { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == $VideoSource['VideoSourceToken']) { foreach ($VideoSource['Profile'] as $Profile) { - if ($Profile['token'] == $this->ReadPropertyString('Profile')) { + if ($Profile['token'] == $this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile)) { break; } } @@ -391,7 +391,7 @@ protected function GetSnapshotUri() } } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile') + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) ]; if (($Capabilities['XAddr'][\ONVIF\NS::Media2]) != '') { diff --git a/ONVIF Media Stream/module.php b/ONVIF Media Stream/module.php index da930fa..cb46191 100644 --- a/ONVIF Media Stream/module.php +++ b/ONVIF Media Stream/module.php @@ -17,44 +17,44 @@ class ONVIFMediaStream extends ONVIFModuleBase { use \ONVIFMediaStream\WebhookHelper; - const wsdl = \ONVIF\WSDL::Media; // default für Media1 - const PTZwsdl = \ONVIF\WSDL::PTZ; // statisch - const TopicFilter = 'videosource'; + public const wsdl = \ONVIF\WSDL::Media; // default für Media1 + public const PTZwsdl = \ONVIF\WSDL::PTZ; // statisch + public const TopicFilter = 'videosource'; public function Create() { //Never delete this line! parent::Create(); //Stream - $this->RegisterPropertyString('VideoSource', ''); - $this->RegisterPropertyString('Profile', ''); + $this->RegisterPropertyString(\ONVIF\Stream\Property::VideoSource, ''); + $this->RegisterPropertyString(\ONVIF\Stream\Property::Profile, ''); // Invert Controls - $this->RegisterPropertyBoolean('InvertPanControl', false); - $this->RegisterPropertyBoolean('InvertTiltControl', false); - $this->RegisterPropertyBoolean('InvertZoomControl', false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::InvertPanControl, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::InvertTiltControl, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::InvertZoomControl, false); //IPS Variables - $this->RegisterPropertyBoolean('EnablePanTiltVariable', false); - $this->RegisterPropertyBoolean('EnableZoomVariable', false); - $this->RegisterPropertyBoolean('EnableSpeedVariable', false); - $this->RegisterPropertyBoolean('EnableTimeVariable', false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltVariable, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnableZoomVariable, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnableSpeedVariable, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnableTimeVariable, false); //HTML-Box - $this->RegisterPropertyBoolean('EnablePanTiltHTML', false); - $this->RegisterPropertyBoolean('EnableZoomHTML', false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltHTML, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnableZoomHTML, false); //SVG-Design in HTML-Box - $this->RegisterPropertyInteger('PanTiltControlWidth', 100); - $this->RegisterPropertyInteger('PanTiltControlHeight', 100); - $this->RegisterPropertyInteger('PanTiltControlOpacity', 60); - $this->RegisterPropertyInteger('ZoomControlWidth', 50); - $this->RegisterPropertyInteger('ZoomControlHeight', 100); - $this->RegisterPropertyInteger('ZoomControlOpacity', 60); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::PanTiltControlWidth, 100); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::PanTiltControlHeight, 100); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::PanTiltControlOpacity, 60); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::ZoomControlWidth, 50); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::ZoomControlHeight, 100); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::ZoomControlOpacity, 60); //Default Speed - $this->RegisterPropertyFloat('PanDefaultSpeed', 1); - $this->RegisterPropertyFloat('TiltDefaultSpeed', 1); - $this->RegisterPropertyFloat('ZoomDefaultSpeed', 1); + $this->RegisterPropertyFloat(\ONVIF\Stream\Property::PanDefaultSpeed, 1); + $this->RegisterPropertyFloat(\ONVIF\Stream\Property::TiltDefaultSpeed, 1); + $this->RegisterPropertyFloat(\ONVIF\Stream\Property::ZoomDefaultSpeed, 1); // Presets - $this->RegisterPropertyBoolean('EnablePresetVariable', false); - $this->RegisterPropertyBoolean('EnablePresetProfile', false); - $this->RegisterPropertyString('PresetProfile', json_encode([])); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnablePresetVariable, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnablePresetProfile, false); + $this->RegisterPropertyString(\ONVIF\Stream\Property::PresetProfile, json_encode([])); // Buffer $this->PTZ_token = ''; $this->PTZ_xAddr = ''; @@ -140,12 +140,12 @@ public function ApplyChanges() $this->PresetTokenList = []; $this->AuthorizationKey = ''; - if ($this->ReadPropertyString('VideoSource') == '') { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource) == '') { $this->SetStatus(IS_INACTIVE); $this->SetMedia(''); return; } - if ($this->ReadPropertyString('Profile') == '') { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::Profile) == '') { $this->SetStatus(IS_INACTIVE); $this->SetMedia(''); return; @@ -163,35 +163,35 @@ public function ApplyChanges() $this->SetStatus(IS_EBASE + 1); } - if ($this->ReadPropertyBoolean('EnablePanTiltHTML') || $this->ReadPropertyBoolean('EnableZoomHTML')) { + 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('EnablePanTiltVariable')) { + 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('EnableZoomVariable')) { + 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('EnableSpeedVariable')) { + 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('EnableTimeVariable')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableTimeVariable)) { $this->RegisterVariableFloat('TIME', $this->Translate('Time'), 'ONVIF.Time', 2); $this->SetValueFloat('TIME', 0); $this->EnableAction('TIME'); @@ -199,9 +199,9 @@ public function ApplyChanges() $this->UnregisterVariable('TIME'); } $PresetProfileName = 'ONVIF.Preset.' . $this->InstanceID; - if ($this->ReadPropertyBoolean('EnablePresetVariable')) { - $UsePresetName = $this->ReadPropertyBoolean('EnablePresetProfile'); - $Presets = json_decode($this->ReadPropertyString('PresetProfile')); + 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) { @@ -274,14 +274,14 @@ public function GetConfigurationForm() 'caption' => $VideoSource['VideoSourceName'], 'value' => $VideoSource['VideoSourceToken'] ]; - if ($this->ReadPropertyString('VideoSource') == $VideoSource['VideoSourceToken']) { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource) == $VideoSource['VideoSourceToken']) { $ActualSources = $VideoSource; foreach ($VideoSource['Profile'] as $Profile) { $ProfileOptions[] = [ 'caption' => $Profile['Name'], 'value' => $Profile['token'] ]; - if ($this->ReadPropertyString('Profile') == $Profile['token']) { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::Profile) == $Profile['token']) { $ActualProfile = $Profile; } } @@ -564,8 +564,8 @@ public function GetConfigurationForm() ]; $Form['actions'] = array_merge($Actions, $Form['actions']); } - $Form['elements'][4]['popup']['items'][1]['visible'] = $this->ReadPropertyBoolean('EnablePresetVariable'); - $PresetProfile = json_decode($this->ReadPropertyString('PresetProfile'), true); + $Form['elements'][4]['popup']['items'][1]['visible'] = $this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePresetVariable); + $PresetProfile = json_decode($this->ReadPropertyString(\ONVIF\Stream\Property::PresetProfile), true); $ValidTokens = array_column($PTZValues, 'PresetToken'); foreach ($PresetProfile as &$Profile) { $KnownToken = array_search($Profile['PresetToken'], $ValidTokens); @@ -614,13 +614,13 @@ public function MoveLeftSpeedTime(float $Speed, float $Time) return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('PanDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::PanDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'PanTilt' => [ - 'x' => (!$this->ReadPropertyBoolean('InvertPanControl') ? $Speed : -$Speed), + 'x' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertPanControl) ? $Speed : -$Speed), 'y' => 0 ] ] @@ -648,13 +648,13 @@ public function MoveRightSpeedTime(float $Speed, float $Time) return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('PanDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::PanDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'PanTilt' => [ - 'x' => (!$this->ReadPropertyBoolean('InvertPanControl') ? -$Speed : $Speed), + 'x' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertPanControl) ? -$Speed : $Speed), 'y' => 0 ] ] @@ -683,14 +683,14 @@ public function MoveUpSpeedTime(float $Speed, float $Time) return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('TiltDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::TiltDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'PanTilt' => [ 'x' => 0, - 'y' => (!$this->ReadPropertyBoolean('InvertTiltControl') ? $Speed : -$Speed) + 'y' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertTiltControl) ? $Speed : -$Speed) ] ] ]; @@ -719,14 +719,14 @@ public function MoveDownSpeedTime(float $Speed, float $Time) return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('TiltDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::TiltDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'PanTilt' => [ 'x' => 0, - 'y' => (!$this->ReadPropertyBoolean('InvertTiltControl') ? -$Speed : $Speed) + 'y' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertTiltControl) ? -$Speed : $Speed) ] ] ]; @@ -753,13 +753,13 @@ public function ZoomNearSpeedTime(float $Speed, float $Time) return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('ZoomDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::ZoomDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'Zoom' => [ - 'x' => (!$this->ReadPropertyBoolean('InvertZoomControl') ? $Speed : -$Speed) + 'x' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertZoomControl) ? $Speed : -$Speed) ] ] ]; @@ -786,13 +786,13 @@ public function ZoomFarSpeedTime(float $Speed, float $Time) return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('ZoomDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::ZoomDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'Zoom' => [ - 'x' => (!$this->ReadPropertyBoolean('InvertZoomControl') ? -$Speed : $Speed) + 'x' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertZoomControl) ? -$Speed : $Speed) ] ] ]; @@ -806,7 +806,7 @@ public function StopPTZ() if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile'), 'PanTilt' => true, 'Zoom' => true]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'PanTilt' => true, 'Zoom' => true]; return $this->SendData($this->PTZ_xAddr, 'Stop', true, $Params, self::PTZwsdl); } @@ -815,7 +815,7 @@ public function MoveStop() if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile'), 'PanTilt' => true]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'PanTilt' => true]; return $this->SendData($this->PTZ_xAddr, 'Stop', true, $Params, self::PTZwsdl); } @@ -824,7 +824,7 @@ public function ZoomStop() if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile'), 'Zoom' => true]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Zoom' => true]; return $this->SendData($this->PTZ_xAddr, 'Stop', true, $Params, self::PTZwsdl); } @@ -846,7 +846,7 @@ public function GotoPresetToken(string $PresetToken) if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile'), 'PresetToken' => $PresetToken]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'PresetToken' => $PresetToken]; return $this->SendData($this->PTZ_xAddr, 'GotoPreset', true, $Params, self::PTZwsdl); } @@ -855,7 +855,7 @@ public function GotoPresetHomePosition() if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile')]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile)]; return $this->SendData($this->PTZ_xAddr, 'GotoHomePosition', true, $Params, self::PTZwsdl); } @@ -881,69 +881,67 @@ public function RequestAction($Ident, $Value) $Time = $this->GetValue('TIME'); } switch ($Ident) { - case 'PRESET': - if ($this->GotoPreset($Value)) { - $this->SetValue('PRESET', $Value); + case 'PRESET': + if ($this->GotoPreset($Value)) { + $this->SetValue('PRESET', $Value); + return true; + } + return false; + case 'TIME': + case 'SPEED': + $this->SetValueFloat($Ident, $Value); return true; - } - return false; - case 'TIME': - case 'SPEED': - $this->SetValueFloat($Ident, $Value); - return true; - case 'PT': - $Result = false; - switch ($Value) { - case 0: - $Result = $this->MoveLeftSpeedTime($Speed, $Time); - break; - case 1: - $Result = $this->MoveUpSpeedTime($Speed, $Time); - break; - case 2: - $Result = $this->MoveStop(); - break; - case 3: - $Result = $this->MoveDownSpeedTime($Speed, $Time); - break; - case 4: - $Result = $this->MoveRightSpeedTime($Speed, $Time); - break; - default: - set_error_handler([$this, 'ModulErrorHandler']); - trigger_error($this->Translate('Invalid Value.'), E_USER_NOTICE); - restore_error_handler(); - return false; - - } - if ($Result) { - $this->SetValueInteger('PT', $Value); - } - return $Result; - case 'ZOOM': - $Result = false; - switch ($Value) { - case 0: - $Result = $this->ZoomFarSpeedTime($Speed, $Time); - break; - case 1: - $Result = $this->ZoomStop(); - break; - case 2: - $Result = $this->ZoomNearSpeedTime($Speed, $Time); - break; + case 'PT': + $Result = false; + switch ($Value) { + case 0: + $Result = $this->MoveLeftSpeedTime($Speed, $Time); + break; + case 1: + $Result = $this->MoveUpSpeedTime($Speed, $Time); + break; + case 2: + $Result = $this->MoveStop(); + break; + case 3: + $Result = $this->MoveDownSpeedTime($Speed, $Time); + break; + case 4: + $Result = $this->MoveRightSpeedTime($Speed, $Time); + break; default: - set_error_handler([$this, 'ModulErrorHandler']); - trigger_error($this->Translate('Invalid Value.'), E_USER_NOTICE); - restore_error_handler(); - return false; - - } - if ($Result) { - $this->SetValueInteger('ZOOM', $Value); - } - return $Result; - } + set_error_handler([$this, 'ModulErrorHandler']); + trigger_error($this->Translate('Invalid Value.'), E_USER_NOTICE); + restore_error_handler(); + return false; + } + if ($Result) { + $this->SetValueInteger('PT', $Value); + } + return $Result; + case 'ZOOM': + $Result = false; + switch ($Value) { + case 0: + $Result = $this->ZoomFarSpeedTime($Speed, $Time); + break; + case 1: + $Result = $this->ZoomStop(); + break; + case 2: + $Result = $this->ZoomNearSpeedTime($Speed, $Time); + break; + default: + set_error_handler([$this, 'ModulErrorHandler']); + trigger_error($this->Translate('Invalid Value.'), E_USER_NOTICE); + restore_error_handler(); + return false; + } + if ($Result) { + $this->SetValueInteger('ZOOM', $Value); + } + return $Result; + } set_error_handler([$this, 'ModulErrorHandler']); trigger_error($this->Translate('Invalid Ident.'), E_USER_NOTICE); restore_error_handler(); @@ -955,7 +953,7 @@ public function ReceiveData($JSONString) $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $EventProperties = $this->ReadAttributeArray('EventProperties'); + $EventProperties = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (!array_key_exists($Data['Topic'], $EventProperties)) { return false; } @@ -973,7 +971,7 @@ public function ReceiveData($JSONString) if ($EventProperty['Sources'][$SourceIndex]['Type'] != 'tt:ReferenceToken') { continue; } - if ($Source['Value'] != $this->ReadPropertyString('VideoSource')) { + if ($Source['Value'] != $this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource)) { continue; } $FoundEventIndex = $SourceIndex; @@ -982,7 +980,7 @@ public function ReceiveData($JSONString) if ($FoundEventIndex !== false) { unset($Data['Sources'][$FoundEventIndex]); } - $PreName = str_replace($this->ReadPropertyString('EventTopic'), '', $Data['Topic']); + $PreName = str_replace($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic), '', $Data['Topic']); return $this->SetEventStatusVariable($PreName, $EventProperties[$Data['Topic']], $Data); } @@ -1052,7 +1050,7 @@ protected function GetPTZCapabilities() } } // Presets - $ProfileToken = ['ProfileToken' => $this->ReadPropertyString('Profile')]; + $ProfileToken = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile)]; $PresetResult = @$this->SendData($this->PTZ_xAddr, 'GetPresets', true, $ProfileToken, self::PTZwsdl); ob_clean(); if (is_bool($PresetResult)) { @@ -1082,9 +1080,9 @@ protected function GetStreamUri() } $this->PTZ_xAddr = $Capabilities['XAddr'][\ONVIF\NS::PTZ]; foreach ($Capabilities['VideoSources'] as $VideoSource) { - if ($this->ReadPropertyString('VideoSource') == $VideoSource['VideoSourceToken']) { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource) == $VideoSource['VideoSourceToken']) { foreach ($VideoSource['Profile'] as $Profile) { - if ($Profile['token'] == $this->ReadPropertyString('Profile')) { + if ($Profile['token'] == $this->ReadPropertyString(\ONVIF\Stream\Property::Profile)) { $this->PTZ_token = $Profile['ptztoken']; break; } @@ -1096,7 +1094,7 @@ protected function GetStreamUri() if (($Capabilities['XAddr'][\ONVIF\NS::Media2]) != '') { $Params = [ 'Protocol' => 'RtspUnicast', - 'ProfileToken' => $this->ReadPropertyString('Profile') + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile) ]; $Result = $this->SendData($Capabilities['XAddr'][\ONVIF\NS::Media2], 'GetStreamUri', true, $Params, \ONVIF\WSDL::Media2); if ($Result == false) { @@ -1115,7 +1113,7 @@ protected function GetStreamUri() 'Protocol' => 'RTSP', ], ], - 'ProfileToken' => $this->ReadPropertyString('Profile') + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile) ]; $Result = $this->SendData($Capabilities['XAddr'][\ONVIF\NS::Media], 'GetStreamUri', true, $Params); if ($Result == false) { @@ -1166,7 +1164,7 @@ protected function WritePTZInHTMLBox() $Key = urlencode($Key); $ImgSrc = ''; $PanTiltSVG = ''; - if ($this->ReadPropertyBoolean('EnablePanTiltHTML')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltHTML)) { $PanTiltSVG = str_replace( [ '%%InstanceId%%', @@ -1176,15 +1174,15 @@ protected function WritePTZInHTMLBox() ], [ $this->InstanceID, - $this->ReadPropertyInteger('PanTiltControlWidth'), - $this->ReadPropertyInteger('PanTiltControlHeight'), - sprintf('%F', $this->ReadPropertyInteger('PanTiltControlOpacity') / 100) + $this->ReadPropertyInteger(\ONVIF\Stream\Property::PanTiltControlWidth), + $this->ReadPropertyInteger(\ONVIF\Stream\Property::PanTiltControlHeight), + sprintf('%F', $this->ReadPropertyInteger(\ONVIF\Stream\Property::PanTiltControlOpacity) / 100) ], file_get_contents(__DIR__ . '/../libs/PanTiltControl.svg') ); } $ZoomSVG = ''; - if ($this->ReadPropertyBoolean('EnableZoomHTML')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableZoomHTML)) { $ZoomSVG = str_replace( [ '%%InstanceId%%', @@ -1194,9 +1192,9 @@ protected function WritePTZInHTMLBox() ], [ $this->InstanceID, - $this->ReadPropertyInteger('ZoomControlWidth'), - $this->ReadPropertyInteger('ZoomControlHeight'), - sprintf('%F', $this->ReadPropertyInteger('ZoomControlOpacity') / 100) + $this->ReadPropertyInteger(\ONVIF\Stream\Property::ZoomControlWidth), + $this->ReadPropertyInteger(\ONVIF\Stream\Property::ZoomControlHeight), + sprintf('%F', $this->ReadPropertyInteger(\ONVIF\Stream\Property::ZoomControlOpacity) / 100) ], file_get_contents(__DIR__ . '/../libs/ZoomControl.svg') ); @@ -1257,48 +1255,48 @@ protected function ProcessHookData() return; } switch ($_GET['action']) { - case 'StopPTZ': - $this->StopPTZ(); - echo 'OK'; - return; - case 'StartPTZ': - switch ($_GET['value']) { - case 'left': - if ($this->MoveLeft()) { - echo 'OK'; - } - return; - case 'right': - if ($this->MoveRight()) { - echo 'OK'; - } - return; - case 'up': - if ($this->MoveUp()) { - echo 'OK'; - } - return; - case 'down': - if ($this->MoveDown()) { - echo 'OK'; - } - return; - case 'near': - if ($this->ZoomNear()) { - echo 'OK'; - } - return; - case 'far': - if ($this->ZoomFar()) { - echo 'OK'; - } - return; - default: - echo $this->Translate('Invalid parameters.'); - return; - } - break; - } + case 'StopPTZ': + $this->StopPTZ(); + echo 'OK'; + return; + case 'StartPTZ': + switch ($_GET['value']) { + case 'left': + if ($this->MoveLeft()) { + echo 'OK'; + } + return; + case 'right': + if ($this->MoveRight()) { + echo 'OK'; + } + return; + case 'up': + if ($this->MoveUp()) { + echo 'OK'; + } + return; + case 'down': + if ($this->MoveDown()) { + echo 'OK'; + } + return; + case 'near': + if ($this->ZoomNear()) { + echo 'OK'; + } + return; + case 'far': + if ($this->ZoomFar()) { + echo 'OK'; + } + return; + default: + echo $this->Translate('Invalid parameters.'); + return; + } + break; + } echo $this->Translate('Invalid parameters.'); return; } diff --git a/README.md b/README.md index 5760d71..3d6cae4 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,8 @@ Für das Discovery werden Pakete über die Multicast-Adresse `239.255.255.250` a **Version 2.12:** **(Dies ist die letzte Version für IPS kleiner Version 7.0)** - Lesen der Fähigkeiten eines Gerätes in der IO Instanz verbessert. +- IO Instanz schreibt Warnungen in das Meldungslog. +- Vorhandene Fehlermeldungen bei der Kommunikation enthalten jetzt den Funktionsnamen bei welchem er Fehler aufgetreten ist. - Falsche Zeitstempel in Antworten von Geräten (`TerminationTime`) konnten zu Fehlern führen. **Version 2.10:** diff --git a/libs/ONVIFModuleBase.php b/libs/ONVIFModuleBase.php index 72b78fe..af0ca4e 100644 --- a/libs/ONVIFModuleBase.php +++ b/libs/ONVIFModuleBase.php @@ -36,20 +36,20 @@ class ONVIFModuleBase extends IPSModule \ONVIFModuleBase\DebugHelper, \ONVIFModuleBase\AttributeArrayHelper, \ONVIFModuleBase\InstanceStatus { - \ONVIFModuleBase\InstanceStatus::MessageSink as IOMessageSink; // MessageSink gibt es sowohl hier in der Klasse, als auch im Trait InstanceStatus. Hier wird für die Methode im Trait ein Alias benannt. - \ONVIFModuleBase\InstanceStatus::RegisterParent as IORegisterParent; - \ONVIFModuleBase\InstanceStatus::RequestAction as IORequestAction; - } - const wsdl = ''; - const TopicFilter = ''; + \ONVIFModuleBase\InstanceStatus::MessageSink as IOMessageSink; // MessageSink gibt es sowohl hier in der Klasse, als auch im Trait InstanceStatus. Hier wird für die Methode im Trait ein Alias benannt. + \ONVIFModuleBase\InstanceStatus::RegisterParent as IORegisterParent; + \ONVIFModuleBase\InstanceStatus::RequestAction as IORequestAction; + } + public const wsdl = ''; + public const TopicFilter = ''; public function Create() { //Never delete this line! parent::Create(); - $this->RegisterPropertyString('EventTopic', ''); + $this->RegisterPropertyString(\ONVIF\Device\Property::EventTopic, ''); $this->EventTopic = ''; - $this->RegisterAttributeArray('EventProperties', []); + $this->RegisterAttributeArray(\ONVIF\Device\Attribute::EventProperties, []); if (IPS_GetKernelRunlevel() != KR_READY) { $this->RegisterMessage(0, IPS_KERNELSTARTED); } @@ -63,8 +63,8 @@ public function Destroy() public function ApplyChanges() { - $EventTopic = $this->ReadPropertyString('EventTopic'); - $PullEvents = ($EventTopic != $this->EventTopic); + $EventTopic = $this->ReadPropertyString(\ONVIF\Device\Property::EventTopic); + $SyncEvents = ($EventTopic != $this->EventTopic); //Never delete this line! parent::ApplyChanges(); $this->RegisterMessage($this->InstanceID, FM_CONNECT); @@ -83,8 +83,8 @@ public function ApplyChanges() } $this->RegisterParent(); $Events = $this->GetEvents($EventTopic); - $this->WriteAttributeArray('EventProperties', $Events); - if ($PullEvents && ($this->HasActiveParent())) { + $this->WriteAttributeArray(\ONVIF\Device\Attribute::EventProperties, $Events); + if ($SyncEvents && ($this->HasActiveParent())) { $this->$EventTopic = $EventTopic; IPS_RunScriptText('IPS_RequestAction(' . $this->InstanceID . ',"SetSynchronizationPoint",true);'); } @@ -133,7 +133,7 @@ protected function RegisterParent() protected function IOChangeState($State) { if ($State == IS_ACTIVE) { - $this->EventTopic = $this->ReadPropertyString('EventTopic'); + $this->EventTopic = $this->ReadPropertyString(\ONVIF\Device\Property::EventTopic); $this->ApplyChanges(); $this->ReloadForm(); } @@ -153,7 +153,7 @@ protected function GetEvents(string $Pattern = '', int $InstanceID = -1, array $ } $this->SendDebug('GetEvents Pattern', $Pattern, 0); $this->SendDebug('GetEvents SkippedTopics', $SkippedTopics, 0); - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'GetEvents', 'Pattern' => $Pattern, 'Instance' => $InstanceID, 'SkippedTopics' => $SkippedTopics]); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'GetEvents', 'Pattern' => $Pattern, 'Instance' => $InstanceID, 'SkippedTopics' => $SkippedTopics]); $answer = $this->SendDataToParent($Data); if ($answer !== false) { $answer = unserialize($answer); @@ -167,7 +167,7 @@ protected function SetSynchronizationPoint() if ($this->ParentID > 0) { if ($this->HasActiveParent()) { $this->SendDebug('SetSynchronizationPoint', '', 0); - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'SetSynchronizationPoint']); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'SetSynchronizationPoint']); $this->SendDataToParent($Data); } } @@ -177,7 +177,7 @@ protected function GetCapabilities() if ($this->ParentID > 0) { if ($this->HasActiveParent()) { $this->SendDebug('GetCapabilities', '', 0); - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'GetCapabilities']); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'GetCapabilities']); $answer = $this->SendDataToParent($Data); if ($answer !== false) { $Result = unserialize($answer); @@ -222,7 +222,7 @@ protected function GetCredentials() { if ($this->ParentID > 0) { if ($this->HasActiveParent()) { - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'GetCredentials']); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'GetCredentials']); $answer = $this->SendDataToParent($Data); if ($answer === false) { $this->SendDebug('GetCredentials', 'No valid answer', 0); @@ -237,7 +237,7 @@ protected function GetUrl() { if ($this->ParentID > 0) { if ($this->HasActiveParent()) { - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'GetUrl']); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'GetUrl']); $answer = $this->SendDataToParent($Data); if ($answer === false) { $this->SendDebug('GetUrl', 'No valid answer', 0); @@ -264,7 +264,7 @@ protected function SendData(string $URI, string $Function, bool $UseLogin = fals $this->SendDebug('Send Function', $Function, 0); $this->SendDebug('Send Params', $Params, 0); $this->SendDebug('Send useLogin', $UseLogin, 0); - $Ret = $this->SendDataToParent(json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'URI' => $URI, 'Function' => $Function, 'Params' => $Params, 'useLogin' => $UseLogin, 'wsdl' => $wsdl])); + $Ret = $this->SendDataToParent(json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'URI' => $URI, 'Function' => $Function, 'Params' => $Params, 'useLogin' => $UseLogin, 'wsdl' => $wsdl])); if ($Ret === false) { $this->SendDebug('Result', false, 0); return false; @@ -341,7 +341,7 @@ protected function GetConfigurationFormEventTopic(array $Form, bool $AddNothingI } $Form['options'] = $SelectTopic; $Form['enabled'] = (count($Events) > 1); - if ($this->ReadPropertyString('EventTopic') == '') { + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { $Form['enabled'] = true; } } @@ -393,54 +393,54 @@ protected function SetEventStatusVariable($PreName, $EventProperty, $Data) $Ident = str_replace([' - ', ':'], ['_', ''], $Name); $Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident); switch ($DataType) { - case 'xs:boolean': - case 'tt:boolean': - $VariableValue = false; - if (strtolower($DataValue['Value']) === 'true') { - $VariableValue = true; - } - if (intval($DataValue['Value']) === 1) { - $VariableValue = true; - } - $this->RegisterVariableBoolean($Ident, $Name, '', 0); - $this->SetValueBoolean($Ident, $VariableValue); - break; - case 'tt:RelayLogicalState': - $this->RegisterVariableBoolean($Ident, $Name, '', 0); - $this->SetValueBoolean($Ident, (strtolower($DataValue['Value']) === 'active')); - break; - case 'xs:float': - case 'xs:double': - case 'xs:long': - case 'tt:float': - case 'tt:double': - case 'tt:long': - $this->RegisterVariableFloat($Ident, $Name, '', 0); - $this->SetValueFloat($Ident, (float) $DataValue['Value']); - break; - case 'xs:integer': - case 'xs:int': - case 'xs:decimal': - case 'xs:short': - case 'xs:unsignedLong': - case 'xs:unsignedInt': - case 'xs:unsignedShort': - case 'xs:unsignedByte': - case 'tt:integer': - case 'tt:int': - case 'tt:decimal': - case 'tt:short': - case 'tt:unsignedLong': - case 'tt:unsignedInt': - case 'tt:unsignedShort': - case 'tt:unsignedByte': - $this->RegisterVariableInteger($Ident, $Name, '', 0); - $this->SetValueInteger($Ident, (int) $DataValue['Value']); - break; - default: - $this->RegisterVariableString($Ident, $Name, '', 0); - $this->SetValueString($Ident, $DataValue['Value']); - break; + case 'xs:boolean': + case 'tt:boolean': + $VariableValue = false; + if (strtolower($DataValue['Value']) === 'true') { + $VariableValue = true; + } + if (intval($DataValue['Value']) === 1) { + $VariableValue = true; + } + $this->RegisterVariableBoolean($Ident, $Name, '', 0); + $this->SetValueBoolean($Ident, $VariableValue); + break; + case 'tt:RelayLogicalState': + $this->RegisterVariableBoolean($Ident, $Name, '', 0); + $this->SetValueBoolean($Ident, (strtolower($DataValue['Value']) === 'active')); + break; + case 'xs:float': + case 'xs:double': + case 'xs:long': + case 'tt:float': + case 'tt:double': + case 'tt:long': + $this->RegisterVariableFloat($Ident, $Name, '', 0); + $this->SetValueFloat($Ident, (float) $DataValue['Value']); + break; + case 'xs:integer': + case 'xs:int': + case 'xs:decimal': + case 'xs:short': + case 'xs:unsignedLong': + case 'xs:unsignedInt': + case 'xs:unsignedShort': + case 'xs:unsignedByte': + case 'tt:integer': + case 'tt:int': + case 'tt:decimal': + case 'tt:short': + case 'tt:unsignedLong': + case 'tt:unsignedInt': + case 'tt:unsignedShort': + case 'tt:unsignedByte': + $this->RegisterVariableInteger($Ident, $Name, '', 0); + $this->SetValueInteger($Ident, (int) $DataValue['Value']); + break; + default: + $this->RegisterVariableString($Ident, $Name, '', 0); + $this->SetValueString($Ident, $DataValue['Value']); + break; } } return true; diff --git a/libs/wsdl.php b/libs/wsdl.php index ae264af..57196e6 100644 --- a/libs/wsdl.php +++ b/libs/wsdl.php @@ -2,165 +2,328 @@ declare(strict_types=1); -namespace ONVIF; - -/** - * WSDL Files - */ -class WSDL +namespace ONVIF { - public const Management = 'ver10/device/wsdl/devicemgmt.wsdl'; - public const Media = 'ver10/media/wsdl/media.wsdl'; - public const Event = 'ver10/events/wsdl/event.wsdl'; - public const Media2 = 'ver20/media/wsdl/media.wsdl'; - public const PTZ = 'ver20/ptz/wsdl/ptz.wsdl'; - public const DeviceIO = 'ver10/deviceio.wsdl'; - public const Imaging = 'ver20/imaging/wsdl/imaging.wsdl'; - public const Analytics = 'ver20/analytics/wsdl/analytics.wsdl'; + + /** + * WSDL Files + */ + class WSDL + { + public const Management = 'ver10/device/wsdl/devicemgmt.wsdl'; + public const Media = 'ver10/media/wsdl/media.wsdl'; + public const Event = 'ver10/events/wsdl/event.wsdl'; + public const Media2 = 'ver20/media/wsdl/media.wsdl'; + public const PTZ = 'ver20/ptz/wsdl/ptz.wsdl'; + public const DeviceIO = 'ver10/deviceio.wsdl'; + public const Imaging = 'ver20/imaging/wsdl/imaging.wsdl'; + public const Analytics = 'ver20/analytics/wsdl/analytics.wsdl'; + } + /** + * Namespaces ONVIF, SOAP & XML + */ + class NS + { + public const Management = 'http://www.onvif.org/ver10/device/wsdl'; + public const Media = 'http://www.onvif.org/ver10/media/wsdl'; + public const Event = 'http://www.onvif.org/ver10/events/wsdl'; + public const Media2 = 'http://www.onvif.org/ver20/media/wsdl'; + public const PTZ = 'http://www.onvif.org/ver20/ptz/wsdl'; + public const DeviceIO = 'http://www.onvif.org/ver10/deviceIO/wsdl'; + public const Imaging = 'http://www.onvif.org/ver20/imaging/wsdl'; + public const Analytics = 'http://www.onvif.org/ver20/analytics/wsdl'; + public const Addressing = 'http://www.w3.org/2005/08/addressing'; + // all other NS + public const Namespaces = [ + 's' => 'http://www.w3.org/2003/05/soap-envelope', + 'e' => 'http://www.w3.org/2003/05/soap-encoding', + 'wsa' => self::Addressing, + 'xs' => 'http://www.w3.org/2001/XMLSchema', + 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', + 'wsaw' => 'http://www.w3.org/2006/05/addressing/wsdl', + 'wsnt' => 'http://docs.oasis-open.org/wsn/b-2', + 'wstop' => 'http://docs.oasis-open.org/wsn/t-1', + 'wsntw' => 'http://docs.oasis-open.org/wsn/bw-2', + 'wsrf-rw'=> 'http://docs.oasis-open.org/wsrf/rw-2', + 'wsrf-r' => 'http://docs.oasis-open.org/wsrf/r-2', + 'wsrf-bf'=> 'http://docs.oasis-open.org/wsrf/bf-2', + 'wsdl' => 'http://schemas.xmlsoap.org/wsdl', + 'wsoap12'=> 'http://schemas.xmlsoap.org/wsdl/soap12', + 'http' => 'http://schemas.xmlsoap.org/wsdl/http', + 'd' => 'http://schemas.xmlsoap.org/ws/2005/04/discovery', + 'wsadis' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing', + 'tt' => 'http://www.onvif.org/ver10/schema', + 'tns1' => 'http://www.onvif.org/ver10/topics', + 'tds' => self::Management, + 'trt' => self::Media, + 'tev' => self::Event, + 'timg' => self::Imaging, + 'tst' => 'http://www.onvif.org/ver10/storage/wsdl', + 'dn' => 'http://www.onvif.org/ver10/network/wsdl', + 'tr2' => self::Media2, + 'tptz' => self::PTZ, + 'tan' => self::Analytics, + 'axt' => 'http://www.onvif.org/ver20/analytics', + 'tmd' => self::DeviceIO, + 'ter' => 'http://www.onvif.org/ver10/error' + ]; + } + + class Media2Conf + { + public const All = 'All'; + public const VideoSource = 'VideoSource'; + public const VideoEncoder = 'VideoEncoder'; + public const AudioSource = 'AudioSource'; + public const AudioEncoder = 'AudioEncoder'; + public const AudioOutput = 'AudioOutput'; + public const AudioDecoder = 'AudioDecoder'; + public const Metadata = 'Metadata'; + public const Analytics = 'Analytics'; + public const PTZ = 'PTZ'; + public const Receiver = 'Receiver'; + } + + class Scopes + { + public const ProfileT = 'onvif://www.onvif.org/Profile/T'; + public const ProfileG = 'onvif://www.onvif.org/Profile/G'; + public const ProfileS = 'onvif://www.onvif.org/Profile/Streaming'; + } + + class EventHandler + { + public const None = 0; + public const Subscribe = 1; + public const PullPoint = 2; + public const Automatic = 3; + public $Type; + public function __construct(int $Type = 0) + { + $this->Type = $Type; + } + public function __sleep() + { + return ['Type']; + } + public function toString(): string + { + switch ($this->Type) { + case self::Subscribe: + return 'Subscription'; + case self::PullPoint: + return 'PullPoint'; + case self::Automatic: + return 'Automatic'; + } + return 'none'; + } + } + class Profile + { + public const NONE = 1; // Fallback Profil S + public const S = 2; // Streaming und WS-Event + public const G = 4; // Recording (ohne streaming!) + public const T = 8; // Streaming und pull point Event, Image Settings + private const ScopesToProfile = [ + Scopes::ProfileS => self::S, + Scopes::ProfileG => self::G, + Scopes::ProfileT => self::T + ]; + private const ProfileBitToChar = [ + self::NONE => 'Fallback S', + self::S => 'S', + self::G => 'G', + self::T => 'T' + ]; + public $Profile; + public function __construct(array $Scopes = []) + { + $this->Profile = 0; + foreach ($Scopes as $Scope) { + if (array_key_exists($Scope, self::ScopesToProfile)) { + $this->Profile |= self::ScopesToProfile[$Scope]; + } + } + } + public function __sleep(): array + { + return ['Profile']; + } + public function HasProfile(int $Profile): bool + { + return ($this->Profile & $Profile) == $Profile; + } + public function toString(): string + { + $Profiles = []; + foreach (self::ProfileBitToChar as $Bit => $Char) { + if ($this->HasProfile($Bit)) { + $Profiles[] = $Char; + } + } + return implode(', ', $Profiles); + } + } + class GUID + { + public const Configurator = '{C6A79C49-19D5-8D45-FFE5-5D77165FAEE6}'; + public const IO = '{F40CA9A7-3B4D-4B26-7214-3A94B6074DFB}'; + public const Input = '{73097230-1ECC-FEEB-5969-C85148DFA76E}'; + public const Output = '{A44B3114-1F72-1FD1-96FB-D7E970BD8614}'; + public const Stream = '{FA889450-38B6-7E20-D4DC-F2C6D0B074FB}'; + public const ImageGrabber = '{18EA97C1-3CEC-80B7-4CAA-D91F8A2A0599}'; + public const Event = '{62584C2E-4542-4EBF-1E92-299F4CF364E4}'; + } } -/** - * Namespaces ONVIF, SOAP & XML - */ -class NS + +namespace ONVIF\Discovery { - public const Management = 'http://www.onvif.org/ver10/device/wsdl'; - public const Media = 'http://www.onvif.org/ver10/media/wsdl'; - public const Event = 'http://www.onvif.org/ver10/events/wsdl'; - public const Media2 = 'http://www.onvif.org/ver20/media/wsdl'; - public const PTZ = 'http://www.onvif.org/ver20/ptz/wsdl'; - public const DeviceIO = 'http://www.onvif.org/ver10/deviceIO/wsdl'; - public const Imaging = 'http://www.onvif.org/ver20/imaging/wsdl'; - public const Analytics = 'http://www.onvif.org/ver20/analytics/wsdl'; - public const Addressing = 'http://www.w3.org/2005/08/addressing'; - // all other NS - public const Namespaces = [ - 's' => 'http://www.w3.org/2003/05/soap-envelope', - 'e' => 'http://www.w3.org/2003/05/soap-encoding', - 'wsa' => self::Addressing, - 'xs' => 'http://www.w3.org/2001/XMLSchema', - 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', - 'wsaw' => 'http://www.w3.org/2006/05/addressing/wsdl', - 'wsnt' => 'http://docs.oasis-open.org/wsn/b-2', - 'wstop' => 'http://docs.oasis-open.org/wsn/t-1', - 'wsntw' => 'http://docs.oasis-open.org/wsn/bw-2', - 'wsrf-rw'=> 'http://docs.oasis-open.org/wsrf/rw-2', - 'wsrf-r' => 'http://docs.oasis-open.org/wsrf/r-2', - 'wsrf-bf'=> 'http://docs.oasis-open.org/wsrf/bf-2', - 'wsdl' => 'http://schemas.xmlsoap.org/wsdl', - 'wsoap12'=> 'http://schemas.xmlsoap.org/wsdl/soap12', - 'http' => 'http://schemas.xmlsoap.org/wsdl/http', - 'd' => 'http://schemas.xmlsoap.org/ws/2005/04/discovery', - 'wsadis' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing', - 'tt' => 'http://www.onvif.org/ver10/schema', - 'tns1' => 'http://www.onvif.org/ver10/topics', - 'tds' => self::Management, - 'trt' => self::Media, - 'tev' => self::Event, - 'timg' => self::Imaging, - 'tst' => 'http://www.onvif.org/ver10/storage/wsdl', - 'dn' => 'http://www.onvif.org/ver10/network/wsdl', - 'tr2' => self::Media2, - 'tptz' => self::PTZ, - 'tan' => self::Analytics, - 'axt' => 'http://www.onvif.org/ver20/analytics', - 'tmd' => self::DeviceIO, - 'ter' => 'http://www.onvif.org/ver10/error' - ]; + class Attribute + { + public const Username = 'Username'; + public const Password = 'Password'; + } } -class Media2Conf +namespace ONVIF\IO { - public const All = 'All'; - public const VideoSource = 'VideoSource'; - public const VideoEncoder = 'VideoEncoder'; - public const AudioSource = 'AudioSource'; - public const AudioEncoder = 'AudioEncoder'; - public const AudioOutput = 'AudioOutput'; - public const AudioDecoder = 'AudioDecoder'; - public const Metadata = 'Metadata'; - public const Analytics = 'Analytics'; - public const PTZ = 'PTZ'; - public const Receiver = 'Receiver'; + class Property + { + public const Active = 'Open'; + public const Address = 'Address'; + public const Username = 'Username'; + public const Password = 'Password'; + public const EventHandler = 'EventHandler'; + public const WebHookIP = 'WebHookIP'; + public const WebHookHTTPS = 'WebHookHTTPS'; + public const WebHookPort = 'WebHookPort'; + public const SubscribeEventTimeout = 'SubscribeEventTimeout'; + public const SubscribeInitialTerminationTime = 'SubscribeInitialTerminationTime'; + public const PullPointInitialTerminationTime = 'PullPointInitialTerminationTime'; + public const PullPointTimeout = 'PullPointTimeout'; + public const MessageLimit = 'MessageLimit'; + } + class Attribute + { + public const VideoSources = 'VideoSources'; + public const AudioSources = 'AudioSources'; + public const VideoSourcesJPEG = 'VideoSourcesJPEG'; + public const AnalyticsTokens = 'AnalyticsTokens'; + public const RelayOutputs = 'RelayOutputs'; + public const DigitalInputs = 'DigitalInputs'; + public const Timestamp_Offset = 'Timestamp_Offset'; + public const XAddr = 'XAddr'; + public const EventProperties = 'EventProperties'; + public const NbrOfInputs = 'NbrOfInputs'; + public const NbrOfOutputs = 'NbrOfOutputs'; + public const NbrOfVideoSources = 'NbrOfVideoSources'; + public const NbrOfAudioSources = 'NbrOfAudioSources'; + public const NbrOfSerialPorts = 'NbrOfSerialPorts'; + public const HasSnapshotUri = 'HasSnapshotUri'; + public const HasRTSPStreaming = 'HasRTSPStreaming'; + public const RuleSupport = 'RuleSupport'; + public const AnalyticsModuleSupport = 'AnalyticsModuleSupport'; + public const WSSubscriptionPolicySupport = 'WSSubscriptionPolicySupport'; + public const WSPullPointSupport = 'WSPullPointSupport'; + public const ConsumerAddress = 'ConsumerAddress'; + public const SubscriptionReference = 'SubscriptionReference'; + public const SubscriptionId = 'SubscriptionId'; + public const CapabilitiesVersion = 'CapabilitiesVersion'; + } + class Timer + { + public const RenewSubscription = 'RenewSubscription'; + } + class State + { + public const INACTIVE = 'Interface closed'; + public const ACTIVE = 'Interface connected'; + public const CONNECTION_LOST = 'Connection lost'; + } } -class Scopes -{ - public const ProfileT = 'onvif://www.onvif.org/Profile/T'; - public const ProfileG = 'onvif://www.onvif.org/Profile/G'; - public const ProfileS = 'onvif://www.onvif.org/Profile/Streaming'; +namespace ONVIF\DataFlow{ + class GUID + { + public const SendEvents = '{E23DD2CD-F098-268A-CE49-1CC04FE8060B}'; + public const SendFunction = '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}'; + } } -class EventHandler +namespace ONVIF\Device { - public const None = 0; - public const Subscribe = 1; - public const PullPoint = 2; - public const Automatic = 3; - public $Type; - public function __construct(int $Type = 0) + class Property { - $this->Type = $Type; + public const EventTopic = 'EventTopic'; } - public function __sleep() + class Attribute { - return ['Type']; + public const EventProperties = 'EventProperties'; } - public function toString(): string +} + +namespace ONVIF\Stream +{ + class Property { - switch ($this->Type) { - case self::Subscribe: - return 'Subscription'; - case self::PullPoint: - return 'PullPoint'; - case self::Automatic: - return 'Automatic'; - } - return 'none'; + public const VideoSource = 'VideoSource'; + public const Profile = 'Profile'; + public const InvertPanControl = 'InvertPanControl'; + public const InvertTiltControl = 'InvertTiltControl'; + public const InvertZoomControl = 'InvertZoomControl'; + public const EnablePanTiltVariable = 'EnablePanTiltVariable'; + public const EnableZoomVariable = 'EnableZoomVariable'; + public const EnableSpeedVariable = 'EnableSpeedVariable'; + public const EnableTimeVariable = 'EnableTimeVariable'; + public const EnablePanTiltHTML = 'EnablePanTiltHTML'; + public const EnableZoomHTML = 'EnableZoomHTML'; + public const PanTiltControlWidth = 'PanTiltControlWidth'; + public const PanTiltControlHeight = 'PanTiltControlHeight'; + public const PanTiltControlOpacity = 'PanTiltControlOpacity'; + public const ZoomControlWidth = 'ZoomControlWidth'; + public const ZoomControlHeight = 'ZoomControlHeight'; + public const ZoomControlOpacity = 'ZoomControlOpacity'; + public const PanDefaultSpeed = 'PanDefaultSpeed'; + public const TiltDefaultSpeed = 'TiltDefaultSpeed'; + public const ZoomDefaultSpeed = 'ZoomDefaultSpeed'; + public const EnablePresetVariable = 'EnablePresetVariable'; + public const EnablePresetProfile = 'EnablePresetProfile'; + public const PresetProfile = 'PresetProfile'; } } -class Profile + +namespace ONVIF\ImageGrabber { - public const NONE = 1; // Fallback Profil S - public const S = 2; // Streaming und WS-Event - public const G = 4; // Recording (ohne streaming!) - public const T = 8; // Streaming und pull point Event, Image Settings - private const ScopesToProfile = [ - Scopes::ProfileS => self::S, - Scopes::ProfileG => self::G, - Scopes::ProfileT => self::T - ]; - private const ProfileBitToChar = [ - self::NONE => 'Fallback S', - self::S => 'S', - self::G => 'G', - self::T => 'T' - ]; - public $Profile; - public function __construct(array $Scopes = []) - { - $this->Profile = 0; - foreach ($Scopes as $Scope) { - if (array_key_exists($Scope, self::ScopesToProfile)) { - $this->Profile |= self::ScopesToProfile[$Scope]; - } - } - } - public function __sleep(): array + class Property { - return ['Profile']; + public const VideoSource = 'VideoSource'; + public const Profile = 'Profile'; + public const Interval = 'Interval'; + public const UseCaching = 'UseCaching'; } - public function HasProfile(int $Profile): bool + class Timer { - return ($this->Profile & $Profile) == $Profile; + public const UpdateImage = 'UpdateImage'; } - public function toString(): string +} + +namespace ONVIF\Input +{ + class Attribute { - $Profiles = []; - foreach (self::ProfileBitToChar as $Bit => $Char) { - if ($this->HasProfile($Bit)) { - $Profiles[] = $Char; - } - } - return implode(', ', $Profiles); + public const DigitalInputs = 'DigitalInputs'; } } + +namespace ONVIF\Output +{ + class Property + { + public const EmulateStatus = 'EmulateStatus'; + } + class Attribute + { + public const RelayOutputs = 'RelayOutputs'; + } +} \ No newline at end of file