Skip to content

Commit 573a7b0

Browse files
jominki354jominki354
authored andcommitted
web carrot prototype (ajouatom#273)
* web work * web work * web work * web work * web work * web work * web work * web work * web work * web work * web work * web work * web work --------- Co-authored-by: jominki354 <jomin354@gmail.com>
1 parent 52c499f commit 573a7b0

34 files changed

Lines changed: 5534 additions & 1073 deletions

launch_chffrplus.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ function launch {
6767

6868
# handle pythonpath
6969
ln -sfn $(pwd) /data/pythonpath
70-
export PYTHONPATH="$PWD"
70+
PYDEPS="$DIR/pydeps"
71+
mkdir -p "$PYDEPS"
72+
export PYTHONPATH="$PYDEPS:$PWD${PYTHONPATH:+:$PYTHONPATH}"
7173

7274
# hardware specific init
7375
if [ -f /AGNOS ]; then
@@ -94,6 +96,24 @@ function launch {
9496
echo "kaitaistruct installing."
9597
pip install kaitaistruct
9698
fi
99+
if python3 -c "import msgpack" > /dev/null 2>&1; then
100+
echo "msgpack already installed."
101+
else
102+
MSGPACK_WHEEL_DIR="$DIR/third_party/wheels"
103+
if ls "$MSGPACK_WHEEL_DIR"/msgpack-*.whl > /dev/null 2>&1; then
104+
echo "msgpack installing from local wheel to pydeps."
105+
python3 -m pip install --no-index --find-links "$MSGPACK_WHEEL_DIR" --target "$PYDEPS" --upgrade msgpack || python3 -m pip install --target "$PYDEPS" --upgrade msgpack
106+
else
107+
echo "msgpack local wheel missing, installing to pydeps from network."
108+
python3 -m pip install --target "$PYDEPS" --upgrade msgpack
109+
fi
110+
111+
if python3 -c "import msgpack" > /dev/null 2>&1; then
112+
echo "msgpack installed for python3."
113+
else
114+
echo "msgpack install failed for python3."
115+
fi
116+
fi
97117

98118
# events language init
99119
#LANG=$(cat ${PARAMS_ROOT}/d/LanguageSetting)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
"sympy", # rednose + friends
1717
"crcmod", # cars + qcomgpsd
1818
"tqdm", # cars (fw_versions.py) on start + many one-off uses
19+
"msgpack", # realtime broker / carrot live payload transport
1920

2021
# hardwared
2122
"smbus2", # configuring amp
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from .raw_protocol import RAW_MODE, RAW_PROTOCOL_VERSION, RAW_WIRE_FORMAT, build_raw_hello
2+
from .raw_services import DEFAULT_RAW_SERVICES, RAW_CORE_SERVICES, RAW_OPTIONAL_SERVICES, is_supported_raw_service, raw_services
3+
4+
__all__ = [
5+
"DEFAULT_RAW_SERVICES",
6+
"RAW_CORE_SERVICES",
7+
"RAW_MODE",
8+
"RAW_OPTIONAL_SERVICES",
9+
"RAW_PROTOCOL_VERSION",
10+
"RAW_WIRE_FORMAT",
11+
"build_raw_hello",
12+
"is_supported_raw_service",
13+
"raw_services",
14+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
6+
RAW_PROTOCOL_VERSION = 1
7+
RAW_WIRE_FORMAT = "cereal-event-capnp"
8+
RAW_MODE = "raw-capnp-relay"
9+
10+
11+
def build_raw_hello(*, service: str) -> dict[str, Any]:
12+
return {
13+
"type": "hello",
14+
"service": service,
15+
"protocolVersion": RAW_PROTOCOL_VERSION,
16+
"mode": RAW_MODE,
17+
"wireFormat": RAW_WIRE_FORMAT,
18+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from __future__ import annotations
2+
3+
import argparse
4+
import sys
5+
import time
6+
7+
from .raw_services import DEFAULT_RAW_SERVICES, is_supported_raw_service
8+
9+
10+
def main() -> int:
11+
parser = argparse.ArgumentParser(description="Raw capnp relay standalone reader")
12+
parser.add_argument("service", help="service name to subscribe to")
13+
parser.add_argument("--iterations", type=int, default=0, help="0 means forever")
14+
args = parser.parse_args()
15+
16+
service = args.service.strip()
17+
if not is_supported_raw_service(service):
18+
print(f"unsupported raw service: {service}", file=sys.stderr)
19+
print("supported services:", ", ".join(DEFAULT_RAW_SERVICES), file=sys.stderr)
20+
return 2
21+
22+
try:
23+
from cereal import messaging
24+
except Exception as exc:
25+
print(f"messaging import failed: {exc}", file=sys.stderr)
26+
return 1
27+
28+
try:
29+
sock = messaging.sub_sock(service, conflate=True)
30+
except Exception as exc:
31+
print(f"failed to open socket for {service}: {exc}", file=sys.stderr)
32+
return 1
33+
34+
count = 0
35+
while True:
36+
payload = sock.receive(non_blocking=False)
37+
if payload is None:
38+
continue
39+
print(f"{int(time.time() * 1000)} {service} {len(payload)}", flush=True)
40+
count += 1
41+
if args.iterations > 0 and count >= args.iterations:
42+
return 0
43+
44+
45+
if __name__ == "__main__":
46+
raise SystemExit(main())
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from __future__ import annotations
2+
3+
RAW_CORE_SERVICES: tuple[str, ...] = (
4+
"selfdriveState",
5+
"carState",
6+
"controlsState",
7+
"longitudinalPlan",
8+
"liveCalibration",
9+
"modelV2",
10+
"roadCameraState",
11+
"deviceState",
12+
)
13+
14+
RAW_OPTIONAL_SERVICES: tuple[str, ...] = (
15+
"radarState",
16+
"carrotMan",
17+
"gpsLocationExternal",
18+
"lateralPlan",
19+
"liveDelay",
20+
"liveTorqueParameters",
21+
"liveParameters",
22+
"navInstructionCarrot",
23+
"peripheralState",
24+
"wideRoadCameraState",
25+
"carControl",
26+
)
27+
28+
DEFAULT_RAW_SERVICES: tuple[str, ...] = RAW_CORE_SERVICES + RAW_OPTIONAL_SERVICES
29+
30+
31+
def raw_services() -> tuple[str, ...]:
32+
return DEFAULT_RAW_SERVICES
33+
34+
35+
def is_supported_raw_service(service: str) -> bool:
36+
return service in DEFAULT_RAW_SERVICES
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from .camera_ws import CameraWsHub
2+
from .raw_ws import RawWsHub
3+
4+
__all__ = [
5+
"CameraWsHub",
6+
"RawWsHub",
7+
]

0 commit comments

Comments
 (0)