Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge with upstream #3

Merged
merged 22 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e342bc4
pre-commit: autoupdate hooks (#532)
adeebshihadeh Sep 12, 2023
ff3dbaa
Update README.md (#533)
computerscienceiscool Sep 15, 2023
25cfa64
pre-commit: autoupdate hooks (#535)
adeebshihadeh Sep 19, 2023
aed84ae
services: capitalize constant service list (#534)
sshane Sep 22, 2023
6bd65e7
Bump pandaStates to 10hz (#536)
sshane Sep 22, 2023
b7be4ae
Merge remote-tracking branch 'sunnypilot/master' into master-with-sunny
MiguelFernandezCimp Sep 22, 2023
16f9307
Bringing sunnypilot
MiguelFernandezCimp Sep 25, 2023
8f09a77
Refactor service list and deprecate certain fields
MiguelFernandezCimp Sep 25, 2023
4572558
pre-commit: autoupdate hooks (#538)
adeebshihadeh Sep 26, 2023
b1a1afe
Added reserved fields for body controls (#537)
mitchellgoffpc Sep 27, 2023
acb24ff
zmq: assert the same PID (#540)
fredyshox Oct 2, 2023
4a07275
pre-commit: autoupdate hooks (#541)
adeebshihadeh Oct 3, 2023
3a95c45
Bringing sunnypilot
MiguelFernandezCimp Sep 25, 2023
2dd44c4
Refactor service list and deprecate certain fields
MiguelFernandezCimp Sep 25, 2023
250dd83
Merge remote-tracking branch 'origin/master-with-sunny' into master-w…
devtekve Oct 12, 2023
a0e9693
Bringing sunnypilot's cereal changes aligned
devtekve Oct 12, 2023
348059a
Bringing sunnypilot's cereal changes aligned
devtekve Oct 12, 2023
b5f4b77
Converging cereal changes
devtekve Oct 12, 2023
3c3165b
Merge remote-tracking branch 'sp-priv/master-with-sunny' into master-…
devtekve Oct 12, 2023
cb12905
Merge remote-tracking branch 'sunnypilot/master' into master-with-sunny
devtekve Oct 12, 2023
2f86e38
accidentally duplicated some literals
devtekve Oct 12, 2023
259b7bc
Update log.capnp
devtekve Oct 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 40 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-yaml
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
hooks:
- id: ruff
- repo: local
hooks:
- id: cppcheck
name: cppcheck
entry: cppcheck
language: system
types: [c++]
exclude: '^(messaging/msgq_tests.cc|messaging/test_runner.cc)'
args:
- --error-exitcode=1
- --inline-suppr
- --language=c++
- --force
- --quiet
- -j4
- repo: https://github.com/cpplint/cpplint
rev: 1.6.1
hooks:
- id: cpplint
args:
- --quiet
- --counting=detailed
- --linelength=240
- --filter=-build,-legal,-readability,-runtime,-whitespace,+build/include_subdir,+build/forward_decl,+build/include_what_you_use,+build/deprecated,+whitespace/comma,+whitespace/line_length,+whitespace/empty_if_body,+whitespace/empty_loop_body,+whitespace/empty_conditional_body,+whitespace/forcolon,+whitespace/parens,+whitespace/semicolon,+whitespace/tab,+readability/braces
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
args:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ All `Events` have a `logMonoTime` and a `valid`. Then a big union defines the pa

### Maintaining backwards-compatibility

When making changes to the messaging spec you want to maintain backwards-compatability, such that old logs can
When making changes to the messaging spec you want to maintain backwards-compatibility, such that old logs can
be parsed with a new version of cereal. Adding structs and adding members to structs is generally safe, most other
things are not. Read more details [here](https://capnproto.org/language.html).

Expand Down
2 changes: 1 addition & 1 deletion car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ struct CarState {

# deprecated
errorsDEPRECATED @0 :List(CarEvent.EventName);
brakeLights @19 :Bool;
brakeLightsDEPRECATED @19 :Bool;
sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved
steeringRateLimitedDEPRECATED @29 :Bool;
canMonoTimesDEPRECATED @12: List(UInt64);
}
Expand Down
4 changes: 4 additions & 0 deletions log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,10 @@ struct Event {
livestreamWideRoadEncodeData @121 :EncodeData;
livestreamDriverEncodeData @122 :EncodeData;

customReservedRawData0 @124 :Data;
customReservedRawData1 @125 :Data;
customReservedRawData2 @126 :Data;

# *********** Custom: reserved for forks ***********
controlsStateSP @107 :Custom.ControlsStateSP;
longitudinalPlanSP @108 :Custom.LongitudinalPlanSP;
Expand Down
4 changes: 2 additions & 2 deletions messaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections import deque

from cereal import log
from cereal.services import service_list
from cereal.services import SERVICE_LIST

assert MultiplePublishersError
assert MessagingError
Expand Down Expand Up @@ -180,7 +180,7 @@ def __init__(self, services: List[str], poll: Optional[List[str]] = None,
if addr is not None:
p = self.poller if s not in self.non_polled_services else None
self.sock[s] = sub_sock(s, poller=p, addr=addr, conflate=True)
self.freq[s] = service_list[s].frequency
self.freq[s] = SERVICE_LIST[s].frequency

try:
data = new_message(s)
Expand Down
10 changes: 8 additions & 2 deletions messaging/impl_zmq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <iostream>
#include <cstdlib>
#include <cerrno>
#include <unistd.h>

#include "cereal/services.h"
#include "cereal/messaging/impl_zmq.h"
Expand Down Expand Up @@ -108,14 +109,19 @@ int ZMQPubSocket::connect(Context *context, std::string endpoint, bool check_end
full_endpoint += endpoint;
}

// ZMQ pub sockets cannot be shared between processes, so we need to ensure pid stays the same
pid = getpid();

return zmq_bind(sock, full_endpoint.c_str());
}

int ZMQPubSocket::sendMessage(Message *message){
int ZMQPubSocket::sendMessage(Message *message) {
assert(pid == getpid());
return zmq_send(sock, message->getData(), message->getSize(), ZMQ_DONTWAIT);
}

int ZMQPubSocket::send(char *data, size_t size){
int ZMQPubSocket::send(char *data, size_t size) {
assert(pid == getpid());
return zmq_send(sock, data, size, ZMQ_DONTWAIT);
}

Expand Down
1 change: 1 addition & 0 deletions messaging/impl_zmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ZMQPubSocket : public PubSocket {
private:
void * sock;
std::string full_endpoint;
int pid = -1;
public:
int connect(Context *context, std::string endpoint, bool check_endpoint=true);
int sendMessage(Message *message);
Expand Down
4 changes: 2 additions & 2 deletions messaging/tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

from cereal import log, car
import cereal.messaging as messaging
from cereal.services import service_list
from cereal.services import SERVICE_LIST

events = [evt for evt in log.Event.schema.union_fields if evt in service_list.keys()]
events = [evt for evt in log.Event.schema.union_fields if evt in SERVICE_LIST.keys()]

def random_sock():
return random.choice(events)
Expand Down
8 changes: 4 additions & 4 deletions messaging/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
from parameterized import parameterized

import cereal.services as services
from cereal.services import service_list, RESERVED_PORT, STARTING_PORT
from cereal.services import SERVICE_LIST, RESERVED_PORT, STARTING_PORT


class TestServices(unittest.TestCase):

@parameterized.expand(service_list.keys())
@parameterized.expand(SERVICE_LIST.keys())
def test_services(self, s):
service = service_list[s]
service = SERVICE_LIST[s]
self.assertTrue(service.port != RESERVED_PORT)
self.assertTrue(service.port >= STARTING_PORT)
self.assertTrue(service.frequency <= 104)

def test_no_duplicate_port(self):
ports: Dict[int, str] = {}
for name, service in service_list.items():
for name, service in SERVICE_LIST.items():
self.assertFalse(service.port in ports.keys(), f"duplicate port {service.port}")
ports[service.port] = name

Expand Down
11 changes: 7 additions & 4 deletions services.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, port: int, should_log: bool, frequency: float, decimation: Op
self.decimation = decimation


services = {
services: dict[str, tuple] = {
# service: (should_log, frequency, qlog decimation (optional))
# note: the "EncodeIdx" packets will still be in the log
"gyroscope": (True, 104., 104),
Expand All @@ -33,7 +33,7 @@ def __init__(self, port: int, should_log: bool, frequency: float, decimation: Op
"deviceState": (True, 2., 1),
"can": (True, 100., 1223), # decimation gives ~5 msgs in a full segment
"controlsState": (True, 100., 10),
"pandaStates": (True, 2., 1),
"pandaStates": (True, 10., 1),
"peripheralState": (True, 2., 1),
"radarState": (True, 20., 5),
"roadEncodeIdx": (False, 20., 1),
Expand Down Expand Up @@ -102,8 +102,11 @@ def __init__(self, port: int, should_log: bool, frequency: float, decimation: Op
"livestreamWideRoadEncodeData": (False, 20.),
"livestreamRoadEncodeData": (False, 20.),
"livestreamDriverEncodeData": (False, 20.),
"customReservedRawData0": (True, 0.),
"customReservedRawData1": (True, 0.),
"customReservedRawData2": (True, 0.),
}
service_list = {name: Service(new_port(idx), *vals) for # type: ignore
SERVICE_LIST = {name: Service(new_port(idx), *vals) for
idx, (name, vals) in enumerate(services.items())}


Expand All @@ -118,7 +121,7 @@ def build_header():

h += "struct service { std::string name; int port; bool should_log; int frequency; int decimation; };\n"
h += "static std::map<std::string, service> services = {\n"
for k, v in service_list.items():
for k, v in SERVICE_LIST.items():
should_log = "true" if v.should_log else "false"
decimation = -1 if v.decimation is None else v.decimation
h += ' { "%s", {"%s", %d, %s, %d, %d}},\n' % \
Expand Down