EepromDataParser.cpp
Go to the documentation of this file.
2 
3 namespace dai {
4 namespace utility {
5 
6 std::vector<std::string> split(const std::string& s, char delimiter) {
7  std::vector<std::string> tokens;
8  size_t start = 0;
9  size_t end = s.find(delimiter);
10 
11  while(end != std::string::npos) {
12  tokens.push_back(s.substr(start, end - start));
13  start = end + 1;
14  end = s.find(delimiter, start);
15  }
16 
17  tokens.push_back(s.substr(start, end));
18 
19  return tokens;
20 }
21 
22 std::string parseProductName(EepromData eeprom, EepromData eepromFactory) {
23  std::string productName;
24  if((productName = eepromFactory.productName).empty()) {
25  if((productName = eeprom.productName).empty()) {
26  productName = eeprom.boardName;
27  }
28  }
29 
30  // Convert to device naming from display/product naming
31  std::transform(productName.begin(), productName.end(), productName.begin(), [](int c) { return std::toupper(c); });
32  std::replace(productName.begin(), productName.end(), ' ', '-');
33 
34  // Handle some known legacy cases
35  if(productName == "BW1098OBC") {
36  productName = "OAK-D";
37  } else if(productName == "DM2097") {
38  productName = "OAK-D-CM4-POE";
39  } else if(productName == "BW1097") {
40  productName = "OAK-D-CM3";
41  }
42 
43  return productName;
44 }
45 
46 std::string parseDeviceName(EepromData eeprom, EepromData eepromFactory) {
47  std::string deviceName;
48  if((deviceName = eepromFactory.deviceName).empty()) {
49  if((deviceName = eeprom.deviceName).empty()) {
50  // Constant skuDiff array
51  const std::array<std::string, 5> skuDiff = {"AF", "FF", "97", "9782", "OV9782"};
52 
53  // Parse productName and use that to generate device name
54  deviceName = parseProductName(eeprom, eepromFactory);
55 
56  // Regenerate from tokens
57  auto tokens = split(deviceName, '-');
58  deviceName = "";
59  for(unsigned int i = 0; i < tokens.size(); i++) {
60  const auto& token = tokens[i];
61 
62  // check if token has to be removed
63  bool skipToken = false;
64  for(const auto& d : skuDiff) {
65  if(token == d) {
66  skipToken = true;
67  break;
68  }
69  }
70  if(skipToken) continue;
71 
72  if(i != 0) deviceName += "-";
73  deviceName += token;
74  }
75 
76  // Return generated deviceName
77  return deviceName;
78  }
79  }
80 
81  return deviceName;
82 }
83 
84 } // namespace utility
85 } // namespace dai
dai::EepromData::boardName
std::string boardName
Definition: EepromData.hpp:21
dai::utility::parseProductName
std::string parseProductName(EepromData eeprom, EepromData eepromFactory)
Parses product name from given EepromData combination.
Definition: EepromDataParser.cpp:22
dai::utility::split
std::vector< std::string > split(const std::string &s, char delimiter)
Splits given string by delimiter.
Definition: EepromDataParser.cpp:6
EepromDataParser.hpp
dai::EepromData::productName
std::string productName
Definition: EepromData.hpp:21
dai::EepromData::deviceName
std::string deviceName
Definition: EepromData.hpp:21
dai::utility::parseDeviceName
std::string parseDeviceName(EepromData eeprom, EepromData eepromFactory)
Parses device name from given EepromData combination.
Definition: EepromDataParser.cpp:46
transform
static void transform(uint32_t digest[], uint32_t block[BLOCK_INTS], uint64_t &transforms)
Definition: sha1.hpp:129
dai
Definition: CameraExposureOffset.hpp:6
dai::EepromData
Definition: EepromData.hpp:19


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19