Current section

Files

Jump to
aprs lib aprs.ex
Raw

lib/aprs.ex

defmodule Aprs do
@moduledoc """
Documentation for Aprs.
"""
_="""
KC5EVE-15>APRX28,DURNGO*,WIDE1*,DOLLAR*:!3735.23NI10748.68W#KC5EVE-15 I-Gate/Digi Needles, CO
TENDER>APN382,RBERRY*,DOLLAR*:!3831.59NS10654.33W#PHG5550/W3,COn N0NHJ /A=008624
KC5HNN>APTT4,RBERRY*,WIDE1,WIDE2-2:/234755h3828.80N/10751.47WR000/000Jerry's motorhome jgrosman@netzero.net/A=005844
K5LGF-9>S7TYQV,HAYDN*,WIDE1*,RBERRY*,WIDE2:`sFOms0j/`"SU}146.550MHz T114 Green Jeep - Larry_%
"""
@doc """
Hello world.
## Examples
iex> Aprs.hello
:world
"""
def start do
packet = """
K5LGF-9>S7TYQV,HAYDN*,WIDE1*,RBERRY*,WIDE2:`sFOms0j/`"SU}146.550MHz T114 Green Jeep - Larry_%
"""
parse packet
end
def parse(packet) do
valid =
with {:ok} <- packet_present?(packet),
{:ok} <- packet_proper_length?(packet),
do: {:ok}
case valid do
{:ok} -> IO.puts "ok"
{:error, error} -> IO.puts "oh noes, error: #{error}"
end
# Separate the header and packet body on the first colon.
# If no body, skip
# Save all the parts of the packet
# Source callsign, put the rest in $rest
# Get the destination callsign and digipeaters.
# Destination callsign.
# digipeaters
# So now we have source and destination callsigns and
# digipeaters parsed and ok. Move on to the body.
# Check the first character of the packet
# and determine the packet type
IO.puts packet
end
defp packet_present?(packet) do
case packet do
nil -> {:error, "Packet can't be empty"}
_ -> {:ok}
end
end
defp packet_proper_length?(packet) do
cond do
String.length(packet) >= 5 -> {:ok}
true -> {:error, "Packet must be at least 5 characters"}
end
end
end
Aprs.start