<commit_before>/*
 *  Copyright (c) 2004-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */

#include "WedgeQsfp.h"
#include "fboss/lib/usb/UsbError.h"
#include <folly/Conv.h>
#include <folly/Memory.h>

using namespace facebook::fboss;
using folly::MutableByteRange;
using folly::make_unique;
using folly::StringPiece;
using std::unique_ptr;

namespace facebook { namespace fboss {

WedgeQsfp::WedgeQsfp(int module, WedgeI2CBusLock* wedgeI2CBus)
  : module_(module),
    wedgeI2CBusLock_(wedgeI2CBus) {
  moduleName_ = folly::to<std::string>(module);
}

WedgeQsfp::~WedgeQsfp() {
}

// Note that the module_ starts at 0, but the USB I2C bus module
// assumes that QSFP module numbers extend from 1 to 16.
//
bool WedgeQsfp::detectTransceiver() {
  uint8_t buf[1];
  try {
    wedgeI2CBusLock_->moduleRead(module_ + 1, WedgeI2CBus::WEDGE_ADDR_QSFP,
                                  0, sizeof(buf), buf);
  } catch (const UsbError& ex) {
    /*
     * This can either mean that we failed to open the USB device
     * because it was already in use, or that the I2C read failed.
     * At some point we might want to return more a more accurate
     * status value to higher-level functions.
     */
    return false;
  }
  return true;
}

int WedgeQsfp::readTransceiver(int dataAddress, int offset,
                               int len, uint8_t* fieldValue) {
  try {
    wedgeI2CBusLock_->moduleRead(module_ + 1, dataAddress, offset, len,
                                  fieldValue);
  } catch (const UsbError& ex) {
    return -1;
  }
  return len;
}

int WedgeQsfp::writeTransceiver(int dataAddress, int offset,
                            int len, uint8_t* fieldValue) {<commit_msg>Tweak WedgeI2CBus to handle 32-port Wedges<commit_after>/*
 *  Copyright (c) 2004-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */

#include "WedgeQsfp.h"
#include "fboss/lib/usb/UsbError.h"
#include <folly/Conv.h>
#include <folly/Memory.h>

using namespace facebook::fboss;
using folly::MutableByteRange;
using folly::make_unique;
using folly::StringPiece;
using std::unique_ptr;

namespace facebook { namespace fboss {

WedgeQsfp::WedgeQsfp(int module, WedgeI2CBusLock* wedgeI2CBus)
  : module_(module),
    wedgeI2CBusLock_(wedgeI2CBus) {
  moduleName_ = folly::to<std::string>(module);
}

WedgeQsfp::~WedgeQsfp() {
}

// Note that the module_ starts at 0, but the USB I2C bus module
// assumes that QSFP module numbers extend from 1 to 16.
//
bool WedgeQsfp::detectTransceiver() {
  uint8_t buf[1];
  try {
    wedgeI2CBusLock_->moduleRead(module_ + 1, TransceiverI2CApi::ADDR_QSFP,
                                 0, sizeof(buf), buf);
  } catch (const UsbError& ex) {
    /*
     * This can either mean that we failed to open the USB device
     * because it was already in use, or that the I2C read failed.
     * At some point we might want to return more a more accurate
     * status value to higher-level functions.
     */
    return false;
  }
  return true;
}

int WedgeQsfp::readTransceiver(int dataAddress, int offset,
                               int len, uint8_t* fieldValue) {
  try {
    wedgeI2CBusLock_->moduleRead(module_ + 1, dataAddress, offset, len,
                                  fieldValue);
  } catch (const UsbError& ex) {
    return -1;
  }
  return len;
}

int WedgeQsfp::writeTransceiver(int dataAddress, int offset,
                            int len, uint8_t* fieldValue) {
{'fraction_non_alphanumeric': 0.09500514933058703, 'fraction_numerical': 0.01364572605561277, 'mean_word_length': 2.9723926380368098, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '964261', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1252, 'n_words': 397}