From 9b7c720869308aed69e39554e00e75a7a01896f9 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 8 Jul 2020 13:50:06 +0000 Subject: [PATCH] Fixes to code. Virt funcs and syslog --- Makefile | 3 +-- include/atca/ApolloBlade.hh | 6 ++++++ src/ApolloMonitor/ApolloMonitor.cc | 9 ++++++--- src/atca/ApolloBlade.cc | 6 +++--- src/atca/FRUReader.cc | 21 ++++++++++----------- src/atca/IPMIFanSpeedSensor.cc | 2 +- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index f9c6514..72df77c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ - CXX=g++ SRC=src BUILD=build @@ -7,7 +6,7 @@ BIN=bin LIB=lib INSTALL_PATH?=./install -CXX_FLAGS=-Iinclude -std=c++11 -fPIC -Wall -g -O3 +CXX_FLAGS=-Iinclude -std=c++11 -fPIC -Wall -g -O3 -Werror -Wpedantic LD_FLAGS=-lboost_program_options -lboost_system -Wl,-rpath=$(PWD)/lib #================================================================================ diff --git a/include/atca/ApolloBlade.hh b/include/atca/ApolloBlade.hh index a206e77..65a2500 100644 --- a/include/atca/ApolloBlade.hh +++ b/include/atca/ApolloBlade.hh @@ -16,8 +16,14 @@ public: virtual int Report(); virtual float GetVal(); + +protected: + virtual int DoConnect(); + private: + + void SetModuleNumber(std::string const &); void SetDatabaseBaseString(std::string const &); diff --git a/src/ApolloMonitor/ApolloMonitor.cc b/src/ApolloMonitor/ApolloMonitor.cc index c621b19..5dcb6de 100644 --- a/src/ApolloMonitor/ApolloMonitor.cc +++ b/src/ApolloMonitor/ApolloMonitor.cc @@ -4,6 +4,8 @@ #include #include +#include + int ApolloMonitor::Report() { int sensorCount = 0; try{ @@ -25,6 +27,7 @@ int ApolloMonitor::Report() { close(sockfd); sockfd = -1; return -1; + } } //write "." writen(sockfd, ".", 1); @@ -32,11 +35,11 @@ int ApolloMonitor::Report() { writen(sockfd,sensorVals.c_str() + iS,end - iS); sensorCount++; iS = end; - } + } }catch(BUException::exBase const & e){ - //syslog(LOG_ERR,"Caught BUException: %s\n Info: %s\n",e.what(),e.Description()); + syslog(LOG_ERR,"Caught BUException: %s\n Info: %s\n",e.what(),e.Description()); }catch(std::exception const & e){ - //syslog(LOG_ERR,"Caught std::exception: %s\n",e.what()); + syslog(LOG_ERR,"Caught std::exception: %s\n",e.what()); } return sensorCount; } diff --git a/src/atca/ApolloBlade.cc b/src/atca/ApolloBlade.cc index 50d1798..3a6306a 100644 --- a/src/atca/ApolloBlade.cc +++ b/src/atca/ApolloBlade.cc @@ -62,7 +62,7 @@ void ApolloBlade::SetSensors(){ // sensorNames.push_back(std::pair("16", "PIM_Temp")); // sensorNames.push_back(std::pair("17", "PIM_I")); - for(size_t iSensor; iSensor < sensorNames.size();iSensor++){ + for(size_t iSensor = 0; iSensor < sensorNames.size();iSensor++){ args[0] = sensorNames[iSensor].second; args[2] = sensorNames[iSensor].first; @@ -74,7 +74,7 @@ void ApolloBlade::SetSensors(){ } int ApolloBlade::DoConnect() { - for(int i = 0; i < apolloSensors.size(); i++){ + for(size_t i = 0; i < apolloSensors.size(); i++){ // need to throw exception if one of these fails if(apolloSensors[i]->Connect(IP, port) < 0) { return -1; @@ -84,7 +84,7 @@ int ApolloBlade::DoConnect() { } int ApolloBlade::Report() { - for(int i = 0; i < apolloSensors.size(); i++){ + for(size_t i = 0; i < apolloSensors.size(); i++){ try { apolloSensors[i]->Report(); } catch (std::runtime_error &e) { diff --git a/src/atca/FRUReader.cc b/src/atca/FRUReader.cc index 4eec3f4..9b83dd0 100644 --- a/src/atca/FRUReader.cc +++ b/src/atca/FRUReader.cc @@ -7,7 +7,8 @@ #include #include -FRUReader::FRUReader(char *hostname_, uint8_t deviceAddr, int fru_id_){ +FRUReader::FRUReader(char *hostname_, uint8_t deviceAddr, int fru_id_) +{ hostname = hostname_; deviceAccessAddress = deviceAddr; @@ -180,7 +181,6 @@ int FRUReader::ReadInformationLength(ipmi_ctx_t ipmiContext) { const size_t buf_rs_size = 256; uint8_t buf_rs[buf_rs_size]; - try{ int raw_result = ipmi_cmd_raw_ipmb(ipmiContext, channel_number, deviceAccessAddress, @@ -188,17 +188,16 @@ int FRUReader::ReadInformationLength(ipmi_ctx_t ipmiContext) { net_fn, (void const *) buf_rq, buf_rq_size, buf_rs, buf_rs_size); - } catch(std::runtime_error &e){ - std::cerr << e.what() << '\n'; + if (raw_result < 0){ + ipmi_ctx_close(ipmiContext); + throw std::runtime_error(strerror(ipmi_ctx_errnum(ipmiContext))); } - // if (raw_result < 0){ - //printf("nothing found for length\n"); - //} + uint8_t length_ls_byte = buf_rs[2]; uint8_t length_ms_byte = buf_rs[3]; informationLength = 256*length_ms_byte + length_ls_byte; - + return 0; } @@ -221,7 +220,7 @@ void FRUReader::ReadInternalUse(){ std::vector::const_iterator first = data.begin() + internalUseStartingOffset; std::vector::const_iterator last = data.begin() + internalUseStartingOffset + lenInternalUse; internalUseData = std::vector(first, last); - for (int i = 0; i < internalUseData.size(); i++){ + for (size_t i = 0; i < internalUseData.size(); i++){ if(i % 8 == 0){ printf("\n"); } @@ -343,7 +342,7 @@ void FRUReader::ReadBoardArea(){ } std::string FRUReader::ReadBoardField(uint8_t field_type_and_length, uint8_t field_index){ uint8_t field_length = ((field_type_and_length) & 0x3f); - uint8_t field_type = ((field_type_and_length) & 0xc0); + //uint8_t field_type = ((field_type_and_length) & 0xc0); //Check in future... std::string field = ""; for(int i = 0; i < field_length; i++){ field += boardData[field_index+i]; @@ -489,7 +488,7 @@ void FRUReader::ReadProductInfo(){ } std::string FRUReader::ReadProductField(uint8_t field_type_and_length, uint8_t field_index){ uint8_t field_length = ((field_type_and_length) & 0x3f); - uint8_t field_type = ((field_type_and_length) & 0xc0); + // uint8_t field_type = ((field_type_and_length) & 0xc0); //check in future... std::string field = ""; for(int i = 0; i < field_length; i++){ field += productInfoData[field_index+i]; diff --git a/src/atca/IPMIFanSpeedSensor.cc b/src/atca/IPMIFanSpeedSensor.cc index a7d4d2a..8c69ee8 100644 --- a/src/atca/IPMIFanSpeedSensor.cc +++ b/src/atca/IPMIFanSpeedSensor.cc @@ -117,7 +117,7 @@ float IPMIFanSpeedSensor::GetVal(){ float raw_fan_speed = float(ipmbSensorVal->sensorValue); - float fan_speed_rpm = raw_fan_speed*46; + // float fan_speed_rpm = raw_fan_speed*46; int fan_speed_percent = raw_fan_speed/1.46; return fan_speed_percent; }