134 lines
2.3 KiB
C++
134 lines
2.3 KiB
C++
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
string removeLastNewLine(string s);
|
|
string getModel(string path);
|
|
|
|
/*
|
|
*
|
|
* g++ -Wall -o cctv_radar cctv_radar.cpp mcp3008Spi.cpp logger.cpp libftpclient.a -lcurl -lwiringPi -pthread
|
|
*
|
|
*/
|
|
int main(void)
|
|
{
|
|
cout << "Hello World!\n";
|
|
|
|
|
|
char * cLine = NULL;
|
|
string path;
|
|
size_t len = 0;
|
|
|
|
int loop = 0;
|
|
|
|
int devicesSize = 0;
|
|
|
|
string devices[5];
|
|
|
|
|
|
FILE* outputfileHwinfo = popen("hwinfo --short --disk", "r");
|
|
|
|
if (outputfileHwinfo == NULL) {
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
while ((getline(&cLine, &len, outputfileHwinfo)) != -1) {
|
|
|
|
if(loop > 0) {
|
|
|
|
string line = string(cLine);
|
|
|
|
path = line.substr (2,8);
|
|
|
|
devices[devicesSize] = path;
|
|
|
|
devicesSize++;
|
|
}
|
|
|
|
loop++;
|
|
}
|
|
|
|
fclose(outputfileHwinfo);
|
|
|
|
|
|
|
|
cout << "Model: " << getModel(devices[0]) << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
string getModel(string path){
|
|
|
|
size_t len = 0;
|
|
|
|
char * cLine = NULL;
|
|
|
|
string comand = ("smartctl -a " + path);
|
|
const char *cComand = comand.c_str();
|
|
|
|
FILE* outputfileSmart = popen(cComand, "r");
|
|
|
|
while ((getline(&cLine, &len, outputfileSmart)) != -1) {
|
|
|
|
string line = string(cLine);
|
|
|
|
//cout << line << endl;
|
|
|
|
string str2 ("Device Model:");
|
|
size_t found = line.find(str2);
|
|
if (found!=string::npos) {
|
|
// cout << "Device Model: at: " << found << '\n';
|
|
// cout << line << endl;
|
|
|
|
int size = line.length();
|
|
|
|
|
|
string str3 (":");
|
|
found = line.find(str3);
|
|
|
|
//cout << "Found1: " << found << endl;
|
|
|
|
for(int i = (found+1); i < size; i++) {
|
|
|
|
if(line[i] != ' ') {
|
|
// cout << i << endl;
|
|
found = i;
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string model = line.substr (found, size);
|
|
|
|
model = removeLastNewLine(model);
|
|
|
|
// cout << model << endl;
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "error";
|
|
|
|
}
|
|
|
|
|
|
|
|
string removeLastNewLine(string s) {
|
|
if (!s.empty() && s[s.length()-1] == '\n') {
|
|
s.erase(s.length()-1);
|
|
}
|
|
return s;
|
|
}
|