# -*- coding: utf-8 -*- # tec.py import os from threading import Thread, Lock from time import sleep import can import struct def CAN_Enable(): #os.system('sudo ip link set can0 type can bitrate 125000') pass #os.system('sudo ifconfig can0 up') def CAN_Disable(): os.system('sudo ifconfig can0 down') class CAN: # thread safe def __init__(self): self.__can0 = None self.__lock = Lock() self.connect() def connect(self): self.__can0 = can.interface.Bus(channel = 'can0', bustype = 'socketcan') @staticmethod def toBytes(x : int): return x.to_bytes(2, byteorder='big', signed=True) @staticmethod def toInt(b) -> int: return int.from_bytes(b, byteorder='big', signed=True) @staticmethod def toFloat(b) -> float: a = bytearray(b) return struct.unpack('