Skip to content

Commit

Permalink
Merge commit '3c1def1cc57f3fb37399a25d0e8088c70985c5ec' into bmw_stepper
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Aug 10, 2024
2 parents fd42d37 + 3c1def1 commit af74c0b
Show file tree
Hide file tree
Showing 38 changed files with 181 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/drivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build_socketcan:
name: socketcan build
runs-on: ubuntu-latest
timeout-minutes: 5
timeout-minutes: 1
steps:
- uses: actions/checkout@v2
- name: Install dependencies
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/jenkins-pr-trigger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: jenkins scan

on:
issue_comment:
types: [created, edited]

jobs:
# TODO: gc old branches in a separate job in this workflow
scan-comments:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }}
steps:
- name: Check for trigger phrase
id: check_comment
uses: actions/github-script@v7
with:
script: |
const triggerPhrase = "trigger-jenkins";
const comment = context.payload.comment.body;
const commenter = context.payload.comment.user.login;
const { data: permissions } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: commenter
});
const hasWriteAccess = permissions.permission === 'write' || permissions.permission === 'admin';
return (hasWriteAccess && comment.includes(triggerPhrase));
result-encoding: json

- name: Checkout repository
if: steps.check_comment.outputs.result == 'true'
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head

- name: Push to tmp-jenkins branch
if: steps.check_comment.outputs.result == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b tmp-jenkins-${{ github.event.issue.number }}
GIT_LFS_SKIP_PUSH=1 git push -f origin tmp-jenkins-${{ github.event.issue.number }}
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ repos:
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.11.1
hooks:
- id: mypy
additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites',
additional_dependencies: ['numpy', 'types-requests', 'types-atomicwrites',
'types-pycurl']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.7
rev: v0.5.5
hooks:
- id: ruff
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ RUN /tmp/install.sh && rm -rf $CPPCHECK_DIR/.git/
ENV SKIP_CPPCHECK_INSTALL=1

ENV CEREAL_REF="861144c136c91f70dcbc652c2ffe99f57440ad47"
ENV OPENDBC_REF="e0d4be4a6215d44809718dc84efe1b9f0299ad63"
ENV OPENDBC_REF="8e9d3688412405154a8189c421cfdc9d5feea715"

RUN git config --global --add safe.directory /tmp/openpilot/panda
RUN mkdir -p /tmp/openpilot/ && \
Expand Down
3 changes: 3 additions & 0 deletions board/gdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

gdb-multiarch --eval-command="target extended-remote localhost:3333"
2 changes: 1 addition & 1 deletion board/jungle/scripts/can_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def can_printer():
canbus = int(os.getenv("CAN", "0"))
while True:
can_recv = p.can_recv()
for address, _, dat, src in can_recv:
for address, dat, src in can_recv:
if src == canbus:
msgs[address].append(dat)

Expand Down
2 changes: 1 addition & 1 deletion board/jungle/scripts/echo_loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_loopback():
incoming = jungle.can_recv()
found = False
for message in incoming:
incomingAddress, _, incomingData, incomingBus = message
incomingAddress, incomingData, incomingBus = message
if incomingAddress == address and incomingData == data[::-1] and incomingBus == bus:
found = True
break
Expand Down
4 changes: 2 additions & 2 deletions board/jungle/scripts/loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def can_loopback(sender):
raise Exception("Amount of received CAN messages (" + str(len(content)) + ") does not equal 1. Bus: " + str(bus) +" OBD: " + str(obd))

# Check content
if content[0][0] != addr or content[0][2] != string:
if content[0][0] != addr or content[0][1] != string:
raise Exception("Received CAN message content or address does not match")

# Check bus
if content[0][3] != bus:
if content[0][2] != bus:
raise Exception("Received CAN message bus does not match")

#################################################################
Expand Down
50 changes: 44 additions & 6 deletions board/stm32h7/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,55 @@ APB4 per: 60MHz
PCLK1: 60MHz (for USART2,3,4,5,7,8)
*/

typedef enum {
PACKAGE_UNKNOWN = 0,
PACKAGE_WITH_SMPS = 1,
PACKAGE_WITHOUT_SMPS = 2,
} PackageSMPSType;

