Initial commit
7
src-tauri/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
5403
src-tauri/Cargo.lock
generated
Normal file
27
src-tauri/Cargo.toml
Normal file
@@ -0,0 +1,27 @@
|
||||
[package]
|
||||
name = "mcrldesktop"
|
||||
version = "0.1.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
# The `_lib` suffix may seem redundant but it is necessary
|
||||
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
||||
name = "mcrldesktop_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
binread = "2.2.0"
|
||||
tauri-plugin-dialog = "2.4.2"
|
||||
|
||||
3
src-tauri/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
12
src-tauri/capabilities/default.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default",
|
||||
"dialog:default",
|
||||
"dialog:allow-open"
|
||||
]
|
||||
}
|
||||
BIN
src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 974 B |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 903 B |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
36
src-tauri/src/lib.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
mod rtlf;
|
||||
|
||||
use crate::rtlf::{RTLFDataRecord, RTLFHeader, RtlfFile};
|
||||
use serde::Serialize;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct RtlfDataResponse {
|
||||
header: RTLFHeader,
|
||||
records: Vec<RTLFDataRecord>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn parse_rtlf_file(path: String) -> Result<RtlfDataResponse, String> {
|
||||
let file = File::open(&path).map_err(|e| e.to_string())?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut rtlf = RtlfFile::new(reader).map_err(|e| e.to_string())?;
|
||||
let records = rtlf.read_all_records();
|
||||
|
||||
Ok(RtlfDataResponse {
|
||||
header: rtlf.header,
|
||||
records,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.invoke_handler(tauri::generate_handler![parse_rtlf_file])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
5
src-tauri/src/main.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
mcrldesktop_lib::run()
|
||||
}
|
||||
63
src-tauri/src/rtlf.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use binread::BinRead;
|
||||
use serde::Serialize;
|
||||
use std::io::{Error, ErrorKind, Read, Seek, SeekFrom};
|
||||
|
||||
#[derive(BinRead, Debug, Clone, Serialize)]
|
||||
#[br(little)]
|
||||
pub struct RTLFHeader {
|
||||
pub magic_number: [u8; 4],
|
||||
pub version: u32,
|
||||
pub car_id: u32,
|
||||
pub track_name_len: u32,
|
||||
#[br(count = track_name_len, map = |s: Vec<u8>| String::from_utf8_lossy(&s).to_string())]
|
||||
pub track_name: String,
|
||||
}
|
||||
|
||||
#[derive(BinRead, Debug, Clone, Serialize)]
|
||||
#[br(little)]
|
||||
pub struct RTLFDataRecord {
|
||||
pub timestamp: f64,
|
||||
pub gps_long: f64,
|
||||
pub gps_lat: f64,
|
||||
pub facing_x: f64,
|
||||
pub facing_y: f64,
|
||||
pub facing_z: f64,
|
||||
pub acceleration_x: f64,
|
||||
pub acceleration_z: f64,
|
||||
pub acceleration_y: f64,
|
||||
pub speed: f64,
|
||||
}
|
||||
|
||||
pub struct RtlfFile<R: Read + Seek> {
|
||||
pub header: RTLFHeader,
|
||||
reader: R,
|
||||
}
|
||||
|
||||
impl<R: Read + Seek> RtlfFile<R> {
|
||||
pub fn new(mut reader: R) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let header = RTLFHeader::read(&mut reader)?;
|
||||
|
||||
if &header.magic_number != b"RTLF" {
|
||||
return Err(Box::new(Error::new(
|
||||
ErrorKind::InvalidData,
|
||||
"Invalid file format: Magic number mismatch",
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(Self { header, reader })
|
||||
}
|
||||
|
||||
pub fn read_all_records(&mut self) -> Vec<RTLFDataRecord> {
|
||||
let mut records = Vec::new();
|
||||
let _ = self.reader.seek(SeekFrom::Start(self.header_size()));
|
||||
|
||||
while let Ok(record) = RTLFDataRecord::read(&mut self.reader) {
|
||||
records.push(record);
|
||||
}
|
||||
records
|
||||
}
|
||||
|
||||
fn header_size(&self) -> u64 {
|
||||
(16 + self.header.track_name_len) as u64
|
||||
}
|
||||
}
|
||||
35
src-tauri/tauri.conf.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "mcrldesktop",
|
||||
"version": "0.1.0",
|
||||
"identifier": "dev.asedem.mcrldesktop",
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run dev",
|
||||
"devUrl": "http://localhost:1420",
|
||||
"beforeBuildCommand": "npm run build",
|
||||
"frontendDist": "../dist"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"title": "mcrldesktop",
|
||||
"width": 800,
|
||||
"height": 600
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||