Skip to content

Commit c2adeef

Browse files
committed
Initial commit
0 parents  commit c2adeef

File tree

18 files changed

+889
-0
lines changed

18 files changed

+889
-0
lines changed

.formatter.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# HanAms
2+
3+
**TODO: Add description**
4+
5+
## Targets
6+
7+
Nerves applications produce images for hardware targets based on the
8+
`MIX_TARGET` environment variable. If `MIX_TARGET` is unset, `mix` builds an
9+
image that runs on the host (e.g., your laptop). This is useful for executing
10+
logic tests, running utilities, and debugging. Other targets are represented by
11+
a short name like `rpi3` that maps to a Nerves system image for that platform.
12+
All of this logic is in the generated `mix.exs` and may be customized. For more
13+
information about targets see:
14+
15+
https://hexdocs.pm/nerves/targets.html#content
16+
17+
## Getting Started
18+
19+
To start your Nerves app:
20+
* `export MIX_TARGET=my_target` or prefix every command with
21+
`MIX_TARGET=my_target`. For example, `MIX_TARGET=rpi3`
22+
* Install dependencies with `mix deps.get`
23+
* Create firmware with `mix firmware`
24+
* Burn to an SD card with `mix firmware.burn`
25+
26+
## Learn more
27+
28+
* Official docs: https://hexdocs.pm/nerves/getting-started.html
29+
* Official website: https://nerves-project.org/
30+
* Forum: https://elixirforum.com/c/nerves-forum
31+
* Discussion Slack elixir-lang #nerves ([Invite](https://elixir-slackin.herokuapp.com/))
32+
* Source: https://github.com/nerves-project/nerves

config/config.exs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Mix.Config module.
3+
#
4+
# This configuration file is loaded before any dependency and
5+
# is restricted to this project.
6+
use Mix.Config
7+
8+
# Customize non-Elixir parts of the firmware. See
9+
# https://hexdocs.pm/nerves/advanced-configuration.html for details.
10+
11+
config :nerves, :firmware, rootfs_overlay: "rootfs_overlay"
12+
13+
# Use shoehorn to start the main application. See the shoehorn
14+
# docs for separating out critical OTP applications such as those
15+
# involved with firmware updates.
16+
17+
config :shoehorn,
18+
init: [:nerves_runtime, :nerves_init_gadget],
19+
app: Mix.Project.config()[:app]
20+
21+
# Use Ringlogger as the logger backend and remove :console.
22+
# See https://hexdocs.pm/ring_logger/readme.html for more information on
23+
# configuring ring_logger.
24+
25+
config :logger, backends: [RingLogger]
26+
27+
# Authorize the device to receive firmware using your public key.
28+
# See https://hexdocs.pm/nerves_firmware_ssh/readme.html for more information
29+
# on configuring nerves_firmware_ssh.
30+
31+
keys =
32+
[
33+
Path.join([System.user_home!(), ".ssh", "id_rsa.pub"]),
34+
Path.join([System.user_home!(), ".ssh", "id_ecdsa.pub"]),
35+
Path.join([System.user_home!(), ".ssh", "id_ed25519.pub"])
36+
]
37+
|> Enum.filter(&File.exists?/1)
38+
39+
if keys == [],
40+
do:
41+
Mix.raise("""
42+
No SSH public keys found in ~/.ssh. An ssh authorized key is needed to
43+
log into the Nerves device and update firmware on it using ssh.
44+
See your project's config.exs for this error message.
45+
""")
46+
47+
config :nerves_firmware_ssh,
48+
authorized_keys: Enum.map(keys, &File.read!/1)
49+
50+
# Configure nerves_init_gadget.
51+
# See https://hexdocs.pm/nerves_init_gadget/readme.html for more information.
52+
53+
# Setting the node_name will enable Erlang Distribution.
54+
# Only enable this for prod if you understand the risks.
55+
node_name = if Mix.env() != :prod, do: "han_ams"
56+
57+
config :nerves_init_gadget,
58+
ifname: "usb0",
59+
address_method: :dhcpd,
60+
mdns_domain: "nerves.local",
61+
node_name: node_name,
62+
node_host: :mdns_domain
63+
64+
# Import target specific config. This must remain at the bottom
65+
# of this file so it overrides the configuration defined above.
66+
# Uncomment to use target specific configurations
67+
68+
# import_config "#{Mix.target()}.exs"

