Skip to content

Commit

Permalink
smlang 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Jan 27, 2025
1 parent 4b80904 commit e63f611
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ log = {version = "0.4", optional = true}
embedded-time = "0.12"
varint-rs = {version = "2.2", default-features = false }
serde = { version = "1", features = ["derive"], default-features = false }
smlang = "0.6.0"
smlang = "0.8.0"
embedded-nal = "0.9"

[features]
Expand Down
22 changes: 11 additions & 11 deletions src/mqtt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ mod sm {
transitions: {
*Disconnected + TcpConnected = Restart,
Restart + SentConnect = Establishing,
Establishing + Connected(ConnAck<'a>) [ handle_connack ] = Active,
Establishing + Connected(ConnAck<'a>) / handle_connack = Active,

Active + SendTimeout = Disconnected,
_ + ProtocolError = Disconnected,

Active + ControlPacket(ReceivedPacket<'a>) [handle_packet] = Active,
Active + SentSubscribe(u16) [handle_subscription] = Active,
Active + ControlPacket(ReceivedPacket<'a>) / handle_packet = Active,
Active + SentSubscribe(u16) / handle_subscription = Active,

_ + TcpDisconnect = Disconnected
},
custom_guard_error: true,
custom_error: true,
}
}

Expand Down Expand Up @@ -176,16 +176,16 @@ impl<Clock> sm::StateMachineContext for ClientContext<'_, Clock>
where
Clock: embedded_time::Clock,
{
type GuardError = MinimqError;
type Error = MinimqError;

fn handle_subscription(&mut self, id: &u16) -> Result<(), Self::GuardError> {
fn handle_subscription(&mut self, id: u16) -> Result<(), Self::Error> {
self.pending_subscriptions
.push(*id)
.push(id)
.map_err(|_| ProtocolError::BufferSize)?;
Ok(())
}

fn handle_packet(&mut self, packet: &ReceivedPacket<'_>) -> Result<(), Self::GuardError> {
fn handle_packet(&mut self, packet: ReceivedPacket<'_>) -> Result<(), Self::Error> {
match &packet {
ReceivedPacket::SubAck(ack) => self.handle_suback(ack)?,
ReceivedPacket::PingResp => self.register_ping_response(),
Expand All @@ -204,7 +204,7 @@ where
Ok(())
}

fn handle_connack(&mut self, acknowledge: &ConnAck<'_>) -> Result<(), Self::GuardError> {
fn handle_connack(&mut self, acknowledge: ConnAck<'_>) -> Result<(), Self::Error> {
acknowledge.reason_code.as_result()?;

// Reset the session state upon connection with a broker that doesn't have a session state
Expand Down Expand Up @@ -253,8 +253,8 @@ where
impl<E> From<sm::Error<MinimqError>> for Error<E> {
fn from(error: sm::Error<MinimqError>) -> Self {
match error {
sm::Error::GuardFailed(err) => Error::Minimq(err),
sm::Error::InvalidEvent => Error::NotReady,
sm::Error::ActionFailed(err) | sm::Error::GuardFailed(err) => Error::Minimq(err),
sm::Error::InvalidEvent | sm::Error::TransitionsFailed => Error::NotReady,
}
}
}
Expand Down

0 comments on commit e63f611

Please sign in to comment.