test_smbus2.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:smbus2 作者: kplindegaard 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号