|
|
|
@ -132,6 +132,7 @@ pOnvif::pOnvif() |
|
|
|
m_bDiscoveryHideDuplicates = true; |
|
|
|
m_pHttpAccessManager = NULL; |
|
|
|
memset( &m_sCapabilities, 0, sizeof( nodeCapability ) ); |
|
|
|
setGenericSpeedSpaces(); |
|
|
|
m_bAuthMode = 0; |
|
|
|
parser_done = false; |
|
|
|
m_pPendingRequest = NULL; |
|
|
|
@ -2050,32 +2051,94 @@ bool pOnvif::ptz_GetPresets(CSTR profileToken) |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
void pOnvif::setGenericSpeedSpaces(void) |
|
|
|
{ |
|
|
|
memset(&m_sPanTiltSpeedSpace, 0, sizeof(m_sPanTiltSpeedSpace)); |
|
|
|
memset(&m_sZoomSpeedSpace, 0, sizeof(m_sZoomSpeedSpace)); |
|
|
|
safeCopy(m_sPanTiltSpeedSpace.uri, sizeof(m_sPanTiltSpeedSpace.uri), PONVIF_SPACE_PT_GENERIC_SPEED); |
|
|
|
safeCopy(m_sZoomSpeedSpace.uri, sizeof(m_sZoomSpeedSpace.uri), PONVIF_SPACE_ZOOM_GENERIC_SPEED); |
|
|
|
m_sPanTiltSpeedSpace.max = m_sZoomSpeedSpace.max = 1.0f; |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
Picks the speed space to use out of the node's <PanTiltSpeedSpace> / <ZoomSpeedSpace> list: |
|
|
|
the generic one if the node has it, otherwise the first one (with its own range). |
|
|
|
*/ |
|
|
|
static bool pickSpeedSpace(XMLNode & spaces, LPCTSTR name, LPCTSTR genericUri, ptzSpeedSpace * out) |
|
|
|
{ |
|
|
|
// nChildNode(name) compares the prefixed name ("tt:..."), getChildNode(name, i) ignores the prefix
|
|
|
|
int tPick = -1; |
|
|
|
for (int i = 0;; i++) |
|
|
|
{ |
|
|
|
XMLNode tSpace = spaces.getChildNode(name, i); |
|
|
|
if (tSpace.isEmpty()) |
|
|
|
{ |
|
|
|
break; |
|
|
|
}; |
|
|
|
LPCTSTR tUri = tSpace.getChildNode("URI", 0).getText(0); |
|
|
|
if (tUri == NULL) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
}; |
|
|
|
if (tPick < 0 || strcmp(tUri, genericUri) == 0) |
|
|
|
{ |
|
|
|
tPick = i; |
|
|
|
}; |
|
|
|
if (strcmp(tUri, genericUri) == 0) |
|
|
|
{ |
|
|
|
break; |
|
|
|
}; |
|
|
|
}; |
|
|
|
if (tPick < 0) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
}; |
|
|
|
XMLNode tSpace = spaces.getChildNode(name, tPick); |
|
|
|
XMLNode tRange = tSpace.getChildNode("XRange", 0); |
|
|
|
LPCTSTR tMin = tRange.getChildNode("Min", 0).getText(0); |
|
|
|
LPCTSTR tMax = tRange.getChildNode("Max", 0).getText(0); |
|
|
|
float fMax = (tMax != NULL) ? (float) atof(tMax) : 0.0f; |
|
|
|
if (fMax <= 0.0f) |
|
|
|
{ |
|
|
|
return false; // no usable range: keep the generic space
|
|
|
|
}; |
|
|
|
memset(out, 0, sizeof(ptzSpeedSpace)); |
|
|
|
safeCopy(out->uri, sizeof(out->uri), tSpace.getChildNode("URI", 0).getText(0)); |
|
|
|
out->min = (tMin != NULL) ? (float) atof(tMin) : 0.0f; |
|
|
|
out->max = fMax; |
|
|
|
out->valid = true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
bool pOnvif::ptz_GetNode(CSTR ptzNodeToken) |
|
|
|
{ |
|
|
|
if (m_pPTZURI == NULL) |
|
|
|
if (m_pPTZURI == NULL || ptzNodeToken == NULL || ptzNodeToken[0] == 0) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
char tBuffer[DEFAULT_BUFFER_SIZE]; |
|
|
|
_buildRequest(tBuffer, sizeof(tBuffer), PONVIF_BODY_GET_PTZ_NODE, xesc(ptzNodeToken).c_str()); |
|
|
|
if (_send_request(m_pPTZURI, tBuffer)) |
|
|
|
if (! _send_request(m_pPTZURI, tBuffer, true)) |
|
|
|
{ |
|
|
|
XMLResults tParseResults; |
|
|
|
XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults); |
|
|
|
LOG("RCPT:"); |
|
|
|
printf("%s\n", m_pLastResponse); |
|
|
|
if (tParseResults.error) |
|
|
|
{ |
|
|
|
char tBuf[CTEXT]; |
|
|
|
sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn); |
|
|
|
LOG_ERROR(tBuf); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// return $response['Envelope']['Body']['GetNodeResponse'];
|
|
|
|
}; |
|
|
|
return false; |
|
|
|
}; |
|
|
|
return false; |
|
|
|
XMLResults tParseResults; |
|
|
|
XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults); |
|
|
|
if (tParseResults.error) |
|
|
|
{ |
|
|
|
char tBuf[CTEXT]; |
|
|
|
sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn); |
|
|
|
LOG_ERROR(tBuf); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
XMLNode tSpaces = response.getChildNode("Body", 0).getChildNode("GetNodeResponse", 0).getChildNode("PTZNode", 0).getChildNode("SupportedPTZSpaces", 0); |
|
|
|
if (tSpaces.isEmpty()) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
}; |
|
|
|
bool tPT = pickSpeedSpace(tSpaces, "PanTiltSpeedSpace", PONVIF_SPACE_PT_GENERIC_SPEED, &m_sPanTiltSpeedSpace); |
|
|
|
bool tZM = pickSpeedSpace(tSpaces, "ZoomSpeedSpace", PONVIF_SPACE_ZOOM_GENERIC_SPEED, &m_sZoomSpeedSpace); |
|
|
|
return tPT || tZM; |
|
|
|
} |
|
|
|
|
|
|
|
bool pOnvif::ptz_GotoPreset(CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x) |
|
|
|
@ -2133,14 +2196,20 @@ bool pOnvif::ptz_RelativeMoveZoom(CSTR profileToken, float zoom, float speedZoom |
|
|
|
return _send_request(m_pPTZURI, tBuffer, true); |
|
|
|
} |
|
|
|
|
|
|
|
bool pOnvif::ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom) |
|
|
|
bool pOnvif::ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom, float speed) |
|
|
|
{ |
|
|
|
if (m_pPTZURI == NULL) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
char tBuffer[DEFAULT_BUFFER_SIZE]; |
|
|
|
_buildRequest(tBuffer, sizeof(tBuffer), PONVIF_BODY_ABSOLUTE_MOVE, xesc(profileToken).c_str(), position_pantilt_x, position_pantilt_y, zoom); |
|
|
|
// The Speed is sent with its space: without it the device uses its default speed space, where
|
|
|
|
// x="1" is not necessarily the maximal speed (the moves were slower than the preset moves).
|
|
|
|
// The generic pan/tilt speed is a scalar (x); y is sent with the same value for devices reading it.
|
|
|
|
float tPT = (speed < 0.0f) ? m_sPanTiltSpeedSpace.max : m_sPanTiltSpeedSpace.min + speed * (m_sPanTiltSpeedSpace.max - m_sPanTiltSpeedSpace.min); |
|
|
|
float tZM = (speed < 0.0f) ? m_sZoomSpeedSpace.max : m_sZoomSpeedSpace.min + speed * (m_sZoomSpeedSpace.max - m_sZoomSpeedSpace.min); |
|
|
|
char tBuffer[DEFAULT_BUFFER_SIZE]; |
|
|
|
_buildRequest(tBuffer, sizeof(tBuffer), PONVIF_BODY_ABSOLUTE_MOVE, xesc(profileToken).c_str(), position_pantilt_x, position_pantilt_y, zoom, tPT, tPT, |
|
|
|
xesc(m_sPanTiltSpeedSpace.uri).c_str(), tZM, xesc(m_sZoomSpeedSpace.uri).c_str()); |
|
|
|
// Wait for the answer so that a SOAP Fault (e.g. position out of range) is detected
|
|
|
|
return _send_request(m_pPTZURI, tBuffer, true); |
|
|
|
} |
|
|
|
|