pub struct MessageHeader { /* private fields */ }
Expand description
Event, area, time, and originator information
The message header is the decoded digital header which precedes the analog SAME message. See crate documentation for an example.
Implementations§
Source§impl MessageHeader
impl MessageHeader
Sourcepub fn new<S>(message: S) -> Result<Self, MessageDecodeErr>
pub fn new<S>(message: S) -> Result<Self, MessageDecodeErr>
Try to construct a SAME header from String
The message
string must match the general format of
a SAME header. If it does not, an error is returned.
Sourcepub fn new_with_errors<S>(
message: S,
error_counts: &[u8],
) -> Result<Self, MessageDecodeErr>
pub fn new_with_errors<S>( message: S, error_counts: &[u8], ) -> Result<Self, MessageDecodeErr>
Try to construct a SAME header from String
, with error counts
The message
string must match the general format of
a SAME header. If it does not, an error is returned.
The error_counts
slice counts the number of bit errors
corrected in byte of message
. The slice must have the
same length as message
.
Sourcepub fn new_with_error_info<S>(
message: S,
error_counts: &[u8],
burst_counts: &[u8],
) -> Result<Self, MessageDecodeErr>
pub fn new_with_error_info<S>( message: S, error_counts: &[u8], burst_counts: &[u8], ) -> Result<Self, MessageDecodeErr>
Try to construct a SAME header from String
, with error details
The message
string must match the general format of
a SAME header. If it does not, an error is returned.
The error_counts
slice counts the number of bit errors
corrected in byte of message
. The slice must have the
same byte count as message
.
burst_counts
is the total number of SAME bursts which were
used to estimate each message byte. This slice must have
the same byte count as message
.
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Message text
Returns UTF-8 string representation of a SAME/EAS
message. Use the release()
method to obtain an owned String
.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Message text
Returns UTF-8 string representation of a SAME/EAS
message. Use the release()
method to obtain an owned String
.
Sourcepub fn originator(&self) -> Originator
pub fn originator(&self) -> Originator
Originator code
The ultimate source of the message, such as
Originator::NationalWeatherService
for the
National Weather Service
Sourcepub fn originator_str(&self) -> &str
pub fn originator_str(&self) -> &str
Originator code (as string)
A three-character string that is usually one of the following:
-
PEP
: Primary Entry Point Station. Generally only used for national activations, which are very rare. -
CIV
: Civil authorities (usu. state and local government) -
WXR
: National Weather Service or Environment Canada -
EAS
: EAS Participant. Usually a broadcast station.
The originator code returned is three characters but is not guaranteed to be one of the above.
Sourcepub fn event(&self) -> EventCode
pub fn event(&self) -> EventCode
Event code
Decodes the SAME event code (like RWT
) into an
EventCode
, which is a combination of:
-
phenomenon()
, which describes what is occurring; and -
significance()
, which indicates the overall severity and/or how “noisy” or intrusive the alert should be.
EventCode
Display as a human-readable string which describes
the SAME code. For example, “TOR
” displays as “Tornado Warning.”
use sameold::{MessageHeader, Phenomenon, SignificanceLevel};
let msg = MessageHeader::new("ZCZC-WXR-RWT-012345+0351-3662322-NOCALL -").unwrap();
let evt = msg.event();
assert_eq!(evt.phenomenon(), Phenomenon::RequiredWeeklyTest);
assert_eq!(evt.significance(), SignificanceLevel::Test);
assert_eq!(format!("{}", evt), "Required Weekly Test");
The decoder will make every effort to interpret SAME codes it
does not explicitly know. The EventCode
might contain only a
valid significance level—or perhaps not even that.
let msg = MessageHeader::new("ZCZC-WXR-OMG-012345+0351-3662322-NOCALL -").unwrap();
assert_eq!(msg.event_str(), "OMG");
assert_eq!(msg.event().to_string(), "Unrecognized Warning");
assert_eq!(msg.event().significance(), SignificanceLevel::Unknown);
assert!(msg.event().is_unrecognized());
Unrecognized messages are still valid, and clients are encouraged to treat them at their significance level. Messages where even the significance level cannot be decoded should be treated as Warnings.
eventcodes
contains the complete list of SAME
codes that are interpreted by sameold
. See also: EventCode
.
Sourcepub fn event_str(&self) -> &str
pub fn event_str(&self) -> &str
Event code
A three-character code like “RWT
” which describes the phenomenon
and/or the severity level of the message. Use the
event()
method to parse this
code into its components for further processing or for
a human-readable display.
See eventcodes
for the complete list
of SAME codes that are interpreted by sameold
. The string value
is not guaranteed to be one of these codes.
Sourcepub fn location_str_iter<'m>(&'m self) -> Split<'m, char>
pub fn location_str_iter<'m>(&'m self) -> Split<'m, char>
Iterator over location codes
Returns an iterator over the location codes in the
message. Location codes are six-digit strings of
the form PSSCCC
:
P
: part of county, or zero for entire countySS
: FIPS State codeCCC
: FIPS County code
Locations are returned in the order listed in the message. Iterator values are guaranteed to be six-digit strings.
Per the SAME standard, a message can have up to 31 location codes.
Sourcepub fn valid_duration(&self) -> Duration
pub fn valid_duration(&self) -> Duration
Message validity duration (Duration)
Returns the message validity duration. The message is valid until
msg.issue_datetime().unwrap() + msg.valid_duration()
After this time elapses, the message is no longer valid and should not be relayed or alerted to anymore.
This field represents the validity time of the message and not the expected duration of the severe condition. Severe conditions may persist after the message expires! (And might be the subject of future messages.)
The valid duration is relative to the
issue_datetime()
and not the
current time.
Requires chrono
.
Sourcepub fn valid_duration_fields(&self) -> (u8, u8)
pub fn valid_duration_fields(&self) -> (u8, u8)
Message validity duration
Returns the message validity duration or “purge time.”
This is a tuple of (hours
, minutes
).
This field represents the validity time of the message and not the expected duration of the severe condition. Severe conditions may persist after the message expires! (And might be the subject of future messages.)
The valid duration is relative to the
issue_daytime_fields()
.
Sourcepub fn issue_datetime(
&self,
received: &DateTime<Utc>,
) -> Result<DateTime<Utc>, InvalidDateErr>
pub fn issue_datetime( &self, received: &DateTime<Utc>, ) -> Result<DateTime<Utc>, InvalidDateErr>
Estimated message issuance datetime (UTC)
Computes the datetime that the SAME message was issued
from the time that the message was received
, which
must be provided.
SAME headers do not include the year of issuance. This makes
it impossible to calculate the full datetime of issuance
without a rough idea of the message’s true UTC time. It is
unnecessary for the received
time to be a precision
timestamp. As long as the provided value is within ±90 days
of true UTC, the output time will be correct.
An error is returned if we are unable to calculate a valid timestamp. This can happen, for example, if we project a message sent on Julian/Ordinal Day 366 into a year that is not a leap year.
The returned datetime is always in one minute increments with the seconds field set to zero.
Requires chrono
.
Sourcepub fn is_expired_at(&self, now: &DateTime<Utc>) -> bool
pub fn is_expired_at(&self, now: &DateTime<Utc>) -> bool
Is the message expired?
Given the current time, determine if this message has
expired. It is assumed that now
is within twelve
hours of the message issuance time. Twelve hours is
the maximum duration
of a
SAME message.
An expired message may still refer to an ongoing hazard or event! Expiration merely indicates that the message should not be relayed or alerted to anymore.
Requires chrono
.
Sourcepub fn issue_daytime_fields(&self) -> (u16, u8, u8)
pub fn issue_daytime_fields(&self) -> (u16, u8, u8)
Mesage issuance day/time (fields)
Returns the message issue day and time, as the string
JJJHHMM
,
-
JJJ
: Ordinal day of the year.001
represents 1 Jan., and365
represents 31 Dec. in non leap-years. During leap-years,366
represents 31 Dec.000
is not used. It is up to the receiving station to have some notion of what the current year is and to detect calendar rollovers. -
HHMM
: UTC time of day, using a 24-hour time scale. Times are UTC and are NOT local times.
Sourcepub fn callsign(&self) -> &str
pub fn callsign(&self) -> &str
Sending station callsign
The FCC or other regulatory body-assigned callsign
of the sending station. Minus signs (-
) in the
callsign are replaced with slashes (/
).
Sourcepub fn parity_error_count(&self) -> usize
pub fn parity_error_count(&self) -> usize
Count of parity errors
The number of bit errors which were corrected by the 2-of-3 parity correction algorithm. High parity error counts indicate a high bit error rate in the receiving system.
Sourcepub fn voting_byte_count(&self) -> usize
pub fn voting_byte_count(&self) -> usize
Number of bytes which were bit-voted
voting_byte_count
is the total number of bytes which were
checked via the “two of three” bitwise voting algorithm—i.e.,
the total number of bytes for which all three SAME bursts were
available.
Sourcepub fn is_national(&self) -> bool
pub fn is_national(&self) -> bool
True if the message is a national activation
Returns true if:
-
the location code in the SAME message indicates national applicability; and
-
the event code is reserved for national use
The message may either be a test or an actual emergency.
Consult the event()
for details.
Clients are strongly encouraged to always play national-level messages and to never provide the option to suppress them.
Trait Implementations§
Source§impl AsRef<[u8]> for MessageHeader
impl AsRef<[u8]> for MessageHeader
Source§impl AsRef<str> for MessageHeader
impl AsRef<str> for MessageHeader
Source§impl Clone for MessageHeader
impl Clone for MessageHeader
Source§fn clone(&self) -> MessageHeader
fn clone(&self) -> MessageHeader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MessageHeader
impl Debug for MessageHeader
Source§impl Display for MessageHeader
impl Display for MessageHeader
Source§impl From<MessageHeader> for String
impl From<MessageHeader> for String
Source§fn from(msg: MessageHeader) -> String
fn from(msg: MessageHeader) -> String
Source§impl Hash for MessageHeader
impl Hash for MessageHeader
Source§impl PartialEq for MessageHeader
impl PartialEq for MessageHeader
Source§impl TryFrom<String> for MessageHeader
impl TryFrom<String> for MessageHeader
impl Eq for MessageHeader
impl StructuralPartialEq for MessageHeader
Auto Trait Implementations§
impl Freeze for MessageHeader
impl RefUnwindSafe for MessageHeader
impl Send for MessageHeader
impl Sync for MessageHeader
impl Unpin for MessageHeader
impl UnwindSafe for MessageHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.