Struct MessageHeader

Source
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

Source

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.

Source

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.

Source

pub fn new_with_error_info<S>( message: S, error_counts: &[u8], burst_counts: &[u8], ) -> Result<Self, MessageDecodeErr>
where S: Into<String>,

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.

Source

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.

Source

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.

Source

pub fn originator(&self) -> Originator

Originator code

The ultimate source of the message, such as Originator::NationalWeatherService for the National Weather Service

Source

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.

Source

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.

Source

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.

Source

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 county
  • SS: FIPS State code
  • CCC: 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.

Source

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.

Source

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().

Source

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.

Source

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.

Source

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., and 365 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.

Source

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 (/).

Source

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.

Source

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.

Source

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.

Source

pub fn release(self) -> String

Obtain the owned message String

Destroys this object and releases the message contained within

Trait Implementations§

Source§

impl AsRef<[u8]> for MessageHeader

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for MessageHeader

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for MessageHeader

Source§

fn clone(&self) -> MessageHeader

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MessageHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MessageHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<MessageHeader> for String

Source§

fn from(msg: MessageHeader) -> String

Converts to this type from the input type.
Source§

impl Hash for MessageHeader

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MessageHeader

Source§

fn eq(&self, other: &MessageHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<(String, &[u8])> for MessageHeader

Source§

type Error = MessageDecodeErr

The type returned in the event of a conversion error.
Source§

fn try_from(inp: (String, &[u8])) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<(String, &[u8], &[u8])> for MessageHeader

Source§

type Error = MessageDecodeErr

The type returned in the event of a conversion error.
Source§

fn try_from(inp: (String, &[u8], &[u8])) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for MessageHeader

Source§

type Error = MessageDecodeErr

The type returned in the event of a conversion error.
Source§

fn try_from(inp: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for MessageHeader

Source§

impl StructuralPartialEq for MessageHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,