fix command
This commit is contained in:
parent
e93c0fbcfd
commit
1dc7fb175c
@ -25,7 +25,7 @@
|
|||||||
-export([start_link/2, get_name/1, get_alias_name/1, get_pid/1, handle/2, activate/2]).
|
-export([start_link/2, get_name/1, get_alias_name/1, get_pid/1, handle/2, activate/2]).
|
||||||
-export([get_metric/1, get_status/1, kill/1]).
|
-export([get_metric/1, get_status/1, kill/1]).
|
||||||
%% 通讯相关
|
%% 通讯相关
|
||||||
-export([pub/4, attach_channel/2, command/2]).
|
-export([pub/4, attach_channel/2]).
|
||||||
-export([deploy_container/3, start_container/2, stop_container/2, remove_container/2, kill_container/2, config_container/3, get_containers/1, await_reply/3]).
|
-export([deploy_container/3, start_container/2, stop_container/2, remove_container/2, kill_container/2, config_container/3, get_containers/1, await_reply/3]).
|
||||||
-export([heartbeat/1]).
|
-export([heartbeat/1]).
|
||||||
|
|
||||||
@ -144,10 +144,6 @@ await_reply(Pid, Ref, Timeout) when is_pid(Pid), is_reference(Ref), is_integer(T
|
|||||||
pub(Pid, Topic, Qos, Content) when is_pid(Pid), is_binary(Topic), is_integer(Qos), is_binary(Content) ->
|
pub(Pid, Topic, Qos, Content) when is_pid(Pid), is_binary(Topic), is_integer(Qos), is_binary(Content) ->
|
||||||
gen_statem:call(Pid, {pub, Topic, Qos, Content}).
|
gen_statem:call(Pid, {pub, Topic, Qos, Content}).
|
||||||
|
|
||||||
-spec command(Pid :: pid(), Command :: message_pb:'CastFrame.Command'()) -> ok | {error, Reason :: any()}.
|
|
||||||
command(Pid, Command) when is_pid(Pid) ->
|
|
||||||
gen_statem:call(Pid, {command, Command}).
|
|
||||||
|
|
||||||
-spec heartbeat(Pid :: pid()) -> no_return().
|
-spec heartbeat(Pid :: pid()) -> no_return().
|
||||||
heartbeat(undefined) ->
|
heartbeat(undefined) ->
|
||||||
ok;
|
ok;
|
||||||
@ -247,19 +243,6 @@ handle_event({call, From}, {pub, Topic, Qos, Content}, ?STATE_ACTIVATED, State =
|
|||||||
{keep_state, State, [{reply, From, {error, <<"主机离线,发送失败"/utf8>>}}]}
|
{keep_state, State, [{reply, From, {error, <<"主机离线,发送失败"/utf8>>}}]}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
%% 发送指令时
|
|
||||||
handle_event({call, From}, {command, Command}, ?STATE_ACTIVATED, State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = HasSession}) ->
|
|
||||||
case HasSession andalso is_pid(ChannelPid) of
|
|
||||||
true ->
|
|
||||||
logger:debug("[iot_host] host: ~p, command: ~p", [UUID, Command]),
|
|
||||||
%% 通过websocket发送请求
|
|
||||||
ssl_channel:command(ChannelPid, Command),
|
|
||||||
{keep_state, State, [{reply, From, ok}]};
|
|
||||||
false ->
|
|
||||||
logger:debug("[iot_host] host: ~p, command: ~p, invalid state: ~p", [UUID, Command, state_map(State)]),
|
|
||||||
{keep_state, State, [{reply, From, {error, <<"主机离线,发送指令失败"/utf8>>}}]}
|
|
||||||
end;
|
|
||||||
|
|
||||||
%% 激活主机
|
%% 激活主机
|
||||||
handle_event({call, From}, {activate, true}, _, State = #state{uuid = UUID, channel_pid = ChannelPid}) ->
|
handle_event({call, From}, {activate, true}, _, State = #state{uuid = UUID, channel_pid = ChannelPid}) ->
|
||||||
case is_pid(ChannelPid) of
|
case is_pid(ChannelPid) of
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user