L1NNA / SV1DUR

Planes-On-The-Bus-Go-Swish-Swish-Swish
3 stars 1 forks source link

ReadQueue #14

Closed JBanks closed 2 years ago

JBanks commented 2 years ago

This code will allow us to detect collisions on the bus. I tested with 0 and with 20_000 delay and it seems to be functioning correctly. Will test fully once the delays are added to the rest of the code. For now word_time will be set to 0 to allow testing with the current setup. This code is connected to issue: https://github.com/L1NNA/I-NEED-A-NAME/issues/7

JBanks commented 2 years ago

This is not as robust as I want it to be. I'll try to think of a way to make it handle more than 2 messages. The simplest way would be to flag the second message to not be processed, and then test the second message on a subsequent evaluation.

So we would have:

fn main() {
    let mut queue: Vec<(u128, u128, bool)> = Vec::new();
    let mut collision: bool;
    for (message_id, time) in [(1, 15), (2, 30), (3, 35), (4, 50), (5, 70), (6, 75), (7, 80)] {
        let elements = queue.len();
        if queue.len() > 0 && queue[elements - 1].0 > time - 15 {
            collision = true;
            queue[elements - 1].2 = true;
        } else {
            collision = false;
        }
        queue.push((time, message_id, collision));
    }
    for entry in queue {
        println!("Element: {:?}", entry);
    }
}