Handle message that don't reply on success

This commit is contained in:
QuantumEntangledAndy committed 2023-06-07 17:36:42 +07:00
1 parent 9eb892ae27
commit 3467951c5c
3 files changed
+53 -32

No files matched your search

@@ -77,18 +77,25 @@ impl BcCamera {
};
sub_set.send(get).await?;
let msg = sub_set.recv().await?;
if let BcMeta {
response_code: 200, ..
} = msg.meta
if let Ok(reply) =
tokio::time::timeout(tokio::time::Duration::from_micros(500), sub_set.recv()).await
{
Ok(())
let msg = reply?;
if let BcMeta {
response_code: 200, ..
} = msg.meta
{
Ok(())
} else {
Err(Error::UnintelligibleReply {
reply: std::sync::Arc::new(Box::new(msg)),
why: "The camera did not accept the Floodlight manual state",
})
}
} else {
Err(Error::UnintelligibleReply {
reply: std::sync::Arc::new(Box::new(msg)),
why: "The camera did not accept the Floodlight manual state",
})
// Some cameras seem to just not send a reply on success, so after 500ms we return Ok
Ok(())
}
}
}
+17 -10
View File
@@ -83,18 +83,25 @@ impl BcCamera {
};
sub_set.send(get).await?;
let msg = sub_set.recv().await?;
if let BcMeta {
response_code: 200, ..
} = msg.meta
if let Ok(reply) =
tokio::time::timeout(tokio::time::Duration::from_micros(500), sub_set.recv()).await
{
Ok(())
let msg = reply?;
if let BcMeta {
response_code: 200, ..
} = msg.meta
{
Ok(())
} else {
Err(Error::UnintelligibleReply {
reply: std::sync::Arc::new(Box::new(msg)),
why: "The camera did not except the LEDState xml",
})
}
} else {
Err(Error::UnintelligibleReply {
reply: std::sync::Arc::new(Box::new(msg)),
why: "The camera did not except the LEDState xml",
})
// Some cameras seem to just not send a reply on success, so after 500ms we return Ok
Ok(())
}
}
+20 -13
View File
@@ -94,21 +94,28 @@ impl BcCamera {
};
sub_set.send(get).await?;
let msg = sub_set.recv().await?;
if msg.meta.response_code != 200 {
return Err(Error::CameraServiceUnavaliable);
}
if let BcMeta {
response_code: 200, ..
} = msg.meta
if let Ok(reply) =
tokio::time::timeout(tokio::time::Duration::from_micros(500), sub_set.recv()).await
{
Ok(())
let msg = reply?;
if msg.meta.response_code != 200 {
return Err(Error::CameraServiceUnavaliable);
}
if let BcMeta {
response_code: 200, ..
} = msg.meta
{
Ok(())
} else {
Err(Error::UnintelligibleReply {
reply: std::sync::Arc::new(Box::new(msg)),
why: "The camera did not except the RfAlarmCfg xml",
})
}
} else {
Err(Error::UnintelligibleReply {
reply: std::sync::Arc::new(Box::new(msg)),
why: "The camera did not except the RfAlarmCfg xml",
})
// Some cameras seem to just not send a reply on success, so after 500ms we return Ok
Ok(())
}
}