49 #include <sys/utsname.h> 63 #include "rnr/rnrconfig.h" 80 static const char *SubSysName =
"CPU";
81 static const char *ProdName =
"Odroid";
83 static void trim(
string &str)
89 for(i=0; i<strWork.size(); ++i)
91 if( (strWork[i] !=
' ') && (strWork[i] !=
'\t') &&
92 (strWork[i] !=
'\n') && (strWork[i] !=
'\r') )
99 for(j=strWork.size()-1; j>=i; --j)
101 if( (strWork[j] !=
' ') && (strWork[j] !=
'\t') &&
102 (strWork[j] !=
'\n') && (strWork[j] !=
'\r') )
112 for(k=0; k<str.size(); ++k)
114 str[k] = strWork[i++];
123 static void tolower(
string &str)
125 for(
size_t i=0; i<str.size(); ++i)
127 str[i] = ::tolower(str[i]);
131 static string normalize(
string str)
144 static bool parseCpuInfo(
string &strCpuHw,
148 const size_t maxlen = 256;
152 char *tokKey, *tokVal;
159 if( (fp = fopen(
"/proc/cpuinfo",
"r")) == NULL )
164 while( fgets(line, maxlen, fp) != NULL )
168 if( (tokKey = strtok(line,
":")) == NULL )
172 else if( (tokVal = strtok(NULL,
"\n")) == NULL )
177 strKey = normalize(tokKey);
179 if( strKey ==
"processor" )
183 else if( strKey ==
"hardware" )
188 else if( strKey ==
"revision" )
200 static bool parseLsbRelease(
string &strDistribId,
201 string &strDistribRel,
202 string &strDistribCode,
203 string &strDistribDesc)
205 const size_t maxlen = 256;
209 char *tokKey, *tokVal;
212 strDistribId.clear();
213 strDistribRel.clear();
214 strDistribCode.clear();
215 strDistribDesc.clear();
217 if( (fp = fopen(
"/etc/lsb-release",
"r")) == NULL )
222 while( fgets(line, maxlen, fp) != NULL )
226 if( (tokKey = strtok(line,
"=")) == NULL )
230 else if( (tokVal = strtok(NULL,
"\n")) == NULL )
235 strKey = normalize(tokKey);
237 if( strKey ==
"distrib_id" )
239 strDistribId = tokVal;
242 else if( strKey ==
"distrib_release" )
244 strDistribRel = tokVal;
247 else if( strKey ==
"distrib_codename" )
249 strDistribCode = tokVal;
250 trim(strDistribCode);
252 else if( strKey ==
"distrib_description" )
254 strDistribDesc = tokVal;
255 trim(strDistribDesc);
264 static bool parseEthMacAddr(
string &strEthMacAddr)
266 const size_t maxlen = 256;
272 strEthMacAddr.clear();
274 if( (fp = fopen(
"/sys/class/net/eth0/address",
"r")) == NULL )
279 if (fgets(line, maxlen, fp) != NULL )
287 strEthMacAddr = line;
296 static bool parseMmcCid(
string &strMmcCid)
298 const size_t maxlen = 256;
306 if( (fp = fopen(
"/sys/block/mmcblk0/device/cid",
"r")) == NULL )
311 if (fgets(line, maxlen, fp) != NULL )
334 string strDistribRel;
335 string strDistribCode;
336 string strDistribDesc;
337 struct utsname utsInfo;
338 string strEthMacAddr;
344 printSubHdr(
"Main Processor Info");
347 if( parseCpuInfo(strCpuHw, strCpuRev, numCores) )
356 printTestResult(sTag,
"Get CPU info.");
359 if( parseLsbRelease(strDistribId, strDistribRel,
360 strDistribCode, strDistribDesc) )
369 printTestResult(sTag,
"Get system release info.");
372 if( uname(&utsInfo) == 0 )
379 memset(&utsInfo, 0,
sizeof(
struct utsname));
382 printTestResult(sTag,
"Get kernel info.");
385 if( parseEthMacAddr(strEthMacAddr) )
394 printTestResult(sTag,
"Get Ethernet hardware info.");
397 if( parseMmcCid(strMmcCid) )
406 printTestResult(sTag,
"Get eMMC CID info.");
409 printf(
"Main Processor Summary:\n");
410 printf(
" Hardware:\n");
411 printf(
" Product: %s\n", ProdName);
412 printf(
" SOC: %s\n",
"Samsung Exynos5 Octa ARM Cortex");
413 printf(
" Architecture: %s\n", utsInfo.machine);
414 printf(
" Hardware Rev: %s\n", strCpuRev.c_str());
415 printf(
" Number of Cores: %d\n", numCores);
416 printf(
" eMMC CID: %s\n", strMmcCid.c_str());
417 printf(
" Ethernet MAC: %s\n", strEthMacAddr.c_str());
418 printf(
" Operating System:\n");
419 printf(
" Kernel: %s\n", utsInfo.sysname);
420 printf(
" Release: %s\n", utsInfo.release);
421 printf(
" Version: %s\n", utsInfo.version);
422 printf(
" Node: %s\n", utsInfo.nodename);
423 printf(
" Distribution:\n");
424 printf(
" Name: %s\n", strDistribId.c_str());
425 printf(
" Release: %s\n", strDistribRel.c_str());
426 printf(
" Code Name: %s\n", strDistribCode.c_str());
427 printf(
" Description: %s\n", strDistribDesc.c_str());
428 printf(
" System Devices:\n");
429 printf(
" Motor Controllers: %s\n", LaeDevMotorCtlrs);
430 printf(
" I2C Bus: %s\n", LaeDevI2C_0);
431 printf(
" %s\n", LaeDevI2C_1);
432 printf(
" %s\n", LaeDevI2C_2);
433 printf(
" IMU: %s\n", LaeDevIMU);
434 printf(
" Dynamixel Bus: %s\n", LaeDevDynabus);
435 printf(
" Front Camera: %s\n", LaeDevFCam);
446 printHdr(
"Main CPU Diagnostics");
451 statsTest = readInfo();
453 printSubTotals(statsTest);
455 statsTotal += statsTest;
461 if( !statsTotal.fatal )
463 statsTest = readInfo();
465 printSubTotals(statsTest);
467 statsTotal += statsTest;
474 printTotals(statsTotal);
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Simple diagnostics statistics class.
Laelaps common utilities.
Top-level package include file.