from SimOneIOStruct import *
SimOne_StartCaseFuncType = CFUNCTYPE(c_void_p)
SimOne_StopCaseFuncType = CFUNCTYPE(c_void_p)
SimOne_MainVehicleStatusUpdateFuncType = CFUNCTYPE(c_void_p, POINTER(SimOne_Data_MainVehicle_Status))
SimOne_FrameStartFuncType = CFUNCTYPE(c_void_p, c_int)
SimOne_FrameEndFuncType = CFUNCTYPE(c_void_p, c_int)
G_API_StartCase_CB = None
G_API_StopCase_CB = None
G_API_MainVehicleChangeStatusCB =None
G_API_FrameStart_CB = None
G_API_FrameStop_CB = None
def _api_startcase_cb():
global G_API_StartCase_CB
if G_API_StartCase_CB is None:
return
G_API_StartCase_CB()
def _api_stopcase_cb():
global G_API_StopCase_CB
if G_API_StopCase_CB is None:
return
G_API_StopCase_CB()
def _api_mainvehiclestatusupdate_cb(mainVehicleId, data):
global G_API_MainVehicleChangeStatusCB
if G_API_MainVehicleChangeStatusCB is None:
return
G_API_MainVehicleChangeStatusCB(mainVehicleId, data)
def _api_framestart_cb(frame):
global G_API_FrameStart_CB
if G_API_FrameStart_CB is None:
return
G_API_FrameStart_CB(frame)
def _api_framestop_cb(frame):
global G_API_FrameStop_CB
if G_API_FrameStop_CB is None:
return
G_API_FrameStop_CB(frame)
api_startcase_cb = SimOne_StartCaseFuncType(_api_startcase_cb)
api_stopcase_cb = SimOne_StopCaseFuncType(_api_stopcase_cb)
api_mainvehiclestatusupdate_cb = SimOne_MainVehicleStatusUpdateFuncType(_api_mainvehiclestatusupdate_cb)
api_framestart_cb = SimOne_FrameStartFuncType(_api_framestart_cb)
api_framestop_cb = SimOne_FrameEndFuncType(_api_framestop_cb)
[文档]
def SoAPIGetVersion():
"""
获取当前库的版本号\n
Retrieve the current API version number.\n
此函数用于获取API的当前版本号\n
This function is used to get the current version number of the API.
:return: API的版本号\n
API version number.
:rtype: str
"""
SimoneAPI.GetVersion.restype = c_char_p
return SimoneAPI.GetVersion()
[文档]
def SoSetLogOut(logLevel, *args):
"""
日志设置接口\n
Configure logging interface.\n
此函数用于配置日志系统的日志级别\n
This function is used to configure the log level of the logging system.
:param ESimOne_LogLevel_Type logLevel: 日志级别\n
The log level.
:param args: 额外参数,用于配置日志系统\n
Additional arguments for configuring the logging system.
:return: 执行结果:成功或失败\n
Execution outcome: success or failure.
:rtype: bool
"""
print(logLevel)
list = ""
for arg in args:
list+=arg
logStr = bytes(list,encoding='utf-8')
return SimoneAPI.SetLogOut(logLevel,logStr)
[文档]
def SoInitSimOneAPI(mainVehicleId='0', isFrameSync=0, serverIP='127.0.0.1', port=23789, startcase=0, stopcase=0, registerNodeId=0):
"""
初始化SimOne API\n
Initialize SimOne API for autonomous driving algorithms.\n
此函数用于初始化SimOne API,用于自动驾驶算法的测试和模拟\n
This function is used to initialize the SimOne API for testing and simulating autonomous driving algorithms.
:param str mainVehicleId: 主车ID,默认为'0'\n
Vehicle ID, default is '0'.
:param int isFrameSync: 是否与SimOne同步帧,默认为0\n
Whether to synchronize frames with SimOne, default is 0.
:param str serverIP: BridgeIO服务器IP,默认为'127.0.0.1'\n
BridgeIO server IP, default is '127.0.0.1'.
:param int port: BridgeIO服务器端口,默认为23789\n
BridgeIO server port, default is 23789.
:param int startcase: 案例开始前调用的回调函数,默认为0\n
Callback function to be called before the case starts, default is 0.
:param int stopcase: 案例结束后调用的回调函数,默认为0\n
Callback function to be called after the case ends, default is 0.
:param int registerNodeId: 未使用,默认为0\n
Not in use, default is 0.
:return: 执行结果:成功或失败\n
Execution outcome: success or failure.
:rtype: bool
"""
_input = create_string_buffer(serverIP.encode(), 256)
_mainVehicleId = create_string_buffer(mainVehicleId.encode(), 256)
global G_API_StartCase_CB
global G_API_StopCase_CB
if startcase == 0:
startcase = None
if stopcase == 0:
stopcase = None
G_API_StartCase_CB = startcase
G_API_StopCase_CB = stopcase
SimoneAPI.InitSimOneAPI.restype = c_bool
ret = SimoneAPI.InitSimOneAPI(_mainVehicleId,isFrameSync,_input,port,startcase,stopcase,registerNodeId)
return ret
[文档]
def SoInitSimOneAPIWithTimeOut(mainVehicleId='0', isFrameSync=0, serverIP='127.0.0.1', port=23789, timeOutMS=-1, startcase=0, stopcase=0, registerNodeId=0):
"""
初始化SimOne API 带超时\n
Initialize SimOne API for autonomous driving algorithm with timeout.\n
此函数用于带超时设置的初始化SimOne API,适用于自动驾驶算法测试和模拟\n
This function initializes the SimOne API with a timeout setting, suitable for testing and simulating autonomous driving algorithms.
:param str mainVehicleId: 主车ID,默认为'0'\n
Vehicle ID, default is '0'.
:param int isFrameSync: 是否与SimOne同步帧,默认为0\n
Whether to synchronize frames with SimOne, default is 0.
:param str serverIP: BridgeIO服务器IP,默认为'127.0.0.1'\n
BridgeIO server IP, default is '127.0.0.1'.
:param int port: BridgeIO服务器端口,默认为23789\n
BridgeIO server port, default is 23789.
:param int timeOutMS: 超时设置,默认为-1\n
Timeout setting, default is -1.
:param int startcase: 案例开始前调用的回调函数,默认为0\n
Callback function to be called before the case starts, default is 0.
:param int stopcase: 案例结束后调用的回调函数,默认为0\n
Callback function to be called after the case ends, default is 0.
:param int registerNodeId: 未使用,默认为0\n
Not in use, default is 0.
:return: 执行结果:成功或失败\n
Execution outcome: success or failure.
:rtype: bool
"""
_input = create_string_buffer(serverIP.encode(), 256)
_mainVehicleId = create_string_buffer(mainVehicleId.encode(), 256)
global G_API_StartCase_CB
global G_API_StopCase_CB
if startcase == 0:
startcase = None
if stopcase == 0:
stopcase = None
G_API_StartCase_CB = startcase
G_API_StopCase_CB = stopcase
SimoneAPI.InitSimOneAPI.restype = c_bool
ret = SimoneAPI.InitSimOneAPIWithTimeOut(_mainVehicleId,isFrameSync,_input,port,timeOutMS,startcase,stopcase,registerNodeId)
return ret
[文档]
def SoInitSimOneAPIEx(vehicle_ids, isFrameSync=0, serverIP='127.0.0.1', port=23789, startcase=0, stopcase=0, registerNodeId=0):
"""
多车版本-初始化SimOne API\n
Initialize SimOne API for multi-vehicle version in autonomous driving algorithm.\n
此函数用于初始化SimOne API,适用于多车版本的自动驾驶算法测试和模拟\n
This function initializes the SimOne API for multi-vehicle version, suitable for testing and simulating autonomous driving algorithms.
:param list vehicle_ids: 主车ID列表,必须为数字字符串\n
List of main vehicle IDs, must be digit strings.
:param int isFrameSync: 是否与SimOne同步帧,默认为0\n
Whether to synchronize frames with SimOne, default is 0.
:param str serverIP: BridgeIO服务器IP,默认为'127.0.0.1'\n
BridgeIO server IP, default is '127.0.0.1'.
:param int port: BridgeIO服务器端口,默认为23789\n
BridgeIO server port, default is 23789.
:param int startcase: 案例开始前调用的回调函数,默认为0\n
Callback function to be called before the case starts, default is 0.
:param int stopcase: 案例结束后调用的回调函数,默认为0\n
Callback function to be called after the case ends, default is 0.
:param int registerNodeId: 未使用,默认为0\n
Not in use, default is 0.
:return: 执行结果:成功或失败\n
Execution outcome: success or failure.
:rtype: bool
"""
if type(vehicle_ids) is not list:
print("vehicle_ids must be list type")
return False
for item in vehicle_ids:
if not item.isdigit():
print("item not is digit:{}".format(item))
return False
# print(item)
_input = create_string_buffer(serverIP.encode(), 256)
# 车辆ID列表
count = len(vehicle_ids)
# 将车辆ID列表转换为C所需的格式
main_vehicle_id_list = (c_char_p * len(vehicle_ids))()
main_vehicle_id_list[:] = [c_char_p(vehicle_id.encode()) for vehicle_id in vehicle_ids]
global G_API_StartCase_CB
global G_API_StopCase_CB
if startcase == 0:
startcase = None
if stopcase == 0:
stopcase = None
G_API_StartCase_CB = startcase
G_API_StopCase_CB = stopcase
SimoneAPI.InitSimOneAPI.restype = c_bool
ret = SimoneAPI.InitSimOneAPIEx(main_vehicle_id_list, count, isFrameSync,_input,port,startcase,stopcase,registerNodeId)
return ret
[文档]
def SoInitSimOneAPIExWithTimeOut(vehicle_ids, isFrameSync=0, serverIP='127.0.0.1', port=23789, timeOutMS=-1, startcase=0, stopcase=0, registerNodeId=0):
"""
带超时的多车版本初始化SimOne API\n
Initialize SimOne API for multi-vehicle version with timeout in autonomous driving algorithm.\n
此函数用于带超时设置的多车版本SimOne API初始化,适用于自动驾驶算法的测试和模拟\n
This function initializes the SimOne API for multi-vehicle version with a timeout setting, suitable for testing and simulating autonomous driving algorithms.
:param list vehicle_ids: 车辆ID列表,必须为数字字符串\n
List of vehicle IDs, must be digit strings.
:param int isFrameSync: 是否与SimOne同步帧,默认为0\n
Whether to synchronize frames with SimOne, default is 0.
:param str serverIP: BridgeIO服务器IP,默认为'127.0.0.1'\n
BridgeIO server IP, default is '127.0.0.1'.
:param int port: BridgeIO服务器端口,默认为23789\n
BridgeIO server port, default is 23789.
:param int timeOutMS: 超时设置,默认为-1\n
Timeout setting, default is -1.
:param int startcase: 案例开始前调用的回调函数,默认为0\n
Callback function to be called before the case starts, default is 0.
:param int stopcase: 案例结束后调用的回调函数,默认为0\n
Callback function to be called after the case ends, default is 0.
:param int registerNodeId: 未使用,默认为0\n
Not in use, default is 0.
:return: 执行结果:成功或失败\n
Execution outcome: success or failure.
:rtype: bool
"""
if type(vehicle_ids) is not list:
print("vehicle_ids must be list type")
return False
for item in vehicle_ids:
if not item.isdigit():
print("item not is digit:{}".format(item))
return False
# print(item)
_input = create_string_buffer(serverIP.encode(), 256)
# 车辆ID列表
count = len(vehicle_ids)
# 将车辆ID列表转换为C所需的格式
main_vehicle_id_list = (c_char_p * len(vehicle_ids))()
main_vehicle_id_list[:] = [c_char_p(vehicle_id.encode()) for vehicle_id in vehicle_ids]
global G_API_StartCase_CB
global G_API_StopCase_CB
if startcase == 0:
startcase = None
if stopcase == 0:
stopcase = None
G_API_StartCase_CB = startcase
G_API_StopCase_CB = stopcase
SimoneAPI.InitSimOneAPI.restype = c_bool
ret = SimoneAPI.InitSimOneAPIExWithTimeOut(main_vehicle_id_list, count, isFrameSync,_input,port,timeOutMS,startcase,stopcase,registerNodeId)
return ret
[文档]
def SoTerminateSimOneAPI():
"""
退出API服务\n
Stop SimOne API service.\n
此函数用于停止并退出SimOne API服务,适用于自动驾驶算法测试和模拟后的资源释放\n
This function is used to stop and exit the SimOne API service, suitable for releasing resources after testing and simulating autonomous driving algorithms.
:return: 执行结果:成功或失败\n
Execution outcome: success or failure.
:rtype: bool
"""
SimoneAPI.TerminateSimOneAPI.restype = c_bool
return SimoneAPI.TerminateSimOneAPI()
[文档]
def SoAPIGetCaseInfo(data):
"""
获取案例详情\n
Get detailed information about the case.\n
此函数用于获取当前SimOne案例的详细信息,包括案例名称、案例ID等\n
This function retrieves detailed information about the current SimOne case, including case name, case ID, etc.
:param SimOne_Data_CaseInfo data: 存储案例信息的数据结构\n
The data structure storing case information.
:return: 执行结果:成功或失败\n
Execution outcome: success or failure.
:rtype: bool
"""
SimoneAPI.GetCaseInfo.restype = c_bool
return SimoneAPI.GetCaseInfo(pointer(data))
[文档]
def SoGetCaseRunStatus():
"""
获取案例运行状态\n
Get the current running status of the case.\n
此函数用于查询SimOne案例的当前运行状态,如是否正在运行或已停止\n
This function is used to query the current running status of the SimOne case, such as whether it is running or has stopped.
:return: 案例的运行状态,如正在运行或已停止\n
The running status of the case, such as running or stopped.
:rtype: ESimOne_Case_Status
"""
SimoneAPI.GetCaseRunStatus.restype = c_int
return SimoneAPI.GetCaseRunStatus()
[文档]
def SoGetMainVehicleList(data):
"""
获取主车信息列表\n
Retrieve the list of main vehicle information.\n
此函数用于获取SimOne环境中所有主车的信息列表,包括车辆的ID、数量、类型等\n
This function is used to retrieve a list of information for all main vehicles in the SimOne environment, including vehicle ID, number, type, etc.
:param SimOne_Data_MainVehicle_Info data: 用于存储主车信息的数据结构\n
The data structure used to store main vehicle information.
:return: 执行结果:成功或失败\n
Execution outcome: success or failure.
:rtype: bool
"""
SimoneAPI.GetMainVehicleList.restype = c_bool
return SimoneAPI.GetMainVehicleList(pointer(data))
[文档]
def SoAPIWait():
"""
获取当前帧号\n
Retrieve the current frame number.\n
当SoInitSimOneAPI的参数isFrameSync设置为true时,此函数用于获取SimOne环境中的当前帧号\n
This function is used to obtain the current frame number in the SimOne environment when the 'isFrameSync' parameter of SoInitSimOneAPI is set to true.
:return: 当前帧号\n
The current frame number.
:rtype: int
"""
SimoneAPI.Wait.restype = c_int
return SimoneAPI.Wait()
[文档]
def SoAPINextFrame(frame):
"""
进行下一帧\n
Proceed to the next frame in a frame-synchronized scene.\n
在帧同步的场景中使用,此函数用于将SimOne环境的执行推进到下一帧\n
This function is used in frame-synchronized scenes to advance the execution of the SimOne environment to the next frame. 当SoInitSimOneAPI的参数isFrameSync设置为true时使用。Use when the 'isFrameSync' parameter of SoInitSimOneAPI is set to true.
:param int frame: 当前帧号,由SoAPIWait返回\n
The current frame number, returned by SoAPIWait.
"""
SimoneAPI.NextFrame.restype = c_void_p
return SimoneAPI.NextFrame(frame)
[文档]
def SoAPIPause():
"""
暂停当前运行案例\n
Pause the current running case.\n
此函数用于暂停SimOne环境中的当前执行,特别适用于非帧同步调试场景\n
This function is used to pause the current execution in the SimOne environment, particularly suited for non-frame-synchronized debugging scenarios.
:return: 暂停操作的返回状态,通常为0\n
The return status of the pause operation, typically 0.
:rtype: int
"""
SimoneAPI.Pause.restype = c_int
return SimoneAPI.Pause()
[文档]
def SoAPIContinue():
"""
继续运行当前处于暂停状态的案例\n
Continue to run the current case which is in pause.\n
此函数用于在非帧同步调试场景中继续SimOne环境中当前暂停的执行\n
This function is used to continue the currently paused execution in the SimOne environment in non-frame-synchronized debugging scenarios.
:return: 继续操作的返回状态,通常为0\n
The return status of the continue operation, typically 0.
:rtype: int
"""
SimoneAPI.Continue.restype = c_int
return SimoneAPI.Continue()
[文档]
def SoAPISetFrameCB(startcb, stopcb):
"""
在仿真场景中为每个帧设置回调函数,在每个帧的开始和结束时调用指定的回调函数\n
Register callback functions to be called at the beginning and end of each frame in a simulation scene.
:param func startcb: 每帧开始时调用的回调函数\n
Callback function called at the beginning of each frame.
:param func stopcb: 每帧结束时调用的回调函数\n
Callback function called at the end of each frame.
:return: 设置回调函数的执行结果,成功或失败\n
The execution outcome of setting the callback functions, success or failure.
:rtype: bool
"""
SimoneAPI.SetFrameCB.restype = c_bool
global G_API_FrameStart_CB
global G_API_FrameStop_CB
if startcb == 0:
startcb = None
if stopcb == 0:
stopcb = None
G_API_FrameStart_CB = startcb
G_API_FrameStop_CB = stopcb
ret = SimoneAPI.SetFrameCB(api_framestart_cb, api_framestop_cb)
return ret
[文档]
def SoGetMainVehicleStatus(mainVehicleId, data):
"""
获取指定主车的状态信息\n
Retrieve the status information of the specified main vehicle.
:param str mainVehicleId: 主车的唯一标识符\n
The unique identifier of the main vehicle.
:param SimOne_Data_MainVehicle_Status data: 用于接收主车状态信息的数据结构\n
Data structure to receive the main vehicle's status information.
:return: 获取状态信息的执行结果,成功或失败\n
Execution outcome of retrieving the status information, success or failure.
:rtype: bool
"""
SimoneAPI.GetMainVehicleStatus.restype = c_bool
return SimoneAPI.GetMainVehicleStatus(mainVehicleId, pointer(data))
[文档]
def SoAPISetMainVehicleStatusUpdateCB(cb):
"""
注册用于获取主车状态更新的回调函数\n
Register a callback function for receiving updates on the main vehicle's status.
:param func cb: 用于接收主车状态更新的回调函数\n
Callback function that will be invoked with updates on the main vehicle's status.
:return: 注册回调函数的执行结果,成功或失败\n
Execution outcome of registering the callback function, success or failure.
:rtype: bool
"""
SimoneAPI.SetMainVehicleStatusUpdateCB.restype = c_bool
global G_API_MainVehicleChangeStatusCB
if cb == 0:
cb = None
G_API_MainVehicleChangeStatusCB = cb
return SimoneAPI.SetMainVehicleStatusUpdateCB(api_mainvehiclestatusupdate_cb)
[文档]
def SoGetHDMapData(hdMap):
"""
获取高精度地图元数据信息\n
Retrieve high-precision map metadata information.
:param SimOne_Data_Map hdMap: 高精度地图的查询数据\n
Query data for high-precision map retrieval.
:return: 获取高精度地图数据的执行结果,成功或失败\n
Execution outcome of retrieving high-precision map data, success or failure.
:rtype: bool
"""
SimoneAPI.GetHDMapData.restype = c_bool
return SimoneAPI.GetHDMapData(pointer(hdMap))