-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6467c91
commit 056e178
Showing
156 changed files
with
17,317 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#忽略gitignore文件 | ||
#.gitignore | ||
#忽略idea setting files | ||
.idea | ||
# python cash files | ||
*.pyc | ||
__pycash__ | ||
# mac default files | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Simulation Platform Library | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
platform is an HTTP library, written in Python. | ||
usage: | ||
>>> import ADCPlatform | ||
>>> ADCPlatform.start('20190812', '123456') | ||
>>> print ADCPlatform.get_control_data() | ||
>>> ADCPlatform.stop() | ||
:copyright: (c) 2019 by Junyu Mei. | ||
:license: CATARC Tianjin. | ||
""" | ||
|
||
|
||
from . import __version__ | ||
from .api import start, stop, get_image, get_control_data, get_data, get_sensors, start_task,\ | ||
control,brake | ||
from .type_node import DataType, ImageType, SignBoard | ||
#from .tools import convert_image_to_numpy_ndarray, ThreadWithExc | ||
|
||
|
||
"""A client to operation ADCPlatform function | ||
Some operation like controller vehicle, get Image and Data from vehicle sensor. | ||
""" | ||
|
||
|
||
def __init__(self, proxy=None, __cookie=None): | ||
self.proxy = proxy | ||
self.__cookie = __cookie | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python | ||
# | ||
# 版本说明文件 | ||
# 当前版本1.0.0 | ||
# 更新历史记录 | ||
# 无 | ||
# 功能: | ||
# 实现对接模拟仿真平台 | ||
|
||
__title__ = 'ADCPlatform' | ||
__description__ = 'Python SDK form Simulation Platform' | ||
__version__ = '1.0.0' | ||
__author__ = 'Junyu Mei' | ||
__author_email__ = '[email protected]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from . import business | ||
from .type_node import DataType, ImageType, SignBoard | ||
|
||
|
||
# 开启 | ||
def start(url, username, password): | ||
business.__server_url = url | ||
result = business.__login(username, password) | ||
if result['RespCode'] == 6 and business.__get_task(): | ||
return True | ||
else: | ||
stop() | ||
return False | ||
|
||
|
||
# 关闭 | ||
def stop(): | ||
business.__logout() | ||
|
||
|
||
# 获取当前车辆安装传感器数据 | ||
def get_sensors(): | ||
return business.__getSensors() | ||
|
||
|
||
# 启动场景 | ||
def start_task(): | ||
return business.__start_task() | ||
|
||
|
||
# 获取图片 | ||
def get_image(sensorId): | ||
return business.__get_image(sensorId) | ||
|
||
# 获取Data数据 | ||
def get_data(sensorId): | ||
return business.__get_data(sensorId) | ||
|
||
|
||
# 第一题发送标志牌信息 | ||
def submit_sign_board(sign_board1: SignBoard, sign_board2: SignBoard, sign_board3: SignBoard): | ||
return business.__send_command('Sign', str(sign_board1.value + 1) + '/' + str(sign_board2.value + 1) + '/' | ||
+ str(sign_board3.value + 1)) | ||
|
||
|
||
# 获取控制数据 | ||
def get_control_data(): | ||
return business.__get_data(business.simtask['Sences']['Vehicles'][0]['ID']) | ||
|
||
|
||
# 控制车辆 | ||
def control(throttle, steering, brake, gear): | ||
# business.__send_command('Throttle', '1') | ||
business.__send_command('control', str(throttle) + '/' + str(steering) + '/' + str(brake) + '/' + str(gear)) | ||
|
||
|
||
# 刹车 | ||
def brake(brake): | ||
# business.__send_command('Throttle', '1') | ||
business.__send_command('brake', str(brake)) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
from . import request_basic | ||
from . import request_node | ||
from . import type_node | ||
from io import BytesIO | ||
|
||
# 存储服务器地址 | ||
__server_url = '' | ||
|
||
# 协议头 | ||
__protocol = 'https://' | ||
|
||
# 存储当前的TaskInfo信息 | ||
simtask = None | ||
|
||
|
||
# 登录接口,返回登录信息 | ||
def __login(username, password): | ||
data = {"account": username, | ||
"password": password} | ||
result = request_basic.__post(__server_url + "/sys/Login", data) | ||
request_basic.__APNToken = result.json()['Data']['token'] | ||
return result.json() | ||
|
||
|
||
# 登出接口,Bool型返回值, 成功返回True,否则返回Flase | ||
def __logout(): | ||
request_basic.__get_with_json(__server_url + "/sys/LogOut", None) | ||
request_basic.__cookies = None | ||
request_basic.__APNToken = None | ||
|
||
|
||
# 发送命令接口,Bool型返回值, 成功返回True,否则返回Flase | ||
def __send_command(command, value): | ||
global simtask | ||
if not simtask: | ||
return False | ||
vehicle_id = simtask['Sences']['Vehicles'][0]['ID'] | ||
result = request_node.__get("/Command/" + command + "/" + value, None) | ||
if result.status_code == 200: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
# 获取当前正在执行的任务数据 | ||
def __get_task(): | ||
result = request_basic.__get_token(__server_url + "Question/GetUserRunningSimTask", None) | ||
task = result.json() | ||
if task['RespCode'] == 1: | ||
# 设置当前任务Token | ||
request_node.__APNToken = task['Data']['Sences']['Token'] | ||
# 设置当前任务APN | ||
request_node.__NodeAPN = __protocol + task['Data']['Sences']['APN'] + ":" + str(task['Data']['Sences']['HttpPort']) | ||
global simtask | ||
simtask = task['Data'] | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
# 获取车辆安装传感器数据 | ||
def __getSensors(): | ||
if not simtask: | ||
return None | ||
sensors = [] | ||
for s in simtask['Sences']['Vehicles'][0]['Sensors']: | ||
sensor = type_node.SensorInfo(s['ID'],s['Name']) | ||
sensors.append(sensor) | ||
return sensors | ||
|
||
|
||
# 发送开始测试指令 | ||
def __start_task(): | ||
result = request_node.__get("/Command/start/1", None) | ||
if result.status_code == 200: | ||
return True | ||
return False | ||
|
||
|
||
# 获取图片接口,返回ImagePackage | ||
def __get_image(objectId): | ||
result = request_node.__get("/widc/data/" + str(objectId), None) | ||
if result==None or len(result.content) == 0: | ||
return None | ||
image_package = type_node.ImagePackage() | ||
image_package.timestamp = result.headers['TimeStamp'] | ||
image_package.byte = BytesIO(result.content) | ||
return image_package | ||
|
||
|
||
# 获取数据接口,返回DataPackage | ||
def __get_data(objectId): | ||
result = request_node.__get("/widc/data/" + str(objectId), None) | ||
if result==None or len(result.content) == 0: | ||
return None | ||
data_package = type_node.DataPackage() | ||
data_package.timestamp = result.headers['TimeStamp'] | ||
data_package.json = result.json() | ||
return data_package | ||
|
||
|
||
# 错误处理接口 | ||
def __error(result): | ||
return result['respMsg'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import requests | ||
|
||
# 设置的代理 | ||
__proxy = None | ||
# 设置的Cookies | ||
__cookies = None | ||
# 设置请求头 | ||
__APNToken = None | ||
|
||
# requests.packages.urllib3.disable_warnings() | ||
|
||
|
||
# post请求 | ||
def __post(url, json_data): | ||
return requests.post(url, None, json_data, proxies=__proxy, cookies=__cookies) | ||
|
||
|
||
# get请求带cookies | ||
def __get(url, params): | ||
return requests.get(url, params, proxies=__proxy, cookies=__cookies) | ||
|
||
|
||
# post请求返回json | ||
def __post_with_json(url, json_data): | ||
return requests.post(url, None, json_data, proxies=__proxy, cookies=__cookies).json() | ||
|
||
|
||
# get请求返回json | ||
def __get_with_json(url, params): | ||
return requests.get(url, params, proxies=__proxy, cookies=__cookies).json() | ||
|
||
|
||
# get请求带token | ||
def __get_token(url, params): | ||
__headers = { | ||
'token': __APNToken | ||
} | ||
return requests.get(url, params, proxies=__proxy, headers=__headers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import requests | ||
|
||
# 存储node节点连接ip | ||
__NodeAPN = None | ||
|
||
# 设置的代理 | ||
__proxy = None | ||
|
||
# 设置请求头 | ||
__APNToken = None | ||
# 会话 | ||
__session = requests.Session() | ||
|
||
requests.packages.urllib3.disable_warnings() | ||
|
||
|
||
# get请求 | ||
def __get(url, params): | ||
__headers = { | ||
'APNToken': __APNToken | ||
} | ||
|
||
return __session.get(__NodeAPN + url, params=params, headers=__headers, verify=False) | ||
|
||
|
||
# get请求返回json | ||
def __get_with_json(url, params): | ||
__headers = { | ||
'APNToken': __APNToken | ||
} | ||
return __session.get(__NodeAPN + url, params=params, headers=__headers, verify=False).json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# {'RespMsg': None, 'Data': {'TaskInfo': {'ID': 10226}, 'Sences': {'Vehicles': [{'Type': 5, 'Sensors': [{'Type': 1, 'Name': 'Lidar-1', 'ID': 10101, 'APN': '10.10.10.8', 'Token': '/7C7VNxYUPBjFq6AOVLg4w=='}, {'Type': 2, 'Name': 'Radar-1', 'ID': 10102, 'APN': '10.10.10.8', 'Token': '/7C7VNxYUPBjFq6AOVLg4w=='}, {'Type': 3, 'Name': 'Camera-1', 'ID': 10103, 'APN': '10.10.10.8', 'Token': '/7C7VNxYUPBjFq6AOVLg4w=='}, {'Type': 5, 'Name': 'Camera-2', 'ID': 10104, 'APN': '10.10.10.8', 'Token': '/7C7VNxYUPBjFq6AOVLg4w=='}], 'ID': 101, 'APN': '10.10.10.8', 'Token': '/7C7VNxYUPBjFq6AOVLg4w=='}], 'ID': 1, 'APN': '10.10.10.8', 'Token': '/7C7VNxYUPBjFq6AOVLg4w=='}}, 'OK': True, 'RespCode': 1} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#coding=utf-8 | ||
from PIL import Image | ||
import numpy | ||
import threading | ||
import ctypes | ||
from time import sleep | ||
|
||
def convert_image_to_numpy_ndarray(imageframe_byte): | ||
#image2 = Image.fromarray(array) # image2 is a PIL image,array is a numpy | ||
#array | ||
return numpy.array(Image.open(imageframe_byte)) | ||
|
||
def _async_raise(tid, exctype:'exctype'): | ||
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), | ||
ctypes.py_object(exctype)) | ||
if res == 0: | ||
raise ValueError("invalid thread id") | ||
elif res != 1: | ||
# "if it returns a number greater than one, you're in trouble, | ||
# and you should call it again with exc=NULL to revert the effect" | ||
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), None) | ||
raise SystemError("PyThreadState_SetAsyncExc failed") | ||
|
||
class ThreadWithExc(threading.Thread): | ||
|
||
def _get_my_tid(self): | ||
if not self.isAlive(): | ||
raise threading.ThreadError("the thread is not active") | ||
|
||
# do we have it cached? | ||
if hasattr(self, "_thread_id"): | ||
return self._thread_id | ||
|
||
# no, look for it in the _active dict | ||
for tid, tobj in threading._active.items(): | ||
if tobj is self: | ||
self._thread_id = tid | ||
return tid | ||
raise AssertionError("could not determine the thread's id") | ||
|
||
def raise_exc(self,excobj): | ||
if self.isAlive(): | ||
_async_raise(self._get_my_tid(),excobj) | ||
|
||
|
||
def stop(self): | ||
self.raise_exc(SystemExit) | ||
while self.isAlive(): | ||
sleep( 0.1 ) | ||
self.raise_exc(SystemExit) | ||
|
||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.