44from enum import IntEnum
55from pathlib import Path
66
7- ERROR_CODES = {
8- 0 : "Successful execution" ,
9- 3100 : "Frequency must be between 0.3 and 3 GHz, inclusive" ,
10- 3101 : "Antenna heigh must be >= 0 meters" ,
11- 3102 : "Street width must be > 0 meters" ,
12- 3103 : "Representative clutter height must be > 0 meters" ,
13- 3104 : "Invalid value for clutter type" ,
14- 3200 : "Frequency must be between 2 and 67 GHz, inclusive" ,
15- 3201 : "Path distance must be >= 0.25 km" ,
16- 3202 : "Percentage must be between 0 and 100" ,
17- 3300 : "Frequency must be between 10 and 100 GHz, inclusive" ,
18- 3301 : "Elevation angle must be between 0 and 100 GHz, inclusive" ,
19- 3302 : "Percentage must be between 0 and 100, inclusive" ,
20- }
21-
227
238class ClutterType (IntEnum ):
249 WaterSea = 1
@@ -31,11 +16,6 @@ class ClutterType(IntEnum):
3116
3217# Load the compiled library
3318lib_name = "P2108"
34- if sys .maxsize > 2 ** 32 :
35- lib_name += "x64"
36- else :
37- # note: 32-bit python is needed to load 32-bit lib.
38- lib_name += "x86"
3919if platform .uname ()[0 ] == "Windows" :
4020 lib_name += ".dll"
4121elif platform .uname ()[0 ] == "Linux" :
@@ -73,18 +53,30 @@ class ClutterType(IntEnum):
7353 c_int ,
7454 POINTER (c_double ),
7555)
56+ lib .GetReturnStatusCharArray .restype = POINTER (c_char_p )
57+ lib .GetReturnStatusCharArray .argtypes = (c_int ,)
58+ lib .FreeReturnStatusCharArray .restype = None
59+ lib .FreeReturnStatusCharArray .argtypes = (POINTER (c_char_p ),)
60+
7661
62+ def err_check (rtn_code : int ) -> None :
63+ """Parse the library's return code and raise an error if one occurred.
7764
78- def err_check (error_code : int ) -> None :
79- """ """
80- ec = error_code
81- if ec == 0 :
65+ Returns immediately for `rtn_code == 0`, otherwise retrieves the
66+ status message string from the underlying library and raises a
67+ RuntimeError with the status message.
68+
69+ :param rtn_code: Integer return code from the underlying library.
70+ :raises RuntimeError: For any non-zero inputs.
71+ :return: None
72+ """
73+ if rtn_code == 0 :
8274 return
83- if ec in ERROR_CODES :
84- # All errors as of v1.0 pertain to inputs out-of-range
85- raise ValueError (ec )
8675 else :
87- raise Exception (f"ITS.ITU.PSeries.P2108 returned unknown error { ec } " )
76+ msg = lib .GetReturnStatusCharArray (c_int (rtn_code ))
77+ msg_str = cast (msg , c_char_p ).value .decode ("utf-8" )
78+ lib .FreeReturnStatusCharArray (msg )
79+ raise RuntimeError (msg_str )
8880
8981
9082def HeightGainTerminalCorrectionModel (
0 commit comments