Enum flipdot_core::Message
source · #[non_exhaustive]pub enum Message<'a> {
SendData(Offset, Data<'a>),
DataChunksSent(ChunkCount),
Hello(Address),
QueryState(Address),
ReportState(Address, State),
RequestOperation(Address, Operation),
AckOperation(Address, Operation),
PixelsComplete(Address),
Goodbye(Address),
Unknown(Frame<'a>),
}
Expand description
High-level representation of a sign bus communication message.
Ascribes meaning to a Frame
and is freely convertible to and from one
(with Unknown
to allow round-tripping unknown message types). This is the
primary way that messages are represented in flipdot
.
§Examples
use flipdot_core::{Address, Message, PageFlipStyle, SignBus, State};
use flipdot_testing::{VirtualSign, VirtualSignBus};
let mut bus = VirtualSignBus::new(vec![VirtualSign::new(Address(3), PageFlipStyle::Manual)]);
// Message is the currency used to send and receive messages on a bus:
let response = bus.process_message(Message::QueryState(Address(3)))?;
assert_eq!(Some(Message::ReportState(Address(3), State::Unconfigured)), response);
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
SendData(Offset, Data<'a>)
Send a chunk of data, with the first member indicating the offset.
E.g. when sending 32 bytes of data in two 16-byte chunks, the first message would have offset 0 and the second would have offset 16. No response is expected.
DataChunksSent(ChunkCount)
Notifies that we are done sending data, and specifies how many chunks were sent.
No response is expected.
Hello(Address)
Initially discovers the sign with the given address on the bus.
A ReportState
message with the sign’s current state is expected.
QueryState(Address)
Queries the sign with the given address for its current state.
A ReportState
message with the sign’s current state is expected.
ReportState(Address, State)
Indicates the state of the sign with the given address.
Sent by the sign in response to a Hello
orQueryState
message.
RequestOperation(Address, Operation)
Requests that the sign with the given address perform an operation.
An AckOperation
response is expected.
AckOperation(Address, Operation)
Sent by the sign with the given address indicating that it will perform the given operation.
PixelsComplete(Address)
Indicates that the pixel data for the sign with the given address has been fully transferred.
This indicates that the sign should load it into memory in preparation to show. No response is expected.
Goodbye(Address)
Notifies the sign with the given address to blank its display and shut down.
The sign will not be usable for 30 seconds after receiving this message. Generally optional as disconnecting switched power from the sign should have the same effect. No response is expected.
Unknown(Frame<'a>)
Wraps a Frame
that does not correspond to any known message.
Trait Implementations§
source§impl<'a> From<Frame<'a>> for Message<'a>
impl<'a> From<Frame<'a>> for Message<'a>
source§fn from(frame: Frame<'a>) -> Self
fn from(frame: Frame<'a>) -> Self
Converts a Frame
into a Message
.
This cannot fail as all valid Frame
s are representable as Message
s (though perhaps Unknown
).
The input Frame
is consumed to allow efficiently reusing its data where possible.
§Examples
let frame = Frame::new(Address(0x12), MsgType(4), Data::try_new(vec![0x07])?);
let message = Message::from(frame);
assert_eq!(Message::ReportState(Address(0x12), State::ConfigReceived), message);
source§impl<'a> From<Message<'a>> for Frame<'a>
impl<'a> From<Message<'a>> for Frame<'a>
source§fn from(message: Message<'a>) -> Self
fn from(message: Message<'a>) -> Self
Converts a Message
into a Frame
.
This cannot fail as all Message
s can be represented as Frame
s.
The input Message
is consumed to allow efficiently reusing its data where possible.
§Examples
let message = Message::ReportState(Address(0xFF), State::ConfigReceived);
let frame = Frame::from(message);
assert_eq!(Frame::new(Address(0xFF), MsgType(4), Data::try_new(vec![0x07])?), frame);