Skip to content

Commit

Permalink
jungle: add debug mode with generated CAN traffic (commaai#1966)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh authored Jun 4, 2024
1 parent 59d5be9 commit fec68d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions board/jungle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def set_ignition(self, enabled):
def set_can_silent(self, silent):
self._handle.controlWrite(PandaJungle.REQUEST_OUT, 0xf5, int(silent), 0, b'')

def set_generated_can(self, enabled):
self._handle.controlWrite(PandaJungle.REQUEST_OUT, 0xa4, int(enabled), 0, b'')

# ******************* serial *******************

def debug_read(self):
Expand Down
17 changes: 17 additions & 0 deletions board/jungle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ uint32_t loop_counter = 0U;
uint16_t button_press_cnt = 0U;
void tick_handler(void) {
if (TICK_TIMER->SR != 0) {
if (generated_can_traffic) {
// queue up messages
for (uint16_t i = 0U; i < 100U; i++) {
CANPacket_t to_send;
to_send.returned = 0U;
to_send.rejected = 0U;
to_send.extended = 0U;
to_send.addr = 0x200U + i;
to_send.bus = i % 3U;
to_send.data_len_code = 8U;
(void)memcpy(to_send.data, "\xff\xff\xff\xff\xff\xff\xff\xff", dlc_to_len[to_send.data_len_code]);
can_set_checksum(&to_send);

can_send(&to_send, to_send.bus, true);
}
}

// tick drivers at 8Hz
usb_tick();

Expand Down
8 changes: 7 additions & 1 deletion board/jungle/main_comms.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extern int _app_start[0xc000]; // Only first 3 sectors of size 0x4000 are used

bool generated_can_traffic = false;

int get_jungle_health_pkt(void *dat) {
COMPILE_TIME_ASSERT(sizeof(struct jungle_health_t) <= USBPACKET_MAX_SIZE);
struct jungle_health_t * health = (struct jungle_health_t*)dat;
Expand Down Expand Up @@ -58,10 +60,14 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
case 0xa2:
current_board->set_ignition((req->param1 == 1U));
break;
// **** 0xa0: Set panda power per channel by bitmask.
// **** 0xa3: Set panda power per channel by bitmask.
case 0xa3:
current_board->set_panda_individual_power(req->param1, (req->param2 > 0U));
break;
// **** 0xa4: Enable generated CAN traffic.
case 0xa4:
generated_can_traffic = (req->param2 > 0U);
break;
// **** 0xa8: get microsecond timer
case 0xa8:
time = microsecond_timer_get();
Expand Down

0 comments on commit fec68d0

Please sign in to comment.