Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lsxredrain committed Jul 20, 2021
2 parents b487fa5 + d1ca020 commit adb46f3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions apps/dgiot_modbus/src/modbus/modbus_rtu.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ encode_data(Data, Address, SlaveId, ProductId) ->
is16(<<"0X", Data/binary>>) when size(Data) == 4 ->
Data;

is16(<<"0X", Data/binary>>) when size(Data) > 4 ->
Data;

is16(<<"0X", Data/binary>>) ->
<<"00", Data/binary>>;

Expand Down
6 changes: 3 additions & 3 deletions apps/dgiot_task/src/dgiot_task.erl
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,16 @@ string2value(Str, Type, Specs) ->
save_pnque(DtuProductId, DtuAddr, ProductId, DevAddr) ->
DtuId = dgiot_parse:get_deviceid(DtuProductId, DtuAddr),
Topic = <<"thing/", ProductId/binary, "/", DevAddr/binary>>,
Args = dgiot_data:get({?TASK_ARGS, DtuProductId}),
supervisor:start_child(dgiot_task, [Args#{<<"dtuid">> => DtuId}]),
dgiot_mqtt:subscribe(Topic),
case dgiot_data:get(?DGIOT_PNQUE, DtuId) of
not_find ->
dgiot_data:insert(?DGIOT_PNQUE, DtuId, [{ProductId, DevAddr}]);
Pn_que ->
New_Pn_que = dgiot_utils:unique_2(Pn_que ++ [{ProductId, DevAddr}]),
dgiot_data:insert(?DGIOT_PNQUE, DtuId, New_Pn_que)
end.
end,
Args = dgiot_data:get({?TASK_ARGS, DtuProductId}),
supervisor:start_child(dgiot_task, [Args#{<<"dtuid">> => DtuId}]).

get_pnque(DtuId) ->
case dgiot_data:get(?DGIOT_PNQUE, DtuId) of
Expand Down
3 changes: 2 additions & 1 deletion apps/dgiot_task/src/dgiot_task_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ save_td(#task{app = _App, tid = Channel, product = ProductId, devaddr = DevAddr,
false ->
Payload = jsx:encode(#{<<"thingdata">> => Data, <<"appdata">> => AppData}),
Topic = <<"topo/", ProductId/binary, "/", DevAddr/binary, "/post">>,
dgiot_mqtt:publish(ProductId, Topic, Payload),
dgiot_mqtt:publish(DevAddr, Topic, Payload),
dgiot_mqtt:publish(DevAddr, <<"报警">>, Data),
dgiot_tdengine_adapter:save(ProductId, DevAddr, Data),
dgiot_bridge:send_log(Channel, "from_dev=> ~ts: ~ts ", [unicode:characters_to_list(Topic), unicode:characters_to_list(jsx:encode(Data))]);
true ->
Expand Down
6 changes: 4 additions & 2 deletions apps/dgiot_tdengine/src/dgiot_tdengine_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ check_fields(Data, #{<<"properties">> := Props}) -> check_fields(Data, Props);
check_fields(Data, Props) -> check_fields(Data, Props, #{}).
check_fields(Data, Props, Acc) when Data == []; Props == [] -> Acc;
check_fields(Data, [#{<<"identifier">> := Field, <<"dataType">> := #{<<"type">> := Type} = DataType} = Prop | Other], Acc) ->
LowerField = list_to_binary(string:to_lower(binary_to_list(Field))),
case check_field(Data, Prop) of
undefined ->
check_fields(Data, Other, Acc);
Expand All @@ -470,12 +471,13 @@ check_fields(Data, [#{<<"identifier">> := Field, <<"dataType">> := #{<<"type">>
undefined ->
Acc1;
Value1 ->
Acc1#{?Struct(Field, Field1) => Value1}
LowerField1 = list_to_binary(string:to_lower(binary_to_list(Field1))),
Acc1#{?Struct(LowerField, LowerField1) => Value1}
end
end, Acc, SubFields),
check_fields(Data, Other, Acc2);
_ ->
check_fields(Data, Other, Acc#{Field => Value})
check_fields(Data, Other, Acc#{LowerField => Value})
end
end.

Expand Down

0 comments on commit adb46f3

Please sign in to comment.