pub struct OutgoingCommunication<'a, CLOCK, UDP, const BUFFER_SIZE: usize, const MAX_OPTION_COUNT: usize, const MAX_OPTION_SIZE: usize>where
CLOCK: Clock,
UDP: UdpClientStack,{ /* private fields */ }Expand description
Outgoing communication path. Sends outgoing requests, pings and CoAP Observe notifications and handles retransmissions and timeouts automatically.
Implementations§
Source§impl<'a, CLOCK, UDP, const BUFFER_SIZE: usize, const MAX_OPTION_COUNT: usize, const MAX_OPTION_SIZE: usize> OutgoingCommunication<'a, CLOCK, UDP, BUFFER_SIZE, MAX_OPTION_COUNT, MAX_OPTION_SIZE>where
CLOCK: Clock,
UDP: UdpClientStack,
impl<'a, CLOCK, UDP, const BUFFER_SIZE: usize, const MAX_OPTION_COUNT: usize, const MAX_OPTION_SIZE: usize> OutgoingCommunication<'a, CLOCK, UDP, BUFFER_SIZE, MAX_OPTION_COUNT, MAX_OPTION_SIZE>where
CLOCK: Clock,
UDP: UdpClientStack,
Sourcepub fn new(
clock: &'a CLOCK,
transmission_parameters: TransmissionParameters,
) -> Self
pub fn new( clock: &'a CLOCK, transmission_parameters: TransmissionParameters, ) -> Self
Initializes the outgoing communication path in the [OutgoingState::Idle(false)] state so
it is ready to send requests.
Sourcepub fn state(&self) -> OutgoingState
pub fn state(&self) -> OutgoingState
Returns the current state of the OutgoingCommunication. Depending on the state, the user
must take action to drive the state forward, see the documentation to the states in
OutgoingState.
Sourcepub fn response(
&self,
) -> Result<EncodedMessage<'_>, Error<<UDP as UdpClientStack>::Error>>
pub fn response( &self, ) -> Result<EncodedMessage<'_>, Error<<UDP as UdpClientStack>::Error>>
Returns the last response which is the same that was returned in the Success event
before. Therefore, usage of this method is only required if the response should be used
later (the message from the Success event can probably not be stored due to lifetime
requirements).
This method is only available in [Idle(true)] and will return Error::Forbidden
otherwise.
Sourcepub fn schedule_non(
&mut self,
code: RequestCode,
options: Vec<CoapOption<'_>, MAX_OPTION_COUNT>,
payload: Option<&[u8]>,
timeout: Duration,
) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
pub fn schedule_non( &mut self, code: RequestCode, options: Vec<CoapOption<'_>, MAX_OPTION_COUNT>, payload: Option<&[u8]>, timeout: Duration, ) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
Schedules a non-confirmable request to be sent
The message is constructed with the given details (message_type, code, options and
payload). The timeout is used for an application-level timeout which is used if no
further retransmissions are tried.
Sourcepub fn schedule_con(
&mut self,
code: RequestCode,
options: Vec<CoapOption<'_>, MAX_OPTION_COUNT>,
payload: Option<&[u8]>,
timeout: Duration,
) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
pub fn schedule_con( &mut self, code: RequestCode, options: Vec<CoapOption<'_>, MAX_OPTION_COUNT>, payload: Option<&[u8]>, timeout: Duration, ) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
Schedules a confirmable request to be sent
The timeout is used for an application-level timeout which is started as soon as an ACK
is received (in case of piggybacked responses, we succeed immediately, so the timeout is
not needed).
Sourcepub fn schedule_notification(
&mut self,
confirmable: bool,
code: ResponseCode,
token: Token,
options: Vec<CoapOption<'_>, MAX_OPTION_COUNT>,
payload: Option<&[u8]>,
) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
pub fn schedule_notification( &mut self, confirmable: bool, code: ResponseCode, token: Token, options: Vec<CoapOption<'_>, MAX_OPTION_COUNT>, payload: Option<&[u8]>, ) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
Schedules a CoAP observe notification to be sent
The options must already contain the Observe option because the sequence number
can not be determined in this method.
Sourcepub fn schedule_ping(
&mut self,
timeout: Duration,
) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
pub fn schedule_ping( &mut self, timeout: Duration, ) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
Schedules a ping to be sent
Sourcepub fn cancel(&mut self) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
pub fn cancel(&mut self) -> Result<(), Error<<UDP as UdpClientStack>::Error>>
Cancels the currently ongoing outgoing communication
This brings us back into the [OutgoingState::Idle(false)] state. Also, this sets up
message de-duplication normally. This has the effect that if we receive a CON response for
a cancelled request, an ACK will be automatically sent. This may look surprising but:
- this behavior is the same as normally receiving+acknowledging the response and just ignoring the response afterwards (which would be valid) and
- this enables the other endpoint to stop retransmitting its CON response.
If the currently ongoing communication is a notification, we will additionally be able to
recognize corresponding RST messages and generate OutgoingEvent::NotificationRst
events.
This method is available in all states but the Idle state. If in Idle state, it returns
Error::Forbidden.