Skip to content

Commit

Permalink
Implement queue size display (close #67)
Browse files Browse the repository at this point in the history
  • Loading branch information
7h0ma5 committed May 26, 2017
1 parent b9e580c commit dcf6d44
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/frontend/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ <h3>Status</h3>
<div class="status" v-bind:class="{ 'connected': status.connected }">
Connected
</div>
<div class="status" v-bind:class="{ 'active': status.queue > 0, 'critical': status.queue > 30 }">
Queue: {{status.queue}}
</div>
<div class="timeslots">
<span v-for="(timeslot, index) in status.timeslots">
<div class="timeslot" v-bind:class="{ 'enabled': timeslot, 'active': index == status.timeslot}">
Expand Down
16 changes: 14 additions & 2 deletions src/frontend/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,30 @@ button.red:active { background-color: ##B71C1C; }
padding: 3px 5px;
}

.on-air {
.status.on-air {
border-color: #F44336;
background-color: #F44336;
color: #fff;
}

.connected {
.status.connected {
border-color: #4CAF50;
background-color: #4CAF50;
color: #fff;
}

.status.active {
border-color: #2196F3;
background-color: #2196F3;
color: #fff;
}

.status.critical {
border-color: #FFC107;
background-color: #FFC107;
color: #fff;
}

@keyframes active_timeslot {
0% {opacity: 1.0;}
50% {opacity: 0.5;}
Expand Down
12 changes: 9 additions & 3 deletions src/pocsag/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ impl SchedulerCore {
}
}

status!(queue: self.queue.len() + 1);

if self.slots.is_current_allowed() { /* transmit immediately */ }
else if let Some(next_slot) = self.slots.next_allowed() {
let mut duration = next_slot.duration_until();

info!("Waiting {} seconds until {:?}...",
duration.as_secs(), next_slot);
debug!("Waiting {} seconds until {:?}...",
duration.as_secs(), next_slot);

// Process other commands while waiting for the time slot
'waiting: while !next_slot.active() {
Expand All @@ -107,6 +109,7 @@ impl SchedulerCore {
match self.rx.recv_timeout(duration) {
Ok(Command::Message(msg)) => {
self.queue.push_back(msg);
status!(queue: self.queue.len() + 1);
},
Ok(Command::SetTimeSlots(slots)) => {
self.slots = slots;
Expand All @@ -121,6 +124,7 @@ impl SchedulerCore {
warn!("No allowed time slots! Sending anyway...");
}

status!(queue: self.queue.len());
status!(transmitting: true);
transmitter.send(&mut Generator::new(self, message.unwrap()));
status!(transmitting: false);
Expand Down Expand Up @@ -160,6 +164,8 @@ impl MessageProvider for SchedulerCore {
};
}

self.queue.pop_front()
let message = self.queue.pop_front();
status!(queue: self.queue.len());
message
}
}
6 changes: 4 additions & 2 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pub struct Status {
pub connected: bool,
pub transmitting: bool,
pub timeslots: TimeSlots,
pub timeslot: TimeSlot
pub timeslot: TimeSlot,
pub queue: usize
}

impl Status {
Expand All @@ -21,7 +22,8 @@ impl Status {
connected: false,
transmitting: false,
timeslots: TimeSlots::new(),
timeslot: TimeSlot::current()
timeslot: TimeSlot::current(),
queue: 0
}
}
}
Expand Down

0 comments on commit dcf6d44

Please sign in to comment.