v0.1.7 add remote server, agent, client
This commit is contained in:
parent
b91733c713
commit
63e6ed4ffd
32
README.md
32
README.md
|
|
@ -243,8 +243,38 @@ vin = await uds.read_data_by_identifier(0xF190)
|
|||
print("VIN:", vin.decode(errors="ignore"))
|
||||
````
|
||||
|
||||
## Удалённая работа через внешний сервер
|
||||
### 1. Сервер/Relay
|
||||
На сервере устанавливаем библиотеку carbus-lib, далее запускаем сервер
|
||||
|
||||
## Удалённая работа через TCP (tcp_bridge)
|
||||
carbus-relay-server --host 0.0.0.0 --port 9000
|
||||
или
|
||||
|
||||
python -m carbus_async.remote.server --host 0.0.0.0 --port 9000
|
||||
|
||||
### 2. Агент
|
||||
На машине куда подключен девайс запускаем агента
|
||||
|
||||
carbus-relay-agent --port COM6 --baudrate 115200 --server <IP_СЕРВЕРА>:9000 --serial 5957 --password 1234
|
||||
или
|
||||
|
||||
python -m carbus_async.remote.agent --port COM6 --baudrate 115200 --server <IP_СЕРВЕРА>:9000 --serial 5957 --password 1234
|
||||
|
||||
где
|
||||
|
||||
--server <IP_СЕРВЕРА>:9000 - адрес и порт сервера
|
||||
--serial 5957 - серийный номер девайса
|
||||
--password 1234 - пароль, требуется для получения уделнного доступа
|
||||
|
||||
### 3. Клиент (удалённая машина)
|
||||
Для получения удаленного доступа используем функцию ***open_remote_device***
|
||||
|
||||
````python
|
||||
from carbus_async import open_remote_device
|
||||
dev = await open_remote_device(<IP_СЕРВЕРА>, 9000, serial=5957, password="1234")
|
||||
````
|
||||
|
||||
## Удалённая работа в локальной сети через TCP (tcp_bridge)
|
||||
|
||||
### 1. Сервер (рядом с адаптером)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ async def main(is_debug=False):
|
|||
nominal_bitrate=500_000,
|
||||
)
|
||||
|
||||
await dev.set_terminator(channel=1, enabled=True)
|
||||
await dev.ensure_terminator(channel=1, enabled=True)
|
||||
|
||||
sender = PeriodicCanSender(dev)
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ async def main(is_debug=False):
|
|||
channel=1,
|
||||
can_id=0x123,
|
||||
data=b"\x01\x02\x03\x04\x05\x06\x07\x08",
|
||||
period_s=0.1,
|
||||
period_s=0.05,
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
import asyncio
|
||||
|
||||
from carbus_async import CarBusDevice, PeriodicCanSender, open_remote_device
|
||||
|
||||
|
||||
async def main(is_debug=False):
|
||||
dev = await open_remote_device("84.54.37.149", 9000, serial=5957, password="1234")
|
||||
|
||||
await dev.open_can_channel(
|
||||
channel=1,
|
||||
nominal_bitrate=500_000,
|
||||
)
|
||||
|
||||
await dev.ensure_terminator(channel=1, enabled=True)
|
||||
|
||||
sender = PeriodicCanSender(dev)
|
||||
|
||||
def mod(tick, data):
|
||||
b = bytearray(data)
|
||||
b[0] = tick & 0xFF
|
||||
return bytes(b)
|
||||
|
||||
sender.add(
|
||||
"cnt",
|
||||
channel=1,
|
||||
can_id=0x100,
|
||||
data=b"\x00" * 8,
|
||||
period_s=0.5,
|
||||
modify=mod)
|
||||
|
||||
sender.add(
|
||||
"heartbeat",
|
||||
channel=1,
|
||||
can_id=0x123,
|
||||
data=b"\x01\x02\x03\x04\x05\x06\x07\x08",
|
||||
period_s=0.05,
|
||||
)
|
||||
|
||||
try:
|
||||
await asyncio.Event().wait()
|
||||
finally:
|
||||
await sender.stop_all()
|
||||
await dev.close()
|
||||
|
||||
return
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
|
|
@ -16,7 +16,7 @@ async def main(is_debug=False):
|
|||
)
|
||||
logging.getLogger("carbus_async.wire").setLevel(logging.DEBUG)
|
||||
|
||||
dev = await open_remote_device("127.0.0.1", 9000, serial=5957, password="1234")
|
||||
dev = await open_remote_device("84.54.37.149", 9000, serial=5957, password="1234")
|
||||
|
||||
print(f"Devise SN: {await dev.get_serial()}")
|
||||
|
||||
|
|
@ -36,4 +36,4 @@ async def main(is_debug=False):
|
|||
await dev.close()
|
||||
|
||||
|
||||
asyncio.run(main(is_debug=True))
|
||||
asyncio.run(main())
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||
|
||||
[project]
|
||||
name = "carbus-lib"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
description = "Async CAN / ISO-TP / UDS library for Car Bus Analyzer"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
|
@ -25,3 +25,7 @@ package-dir = {"" = "."}
|
|||
[tool.setuptools.packages.find]
|
||||
where = ["."]
|
||||
include = ["carbus_async*", "isotp_async*", "uds_async*"]
|
||||
|
||||
[project.scripts]
|
||||
carbus-relay-server = "carbus_async.remote.server:main"
|
||||
carbus-relay-agent = "carbus_async.remote.agent:main"
|
||||
Loading…
Reference in New Issue