// TODO: find a better way to distinguish between H725 (using SMPS) and H723 (lacking SMPS)
// The package will do for now, since we have only used TFBGA100 for H723
PackageSMPSType get_package_smps_type(void) {
PackageSMPSType ret;
RCC->APB4ENR |= RCC_APB4ENR_SYSCFGEN; // make sure SYSCFG clock is enabled. does seem to read fine without too though

switch(SYSCFG->PKGR & 0xFU) {
case 0b0001U: // TFBGA100 Legacy
case 0b0011U: // TFBGA100
ret = PACKAGE_WITHOUT_SMPS;
break;
case 0b0101U: // LQFP144 Legacy
case 0b0111U: // LQFP144 Industrial
case 0b1000U: // UFBGA169
ret = PACKAGE_WITH_SMPS;
break;
default:
ret = PACKAGE_UNKNOWN;
}
return ret;
}

void clock_init(void) {
/*
WARNING: PWR->CR3's lower byte can only be written once
* subsequent writes will silently fail
* only cleared with a full power-on-reset, not soft reset or reset pin
* some H7 have a bootrom with a DFU routine that writes (and locks) CR3
* if the CR3 config doesn't match the HW, the core will deadlock and require immediately going into DFU from a cold boot
In a normal bootup, the bootstub will be the first to write this. The app section calls clock_init again, but the CR3 write will silently fail. This is fine for most cases, but caution should be taken that the bootstub and app always write the same config.
*/

// Set power mode to direct SMPS power supply (depends on the board layout)
#ifndef PANDA_JUNGLE
if ((PWR->CR3 & PWR_CR3_SMPSEXTRDY) != 0U) {
#else
if (true) {
#endif
PackageSMPSType package_smps = get_package_smps_type();
if (package_smps == PACKAGE_WITHOUT_SMPS) {
register_set(&(PWR->CR3), PWR_CR3_LDOEN, 0xFU); // no SMPS, so powered by LDO
} else if (package_smps == PACKAGE_WITH_SMPS) {
register_set(&(PWR->CR3), PWR_CR3_SMPSEN, 0xFU); // powered only by SMPS
} else {
register_set(&(PWR->CR3), PWR_CR3_LDOEN, 0xFU);
while(true); // unknown package, let's hang here
}

// Set VOS level (VOS3 to 170Mhz, VOS2 to 300Mhz, VOS1 to 400Mhz, VOS0 to 550Mhz)
register_set(&(PWR->D3CR), PWR_D3CR_VOS_1 | PWR_D3CR_VOS_0, 0xC000U); //VOS1, needed for 80Mhz CAN FD
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U);
Expand Down
2 changes: 1 addition & 1 deletion examples/can_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def can_logger():
while True:
can_recv = p.can_recv()

for address, _, dat, src in can_recv:
for address, dat, src in can_recv:
csvwriter.writerow(
[str(src), str(hex(address)), f"0x{dat.hex()}", len(dat), str(time.time() - start_time)])

Expand Down
2 changes: 1 addition & 1 deletion examples/tesla_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def tesla_tester():
while True:
#Read the VIN
can_recv = p.can_recv()
for address, _, dat, src in can_recv:
for address, dat, src in can_recv:
if src == body_bus_num:
if address == 1384: # 0x568 is VIN
vin_index = int(binascii.hexlify(dat)[:2]) # first byte is the index, 00, 01, 02
Expand Down
6 changes: 3 additions & 3 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def calculate_checksum(data):

def pack_can_buffer(arr):
snds = [b'']
for address, _, dat, bus in arr:
for address, dat, bus in arr:
assert len(dat) in LEN_TO_DLC
#logging.debug(" W 0x%x: 0x%s", address, dat.hex())

Expand Down Expand Up @@ -85,7 +85,7 @@ def unpack_can_buffer(dat):
data = dat[CANPACKET_HEAD_SIZE:(CANPACKET_HEAD_SIZE+data_len)]
dat = dat[(CANPACKET_HEAD_SIZE+data_len):]

ret.append((address, 0, data, bus))
ret.append((address, data, bus))

return (ret, dat)

Expand Down Expand Up @@ -813,7 +813,7 @@ def can_send_many(self, arr, timeout=CAN_SEND_TIMEOUT_MS):
logging.error("CAN: BAD SEND MANY, RETRYING")

def can_send(self, addr, dat, bus, timeout=CAN_SEND_TIMEOUT_MS):
self.can_send_many([[addr, None, dat, bus]], timeout=timeout)
self.can_send_many([[addr, dat, bus]], timeout=timeout)

@ensure_can_packet_version
def can_recv(self):
Expand Down
2 changes: 1 addition & 1 deletion python/ccp.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _recv_dto(self, timeout: float) -> bytes:
msgs = self._panda.can_recv() or []
if len(msgs) >= 256:
print("CAN RX buffer overflow!!!", file=sys.stderr)
for rx_addr, _, rx_data_bytearray, rx_bus in msgs:
for rx_addr, rx_data_bytearray, rx_bus in msgs:
if rx_bus == self.can_bus and rx_addr == self.rx_addr:
rx_data = bytes(rx_data_bytearray)
if self.debug:
Expand Down
6 changes: 3 additions & 3 deletions python/isotp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def recv(panda, cnt, addr, nbus):
while len(ret) < cnt:
kmsgs += panda.can_recv()
nmsgs = []
for ids, ts, dat, bus in kmsgs:
for ids, dat, bus in kmsgs:
if ids == addr and bus == nbus and len(ret) < cnt:
ret.append(dat)
else:
# leave around
nmsgs.append((ids, ts, dat, bus))
nmsgs.append((ids, dat, bus))
kmsgs = nmsgs[-256:]
return ret

Expand Down Expand Up @@ -96,7 +96,7 @@ def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None, rate=None):
panda.can_send(addr, sends[-1], 0)
else:
if rate is None:
panda.can_send_many([(addr, None, s, bus) for s in sends])
panda.can_send_many([(addr, s, bus) for s in sends])
else:
for dat in sends:
panda.can_send(addr, dat, bus)
Expand Down
4 changes: 2 additions & 2 deletions python/uds.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def get_dtc_status_names(status):
return result

class CanClient():
def __init__(self, can_send: Callable[[int, bytes, int], None], can_recv: Callable[[], list[tuple[int, int, bytes, int]]],
def __init__(self, can_send: Callable[[int, bytes, int], None], can_recv: Callable[[], list[tuple[int, bytes, int]]],
tx_addr: int, rx_addr: int, bus: int, sub_addr: int | None = None, debug: bool = False):
self.tx = can_send
self.rx = can_recv
Expand Down Expand Up @@ -339,7 +339,7 @@ def _recv_buffer(self, drain: bool = False) -> None:
print(f"CAN-RX: drain - {len(msgs)}")
self.rx_buff.clear()
else:
for rx_addr, _, rx_data, rx_bus in msgs or []:
for rx_addr, rx_data, rx_bus in msgs or []:
if self._recv_filter(rx_bus, rx_addr) and len(rx_data) > 0:
rx_data = bytes(rx_data) # convert bytearray to bytes

Expand Down
2 changes: 1 addition & 1 deletion python/xcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _recv_dto(self, timeout: float) -> bytes:
msgs = self._panda.can_recv() or []
if len(msgs) >= 256:
print("CAN RX buffer overflow!!!", file=sys.stderr)
for rx_addr, _, rx_data, rx_bus in msgs:
for rx_addr, rx_data, rx_bus in msgs:
if rx_bus == self.can_bus and rx_addr == self.rx_addr:
rx_data = bytes(rx_data) # convert bytearray to bytes
if self.debug:
Expand Down
6 changes: 3 additions & 3 deletions tests/black_white_loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration):

loop_buses = []
for loop in cans_loop:
if (loop[0] != at) or (loop[2] != st):
if (loop[0] != at) or (loop[1] != st):
content_errors += 1

print(" Loop on bus", str(loop[3]))
loop_buses.append(loop[3])
print(" Loop on bus", str(loop[2]))
loop_buses.append(loop[2])
if len(cans_loop) == 0:
print(" No loop")
assert not os.getenv("NOASSERT")
Expand Down
6 changes: 3 additions & 3 deletions tests/black_white_relay_endurance.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration):

