Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Nall-chan committed Aug 31, 2023
1 parent c29eba7 commit 0de60c5
Show file tree
Hide file tree
Showing 12 changed files with 953 additions and 781 deletions.
2 changes: 1 addition & 1 deletion .vscode
Submodule .vscode updated 1 files
+6 −6 tasks.json
120 changes: 59 additions & 61 deletions ONVIF Configurator/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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']));
Expand All @@ -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 = [
Expand All @@ -89,7 +85,7 @@ public function GetConfigurationForm()
}

$Device['create'] = [
'moduleID' => self::GUID_ONVIF_EVENT,
'moduleID' => \ONVIF\GUID::Event,
'configuration' => [
'EventTopic' => $Topic
],
Expand All @@ -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
],
Expand All @@ -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);
Expand All @@ -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
],
Expand All @@ -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 = [
Expand All @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions ONVIF Digital Input/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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',
Expand Down
22 changes: 11 additions & 11 deletions ONVIF Digital Output/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}
Expand All @@ -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 {
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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',
Expand Down
Loading

0 comments on commit 0de60c5

Please sign in to comment.