File: sensor_factors_000.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 (106 lines) | stat: -rw-r--r-- 2,467 bytes parent folder | download | duplicates (8)
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
/*
 * Test convertion for raw -> interpreted and interpreted -> raw
 *
 * Copyright (c) 2004 by FORCE Computers
 *
 * 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.
 *
 * Authors:
 *     Thomas Kanngieser <thomas.kanngieser@fci.com>
 *
 */


#include "test.h"
#include "ipmi_sensor_factors.h"

#define dAnalogDataFormat eIpmiAnalogDataFormatUnsigned
#define dLinearization eIpmiLinearizationLinear
#define dM             136
#define dTolerance     9
#define dB             0
#define dAccuracy      15
#define dAccuracyExp   0
#define dRExp          -4
#define dBExp          0


static cIpmiSdr sdr = 
{
  0,
  1,
  5,
  eSdrTypeFullSensorRecord, 
  60,
  {
    0, 0, // record id
    0x51, // ipmi version
    0, // record type
    0, // length
    0, // owner id
    0, // lun
    0, // num
    0, // entity id
    0, // instance
    0, // initialization
    0, // capabilities
    0, // type
    0, // event reading type
    0, 0, // event mask
    0, 0, // event mask
    0, 0, // event mask
    dAnalogDataFormat << 6, // units 1
    0, // units 2
    0, // units 3
    eIpmiLinearizationLinear,
    dM & 0xff,
    ((dM >> 2) & 0xc0) | (dTolerance & 0x3f),
    dB & 0xff,
    ((dB >> 2) & 0xc0) | (dAccuracy & 0x3f),
    ((dAccuracy >> 2) & 0xf0) | ((dAccuracyExp << 2) & 0x0c),
    ((dRExp << 4) & 0xf0) | (dBExp & 0x0f ),
    0,
    0,
  }
};


int
main( int /*argc*/, char * /*argv*/[] )
{
  cIpmiSensorFactors *s = new cIpmiSensorFactors;

  Test( s->GetDataFromSdr( &sdr ) );

  cIpmiSensorFactors c;
  c.m_analog_data_format = dAnalogDataFormat;
  c.m_linearization      = dLinearization;
  c.m_m                  = dM;
  c.m_tolerance          = dTolerance;
  c.m_b                  = dB;
  c.m_r_exp              = dRExp;
  c.m_accuracy_exp       = dAccuracyExp;
  c.m_accuracy           = dAccuracy;
  c.m_b_exp              = dBExp;

  Test( s->Cmp( c ) );

  for( unsigned int i = 0; i < 256; i++ )
     {
       double d;
       unsigned int r;

       Test( s->ConvertFromRaw( i, d, false ) );
       Test( s->ConvertToRaw( cIpmiSensorFactors::eRoundNormal, d, r, false, false ) );
       Test( r == i );
     }

  delete s;

  return TestResult();
}