lib/han_ams.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule HanAms do
2+
@moduledoc """
3+
Documentation for HanAms.
4+
"""
5+
6+
@doc """
7+
Hello world.
8+
9+
## Examples
10+
11+
iex> HanAms.hello
12+
:world
13+
14+
"""
15+
def hello do
16+
:world
17+
end
18+
end

lib/han_ams/List13.ex

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
defmodule HanAms.List13 do
2+
defstruct [:obis_list_version, :gs1, :meter_model]
3+
end
4+
5+
# type BaseItem struct {
6+
# MessageType messageTypes `json:"Message_Type"`
7+
# MeterTime time.Time `json:"Meter_Time"`
8+
# HostTime time.Time `json:"Host_Time"`
9+
# }
10+
11+
# type MessageType1 struct { // Also known as aka Items1
12+
# BaseItem
13+
# ActPowPos int `json:"Act_Pow_P_Q1_Q4"` /* OBIS Code 1.0.1.7.0.255 - Active Power + (Q1+Q4) */
14+
# }
15+
16+
# type TwoFasesMessageType2 struct { // Also known as aka Items9
17+
# BaseItem
18+
# ObisListVersion string `json:"OBIS_List_Version"` /* OBIS Code 1.1.0.2.129.255 - OBIS List Version Identifier */
19+
# Gs1 string `json:"GS1"` /* OBIS Code 0.0.96.1.0.255 - Meter-ID(GIAI GS1 - 16 digits */
20+
# MeterModel string `json:"Meter_Model"` /* OBIS Code 0.0.96.1.7 - Meter Type */
21+
# ActPowPos int `json:"Act_Pow_P_Q1_Q4"` /* Active Power + */
22+
# ActPowNeg int `json:"Act_Pow_M_Q2_Q3"` /* Actve Power - */
23+
# ReactPowPos int `json:"React_Pow_P"` /* Reactive Power + */
24+
# ReactPowNeg int `json:"React_Pow_M"` /* Reactive Power - */
25+
# CurrL1 int `json:"Curr_L1"` /* Current Phase L1 */
26+
# VoltL1 int `json:"Volt_L1"` /* Voltage L1 */
27+
# }
28+
29+
# type ThreeFasesMessageType2 struct { // Also known as Items13
30+
# BaseItem
31+
# ObisListVersion string `json:"OBIS_List_Version"` /* OBIS Code 1.1.0.2.129.255 - OBIS List Version Identifier */
32+
# Gs1 string `json:"GS1"` /* OBIS Code 0.0.96.1.0.255 - Meter-ID(GIAI GS1 - 16 digits */
33+
# MeterModel string `json:"Meter_Model"` /* OBIS Code 0.0.96.1.7.255 - Meter Type */
34+
# ActPowPos int `json:"Act_Pow_P_Q1_Q4"` /* Active Power + */
35+
# ActPowNeg int `json:"Act_Pow_M_Q2_Q3"` /* Active Power - */
36+
# ReactPowPos int `json:"React_Pow_P_Q1_Q2"` /* Reactive Power + */
37+
# ReactPowNeg int `json:"React_Pow_M_Q3_Q4"` /* Reactive Power - */
38+
# CurrL1 int `json:"Curr_L1"` /* Current Phase L1 mA */
39+
# CurrL2 int `json:"Curr_L2"` /* Current Phase L2 mA */
40+
# CurrL3 int `json:"Curr_L3"` /* Current Phase L3 mA */
41+
# VoltL1 int `json:"Volt_L1"` /* Voltage L1 */
42+
# VoltL2 int `json:"Volt_L2"` /* Voltage L2 */
43+
# VoltL3 int `json:"Volt_L3"` /* Voltage L3 */
44+
# }
45+
46+
# type TwoFasesMessageType3 struct { // Also known as Items14
47+
# BaseItem
48+
# ObisListVersion string `json:"OBIS_List_Version"` /* OBIS Code 1.1.0.2.129.255 - OBIS List Version Identifier */
49+
# Gs1 string `json:"GS1"` /* OBIS Code 0.0.96.1.0.255 - Meter-ID(GIAI GS1 - 16 digits */
50+
# MeterModel string `json:"Meter_Model"` /* OBIS Code 0.0.96.1.7.255 - Meter Type */
51+
# ActPowPos int `json:"Act_Pow_P_Q1_Q4"` /* Active Power + */
52+
# ActPowNeg int `json:"Act_Pow_M_Q2_Q3"` /* Active Power - */
53+
# ReactPowPos int `json:"React_Pow_P_Q1_Q2"` /* Reactive Power + */
54+
# ReactPowNeg int `json:"React_Pow_M_Q3_Q4"` /* Reactive Power - */
55+
# CurrL1 int `json:"Curr_L1"`
56+
# VoltL1 int `json:"Volt_L1"`
57+
# DateTime time.Time `json:"Date_Time2"` /* OBIS Code: 0.0.1.0.0.255 - Clock and Date in Meter */
58+
# ActEnergyPos int `json:"Act_Energy_P"`
59+
# ActEnergyNeg int `json:"Act_Energy_M"`
60+
# ReactEnergyPos int `json:"React_Energy_P"`
61+
# ReactEnergyNeg int `json:"React_Energy_M"`
62+
# }

