SensorStateInfo.cpp
Go to the documentation of this file.
00001 //
00002 // SensorStateInfo.cpp
00003 //
00004 //  Created on: 02.09.2011
00005 //      Author: wahnfla
00006 //
00007 
00008 #include "SensorStateInfo.hpp"
00009 #include "Measurement.hpp"
00010 #include "../tools/errorhandler.hpp"
00011 //#include "StringToolbox.hpp"
00012 
00013 namespace datatypes
00014 {
00015 
00016 SensorStateInfo::SensorStateInfo()
00017 {
00018         m_datatype = Datatype_SensorStateInfo;
00019 }
00020 
00021 
00022 SensorStateInfo::~SensorStateInfo()
00023 {
00024 }
00025 
00031 const UINT32 SensorStateInfo::getUsedMemory() const
00032 {
00033         UINT32 size;
00034 
00035         // Quick hack: Factor 4 may be ok...
00036         size = (UINT32)(4.0 * ((double)sizeof(*this)));
00037 
00038         return size;
00039 }
00040 
00041 const EvalCases& SensorStateInfo::getEvalCases() const
00042 {
00043         return m_evalCases;
00044 }
00045 
00046 const Fields& SensorStateInfo::getFields() const
00047 {
00048         return m_fields;
00049 }
00050 
00051 const SensorStateInfo::StateVector& SensorStateInfo::getInputStates() const
00052 {
00053         return m_inputStates;
00054 }
00055 
00056 const MeasurementList& SensorStateInfo::getMeasurementList() const
00057 {
00058         return m_measurementList;
00059 }
00060 
00061 const SensorStateInfo::StateVector& SensorStateInfo::getOutputStates() const
00062 {
00063         return m_outputStates;
00064 }
00065 
00066 void SensorStateInfo::setEvalCases(const EvalCases& m_evalCases)
00067 {
00068         this->m_evalCases = m_evalCases;
00069 }
00070 
00071 void SensorStateInfo::setFields(const Fields& m_fields)
00072 {
00073         this->m_fields = m_fields;
00074 }
00075 
00076 void SensorStateInfo::setInputStates(const SensorStateInfo::StateVector& m_inputStates)
00077 {
00078         this->m_inputStates = m_inputStates;
00079 }
00080 
00081 void SensorStateInfo::setMeasurementList(const MeasurementList& m_measurementList)
00082 {
00083         this->m_measurementList = m_measurementList;
00084 }
00085 
00086 void SensorStateInfo::setOutputStates(const SensorStateInfo::StateVector& m_outputStates)
00087 {
00088         this->m_outputStates = m_outputStates;
00089 }
00090 
00091 const SensorStateInfo::StateMap& SensorStateInfo::getStateMap() const
00092 {
00093         return m_stateMap;
00094 }
00095 
00096 void SensorStateInfo::setStateMap(const SensorStateInfo::StateMap& stateMap)
00097 {
00098         m_stateMap = stateMap;
00099 }
00100 
00101 // UINT32 SensorStateInfo::getDeviceID() const
00102 // {
00103 //      return m_deviceID;
00104 // }
00105 // 
00106 // void SensorStateInfo::setDeviceID(UINT32 deviceID)
00107 // {
00108 //      m_deviceID = deviceID;
00109 // }
00110 
00111 //
00112 //
00113 //
00114 std::string SensorStateInfo::toString() const
00115 {
00116         std::stringstream output;
00117 
00118         // Measurement list
00119         std::vector<Measurement>::const_iterator meas;
00120         for (meas = m_measurementList.m_list.begin(); meas != m_measurementList.m_list.end(); ++meas)
00121         {
00122                 output << meas->getName() << "=" ;
00123                 output << meas->valueToString() << " ";
00124         }
00125         output << std::endl;
00126 
00127         // Filterparameter
00128         StateMap::const_iterator mapIter;
00129         for (mapIter = m_stateMap.begin(); mapIter != m_stateMap.end(); ++mapIter)
00130         {
00131                 // First = Name
00132                 // Second = Bool-Wert
00133                 output << mapIter->first << "=" << std::string(mapIter->second ? "true" : "false") << " ";      // << std::endl;
00134         }
00135         output << std::endl;
00136 
00137         // Zustand der Bit-Eingaenge
00138         output << "Inputs:" << std::endl << " ";
00139         StateVector::const_iterator state;
00140         UINT32 number = 0;
00141         for (state = m_inputStates.begin(); state != m_inputStates.end(); ++state)
00142         {
00143                 output << " " << number << "=" << ioStateToString(*state);      //  << std::endl;
00144                 ++number;
00145         }
00146         output << std::endl;
00147 
00148         // Zustand der Bit-Ausgaenge
00149         output << "Outputs:" << std::endl << " ";
00150         number = 0;
00151         for (state = m_outputStates.begin(); state != m_outputStates.end(); ++state)
00152         {
00153                 output << " " << number << "=" << ioStateToString(*state);      // << std::endl;
00154                 ++number;
00155         }
00156         output << std::endl;
00157 
00158         // Koordinaten der Felder
00159         output << "Fields: " << std::endl;
00160         Fields::FieldVector::const_iterator field;
00161         for (field = m_fields.getFields().begin(); field != m_fields.getFields().end(); ++field)
00162         {
00163                 const FieldParameter& fp = *(*field);
00164                 output << "  " << fp.getFieldNumber() << ": " << fp.getFieldName() << ": " << FieldDescription::fieldTypeToString(fp.getFieldType()) << std::endl;
00165                 output << "  " << fp.getPolygon().toString() << std::endl;
00166         }
00167 
00168         // Auswertefaelle
00169         output << "Evalcases: " << std::endl;
00170         EvalCaseVector::const_iterator ecp;
00171         number = 0;
00172         for (ecp = m_evalCases.getEvalCases().begin(); ecp != m_evalCases.getEvalCases().end(); ++ecp)
00173         {
00174                 const EvalCase& evalCase = *(*ecp);
00175                 output << evalCase.getCaseNumber() << "=" << evalCase.getCaseName();    //  << std::endl;
00176                 output << ": " << "Strat.: " << EvalCase::strategyToString(evalCase.getStrategy());     // std::endl;
00177                 output << "; " << "Blnk. size: " << evalCase.getBlankingSize() << "m";  //  << std::endl;
00178                 output << "; " << "Dist. dep.: " << std::string(evalCase.isDistDependent() ? "true" : "false"); // << std::endl;
00179                 output << "; " << "FieldNumber: " << evalCase.getFieldNumber();
00180 
00181                 UINT32 responseTime = evalCase.getResponseTime();
00182                 if (responseTime < 100000)
00183                 {
00184                         // Normal: Microsekunden
00185                         output << "; " << "Resp. time: " << responseTime << " us";      //  << std::endl;
00186                 }
00187                 else
00188                 {
00189                         // Skaliert: Millisekunden
00190                         output << "; " << "Resp. time: " << (UINT32)(responseTime / 1000) << " ms";     //  << std::endl;
00191                 }
00192                 output << "; " << "Output nr: " << evalCase.getOutputNumber();                          //  << std::endl;
00193                 output << "; " << "Res. neg.: " << std::string(evalCase.isResultNegation() ? "true" : "false") << std::endl;
00194                 ++number;
00195         }
00196 
00197         return output.str();
00198 }
00199 
00200 FieldParameter::CaseResult isFieldInfringed(const SensorStateInfo& sensorStateInfo, const FieldParameter& field, const EvalCaseResults& results)
00201 {
00202         UINT8 isInfringed = 0;
00203 
00204         // find eval case that belongs to the field
00205         EvalCaseVector::const_iterator evalIter;
00206         for (evalIter = sensorStateInfo.getEvalCases().getEvalCases().begin(); evalIter != sensorStateInfo.getEvalCases().getEvalCases().end(); ++evalIter)
00207         {
00208                 const EvalCase& ec = *(*evalIter);
00209                 UINT32 i;
00210                 for (i = 0; i < results.size(); ++i)
00211                 {
00212                         if (ec.getCaseNumber() == results[i].CaseHdr.usiNumber)
00213                         {
00214                                 if (ec.getFieldNumber() == field.getFieldNumber())
00215                                 {
00216                                         isInfringed = results[i].m_eCaseResult;
00217                                         break;
00218                                 }
00219                         }
00220                 }
00221         }
00222 
00223         return FieldParameter::CaseResult(isInfringed);
00224 }
00225 
00226 void SensorStateInfo::setLastKnownEvalCaseResults(const EvalCaseResults& evalCaseResults)
00227 {
00228         Fields::FieldVector::const_iterator fieldIter;
00229         for (fieldIter = m_fields.getFields().begin(); fieldIter != m_fields.getFields().end(); ++fieldIter)
00230         {
00231                 FieldParameter& f = const_cast<FieldParameter&>(*(*fieldIter));
00232                 FieldParameter::CaseResult fieldInfringed = isFieldInfringed(*this, f, evalCaseResults);
00233                 f.setLastKnownInfringementState(fieldInfringed);
00234         }
00235 }
00236 
00237 
00238 } // namespace datatypes


libsick_ldmrs
Author(s): SICK AG , Martin G√ľnther , Jochen Sprickerhof
autogenerated on Wed Jun 14 2017 04:04:50