Skip to content

Commit

Permalink
fix: channel log,install.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
AvantLiu committed Sep 24, 2021
1 parent fbaf628 commit 9fcc72c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions apps/dgiot_bridge/src/dgiot_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ send_log(ChannelId, ProductId, Fmt, Args) ->
send_log(ChannelId, Fmt, Args) ->
is_send_log(ChannelId, undefined, undefined,
fun() ->
Topic = <<"log/channel/", ChannelId/binary>>,
Topic = <<"log/channel/", ChannelId/binary, "/channelid">>,
Payload = io_lib:format("[~s]~p " ++ Fmt, [node(), self() | Args]),
dgiot_mqtt:publish(ChannelId, Topic, unicode:characters_to_binary(Payload))
end).
Expand Down Expand Up @@ -230,7 +230,7 @@ register_all_channel() ->
Mod = maps:get(mod, Channel_type),
CType = maps:get(cType, Channel_type),
register_channel(CType, Mod)
end, list()).
end, list()).

get_all_channel() ->
lists:foldl(fun({_, Channel_type}, Acc) ->
Expand Down Expand Up @@ -302,7 +302,7 @@ list() ->
case [Channel || {channel_type, [Channel]} <- Mod:module_info(attributes)] of
[] ->
Acc;
[Channel|_] ->
[Channel | _] ->
[{maps:get(priority, Channel, 255), Channel#{app => App, mod => Mod, vsn => Vsn}}] ++ Acc
end
end
Expand Down
13 changes: 7 additions & 6 deletions apps/dgiot_modbus/src/dgiot_modbus_tcp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ init(#tcp{state = #state{id = ChannelId}} = TCPState) ->
%% 9C A5 25 CD 00 DB
%% 11 04 02 06 92 FA FE
handle_info({tcp, Buff}, #tcp{socket = Socket, state = #state{id = ChannelId, devaddr = <<>>, head = Head, len = Len, product = ProductId, dtutype = Dtutype} = State} = TCPState) ->
dgiot_bridge:send_log(ChannelId, "DTU revice from ~p", [dgiot_utils:binary_to_hex(Buff)]),
dgiot_bridge:send_log(ChannelId, ProductId, "DTU revice from ~p", [dgiot_utils:binary_to_hex(Buff)]),
DTUIP = dgiot_utils:get_ip(Socket),
DtuAddr = dgiot_utils:binary_to_hex(Buff),
List = dgiot_utils:to_list(DtuAddr),
Expand Down Expand Up @@ -83,7 +83,7 @@ handle_info({tcp, Buff}, #tcp{socket = Socket, state = #state{id = ChannelId, de
end;

handle_info({tcp, Buff}, #tcp{state = #state{id = ChannelId, devaddr = DtuAddr, env = #{product := ProductId, pn := Pn, di := Di}, product = DtuProductId} = State} = TCPState) ->
dgiot_bridge:send_log(ChannelId, "revice from ~p", [dgiot_utils:binary_to_hex(Buff)]),
dgiot_bridge:send_log(ChannelId, ProductId, DtuAddr, "revice from ~p", [dgiot_utils:binary_to_hex(Buff)]),
<<H:8, L:8>> = dgiot_utils:hex_to_binary(modbus_rtu:is16(Di)),
<<Sh:8, Sl:8>> = dgiot_utils:hex_to_binary(modbus_rtu:is16(Pn)),
case modbus_rtu:parse_frame(Buff, [], #{
Expand All @@ -95,7 +95,7 @@ handle_info({tcp, Buff}, #tcp{state = #state{id = ChannelId, devaddr = DtuAddr,
{_, Things} ->
?LOG(info, "Things ~p", [Things]),
NewTopic = <<"thing/", DtuProductId/binary, "/", DtuAddr/binary, "/post">>,
dgiot_bridge:send_log(ChannelId, "end to_task: ~p: ~p ~n", [NewTopic, jsx:encode(Things)]),
dgiot_bridge:send_log(ChannelId, ProductId, DtuAddr, "end to_task: ~p: ~p ~n", [NewTopic, jsx:encode(Things)]),
DeviceId = dgiot_parse:get_deviceid(ProductId, DtuAddr),
dgiot_mqtt:publish(DeviceId, NewTopic, jsx:encode(Things));
Other ->
Expand All @@ -122,7 +122,7 @@ handle_info({deliver, _, Msg}, #tcp{state = #state{id = ChannelId} = State} = TC
pass
end,
{noreply, TCPState};
[<<"thing">>, _ProductId, _DevAddr] ->
[<<"thing">>, _ProductId, DevAddr] ->
[#{<<"thingdata">> := ThingData} | _] = jsx:decode(Payload, [{labels, binary}, return_maps]),
?LOG(error, "ThingData ~p", [ThingData]),
case ThingData of
Expand All @@ -140,7 +140,7 @@ handle_info({deliver, _, Msg}, #tcp{state = #state{id = ChannelId} = State} = TC
<<"di">> => Di}),
?LOG(error, "Datas ~p", [Datas]),
lists:map(fun(X) ->
dgiot_bridge:send_log(ChannelId, "to_device: ~p ", [dgiot_utils:binary_to_hex(X)]),
dgiot_bridge:send_log(ChannelId, ProductId, DevAddr, "to_device: ~p ", [dgiot_utils:binary_to_hex(X)]),
dgiot_tcp_server:send(TCPState, X),
timer:sleep(1000)
end, Datas),
Expand All @@ -159,7 +159,7 @@ handle_info({deliver, _, Msg}, #tcp{state = #state{id = ChannelId} = State} = TC
<<"di">> => Di}),
%% ?LOG(error, "Datas ~p", [Datas]),
lists:map(fun(X) ->
dgiot_bridge:send_log(ChannelId, "to_device: ~p ", [dgiot_utils:binary_to_hex(X)]),
dgiot_bridge:send_log(ChannelId, ProductId, DevAddr, "to_device: ~p ", [dgiot_utils:binary_to_hex(X)]),
dgiot_tcp_server:send(TCPState, X),
timer:sleep(1000)
end, Datas),
Expand All @@ -180,6 +180,7 @@ handle_info({deliver, _, Msg}, #tcp{state = #state{id = ChannelId} = State} = TC
#{<<"_dgiotprotocol">> := <<"modbus">>} ->
Payloads = modbus_rtu:set_params(maps:without([<<"_dgiotprotocol">>], Payload), ProductId, DevAddr),
lists:map(fun(X) ->
dgiot_bridge:send_log(ChannelId, ProductId, DevAddr, "to_device: ~p ", [dgiot_utils:binary_to_hex(X)]),
dgiot_tcp_server:send(TCPState, X)
end, Payloads);
_ ->
Expand Down
6 changes: 3 additions & 3 deletions dgiot_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ else
fi

# ============================= get input parameters =================================================
# dgiot_install.sh -v [single | cluster] -d [prod.iotn2n.com | your_domain_name] -s [dgiot_36 | dgiot_n]
# dgiot_install.sh -v [single | cluster] -d [prod.iotn2n.com | your_domain_name] -s [dgiot_44 | dgiot_n]

# set parameters by default value
verType=single # [single | cluster]
domain_name="prod.iotn2n.com" #[prod.iotn2n.com | your_domain_name]
dgiot="dgiot_36" #[dgiot_36 | dgiot_n]
dgiot="dgiot_44" #[dgiot_44 | dgiot_n]
while getopts "h:v:d:s:" arg
do
case $arg in
Expand All @@ -131,7 +131,7 @@ do
domain_name=$(echo $OPTARG)
;;
h)
echo "Usage: `basename $0` -v [single | cluster] -s [dgiot_36 | dgiot_n] -d [prod.iotn2n.com | your_domain_name]"
echo "Usage: `basename $0` -v [single | cluster] -s [dgiot_44 | dgiot_n] -d [prod.iotn2n.com | your_domain_name]"
exit 0
;;
?) #unknow option
Expand Down

0 comments on commit 9fcc72c

Please sign in to comment.