Skip to content

Commit

Permalink
Update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyc committed May 31, 2024
2 parents 91f5cec + 48178c9 commit a4ec3d7
Show file tree
Hide file tree
Showing 26 changed files with 477 additions and 230 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
## Unreleased
* Added the ability to remote TX audio.
* Added TX TUNE button
* Added the ability to remotely wake the radio from the connections listing.
* Reworked the connections screen to be a LiveView.
* Added the ability to configure the UDP audio port from 60001 via OPEN890_UDP_PORT
* Updated startup message to explain how to control the server host and port through OPEN890_HOST and OPEN890_PORT
* Fixed PROC on/off state not correctly queried on startup
* Further fixes to purple TF SET indicator (WIP)


## 1.0.8.1 - 2023-11-20
* Fixed TF SET display
* Added purple TF SET carrier indicator
Expand Down
2 changes: 0 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ config :logger, :console,
config :phoenix, :json_library, Jason
config :phoenix, :trim_on_html_eex_engine, false

config :open890, Open890.RadioConnectionRepo, database: :"db/radio_connections.dets"

config :esbuild,
version: "0.14.0",
default: [
Expand Down
3 changes: 3 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ if config_env() in [:dev, :prod] do
config :open890, Open890.UDPAudioServer, port: udp_port

Logger.info("Configured OPEN890_HOST: #{inspect(host)}, OPEN890_PORT: #{inspect(port)}, OPEN890_UDP_PORT: #{inspect(udp_port)}")

config :open890, Open890.RadioConnectionRepo, database: :"db/radio_connections.dets"
else
config :open890, Open890.UDPAudioServer, port: 60001
config :open890, Open890.RadioConnectionRepo, database: :"db/radio_connections_test.dets"
end
2 changes: 0 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ config :open890, Open890Web.Endpoint,

# Print only warnings and errors during test
config :logger, level: :warn

config :open890, Open890.RadioConnectionRepo, database: :"db/radio_connections_test.dets"
1 change: 1 addition & 0 deletions lib/open890/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ defmodule Open890.Application do
|> Enum.filter(fn conn ->
Map.get(conn, :auto_start, "false") == "true"
end)
|> IO.inspect(label: "auto-start connections")
|> Enum.each(fn conn ->
Logger.info("Auto-starting connection id #{conn.id}, \"#{conn.name}\"")
conn |> RadioConnection.start()
Expand Down
31 changes: 28 additions & 3 deletions lib/open890/connection_commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defmodule Open890.ConnectionCommands do
Logger.debug("*** GET INITIAL STATE ***")

conn
|> power_on()
|> get_power_state()
|> get_active_receiver()
|> get_vfo_a_freq()
|> get_vfo_b_freq()
Expand Down Expand Up @@ -59,6 +61,24 @@ defmodule Open890.ConnectionCommands do
|> get_proc_enabled()
end

def power_on(conn), do: conn |> cmd("PS1")
def power_off(conn), do: conn |> cmd("PS0")

def wake(%RadioConnection{mac_address: nil} = conn) do
Logger.info("Attempted to WOL connection without a MAC address")
conn
end

def wake(%RadioConnection{mac_address: mac_address} = conn) do
Logger.info("Sending WOL packet to #{mac_address}")
WOL.send(mac_address)
conn
end

def wake(conn) do
WOL.send(conn.mac_address)
end

def get_busy_led_state(conn), do: conn |> cmd("BY")
def get_fine(conn), do: conn |> cmd("FS")

Expand Down Expand Up @@ -165,13 +185,18 @@ defmodule Open890.ConnectionCommands do
end

def set_power_level(conn, value) do
value = value
|> to_string()
|> String.pad_leading(3, "0")
value =
value
|> to_string()
|> String.pad_leading(3, "0")

conn |> cmd("PC#{value}")
end

def get_power_state(conn) do
conn |> cmd("PS")
end

def get_power_level(conn) do
conn |> cmd("PC")
end
Expand Down
12 changes: 12 additions & 0 deletions lib/open890/extract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ defmodule Open890.Extract do
end
end

def power_state(str) when is_binary(str) do
str
|> trim_to_integer(["PS"])
|> case do
0 -> :off
1 -> :on
2 -> :source_off
3 -> :on_activating
_ -> :on
end
end

def power_level(str) when is_binary(str) do
str |> trim_to_integer(["PC"])
end
Expand Down
38 changes: 33 additions & 5 deletions lib/open890/radio_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Open890.RadioConnection do
name: nil,
ip_address: nil,
tcp_port: @default_tcp_port,
mac_address: nil,
user_name: nil,
password: nil,
user_is_admin: false,
Expand All @@ -24,7 +25,21 @@ defmodule Open890.RadioConnection do

alias Open890.{CloudlogSupervisor, RadioConnectionSupervisor}
alias Open890.RadioConnectionRepo, as: Repo
alias Open890.{RadioState, UserMarker}
alias Open890.{ConnectionCommands, RadioState, UserMarker}

def mac_address(connection) do
connection |> Map.get(:mac_address, nil)
end

def wake(%__MODULE__{mac_address: mac}) when is_binary(mac) do
Logger.info("Sending WOL packet to #{inspect mac}")
WOL.send(mac)
end

def wake(_) do
Logger.info("No MAC address associated with connection, not sending WOL")
:ok
end

def tcp_port(%__MODULE__{} = connection) do
connection
Expand All @@ -45,7 +60,7 @@ defmodule Open890.RadioConnection do

def first, do: all() |> Enum.at(0)

def add_user_marker(%__MODULE__{id: id} = connection, %UserMarker{} = marker) do
def add_user_marker(%__MODULE__{id: _id} = _connection, %UserMarker{} = _marker) do
# the problem here is that the old connection struct seemingly doesn't even
# have a :user_markers key, despite it being in the struct. it's like it's completely
# frozen in the previous state when coming from dets, keys and all
Expand All @@ -55,11 +70,11 @@ defmodule Open890.RadioConnection do
:ok
end

def delete_user_marker(%__MODULE__{} = connection, user_marker_id) do
def delete_user_marker(%__MODULE__{} = _connection, _user_marker_id) do
:ok
end

def clear_user_markers(%__MODULE__{} = connection) do
def clear_user_markers(%__MODULE__{} = _connection) do
# repo().update(%{connection | user_markers: []})
:ok
end
Expand Down Expand Up @@ -109,6 +124,7 @@ defmodule Open890.RadioConnection do
name: params["name"],
ip_address: params["ip_address"],
tcp_port: params["tcp_port"],
mac_address: params["mac_address"],
user_name: params["user_name"],
password: params["password"],
user_is_admin: params["user_is_admin"],
Expand Down Expand Up @@ -246,6 +262,10 @@ defmodule Open890.RadioConnection do
end
end

def query_power_state(connection) do
connection |> cmd("PS")
end

def cmd(%__MODULE__{} = connection, command) when is_binary(command) do
connection
|> get_connection_pid()
Expand Down Expand Up @@ -275,12 +295,20 @@ defmodule Open890.RadioConnection do
end
end

def power_off(%{id: _id} = conn) do
ConnectionCommands.power_off(conn)
end

def broadcast_freq_delta(%__MODULE__{id: id} = _connection, args) do
Open890Web.Endpoint.broadcast("connection:#{id}", "freq_delta", args)
end

def broadcast_connection_state(%__MODULE__{id: id} = _connection, state) do
Open890Web.Endpoint.broadcast("connection:#{id}", "connection_state", state)
Open890Web.Endpoint.broadcast("connection:#{id}", "connection_state", %{id: id, state: state})
end

def broadcast_power_state(%__MODULE__{id: id} = _connection, power_state) do
Open890Web.Endpoint.broadcast("connection:#{id}", "power_state", %{id: id, state: power_state})
end

def broadcast_band_scope(%__MODULE__{id: id}, band_scope_data) do
Expand Down
1 change: 1 addition & 0 deletions lib/open890/radio_connection_repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ defmodule Open890.RadioConnectionRepo do
end

def update(%RadioConnection{id: id} = conn) when not is_nil(id) do
conn |> IO.inspect(label: "ConnectionRepo.update, conn")
table_name() |> :dets.insert({id, conn})
end

Expand Down
2 changes: 1 addition & 1 deletion lib/open890/radio_state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ defmodule Open890.RadioState do
comp_meter: 0,
cw_delay: nil,
cw_key_speed: nil,
data_speed: nil,
data_speed: 1,
display_screen_id: 0,
filter_high_freq: nil,
filter_low_freq: nil,
Expand Down
12 changes: 5 additions & 7 deletions lib/open890/tcp_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Open890.TCPClient do
use GenServer
require Logger
alias Open890.RTP
alias Open890.Extract

import Bitwise, [:>>>, :&&&]

Expand Down Expand Up @@ -276,9 +277,10 @@ defmodule Open890.TCPClient do
{:stop, :shutdown, state}
end

# power status respnose
def handle_msg("PS1", state) do
# TODO: Cancel the connection timer here
def handle_msg("PS" <> _level = msg, %{connection: connection} = state) do
power_state = Extract.power_state(msg)
RadioConnection.broadcast_power_state(connection, power_state)

state
end

Expand All @@ -293,10 +295,6 @@ defmodule Open890.TCPClient do
# # filter scope LAN/high cycle respnose
# def handle_msg("DD11", state), do: state

def handle_msg("PS0", state) do
{:noreply, state}
# {:stop, :normal, state}
end

def handle_msg("BSD", %{connection: connection} = state) do
RadioConnection.broadcast_band_scope_cleared(connection)
Expand Down
15 changes: 15 additions & 0 deletions lib/open890_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ defmodule Open890Web do
and import those modules here.
"""

def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)

def controller do
quote do
require Logger
Expand All @@ -25,6 +27,8 @@ defmodule Open890Web do
import Plug.Conn
import Open890Web.Gettext
alias Open890Web.Router.Helpers, as: Routes

unquote(verified_routes())
end
end

Expand Down Expand Up @@ -109,6 +113,17 @@ defmodule Open890Web do
alias Open890.RadioConnection

import Phoenix.LiveView

unquote(verified_routes())
end
end

def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: Open890Web.Endpoint,
router: Open890Web.Router,
statics: Open890Web.static_paths()
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/open890_web/components/slider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Open890Web.Components.Slider do
attr :label, :string, required: true
attr :max_value, :integer, required: false
attr :padded_top_value, :integer, required: false
attr :padded_top, :boolean, default: false
attr :value, :any, required: true
attr :wheel, :string, required: false

Expand Down
4 changes: 2 additions & 2 deletions lib/open890_web/components/voip_buttons.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ defmodule Open890Web.Components.VoipButtons do
def mic_button(assigns) do
~H"""
<%= if @enabled do %>
<span class="ui large green button" phx-click="toggle_mic">
<span class="ui small green button" phx-click="toggle_mic">
<i class="icon microphone"></i> VOIP Mic: ON
</span>
<% else %>
<span class="ui large red inverted button" phx-click="toggle_mic">
<span class="ui small red inverted button" phx-click="toggle_mic">
<i class="icon microphone slash"></i> VOIP Mic: OFF
</span>
<% end %>
Expand Down
Loading

0 comments on commit a4ec3d7

Please sign in to comment.