From 5f26622adf6be4cc3bd8b4f653fedcec064924e8 Mon Sep 17 00:00:00 2001 From: Empire Date: Fri, 22 Sep 2023 21:30:55 +0200 Subject: [PATCH 01/14] add temperature display --- client/bin/src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 1fa2072..4692bb8 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -131,6 +131,7 @@ fn render_weather(display: &mut UdpDisplay ,data: &Option { + let mut temp:&f64 = &-1_f64; if !result.list.is_empty() { let mut max:f64 = 0_f64; let mut best = &result.list[0]; @@ -148,6 +149,9 @@ fn render_weather(display: &mut UdpDisplay ,data: &Option { let rain_v = x.three_hours; @@ -159,7 +163,6 @@ fn render_weather(display: &mut UdpDisplay ,data: &Option println!("No rain at {hour}:{minute}"), } - } @@ -168,7 +171,14 @@ fn render_weather(display: &mut UdpDisplay ,data: &Option Date: Fri, 22 Sep 2023 21:47:59 +0200 Subject: [PATCH 02/14] code style --- client/bin/Cargo.toml | 2 +- client/bin/src/main.rs | 52 ++++++++++----------- client/bin/src/straba.rs | 77 +++++++++++++++----------------- client/openweathermap/src/lib.rs | 0 4 files changed, 60 insertions(+), 71 deletions(-) mode change 100755 => 100644 client/openweathermap/src/lib.rs diff --git a/client/bin/Cargo.toml b/client/bin/Cargo.toml index 4f141b1..d3473c8 100644 --- a/client/bin/Cargo.toml +++ b/client/bin/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "LEDboardClient" +name = "ledboard_client" version = "0.1.0" edition = "2021" diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 4692bb8..10ce554 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -12,7 +12,6 @@ use embedded_graphics::{ mono_font::{iso_8859_1::FONT_6X10, iso_8859_1::FONT_5X8, MonoTextStyle}, pixelcolor::BinaryColor, prelude::*, - primitives::PrimitiveStyle, text::Text, }; @@ -22,7 +21,6 @@ use std::io; use openweathermap::forecast::Forecast; use straba::NextDeparture; -use ping; // This declaration will look for a file named `straba.rs` and will // insert its contents inside a module named `straba` under this scope mod straba; @@ -36,10 +34,6 @@ const IMAGE_HEIGHT_BYTE: u32 = 40; const IMAGE_LENGTH: usize = (IMAGE_WIDTH_BYTE * IMAGE_HEIGHT_BYTE) as usize; const PACKAGE_LENGTH: usize = (IMAGE_LENGTH + 1) as usize; -const PRIMITIVE_STYLE:PrimitiveStyle = PrimitiveStyle::with_stroke(BinaryColor::On, 1); - - - struct UdpDisplay { image: [u8; IMAGE_SIZE_BYTE], @@ -236,7 +230,7 @@ fn render_weather_icon(condition: &Weather, display: &mut UdpDisplay ){ fn send_package(ipaddress: String, data: &Option>, - strabaRes: &NextDeparture) { + straba_res: &NextDeparture) { let mut package: [u8; PACKAGE_LENGTH] = [0; PACKAGE_LENGTH]; // Brightness @@ -246,31 +240,31 @@ fn send_package(ipaddress: String, image: [0; IMAGE_SIZE_BYTE], }; - if (data.is_some()) { + if data.is_some() { render_weather(&mut display, data); } - if strabaRes.failure == false { + if straba_res.failure == false { let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On); let text_style_station = MonoTextStyle::new(&FONT_5X8, BinaryColor::On); - let mut outbound = format!("+{}min", (strabaRes.outbound_diff / 60)); - if (strabaRes.outbound_diff < 60) { + let mut outbound = format!("+{}min", (straba_res.outbound_diff / 60)); + if straba_res.outbound_diff < 60 { outbound = String::from("sofort"); } - Text::new(&strabaRes.outbound_station, Point::new(1, 15), text_style_station) + Text::new(&straba_res.outbound_station, Point::new(1, 15), text_style_station) .draw(&mut display) .unwrap(); Text::new(&outbound, Point::new(80, 15), text_style) .draw(&mut display) .unwrap(); - let mut inbound = format!("+{}min", (strabaRes.inbound_diff / 60)); - if (strabaRes.inbound_diff < 60) { + let mut inbound = format!("+{}min", (straba_res.inbound_diff / 60)); + if straba_res.inbound_diff < 60 { inbound = String::from("sofort"); } - Text::new(&strabaRes.inbound_station, Point::new(1, 25), text_style_station) + Text::new(&straba_res.inbound_station, Point::new(1, 25), text_style_station) .draw(&mut display) .unwrap(); Text::new(&inbound, Point::new(80, 24), text_style) @@ -296,12 +290,12 @@ LEDboardClient " } fn check_connection(ipaddress: String) -> bool { - let mut device_online = false; + let device_online; // generate a faulty package length let mut package: [u8; PACKAGE_LENGTH/2] = [0; PACKAGE_LENGTH/2]; // client need to bind to client port (1 before 4242) let socket = UdpSocket::bind("0.0.0.0:14242").expect("couldn't bind to address"); - socket.set_read_timeout(Some(Duration::from_secs(10))); /* 10 seconds timeout */ + socket.set_read_timeout(Some(Duration::from_secs(10))).unwrap(); /* 10 seconds timeout */ socket .send_to(&package, ipaddress + ":4242") .expect("couldn't send data"); @@ -309,14 +303,14 @@ fn check_connection(ipaddress: String) -> bool { // self.recv_buff is a [u8; 8092] let answer = socket.recv_from(&mut package); match answer { - Ok((n, addr)) => { + Ok((_n, _addr)) => { //println!("{} bytes response from {:?} {:?}", n, addr, &package[..n]); device_online = true; } Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { device_online = false; } - Err(e) => { + Err(_e) => { device_online = false; } } @@ -338,7 +332,7 @@ fn main() { let mut device_online = check_connection(ip.to_string()); - if (!device_online) { + if !device_online { println!("{} not online", ip); return } @@ -352,12 +346,12 @@ fn main() { let mut last_data = Option::None; // Test Webcrawler for public transportataion - let mut strabaRes = straba::fetch_data(Some(true)); - println!("{:?} {:?}s", strabaRes.outbound_station, strabaRes.outbound_diff); - println!("{:?} {:?}s", strabaRes.inbound_station , strabaRes.inbound_diff); + let mut straba_res = straba::fetch_data(Some(true)); + println!("{:?} {:?}s", straba_res.outbound_station, straba_res.outbound_diff); + println!("{:?} {:?}s", straba_res.inbound_station , straba_res.inbound_diff); // Render start - send_package(ip.to_string(), &last_data, &strabaRes); + send_package(ip.to_string(), &last_data, &straba_res); loop { let st_now = SystemTime::now(); let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs(); @@ -376,19 +370,19 @@ fn main() { } } - if (strabaRes.request_time + 60) < seconds as i64 { + if (straba_res.request_time + 60) < seconds as i64 { device_online = check_connection(ip.to_string()); // request once a minute new data if device_online == true { - strabaRes = straba::fetch_data(None); - println!("Update {:?} {:?}s", strabaRes.outbound_station, strabaRes.outbound_diff); - println!("Update {:?} {:?}s", strabaRes.inbound_station , strabaRes.inbound_diff); + straba_res = straba::fetch_data(None); + println!("Update {:?} {:?}s", straba_res.outbound_station, straba_res.outbound_diff); + println!("Update {:?} {:?}s", straba_res.inbound_station , straba_res.inbound_diff); } } if device_online == true { // Render new image - send_package(ip.to_string(), &last_data, &strabaRes); + send_package(ip.to_string(), &last_data, &straba_res); } } } diff --git a/client/bin/src/straba.rs b/client/bin/src/straba.rs index 9398baf..f0cd5ee 100644 --- a/client/bin/src/straba.rs +++ b/client/bin/src/straba.rs @@ -1,11 +1,6 @@ use chrono::DateTime; use std::time::{SystemTime, UNIX_EPOCH}; -use chrono_tz::Europe::Berlin; -/* @file straba.rs - * @brief fetch next depature of light rail vehicle - */ -use serde_json::Value; use serde::Deserialize; const STATION_URL:&str = "https://www.rnv-online.de/rest/departure/2494"; @@ -16,7 +11,7 @@ const STATION_URL:&str = "https://www.rnv-online.de/rest/departure/2494"; pub struct Station { pub id: String, pub name: String, - pub graphQL: GraphQL, + pub graph_ql: GraphQL, } #[derive(Default, Debug, Clone, PartialEq, Deserialize)] @@ -41,7 +36,7 @@ pub struct JourneysElement { #[derive(Default, Debug, Clone, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Line { - pub lineGroup: LineGroup, + pub line_group: LineGroup, } #[derive(Default, Debug, Clone, PartialEq, Deserialize)] @@ -61,15 +56,15 @@ pub struct Journey { #[derive(Default, Debug, Clone, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] pub struct StopsElement { - pub destinationLabel: String, - pub plannedDeparture: IsoStringDateTime, - pub realtimeDeparture: IsoStringDateTime, + pub destination_label: String, + pub planned_departure: IsoStringDateTime, + pub realtime_departure: IsoStringDateTime, } #[derive(Default, Debug, Clone, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] pub struct IsoStringDateTime { - pub isoString: Option, + pub iso_string: Option, } // Return value @@ -89,7 +84,7 @@ pub fn fetch_data(debug_print : Option) -> NextDeparture { let url = &format!("{}?datetime={}", STATION_URL, seconds); let result = reqwest::blocking::get(url); - let mut returnValue = NextDeparture { + let mut return_value = NextDeparture { failure : false, outbound_station : String::from(""), outbound_diff : 10000, @@ -100,64 +95,64 @@ pub fn fetch_data(debug_print : Option) -> NextDeparture { if result.is_err() { println!("Could not read station response {:?}", result.err()); - returnValue.failure = true; - return returnValue; + return_value.failure = true; + return return_value; } let text = result.unwrap().text(); if text.is_err() { println!("Could not convert response {:?}", text.err()); - returnValue.failure = true; - return returnValue; + return_value.failure = true; + return return_value; } - let rawText = &text.unwrap(); - let body: std::result::Result = serde_json::from_str(&rawText); + let raw_text = &text.unwrap(); + let body: std::result::Result = serde_json::from_str(&raw_text); if body.is_err() { println!("Could not parse json {:?}", body.err()); println!("------------------------- %< ----------------------------"); - println!("{}", &rawText); + println!("{}", &raw_text); println!("------------------------- %< ----------------------------"); - returnValue.failure = true; - return returnValue; + return_value.failure = true; + return return_value; } // parse JSON result.. search of both directions let json = body.unwrap(); - for el in (json.graphQL.response.journeys.elements) { - if (debug_print.is_some() && debug_print.unwrap() == true) { - println!("Line {:}", el.line.lineGroup.label); + for el in json.graph_ql.response.journeys.elements { + if debug_print.is_some() && debug_print.unwrap() == true { + println!("Line {:}", el.line.line_group.label); } for stop in el.stops { // use only valid data - if stop.realtimeDeparture.isoString.is_some() && - stop.destinationLabel != "" { - let txt_departure = stop.realtimeDeparture.isoString.unwrap(); + if stop.realtime_departure.iso_string.is_some() && + stop.destination_label != "" { + let txt_departure = stop.realtime_departure.iso_string.unwrap(); let next_departure = DateTime::parse_from_rfc3339(&txt_departure).unwrap(); let diff = next_departure.timestamp() - (seconds as i64); - if (debug_print.is_some() && debug_print.unwrap() == true) { - println!("To {:} {:} (in {:} seconds)", stop.destinationLabel, txt_departure, diff ); + if debug_print.is_some() && debug_print.unwrap() == true { + println!("To {:} {:} (in {:} seconds)", stop.destination_label, txt_departure, diff ); } - if stop.destinationLabel.contains("Rheinau") { - if (diff < returnValue.outbound_diff) { - returnValue.outbound_station = stop.destinationLabel; - returnValue.outbound_diff = diff; + if stop.destination_label.contains("Rheinau") { + if diff < return_value.outbound_diff { + return_value.outbound_station = stop.destination_label; + return_value.outbound_diff = diff; } - } else if stop.destinationLabel.contains("Hochschule") || - stop.destinationLabel.contains("Hauptbahnhof") || - stop.destinationLabel.contains("Schönau") { - if (diff < returnValue.inbound_diff) { - returnValue.inbound_station = stop.destinationLabel; - returnValue.inbound_diff = diff; + } else if stop.destination_label.contains("Hochschule") || + stop.destination_label.contains("Hauptbahnhof") || + stop.destination_label.contains("Schönau") { + if diff < return_value.inbound_diff { + return_value.inbound_station = stop.destination_label; + return_value.inbound_diff = diff; } } } else { - println!("Planned {:} {:?}", stop.destinationLabel, stop.plannedDeparture.isoString) + println!("Planned {:} {:?}", stop.destination_label, stop.planned_departure.iso_string) } } } - returnValue + return_value } diff --git a/client/openweathermap/src/lib.rs b/client/openweathermap/src/lib.rs old mode 100755 new mode 100644 From a28610f821c7987f034beed218311d62ae0e6b84 Mon Sep 17 00:00:00 2001 From: Empire Date: Fri, 22 Sep 2023 22:10:52 +0200 Subject: [PATCH 03/14] time start --- client/bin/src/main.rs | 20 +++++++++++++++++++- client/bin/src/straba.rs | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 10ce554..d5d467f 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -1,4 +1,4 @@ -use std::time::Duration; +use std::{time::Duration, fmt::format}; use bit::BitIndex; use chrono_tz::Europe::Berlin; use chrono::{DateTime, NaiveDateTime, Utc, Timelike}; @@ -228,6 +228,19 @@ fn render_weather_icon(condition: &Weather, display: &mut UdpDisplay ){ Image::new(&icon_image.unwrap(), Point::new((IMAGE_WIDTH-40) as i32, 0)).draw(display).unwrap(); } +fn render_clock(display: &mut UdpDisplay){ + let cur_time = DateTime::::default(); + let europe_time = cur_time.with_timezone(&Berlin); + let hour = europe_time.hour(); + let minute = europe_time.minute(); + let second = europe_time.second(); + let time = format!("{hour:0>2}:{minute:0>2}:{second:0>2}"); + let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On); + Text::new(&time, Point::new((1) as i32, 7), text_style) + .draw(display) + .unwrap(); +} + fn send_package(ipaddress: String, data: &Option>, straba_res: &NextDeparture) { @@ -272,6 +285,11 @@ fn send_package(ipaddress: String, .unwrap(); } + + + render_clock(&mut display); + + package[1..PACKAGE_LENGTH].copy_from_slice(&display.image); // client need to bind to client port (1 before 4242) let socket = UdpSocket::bind("0.0.0.0:14242").expect("couldn't bind to address"); diff --git a/client/bin/src/straba.rs b/client/bin/src/straba.rs index f0cd5ee..86f80ff 100644 --- a/client/bin/src/straba.rs +++ b/client/bin/src/straba.rs @@ -11,6 +11,7 @@ const STATION_URL:&str = "https://www.rnv-online.de/rest/departure/2494"; pub struct Station { pub id: String, pub name: String, + #[serde(alias = "graphQL")] pub graph_ql: GraphQL, } From efebb0c1f475bc84c24aad81ced53ffc8579468f Mon Sep 17 00:00:00 2001 From: Empire Date: Fri, 22 Sep 2023 22:32:19 +0200 Subject: [PATCH 04/14] add time with seconds --- client/bin/Cargo.toml | 2 +- client/bin/src/main.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/client/bin/Cargo.toml b/client/bin/Cargo.toml index d3473c8..51bbb76 100644 --- a/client/bin/Cargo.toml +++ b/client/bin/Cargo.toml @@ -10,7 +10,7 @@ embedded-graphics = "0.8.0" substring = "1.4.5" tinybmp = "0.5.0" openweathermap = { path = "../openweathermap" } -chrono = { version = "0.4.23", default-features = false , features = ["iana-time-zone"] } +chrono = { version = "0.4.23", default-features = false , features = ["clock", "std","iana-time-zone"] } chrono-tz = "0.8.0" colored = "2.0.0" datetime = "0.5.2" diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index d5d467f..ce0c5c7 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -2,6 +2,7 @@ use std::{time::Duration, fmt::format}; use bit::BitIndex; use chrono_tz::Europe::Berlin; use chrono::{DateTime, NaiveDateTime, Utc, Timelike}; +use chrono::prelude::*; use std::time::{SystemTime, UNIX_EPOCH}; use openweathermap::forecast::Weather; use substring::Substring; @@ -138,7 +139,7 @@ fn render_weather(display: &mut UdpDisplay ,data: &Option::default(); + let cur_time = chrono::offset::Utc::now(); if zoned_time > cur_time { println!("Skipping old result {hour}:{minute} @{time_s}"); } @@ -229,8 +230,8 @@ fn render_weather_icon(condition: &Weather, display: &mut UdpDisplay ){ } fn render_clock(display: &mut UdpDisplay){ - let cur_time = DateTime::::default(); - let europe_time = cur_time.with_timezone(&Berlin); + let time = chrono::offset::Utc::now(); + let europe_time = time.with_timezone(&Berlin); let hour = europe_time.hour(); let minute = europe_time.minute(); let second = europe_time.second(); @@ -373,7 +374,7 @@ fn main() { loop { let st_now = SystemTime::now(); let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs(); - let delay = time::Duration::from_millis(10000); + let delay = time::Duration::from_millis(500); thread::sleep(delay); // Only request, if the device is present if device_online == true { From c2035df4d99020944c7fcefbe72414628519c72f Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 22 Sep 2023 22:43:55 +0200 Subject: [PATCH 05/14] Removed plus --- client/bin/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index ce0c5c7..dbc84dd 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -261,7 +261,7 @@ fn send_package(ipaddress: String, if straba_res.failure == false { let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On); let text_style_station = MonoTextStyle::new(&FONT_5X8, BinaryColor::On); - let mut outbound = format!("+{}min", (straba_res.outbound_diff / 60)); + let mut outbound = format!("{}min", (straba_res.outbound_diff / 60)); if straba_res.outbound_diff < 60 { outbound = String::from("sofort"); } @@ -272,7 +272,7 @@ fn send_package(ipaddress: String, .draw(&mut display) .unwrap(); - let mut inbound = format!("+{}min", (straba_res.inbound_diff / 60)); + let mut inbound = format!("{}min", (straba_res.inbound_diff / 60)); if straba_res.inbound_diff < 60 { inbound = String::from("sofort"); } From 6d5d7cf261f68c2e782e5b06a0638749996f0795 Mon Sep 17 00:00:00 2001 From: Ada Date: Fri, 22 Sep 2023 22:47:21 +0200 Subject: [PATCH 06/14] Update server to respond to status checking messages The simulator responds to unknown valid datagrams by returning them to the sender. --- simulation/VirtualLedBoard/udpserver.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/simulation/VirtualLedBoard/udpserver.cpp b/simulation/VirtualLedBoard/udpserver.cpp index 0acdf06..e1e9f14 100644 --- a/simulation/VirtualLedBoard/udpserver.cpp +++ b/simulation/VirtualLedBoard/udpserver.cpp @@ -2,6 +2,7 @@ #include "settings.h" #include #include +#include #include "mainwindow.h" #define UDP_IMAGE_PORT 4242 @@ -49,6 +50,7 @@ void UdpLedServer ::readPendingDatagrams() void UdpLedServer::processTheDatagram(QNetworkDatagram datagram) { if (datagram.isValid() && datagram.data().length() == PACKET_LENGTH) { + qInfo("Received regular datagram."); uint8_t brightness = datagram.data().at(PACKET_INDEX_BRIGHTNESS); int currentIndex = PACKET_INDEX_PANEL0; @@ -70,5 +72,13 @@ void UdpLedServer::processTheDatagram(QNetworkDatagram datagram) { qDebug() << "Received datagram:" << brightness; + } else if (datagram.isValid() && datagram.data().length() != PACKET_LENGTH) { + qDebug("Received status-check datagram."); + //socket = new QUdpSocket(this); + this->mUdpSocket->writeDatagram(datagram.data(), sizeof(datagram.data()), datagram.senderAddress(), datagram.senderPort()); + //this->mUdpSocket->writeDatagram(datagram); + qDebug("Returned datagram"); + } else { + qDebug("Received invalid datagram."); } } From 860815313b6130227d1c9f29eb3b43f087a90938 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 23 Sep 2023 15:42:18 +0200 Subject: [PATCH 07/14] Handle unused variable --- simulation/VirtualLedBoard/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/simulation/VirtualLedBoard/mainwindow.cpp b/simulation/VirtualLedBoard/mainwindow.cpp index b99fbab..da8445b 100644 --- a/simulation/VirtualLedBoard/mainwindow.cpp +++ b/simulation/VirtualLedBoard/mainwindow.cpp @@ -22,6 +22,7 @@ MainWindow::~MainWindow() } void MainWindow::drawImage(QImage *target) { + (void)target; /* handle unused variable ;-) */ this->mScene=new QGraphicsScene() ; QGraphicsView *graphicsView = new QGraphicsView(); graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); From 46f7eb4f8a02ab4fc8513e0a436926369e71cdb7 Mon Sep 17 00:00:00 2001 From: Ada Date: Sun, 24 Sep 2023 22:29:24 +0200 Subject: [PATCH 08/14] Fix misaligned text elements in second line --- client/bin/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index dbc84dd..651e98c 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -226,7 +226,7 @@ fn render_weather_icon(condition: &Weather, display: &mut UdpDisplay ){ return; } }; - Image::new(&icon_image.unwrap(), Point::new((IMAGE_WIDTH-40) as i32, 0)).draw(display).unwrap(); + Image::new(&icon_image.unwrap(), Point::new((IMAGE_WIDTH-40) as i32, 6)).draw(display).unwrap(); } fn render_clock(display: &mut UdpDisplay){ @@ -281,7 +281,7 @@ fn send_package(ipaddress: String, Text::new(&straba_res.inbound_station, Point::new(1, 25), text_style_station) .draw(&mut display) .unwrap(); - Text::new(&inbound, Point::new(80, 24), text_style) + Text::new(&inbound, Point::new(80, 25), text_style) .draw(&mut display) .unwrap(); } From 04aab61ab7fd87ec4c8a2d83d6d33ebb9b2a0d11 Mon Sep 17 00:00:00 2001 From: Ada Date: Sun, 24 Sep 2023 23:03:02 +0200 Subject: [PATCH 09/14] Shift weather back to original location --- client/bin/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 651e98c..35ca3fa 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -10,7 +10,7 @@ use tinybmp::Bmp; use core::time; use embedded_graphics::{ image::Image, - mono_font::{iso_8859_1::FONT_6X10, iso_8859_1::FONT_5X8, MonoTextStyle}, + mono_font::{iso_8859_1::FONT_6X10, iso_8859_1::FONT_5X8, iso_8859_1::FONT_4X6, MonoTextStyle}, pixelcolor::BinaryColor, prelude::*, text::Text, @@ -226,7 +226,7 @@ fn render_weather_icon(condition: &Weather, display: &mut UdpDisplay ){ return; } }; - Image::new(&icon_image.unwrap(), Point::new((IMAGE_WIDTH-40) as i32, 6)).draw(display).unwrap(); + Image::new(&icon_image.unwrap(), Point::new((IMAGE_WIDTH-40) as i32, 0)).draw(display).unwrap(); } fn render_clock(display: &mut UdpDisplay){ From e07413f59411ae9ad73f4011bc6f2d90a6034cc4 Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 28 Sep 2023 22:08:54 +0200 Subject: [PATCH 10/14] Fix kerning issues by changing font. Shorten names when necessary. --- client/bin/src/main.rs | 66 +++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 35ca3fa..8fe5ba9 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -1,4 +1,5 @@ use std::{time::Duration, fmt::format}; +use str; use bit::BitIndex; use chrono_tz::Europe::Berlin; use chrono::{DateTime, NaiveDateTime, Utc, Timelike}; @@ -242,6 +243,43 @@ fn render_clock(display: &mut UdpDisplay){ .unwrap(); } +fn render_strab_partial(display: &mut UdpDisplay, station: &String, diff: i64, height: i32) { + let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On); + let mut diff_str = format!("{}min", (diff / 60)); + if diff < 60 { + diff_str = String::from("sofort"); + } + let station_short: String; + if str::len(&station) > 13 { + station_short = station + .replace("Straße", "Str") + .replace("straße", "str") + .replace("Platz", "Pl") + .replace("platz", "pl") + .replace("Hauptbahnhof", "Hbf") + .replace("Bahnhof", "Bf"); + } else { + station_short = station.to_string(); + } + let station_clip: String; + if str::len(&station_short) > 13 { + station_clip = station_short[0..12].to_string(); + } else { + station_clip = station_short.to_string(); + } + Text::new(&station_clip, Point::new(1, height), text_style) + .draw(display) + .unwrap(); + Text::new(&diff_str, Point::new(80, height), text_style) + .draw(display) + .unwrap(); +} + +fn render_strab(display: &mut UdpDisplay, straba_res: &NextDeparture) { + render_strab_partial(display, &straba_res.outbound_station, straba_res.outbound_diff, 15); + render_strab_partial(display, &straba_res.inbound_station, straba_res.inbound_diff, 25); +} + fn send_package(ipaddress: String, data: &Option>, straba_res: &NextDeparture) { @@ -259,35 +297,9 @@ fn send_package(ipaddress: String, } if straba_res.failure == false { - let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On); - let text_style_station = MonoTextStyle::new(&FONT_5X8, BinaryColor::On); - let mut outbound = format!("{}min", (straba_res.outbound_diff / 60)); - if straba_res.outbound_diff < 60 { - outbound = String::from("sofort"); - } - Text::new(&straba_res.outbound_station, Point::new(1, 15), text_style_station) - .draw(&mut display) - .unwrap(); - Text::new(&outbound, Point::new(80, 15), text_style) - .draw(&mut display) - .unwrap(); - - let mut inbound = format!("{}min", (straba_res.inbound_diff / 60)); - if straba_res.inbound_diff < 60 { - inbound = String::from("sofort"); - } - - - Text::new(&straba_res.inbound_station, Point::new(1, 25), text_style_station) - .draw(&mut display) - .unwrap(); - Text::new(&inbound, Point::new(80, 25), text_style) - .draw(&mut display) - .unwrap(); + render_strab(&mut display, straba_res); } - - render_clock(&mut display); From 5923bc830e7eb8fd438051972e770d1c11c9cdcb Mon Sep 17 00:00:00 2001 From: Ollo Date: Wed, 4 Oct 2023 20:41:29 +0200 Subject: [PATCH 11/14] Added returncode for main function --- client/bin/src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 35ca3fa..cf2e782 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -1,8 +1,7 @@ -use std::{time::Duration, fmt::format}; +use std::time::Duration; use bit::BitIndex; use chrono_tz::Europe::Berlin; use chrono::{DateTime, NaiveDateTime, Utc, Timelike}; -use chrono::prelude::*; use std::time::{SystemTime, UNIX_EPOCH}; use openweathermap::forecast::Weather; use substring::Substring; @@ -19,6 +18,7 @@ use embedded_graphics::{ use std::net::UdpSocket; use std::{env, thread}; use std::io; +use std::process::ExitCode; use openweathermap::forecast::Forecast; use straba::NextDeparture; @@ -336,14 +336,14 @@ fn check_connection(ipaddress: String) -> bool { return device_online; } -fn main() { +fn main() -> ExitCode { let args: Vec = env::args().collect(); - match args.len() { // no arguments passed 1 => { // show a help message help(); + return ExitCode::SUCCESS; } // one argument passed 2 => { @@ -353,7 +353,7 @@ fn main() { let mut device_online = check_connection(ip.to_string()); if !device_online { println!("{} not online", ip); - return + return ExitCode::FAILURE; } let receiver = openweathermap::init_forecast("Mannheim", @@ -409,6 +409,7 @@ fn main() { _ => { // show a help message help(); + return ExitCode::SUCCESS; } } } From e42b08bcf3489d513dc088710f4db50882c8384d Mon Sep 17 00:00:00 2001 From: Ollo Date: Wed, 4 Oct 2023 20:43:08 +0200 Subject: [PATCH 12/14] Update StraBa every 50 seconds --- client/bin/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index cf2e782..f7ce8b4 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -389,7 +389,7 @@ fn main() -> ExitCode { } } - if (straba_res.request_time + 60) < seconds as i64 { + if (straba_res.request_time + 50) < seconds as i64 { device_online = check_connection(ip.to_string()); // request once a minute new data if device_online == true { From 3951b4e41c3a3aba5467c849ae07e00a09d5a848 Mon Sep 17 00:00:00 2001 From: Ada Date: Fri, 13 Oct 2023 21:14:24 +0200 Subject: [PATCH 13/14] Fix inconsistent spacing between lines --- client/bin/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 4a8b134..f09156a 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -276,8 +276,8 @@ fn render_strab_partial(display: &mut UdpDisplay, station: &String, diff: i64, h } fn render_strab(display: &mut UdpDisplay, straba_res: &NextDeparture) { - render_strab_partial(display, &straba_res.outbound_station, straba_res.outbound_diff, 15); - render_strab_partial(display, &straba_res.inbound_station, straba_res.inbound_diff, 25); + render_strab_partial(display, &straba_res.outbound_station, straba_res.outbound_diff, 17); + render_strab_partial(display, &straba_res.inbound_station, straba_res.inbound_diff, 27); } fn send_package(ipaddress: String, From c39f944b5a5f5dd0bca67f740a47ebac3d3daf89 Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 5 Jan 2024 22:16:24 +0100 Subject: [PATCH 14/14] datetime format in URL changed --- client/bin/src/straba.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/client/bin/src/straba.rs b/client/bin/src/straba.rs index 86f80ff..541f33b 100644 --- a/client/bin/src/straba.rs +++ b/client/bin/src/straba.rs @@ -1,6 +1,6 @@ use chrono::DateTime; use std::time::{SystemTime, UNIX_EPOCH}; - +use chrono::Local; use serde::Deserialize; const STATION_URL:&str = "https://www.rnv-online.de/rest/departure/2494"; @@ -79,10 +79,11 @@ pub struct NextDeparture { } pub fn fetch_data(debug_print : Option) -> NextDeparture { - + let date = Local::now(); let st_now = SystemTime::now(); let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs(); - let url = &format!("{}?datetime={}", STATION_URL, seconds); + let timeString = date.format("%Y-%m-%d %H:%M:%S"); + let url = &format!("{}?datetime={}", STATION_URL, timeString); let result = reqwest::blocking::get(url); let mut return_value = NextDeparture { @@ -118,11 +119,25 @@ pub fn fetch_data(debug_print : Option) -> NextDeparture { return return_value; } + if debug_print.is_some() && debug_print.unwrap() == true { + println!("----------- Seconds {:} {:} requesting ... -----------", seconds, timeString); + } // parse JSON result.. search of both directions let json = body.unwrap(); + + if debug_print.is_some() && debug_print.unwrap() == true { + println!("Requesting {:}", json.graph_ql.response.name); + println!("Elements {:}", json.graph_ql.response.journeys.elements.len() ); + println!("------------------------- %< ----------------------------"); + println!("{}", &raw_text); + println!("------------------------- %< ----------------------------"); + } + for el in json.graph_ql.response.journeys.elements { + if debug_print.is_some() && debug_print.unwrap() == true { - println!("Line {:}", el.line.line_group.label); + println!("Requesting {:}", json.graph_ql.response.name); + println!("Line {:}", el.line.line_group.label); } for stop in el.stops { // use only valid data @@ -140,6 +155,8 @@ pub fn fetch_data(debug_print : Option) -> NextDeparture { if diff < return_value.outbound_diff { return_value.outbound_station = stop.destination_label; return_value.outbound_diff = diff; + } else if debug_print.is_some() && debug_print.unwrap() == true { + println!("Unkown diff Stop {:} {:} (in {:} seconds)", stop.destination_label, txt_departure, diff ); } } else if stop.destination_label.contains("Hochschule") || stop.destination_label.contains("Hauptbahnhof") || @@ -147,13 +164,19 @@ pub fn fetch_data(debug_print : Option) -> NextDeparture { if diff < return_value.inbound_diff { return_value.inbound_station = stop.destination_label; return_value.inbound_diff = diff; + } else if debug_print.is_some() && debug_print.unwrap() == true { + println!("Unkown diff Stop {:} {:} (in {:} seconds)", stop.destination_label, txt_departure, diff ); } + } else if debug_print.is_some() && debug_print.unwrap() == true { + println!("Unkown Stop {:} {:} (in {:} seconds)", stop.destination_label, txt_departure, diff ); } } else { println!("Planned {:} {:?}", stop.destination_label, stop.planned_departure.iso_string) } } } - + if debug_print.is_some() && debug_print.unwrap() == true { + println!("----------- end of straba.rs -----------"); + } return_value }