This commit is contained in:
anlicheng 2023-12-25 17:26:33 +08:00
parent 4306b94bf0
commit 1977fa5278

View File

@ -15,7 +15,7 @@
%% API %% API
-export([start_link/0]). -export([start_link/0]).
-export([mock/0, mock/1]). -export([mock/4]).
%% gen_server callbacks %% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
@ -43,19 +43,15 @@
%%% API %%% API
%%%=================================================================== %%%===================================================================
mock() -> mock(LocationCode, SType, CType, Value) when is_binary(LocationCode), is_integer(SType), is_integer(CType) ->
LocationCode = <<"0001000290040150004002560">>,
mock(LocationCode).
mock(LocationCode) when is_binary(LocationCode) ->
Req = #{ Req = #{
<<"version">> => <<"1.0">>, <<"version">> => <<"1.0">>,
<<"ts">> => iot_util:current_time(), <<"ts">> => iot_util:current_time(),
<<"properties">> => #{ <<"properties">> => #{
<<"type">> => <<"ctrl">>, <<"type">> => <<"ctrl">>,
<<"stype">> => 0, <<"stype">> => SType,
<<"ctype">> => 1, <<"ctype">> => CType,
<<"value">> => 1234, <<"value">> => Value,
<<"timestamp">> => iot_util:current_time() <<"timestamp">> => iot_util:current_time()
}, },
<<"location_code">> => LocationCode <<"location_code">> => LocationCode
@ -98,9 +94,9 @@ init([]) ->
{noreply, NewState :: #state{}, timeout() | hibernate} | {noreply, NewState :: #state{}, timeout() | hibernate} |
{stop, Reason :: term(), Reply :: term(), NewState :: #state{}} | {stop, Reason :: term(), Reply :: term(), NewState :: #state{}} |
{stop, Reason :: 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])), publish_directive(Request, jiffy:encode(Request, [force_utf8])),
{reply, ok, State}. {reply, ok, State#state{flight_num = FlightNum + 1}}.
%% @private %% @private
%% @doc Handling cast messages %% @doc Handling cast messages