use std::collections::HashMap;
use crate::constants::INVALID_DOUBLE_VALUE;
#[derive(Debug, Clone, PartialEq)]
pub enum TraciValue {
Int(i32),
Double(f64),
String(String),
StringList(Vec<String>),
DoubleList(Vec<f64>),
Pos2D { x: f64, y: f64 },
Pos3D { x: f64, y: f64, z: f64 },
Color(TraciColor),
Polygon(Vec<TraciPosition>),
LogicList(Vec<TraciLogic>),
ConnectionList(Vec<Vec<TraciConnection>>),
Stage(TraciStage),
VehicleDataList(Vec<TraciVehicleData>),
NextTLSList(Vec<TraciNextTLSData>),
BestLanesList(Vec<TraciBestLanesData>),
Unknown { type_id: u8, raw: Vec<u8> },
}
pub type TraciResults = HashMap<u8, TraciValue>;
pub type SubscriptionResults = HashMap<String, TraciResults>;
pub type ContextSubscriptionResults = HashMap<String, SubscriptionResults>;
#[derive(Debug, Clone, PartialEq)]
pub struct TraciPosition {
pub x: f64,
pub y: f64,
pub z: f64,
}
impl TraciPosition {
pub fn new_2d(x: f64, y: f64) -> Self {
Self { x, y, z: INVALID_DOUBLE_VALUE }
}
pub fn new_3d(x: f64, y: f64, z: f64) -> Self {
Self { x, y, z }
}
pub fn is_3d(&self) -> bool {
self.z != INVALID_DOUBLE_VALUE
}
}
impl Default for TraciPosition {
fn default() -> Self {
Self { x: INVALID_DOUBLE_VALUE, y: INVALID_DOUBLE_VALUE, z: INVALID_DOUBLE_VALUE }
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciRoadPosition {
pub edge_id: String,
pub pos: f64,
pub lane_index: i32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TraciColor {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
impl TraciColor {
pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
Self { r, g, b, a }
}
}
impl Default for TraciColor {
fn default() -> Self {
Self { r: 0, g: 0, b: 0, a: 255 }
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciPhase {
pub duration: f64,
pub state: String,
pub min_dur: f64,
pub max_dur: f64,
pub next: Vec<i32>,
pub name: String,
}
impl Default for TraciPhase {
fn default() -> Self {
Self {
duration: INVALID_DOUBLE_VALUE,
state: String::new(),
min_dur: INVALID_DOUBLE_VALUE,
max_dur: INVALID_DOUBLE_VALUE,
next: Vec::new(),
name: String::new(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciLogic {
pub program_id: String,
pub type_: i32,
pub current_phase_index: i32,
pub phases: Vec<TraciPhase>,
pub sub_parameter: HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciConnection {
pub approached_lane: String,
pub has_prio: bool,
pub is_open: bool,
pub has_foe: bool,
pub approached_internal: String,
pub state: String,
pub direction: String,
pub length: f64,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciLink {
pub from_lane: String,
pub via_lane: String,
pub to_lane: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciVehicleData {
pub id: String,
pub length: f64,
pub entry_time: f64,
pub leave_time: f64,
pub type_id: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciNextTLSData {
pub id: String,
pub tl_index: i32,
pub dist: f64,
pub state: char,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciBestLanesData {
pub lane_id: String,
pub length: f64,
pub occupation: f64,
pub best_lane_offset: i32,
pub allows_continuation: bool,
pub continuation_lanes: Vec<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciStage {
pub type_: i32,
pub v_type: String,
pub line: String,
pub dest_stop: String,
pub edges: Vec<String>,
pub travel_time: f64,
pub cost: f64,
pub length: f64,
pub intended: String,
pub depart: f64,
pub depart_pos: f64,
pub arrival_pos: f64,
pub description: String,
}
impl Default for TraciStage {
fn default() -> Self {
Self {
type_: crate::constants::INVALID_INT_VALUE,
v_type: String::new(),
line: String::new(),
dest_stop: String::new(),
edges: Vec::new(),
travel_time: INVALID_DOUBLE_VALUE,
cost: INVALID_DOUBLE_VALUE,
length: INVALID_DOUBLE_VALUE,
intended: String::new(),
depart: INVALID_DOUBLE_VALUE,
depart_pos: INVALID_DOUBLE_VALUE,
arrival_pos: INVALID_DOUBLE_VALUE,
description: String::new(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciNextStopData {
pub lane: String,
pub start_pos: f64,
pub end_pos: f64,
pub stopping_place_id: String,
pub stop_flags: i32,
pub duration: f64,
pub until: f64,
pub intended_arrival: f64,
pub arrival: f64,
pub depart: f64,
pub split: String,
pub join: String,
pub act_type: String,
pub trip_id: String,
pub line: String,
pub speed: f64,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciReservation {
pub id: String,
pub persons: Vec<String>,
pub group: String,
pub from_edge: String,
pub to_edge: String,
pub depart_pos: f64,
pub arrival_pos: f64,
pub depart: f64,
pub reservation_time: f64,
pub state: i32,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciCollision {
pub collider: String,
pub victim: String,
pub collider_type: String,
pub victim_type: String,
pub collider_speed: f64,
pub victim_speed: f64,
pub type_: String,
pub lane: String,
pub pos: f64,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraciSignalConstraint {
pub signal_id: String,
pub trip_id: String,
pub foe_id: String,
pub foe_signal: String,
pub limit: i32,
pub type_: i32,
pub must_wait: bool,
pub active: bool,
pub param: HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SubscribedKinematics {
pub position: TraciPosition,
pub speed: f64,
pub acceleration: f64,
pub angle: f64,
}