loop_buses = []
for loop in cans_loop:
if (loop[0] != at) or (loop[2] != st):
if (loop[0] != at) or (loop[1] != st):
content_errors += 1

print(" Loop on bus", str(loop[3]))
loop_buses.append(loop[3])
print(" Loop on bus", str(loop[2]))
loop_buses.append(loop[2])
if len(cans_loop) == 0:
print(" No loop")
assert os.getenv("NOASSERT")
Expand Down
4 changes: 2 additions & 2 deletions tests/black_white_relay_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def test_buses(black_panda, other_panda, test_obj):

loop_buses = []
for loop in cans_loop:
if (loop[0] != at) or (loop[2] != st):
if (loop[0] != at) or (loop[1] != st):
content_errors += 1
loop_buses.append(loop[3])
loop_buses.append(loop[2])

# test loop buses
recv_buses.sort()
Expand Down
2 changes: 1 addition & 1 deletion tests/bulk_write_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def flood_tx(panda):
print('Sending!')
msg = b"\xaa" * 4
packet = [[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]] * NUM_MESSAGES_PER_BUS
packet = [[0xaa, msg, 0], [0xaa, msg, 1], [0xaa, msg, 2]] * NUM_MESSAGES_PER_BUS
panda.can_send_many(packet, timeout=10000)
print(f"Done sending {3*NUM_MESSAGES_PER_BUS} messages!")

