本文整理匯總了Python中socket.PF_CAN屬性的典型用法代碼示例。如果您正苦於以下問題:Python socket.PF_CAN屬性的具體用法?Python socket.PF_CAN怎麽用?Python socket.PF_CAN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類socket
的用法示例。
在下文中一共展示了socket.PF_CAN屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __bind_socket
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def __bind_socket(self, sock, iface, sid, did):
socket_id = ctypes.c_int(sock.fileno())
ifr = self.__get_sock_ifreq(sock, iface)
if sid > 0x7ff:
sid = sid | socket.CAN_EFF_FLAG
if did > 0x7ff:
did = did | socket.CAN_EFF_FLAG
# select the CAN interface and bind the socket to it
addr = SOCKADDR_CAN(ctypes.c_uint16(socket.PF_CAN),
ifr.ifr_ifindex,
ADDR_INFO(TP(ctypes.c_uint32(did),
ctypes.c_uint32(sid))))
error = LIBC.bind(socket_id, ctypes.byref(addr),
ctypes.sizeof(addr))
if error < 0:
warning("Couldn't bind socket")
示例2: __bindSocket
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def __bindSocket(self, sock, iface, sid, did):
socketID = ctypes.c_int(sock.fileno())
ifr = self.__getSockIfreq(sock, iface)
if sid > 0x7ff:
sid = sid | socket.CAN_EFF_FLAG
if did > 0x7ff:
did = did | socket.CAN_EFF_FLAG
# select the CAN interface and bind the socket to it
addr = SOCKADDR_CAN(ctypes.c_uint16(socket.PF_CAN),
ifr.ifr_ifindex,
ADDR_INFO(TP(ctypes.c_uint32(sid),
ctypes.c_uint32(did))))
error = libc.bind(socketID, ctypes.byref(addr), ctypes.sizeof(addr))
if error < 0:
warning("Couldn't bind socket")
示例3: __init__
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def __init__(self, iface=None, sid=0, did=0, extended_addr=None, extended_rx_addr=None, listen_only=False, basecls=ISOTP):
if iface is None:
iface = conf.CANiface
self.ins = socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, CAN_ISOTP)
self.__setOptionFlags(self.ins, extended_addr, extended_rx_addr, listen_only)
self.ins.setsockopt(SOL_CAN_ISOTP,
CAN_ISOTP_RECV_FC,
self.__build_can_isotp_fc_options())
self.ins.setsockopt(SOL_CAN_ISOTP,
CAN_ISOTP_LL_OPTS,
self.__build_can_isotp_ll_options())
self.__bindSocket(self.ins, iface, sid, did)
self.outs = self.ins
if basecls is None:
warning('Provide a basecls ')
self.basecls = basecls
示例4: _have_socket_can
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def _have_socket_can():
"""Check whether CAN sockets are supported on this host."""
try:
s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
except (AttributeError, OSError):
return False
else:
s.close()
return True
示例5: setUp
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def setUp(self):
self.s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
self.addCleanup(self.s.close)
try:
self.s.bind((self.interface,))
except OSError:
self.skipTest('network interface `%s` does not exist' %
self.interface)
示例6: clientSetUp
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def clientSetUp(self):
self.cli = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
try:
self.cli.bind((self.interface,))
except OSError:
# skipTest should not be called here, and will be called in the
# server instead
pass
示例7: testCrucialConstants
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def testCrucialConstants(self):
socket.AF_CAN
socket.PF_CAN
socket.CAN_RAW
示例8: testCreateSocket
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def testCreateSocket(self):
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
pass
示例9: testBindAny
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def testBindAny(self):
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
s.bind(('', ))
示例10: testTooLongInterfaceName
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def testTooLongInterfaceName(self):
# most systems limit IFNAMSIZ to 16, take 1024 to be sure
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
self.assertRaisesRegex(OSError, 'interface name too long',
s.bind, ('x' * 1024,))
示例11: testLoopback
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def testLoopback(self):
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
for loopback in (0, 1):
s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_LOOPBACK,
loopback)
self.assertEqual(loopback,
s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_LOOPBACK))
示例12: testFilter
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def testFilter(self):
can_id, can_mask = 0x200, 0x700
can_filter = struct.pack("=II", can_id, can_mask)
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, can_filter)
self.assertEqual(can_filter,
s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, 8))
s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, bytearray(can_filter))
示例13: testBCM
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def testBCM(self):
bcm = socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_BCM)
self.addCleanup(bcm.close)
bcm.connect((self.interface,))
self.can_id = 0x123
self.data = bytes([0xc0, 0xff, 0xee])
self.cf = self.build_can_frame(self.can_id, self.data)
opcode = socket.CAN_BCM_TX_SEND
flags = 0
count = 0
ival1_seconds = ival1_usec = ival2_seconds = ival2_usec = 0
bcm_can_id = 0x0222
nframes = 1
assert len(self.cf) == 16
header = struct.pack(self.bcm_cmd_msg_fmt,
opcode,
flags,
count,
ival1_seconds,
ival1_usec,
ival2_seconds,
ival2_usec,
bcm_can_id,
nframes,
)
header_plus_frame = header + self.cf
bytes_sent = bcm.send(header_plus_frame)
self.assertEqual(bytes_sent, len(header_plus_frame))
示例14: testFilter
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import PF_CAN [as 別名]
def testFilter(self):
can_id, can_mask = 0x200, 0x700
can_filter = struct.pack("=II", can_id, can_mask)
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, can_filter)
self.assertEqual(can_filter,
s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, 8))