当前位置: 首页>>代码示例>>C++>>正文


C++ i2c_iface::read_eeprom方法代码示例

本文整理汇总了C++中i2c_iface::read_eeprom方法的典型用法代码示例。如果您正苦于以下问题:C++ i2c_iface::read_eeprom方法的具体用法?C++ i2c_iface::read_eeprom怎么用?C++ i2c_iface::read_eeprom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在i2c_iface的用法示例。


在下文中一共展示了i2c_iface::read_eeprom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: offsetof

static void load_b000(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){
    //extract the serial
    mb_eeprom["serial"] = bytes_to_string(iface.read_eeprom(
        B000_EEPROM_ADDR, offsetof(b000_eeprom_map, serial), B000_SERIAL_LEN
    ));

    //extract the name
    mb_eeprom["name"] = bytes_to_string(iface.read_eeprom(
        B000_EEPROM_ADDR, offsetof(b000_eeprom_map, name), NAME_MAX_LEN
    ));

    //extract master clock rate as a 32-bit uint in Hz
    boost::uint32_t master_clock_rate;
    const byte_vector_t rate_bytes = iface.read_eeprom(
        B000_EEPROM_ADDR, offsetof(b000_eeprom_map, mcr), sizeof(master_clock_rate)
    );
    std::copy(
        rate_bytes.begin(), rate_bytes.end(), //input
        reinterpret_cast<boost::uint8_t *>(&master_clock_rate) //output
    );
    master_clock_rate = ntohl(master_clock_rate);
    if (master_clock_rate > 1e6 and master_clock_rate < 1e9){
        mb_eeprom["mcr"] = boost::lexical_cast<std::string>(master_clock_rate);
    }
    else mb_eeprom["mcr"] = "";
}
开发者ID:benreynwar,项目名称:UHD-Mirror,代码行数:26,代码来源:mboard_eeprom.cpp

示例2: load

void dboard_eeprom_t::load(i2c_iface &iface, uint8_t addr){
    byte_vector_t bytes = iface.read_eeprom(addr, 0, DB_EEPROM_CLEN);

    std::ostringstream ss;
    for (size_t i = 0; i < bytes.size(); i++){
        UHD_LOG_TRACE("DB_EEPROM",
            boost::format("eeprom byte[0x%02x] = 0x%02x")
            % i
            % int(bytes.at(i))
        );
    }

    try{
        UHD_ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN);
        UHD_ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE);
        UHD_ASSERT_THROW(bytes[DB_EEPROM_CHKSUM] == checksum(bytes));

        //parse the ids
        id = dboard_id_t::from_uint16(0
            | (uint16_t(bytes[DB_EEPROM_ID_LSB]) << 0)
            | (uint16_t(bytes[DB_EEPROM_ID_MSB]) << 8)
        );

        //parse the serial
        serial = bytes_to_string(
            byte_vector_t(&bytes.at(DB_EEPROM_SERIAL),
            &bytes.at(DB_EEPROM_SERIAL+DB_EEPROM_SERIAL_LEN))
        );

        //parse the revision
        const uint16_t rev_num = 0
            | (uint16_t(bytes[DB_EEPROM_REV_LSB]) << 0)
            | (uint16_t(bytes[DB_EEPROM_REV_MSB]) << 8)
        ;
        if (rev_num != 0 and rev_num != 0xffff){
            revision = std::to_string(rev_num);
        }

    }catch(const uhd::assertion_error &){
        id = dboard_id_t::none();
        serial = "";
    }
}
开发者ID:EttusResearch,项目名称:uhd,代码行数:43,代码来源:dboard_eeprom.cpp


注:本文中的i2c_iface::read_eeprom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。