Skip to content

Commit

Permalink
try SDK method if ISAPI fails with err 23 for callsignal
Browse files Browse the repository at this point in the history
  • Loading branch information
pergolafabio committed Oct 10, 2023
1 parent 0da4c54 commit 403d8e9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
14 changes: 8 additions & 6 deletions hikvision-doorbell/src/doorbell.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,22 @@ def unlock_door(self, lock_id: int):

logger.info(" Door {} unlocked by SDK", lock_id + 1)

def answer_call(self):
def callsignal(self, cmd_type: int):
""" Answer the specified door using the NET_DVR_VIDEO_CALL_PARAM.
command type: 0- Request call, 1- cancel call, 2- answer the call, 3- refuse the call, 4- called timeout, 5- end the call, 6- the device is busy, 7- the device is busy.
"""
gw = NET_DVR_VIDEO_CALL_PARAM()
gw.dwSize = sizeof(NET_DVR_VIDEO_CALL_PARAM)
gw.dwCmdType = 0
gw.wUnitNumber = 1
gw.dwCmdType = cmd_type
#gw.wUnitNumber = 1
gw.byRes = (c_byte * 115)()

result = self._sdk.NET_DVR_SetDVRConfig(self.user_id, 16036, 1, byref(gw),255)
if not result:
logger.debug("NET_DVR_SetDVRConfig failed with code {}", self._sdk.NET_DVR_GetLastError())
logger.info(" Door answered by SDK")

raise SDKError(self._sdk, "Error while calling NET_DVR_VIDEO_CALL_PARAM")
logger.info("Callsignal {} sended with SDK", cmd_type)


def reboot_device(self):
# We know that the SDK gives error when rebooting since it cannot contact the device, raising error code 10
try:
Expand Down
33 changes: 27 additions & 6 deletions hikvision-doorbell/src/mqtt_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,15 @@ def _reject_call_callback(self, client, doorbell: Doorbell, message: MQTTMessage
try:
doorbell._call_isapi("PUT", url, json.dumps(requestBody))
except SDKError as err:
logger.error("Error while rejecting call: {}", err)
# If error code is 23 on some indoor stations, ISAPI failed, fallback to SDK method
logger.error("Error while answering call with ISAPI: {}", err)
error_code = err.args[1]
if error_code == 23:
try:
logger.debug("Answering call failed with ISAPI method, with error {} fallback to SDK method", error_code)
doorbell.callsignal(3)
except SDKError as err:
logger.error("Error while answering call with SDK: {}", err)

def _hangup_call_callback(self, client, doorbell: Doorbell, message: MQTTMessage):
logger.info("Received hangup command for doorbell: {}", doorbell._config.name)
Expand All @@ -322,7 +330,15 @@ def _hangup_call_callback(self, client, doorbell: Doorbell, message: MQTTMessage
try:
doorbell._call_isapi("PUT", url, json.dumps(requestBody))
except SDKError as err:
logger.error("Error while hanging up call: {}", err)
# If error code is 23 on some indoor stations, ISAPI failed, fallback to SDK method
logger.error("Error while answering call with ISAPI: {}", err)
error_code = err.args[1]
if error_code == 23:
try:
logger.debug("Answering call failed with ISAPI method, with error {} fallback to SDK method", error_code)
doorbell.callsignal(5)
except SDKError as err:
logger.error("Error while answering call with SDK: {}", err)

def _answer_call_callback(self, client, doorbell: Doorbell, message: MQTTMessage):
logger.info("Received answer command for doorbell: {}", doorbell._config.name)
Expand All @@ -336,11 +352,16 @@ def _answer_call_callback(self, client, doorbell: Doorbell, message: MQTTMessage
# Avoid crashing inside the callback, otherwise we lose the MQTT client
try:
doorbell._call_isapi("PUT", url, json.dumps(requestBody))
## Tried to answer the call with SDK instead of ISAPI, but always receive error 23 here??
## result = self._sdk.NET_DVR_SetDVRConfig(self.user_id, 16036, 1, byref(gw),255)
# doorbell.answer_call()
except SDKError as err:
logger.error("Error while answering call: {}", err)
# If error code is 23 on some indoor stations, ISAPI failed, fallback to SDK method
logger.error("Error while answering call with ISAPI: {}", err)
error_code = err.args[1]
if error_code == 23:
try:
logger.debug("Answering call failed with ISAPI method, with error {} fallback to SDK method", error_code)
doorbell.callsignal(2)
except SDKError as err:
logger.error("Error while answering call with SDK: {}", err)

def _caller_info_callback(self, client, doorbell: Doorbell, message: MQTTMessage):
logger.info("Trying to get caller info command for doorbell: {}", doorbell._config.name)
Expand Down

0 comments on commit 403d8e9

Please sign in to comment.