Skip to content

Commit

Permalink
Implement server-side TimeSlot calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
7h0ma5 committed Mar 24, 2017
1 parent cadaf63 commit 3b063b2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/frontend/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ <h3>Status</h3>
</div>
<div class="timeslots">
<span v-for="(timeslot, index) in status.timeslots">
<div class="timeslot" v-bind:class="{ 'enabled': timeslot, 'active': index == activeTimeslot}">
<div class="timeslot" v-bind:class="{ 'enabled': timeslot, 'active': index == status.timeslot}">
{{index.toString(16).toUpperCase()}}
</div>
</span>
Expand Down
9 changes: 0 additions & 9 deletions src/frontend/assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var vm = new Vue({
el: "#wrapper",
created() {
this.connect();
this.update_timeslot();
},
data: {
connected: false,
Expand All @@ -17,7 +16,6 @@ var vm = new Vue({
raspager: {}
},
status: {},
activeTimeslot: 0,
message: "",
addr: localStorage ? (localStorage.pager_addr || 0) : 0
},
Expand Down Expand Up @@ -102,13 +100,6 @@ var vm = new Vue({

this.send(req);
this.message = "";
},
update_timeslot: function(event) {
var date = Date.now();
var timeslot = (Math.floor(date / 100) / 64) & 0b1111;
var next_timeslot = (((Math.floor(date / 100) / 64) + 1) * 64) * 100;
this.activeTimeslot = timeslot;
setTimeout(this.update_timeslot, next_timeslot - date);
}
}
});
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ fn main() {
let mut config = Config::load();
let scheduler = Scheduler::new(&config);

thread::spawn(timeslot_updater);

let mut restart = true;
while restart {
let (stop_conn, conn_thread) = Connection::start(config.clone(), scheduler.clone());
Expand Down Expand Up @@ -125,3 +127,11 @@ fn main() {
info!("Terminating... 73!");
thread::sleep(time::Duration::from_millis(1000));
}

pub fn timeslot_updater() {
loop {
let timeslot = pocsag::TimeSlot::current();
status!(timeslot: timeslot);
thread::sleep(timeslot.next().duration_until());
}
}
2 changes: 1 addition & 1 deletion src/pocsag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod encoding;
pub use self::generator::Generator;
pub use self::message::{Message, MessageSpeed, MessageType, MessageFunc};
pub use self::scheduler::Scheduler;
pub use self::timeslots::TimeSlots;
pub use self::timeslots::{TimeSlots, TimeSlot};
pub use self::encoding::Encoding;

pub trait MessageProvider {
Expand Down
6 changes: 5 additions & 1 deletion src/pocsag/timeslots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn deciseconds(duration: Duration) -> u64 {
seconds * 10 + deciseconds
}

#[derive(PartialEq)]
#[derive(Serialize, Clone, Copy, PartialEq)]
pub struct TimeSlot(usize);

impl TimeSlot {
Expand All @@ -29,6 +29,10 @@ impl TimeSlot {
*self == TimeSlot::current()
}

pub fn next(&self) -> TimeSlot {
TimeSlot((self.0 + 1) % 16)
}

pub fn duration_until(&self) -> Duration {
let now = unix_time();
let now_decis = deciseconds(now);
Expand Down
8 changes: 5 additions & 3 deletions src/status.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::{Mutex, RwLock};
use pocsag::TimeSlots;
use pocsag::{TimeSlots, TimeSlot};
use frontend::Responder;

lazy_static! {
Expand All @@ -11,15 +11,17 @@ lazy_static! {
pub struct Status {
pub connected: bool,
pub transmitting: bool,
pub timeslots: TimeSlots
pub timeslots: TimeSlots,
pub timeslot: TimeSlot
}

impl Status {
pub fn new() -> Status {
Status {
connected: false,
transmitting: false,
timeslots: TimeSlots::new()
timeslots: TimeSlots::new(),
timeslot: TimeSlot::current()
}
}
}
Expand Down

2 comments on commit 3b063b2

@dh3wr
Copy link
Member

@dh3wr dh3wr commented on 3b063b2 Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Machst du dazu auch eine neue Release?

@7h0ma5
Copy link
Member Author

@7h0ma5 7h0ma5 commented on 3b063b2 Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im Debian-Repo ist dieser Commit schon seit drei Tagen drin, aber noch unter der Version 0.5.0. Ich habe jetzt mal die 0.5.1 released, die ist jetzt auch fertig kompiliert im Repository.

Please sign in to comment.