fix alarms
This commit is contained in:
parent
3561a3e3ad
commit
80c88d91f4
@ -55,11 +55,12 @@ parse(Input) when is_binary(Input) ->
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
end, Trees),
|
end, Trees),
|
||||||
|
lager:debug("alarms is: ~p", [Alarms]),
|
||||||
|
|
||||||
case length(Modbus) == 1 of
|
case length(Modbus) == 1 of
|
||||||
true ->
|
true ->
|
||||||
NDevices = lists:map(fun(Device) -> merge_io(Device, Templates) end, Devices),
|
NDevices = lists:map(fun(Device) -> merge_io(Device, Templates) end, Devices),
|
||||||
AST = #ast{modbus = hd(Modbus), devices = NDevices, alarms = Alarms },
|
AST = #ast{modbus = hd(Modbus), devices = NDevices},
|
||||||
{ok, AST};
|
{ok, AST};
|
||||||
false ->
|
false ->
|
||||||
{error, modbus_block_error}
|
{error, modbus_block_error}
|
||||||
@ -190,9 +191,7 @@ parse_ast0(#block{ident = <<"alarm", Name0/binary>>, props = Props}) ->
|
|||||||
#modbus_alarm {
|
#modbus_alarm {
|
||||||
name = string:trim(Name0),
|
name = string:trim(Name0),
|
||||||
condition = map_of_binary(<<"condition">>, MapProps, <<>>),
|
condition = map_of_binary(<<"condition">>, MapProps, <<>>),
|
||||||
hold_time = map_of_time(<<"hold_time">>, MapProps, 0),
|
hold_time = map_of_time(<<"hold_time">>, MapProps, 0)
|
||||||
actions = maps:get(<<"actions">>, MapProps, undefined),
|
|
||||||
recovery_actions = maps:get(<<"recovery_actions">>, MapProps, undefined)
|
|
||||||
}.
|
}.
|
||||||
|
|
||||||
parse_ast1(Props) ->
|
parse_ast1(Props) ->
|
||||||
|
|||||||
@ -94,7 +94,7 @@ start_link(OwnerPid, AST = #ast{}) when is_pid(OwnerPid) ->
|
|||||||
%% @doc Whenever a gen_statem is started using gen_statem:start/[3,4] or
|
%% @doc Whenever a gen_statem is started using gen_statem:start/[3,4] or
|
||||||
%% gen_statem:start_link/[3,4], this function is called by the new
|
%% gen_statem:start_link/[3,4], this function is called by the new
|
||||||
%% process to initialize.
|
%% process to initialize.
|
||||||
init([OwnerPid, AST = #ast{modbus = Modbus = #modbus{transport = Transport, error_log = ErrorLog, access_log = AccessLog}, devices = Devices, alarms = Alarms}]) ->
|
init([OwnerPid, AST = #ast{modbus = Modbus = #modbus{transport = Transport, error_log = ErrorLog, access_log = AccessLog}, devices = Devices}]) ->
|
||||||
%lager:debug("[modbus_service] ast is: ~p", [AST]),
|
%lager:debug("[modbus_service] ast is: ~p", [AST]),
|
||||||
lager:debug("[modbus_service] devices is: ~p", [Devices]),
|
lager:debug("[modbus_service] devices is: ~p", [Devices]),
|
||||||
|
|
||||||
@ -207,11 +207,6 @@ handle_event(info, {device_report, DeviceName, MetricName, Value, Uint}, ?CONNEC
|
|||||||
OwnerPid ! {metric_data, DeviceName, MetricName, Value, Uint},
|
OwnerPid ! {metric_data, DeviceName, MetricName, Value, Uint},
|
||||||
{keep_state, State};
|
{keep_state, State};
|
||||||
|
|
||||||
handle_event(info, {device_alarm, AlarmName, HoldTime, Val}, ?CONNECTED, State = #state{owner_pid = OwnerPid}) ->
|
|
||||||
lager:debug("[modbus_service] get alarm device_name: ~p, name: ~p, value: ~p, uint: ~p", [DeviceName, MetricName, Value, Uint]),
|
|
||||||
% OwnerPid ! {metric_data, DeviceName, MetricName, Value, Uint},
|
|
||||||
{keep_state, State};
|
|
||||||
|
|
||||||
%% 广播消息
|
%% 广播消息
|
||||||
handle_event(info, {broadcast, Key, Val}, ?CONNECTED, State = #state{alarm_pids = AlarmPids}) ->
|
handle_event(info, {broadcast, Key, Val}, ?CONNECTED, State = #state{alarm_pids = AlarmPids}) ->
|
||||||
%% 推送告警信息
|
%% 推送告警信息
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user