Skip to content

Commit

Permalink
Merge pull request #9 from rnd-ash/dev
Browse files Browse the repository at this point in the history
Version 0.2.0
  • Loading branch information
rnd-ash committed Jun 5, 2024
2 parents f414ef9 + 69a6593 commit a878408
Show file tree
Hide file tree
Showing 39 changed files with 3,332 additions and 2,290 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
run: ls config_app/ -aslh
- uses: actions/upload-artifact@v3
with:
path: config_app/
name: config_app-${{env.APP_VERSION}}-x86_64.AppImage
path: config_app/*.AppImage
name: config-app-linux


Windows-App:
Expand All @@ -66,7 +66,7 @@ jobs:
run: ls target -R
- uses: actions/upload-artifact@v3
with:
name: config-app-${{env.BRANCH_NAME}}-exe
name: config-app-exe
path: target/i686-pc-windows-msvc/release/*.exe

OSX-app:
Expand All @@ -76,14 +76,16 @@ jobs:
- run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal
- name: Install cargo-bundle
run: cargo install cargo-bundle
- uses: Swatinem/rust-cache@v2
- name: Build executable
working-directory: ./config_app
run: cargo build --verbose --release
run: cargo bundle --release
- uses: actions/upload-artifact@v3
with:
name: config-app-${{env.BRANCH_NAME}}-osx
path: target/release/config_app
name: config-app-osx
path: target/release/bundle/osx/*.app

Create-Upload:
needs: [Windows-App, Linux-App, OSX-app]
Expand Down Expand Up @@ -112,9 +114,9 @@ jobs:
tag_name: ${{ env.BRANCH_NAME }}-${{ github.sha }}
name: Release ${{ env.BRANCH_NAME }}
files: |
config-app-${{env.BRANCH_NAME}}-exe/*.exe
config-app-${{env.BRANCH_NAME}}-appimage/*.AppImage
config-app-${{env.BRANCH_NAME}}-osx/config_app
config-app-exe/*.exe
config-app-linux/*.AppImage
config-app-osx/*.app


35 changes: 35 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Remote deploy code documentation

on:
push:
branches: ["dev", "main"]

env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

jobs:
deploy_docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal
- run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal
- uses: Swatinem/rust-cache@v2
- name: Install deps
run: sudo apt-get update && sudo apt-get install -y binutils coreutils desktop-file-utils fakeroot fuse libgdk-pixbuf2.0-dev patchelf python3-pip python3-setuptools squashfs-tools strace util-linux zsync libgtk-3-dev
- name: Cargo doc
run: cargo doc
- name: Deploy docs
uses: appleboy/scp-action@v0.1.4
with:
source: "target/doc/*"
target: "/var/www/html/config_app/${{ env.BRANCH_NAME }}"
username: ${{ secrets.USER }}
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
rm: true

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.0.8 (Dev)
* Add new YML based SCN coding wizard

# 1.0.7 (08/08/23)
* Move diagnostic executor to seperate thread
* Migrate to diag_server_unified ecu_diagnostics branch
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

The configuration app for the Ultimate-NAG52 TCU

## Starting version 1.0.8
to load the TCU Settings page, you will need `MODULE_SETTINGS.yml` file that is shipped with the TCUs firmware on Github!

## Repo structure

* Backend - Backend for ECU diagnostics
Expand Down
14 changes: 9 additions & 5 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
[package]
name = "backend"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ecu_diagnostics="0.95.0"
ecu_diagnostics="0.95.6"
#ecu_diagnostics = { git = "https://github.com/rnd-ash/ecu_diagnostics", branch="diag_server_unified" }
#ecu_diagnostics = { path = "../../ecu_diagnostics" }
serial-rs = "0.2.1"
packed_struct="0.10.0"
static_assertions = "1.1.0"
serde_yaml="0.9.21"
serde = { version = "1.0", features = ["derive"] }
serde-big-array = "0.5.1"
serde_derive = "1.0.197"
chrono="0.4.24"
strum = "0.25.0"
strum_macros = "0.25"
strum = "0.26.2"
strum_macros = "0.26.2"
serde_json = "1.0.97"
miette="5.10.0"
miette="7.2.0"
bitflags="2.4.0"
flate2="1.0"
121 changes: 121 additions & 0 deletions backend/src/diag/calibration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use std::collections::{BTreeMap, BTreeSet};
use packed_struct::derive::PackedStruct;
use serde_big_array::BigArray;
use serde_derive::{Serialize, Deserialize};

#[derive(PackedStruct, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[repr(C)]
#[packed_struct(endian = "lsb")]
pub struct EgsHydraulicConfiguration {
pub multiplier_1: u16,
pub multiplier_other: u16,
pub lp_reg_pressure: u16,
pub spc_overlap_circuit_factor: [u16; 8],
pub mpc_overlap_circuit_factor: [u16; 8],
pub spring_overlap_pressure: [i16; 8],
pub shift_reg_pressure: u16,
pub spc_gain_factor_shift: [u16; 8],
pub min_mpc_pressure: u16,
pub unk1: u8,
pub unk2: u8,
pub unk3: u16,
pub unk4: u16,
pub unk5: u16,
pub shift_pressure_addr_percent: u16,
pub inlet_pressure_offset: u16,
pub inlet_pressure_input_min: u16,
pub inlet_pressure_input_max: u16,
pub inlet_pressure_output_min: u16,
pub inlet_pressure_output_max: u16,
pub extra_pressure_pump_speed_min: u16,
pub extra_pressure_pump_speed_max: u16,
pub extra_pressure_adder_r1_1: u16,
pub extra_pressure_adder_other_gears: u16,
pub shift_pressure_factor_percent: u16,
pub pcs_map_x: [u16; 7],
pub pcs_map_y: [u16; 4],
#[serde(with = "BigArray")]
pub pcs_map_z: [u16; 28]
}

#[derive(PackedStruct, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[repr(C)]
#[packed_struct(endian = "lsb")]
pub struct EgsMechanicalConfiguration {
pub gb_ty: u8,
pub ratio_table: [u16; 8],
#[serde(alias="shift_something_unk1")]
pub intertia_factor_table: [u16; 8],
#[serde(with = "BigArray")]
pub friction_map: [u16; 48],
pub max_torque_on_clutch: [u16; 4],
pub max_torque_off_clutch: [u16; 4],
pub release_spring_pressure: [u16; 6],
#[serde(alias="torque_byte_unk2")]
pub intertia_torque: [u16; 8],
pub strongest_loaded_clutch_idx: [u8; 8],
pub unk3: [u16; 8],
pub atf_density_minus_50c: u16,
pub atf_density_drop_per_c: u16,
pub atf_density_centrifugal_force_factor: [u16; 3]
}

#[derive(PackedStruct, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[repr(C)]
#[packed_struct(endian = "lsb")]
pub struct EgsTorqueConverterConfiguration {
pub loss_map_x: [u16; 2],
pub loss_map_z: [u16; 2],
pub pump_map_x: [u16; 11],
pub pump_map_z: [u16; 11]
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct CalibrationRecord<T>
where T: PartialEq + Eq + PartialOrd + Ord {
pub name: String,
pub data: T,
pub valid_egs_pns: Vec<String>
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ChassisConfig {
pub gearbox: String,
pub chassis: String,
pub hydr_cfg: String,
pub mech_cfg: String,
pub tcc_cfg: String
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct EgsData {
pub pn: String,
pub chassis: Vec<ChassisConfig>
}

#[derive(Debug, Serialize, Deserialize, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct CalibrationDatabase {
pub egs_list: Vec<EgsData>,
pub hydralic_calibrations: Vec<CalibrationRecord<EgsHydraulicConfiguration>>,
pub mechanical_calibrations: Vec<CalibrationRecord<EgsMechanicalConfiguration>>,
pub torqueconverter_calibrations: Vec<CalibrationRecord<EgsTorqueConverterConfiguration>>
}

// On the TCU itself (At address 0x34900)
#[derive(PackedStruct, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[repr(C)]
#[packed_struct(endian = "lsb")]
pub struct EgsStoredCalibration {
pub magic: u32,
pub len: u16,
pub crc: u16,
pub tcc_cal_name: [u8;16],
#[packed_field(element_size_bytes="52")]
pub tcc_cal: EgsTorqueConverterConfiguration,
pub mech_cal_name: [u8;16],
#[packed_field(element_size_bytes="207")]
pub mech_cal: EgsMechanicalConfiguration,
pub hydr_cal_name: [u8;16],
#[packed_field(element_size_bytes="182")]
pub hydr_cal: EgsHydraulicConfiguration
}
65 changes: 65 additions & 0 deletions backend/src/diag/device_modes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use bitflags::{bitflags};
use ecu_diagnostics::{DiagServerResult, DiagError, kwp2000::KwpSessionType, dynamic_diag::DiagSessionMode};

use super::Nag52Diag;

bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TcuDeviceMode: u16 {
const NORMAL = 1 << 0;
// Bit 1 ?
const ROLLER = 1 << 2;
const SLAVE = 1 << 3;
const TEMPORARY_ERROR = 1 << 4;
// Bit 5?
const ERROR = 1 << 6;
const NO_CALIBRATION = 1 << 7;
// Bit 8?
// Bit 9?
// Bit 10?
// Bit 11?
// Bit 12?
// Bit 13?
// Bit 14?
const CANLOGGER = 1 << 15;
}
}

impl Nag52Diag {
pub fn read_device_mode(&self) -> DiagServerResult<TcuDeviceMode> {
let res = self.with_kwp(|kwp| {
kwp.kwp_set_session(KwpSessionType::ExtendedDiagnostics.into())?;
kwp.send_byte_array_with_response(&[0x30, 0x10, 0x01])
})?;
if res.len() != 5 {
Err(DiagError::InvalidResponseLength)
} else {
let x: u16 = u16::from_be_bytes(res[3..].try_into().unwrap());
//self.set_device_mode(TcuDeviceMode::SLAVE, true)?;
//Ok(TcuDeviceMode::NORMAL)
Ok(TcuDeviceMode::from_bits_retain(x))
}
}

pub fn set_device_mode(&self, mode: TcuDeviceMode, store_in_eeprom: bool) -> DiagServerResult<()> {
let _ = self.with_kwp(|kwp| {
let x = mode.bits();
kwp.kwp_set_session(KwpSessionType::ExtendedDiagnostics.into())?;
kwp.send_byte_array_with_response(&[
0x30,
0x10,
if store_in_eeprom {0x08} else {0x07},
((x >> 8) & 0xFF) as u8,
((x >> 0) & 0xFF) as u8
])
})?;
Ok(())
}

pub fn return_mode_control_to_ecu(&self) -> DiagServerResult<()> {
let _ = self.with_kwp(|kwp| {
kwp.send_byte_array_with_response(&[0x30, 0x10, 0x00])
})?;
Ok(())
}
}
27 changes: 26 additions & 1 deletion backend/src/diag/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ impl Nag52Diag {
}
}

pub fn get_module_settings_desc_partition(&self) -> PartitionInfo {
PartitionInfo {
address: 0x330000,
size: 0x19000,
}
}

pub fn get_coredump_flash_info(&self) -> DiagServerResult<PartitionInfo> {
self.with_kwp(|server| {
server.kwp_read_custom_local_identifier(0x29).map(|res| {
Expand Down Expand Up @@ -53,7 +60,6 @@ impl Nag52Diag {
pub fn get_running_fw_info(&self) -> DiagServerResult<FirmwareHeader> {
self.with_kwp(|server| {
server.kwp_read_custom_local_identifier(0x28).map(|res| {
println!("{:02X?}", res);
FirmwareHeader::unpack_from_slice(&res)
.map_err(|_| DiagError::InvalidResponseLength)
})?
Expand All @@ -79,6 +85,25 @@ impl Nag52Diag {
res
}

pub fn begin_yml_ota(&self, len: u32) -> DiagServerResult<(u32, u16)> {
let part_info_next = self.get_module_settings_desc_partition();
let res = self.with_kwp(|server| {
server.kwp_set_session(KwpSessionTypeByte::Standard(
kwp2000::KwpSessionType::Reprogramming,
))?;
let x = part_info_next.address;
let mut req: Vec<u8> =
vec![0x34, (x >> 16) as u8, (x >> 8) as u8, (x) as u8, OTA_FORMAT];
req.push((len >> 16) as u8);
req.push((len >> 8) as u8);
req.push((len) as u8);
let resp = server.send_byte_array_with_response(&req)?;
let bs = (resp[1] as u16) << 8 | resp[2] as u16;
Ok((part_info_next.address, bs))
});
res
}

pub fn begin_download(&self, partition_info: &PartitionInfo) -> DiagServerResult<u16> {
let res = self.with_kwp(|server| {
server.kwp_set_session(KwpSessionTypeByte::Standard(
Expand Down
1 change: 1 addition & 0 deletions backend/src/diag/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl Display for EgsMode {
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
pub enum PCBVersion {
OnePointOne,
OnePointTwo,
Expand Down
Loading

0 comments on commit a878408

Please sign in to comment.