Skip to content

Commit 709e020

Browse files
committed
v2.3.0: GUI platform support and network devices
Backend (Tauri): - DevicePlatform enum with 9 platforms (RP2040, RP2350, STM32F1/F4, ESP32, Arduino GIGA, RPi, OPi) - DeviceCapabilities struct (NV-DDR, HW ECC, WiFi, BT, USB HS) - NetworkDevice for TCP/Unix socket connections to SBC - ActiveDevice enum supporting USB and Network connections - New commands: get_device_info, get_platform_info, add_network_device, connect_network_device - Mock mode with platform selection and capabilities Frontend (React): - PlatformInfo component showing connected device capabilities - NetworkDeviceDialog for adding SBC devices via TCP - Updated device list with platform icons and network badges - Extended DeviceInfo interface with platform/capabilities Styling: - Platform info panel with capability badges - Network device dialog with form inputs - Device list improvements for platform display
1 parent 57569f9 commit 709e020

11 files changed

Lines changed: 1153 additions & 16 deletions

File tree

openflash.wiki

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit eba80288605fb74aac5344e4bef5eada5ecad375
1+
Subproject commit e681ed16e3fc05422162b39b2c22e1d0877b8539

openflash/gui/src-tauri/src/command.rs

Lines changed: 197 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::sync::Mutex;
55
use tauri::{AppHandle, Emitter, State};
66

77
use crate::config::AppConfig;
8-
use crate::device::{ChipInfo, DeviceInfo, DeviceManager, FlashInterface, UfsLunInfo};
8+
use crate::device::{ChipInfo, DeviceInfo, DeviceManager, FlashInterface, UfsLunInfo,
9+
DevicePlatform, DeviceCapabilities, ConnectionType};
910
use crate::mock;
1011

