Compare commits
16 Commits
40f8c46d80
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| dde33ca5c3 | |||
| d12b4da065 | |||
| 3992a77c78 | |||
| 512b683d55 | |||
| fc74dc5d9b | |||
| edaac93dfd | |||
| 1b2862dea5 | |||
| 6b70140869 | |||
| 23b1863a82 | |||
| b7894ea559 | |||
| f84022b8cf | |||
| 559a314dbe | |||
| b60520009f | |||
| 618c4ff2fe | |||
| a2ccb9b761 | |||
| 8496cfd72f |
@@ -1,3 +1,4 @@
|
||||
/target
|
||||
/.vscode
|
||||
/libs
|
||||
Cargo.lock
|
||||
|
||||
+9
-14
@@ -8,10 +8,14 @@ host = "x86_64-unknown-linux-gnu"
|
||||
chrono = "0.4"
|
||||
csv = "1.4"
|
||||
gtfs-structures = "0.47"
|
||||
gtfs-realtime = "0.2"
|
||||
log = "0.4"
|
||||
prost = "0.14"
|
||||
prost-types = "0.14"
|
||||
reqwest = { version = "0.11", features = ["blocking"] }
|
||||
sdl3 = {version = "0.17", features = ["ttf"]}
|
||||
serde = { version = "1.0", features = ["derive"]}
|
||||
serde_json = "1.0"
|
||||
time-format = "1.2"
|
||||
yaml_serde = "0.10"
|
||||
zip = "8.3"
|
||||
@@ -22,17 +26,8 @@ opt-level = 1
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
|
||||
[target.aarch64-unknown-linux-gnu]
|
||||
cc = "aarch64-linux-gnu-gcc"
|
||||
cxx = "aarch64-linux-gnu-g++"
|
||||
ar = "aarch64-linux-gnu-ar"
|
||||
# ranlib = "aarch64-linux-gnu-ranlib"
|
||||
linker = "aarch64-linux-gnu-gcc"
|
||||
|
||||
|
||||
[target.arm-unknown-linux-gnueabihf]
|
||||
cc = "arm-linux-gnueabihf-gcc"
|
||||
cxx = "arm-linux-gnueabihf-g++"
|
||||
ar = "arm-linux-gnueabihf-ar"
|
||||
# ranlib = "arm-linux-gnueabihf-ranlib"
|
||||
linker = "arm-linux-gnueabihf-gcc"
|
||||
[package.metadata.appimage]
|
||||
assets = ["resources"]
|
||||
icon = "resources/icon.png"
|
||||
desktop_entry = "other/rs-dublinbus.desktop"
|
||||
auto-link=true
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
# The deployment process works like this:
|
||||
# 1. Build locally just to make sure that things work
|
||||
# 2. SSH into the machine that will build the AppImage for ARM. There:
|
||||
# 2.1. run git pull to get the latest version of the code
|
||||
# 2.2. run argo appimage to build the image
|
||||
# 3. SCP the appimage back to the local machine
|
||||
# 4. SCP the files to the Raspberry Pi running the display:
|
||||
# AppImage
|
||||
# systemd service file
|
||||
# 5. SSH into the display machine as root and:
|
||||
# 5.1. Copy the AppImage file to /opt/dublinbus-display (create the directory if necessary)
|
||||
# 5.2. If the service exists, restart it and exit
|
||||
# 5.3. Copy the service file to /etc/systemd/system
|
||||
# 5.4. Enable and activate the service
|
||||
|
||||
|
||||
|
||||
# Variables
|
||||
GIT_REPO_URL="http://git.nahuellofeudo.com/nahuel/rs-dublinbus.git"
|
||||
|
||||
# For the build machine
|
||||
BUILD_MACHINE_NAME=raspi-ssd.localnet
|
||||
BUILD_MACHINE_USER=nahuel
|
||||
BUILD_MACHINE_SOURCE_DIRECTORY=/home/nahuel/Documents/sources
|
||||
|
||||
DEPLOY_MACHINE_NAME=dublinbus-display.local
|
||||
DEPLOY_MACHINE_USER=display
|
||||
DEPLOY_MACHINE_TARGET_DIRECTORY=/opt/dublinbus
|
||||
|
||||
|
||||
# 1. Build locally
|
||||
cargo appimage
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo
|
||||
echo
|
||||
echo "-------------------------------------------------------"
|
||||
echo "\"cargo appimage\" failed. Check the logs"
|
||||
echo "-------------------------------------------------------"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "-------------------------------------------------------"
|
||||
echo "Local build successful "
|
||||
echo "-------------------------------------------------------"
|
||||
|
||||
|
||||
# 2. Build remotely on the ARM machine
|
||||
ssh $BUILD_MACHINE_USER@$BUILD_MACHINE_NAME << EOF
|
||||
echo Entering ${BUILD_MACHINE_SOURCE_DIRECTORY}
|
||||
cd ${BUILD_MACHINE_SOURCE_DIRECTORY}
|
||||
if [[ ! -d rs-dublinbus ]]; then
|
||||
git clone ${GIT_REPO_URL}
|
||||
cd rs-dublinbus
|
||||
else
|
||||
cd rs-dublinbus
|
||||
git reset --hard
|
||||
git pull
|
||||
fi
|
||||
|
||||
cargo appimage
|
||||
EOF
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo
|
||||
echo
|
||||
echo "-------------------------------------------------------"
|
||||
echo "Remote build failed. Check the logs"
|
||||
echo "-------------------------------------------------------"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "-------------------------------------------------------"
|
||||
echo "Remote build successful "
|
||||
echo "-------------------------------------------------------"
|
||||
|
||||
# 3. SCP the appimage back to the local machine
|
||||
scp $BUILD_MACHINE_USER@$BUILD_MACHINE_NAME:Documents/sources/rs-dublinbus/target/appimage/rs-dublinbus.AppImage /tmp
|
||||
|
||||
# 4. SCP the files to the Raspberry Pi running the display:
|
||||
scp /tmp/rs-dublinbus.AppImage $DEPLOY_MACHINE_USER@$DEPLOY_MACHINE_NAME:$DEPLOY_MACHINE_TARGET_DIRECTORY
|
||||
|
||||
# Set up the service
|
||||
ssh $DEPLOY_MACHINE_USER@$DEPLOY_MACHINE_NAME << EOF
|
||||
sudo systemctl restart dublinbus
|
||||
EOF
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "-------------------------------------------------------"
|
||||
echo "Service deployed and restarted "
|
||||
echo "-------------------------------------------------------"
|
||||
@@ -3,6 +3,17 @@
|
||||
- LCD Rounded font by Jecko Development (http://www.jeckodevelopment.com)
|
||||
|
||||
|
||||
## Dependencies (Debian/Raspberry Pi OS)
|
||||
|
||||
* librust-openssl-dev
|
||||
* protobuf-compiler
|
||||
* libsdl3-dev
|
||||
* libsdl3-ttf-dev
|
||||
|
||||
## Install appimage package
|
||||
```
|
||||
cargo install cargo-appimage
|
||||
```
|
||||
|
||||
## Install ARM toolchains:
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=Start Dublin Bus display
|
||||
After=multi-user.target
|
||||
Wants=multi-user.target
|
||||
|
||||
[Service]
|
||||
Restart=always
|
||||
Type=exec
|
||||
WorkingDirectory=/opt/dublinbus
|
||||
ExecStart=/opt/dublinbus/rs-dublinbus.AppImage
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,7 +1,7 @@
|
||||
screen:
|
||||
width: 1920
|
||||
height: 720
|
||||
font-path: "resources/jd_lcd_rounded/jd-lcd-rounded.ttf"
|
||||
font-path: "resources/jd-lcd-rounded.ttf"
|
||||
|
||||
gtfs:
|
||||
routes:
|
||||
@@ -11,8 +11,8 @@ gtfs:
|
||||
stops:
|
||||
- 1114
|
||||
- 2410
|
||||
data-folder: "/home/nahuel/Downloads"
|
||||
data-folder: "/tmp"
|
||||
gtfs-url: "https://www.transportforireland.ie/transitData/Data/GTFS_Realtime.zip"
|
||||
realtime-url: "https://api.nationaltransport.ie/gtfsr/v2/gtfsr"
|
||||
realtime-api-key: "Not defined"
|
||||
realtime-api-key: "aa8509902455412e886b9df11f0e21ec"
|
||||
refresh-seconds: 61
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@@ -1,14 +0,0 @@
|
||||
JECKO DEVELOPMENT FONT
|
||||
|
||||
This font was created by Jecko Development (http://www.jeckodevelopment.com)
|
||||
This font has a homepage where this archive and other versions may be found ::
|
||||
http://www.jeckodevelopment.com/fonts/
|
||||
This font is released under a Creative Commons Attribution Non-commercial No Derivatives
|
||||
license (http://creativecommons.org/licenses/by-nc-nd/3.0/).
|
||||
NOTE FOR FLASH USERS: This font is optimized for
|
||||
Flash. If the font in this archive is a pixel font, it is best displayed at a
|
||||
font-size of 64.
|
||||
|
||||
Feel free to write us at info@jeckodevelopment.com or visit our website http://www.jeckodevelopment.com
|
||||
|
||||
|
||||
+14
-3
@@ -5,7 +5,7 @@ mod refresher;
|
||||
mod realtime;
|
||||
pub mod structs;
|
||||
use chrono::{DateTime, Local, Timelike};
|
||||
use log::{debug, trace};
|
||||
use log::{debug, trace, warn};
|
||||
use std::{collections::{HashMap, HashSet}, fs::File };
|
||||
use gtfs_structures::{Exception, RawTrip};
|
||||
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences, Error}};
|
||||
@@ -18,12 +18,14 @@ impl Gtfs<'_> {
|
||||
let target_date = naive_target.date();
|
||||
|
||||
// Find which calendars apply
|
||||
debug!("Looking for calendars that apply to date {:#?}", target_date);
|
||||
let mut active_service_ids: HashSet<String> = HashSet::new();
|
||||
for (id, calendar) in self.calendar.iter() {
|
||||
if calendar.valid_weekday(target_date)
|
||||
&& calendar.start_date <= target_date
|
||||
&& calendar.end_date > target_date {
|
||||
active_service_ids.insert(id.to_string());
|
||||
debug!("Matched calendar: {:#?}", calendar);
|
||||
}
|
||||
}
|
||||
debug!("Found {} services active today", active_service_ids.len());
|
||||
@@ -43,7 +45,7 @@ impl Gtfs<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
debug!("After exceptions, there are now {} services active", active_service_ids.len());
|
||||
debug!("After exceptions, there are now {} services active: {:#?}", active_service_ids.len(), active_service_ids);
|
||||
|
||||
// Find the trips happening on these calendars
|
||||
let mut trips: HashMap<&String, &RawTrip> = HashMap::new();
|
||||
@@ -82,15 +84,24 @@ impl Gtfs<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arrivals.sort();
|
||||
|
||||
debug!("Found {} arrivals", arrivals.len());
|
||||
|
||||
// Update real-time deltas
|
||||
|
||||
let realtime_result = self.realtime_update(&mut arrivals);
|
||||
if realtime_result.is_err() {
|
||||
warn!("Unable to update realtime arrivals: {:#?}", realtime_result.err().unwrap()._message)
|
||||
}
|
||||
|
||||
return Some(arrivals);
|
||||
}
|
||||
|
||||
|
||||
/// Load a GTFS structure from a zip file
|
||||
pub fn load(prefs: &Preferences) -> Result<Gtfs, Error> {
|
||||
pub fn load(prefs: &Preferences) -> Result<Gtfs<'_>, Error> {
|
||||
|
||||
_ = refresher::refresh(prefs);
|
||||
|
||||
|
||||
+61
-13
@@ -1,15 +1,14 @@
|
||||
use log::debug;
|
||||
/***
|
||||
* Implementation of GTFS-R polling
|
||||
*/
|
||||
use reqwest::{StatusCode, blocking::Client};
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use std::{str::FromStr, time::Duration};
|
||||
|
||||
use reqwest::{blocking::Client, header::{HeaderName, HeaderValue}};
|
||||
|
||||
use crate::gtfs::structs::{Arrival, Error, Gtfs};
|
||||
use crate::gtfs::{self, structs::{Arrival, Error, Gtfs}};
|
||||
|
||||
impl Gtfs<'_> {
|
||||
fn realtime_update (&self, arrivals: Vec<Arrival<'_>>) -> Result<bool, Error>{
|
||||
pub(crate) fn realtime_update (&self, arrivals: &mut Vec<Arrival<'_>>) -> Result<(), gtfs::structs::Error>{
|
||||
|
||||
// Poll GTFS-R API
|
||||
let client = Client::builder()
|
||||
@@ -17,20 +16,69 @@ impl Gtfs<'_> {
|
||||
.connect_timeout(Duration::from_secs(5))
|
||||
.build()?;
|
||||
|
||||
let mut response = client
|
||||
.get(self.preferences.realtime_url)
|
||||
.header("x-api-key", self.preferences.realtime_api_key)
|
||||
let response = client
|
||||
.get(&self.preferences.realtime_url)
|
||||
.header("x-api-key", &self.preferences.realtime_api_key)
|
||||
.send()?;
|
||||
|
||||
if response.status() != StatusCode::OK {
|
||||
return Err(Error {
|
||||
_message : format!("HTTP Respomse: {:#?}. Payload: \n{:#?}\n", response.status(), response.text().unwrap())
|
||||
})
|
||||
}
|
||||
|
||||
// Parse response
|
||||
let response = json::rdr
|
||||
let response_bytes= response.bytes()?;
|
||||
let data: Result<gtfs_realtime::FeedMessage, prost::DecodeError> = prost::Message::decode(response_bytes.as_ref());
|
||||
if data.is_err() {
|
||||
return Err(Error {
|
||||
_message : format! ("Error loading realtime prtobuf: {:#?}", data.err().unwrap())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// Build a map of (trip, stop) -> Arrival for faster lookup
|
||||
let mut lookup: HashMap<(String, String), usize> = HashMap::new();
|
||||
let num_arrivals = arrivals.len();
|
||||
for i in 0..num_arrivals {
|
||||
let arrival = arrivals.get(i).unwrap();
|
||||
lookup.insert((arrival.trip.id.clone(), arrival.stop.id.clone()), i);
|
||||
}
|
||||
|
||||
// Match deltas to existing arrivals
|
||||
let entities = data.unwrap().entity;
|
||||
debug!("Loaded {} entities from realtime update.", entities.len());
|
||||
for entity in entities {
|
||||
if entity.trip_update.is_some() && entity.stop.is_some() {
|
||||
let trip_update = entity.trip_update.unwrap();
|
||||
|
||||
// Look up the entry in arrivals for the current
|
||||
for stop_update in trip_update.stop_time_update {
|
||||
if stop_update.stop_id.is_none() {
|
||||
continue;
|
||||
}
|
||||
let trip_id = trip_update.trip.trip_id.clone().unwrap();
|
||||
let stop_id = stop_update.stop_id.unwrap();
|
||||
let key = (trip_id, stop_id);
|
||||
if lookup.contains_key(&key) {
|
||||
|
||||
// Update the arrival time
|
||||
let arrival_index = lookup.get(&key);
|
||||
let arrival: &mut Arrival<'_> = arrivals.get_mut(*arrival_index.unwrap()).unwrap();
|
||||
if let Some(update) = stop_update.departure.or(stop_update.arrival) {
|
||||
let new_time = (((arrival.departure_time as i64)
|
||||
+ (update.delay.unwrap_or(0) as i64))) as u32;
|
||||
debug!("Updated arrival time of {:#?} by {}s", &key, update.delay.unwrap());
|
||||
arrival.departure_time = new_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the arrival times
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -28,6 +28,12 @@ impl From<ZipError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for Error {
|
||||
fn from(value: serde_json::Error) -> Self {
|
||||
return Error { _message: value.to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This is to store the preferences for the GTFS(-R) side of the code.
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
|
||||
+14
-6
@@ -1,10 +1,10 @@
|
||||
mod gtfs;
|
||||
mod renderer;
|
||||
mod config;
|
||||
use std::{ops::Add, process, thread::Builder, time::SystemTime};
|
||||
use std::{env, ops::Add, process, thread::Builder, time::SystemTime};
|
||||
use chrono::{DateTime, Duration, Local, NaiveTime};
|
||||
use log::{Level, Metadata, Record, error, info};
|
||||
use sdl3::event::Event;
|
||||
use log::{Metadata, Record, error, info};
|
||||
use sdl3::{event::Event};
|
||||
use crate::{config::load_config, gtfs::structs::{Arrival, Gtfs}, renderer::structs::{DisplayData, DisplayEntry, Screen}};
|
||||
|
||||
const NUM_ARRIVALS: usize = 4;
|
||||
@@ -54,12 +54,15 @@ fn refresh_schedule<'a>(gtfs: &'a Gtfs, screen : &mut Screen<'a>) -> Option<Vec<
|
||||
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
// Initialize logger
|
||||
static MY_LOGGER: MyLogger = MyLogger;
|
||||
|
||||
struct MyLogger;
|
||||
impl log::Log for MyLogger {
|
||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||
return metadata.level() < Level::Trace;
|
||||
fn enabled(&self, _metadata: &Metadata) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
@@ -76,7 +79,12 @@ fn main() {
|
||||
print!("Error setting up the main logger:{:#?}", logger.err());
|
||||
process::exit(-1);
|
||||
}
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
|
||||
if args.contains(&String::from("--debug")) {
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
} else {
|
||||
log::set_max_level(log::LevelFilter::Warn);
|
||||
}
|
||||
|
||||
|
||||
let config_result = load_config(String::from("resources/dublinbus.yaml"));
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ const TEXT_SIZE: f32 = 160.0; // Size of the font in pixels
|
||||
// Offsets of each part within a line
|
||||
const XOFFSET_ROUTE: u32 = 24;
|
||||
const XOFFSET_DESTINATION: u32 = 300;
|
||||
const XOFFSEET_TIME_LEFT: u32 = 1606;
|
||||
const XOFFSEET_TIME_LEFT: u32 = 1560;
|
||||
const INTER_LINE_OVERLAP: u32 = 15;
|
||||
|
||||
impl Screen<'_> {
|
||||
@@ -36,10 +36,10 @@ impl Screen<'_> {
|
||||
fn format_due_for(&self, due_in_mins: i32, departure_time: u32) -> String {
|
||||
trace!("Due in mins: {:02}", due_in_mins);
|
||||
if due_in_mins <= 1 {
|
||||
return String::from("due");
|
||||
return String::from("Due");
|
||||
}
|
||||
if due_in_mins < 60 {
|
||||
return due_in_mins.to_string() + "min";
|
||||
return due_in_mins.to_string() + " min";
|
||||
}
|
||||
return format!("{:02}:{:02}", (departure_time / 3600) as i32, ((departure_time / 60) % 60) as i32);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ impl Screen<'_> {
|
||||
self.do_print_at(5, display_data.status.as_ref().unwrap(), 0);
|
||||
} else {
|
||||
// Display date and time otherwise
|
||||
self.do_print_at(5, &format!("Current time: {:02}/{:02}/{:4} {:02}:{:02}",
|
||||
self.do_print_at(5, &format!(" Current time: {:02}/{:02}/{:4} {:02}:{:02}",
|
||||
local_time.day(), local_time.month(), local_time.year(),
|
||||
local_time.hour(), local_time.minute()
|
||||
).to_string(), 0);
|
||||
|
||||
Reference in New Issue
Block a user