#[doc(hidden)]
pub mod elev;
pub mod poll;
use crate::print;
use crate::config;
use serde::{Serialize, Deserialize};
use std::hash::{Hash, Hasher};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ElevMsgType
{
CALLBTN,
FLOORSENS,
STOPBTN,
OBSTRX,
}
#[derive(Debug, Clone)]
pub struct ElevMessage
{
pub msg_type: ElevMsgType,
pub call_button: Option<CallButton>,
pub floor_sensor: Option<u8>,
pub stop_button: Option<bool>,
pub obstruction: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)] #[allow(non_camel_case_types)]
pub enum CallType
{
UP = 0,
DOWN = 1,
INSIDE = 2,
COSMIC_ERROR = 255,
}
impl From<u8> for CallType
{
fn from(
value: u8
) -> Self
{
match value
{
0 => CallType::UP,
1 => CallType::DOWN,
2 => CallType::INSIDE,
_ => {
print::cosmic_err("Call type does not exist".to_string());
CallType::COSMIC_ERROR
},
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Eq)]
pub struct CallButton
{
pub floor: u8,
pub call_type: CallType,
pub elev_id: u8,
}
impl Default for CallButton
{
fn default() -> Self
{
CallButton{floor: 1, call_type: CallType::INSIDE, elev_id: config::ERROR_ID}
}
}
impl PartialEq for CallButton
{
fn eq(&self, other: &Self) -> bool
{
if self.call_type == CallType::INSIDE
{
self.floor == other.floor && self.call_type == other.call_type && self.elev_id == other.elev_id
} else
{
self.floor == other.floor && self.call_type == other.call_type
}
}
}
impl Hash for CallButton
{
fn hash<H: Hasher>(&self, state: &mut H)
{
self.floor.hash(state);
self.call_type.hash(state);
if self.call_type == CallType::INSIDE
{
self.elev_id.hash(state);
}
}
}