lib/han_ams/Parser.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
defmodule HanAms.Parser do
2+
def parse(bytes) do
3+
<<0x7E, header::size(18), rest>> = bytes
4+
IO.inspect(rest)
5+
end
6+
end

lib/han_ams/application.ex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
defmodule HanAms.Application do
2+
# See https://hexdocs.pm/elixir/Application.html
3+
# for more information on OTP Applications
4+
@moduledoc false
5+
6+
@target Mix.target()
7+
8+
use Application
9+
10+
def start(_type, _args) do
11+
# See https://hexdocs.pm/elixir/Supervisor.html
12+
# for other strategies and supported options
13+
opts = [strategy: :one_for_one, name: HanAms.Supervisor]
14+
Supervisor.start_link(children(@target), opts)
15+
end
16+
17+
# List all child processes to be supervised
18+
def children(:host) do
19+
[
20+
# Starts a worker by calling: HanAms.Worker.start_link(arg)
21+
# {HanAms.Worker, arg},
22+
]
23+
end
24+
25+
def children(_target) do
26+
[
27+
# Starts a worker by calling: HanAms.Worker.start_link(arg)
28+
# {HanAms.Worker, arg},
29+
]
30+
end
31+
end

mix.exs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
defmodule HanAms.MixProject do
2+
use Mix.Project
3+
4+
@all_targets [:rpi, :rpi0, :rpi2, :rpi3, :rpi3a, :bbb, :x86_64]
5+
6+
def project do
7+
[
8+
app: :han_ams,
9+
version: "0.1.0",
10+
elixir: "~> 1.8",
11+
archives: [nerves_bootstrap: "~> 1.5"],
12+
start_permanent: Mix.env() == :prod,
13+
build_embedded: true,
14+
aliases: [loadconfig: [&bootstrap/1]],
15+
deps: deps()
16+
]
17+
end
18+
19+
# Starting nerves_bootstrap adds the required aliases to Mix.Project.config()
20+
# Aliases are only added if MIX_TARGET is set.
21+
def bootstrap(args) do
22+
Application.start(:nerves_bootstrap)
23+
Mix.Task.run("loadconfig", args)
24+
end
25+
26+
# Run "mix help compile.app" to learn about applications.
27+
def application do
28+
[
29+
mod: {HanAms.Application, []},
30+
extra_applications: [:logger, :runtime_tools]
31+
]
32+
end
33+
34+
# Run "mix help deps" to learn about dependencies.
35+
defp deps do
36+
[
37+
# Dependencies for all targets
38+
{:nerves, "~> 1.4", runtime: false},
39+
{:shoehorn, "~> 0.4"},
40+
{:ring_logger, "~> 0.6"},
41+
{:toolshed, "~> 0.2"},
42+
43+
# Dependencies for all targets except :host
44+
{:nerves_runtime, "~> 0.6", targets: @all_targets},
45+
{:nerves_init_gadget, "~> 0.4", targets: @all_targets},
46+
{:nerves_firmware_ssh, "~> 0.4", targets: @all_targets},
47+
48+
# Dependencies for specific targets
49+
{:nerves_system_rpi, "~> 1.6", runtime: false, targets: :rpi},
50+
{:nerves_system_rpi0, "~> 1.6", runtime: false, targets: :rpi0},
51+
{:nerves_system_rpi2, "~> 1.6", runtime: false, targets: :rpi2},
52+
{:nerves_system_rpi3, "~> 1.6", runtime: false, targets: :rpi3},
53+
{:nerves_system_rpi3a, "~> 1.6", runtime: false, targets: :rpi3a},
54+
{:nerves_system_bbb, "~> 2.0", runtime: false, targets: :bbb},
55+
{:nerves_system_x86_64, "~> 1.6", runtime: false, targets: :x86_64}
56+
]
57+
end
58+
end

0 commit comments

Comments
 (0)