Skip to content

Commit

Permalink
support extended addressing in canbitbang
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Jun 11, 2018
1 parent 36df099 commit ed2920c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 14 additions & 3 deletions board/drivers/canbitbang.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define MAX_BITS_CAN_PACKET (64+44+25)
#define MAX_BITS_CAN_PACKET (200)

// returns out_len
int do_bitstuff(char *out, char *in, int in_len) {
Expand Down Expand Up @@ -71,8 +71,19 @@ int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) {
// test packet
int dlc_len = to_bang->RDTR & 0xF;
len = append_int(pkt, len, 0, 1); // Start-of-frame
len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier
len = append_int(pkt, len, 0, 3); // RTR+IDE+reserved

if (to_bang->RIR & 4) {
// extended identifier
len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier
len = append_int(pkt, len, 3, 2); // SRR+IDE
len = append_int(pkt, len, (to_bang->RIR >> 3) & ((1<<18)-1), 18); // Identifier
len = append_int(pkt, len, 0, 3); // RTR+r1+r0
} else {
// standard identifier
len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier
len = append_int(pkt, len, 0, 3); // RTR+IDE+reserved
}

len = append_int(pkt, len, dlc_len, 4); // Data length code

// append data
Expand Down
12 changes: 8 additions & 4 deletions tests/gmbitbang/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import time
from panda import Panda

p1 = Panda('430026000951363338383037')
p2 = Panda('380016000551363338383037')
p1 = Panda('380016000551363338383037')
p2 = Panda('430026000951363338383037')

# this is a test, no safety
p1.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
Expand All @@ -17,11 +17,15 @@
p2.set_gmlan(bus=2)

# send w bitbang then without
#iden = 123
iden = 18000
#dat = "\x01\x02"
dat = "\x01\x02\x03\x04\x05\x06\x07\x08"
while 1:
p1.set_gmlan(bus=None)
p1.can_send(123, "\x01\x02\x03\x04\x05\x06\x07\x08", bus=3)
p1.can_send(iden, dat, bus=3)
p1.set_gmlan(bus=2)
p1.can_send(123, "\x01\x02\x03\x04\x05\x06\x07\x08", bus=3)
p1.can_send(iden, dat, bus=3)
time.sleep(0.01)
print p2.can_recv()
exit(0)
Expand Down

0 comments on commit ed2920c

Please sign in to comment.