mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-11-29 18:57:41 +08:00
feat: add dgiot_image
This commit is contained in:
parent
3f927bcc06
commit
c52dd70072
47
CHANGELOG.md
47
CHANGELOG.md
@ -1,14 +1,59 @@
|
||||
# [4.3.6](https://github.com/dgiot/dgiot/compare/v4.3.5...v) (2021-10-30)
|
||||
# [](https://github.com/dgiot/dgiot/compare/v4.3.9...v) (2021-11-23)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* evidence_topo ([9e5a5f6](https://github.com/dgiot/dgiot/commit/9e5a5f6f147775ab470dca016027b733554e5a91))
|
||||
* post_evidence ([3f927bc](https://github.com/dgiot/dgiot/commit/3f927bcc06093fffe28b7749440ad95dd00c683d))
|
||||
* post_evidence ([8d109b0](https://github.com/dgiot/dgiot/commit/8d109b0bfd5cefadc8c0dff787690a29c9417980))
|
||||
|
||||
|
||||
|
||||
## [4.3.9](https://github.com/dgiot/dgiot/compare/v4.3.8...v4.3.9) (2021-11-19)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* evidence_category ([d495519](https://github.com/dgiot/dgiot/commit/d495519c4d07b0e008e97319e04830cd40afe58e))
|
||||
* refresh_session ([c56a594](https://github.com/dgiot/dgiot/commit/c56a5940e3a954a694d52c0edc0ffd2075bb1736))
|
||||
* sync_dict,view ([170e2d1](https://github.com/dgiot/dgiot/commit/170e2d1f93b43506c70d7672a1ce809f8f0ff77b))
|
||||
|
||||
|
||||
|
||||
## [4.3.8](https://github.com/dgiot/dgiot/compare/v4.3.7...v4.3.8) (2021-11-12)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* dgiot_install 68 ([63abd74](https://github.com/dgiot/dgiot/commit/63abd74fffdd592cdb56b2d09c26ff4af43ceaf1))
|
||||
* do_report ([974baad](https://github.com/dgiot/dgiot/commit/974baadcda32ecccd1fe03505347b910c649e5ea))
|
||||
|
||||
|
||||
|
||||
## [4.3.7](https://github.com/dgiot/dgiot/compare/v4.3.6...v4.3.7) (2021-11-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Modify swagger ([d4175a8](https://github.com/dgiot/dgiot/commit/d4175a8138cd778b29b8a2d8869c201eb1a9d383))
|
||||
* reporttemplate ([3cc8a70](https://github.com/dgiot/dgiot/commit/3cc8a705d2b7ab9e27195f94a5554b29502d2dd6))
|
||||
|
||||
|
||||
|
||||
## [4.3.6](https://github.com/dgiot/dgiot/compare/v4.3.5...v4.3.6) (2021-11-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* get_env ([58e2d52](https://github.com/dgiot/dgiot/commit/58e2d52212b9f859f4195023e432837d74545fc0))
|
||||
* install centos 7.9 ([16028f4](https://github.com/dgiot/dgiot/commit/16028f4c201920cf7c62a21176a9a492fc97f6aa))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add post testpaper ([b7ad572](https://github.com/dgiot/dgiot/commit/b7ad572265deafa0c479817dfb46c9967b03917e))
|
||||
* centos 7.9 ([a7e56a6](https://github.com/dgiot/dgiot/commit/a7e56a630e22db7a1e8513c96ec58f3127a6cd7c))
|
||||
* Configuration modification Label ([b71b0c2](https://github.com/dgiot/dgiot/commit/b71b0c2094f5e184efbe86f6eeecea594676a7be))
|
||||
* device_card ([6c54a07](https://github.com/dgiot/dgiot/commit/6c54a07013fb7b9b92e5ddaf498471488b1341a7))
|
||||
* go-fastdfs Api ([c4ad4e4](https://github.com/dgiot/dgiot/commit/c4ad4e4ed5be37b0b9c3abb7211746c38d26cf96))
|
||||
* go-fastdfs Api ([3160613](https://github.com/dgiot/dgiot/commit/316061335e7c96bcea36d6d55da6cbc3d76931e9))
|
||||
|
73
apps/dgiot/src/utils/dgiot_image.erl
Normal file
73
apps/dgiot/src/utils/dgiot_image.erl
Normal file
@ -0,0 +1,73 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author jonhl
|
||||
%%% @copyright (C) 2021, <COMPANY>
|
||||
%%% @doc
|
||||
%%%
|
||||
%%% @end
|
||||
%%% Created : 23. 11月 2021 12:14
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(dgiot_image).
|
||||
-author("jonhl").
|
||||
|
||||
%% API
|
||||
-export([
|
||||
image_type/1
|
||||
, image_valid/1]).
|
||||
|
||||
-include_lib("kernel/include/file.hrl").
|
||||
-define(MAX_IMG_SIZE, 4*1024*1024).
|
||||
% max image file size-
|
||||
-define(MAX_IMG_WIDTH, 2048).
|
||||
-define(MAX_IMG_HEIGHT, 2048).
|
||||
|
||||
image_type(File) when is_list(File) ->
|
||||
case file:read_file(File) of
|
||||
{ok, Data} ->
|
||||
image_type(Data);
|
||||
_ ->
|
||||
{error, openfile}
|
||||
end;
|
||||
%% Gif header, width and height%% http://www.etsimo.uniovi.es/gifanim/gif87a.txt
|
||||
image_type(<<$G, $I, $F, $8, $9, $a, Width:16/little, Height:16/little, _/binary>>) ->
|
||||
{gif, Width, Height};
|
||||
image_type(<<$G, $I, $F, $8, $7, $a, Width:16/little, Height:16/little, _/binary>>) ->
|
||||
{gif, Width, Height};
|
||||
%% Png header%% ref: http://www.w3.org/TR/PNG/#5DataRep
|
||||
image_type(<<137, 80, 78, 71, 13, 10, 26, 10, _:4/signed-integer-unit:8, 73, 72, 68, 82, Width:32/signed-big, Height:32/signed-big, _/binary>>) ->
|
||||
{png, Width, Height};
|
||||
%% Jpeg header%% ref:http://en.wikipedia.org/wiki/Jpeg#JPEG_files
|
||||
%% http://www.obrador.com/essentialjpeg/headerinfo.htm
|
||||
image_type(<<16#FF, 16#D8, JpegData/binary>>) ->
|
||||
{W, H} = parse_jpeg(JpegData), {jpeg, W, H};
|
||||
image_type(_) -> unknown.
|
||||
|
||||
parse_jpeg(Jpeg) ->
|
||||
parse_jpeg(Jpeg, {}).
|
||||
parse_jpeg(<<>>, Results) ->
|
||||
Results;
|
||||
parse_jpeg(<<16#FF, 16#C0, _:16, _:8, Height:16/signed-big, Width:16/signed-big, _/binary>>, _) ->
|
||||
parse_jpeg(<<>>, {Width, Height});
|
||||
parse_jpeg(<<_:8, Rest/binary>>, Results) ->
|
||||
parse_jpeg(Rest, Results).
|
||||
|
||||
image_valid(File) when is_list(File) ->
|
||||
{ok, FileInfo} = file:read_file_info(File),
|
||||
if FileInfo#file_info.size > ?MAX_IMG_SIZE ->
|
||||
{false, image_size_too_big};
|
||||
true ->
|
||||
case image_type(File) of
|
||||
unknown ->
|
||||
{false, image_type_invalid};
|
||||
{Type, Width, Height} when Width =< ?MAX_IMG_WIDTH andalso Height =< ?MAX_IMG_HEIGHT ->
|
||||
case Type of
|
||||
gif ->
|
||||
true;
|
||||
jpeg ->
|
||||
true;
|
||||
png ->
|
||||
true
|
||||
end;
|
||||
{_, _, _} ->
|
||||
{false, image_dimension_invalid}
|
||||
end
|
||||
end.
|
@ -883,4 +883,3 @@ url_path(Url) ->
|
||||
%% "192.168.0.183:5094/wordServer/20211112142832/1.jpg",
|
||||
{match, [{Start, _Len}]} = re:run(Url, <<"\/">>),
|
||||
to_binary(string:substr(Url, Start + 1, length(Url))).
|
||||
|
||||
|
@ -97,7 +97,8 @@ save({Type, Attrs, _}) ->
|
||||
false ->
|
||||
pass
|
||||
end;
|
||||
_ -> pass
|
||||
_ ->
|
||||
pass
|
||||
end;
|
||||
|
||||
save(_) ->
|
||||
|
@ -74,18 +74,18 @@ request(Method, Header, Path0, Body, Options) ->
|
||||
TdchannelId = maps:get(<<"tdchannel">>, Channel, <<"">>),
|
||||
TaskchannelId = maps:get(<<"taskchannel">>, Channel, <<"">>),
|
||||
Otherchannel = maps:get(<<"otherchannel">>, Channel, []),
|
||||
channel_add_prduct_relation(Otherchannel ++ [TdchannelId] ++ [TaskchannelId], ProductId);
|
||||
channel_add_product_relation(Otherchannel ++ [TdchannelId] ++ [TaskchannelId], ProductId);
|
||||
_ ->
|
||||
pass
|
||||
end;
|
||||
<<"/classes/Product/", ProductId/binary>> when Method == 'PUT' ->
|
||||
case Body of
|
||||
#{<<"channel">> := Channel} ->
|
||||
channel_delete_prduct_relation(ProductId),
|
||||
channel_delete_product_relation(ProductId),
|
||||
TdchannelId = maps:get(<<"tdchannel">>, Channel, <<"">>),
|
||||
TaskchannelId = maps:get(<<"taskchannel">>, Channel, <<"">>),
|
||||
Otherchannel = maps:get(<<"otherchannel">>, Channel, []),
|
||||
channel_add_prduct_relation(Otherchannel ++ [TdchannelId] ++ [TaskchannelId], ProductId);
|
||||
channel_add_product_relation(Otherchannel ++ [TdchannelId] ++ [TaskchannelId], ProductId);
|
||||
_ ->
|
||||
pass
|
||||
end;
|
||||
@ -476,7 +476,7 @@ log(Method, {Url, Header, _, Body}) ->
|
||||
|
||||
|
||||
|
||||
channel_add_prduct_relation(ChannelIds, ProductId) ->
|
||||
channel_add_product_relation(ChannelIds, ProductId) ->
|
||||
Map =
|
||||
#{<<"product">> =>
|
||||
#{
|
||||
@ -494,7 +494,7 @@ channel_add_prduct_relation(ChannelIds, ProductId) ->
|
||||
dgiot_parse:update_object(<<"Channel">>, ChannelId, Map)
|
||||
end, ChannelIds).
|
||||
|
||||
channel_delete_prduct_relation(ProductId) ->
|
||||
channel_delete_product_relation(ProductId) ->
|
||||
Map =
|
||||
#{<<"product">> => #{
|
||||
<<"__op">> => <<"RemoveRelation">>,
|
||||
|
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
@ -1,24 +0,0 @@
|
||||
PROJECT = shuwa_modbus
|
||||
PROJECT_DESCRIPTION = shuwa_modbus Protocol Plugin
|
||||
PROJECT_VERSION = 1.5.4
|
||||
|
||||
CUR_BRANCH := $(shell git branch | grep -e "^*" | cut -d' ' -f 2)
|
||||
BRANCH := $(if $(filter $(CUR_BRANCH), master develop), $(CUR_BRANCH), develop)
|
||||
|
||||
BUILD_DEPS = emqx cuttlefish lager
|
||||
dep_emqx = git-emqx https://github.com/emqx/emqx $(BRANCH)
|
||||
dep_cuttlefish = git-emqx https://github.com/emqx/cuttlefish v2.2.1
|
||||
dep_lager = git https://github.com/basho/lager master
|
||||
|
||||
DIALYZER_DIRS := ebin/
|
||||
DIALYZER_OPTS := --verbose --statistics -Werror_handling \
|
||||
-Wrace_conditions #-Wunmatched_returns
|
||||
|
||||
ERLC_OPTS += +'{parse_transform, lager_transform}'
|
||||
|
||||
include erlang.mk
|
||||
|
||||
app:: rebar.config
|
||||
|
||||
app.config::
|
||||
./deps/cuttlefish/cuttlefish -l info -e etc/ -c etc/shuwa_modbus.conf -d data
|
@ -1,4 +0,0 @@
|
||||
## dgiot_shouyincheng
|
||||
|
||||
dgiot_shouyincheng
|
||||
|
@ -1,16 +0,0 @@
|
||||
-define(DGIOT_SHOUYINCHENG_TCP_DTU, dgiot_shouyincheng_tcp_dtu).
|
||||
-record(state, {
|
||||
id,
|
||||
devaddr = <<>>,
|
||||
heartcount = 0,
|
||||
regtype = <<>>,
|
||||
head = "xxxxxx0eee",
|
||||
len = 0,
|
||||
app = <<>>,
|
||||
product = <<>>,
|
||||
deviceId = <<>>,
|
||||
scale = 10,
|
||||
temperature = 0,
|
||||
env = <<>>,
|
||||
dtutype = <<>>
|
||||
}).
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"definitions": {},
|
||||
"paths": {
|
||||
},
|
||||
"tags": []
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
{application, dgiot_shouyincheng,
|
||||
[{description, "DGIOT SHOUYINCHENG"},
|
||||
{vsn, "4.3.0"},
|
||||
{modules, []},
|
||||
{registered, [dgiot_shouyincheng_sup]},
|
||||
{applications, [kernel, stdlib, dgiot]},
|
||||
{mod, {dgiot_shouyincheng_app, []}}
|
||||
]}.
|
@ -1,25 +0,0 @@
|
||||
%%-*- mode: erlang -*-
|
||||
%% .app.src.script
|
||||
|
||||
RemoveLeadingV =
|
||||
fun(Tag) ->
|
||||
case re:run(Tag, "v\[0-9\]+\.\[0-9\]+\.*") of
|
||||
nomatch ->
|
||||
Tag;
|
||||
{match, _} ->
|
||||
%% if it is a version number prefixed by 'v' then remove the 'v'
|
||||
"v" ++ Vsn = Tag,
|
||||
Vsn
|
||||
end
|
||||
end,
|
||||
|
||||
case os:getenv("EMQX_DEPS_DEFAULT_VSN") of
|
||||
false -> CONFIG; % env var not defined
|
||||
[] -> CONFIG; % env var set to empty string
|
||||
Tag ->
|
||||
[begin
|
||||
AppConf0 = lists:keystore(vsn, 1, AppConf, {vsn, RemoveLeadingV(Tag)}),
|
||||
{application, App, AppConf0}
|
||||
end || Conf = {application, App, AppConf} <- CONFIG]
|
||||
end.
|
||||
|
@ -1,64 +0,0 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author stoneliu
|
||||
%%% @copyright (C) 2020, <COMPANY>
|
||||
%%% @doc
|
||||
%%% solarPower
|
||||
%%% @end
|
||||
%%% Created : 07. 五月 2021 12:00
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(dgiot_shouyincheng).
|
||||
-author("stoneliu").
|
||||
-export([parse_frame/2]).
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
|
||||
|
||||
%% Buff = dgiot_utils:hex_to_binary(<<"3D302E30303030203D302E303030303530303138200D0A">>).
|
||||
%% Buff = dgiot_utils:hex_to_binary(<<"3D302E303230302D3D302E303130303530303138200D0A">>).
|
||||
%% Buff = dgiot_utils:hex_to_binary(<<"3D302E30323030203D302E303130303530303138200D0A">>).
|
||||
%% Buff = dgiot_utils:hex_to_binary(<<"3d31312e303230203d30302e3031303530303138200D0A">>).
|
||||
%% Buff = <<"=0.0000 =0.000050018 \r\n">>.
|
||||
%% <<"=", Suttle:6/binary, " ", "=", Tare:5/binary, Y2:1/binary, F1:1/binary, K1:1/binary, K2:1/binary, B1:1/binary, B2:1/binary, C1:1/binary, CR:1/binary, LF:1/binary>> = Buff.
|
||||
parse_frame(<<"=", Suttle:6/binary, Y1:1/binary, "=", Tare:5/binary, _:9/binary>>, #state{product = ProductId}) ->
|
||||
case dgiot_product:lookup_prod(ProductId) of
|
||||
{ok, #{<<"thing">> := #{<<"properties">> := Props}}} ->
|
||||
Ack = lists:foldl(fun(X, Acc) ->
|
||||
case X of
|
||||
#{<<"identifier">> := Identifier,
|
||||
<<"dataForm">> := #{
|
||||
<<"protocol">> := <<"normal">>,
|
||||
<<"address">> := <<"0X01">>,
|
||||
<<"data">> := 6}} ->
|
||||
RelSuttle =
|
||||
case Y1 of
|
||||
<<" ">> ->
|
||||
dgiot_utils:to_float(lists:reverse(dgiot_utils:to_list(Suttle)));
|
||||
<<"-">> ->
|
||||
dgiot_utils:to_float(lists:reverse(dgiot_utils:to_list(<<Suttle/binary, "-">>)));
|
||||
_O ->
|
||||
?LOG(info, "_O ~p", [_O]),
|
||||
<<"0">>
|
||||
end,
|
||||
Acc#{Identifier => RelSuttle};
|
||||
#{<<"identifier">> := Identifier,
|
||||
<<"dataForm">> := #{
|
||||
<<"protocol">> := <<"normal">>,
|
||||
<<"address">> := <<"0X02">>,
|
||||
<<"data">> := 5}} ->
|
||||
RelTare = dgiot_utils:to_float(lists:reverse(dgiot_utils:to_list(Tare))),
|
||||
Acc#{Identifier => RelTare};
|
||||
_Other ->
|
||||
?LOG(info, "_Other ~p", [_Other]),
|
||||
Acc
|
||||
end
|
||||
end, #{}, Props),
|
||||
{params, Ack};
|
||||
_ ->
|
||||
{erroe, #{}}
|
||||
end;
|
||||
|
||||
parse_frame(_Buff, _State) ->
|
||||
{error, <<>>}.
|
||||
|
||||
|
||||
|
@ -1,31 +0,0 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(dgiot_shouyincheng_app).
|
||||
|
||||
-emqx_plugin(?MODULE).
|
||||
|
||||
-behaviour(application).
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
|
||||
%% Application callbacks
|
||||
-export([start/2, stop/1]).
|
||||
|
||||
start(_StartType, _StartArgs) ->
|
||||
dgiot_shouyincheng_sup:start_link().
|
||||
|
||||
stop(_State) ->
|
||||
ok.
|
@ -1,185 +0,0 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
-module(dgiot_shouyincheng_channel).
|
||||
-behavior(dgiot_channelx).
|
||||
-author("johnliu").
|
||||
-include_lib("dgiot_bridge/include/dgiot_bridge.hrl").
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
-define(TYPE, <<"YONGKANG">>).
|
||||
%% API
|
||||
-export([start/2]).
|
||||
|
||||
%% Channel callback
|
||||
-export([init/3, handle_init/1, handle_event/3, handle_message/2, stop/3]).
|
||||
|
||||
%% 注册通道类型
|
||||
-channel_type(#{
|
||||
cType => ?TYPE,
|
||||
type => ?PROTOCOL_CHL,
|
||||
title => #{
|
||||
zh => <<"收银秤通道"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"收银秤通道"/utf8>>
|
||||
}
|
||||
}).
|
||||
%% 注册通道参数
|
||||
-params(#{
|
||||
<<"port">> => #{
|
||||
order => 1,
|
||||
type => integer,
|
||||
required => true,
|
||||
default => 20110,
|
||||
title => #{
|
||||
zh => <<"端口"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"侦听端口"/utf8>>
|
||||
}
|
||||
},
|
||||
<<"regtype">> => #{
|
||||
order => 2,
|
||||
type => string,
|
||||
required => true,
|
||||
default => <<"上传Mac"/utf8>>,
|
||||
title => #{
|
||||
zh => <<"注册类型"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"上传Mac"/utf8>>
|
||||
}
|
||||
},
|
||||
<<"regular">> => #{
|
||||
order => 3,
|
||||
type => string,
|
||||
required => true,
|
||||
default => <<"9C-A5-25-**-**-**">>,
|
||||
title => #{
|
||||
zh => <<"登录报文帧头"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"填写正则表达式匹配login"/utf8>>
|
||||
}
|
||||
},
|
||||
<<"dtutype">> => #{
|
||||
order => 4,
|
||||
type => string,
|
||||
required => true,
|
||||
default => <<"usr">>,
|
||||
title => #{
|
||||
zh => <<"控制器厂商"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"控制器厂商"/utf8>>
|
||||
}
|
||||
},
|
||||
<<"ico">> => #{
|
||||
order => 102,
|
||||
type => string,
|
||||
required => false,
|
||||
default => <<"http://dgiot-1253666439.cos.ap-shanghai-fsi.myqcloud.com/shuwa_tech/zh/product/dgiot/channel/modbus.png">>,
|
||||
title => #{
|
||||
en => <<"channel ICO">>,
|
||||
zh => <<"通道ICO"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
en => <<"channel ICO">>,
|
||||
zh => <<"通道ICO"/utf8>>
|
||||
}
|
||||
}
|
||||
}).
|
||||
|
||||
start(ChannelId, ChannelArgs) ->
|
||||
dgiot_channelx:add(?TYPE, ChannelId, ?MODULE, ChannelArgs).
|
||||
|
||||
%% 通道初始化
|
||||
init(?TYPE, ChannelId, #{
|
||||
<<"port">> := Port,
|
||||
<<"regtype">> := Type,
|
||||
<<"regular">> := Regular,
|
||||
<<"product">> := Products,
|
||||
<<"dtutype">> := Dtutype
|
||||
} = _Args) ->
|
||||
[{ProdcutId, App} | _] = get_app(Products),
|
||||
{Header, Len} = get_header(Regular),
|
||||
State = #state{
|
||||
id = ChannelId,
|
||||
regtype = Type,
|
||||
head = Header,
|
||||
len = Len,
|
||||
app = App,
|
||||
product = ProdcutId,
|
||||
dtutype = Dtutype
|
||||
},
|
||||
|
||||
%% dgiot_data:insert({ChannelId, heartbeat}, {Heartbeat, Port}),
|
||||
{ok, State, dgiot_shouyincheng_tcp:start(Port, State)};
|
||||
|
||||
init(?TYPE, _ChannelId, _Args) ->
|
||||
{ok, #{}, #{}}.
|
||||
|
||||
handle_init(State) ->
|
||||
{ok, State}.
|
||||
|
||||
%% 通道消息处理,注意:进程池调用
|
||||
handle_event(_EventId, _Event, State) ->
|
||||
{ok, State}.
|
||||
|
||||
% SELECT clientid, payload, topic FROM "meter"
|
||||
% SELECT clientid, disconnected_at FROM "$events/client_disconnected" WHERE username = 'dgiot'
|
||||
% SELECT clientid, connected_at FROM "$events/client_connected" WHERE username = 'dgiot'
|
||||
handle_message({rule, #{clientid := DevAddr, connected_at := _ConnectedAt}, #{peername := PeerName} = _Context}, State) ->
|
||||
?LOG(error, "DevAddr ~p PeerName ~p", [DevAddr, PeerName]),
|
||||
{ok, State};
|
||||
|
||||
handle_message({rule, #{clientid := DevAddr, disconnected_at := _DisconnectedAt}, _Context}, State) ->
|
||||
?LOG(error, "DevAddr ~p ", [DevAddr]),
|
||||
{ok, State};
|
||||
|
||||
handle_message({rule, #{clientid := DevAddr, payload := Payload, topic := _Topic}, _Msg}, #state{id = ChannelId} = State) ->
|
||||
?LOG(error, "DevAddr ~p Payload ~p ChannelId ~p", [DevAddr, Payload, ChannelId]),
|
||||
{ok, State};
|
||||
|
||||
handle_message(_Message, State) ->
|
||||
{ok, State}.
|
||||
|
||||
stop(_ChannelType, _ChannelId, _State) ->
|
||||
ok.
|
||||
|
||||
get_app(Products) ->
|
||||
lists:map(fun({ProdcutId, #{<<"ACL">> := Acl}}) ->
|
||||
Predicate = fun(E) ->
|
||||
case E of
|
||||
<<"role:", _/binary>> -> true;
|
||||
_ -> false
|
||||
end
|
||||
end,
|
||||
[<<"role:", App/binary>> | _] = lists:filter(Predicate, maps:keys(Acl)),
|
||||
{ProdcutId, App}
|
||||
end, Products).
|
||||
|
||||
|
||||
|
||||
get_header(Regular) ->
|
||||
lists:foldl(fun(X, {Header, Len}) ->
|
||||
case X of
|
||||
"**" -> {Header, Len + length(X)};
|
||||
"*" -> {Header, Len + length(X)};
|
||||
_ -> {Header ++ X, Len + length(X)}
|
||||
end
|
||||
end, {[], 0},
|
||||
re:split(dgiot_utils:to_list(Regular), "-", [{return, list}])).
|
@ -1,34 +0,0 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(dgiot_shouyincheng_sup).
|
||||
|
||||
-behaviour(supervisor).
|
||||
|
||||
%% API
|
||||
-export([start_link/0]).
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
|
||||
%% Supervisor callbacks
|
||||
-export([init/1]).
|
||||
|
||||
start_link() ->
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
init([]) ->
|
||||
{ok, {{one_for_one, 5, 10}, []}}.
|
||||
|
||||
|
@ -1,167 +0,0 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
-module(dgiot_shouyincheng_tcp).
|
||||
-author("stoneliu").
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
-include_lib("dgiot/include/dgiot_socket.hrl").
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
|
||||
-define(MAX_BUFF_SIZE, 1024).
|
||||
|
||||
-export([
|
||||
get_deviceid/2,
|
||||
start/2
|
||||
]).
|
||||
|
||||
%% TCP callback
|
||||
-export([init/1, handle_info/2, handle_cast/2, handle_call/3, terminate/2, code_change/3]).
|
||||
|
||||
start(Port, State) ->
|
||||
dgiot_tcp_server:child_spec(?MODULE, dgiot_utils:to_int(Port), State).
|
||||
|
||||
%% =======================
|
||||
%% {ok, State} | {stop, Reason}
|
||||
%%init(TCPState) ->
|
||||
%% erlang:send_after(5 * 1000, self(), login),.
|
||||
%% {ok, TCPState}.
|
||||
|
||||
init(#tcp{state = #state{id = ChannelId}} = TCPState) ->
|
||||
?LOG(info, "ChannelId ~p", [ChannelId]),
|
||||
case dgiot_bridge:get_products(ChannelId) of
|
||||
{ok, _TYPE, _ProductIds} ->
|
||||
{ok, TCPState};
|
||||
{error, not_find} ->
|
||||
{stop, not_find_channel}
|
||||
end.
|
||||
|
||||
%% 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)]),
|
||||
DTUIP = dgiot_utils:get_ip(Socket),
|
||||
DtuAddr = dgiot_utils:binary_to_hex(Buff),
|
||||
List = dgiot_utils:to_list(DtuAddr),
|
||||
List1 = dgiot_utils:to_list(Buff),
|
||||
#{<<"objectId">> := DeviceId} =
|
||||
dgiot_parse:get_objectid(<<"Device">>, #{<<"product">> => ProductId, <<"devaddr">> => DtuAddr}),
|
||||
case re:run(DtuAddr, Head, [{capture, first, list}]) of
|
||||
{match, [Head]} when length(List) == Len ->
|
||||
{DevId, Devaddr} =
|
||||
case create_device(DeviceId, ProductId, DtuAddr, DTUIP, Dtutype) of
|
||||
{<<>>, <<>>} ->
|
||||
{<<>>, <<>>};
|
||||
{DevId1, Devaddr1} ->
|
||||
{DevId1, Devaddr1}
|
||||
end,
|
||||
{noreply, TCPState#tcp{buff = <<>>, state = State#state{devaddr = Devaddr, deviceId = DevId}}};
|
||||
_Error ->
|
||||
case re:run(Buff, Head, [{capture, first, list}]) of
|
||||
{match, [Head]} when length(List1) == Len ->
|
||||
create_device(DeviceId, ProductId, Buff, DTUIP, Dtutype),
|
||||
{noreply, TCPState#tcp{buff = <<>>, state = State#state{devaddr = Buff}}};
|
||||
Error1 ->
|
||||
?LOG(info, "Error1 ~p Buff ~p ", [Error1, dgiot_utils:to_list(Buff)]),
|
||||
{noreply, TCPState#tcp{buff = <<>>}}
|
||||
end
|
||||
end;
|
||||
|
||||
%% 3D302E30303030203D302E303030303530303138200D0A
|
||||
handle_info({tcp, Buff}, #tcp{state = #state{id = ChannelId, devaddr = DevAddr, product = ProductId} = State} = TCPState) ->
|
||||
dgiot_bridge:send_log(ChannelId, ProductId, DevAddr, "revice from ~p", [Buff]),
|
||||
case dgiot_shouyincheng:parse_frame(Buff, State) of
|
||||
{params, Data} ->
|
||||
dgiot_tdengine_adapter:save(ProductId, DevAddr, Data);
|
||||
_ ->
|
||||
pass
|
||||
end,
|
||||
{noreply, TCPState};
|
||||
|
||||
handle_info({deliver, _, _Msg}, #tcp{state = #state{id = _ChannelId} = _State} = TCPState) ->
|
||||
|
||||
{noreply, TCPState};
|
||||
%% {stop, TCPState} | {stop, Reason} | {ok, TCPState} | ok | stop
|
||||
handle_info(_Info, TCPState) ->
|
||||
?LOG(info, "TCPState ~p", [TCPState]),
|
||||
{noreply, TCPState}.
|
||||
|
||||
handle_call(_Msg, _From, TCPState) ->
|
||||
{reply, ok, TCPState}.
|
||||
|
||||
handle_cast(_Msg, TCPState) ->
|
||||
{noreply, TCPState}.
|
||||
|
||||
terminate(_Reason, _TCPState) ->
|
||||
ok.
|
||||
|
||||
code_change(_OldVsn, TCPState, _Extra) ->
|
||||
{ok, TCPState}.
|
||||
|
||||
get_deviceid(ProdcutId, DevAddr) ->
|
||||
#{<<"objectId">> := DeviceId} =
|
||||
dgiot_parse:get_objectid(<<"Device">>, #{<<"product">> => ProdcutId, <<"devaddr">> => DevAddr}),
|
||||
DeviceId.
|
||||
|
||||
create_device(DeviceId, ProductId, DTUMAC, DTUIP, Dtutype) ->
|
||||
case dgiot_parse:get_object(<<"Product">>, ProductId) of
|
||||
{ok, #{<<"ACL">> := Acl, <<"devType">> := DevType, <<"name">> := ProductName}} ->
|
||||
case dgiot_parse:get_object(<<"Device">>, DeviceId) of
|
||||
{ok, #{<<"devaddr">> := _GWAddr}} ->
|
||||
dgiot_parse:update_object(<<"Device">>, DeviceId, #{<<"ip">> => DTUIP, <<"status">> => <<"ONLINE">>});
|
||||
_ ->
|
||||
dgiot_device:create_device(#{
|
||||
<<"devaddr">> => DTUMAC,
|
||||
<<"name">> => <<ProductName/binary, DTUMAC/binary>>,
|
||||
<<"ip">> => DTUIP,
|
||||
<<"isEnable">> => true,
|
||||
<<"product">> => ProductId,
|
||||
<<"ACL">> => Acl,
|
||||
<<"status">> => <<"ONLINE">>,
|
||||
<<"location">> => #{<<"__type">> => <<"GeoPoint">>, <<"longitude">> => 120.161324, <<"latitude">> => 30.262441},
|
||||
<<"brand">> => Dtutype,
|
||||
<<"devModel">> => DevType
|
||||
})
|
||||
end,
|
||||
Productname =
|
||||
case dgiot_parse:get_object(<<"Product">>, ProductId) of
|
||||
{ok, #{<<"name">> := Productname1}} ->
|
||||
Productname1;
|
||||
_ ->
|
||||
<<"">>
|
||||
end,
|
||||
?MLOG(info, #{<<"clientid">> => DeviceId, <<"devaddr">> => DTUMAC, <<"productid">> => ProductId, <<"productname">> => Productname, <<"devicename">> => <<Dtutype/binary, DTUMAC/binary>>, <<"status">> => <<"上线"/utf8>>}, ['device_statuslog']),
|
||||
{DeviceId, DTUMAC};
|
||||
Error2 ->
|
||||
?LOG(info, "Error2 ~p ", [Error2]),
|
||||
{<<>>, <<>>}
|
||||
end.
|
||||
|
||||
%%create_instruct(ACL, DtuProductId, DtuDevId) ->
|
||||
%% case dgiot_product:lookup_prod(DtuProductId) of
|
||||
%% {ok, #{<<"thing">> := #{<<"properties">> := Properties}}} ->
|
||||
%% lists:map(fun(Y) ->
|
||||
%% case Y of
|
||||
%% #{<<"dataForm">> := #{<<"slaveid">> := 256}} -> %%不做指令
|
||||
%% pass;
|
||||
%% #{<<"dataForm">> := #{<<"slaveid">> := SlaveId}} ->
|
||||
%% Pn = dgiot_utils:to_binary(SlaveId),
|
||||
%%%% ?LOG(info,"DtuProductId ~p DtuDevId ~p Pn ~p ACL ~p", [DtuProductId, DtuDevId, Pn, ACL]),
|
||||
%%%% ?LOG(info,"Y ~p", [Y]),
|
||||
%% dgiot_instruct:create(DtuProductId, DtuDevId, Pn, ACL, <<"all">>, #{<<"properties">> => [Y]});
|
||||
%% _ -> pass
|
||||
%% end
|
||||
%% end, Properties);
|
||||
%% _ -> pass
|
||||
%% end.
|
@ -1,85 +0,0 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
-module(dgiot_shouyincheng_handler).
|
||||
-author("stoneliu").
|
||||
-behavior(dgiot_rest).
|
||||
-dgiot_rest(all).
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
|
||||
%% API
|
||||
-export([swagger_shouyincheng_tcp/0]).
|
||||
-export([handle/4]).
|
||||
|
||||
%% API描述
|
||||
%% 支持二种方式导入
|
||||
%% 示例:
|
||||
%% 1. Metadata为map表示的JSON,
|
||||
%% dgiot_http_server:bind(<<"/pump">>, ?MODULE, [], Metadata)
|
||||
%% 2. 从模块的priv/swagger/下导入
|
||||
%% dgiot_http_server:bind(<<"/swagger_shouyincheng.json">>, ?MODULE, [], priv)
|
||||
swagger_shouyincheng_tcp() ->
|
||||
[
|
||||
dgiot_http_server:bind(<<"/swagger_shouyincheng.json">>, ?MODULE, [], priv)
|
||||
].
|
||||
|
||||
|
||||
%%%===================================================================
|
||||
%%% 请求处理
|
||||
%%% 如果登录, Context 内有 <<"user">>, version
|
||||
%%%===================================================================
|
||||
|
||||
-spec handle(OperationID :: atom(), Args :: map(), Context :: map(), Req :: dgiot_req:req()) ->
|
||||
{Status :: dgiot_req:http_status(), Body :: map()} |
|
||||
{Status :: dgiot_req:http_status(), Headers :: map(), Body :: map()} |
|
||||
{Status :: dgiot_req:http_status(), Headers :: map(), Body :: map(), Req :: dgiot_req:req()}.
|
||||
|
||||
handle(OperationID, Args, Context, Req) ->
|
||||
Headers = #{},
|
||||
case catch do_request(OperationID, Args, Context, Req) of
|
||||
{ErrType, Reason} when ErrType == 'EXIT'; ErrType == error ->
|
||||
?LOG(info, "do request: ~p, ~p, ~p~n", [OperationID, Args, Reason]),
|
||||
Err = case is_binary(Reason) of
|
||||
true -> Reason;
|
||||
false ->
|
||||
dgiot_ctl:format("~p", [Reason])
|
||||
end,
|
||||
{500, Headers, #{<<"error">> => Err}};
|
||||
ok ->
|
||||
%% ?LOG(debug,"do request: ~p, ~p ->ok ~n", [OperationID, Args]),
|
||||
{200, Headers, #{}, Req};
|
||||
{ok, Res} ->
|
||||
%% ?LOG(info,"do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
|
||||
{200, Headers, Res, Req};
|
||||
{Status, Res} ->
|
||||
%% ?LOG(info,"do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
|
||||
{Status, Headers, Res, Req};
|
||||
{Status, NewHeaders, Res} ->
|
||||
%% ?LOG(info,"do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
|
||||
{Status, maps:merge(Headers, NewHeaders), Res, Req}
|
||||
end.
|
||||
|
||||
|
||||
%%%===================================================================
|
||||
%%% 内部函数 Version:API版本
|
||||
%%%===================================================================
|
||||
|
||||
|
||||
%% PumpTemplet 概要: 新增报告模板 描述:新增报告模板
|
||||
%% OperationId:post_pump_templet
|
||||
%% 请求:get /iotapi/pump/templet
|
||||
%% 服务器不支持的API接口
|
||||
do_request(_OperationId, _Args, _Context, _Req) ->
|
||||
{error, <<"Not Allowed.">>}.
|
@ -24,5 +24,4 @@
|
||||
{dgiot_niisten, {{enable_plugin_dgiot_niisten}}}.
|
||||
{dgiot_modbus, {{enable_plugin_dgiot_modbus}}}.
|
||||
{dgiot_group, {{enable_plugin_dgiot_group}}}.
|
||||
{dgiot_shouyincheng, {{enable_plugin_dgiot_shouyincheng}}}.
|
||||
{dgiot_gb26875, {{enable_plugin_dgiot_gb26875}}}.
|
||||
|
@ -77,6 +77,8 @@
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/lib/cowboy" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/lib/cowlib" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/lib/cuttlefish" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/lib/cuttlefish/_build/default/lib/getopt" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/lib/cuttlefish/_build/escript/lib/getopt" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/lib/ecpool" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/lib/ehttpc" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/lib/ejdbc" vcs="Git" />
|
||||
@ -115,6 +117,7 @@
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/plugins/grpc_plugin" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/plugins/pc" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/_build/emqx/plugins/relup_helper" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/apps/dgiot_amis_server" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/apps/dgiot_esports" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/apps/dgiot_jieshun" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/apps/dgiot_mingcheng" vcs="Git" />
|
||||
|
@ -219,7 +219,6 @@ overlay_vars_rel(RelType) ->
|
||||
, {enable_plugin_dgiot_modbus, true}
|
||||
, {enable_plugin_dgiot_group, true}
|
||||
, {enable_plugin_dgiot_ffmpeg, true}
|
||||
, {enable_plugin_dgiot_shouyincheng, true}
|
||||
, {enable_plugin_dgiot_gb26875, true}
|
||||
, {vm_args_file, VmArgs}
|
||||
].
|
||||
@ -350,8 +349,7 @@ relx_plugin_apps_per_rel(cloud) ->
|
||||
, dgiot_modbus
|
||||
, dgiot_group
|
||||
, dgiot_ffmpeg
|
||||
, dgiot_shouyincheng
|
||||
, dgiot_gb26875
|
||||
, dgiot_gb26875
|
||||
];
|
||||
relx_plugin_apps_per_rel(edge) ->
|
||||
[].
|
||||
|
Loading…
Reference in New Issue
Block a user