def mock_ioctl(fd, command, msg):
print("Mocking ioctl")
assert fd == MOCK_FD
assert command is not None
# Reproduce ioctl read operations
if command == I2C_SMBUS and msg.read_write == I2C_SMBUS_READ:
offset = msg.command
if msg.size == I2C_SMBUS_BYTE_DATA:
msg.data.contents.byte = test_buffer[offset]
elif msg.size == I2C_SMBUS_WORD_DATA:
msg.data.contents.word = test_buffer[offset+1]*256 + test_buffer[offset]
elif msg.size == I2C_SMBUS_I2C_BLOCK_DATA:
for k in range(msg.data.contents.byte):
msg.data.contents.block[k+1] = test_buffer[offset+k]
# Override open, close and ioctl with our mock functions
评论列表
文章目录