Skip to content

Commit 6bb2462

Browse files
committed
Factor out bool encoding function.
Sets `true` to `1` and `false` to `0`.
1 parent 0d6d5a7 commit 6bb2462

File tree

1 file changed

+16
-53
lines changed

1 file changed

+16
-53
lines changed

src/eipmi_request.erl

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,7 @@ encode_storage(Req, _Properties) when
177177
%% @private
178178
%%------------------------------------------------------------------------------
179179
encode_transport(?GET_IP_UDP_RMCP_STATISTICS, Properties) ->
180-
Clear = proplists:get_value(clear_statistics, Properties, false),
181-
C =
182-
case Clear of
183-
true -> 1;
184-
false -> 0
185-
end,
180+
C = get_encoded_bool(clear_statistics, Properties),
186181
<<0:4, ?IPMI_REQUESTED_CHANNEL:4, 0:7, C:1>>;
187182
encode_transport(?SET_LAN_CONFIGURATION_PARAMETERS, Properties) ->
188183
P = proplists:get_value(parameter, Properties),
@@ -239,11 +234,7 @@ encode_transport(?SET_LAN_CONFIGURATION_PARAMETERS, Properties) ->
239234
oem1 -> 6;
240235
oem2 -> 7
241236
end,
242-
A =
243-
case proplists:get_value(acknowledge, Properties, false) of
244-
true -> 1;
245-
false -> 0
246-
end,
237+
A = get_encoded_bool(acknowledge, Properties),
247238
To = proplists:get_value(timeout, Properties, 0),
248239
R = proplists:get_value(retries, Properties, 0),
249240
<<0:4, S:4, A:1, 0:4, T:3, To:8, 0:5, R:3>>;
@@ -291,18 +282,8 @@ encode_chassis(?CHASSIS_IDENTIFY, Properties) ->
291282
<<0:8, 0:7, 1:1>>
292283
end;
293284
encode_chassis(?SET_CHASSIS_CAPABILITIES, Properties) ->
294-
Lockout = proplists:get_bool(lockout, Properties),
295-
L =
296-
case Lockout of
297-
true -> 1;
298-
false -> 0
299-
end,
300-
Intrusion = proplists:get_bool(intrusion, Properties),
301-
I =
302-
case Intrusion of
303-
true -> 1;
304-
false -> 0
305-
end,
285+
L = get_encoded_bool(lockout, Properties),
286+
I = get_encoded_bool(intrusion, Properties),
306287
F = proplists:get_value(fru_address, Properties),
307288
Sdr = proplists:get_value(sdr_address, Properties),
308289
Sel = proplists:get_value(sel_address, Properties),
@@ -324,30 +305,10 @@ encode_chassis(?SET_POWER_RESTORE_POLICY, Properties) ->
324305
end,
325306
<<0:5, P:3>>;
326307
encode_chassis(?SET_FRONT_PANEL_ENABLES, Properties) ->
327-
Standby = proplists:get_bool(disable_standby, Properties),
328-
S =
329-
case Standby of
330-
true -> 1;
331-
false -> 0
332-
end,
333-
Diagnostic = proplists:get_bool(disable_diagnostic_interrupt, Properties),
334-
D =
335-
case Diagnostic of
336-
true -> 1;
337-
false -> 0
338-
end,
339-
Reset = proplists:get_bool(disable_reset, Properties),
340-
R =
341-
case Reset of
342-
true -> 1;
343-
false -> 0
344-
end,
345-
Power = proplists:get_bool(disable_power, Properties),
346-
P =
347-
case Power of
348-
true -> 1;
349-
false -> 0
350-
end,
308+
S = get_encoded_bool(disable_standby, Properties),
309+
D = get_encoded_bool(disable_diagnostic_interrupt, Properties),
310+
R = get_encoded_bool(disable_reset, Properties),
311+
P = get_encoded_bool(disable_power, Properties),
351312
<<0:4, S:1, D:1, R:1, P:1>>;
352313
encode_chassis(?SET_POWER_CYCLE_INTERVAL, Properties) ->
353314
I = proplists:get_value(interval, Properties, 0),
@@ -392,12 +353,8 @@ encode_picmg(?GET_FRU_ACTIVATION_POLICY, Properties) ->
392353
<<?PICMG_ID:8, FruId:8>>;
393354
encode_picmg(?SET_FRU_ACTIVATION, Properties) ->
394355
FruId = proplists:get_value(fru_id, Properties),
395-
Activate = proplists:get_value(activate, Properties),
396-
<<?PICMG_ID:8, FruId:8,
397-
(case Activate of
398-
true -> 1;
399-
false -> 0
400-
end):8>>;
356+
Activate = get_encoded_bool(activate, Properties),
357+
<<?PICMG_ID:8, FruId:8, Activate:8>>;
401358
encode_picmg(?FRU_CONTROL, Properties) ->
402359
FruId = proplists:get_value(fru_id, Properties),
403360
Control = proplists:get_value(control, Properties),
@@ -523,3 +480,9 @@ encode_picmg_site_type(pmc) -> 16#08;
523480
encode_picmg_site_type(rear_transition_module) -> 16#09;
524481
encode_picmg_site_type(mch) -> 16#0a;
525482
encode_picmg_site_type(power_module) -> 16#0b.
483+
484+
get_encoded_bool(Prop, List) ->
485+
case proplists:get_bool(Prop, List) of
486+
true -> 1;
487+
false -> 0
488+
end.

0 commit comments

Comments
 (0)