SensorStateInfo.cpp
Go to the documentation of this file.
1 //
2 // SensorStateInfo.cpp
3 //
4 // Created on: 02.09.2011
5 // Author: wahnfla
6 //
7 
8 #include "SensorStateInfo.hpp"
9 #include "Measurement.hpp"
10 #include "../tools/errorhandler.hpp"
11 //#include "StringToolbox.hpp"
12 
13 namespace datatypes
14 {
15 
17 {
19 }
20 
21 
23 {
24 }
25 
32 {
33  UINT32 size;
34 
35  // Quick hack: Factor 4 may be ok...
36  size = (UINT32)(4.0 * ((double)sizeof(*this)));
37 
38  return size;
39 }
40 
42 {
43  return m_evalCases;
44 }
45 
47 {
48  return m_fields;
49 }
50 
52 {
53  return m_inputStates;
54 }
55 
57 {
58  return m_measurementList;
59 }
60 
62 {
63  return m_outputStates;
64 }
65 
67 {
68  this->m_evalCases = m_evalCases;
69 }
70 
72 {
73  this->m_fields = m_fields;
74 }
75 
77 {
78  this->m_inputStates = m_inputStates;
79 }
80 
82 {
83  this->m_measurementList = m_measurementList;
84 }
85 
87 {
88  this->m_outputStates = m_outputStates;
89 }
90 
92 {
93  return m_stateMap;
94 }
95 
97 {
98  m_stateMap = stateMap;
99 }
100 
101 // UINT32 SensorStateInfo::getDeviceID() const
102 // {
103 // return m_deviceID;
104 // }
105 //
106 // void SensorStateInfo::setDeviceID(UINT32 deviceID)
107 // {
108 // m_deviceID = deviceID;
109 // }
110 
111 //
112 //
113 //
114 std::string SensorStateInfo::toString() const
115 {
116  std::stringstream output;
117 
118  // Measurement list
119  std::vector<Measurement>::const_iterator meas;
120  for (meas = m_measurementList.m_list.begin(); meas != m_measurementList.m_list.end(); ++meas)
121  {
122  output << meas->getName() << "=" ;
123  output << meas->valueToString() << " ";
124  }
125  output << std::endl;
126 
127  // Filterparameter
128  StateMap::const_iterator mapIter;
129  for (mapIter = m_stateMap.begin(); mapIter != m_stateMap.end(); ++mapIter)
130  {
131  // First = Name
132  // Second = Bool-Wert
133  output << mapIter->first << "=" << std::string(mapIter->second ? "true" : "false") << " "; // << std::endl;
134  }
135  output << std::endl;
136 
137  // Zustand der Bit-Eingaenge
138  output << "Inputs:" << std::endl << " ";
139  StateVector::const_iterator state;
140  UINT32 number = 0;
141  for (state = m_inputStates.begin(); state != m_inputStates.end(); ++state)
142  {
143  output << " " << number << "=" << ioStateToString(*state); // << std::endl;
144  ++number;
145  }
146  output << std::endl;
147 
148  // Zustand der Bit-Ausgaenge
149  output << "Outputs:" << std::endl << " ";
150  number = 0;
151  for (state = m_outputStates.begin(); state != m_outputStates.end(); ++state)
152  {
153  output << " " << number << "=" << ioStateToString(*state); // << std::endl;
154  ++number;
155  }
156  output << std::endl;
157 
158  // Koordinaten der Felder
159  output << "Fields: " << std::endl;
160  Fields::FieldVector::const_iterator field;
161  for (field = m_fields.getFields().begin(); field != m_fields.getFields().end(); ++field)
162  {
163  const FieldParameter& fp = *(*field);
164  output << " " << fp.getFieldNumber() << ": " << fp.getFieldName() << ": " << FieldDescription::fieldTypeToString(fp.getFieldType()) << std::endl;
165  output << " " << fp.getPolygon().toString() << std::endl;
166  }
167 
168  // Auswertefaelle
169  output << "Evalcases: " << std::endl;
170  EvalCaseVector::const_iterator ecp;
171  number = 0;
172  for (ecp = m_evalCases.getEvalCases().begin(); ecp != m_evalCases.getEvalCases().end(); ++ecp)
173  {
174  const EvalCase& evalCase = *(*ecp);
175  output << evalCase.getCaseNumber() << "=" << evalCase.getCaseName(); // << std::endl;
176  output << ": " << "Strat.: " << EvalCase::strategyToString(evalCase.getStrategy()); // std::endl;
177  output << "; " << "Blnk. size: " << evalCase.getBlankingSize() << "m"; // << std::endl;
178  output << "; " << "Dist. dep.: " << std::string(evalCase.isDistDependent() ? "true" : "false"); // << std::endl;
179  output << "; " << "FieldNumber: " << evalCase.getFieldNumber();
180 
181  UINT32 responseTime = evalCase.getResponseTime();
182  if (responseTime < 100000)
183  {
184  // Normal: Microsekunden
185  output << "; " << "Resp. time: " << responseTime << " us"; // << std::endl;
186  }
187  else
188  {
189  // Skaliert: Millisekunden
190  output << "; " << "Resp. time: " << (UINT32)(responseTime / 1000) << " ms"; // << std::endl;
191  }
192  output << "; " << "Output nr: " << evalCase.getOutputNumber(); // << std::endl;
193  output << "; " << "Res. neg.: " << std::string(evalCase.isResultNegation() ? "true" : "false") << std::endl;
194  ++number;
195  }
196 
197  return output.str();
198 }
199 
200 FieldParameter::CaseResult isFieldInfringed(const SensorStateInfo& sensorStateInfo, const FieldParameter& field, const EvalCaseResults& results)
201 {
202  UINT8 isInfringed = 0;
203 
204  // find eval case that belongs to the field
205  EvalCaseVector::const_iterator evalIter;
206  for (evalIter = sensorStateInfo.getEvalCases().getEvalCases().begin(); evalIter != sensorStateInfo.getEvalCases().getEvalCases().end(); ++evalIter)
207  {
208  const EvalCase& ec = *(*evalIter);
209  UINT32 i;
210  for (i = 0; i < results.size(); ++i)
211  {
212  if (ec.getCaseNumber() == results[i].CaseHdr.usiNumber)
213  {
214  if (ec.getFieldNumber() == field.getFieldNumber())
215  {
216  isInfringed = results[i].m_eCaseResult;
217  break;
218  }
219  }
220  }
221  }
222 
223  return FieldParameter::CaseResult(isInfringed);
224 }
225 
227 {
228  Fields::FieldVector::const_iterator fieldIter;
229  for (fieldIter = m_fields.getFields().begin(); fieldIter != m_fields.getFields().end(); ++fieldIter)
230  {
231  FieldParameter& f = const_cast<FieldParameter&>(*(*fieldIter));
232  FieldParameter::CaseResult fieldInfringed = isFieldInfringed(*this, f, evalCaseResults);
233  f.setLastKnownInfringementState(fieldInfringed);
234  }
235 }
236 
237 
238 } // namespace datatypes
std::string toString() const
Text output for debugging.
Definition: Polygon2D.cpp:584
const FieldDescription::FieldType getFieldType() const
void setFields(const Fields &fields)
void setMeasurementList(const MeasurementList &m_measurementList)
uint32_t UINT32
const UINT16 getFieldNumber() const
const std::string & getCaseName() const
Definition: EvalCase.cpp:41
const std::string & getFieldName() const
void setStateMap(const StateMap &stateMap)
static std::string fieldTypeToString(FieldType type)
void setLastKnownInfringementState(CaseResult lastKnownInfringementState)
UINT8 getOutputNumber() const
Definition: EvalCase.cpp:87
const EvalCases & getEvalCases() const
double getBlankingSize() const
Definition: EvalCase.cpp:36
bool isDistDependent() const
Definition: EvalCase.cpp:112
UINT16 getFieldNumber() const
Definition: EvalCase.cpp:56
UINT32 getResponseTime() const
Definition: EvalCase.cpp:92
std::vector< Measurement > m_list
Definition: Measurement.hpp:89
EvaluationStrategy getStrategy() const
Definition: EvalCase.cpp:102
std::map< std::string, bool > StateMap
const EvalCaseVector & getEvalCases() const
Definition: EvalCases.cpp:41
FieldParameter::CaseResult isFieldInfringed(const SensorStateInfo &sensorStateInfo, const FieldParameter &field, const EvalCaseResults &results)
void setInputStates(const StateVector &m_inputStates)
UINT8 getCaseNumber() const
Definition: EvalCase.cpp:46
const StateVector & getInputStates() const
void setLastKnownEvalCaseResults(const EvalCaseResults &evalCaseResults)
const Fields & getFields() const
const StateVector & getOutputStates() const
MeasurementList m_measurementList
e.g. temperature
const StateMap & getStateMap() const
std::vector< IOState > StateVector
const MeasurementList & getMeasurementList() const
static std::string strategyToString(EvaluationStrategy strategy)
Definition: EvalCase.hpp:32
void setEvalCases(const EvalCases &evalCases)
bool isResultNegation() const
Definition: EvalCase.cpp:117
std::string toString() const
const Polygon2D & getPolygon() const
const UINT32 getUsedMemory() const
const FieldVector & getFields() const
Definition: Fields.hpp:43
static std::string ioStateToString(IOState state)
uint8_t UINT8
void setOutputStates(const StateVector &m_outputStates)


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Sat Jun 8 2019 17:57:33