From 37cb8d89af13483d41a675dd802cdd96337c040a Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Wed, 7 May 2025 22:14:29 +0800 Subject: [PATCH] fix --- apps/iot/src/iot_device_sup.erl | 60 --------------------------------- apps/iot/src/iot_host.erl | 2 +- apps/iot/src/iot_sup.erl | 9 ----- 3 files changed, 1 insertion(+), 70 deletions(-) delete mode 100644 apps/iot/src/iot_device_sup.erl diff --git a/apps/iot/src/iot_device_sup.erl b/apps/iot/src/iot_device_sup.erl deleted file mode 100644 index 9b9d26d..0000000 --- a/apps/iot/src/iot_device_sup.erl +++ /dev/null @@ -1,60 +0,0 @@ -%%%------------------------------------------------------------------- -%%% @author aresei -%%% @copyright (C) 2023, -%%% @doc -%%% @end -%%%------------------------------------------------------------------- --module(iot_device_sup). --include("iot.hrl"). - --behaviour(supervisor). - --export([start_link/0, init/1, delete_device/1, ensured_device_started/1]). - -start_link() -> - supervisor:start_link({local, ?MODULE}, ?MODULE, []). - -init([]) -> - %% 启动主机相关的devices - {ok, DeviceInfos} = device_bo:get_all_devices(), - Specs = lists:map(fun child_spec/1, DeviceInfos), - - {ok, {#{strategy => one_for_one, intensity => 1000, period => 3600}, Specs}}. - --spec ensured_device_started(UUID :: binary()) -> {ok, Pid :: pid()} | {error, Reason :: any()}. -ensured_device_started(DeviceUUID) when is_binary(DeviceUUID) -> - case iot_device:get_pid(DeviceUUID) of - undefined -> - case supervisor:start_child(?MODULE, child_spec(DeviceUUID)) of - {ok, Pid} when is_pid(Pid) -> - {ok, Pid}; - {error, {'already_started', Pid}} when is_pid(Pid) -> - {ok, Pid}; - {error, Error} -> - {error, Error} - end; - Pid when is_pid(Pid) -> - {ok, Pid} - end. - -delete_device(UUID) when is_binary(UUID) -> - Id = iot_device:get_name(UUID), - ok = supervisor:terminate_child(?MODULE, Id), - supervisor:delete_child(?MODULE, Id). - -child_spec(DeviceUUID) when is_binary(DeviceUUID) -> - Name = iot_device:get_name(DeviceUUID), - #{id => Name, - start => {iot_device, start_link, [Name, DeviceUUID]}, - restart => permanent, - shutdown => 2000, - type => worker, - modules => ['iot_device']}; -child_spec(DeviceInfo = #{<<"device_uuid">> := DeviceUUID}) when is_binary(DeviceUUID) -> - Name = iot_device:get_name(DeviceUUID), - #{id => Name, - start => {iot_device, start_link, [Name, DeviceInfo]}, - restart => permanent, - shutdown => 2000, - type => worker, - modules => ['iot_device']}. \ No newline at end of file diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index c13242d..e45063d 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -325,7 +325,7 @@ handle_event({call, From}, {activate_device, DeviceUUID, Auth}, _, State = #stat %% 需要将消息转换成json格式然后再处理, 需要在host进程里面处理, 数据带有props,服务端暂时未用到 handle_event(cast, {handle, {data, Data}}, ?STATE_ACTIVATED, State = #state{has_session = true}) -> - handle_data(Data, State), + %handle_data(Data, State), {keep_state, State}; %% ping的数据是通过aes加密后的,因此需要在有会话的情况下才行 diff --git a/apps/iot/src/iot_sup.erl b/apps/iot/src/iot_sup.erl index c644a48..cf060de 100644 --- a/apps/iot/src/iot_sup.erl +++ b/apps/iot/src/iot_sup.erl @@ -28,15 +28,6 @@ start_link() -> init([]) -> SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600}, Specs = [ - #{ - id => 'iot_device_sup', - start => {'iot_device_sup', start_link, []}, - restart => permanent, - shutdown => 2000, - type => supervisor, - modules => ['iot_device_sup'] - }, - #{ id => 'iot_host_sup', start => {'iot_host_sup', start_link, []},