1112
#[tauri::command]
@@ -1182,3 +1183,198 @@ pub fn add_recent_file(path: String, config: State<'_, Mutex<AppConfig>>) -> Res
11821183
cfg.add_recent_file(&path);
11831184
cfg.save()
11841185
}
1186+
1187+
// ============================================================================
1188+
// Platform commands (v2.3)
1189+
// ============================================================================
1190+
1191+
/// Platform info response
1192+
#[derive(Serialize, Deserialize)]
1193+
pub struct PlatformInfo {
1194+
pub platform: String,
1195+
pub platform_id: u8,
1196+
pub icon: String,
1197+
pub name: String,
1198+
pub is_sbc: bool,
1199+
pub capabilities: DeviceCapabilitiesInfo,
1200+
pub protocol_version: u8,
1201+
pub firmware_version: Option<String>,
1202+
}
1203+
1204+
#[derive(Serialize, Deserialize)]
1205+
pub struct DeviceCapabilitiesInfo {
1206+
pub parallel_nand: bool,
1207+
pub spi_nand: bool,
1208+
pub spi_nor: bool,
1209+
pub emmc: bool,
1210+
pub nvddr: bool,
1211+
pub hardware_ecc: bool,
1212+
pub wifi: bool,
1213+
pub bluetooth: bool,
1214+
pub high_speed_usb: bool,
1215+
}
1216+
1217+
/// Get detailed device info including platform and capabilities
1218+
#[tauri::command]
1219+
pub async fn get_device_info(
1220+
device_manager: State<'_, Mutex<DeviceManager>>,
1221+
) -> Result<PlatformInfo, String> {
1222+
if mock::is_mock_connected() {
1223+
let response = mock::get_mock_device_info_response();
1224+
let platform = DevicePlatform::from_id(response[1]);
1225+
let caps = mock::get_mock_capabilities(platform);
1226+
1227+
return Ok(PlatformInfo {
1228+
platform: format!("{:?}", platform),
1229+
platform_id: response[1],
1230+
icon: platform.icon().to_string(),
1231+
name: platform.name().to_string(),
1232+
is_sbc: platform.is_sbc(),
1233+
capabilities: DeviceCapabilitiesInfo {
1234+
parallel_nand: caps.parallel_nand,
1235+
spi_nand: caps.spi_nand,
1236+
spi_nor: caps.spi_nor,
1237+
emmc: caps.emmc,
1238+
nvddr: caps.nvddr,
1239+
hardware_ecc: caps.hardware_ecc,
1240+
wifi: caps.wifi,
1241+
bluetooth: caps.bluetooth,
1242+
high_speed_usb: caps.high_speed_usb,
1243+
},
1244+
protocol_version: response[2],
1245+
firmware_version: Some("2.3.0".to_string()),
1246+
});
1247+
}
1248+
1249+
let device = {
1250+
let manager = device_manager.lock().map_err(|e| e.to_string())?;
1251+
manager.get_active_device().ok_or("No device connected")?
1252+
};
1253+
1254+
let dev = device.lock().await;
1255+
1256+
// Send GetDeviceInfo command (0xBB from scripting module, or 0x01 for basic info)
1257+
let response = dev
1258+
.send_command(openflash_core::protocol::Command::Ping, &[])
1259+
.await?;
1260+
1261+
// For now, return basic info - real implementation would parse device response
1262+
let platform = DevicePlatform::Unknown;
1263+
1264+
Ok(PlatformInfo {
1265+
platform: format!("{:?}", platform),
1266+
platform_id: 0,
1267+
icon: platform.icon().to_string(),
1268+
name: platform.name().to_string(),
1269+
is_sbc: platform.is_sbc(),
1270+
capabilities: DeviceCapabilitiesInfo {
1271+
parallel_nand: true,
1272+
spi_nand: true,
1273+
spi_nor: true,
1274+
emmc: true,
1275+
nvddr: false,
1276+
hardware_ecc: false,
1277+
wifi: false,
1278+
bluetooth: false,
1279+
high_speed_usb: false,
1280+
},
1281+
protocol_version: if response.len() >= 2 { response[1] } else { 0 },
1282+
firmware_version: None,
1283+
})
1284+
}
1285+
1286+
/// Get platform info for the current connection
1287+
#[tauri::command]
1288+
pub fn get_platform_info(
1289+
device_manager: State<'_, Mutex<DeviceManager>>,
1290+
) -> Result<Option<PlatformInfo>, String> {
1291+
let manager = device_manager.lock().map_err(|e| e.to_string())?;
1292+
1293+
if let Some(platform) = manager.get_platform() {
1294+
let caps = manager.get_capabilities().cloned().unwrap_or_default();
1295+
1296+
Ok(Some(PlatformInfo {
1297+
platform: format!("{:?}", platform),
1298+
platform_id: match platform {
1299+
DevicePlatform::Rp2040 => 0x01,
1300+
DevicePlatform::Stm32f1 => 0x02,
1301+
DevicePlatform::Stm32f4 => 0x03,
1302+
DevicePlatform::Esp32 => 0x04,
1303+
DevicePlatform::Rp2350 => 0x05,
1304+
DevicePlatform::RaspberryPi => 0x10,
1305+
DevicePlatform::OrangePi => 0x11,
1306+
DevicePlatform::ArduinoGiga => 0x20,
1307+
DevicePlatform::Unknown => 0x00,
1308+
},
1309+
icon: platform.icon().to_string(),
1310+
name: platform.name().to_string(),
1311+
is_sbc: platform.is_sbc(),
1312+
capabilities: DeviceCapabilitiesInfo {
1313+
parallel_nand: caps.parallel_nand,
1314+
spi_nand: caps.spi_nand,
1315+
spi_nor: caps.spi_nor,
1316+
emmc: caps.emmc,
1317+
nvddr: caps.nvddr,
1318+
hardware_ecc: caps.hardware_ecc,
1319+
wifi: caps.wifi,
1320+
bluetooth: caps.bluetooth,
1321+
high_speed_usb: caps.high_speed_usb,
1322+
},
1323+
protocol_version: 0x23,
1324+
firmware_version: None,
1325+
}))
1326+
} else {
1327+
Ok(None)
1328+
}
1329+
}
1330+
1331+
/// Add a network device (SBC) to the device list
1332+
#[tauri::command]
1333+
pub fn add_network_device(
1334+
host: String,
1335+
port: u16,
1336+
name: Option<String>,
1337+
device_manager: State<'_, Mutex<DeviceManager>>,
1338+
) -> Result<(), String> {
1339+
let mut manager = device_manager.lock().map_err(|e| e.to_string())?;
1340+
manager.add_network_device(host, port, name);
1341+
Ok(())
1342+
}
1343+
1344+
/// Connect to a network device (TCP)
1345+
#[tauri::command]
1346+
pub async fn connect_network_device(
1347+
host: String,
1348+
port: u16,
1349+
device_manager: State<'_, Mutex<DeviceManager>>,
1350+
) -> Result<(), String> {
1351+
// For mock devices
1352+
if host == "localhost" && port == 9999 && mock::is_mock_enabled() {
1353+
return mock::mock_connect(&format!("mock:tcp:{}:{}", host, port));
1354+
}
1355+
1356+
let mut manager = device_manager.lock().map_err(|e| e.to_string())?;
1357+
1358+
// Use tokio runtime for async connection
1359+
// Note: This is a simplified version - real implementation would use proper async
1360+
Err("Network connection not yet implemented for real devices".to_string())
1361+
}
1362+
1363+
/// Set mock platform for testing
1364+
#[tauri::command]
1365+
pub fn set_mock_platform(platform: String) -> Result<(), String> {
1366+
let platform = match platform.to_lowercase().as_str() {
1367+
"rp2040" | "pico" => DevicePlatform::Rp2040,
1368+
"rp2350" | "pico2" => DevicePlatform::Rp2350,
1369+
"stm32f1" | "bluepill" => DevicePlatform::Stm32f1,
1370+
"stm32f4" | "blackpill" => DevicePlatform::Stm32f4,
1371+
"esp32" => DevicePlatform::Esp32,
1372+
"raspberrypi" | "rpi" => DevicePlatform::RaspberryPi,
1373+
"orangepi" | "opi" => DevicePlatform::OrangePi,
1374+
"arduinogiga" | "giga" => DevicePlatform::ArduinoGiga,
1375+
_ => return Err(format!("Unknown platform: {}", platform)),
1376+
};
1377+
1378+
mock::set_mock_platform(platform);
1379+
Ok(())
1380+
}

0 commit comments

Comments
 (0)