Skip to content

Commit

Permalink
expand domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Donald Ball committed Jan 26, 2023
1 parent e205e00 commit d0ad9e4
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 33 deletions.
2 changes: 1 addition & 1 deletion rust/speed/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use crate::message::Message;
use crate::domain::Message;

use tokio::{
io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter},
Expand Down
93 changes: 93 additions & 0 deletions rust/speed/src/domain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use std::collections::BTreeSet;

// Messages are sent between clients and the server.
//
// The server expects a client to identify its type.
//
// server: {IAmCamera: [Plate]*, IAmDispatcher: []} with one WantHeartbeat allowed at any point
// camera clients expect only heartbeats, dispatchers also expect tickets.
//
// TODO how can we statically encode the code on the struct cases?
// TODO if we did, would that affect the dispatch speed in reads, writes, etc.?
// TODO how can we encode the direction, and/or the state sequence constraints on the message types
// TODO how can we construct de/serialization code for these declaratively?
pub enum Message {
// server -> client
Error {
msg: String,
},
Plate {
plate: String,
timestamp: Timestamp,
},
Ticket {
plate: String,
road: Road,
mile1: Mile,
timestamp1: Timestamp,
mile2: Mile,
timestamp2: Timestamp,
speed: Speed,
},
WantHeartbeat {
interval: Deciseconds,
},
Heartbeat,
IAmCamera {
road: Road,
mile: Mile,
limit: Speed,
},
IAmDispatcher {
// Note this is redundant with roads.len(), just a serialization artifact.
// Do we keep it in the struct or compute it at serialization?
numroads: u8,
roads: Vec<Road>,
},
}

pub type Timestamp = u32;

pub type Road = u16;

pub type Mile = u16;

pub type Speed = u16;

pub type Deciseconds = u32;

pub type Plate = String;

pub struct Camera {
road: Road,
mile: Mile,
limit: Speed,
}

pub struct Dispatcher {
roads: BTreeSet<Road>,
}

pub struct Ticket {
plate: Plate,
road: Road,
mile1: Mile,
timestamp1: Timestamp,
mile2: Mile,
timestamp2: Timestamp,
speed: Speed,
}

pub struct Region {
// cameras, dispatchers, tickets
}

impl Region {
// records an observation of a plate by a camera
pub fn record_plate(camera: Camera, plate: Plate) {}

// returns a ticket to dispatch, if there is any. Tickets are issued only once.
pub fn issue_ticket() -> Option<(Ticket, Dispatcher)> {
None
}
}
2 changes: 1 addition & 1 deletion rust/speed/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod connection;
pub mod message;
pub mod domain;

#[tokio::main]
async fn main() {
Expand Down
31 changes: 0 additions & 31 deletions rust/speed/src/message.rs

This file was deleted.

0 comments on commit d0ad9e4

Please sign in to comment.