Expand Down
2 changes: 1 addition & 1 deletion tests/can_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def can_printer():
canbus = int(os.getenv("CAN", "0"))
while True:
can_recv = p.can_recv()
for address, _, dat, src in can_recv:
for address, dat, src in can_recv:
if src == canbus:
msgs[address].append(dat)

Expand Down
4 changes: 2 additions & 2 deletions tests/canfd/test_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def canfd_test(p_send, p_recv):
data = bytearray(random.getrandbits(8) for _ in range(DLC_TO_LEN[dlc]))
if len(data) >= 2:
data[0] = calculate_checksum(data[1:] + bytes(str(address), encoding="utf-8"))
to_send.append([address, 0, data, bus])
to_send.append([address, data, bus])
sent_msgs[bus].add((address, bytes(data)))

p_send.can_send_many(to_send, timeout=0)
Expand All @@ -95,7 +95,7 @@ def canfd_test(p_send, p_recv):
while (time.monotonic() - start_time < 1) and any(len(x) > 0 for x in sent_msgs.values()):
incoming = p_recv.can_recv()
for msg in incoming:
address, _, data, bus = msg
address, data, bus = msg
if len(data) >= 2:
assert calculate_checksum(data[1:] + bytes(str(address), encoding="utf-8")) == data[0]
k = (address, bytes(data))
Expand Down
2 changes: 1 addition & 1 deletion tests/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
while True:
incoming = p.can_recv()
for message in incoming:
address, notused, data, bus = message
address, data, bus = message
if b'test' in data:
p.can_send(address, data[::-1], bus)
6 changes: 3 additions & 3 deletions tests/elm_car_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def __can_monitor(self):
self.panda.can_recv() # Toss whatever was already there

while not self.__stop:
for address, ts, data, src in self.panda.can_recv():
for address, data, src in self.panda.can_recv():
if self.__on and src == 0 and len(data) == 8 and data[0] >= 2:
if not self.__silent:
print("Processing CAN message", src, hex(address), binascii.hexlify(data))
self.__can_process_msg(data[1], data[2], address, ts, data, src)
self.__can_process_msg(data[1], data[2], address, data, src)
elif not self.__silent:
print("Rejecting CAN message", src, hex(address), binascii.hexlify(data))

Expand Down Expand Up @@ -120,7 +120,7 @@ def _can_addr_matches(self, addr):
return True
return False

def __can_process_msg(self, mode, pid, address, ts, data, src):
def __can_process_msg(self, mode, pid, address, data, src):
if not self.__silent:
print("CAN MSG", binascii.hexlify(data[1:1 + data[0]]),
"Addr:", hex(address), "Mode:", hex(mode)[2:].zfill(2),
Expand Down
Loading

0 comments on commit af74c0b

Please sign in to comment.