Created
April 25, 2020 09:45
-
-
Save karlding/cd51c45794417d255b4e0a82816f4b17 to your computer and use it in GitHub Desktop.
Revisions
-
karlding created this gist
Apr 25, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ """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()