diff --git a/CHANGELOG.md b/CHANGELOG.md index 79a63ad..637ef2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.9.2] - 2019-10-28 +### Fixed +- In some cases stations stopped transmitting every ~0.5 secs should be fixed +- Restore consistent ~3sec pause between reports + ## [0.9.1] - 2019-10-14 ### Fixed - Do not SPAM logs when connection to SRS is lost #18 diff --git a/datis/Cargo.toml b/datis/Cargo.toml index 683e2c3..f59c522 100644 --- a/datis/Cargo.toml +++ b/datis/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "datis" -version = "0.9.1" +version = "0.9.2" authors = ["Markus Ast "] edition = "2018" diff --git a/datis/src/srs.rs b/datis/src/srs.rs index a090e97..f6de309 100644 --- a/datis/src/srs.rs +++ b/datis/src/srs.rs @@ -260,19 +260,30 @@ fn audio_broadcast( data.set_position(0); let start = Instant::now(); - let mut size = 0; let mut audio = PacketReader::new(data); let mut id: u64 = 1; while let Some(pck) = audio.read_packet()? { - let pck_size = pck.data.len(); - if pck_size == 0 { + if pck.data.len() == 0 { continue; } - size += pck_size; let frame = pack_frame(&sguid, id, station.atis_freq, &pck.data)?; stream.write_all(&frame)?; + + // wait for the current ~playtime before sending the next package + let playtime = Duration::from_millis(id * 20); + let elapsed = start.elapsed(); + if playtime > elapsed { + thread::sleep(playtime - elapsed); + } + id += 1; + if ctx.should_stop() { + return Ok(false); + } + } + + 'recv: loop { // check whether the TCP connection is still alive (by trying to read and it and expect it to time out) match io::copy(&mut stream, &mut sink) { Ok(bytes_read) if bytes_read == 0 => { @@ -281,34 +292,18 @@ fn audio_broadcast( return Ok(true); } Err(err) => match err.kind() { - io::ErrorKind::TimedOut => {} + io::ErrorKind::TimedOut => { + break 'recv; + } _ => { return Err(err.into()); } }, _ => {} } - - // wait for the current ~playtime before sending the next package - let secs = (size * 8) as f64 / 1024.0 / 32.0; // 32 kBit/s - let playtime = Duration::from_millis((secs * 1000.0) as u64); - let elapsed = start.elapsed(); - if playtime > elapsed { - thread::sleep(playtime - elapsed); - } - - if ctx.should_stop() { - return Ok(false); - } } - debug!("TOTAL SIZE: {}", size); - - // 32 kBit/s - let secs = (size * 8) as f64 / 1024.0 / 32.0; - debug!("SECONDS: {}", secs); - - let playtime = Duration::from_millis((secs * 1000.0) as u64); + let playtime = Duration::from_millis(id * 20); let elapsed = Instant::now() - start; if playtime > elapsed { thread::sleep(playtime - elapsed); diff --git a/mod/Mods/tech/DATIS/entry.lua b/mod/Mods/tech/DATIS/entry.lua index a1e6778..72cca7f 100644 --- a/mod/Mods/tech/DATIS/entry.lua +++ b/mod/Mods/tech/DATIS/entry.lua @@ -5,7 +5,7 @@ declare_plugin("DATIS", { "datis.dll", }, - version = "0.3.0", + version = "0.9.2", state = "installed", developerName = "github.com/rkusa",