Struct sameold::MessageHeader
source · pub struct MessageHeader { /* private fields */ }Expand description
Event, area, time, and originator information
Implementations§
source§impl MessageHeader
impl MessageHeader
sourcepub fn new<S>(message: S) -> Result<Self, MessageDecodeErr>where
S: Into<String>,
pub fn new<S>(message: S) -> Result<Self, MessageDecodeErr>where S: Into<String>,
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>where
S: Into<String>,
pub fn new_with_errors<S>( message: S, error_counts: &[u8] ) -> Result<Self, MessageDecodeErr>where S: Into<String>,
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 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::WeatherService 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) -> Result<EventCode, UnrecognizedEventCode>
pub fn event(&self) -> Result<EventCode, UnrecognizedEventCode>
Event code
Decodes the event code into an enumerated type.
For example, messages which contain an
event_str() of “RWT” will decode
as EventCode::RequiredWeeklyTest.
If the event code is unrecognized, an error is returned.
An error here does NOT mean that the message is
invalid or should be discarded. Instead, if the
error is
WithSignificance,
then you should treat it as a valid (but unknown)
message at the given significance level. This will help
your application react correctly if new codes are
added in the future.
Event codes can be converted to human-readable strings.
use sameold::EventCode;
assert_eq!("Required Weekly Test", (EventCode::RequiredWeeklyTest).as_display_str());
assert_eq!(
"Required Weekly Test",
format!("{}", EventCode::RequiredWeeklyTest)
);All EventCode are mapped to a significance level.
This may be useful when deciding how to handle the event.
let lvl = (EventCode::RequiredWeeklyTest).to_significance_level();
assert_eq!(lvl, SignificanceLevel::Test);sourcepub fn event_str(&self) -> &str
pub fn event_str(&self) -> &str
Event code
A three-character code which is generally formatted according to severity level.
xxT: TestxxS: Statement / AdvisoryxxA: WatchxxW: Warning (generally most severe events)
Major exceptions to this are the codes SVR
(“Severe Thunderstorm Warning”) and TOR
(“Tornado Warning”), which are among the most common
messages in the United States. Plenty of other codes
also do not adhere to this standard.
The event code returned is three characters but is not guaranteed to be one of the above.
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.001represents 1 Jan., and365represents 31 Dec. in non leap-years. During leap-years,366represents 31 Dec.000is 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.
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<MessageHeader> for MessageHeader
impl PartialEq<MessageHeader> for MessageHeader
source§fn eq(&self, other: &MessageHeader) -> bool
fn eq(&self, other: &MessageHeader) -> bool
self and other values to be equal, and is used
by ==.source§impl TryFrom<String> for MessageHeader
impl TryFrom<String> for MessageHeader
impl Eq for MessageHeader
impl StructuralEq for MessageHeader
impl StructuralPartialEq for MessageHeader
Auto Trait Implementations§
impl RefUnwindSafe for MessageHeader
impl Send for MessageHeader
impl Sync for MessageHeader
impl Unpin for MessageHeader
impl UnwindSafe for MessageHeader
Blanket Implementations§
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.