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

Does the PIC and Si4010 code generate exactly the same signal? #5

Open
nicholas-gh opened this issue Feb 13, 2020 · 1 comment
Open

Comments

@nicholas-gh
Copy link

I've determined that

abButtonFrame[0] = 0x55;
abButtonFrame[1] = 0x55;
abButtonFrame[2] = 0x55;
abButtonFrame[3] = 0x51; // Tesla specific data
abButtonFrame[4] = 0xd3;
abButtonFrame[5] = 0x4c;
abButtonFrame[6] = 0x33;
abButtonFrame[7] = 0x33;
abButtonFrame[8] = 0xd3;
abButtonFrame[9] = 0xb2;
abButtonFrame[10] = 0xb4;
abButtonFrame[11] = 0x52;
abButtonFrame[12] = 0xcb;
abButtonFrame[13] = 0x32;
abButtonFrame[14] = 0xd5;
abButtonFrame[15] = 0xd2;
abButtonFrame[16] = 0xA8;
abButtonFrame[17] = 0x69;
abButtonFrame[18] = 0xa6;
abButtonFrame[19] = 0x99;
abButtonFrame[20] = 0x99;
abButtonFrame[21] = 0x69;
abButtonFrame[22] = 0x59;
abButtonFrame[23] = 0x5a;
abButtonFrame[24] = 0xa9;
abButtonFrame[25] = 0x65;
abButtonFrame[26] = 0x99;
abButtonFrame[27] = 0x6a;
abButtonFrame[28] = 0x69;
abButtonFrame[29] = 0xd4;
abButtonFrame[30] = 0x34;
abButtonFrame[31] = 0xd3;
abButtonFrame[32] = 0xcc;
abButtonFrame[33] = 0xcc;
abButtonFrame[34] = 0xb4;
abButtonFrame[35] = 0x2c;
abButtonFrame[36] = 0xad;
abButtonFrame[37] = 0xd4;
abButtonFrame[38] = 0xb2;
abButtonFrame[39] = 0x4c;
abButtonFrame[40] = 0xb5;
abButtonFrame[41] = 0x34;
is the same data as https://teslamotorsclub.com/tmc/posts/2383825/ - after I spotted the note about LSB. The Si4010 code is 'ready to send', so manchester encoding, preamble, message-repeats markers are all already in it; and since the 'message-repeats' marker (100?) isn't a full byte I see how the repeated data actually doesn't look repeated in the Si4010 code.

The data at

movlw 0x12
call MC_TX
movlw 0x95
call MC_TX
movlw 0x53
call MC_TX
movlw 0x67
call MC_TX
movlw 0x1B
call MC_TX
movlw 0x43
call MC_TX
movlw 0x20
call MC_TX3
is almost the same; but the last few bytes of the repeated message seems to differ.

I think the PIC code generates either

010101100101100110010110011001100110011001011010011010010110101001010110100110100110010101011010 100101

or potentially (if I'm confused how (MC_TX3)[https://github.com/mstegen/Open-Chargeport/blob/4fdffded66910fe04250e5dc19f3d89ede9bd17c/sourcecode/OpenChargeport_10F200.asm#L83] works)

010101100101100110010110011001100110011001011010011010010110101001010110100110100110010101011010 100

and the Si4010 and 'rpitx' examples generate

0101011001011001100101100110011001100110010110100110100101101010010101101001101001100101010110100101 100

I assume all three of these examples work, and the Tesla port doesn't notice the small variation?

If it works (and I assume it must do since it's here), then the PIC code has the most concise representation of the Tesla button code I've come across so far.

@nicholas-gh
Copy link
Author

Here's my python playaround to try compare the three examples:

#!/usr/bin/python


# sources
# https://teslamotorsclub.com/tmc/posts/2383825/
# https://github.com/mstegen/Open-Chargeport/blob/master/Si4010/source/keyfob_demo_main.c

thenoone_preamble = "111111111111"
thenoone_data = "00010010100101010101001101100111000110110100001100"
thenoone_rec_split = "100" # not manchester?

Si4010 = [0x55, 0x55, 0x55, 0x51, 0xd3, 0x4c, 0x33, 0x33, 0xd3, 0xb2, 0xb4, 0x52, 0xcb, 0x32, 0xd5, 0xd2, 0xA8, 0x69, 0xa6, 0x99, 0x99, 0x69, 0x59, 0x5a, 0xa9, 0x65, 0x99, 0x6a, 0x69, 0xd4, 0x34, 0xd3, 0xcc, 0xcc, 0xb4, 0x2c, 0xad, 0xd4, 0xb2, 0x4c, 0xb5, 0x34]

pic_preamble = "10"*13 + "0" # 0 is an extra 400us delay after the preamble that's in the code, not in the data
pic = [0x12, 0x95, 0x53, 0x67, 0x1B, 0x43]
pic_3 = 0x20

def manchester(data):
    return "".join(["10" if bit == "1" else "01" for bit in data])
thenoone_symbols = thenoone_rec_split.join([manchester(thenoone_preamble)] + [manchester(thenoone_data)]*3)

print "noone ", [int(thenoone_symbols[b:b+8][::-1], 2) for b in range(0, len(thenoone_symbols), 8)]
print "Si4010", Si4010

pic_symbols = pic_preamble + ("".join([manchester(format(byte, '08b')) for byte in pic]) + manchester(format(pic_3, '03b')))*3
print "pic   ", [int(pic_symbols[b:b+8][::-1], 2) for b in range(0, len(pic_symbols), 8)]

and the output is

noone  [85, 85, 85, 81, 211, 76, 51, 51, 211, 178, 180, 82, 203, 50, 213, 210, 168, 105, 166, 153, 153, 105, 89, 90, 169, 101, 153, 106, 105, 212, 52, 211, 204, 204, 180, 44, 173, 212, 178, 76, 181, 20]
Si4010 [85, 85, 85, 81, 211, 76, 51, 51, 211, 178, 180, 82, 203, 50, 213, 210, 168, 105, 166, 153, 153, 105, 89, 90, 169, 101, 153, 106, 105, 212, 52, 211, 204, 204, 180, 44, 173, 212, 178, 76, 181, 52]
pic    [85, 85, 85, 81, 211, 76, 51, 51, 211, 178, 180, 82, 203, 50, 213, 74, 85, 53, 205, 52, 51, 51, 45, 75, 43, 181, 44, 83, 173, 84, 85, 211, 76, 51, 51, 211, 178, 180, 82, 203, 50, 213, 74, 85]

So the Si4010 and TheNoOne's code varies only at the very end; but I don't understand the Pic code well enough to see if/why its "3 bit" "frame delimiter" is the same result as the other two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant