|
@@ -1,6 +1,7 @@
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import asyncio
|
|
import asyncio
|
|
|
|
|
+import logging
|
|
|
import os
|
|
import os
|
|
|
import socket
|
|
import socket
|
|
|
import threading
|
|
import threading
|
|
@@ -41,6 +42,7 @@ POINT_OBJECT_TYPES = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
_BACNET_LOCK = threading.Lock()
|
|
_BACNET_LOCK = threading.Lock()
|
|
|
|
|
+logger = logging.getLogger("uvicorn.error")
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
@@ -75,6 +77,14 @@ async def read_property_direct(
|
|
|
property_name: str,
|
|
property_name: str,
|
|
|
array_index: int | None = None,
|
|
array_index: int | None = None,
|
|
|
) -> Any:
|
|
) -> Any:
|
|
|
|
|
+ logger.info(
|
|
|
|
|
+ "BACnet ReadProperty target=%s object_type=%s object_id=%s property=%s array_index=%s",
|
|
|
|
|
+ address,
|
|
|
|
|
+ object_type,
|
|
|
|
|
+ object_id,
|
|
|
|
|
+ property_name,
|
|
|
|
|
+ array_index,
|
|
|
|
|
+ )
|
|
|
value = await bacnet.this_application.app.read_property(
|
|
value = await bacnet.this_application.app.read_property(
|
|
|
Address(address),
|
|
Address(address),
|
|
|
ObjectIdentifier((bac0_object_type(object_type), object_id)),
|
|
ObjectIdentifier((bac0_object_type(object_type), object_id)),
|
|
@@ -82,6 +92,15 @@ async def read_property_direct(
|
|
|
array_index,
|
|
array_index,
|
|
|
)
|
|
)
|
|
|
if isinstance(value, ErrorRejectAbortNack):
|
|
if isinstance(value, ErrorRejectAbortNack):
|
|
|
|
|
+ logger.error(
|
|
|
|
|
+ "BACnet ReadProperty returned error target=%s object_type=%s object_id=%s property=%s array_index=%s error=%s",
|
|
|
|
|
+ address,
|
|
|
|
|
+ object_type,
|
|
|
|
|
+ object_id,
|
|
|
|
|
+ property_name,
|
|
|
|
|
+ array_index,
|
|
|
|
|
+ value,
|
|
|
|
|
+ )
|
|
|
raise BacnetCommunicationError(str(value))
|
|
raise BacnetCommunicationError(str(value))
|
|
|
return value
|
|
return value
|
|
|
|
|
|
|
@@ -194,6 +213,13 @@ async def read_points_async(request: BacnetPointReadRequest) -> list[dict[str, A
|
|
|
local_ip = local_bacnet_ip(request.ip, request.port)
|
|
local_ip = local_bacnet_ip(request.ip, request.port)
|
|
|
local_port = get_free_udp_port()
|
|
local_port = get_free_udp_port()
|
|
|
points: list[dict[str, Any]] = []
|
|
points: list[dict[str, Any]] = []
|
|
|
|
|
+ logger.info(
|
|
|
|
|
+ "BACnet read_points start target=%s local_ip=%s local_port=%s points=%s",
|
|
|
|
|
+ address,
|
|
|
|
|
+ local_ip,
|
|
|
|
|
+ local_port,
|
|
|
|
|
+ len(request.points),
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
with warnings.catch_warnings():
|
|
with warnings.catch_warnings():
|
|
|
warnings.filterwarnings("ignore", message=BAC0_REGISTERED_WARNING)
|
|
warnings.filterwarnings("ignore", message=BAC0_REGISTERED_WARNING)
|
|
@@ -214,6 +240,13 @@ async def search_points_async(request: BacnetPointSearchRequest) -> list[dict[st
|
|
|
local_ip = local_bacnet_ip(request.ip, request.port)
|
|
local_ip = local_bacnet_ip(request.ip, request.port)
|
|
|
local_port = get_free_udp_port()
|
|
local_port = get_free_udp_port()
|
|
|
points: list[dict[str, Any]] = []
|
|
points: list[dict[str, Any]] = []
|
|
|
|
|
+ logger.info(
|
|
|
|
|
+ "BACnet search_points start target=%s local_ip=%s local_port=%s device_id=%s",
|
|
|
|
|
+ address,
|
|
|
|
|
+ local_ip,
|
|
|
|
|
+ local_port,
|
|
|
|
|
+ request.bacnet_device_id,
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
with warnings.catch_warnings():
|
|
with warnings.catch_warnings():
|
|
|
warnings.filterwarnings("ignore", message=BAC0_REGISTERED_WARNING)
|
|
warnings.filterwarnings("ignore", message=BAC0_REGISTERED_WARNING)
|
|
@@ -227,6 +260,7 @@ async def search_points_async(request: BacnetPointSearchRequest) -> list[dict[st
|
|
|
"objectList",
|
|
"objectList",
|
|
|
array_index=0,
|
|
array_index=0,
|
|
|
)
|
|
)
|
|
|
|
|
+ logger.info("BACnet objectList count target=%s count=%s", address, object_count)
|
|
|
except Exception as exc:
|
|
except Exception as exc:
|
|
|
raise BacnetCommunicationError(
|
|
raise BacnetCommunicationError(
|
|
|
f"no response from BACnet device {address} while reading "
|
|
f"no response from BACnet device {address} while reading "
|
|
@@ -265,8 +299,10 @@ def read_points(request: BacnetPointReadRequest) -> dict[str, Any]:
|
|
|
with _BACNET_LOCK:
|
|
with _BACNET_LOCK:
|
|
|
points = run_bacnet(read_points_async(request))
|
|
points = run_bacnet(read_points_async(request))
|
|
|
except BacnetCommunicationError as exc:
|
|
except BacnetCommunicationError as exc:
|
|
|
|
|
+ logger.exception("BACnet read_points communication failed device=%s", device_payload(request))
|
|
|
return response_payload(1, str(exc), {"device": device_payload(request), "points": []})
|
|
return response_payload(1, str(exc), {"device": device_payload(request), "points": []})
|
|
|
except Exception as exc:
|
|
except Exception as exc:
|
|
|
|
|
+ logger.exception("BACnet read_points failed device=%s", device_payload(request))
|
|
|
return response_payload(1, str(exc), {"device": device_payload(request), "points": []})
|
|
return response_payload(1, str(exc), {"device": device_payload(request), "points": []})
|
|
|
return response_payload(0, "success", {"device": device_payload(request), "points": points})
|
|
return response_payload(0, "success", {"device": device_payload(request), "points": points})
|
|
|
|
|
|
|
@@ -276,7 +312,9 @@ def search_points(request: BacnetPointSearchRequest) -> dict[str, Any]:
|
|
|
with _BACNET_LOCK:
|
|
with _BACNET_LOCK:
|
|
|
points = run_bacnet(search_points_async(request))
|
|
points = run_bacnet(search_points_async(request))
|
|
|
except BacnetCommunicationError as exc:
|
|
except BacnetCommunicationError as exc:
|
|
|
|
|
+ logger.exception("BACnet search_points communication failed device=%s", device_payload(request))
|
|
|
return response_payload(1, str(exc), {"device": device_payload(request), "points": []})
|
|
return response_payload(1, str(exc), {"device": device_payload(request), "points": []})
|
|
|
except Exception as exc:
|
|
except Exception as exc:
|
|
|
|
|
+ logger.exception("BACnet search_points failed device=%s", device_payload(request))
|
|
|
return response_payload(1, str(exc), {"device": device_payload(request), "points": []})
|
|
return response_payload(1, str(exc), {"device": device_payload(request), "points": []})
|
|
|
return response_payload(0, "success", {"device": device_payload(request), "points": points})
|
|
return response_payload(0, "success", {"device": device_payload(request), "points": points})
|