Aprs.WeatherHelpers (aprs v2.0.1)

View Source

Binary weather field scanning helpers for APRS.

Summary

Functions

Split a leading timestamp off a weather report.

Scan a weather report in one left-to-right pass.

Types

weather_value()

@type weather_value() :: integer() | float() | nil

weather_values()

@type weather_values() :: %{required(atom()) => weather_value()}

Functions

extract_timestamp(data)

@spec extract_timestamp(binary()) :: String.t() | nil

The timestamp half of extract_timestamp_and_data/1.

extract_timestamp_and_data(data)

@spec extract_timestamp_and_data(binary()) :: {String.t() | nil, binary()}

Split a leading timestamp off a weather report.

A positionless report starts with the eight-digit MDHM form, which is recognised only when it is followed by the wind direction field. Otherwise the seven-byte DDHHMM form (h, z or /) is looked for anywhere in the data. Returns {timestamp_or_nil, data_without_timestamp}.

remove_timestamp(data)

@spec remove_timestamp(binary()) :: binary()

The data half of extract_timestamp_and_data/1.

scan_weather_data(data)

@spec scan_weather_data(binary()) :: {weather_values(), binary()}

Scan a weather report in one left-to-right pass.

Returns {weather_values, remainder}, where the remainder is the part of the input that was not a weather field - for a position comment, the comment text. Fields the report omits are nil. A bare ddd/sss wind pair at the start is accepted as direction and speed.

Single fields

parse_humidity(data)

@spec parse_humidity(binary()) :: integer() | nil

See parse_wind_direction/1.

parse_luminosity(data)

@spec parse_luminosity(binary()) :: integer() | nil

See parse_wind_direction/1.

parse_pressure(data)

@spec parse_pressure(binary()) :: float() | nil

See parse_wind_direction/1.

parse_rainfall_1h(data)

@spec parse_rainfall_1h(binary()) :: float() | nil

See parse_wind_direction/1.

parse_rainfall_24h(data)

@spec parse_rainfall_24h(binary()) :: float() | nil

See parse_wind_direction/1.

parse_rainfall_since_midnight(data)

@spec parse_rainfall_since_midnight(binary()) :: float() | nil

See parse_wind_direction/1.

parse_snow(data)

@spec parse_snow(binary()) :: float() | nil

See parse_wind_direction/1.

parse_temperature(data)

@spec parse_temperature(binary()) :: integer() | nil

See parse_wind_direction/1.

parse_wind_direction(data)

@spec parse_wind_direction(binary()) :: integer() | nil

Return one weather field from a report, or nil when it is absent.

Each of these runs scan_weather_data/1 and picks a single value out, so parsing a whole report with scan_weather_data/1 is cheaper than calling them one at a time.

parse_wind_gust(data)

@spec parse_wind_gust(binary()) :: integer() | nil

See parse_wind_direction/1.

parse_wind_speed(data)

@spec parse_wind_speed(binary()) :: integer() | nil

See parse_wind_direction/1.