summaryrefslogtreecommitdiffstats
path: root/scripts/writesensor.mako.cpp
blob: 41f9d60b89f027ac0fa9855746bbfeb0adace1fd (plain)
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
## This file is a template.  The comment below is emitted
## into the rendered file; feel free to edit this file.

// !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!!
<%
from collections import defaultdict
readingTypes = { 'reading': 'cmdData.reading',
                 'assertion': '0',
                 'eventdata1': 'cmdData.eventData1',
                 'eventdata2': 'cmdData.eventData2',
                 'eventdata3': 'cmdData.eventData3'}
funcProps = {}
%>\
%for key in sensorDict.iterkeys():
<%
    sensor = sensorDict[key]
    sensorType = sensor["sensorType"]
    serviceInterface = sensor["serviceInterface"]
    readingType = sensor["readingType"]
    if serviceInterface == "org.freedesktop.DBus.Properties":
        command = "Set"
    elif serviceInterface == "xyz.openbmc_project.Inventory.Manager":
        command = "Notify"
    else:
        assert "Un-supported interface: serviceInterface"
    endif
    sensorInterface = serviceInterface
    updateFunc = "sensor_set::sensor_type_" + str(sensorType) + "::update"
    funcProps[sensorType] = {}
    funcProps[sensorType].update({"command" : command})
    funcProps[sensorType].update({"path" : sensor["path"]})
    funcProps[sensorType].update({"serviceInterface" : serviceInterface})
    funcProps[sensorType].update({"updateFunc" : updateFunc})
    funcProps[sensorType].update({"readingType" : readingType})
    funcProps[sensorType].update({"source" : readingTypes[readingType]})
    funcProps[sensorType].update({"interfaces" : sensor["interfaces"]})
    if command == "Set":
        for interface, props in funcProps[sensorType]["interfaces"].items():
            sensorInterface = interface
    funcProps[sensorType].update({"sensorInterface" : sensorInterface})
%>\
% endfor
#include <bitset>
#include "types.hpp"
#include "host-ipmid/ipmid-api.h"
#include <phosphor-logging/elog-errors.hpp>
#include "xyz/openbmc_project/Common/error.hpp"
#include <phosphor-logging/log.hpp>
#include "sensordatahandler.hpp"

namespace ipmi
{
namespace sensor
{


namespace sensor_set
{
% for sensorType, funcProp in funcProps.iteritems():
namespace sensor_type_${sensorType}
{

ipmi_ret_t update(const SetSensorReadingReq& cmdData,
                  const Info& sensorInfo)
{
    auto msg = ${(funcProp["command"]).lower()}::makeDbusMsg(
                    "${funcProp['serviceInterface']}",
                     sensorInfo.sensorPath,
                    "${funcProp['command']}",
                    "${funcProp['sensorInterface']}");

    auto interfaceList = sensorInfo.sensorInterfaces;
% for interface, properties in funcProp["interfaces"].iteritems():
    % for dbus_property, property_value in properties.iteritems():
        % for offset, values in property_value.iteritems():
            % if offset == 0xFF:
<%                funcName = "appendReadingData"%>\
<%                param = "static_cast<"+values["type"]+">("+funcProp["source"]+")"%>\
            %  elif funcProp["readingType"] == "assertion":
<%                funcName = "appendAssertion"%>\
<%                param = "sensorInfo.sensorPath, cmdData"%>\
            % else:
<%                funcName = "appendDiscreteSignalData"%>\
<%                param = funcProp["source"]%>\
            % endif
        % endfor
    % endfor
% endfor
    auto result = ${(funcProp["command"]).lower()}::${funcName}(msg,
                        interfaceList,
                        ${param});
    if (result != IPMI_CC_OK)
    {
        return result;
    }
    return updateToDbus(msg);
}
}//namespace sensor_type_${sensorType}

% endfor
}//namespace sensor_get
}//namespace sensor
}//namespace ipmi

using namespace ipmi::sensor;
extern const IdInfoMap sensors = {
% for key in sensorDict.iterkeys():
   % if key:
{${key},{
<%
       sensor = sensorDict[key]
       interfaces = sensor["interfaces"]
       path = sensor["path"]
       sensorType = sensor["sensorType"]
       readingType = sensor["sensorReadingType"]
       multiplier = sensor.get("multiplierM", 1)
       offset = sensor.get("offsetB", 0)
       exp = sensor.get("bExp", 0)
       valueReadingType = sensor["readingType"]
       updateFunc = funcProps[sensorType]["updateFunc"]
%>
        ${sensorType},"${path}",${readingType},${multiplier},${offset},${exp},
        ${offset * pow(10,exp)},${updateFunc},{
    % for interface,properties in interfaces.iteritems():
            {"${interface}",{
            % for dbus_property,property_value in properties.iteritems():
                {"${dbus_property}",{
                % for offset,values in property_value.iteritems():
                    { ${offset},{
                        % if offset == 0xFF:
                            }},
<%                          continue %>\
                        % endif
<%                          valueType = values["type"] %>\
                    % for name,value in values.iteritems():
                        % if name == "type":
<%                          continue %>\
                        % endif
                        % if valueType == "string":
                           std::string("${value}"),
                        % elif valueType == "bool":
<%                         value = str(value).lower() %>\
                           ${value},
                        % else:
                           ${value},
                        % endif
                     % endfor
                        }
                    },
                % endfor
                }},
            % endfor
            }},
    % endfor
     }
}},
   % endif
% endfor
};

OpenPOWER on IntegriCloud