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}; use crate::frame::{self, ClientFrames, ServerFrames};
#[derive(PartialEq)]
pub(crate) enum ConnectionType { pub(crate) enum ConnectionType {
Camera, Camera,
Dispatcher, Dispatcher,

View file

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