Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
abelino committed Aug 27, 2024
0 parents commit e3f6f4b
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
IO.puts """
\u001b[33mFormatter disabled.\u001b[0m
This repository uses a style guide.
See:
https://github.com/amclain/styleguides/blob/master/elixir/STYLEGUIDE.md
"""

Kernel.exit(:normal)

[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
bacnet-*.tar

# Temporary files, for example, from tests.
/tmp/

# Ignore the lock file for libraries.
mix.lock
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
elixir 1.17.2-otp-27
erlang 27.0.1
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.20.0 FATAL_ERROR)

# dependency manager
set(CPM_VERSION 0.40.2)
set(CPM_USE_NAMED_CACHE_DIRECTORIES false)
set(CPM_PATH "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_VERSION}.cmake")
if(NOT EXISTS ${CPM_PATH})
message(STATUS "Downloading CPM.cmake to ${CPM_PATH}")
set(CPM_GH_URL https://github.com/cpm-cmake/cpm.cmake/releases/download)
set(CPM_RELEASE_URL ${CPM_GH_URL}/v${CPM_VERSION}/CPM.cmake)
file(DOWNLOAD ${CPM_RELEASE_URL} ${CPM_PATH})
endif()
include(${CPM_PATH})

# dependencies
CPMFindPackage(
NAME bacnet
GIT_REPOSITORY [email protected]:bacnet-stack/bacnet-stack.git
GIT_TAG bacnet-stack-1.3.8)

# setup erlang
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} $ENV{ERL_EI_LIBDIR})
find_library(ERLANG_EI_LIB ei)
include_directories($ENV{ERL_EI_INCLUDE_DIR})

# sources
file(GLOB sources src/*.c)

# build
project(bacnetd)
set(CMAKE_BUILD_TYPE Release)
add_executable(bacnetd ${sources})
set_target_properties(bacnetd PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_RELEASE $ENV{MIX_APP_PATH}/priv)
target_link_libraries(bacnetd PRIVATE bacnet-stack::bacnet-stack ${ERLANG_EI_LIB})
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright 2024 Redwire Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# BACNet

## Installation

The package can be installed by adding `bacnet` to your list of dependencies
in `mix.exs`:

```elixir
def deps do
[
{:bacnet, "~> 0.1.0"}
]
end
```
5 changes: 5 additions & 0 deletions lib/bacnet.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Bacnet do
@moduledoc """
BACNet client.
"""
end
15 changes: 15 additions & 0 deletions lib/bacnet/application.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Bacnet.Application do
@moduledoc false

use Application

@impl true
def start(_type, _args) do
children = children()
opts = [strategy: :one_for_one, name: Bacnet.Supervisor]

Supervisor.start_link(children, opts)
end

defp children(), do: []
end
104 changes: 104 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
defmodule Bacnet.MixProject do
use Mix.Project

def project do
[
app: :bacnet,
version: "0.1.0",
elixir: "~> 1.16",
aliases: aliases(),
description: description(),
package: package(),
deps: deps(),
docs: docs(),
compilers: [:cmake] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
test_coverage: [tool: ExCoveralls, test_task: "espec"],
dialyzer: [
ignore_warnings: "dialyzer.ignore.exs",
list_unused_filters: true,
plt_file: {:no_warn, plt_file_path()},
],
preferred_cli_env: [
coveralls: :test,
"coveralls.detail": :test,
"coveralls.post": :test,
"coveralls.html": :test,
"coveralls.show": :test,
espec: :test,
],
]
end

def application do
[
extra_applications: [:logger],
mod: {Bacnet.Application, []}
]
end

defp aliases do
[
"coveralls.show": ["coveralls.html", &open("cover/excoveralls.html", &1)],
"docs.show": ["docs", &open("doc/index.html", &1)],
test: "coveralls",
]
end

defp deps do
[
{:dialyxir, "~> 1.4", only: :dev, runtime: false},
{:espec, "~> 1.9", only: :test},
{:elixir_cmake, "~> 0.8.0"},
{:excoveralls, "~> 0.18", only: :test},
{:ex_doc, "~> 0.34", only: :dev, runtime: false},
]
end

defp description do
"""
BACNet elixir library
"""
end

defp docs do
[
main: "readme",
extras: ["README.md", "LICENSE"]
]
end

defp package do
[
licenses: ["Apache-2.0"],
links: %{"GitHub" => "https://github.com/redwirelabs/bacnet_ex"},
maintainers: ["Abelino Romo"],
files: [
".tool-versions",
"CMakeLists.txt",
"LICENSE",
"README.md",
"lib",
"mix.exs",
"src",
],
]
end

# Open a file with the default application for its type.
defp open(file, _args) do
open_command =
System.find_executable("xdg-open") # Linux
|| System.find_executable("open") # Mac
|| raise "Could not find executable 'open' or 'xdg-open'"

System.cmd(open_command, [file])
end

# Path to the dialyzer .plt file.
defp plt_file_path do
[Mix.Project.build_path(), "plt", "dialyxir.plt"]
|> Path.join()
|> Path.expand()
end
end
5 changes: 5 additions & 0 deletions spec/bacnet_spec.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Bacnet.Spec do
use ESpec

specify do: expect true |> to(eq true)
end
9 changes: 9 additions & 0 deletions spec/spec_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ESpec.configure fn(config) ->
config.before fn(tags) ->
{:shared, tags: tags}
end

config.finally fn(_shared) ->
:ok
end
end
7 changes: 7 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "bacnet/datalink/dlenv.h"

int main(int argc, char **argv) {
dlenv_init();

return 0;
}

0 comments on commit e3f6f4b

Please sign in to comment.