From 1977fa527899c2ca8cb21593ef48d02ab0cc6a86 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Mon, 25 Dec 2023 17:26:33 +0800 Subject: [PATCH] fix --- apps/iot/src/consumer/iot_zd_consumer.erl | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/iot/src/consumer/iot_zd_consumer.erl b/apps/iot/src/consumer/iot_zd_consumer.erl index ce701dd..5a05c02 100644 --- a/apps/iot/src/consumer/iot_zd_consumer.erl +++ b/apps/iot/src/consumer/iot_zd_consumer.erl @@ -15,7 +15,7 @@ %% API -export([start_link/0]). --export([mock/0, mock/1]). +-export([mock/4]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). @@ -43,19 +43,15 @@ %%% API %%%=================================================================== -mock() -> - LocationCode = <<"0001000290040150004002560">>, - mock(LocationCode). - -mock(LocationCode) when is_binary(LocationCode) -> +mock(LocationCode, SType, CType, Value) when is_binary(LocationCode), is_integer(SType), is_integer(CType) -> Req = #{ <<"version">> => <<"1.0">>, <<"ts">> => iot_util:current_time(), <<"properties">> => #{ <<"type">> => <<"ctrl">>, - <<"stype">> => 0, - <<"ctype">> => 1, - <<"value">> => 1234, + <<"stype">> => SType, + <<"ctype">> => CType, + <<"value">> => Value, <<"timestamp">> => iot_util:current_time() }, <<"location_code">> => LocationCode @@ -98,9 +94,9 @@ init([]) -> {noreply, NewState :: #state{}, timeout() | hibernate} | {stop, Reason :: term(), Reply :: term(), NewState :: #state{}} | {stop, Reason :: term(), NewState :: #state{}}). -handle_call({mock, Request}, _From, State = #state{conn_pid = ConnPid}) when is_pid(ConnPid) -> +handle_call({mock, Request}, _From, State = #state{conn_pid = ConnPid, flight_num = FlightNum}) when is_pid(ConnPid) -> publish_directive(Request, jiffy:encode(Request, [force_utf8])), - {reply, ok, State}. + {reply, ok, State#state{flight_num = FlightNum + 1}}. %% @private %% @doc Handling cast messages