Created
April 25, 2020 09:45
-
-
Save karlding/cd51c45794417d255b4e0a82816f4b17 to your computer and use it in GitHub Desktop.
A partial re-implementation of testj1939 from can-utils in Python to test bpo-40291
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A partial re-implementation of testj1939 from can-utils in Python to test | |
https://github.com/python/cpython/pull/19538 | |
""" | |
import socket | |
def main(): | |
with socket.socket( | |
family=socket.PF_CAN, type=socket.SOCK_DGRAM, proto=socket.CAN_J1939 | |
) as s: | |
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
addr = "vcan0", socket.J1939_NO_NAME, socket.J1939_NO_PGN, socket.J1939_NO_ADDR | |
s.bind(addr) | |
while True: | |
data, addr = s.recvfrom(128) | |
print("{:02x} {:05x}:".format(addr[3], addr[2]), end="") | |
for j in range(len(data)): | |
if j % 8 == 0 and j != 0: | |
print("\n{:05x} ".format(j), end="") | |
print(" {:02x}".format(data[j]), end="") | |
print("\n", end="") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment