Send error

This commit is contained in:
Bastian Gruber 2023-05-22 15:00:59 +02:00
parent c57c0de2db
commit 641b48b367
No known key found for this signature in database
GPG key ID: BE9F8C772B188CBF
2 changed files with 24 additions and 12 deletions

View file

@ -8,6 +8,7 @@ use tokio::{
use crate::frame::{self, ClientFrames, ServerFrames};
#[derive(PartialEq)]
pub(crate) enum ConnectionType {
Camera,
Dispatcher,

View file

@ -180,16 +180,27 @@ impl Handler {
) -> crate::Result<()> {
match frame {
ClientFrames::Plate { plate, timestamp } => {
info!("Receive new plate: {plate} at {timestamp}");
issue_possible_ticket(
db,
Plate {
plate: PlateName(plate.clone()),
timestamp: Timestamp(timestamp),
},
CameraId(self.connection.get_address()),
)
.await;
if self.connection_type.is_some()
&& self.connection_type == Some(ConnectionType::Camera)
{
info!("Receive new plate: {plate} at {timestamp}");
issue_possible_ticket(
db,
Plate {
plate: PlateName(plate.clone()),
timestamp: Timestamp(timestamp),
},
CameraId(self.connection.get_address()),
)
.await;
} else {
let _ = send_message
.send(ServerFrames::Error {
msg: "Not connected as camera".to_string(),
})
.await;
return Err("Already connected".into());
}
}
ClientFrames::WantHeartbeat { interval } => {
if interval > 0 {
@ -204,7 +215,7 @@ impl Handler {
if self.connection_type.is_some() {
let _ = send_message
.send(ServerFrames::Error {
msg: "Already connected as camera".to_string(),
msg: "Already connected as a connection type".to_string(),
})
.await;
return Err("Already connected".into());
@ -224,7 +235,7 @@ impl Handler {
if self.connection_type.is_some() {
let _ = send_message
.send(ServerFrames::Error {
msg: "Already connected as dispatcher".to_string(),
msg: "Already connected as a connection type".to_string(),
})
.await;
return Err("Already connected".into());