File: new_sim_sensor_common.cpp

package info (click to toggle)
openhpi 3.8.0-2.3
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 31,888 kB
  • sloc: ansic: 225,326; cpp: 63,687; java: 16,472; cs: 15,161; python: 11,884; sh: 11,508; makefile: 4,945; perl: 1,529; xml: 36; asm: 13
file content (226 lines) | stat: -rw-r--r-- 6,108 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/** 
 * @file    new_sim_sensor_common.cpp
 *
* The file includes a class for common sensor handling:\n
 * NewSimulatorSensorCommon
 * 
 * @author  Lars Wetzel <larswetzel@users.sourceforge.net>
 * @version 0.1
 * @date    2010
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This
 * file and program are licensed under a BSD style license.  See
 * the Copying file included with the OpenHPI distribution for
 * full licensing terms.
 * 
 */
  
#include "new_sim_sensor_common.h"
#include "new_sim_domain.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <glib.h>
#include <math.h>


/**
 * Constructor
 **/
NewSimulatorSensorCommon::NewSimulatorSensorCommon( NewSimulatorResource *res )
  : NewSimulatorSensor( res )
{
}


/**
 * Fully qualified constructor to fill an object with the parsed data
 **/
NewSimulatorSensorCommon::NewSimulatorSensorCommon( NewSimulatorResource *res,
                      SaHpiRdrT rdr, 
                      SaHpiSensorReadingT data, 
                      SaHpiEventStateT event_state, 
                      SaHpiEventStateT event_amask, 
                      SaHpiEventStateT event_dmask,
                      SaHpiBoolT enabled, 
                      SaHpiBoolT event_enabled)
  : NewSimulatorSensor( res, rdr, data, event_state, event_amask, event_dmask, 
                        enabled, event_enabled ) {    
}


/**
 * Destructor
 **/
NewSimulatorSensorCommon::~NewSimulatorSensorCommon()
{
}


/**
 * A rdr structure is filled with the internally data
 * 
 * This method is called by method NewSimulatorRdr::Populate().
 * 
 * @param resource Address of resource structure
 * @param rdr Address of rdr structure
 * 
 * @return true
 **/
bool NewSimulatorSensorCommon::CreateRdr( SaHpiRptEntryT &resource,
                                     SaHpiRdrT &rdr ) {
  if ( NewSimulatorSensor::CreateRdr( resource, rdr ) == false )
       return false;

  return true;
}


/** 
 * HPI function saHpiSensorReadingGet()
 * 
 * See also the description of the function inside the specification or header file.
 * Copying the internal reading values (if a read is allowed).
 * 
 * @param data sensor reading variable in which the data should be copied 
 * @param state sensor event state variable in which the states should be copied
 * 
 * @return error code 
 **/
SaErrorT NewSimulatorSensorCommon::GetSensorReading( SaHpiSensorReadingT &data,
                                                     SaHpiEventStateT &state ) {

  stdlog << "DBG: NewSimulatorSensorCommon::GetSensorReading is called\n";                                                 	
  if ( m_enabled == SAHPI_FALSE )
     return SA_ERR_HPI_INVALID_REQUEST;

  if ( &data != NULL ) {
     if (m_read_support) {
        memcpy( &data, &m_read_data, sizeof( SaHpiSensorReadingT ));
     } else {
        memset( &data, 0, sizeof( SaHpiSensorReadingT ) );
        data.IsSupported = SAHPI_FALSE;
     }
  }

  if ( &state != NULL ) {
     memcpy( &state, &m_event_data, sizeof( SaHpiEventStateT ) );
  }

  return SA_OK;
}

/**
SaErrorT
NewSimulatorSensorCommon::CreateEvent( NewSimulatorEvent *event, SaHpiEventT &h )
{

  SaErrorT rv = NewSimulatorSensor::CreateEvent( event, h );

  if ( rv != SA_OK )
       return rv;

  // sensor event
  SaHpiSensorEventT &se = h.EventDataUnion.SensorEvent;

  se.Assertion = (SaHpiBoolT)!(event->m_data[9] & 0x80);

  se.EventState = (1 << (event->m_data[10] & 0x0f));

  // default value
  h.Severity = SAHPI_INFORMATIONAL;

  SaHpiSensorOptionalDataT optional_data = 0;

  // byte 2
  tIpmiEventType type = (tIpmiEventType)(event->m_data[10] >> 6);

  if ( type == eIpmiEventData1 )
  {
      if ((event->m_data[11] & 0x0f) != 0x0f)
      {
          se.PreviousState = (1 << (event->m_data[11] & 0x0f));
          optional_data |= SAHPI_SOD_PREVIOUS_STATE;
      }
      if ((event->m_data[11] & 0xf0) != 0xf0)
      {
          SaHpiEventStateT evt_sec_state = (1 << ((event->m_data[11]>> 4) & 0x0f));
          switch (evt_sec_state)
          {
          case SAHPI_ES_OK:
              h.Severity = SAHPI_OK;
              break;
          case SAHPI_ES_MINOR_FROM_OK:
              h.Severity = SAHPI_MINOR;
              break;
          case SAHPI_ES_MAJOR_FROM_LESS:
              h.Severity = SAHPI_MAJOR;
              break;
          case SAHPI_ES_CRITICAL_FROM_LESS:
              h.Severity = SAHPI_CRITICAL;
              break;
          case SAHPI_ES_MINOR_FROM_MORE:
              h.Severity = SAHPI_MINOR;
              break;
          case SAHPI_ES_MAJOR_FROM_CRITICAL:
              h.Severity = SAHPI_MAJOR;
              break;
          case SAHPI_ES_CRITICAL:
              h.Severity = SAHPI_CRITICAL;
              break;
          case SAHPI_ES_MONITOR:
              h.Severity = SAHPI_INFORMATIONAL;
              break;
          case SAHPI_ES_INFORMATIONAL:
              h.Severity = SAHPI_INFORMATIONAL;
              break;
          }
      }
  }
  else if ( type == eIpmiEventData2 )
  {
       se.Oem = (SaHpiUint32T)event->m_data[11]; 
       optional_data |= SAHPI_SOD_OEM;
  }
  else if ( type == eIpmiEventData3 )
  {
       se.SensorSpecific = (SaHpiUint32T)event->m_data[11]; 
       optional_data |= SAHPI_SOD_SENSOR_SPECIFIC;
  }

  // byte 3
  type = (tIpmiEventType)((event->m_data[10] & 0x30) >> 4);

  if ( type == eIpmiEventData2 )
  {
       se.Oem |= (SaHpiUint32T)((event->m_data[12] << 8) & 0xff00);
       optional_data |= SAHPI_SOD_OEM;
  }
  else if ( type == eIpmiEventData3 )
  {
       se.SensorSpecific |= (SaHpiUint32T)((event->m_data[12] << 8) & 0xff00);
       optional_data |= SAHPI_SOD_SENSOR_SPECIFIC;
  }

  se.OptionalDataPresent = optional_data;


  return SA_OK;
}
**/


/** 
 * Dump the sensor information
 * 
 * @param dump Address of the log
 * 
 **/
void NewSimulatorSensorCommon::Dump( NewSimulatorLog &dump ) const {
	
  NewSimulatorSensor::Dump( dump );
  dump << "Common Sensor is defined,\n";
}