iot/apps/iot/include/iot.hrl
2023-08-09 11:56:37 +08:00

123 lines
3.5 KiB
Erlang
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

%%%-------------------------------------------------------------------
%%% @author licheng5
%%% @copyright (C) 2023, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 14. 2月 2023 19:48
%%%-------------------------------------------------------------------
-author("licheng5").
%% 主机状态定义
-define(HOST_STATUS_INACTIVE, -1). %% 未接入
-define(HOST_STATUS_OFFLINE, 0). %% 离线
-define(HOST_STATUS_ONLINE, 1). %% 在线
%% 下发的任务状态
-define(TASK_STATUS_INIT, -1). %% 未接入
-define(TASK_STATUS_FAILED, 0). %% 离线
-define(TASK_STATUS_OK, 1). %% 在线
%% 主机端上报数据类型标识
%% 建立到websocket的register关系
-define(METHOD_REGISTER, 16#00).
-define(METHOD_CREATE_SESSION, 16#01).
-define(METHOD_DATA, 16#02).
-define(METHOD_PING, 16#03).
-define(METHOD_INFORM, 16#04).
-define(METHOD_FEEDBACK_STEP, 16#05).
-define(METHOD_FEEDBACK_RESULT, 16#06).
%% 消息体类型
-define(PACKET_REQUEST, 16#01).
-define(PACKET_RESPONSE, 16#02).
-define(PACKET_PUBLISH, 16#03).
-define(PACKET_PUBLISH_RESPONSE, 16#04).
%% 缓存数据库表
-record(kv, {
key :: binary(),
val :: binary() | list() | map() | sets:set(),
expire_at = 0 :: integer(),
type :: atom()
}).
-record(http_endpoint, {
url = <<>> :: binary(),
pool_size = 10 :: integer()
}).
-record(ws_endpoint, {
url = <<>> :: binary()
}).
-record(mqtt_endpoint, {
host = <<>> :: binary(),
port = 0 :: integer(),
username = <<>> :: binary(),
password = <<>> :: binary(),
topic = <<>> :: binary(),
qos = 0 :: integer()
}).
-record(kafka_endpoint, {
username = <<>> :: binary(),
password = <<>> :: binary(),
bootstrap_servers = [] :: [binary()],
topic = <<>> :: binary()
}).
-record(mysql_endpoint, {
host = <<>> :: binary(),
port = 0 :: integer(),
username = <<>> :: binary(),
password = <<>> :: binary(),
database = <<>> :: binary(),
table_name = <<>> :: binary(),
pool_size = 10 :: integer()
}).
%% 对端配置
-record(endpoint, {
%% 不同的对端名字要唯一
name = <<>> :: binary(),
%% 标题描述
title = <<>> :: binary(),
%% 匹配规则, 固定了满足点位信息的前缀匹配的数据的转发规则
matcher = <<>> :: binary(),
mapper = <<>> :: binary(),
%% 数据转换规则,基于
%% fun(LocationCode :: binary(), Fields :: [{<<"key">> => <<>>, <<"value">> => <<>>, <<"unit">> => <<>>}])
%% fun(LocationCode :: binary(), Fields :: [{<<"key">> => <<>>, <<"value">> => <<>>, <<"unit">> => <<>>}], Timestamp :: integer())
mapper_fun = fun(_, Fields) -> Fields end :: fun(),
%% 配置项, 格式: #{<<"protocol">> => <<"http|https|ws|kafka|mqtt">>, <<"args">> => #{}}
config = #http_endpoint{} :: #http_endpoint{} | #ws_endpoint{} | #mqtt_endpoint{} | #kafka_endpoint{} | #mysql_endpoint{},
%% 更新时间
updated_at = 0 :: integer(),
%% 创建时间
created_at = 0 :: integer()
}).
%% id生成器
-record(id_generator, {
tab :: atom(),
increment_id = 0 :: integer()
}).
%% 北向数据
-record(north_data, {
id = 0 :: integer(),
location_code :: binary(),
%% 数据库类型的endpoint 可以返回list: [{K, V}, {K1, V1}]
fields :: [{K :: binary(), V :: any()}],
timestamp = 0 :: integer()
}).
%% 发送数据
-record(post_data, {
id = 0 :: integer(),
location_code :: binary(),
%% 数据库类型的endpoint 可以返回list: [{K, V}, {K1, V1}]
body :: binary() | list()
}).