Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
Summary: Title

Reviewed By: alandau

Differential Revision: D60961526

fbshipit-source-id: 19154cabe0d2d8df6768d7009e15c22a32a48a4b
  • Loading branch information
Mohammed Al-Sanabani authored and facebook-github-bot committed Aug 27, 2024
1 parent ac976c0 commit 846e41e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
26 changes: 12 additions & 14 deletions fboss/platform/weutil/FbossEepromParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

#include <fboss/platform/weutil/FbossEepromParser.h>

#include <cctype>
#include <filesystem>
#include <fstream>
#include <ios>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <utility>
Expand Down Expand Up @@ -41,7 +40,7 @@ typedef struct {
std::optional<int> offset;
} EepromFieldEntry;

std::vector<EepromFieldEntry> kFieldDictionaryV3 = {
const std::vector<EepromFieldEntry> kFieldDictionaryV3 = {
{0, "Version", FIELD_LE_UINT, 1, 2}, // TypeCode 0 is reserved
{1, "Product Name", FIELD_STRING, 20, 3},
{2, "Product Part Number", FIELD_STRING, 8, 23},
Expand All @@ -65,7 +64,7 @@ std::vector<EepromFieldEntry> kFieldDictionaryV3 = {
{19, "Location on Fabric", FIELD_STRING, 20, 175},
{250, "CRC8", FIELD_LE_HEX, 1, 195}};

std::vector<EepromFieldEntry> kFieldDictionaryV4 = {
const std::vector<EepromFieldEntry> kFieldDictionaryV4 = {
{0, "NA", FIELD_LE_UINT, -1, -1}, // TypeCode 0 is reserved
{1, "Product Name", FIELD_STRING, VARIABLE, VARIABLE},
{2, "Product Part Number", FIELD_STRING, VARIABLE, VARIABLE},
Expand All @@ -89,7 +88,7 @@ std::vector<EepromFieldEntry> kFieldDictionaryV4 = {
{250, "CRC16", FIELD_LE_HEX, 2, VARIABLE},
};

std::vector<EepromFieldEntry> kFieldDictionaryV5 = {
const std::vector<EepromFieldEntry> kFieldDictionaryV5 = {
{0, "NA", FIELD_LE_UINT, -1, -1}, // TypeCode 0 is reserved
{1, "Product Name", FIELD_STRING, VARIABLE, VARIABLE},
{2, "Product Part Number", FIELD_STRING, VARIABLE, VARIABLE},
Expand All @@ -114,6 +113,14 @@ std::vector<EepromFieldEntry> kFieldDictionaryV5 = {
{250, "CRC16", FIELD_BE_HEX, 2, VARIABLE},
};

// Header size in EEPROM. First two bytes are 0xFBFB followed
// by a byte specifying the EEPROM version and one byte of 0xFF
constexpr int kHeaderSize = 4;
// Field Type and Length are 1 byte each.
constexpr int kEepromTypeLengthSize = 2;
// CRC size (16 bits)
constexpr int kCrcSize = 2;

std::vector<EepromFieldEntry> getEepromFieldDict(int version) {
switch (version) {
case 3:
Expand Down Expand Up @@ -152,15 +159,6 @@ std::string parseMacHelper(int len, unsigned char* ptr, bool useBigEndian) {
}
return retVal;
}

// Header size in EEPROM. First two bytes are 0xFBFB followed
// by a byte specifying the EEPROM version and one byte of 0xFF
constexpr int kHeaderSize = 4;
// Field Type and Length are 1 byte each.
constexpr int kEepromTypeLengthSize = 2;
// CRC size (16 bits)
constexpr int kCrcSize = 2;

} // namespace

namespace facebook::fboss::platform {
Expand Down
10 changes: 2 additions & 8 deletions fboss/platform/weutil/WeutilImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
// (c) Facebook, Inc. and its affiliates. Confidential and proprietary.

#include "fboss/platform/weutil/WeutilImpl.h"
#include "fboss/platform/helpers/PlatformUtils.h"

#include <folly/Conv.h>
#include <folly/Format.h>
#include <folly/json/json.h>
#include <folly/logging/xlog.h>
#include <cctype>
#include <filesystem>
#include <fstream>
#include <ios>
#include <iostream>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

Expand All @@ -27,14 +21,14 @@ std::vector<std::pair<std::string, std::string>> WeutilImpl::getContents() {
}

void WeutilImpl::printInfo() {
for (const auto& item : parser_.getContents()) {
for (const auto& item : getContents()) {
std::cout << item.first << ": " << item.second << std::endl;
}
return;
}

void WeutilImpl::printInfoJson() {
auto info = parser_.getContents();
auto info = getContents();
int vectorSize = info.size();
int cursor = 0;
// Manually create JSON object without using folly, so that this code
Expand Down

0 comments on commit 846e41e

Please sign in to comment.