fix
This commit is contained in:
parent
f781d5e94b
commit
6375eaefe1
@ -27,7 +27,7 @@
|
||||
device_uuid :: binary(),
|
||||
service_name :: binary(),
|
||||
at :: integer(),
|
||||
tags :: map(),
|
||||
tags :: term(),
|
||||
fields :: binary()
|
||||
}).
|
||||
|
||||
|
||||
@ -128,24 +128,27 @@ handle_info({connect_reply, Reply}, State = #state{status = ?STATE_CONNECTING, t
|
||||
|
||||
handle_info({auth_reply, {ok, ReplyBin}}, State = #state{status = ?STATE_AUTH, transport_pid = TransportPid}) ->
|
||||
try message_pb:decode_msg(ReplyBin, auth_reply) of
|
||||
#auth_reply{code = 1, message = Message, repository_url = RepositoryUrl} ->
|
||||
lager:debug("[efka_agent] auth failed, message: ~p, repository_url: ~p", [Message, RepositoryUrl]),
|
||||
{noreply, State#state{status = ?STATE_ACTIVATED}};
|
||||
%% 主机在后台的授权未通过;此时agent不能推送数据给云端服务器,但是云端服务器可以推送命令给agent
|
||||
%% socket的连接状态需要维持
|
||||
#auth_reply{code = -1, message = Message, repository_url = _} ->
|
||||
lager:debug("[efka_agent] auth denied, message: ~p", [Message]),
|
||||
{noreply, State#state{status = ?STATE_RESTRICTED}};
|
||||
#auth_reply{code = -2, message = Message, repository_url = _} ->
|
||||
% 其他类型的错误,需要间隔时间重试
|
||||
efka_logger:debug("[efka_agent] auth failed, message: ~p", [Message]),
|
||||
efka_transport:stop(TransportPid),
|
||||
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}};
|
||||
_ ->
|
||||
% 其他类型的错误,需要间隔时间重试
|
||||
lager:debug("[efka_agent] auth failed, invalid message"),
|
||||
efka_transport:stop(TransportPid),
|
||||
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}}
|
||||
#auth_reply{code = Code, message = Message, repository_url = RepositoryUrl} ->
|
||||
case Code of
|
||||
0 ->
|
||||
lager:debug("[efka_agent] auth failed, message: ~p, repository_url: ~p", [Message, RepositoryUrl]),
|
||||
{noreply, State#state{status = ?STATE_ACTIVATED}};
|
||||
1 ->
|
||||
%% 主机在后台的授权未通过;此时agent不能推送数据给云端服务器,但是云端服务器可以推送命令给agent
|
||||
%% socket的连接状态需要维持
|
||||
lager:debug("[efka_agent] auth denied, message: ~p", [Message]),
|
||||
{noreply, State#state{status = ?STATE_RESTRICTED}};
|
||||
2 ->
|
||||
% 其他类型的错误,需要间隔时间重试
|
||||
efka_logger:debug("[efka_agent] auth failed, message: ~p", [Message]),
|
||||
efka_transport:stop(TransportPid),
|
||||
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}};
|
||||
_ ->
|
||||
% 其他类型的错误,需要间隔时间重试
|
||||
lager:debug("[efka_agent] auth failed, invalid message"),
|
||||
efka_transport:stop(TransportPid),
|
||||
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}}
|
||||
end
|
||||
catch _:Reason ->
|
||||
% 其他类型的错误,需要间隔时间重试
|
||||
lager:debug("[efka_agent] auth decode bin get error: ~p", [Reason]),
|
||||
@ -161,7 +164,7 @@ handle_info({auth_reply, {error, Reason}}, State = #state{transport_pid = Transp
|
||||
%% 激活消息
|
||||
|
||||
%% TODO
|
||||
handle_info({server_push_message, <<8:8, ActivatePush>>}, State = #state{transport_pid = TransportPid, status = Status}) ->
|
||||
handle_info({server_push_message, <<8:8, ActivatePush/binary>>}, State = #state{transport_pid = TransportPid, status = Status}) ->
|
||||
#activate_push{auth = Auth} = message_pb:decode_msg(ActivatePush, activate_push),
|
||||
case {Auth, Status} of
|
||||
{true, ?STATE_ACTIVATED} ->
|
||||
@ -176,8 +179,8 @@ handle_info({server_push_message, <<8:8, ActivatePush>>}, State = #state{transpo
|
||||
end;
|
||||
|
||||
%% 收到需要回复的指令
|
||||
handle_info({server_push_message, PacketId, <<16:8, Directive>>}, State = #state{transport_pid = TransportPid, status = ?STATE_ACTIVATED}) ->
|
||||
#topic_message{topic = Topic, content = Content} = message_pb:decode_msg(Directive, directive),
|
||||
handle_info({server_push_message, PacketId, <<16:8, Directive/binary>>}, State = #state{transport_pid = TransportPid, status = ?STATE_ACTIVATED}) ->
|
||||
#topic_message{topic = Topic, content = Content} = message_pb:decode_msg(Directive, topic_message),
|
||||
efka_logger:debug("[efka_agent] get directive with packet_id: ~p, to device_uuid: ~p, content: ~p", [PacketId, Topic, Content]),
|
||||
%% 消息发送到订阅系统
|
||||
case PacketId > 0 of
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(id_generator_model).
|
||||
-author("anlicheng").
|
||||
-include("efka_tables.hrl").
|
||||
|
||||
%% API
|
||||
-export([create_table/0, next_id/1]).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user