Skip to content

Commit

Permalink
Add Basic Sofware Module
Browse files Browse the repository at this point in the history
Added software module with basic methods. A lot of work still to get
this done.
  • Loading branch information
JamesMc86 committed Oct 11, 2022
1 parent 40f44df commit 1337e29
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ni-syscfg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ homepage = "https://github.com/WiresmithTech/ni-syscfg-rs"
ni-syscfg-sys = { path = "../ni-syscfg-sys", version="20.5" }
thiserror = "1"
num-derive = "0.3"
num-traits = "0.2"
num-traits = "0.2"

[[bin]]
name = "ni-syscfg"
path = "bin/ni-syscfg.rs"
19 changes: 19 additions & 0 deletions ni-syscfg/bin/ni-syscfg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::path::PathBuf;

use ni_syscfg::SessionConfig;

fn main() {
let session = SessionConfig::new()
.target("192.168.10.102")
.username("admin")
.unwrap()
.password("labview")
.unwrap()
.connect()
.expect("Session failed");
session
.get_software_image(&PathBuf::from(
r"C:\Users\JamesMcNally\Documents\Delete\TestImage",
))
.unwrap();
}
2 changes: 2 additions & 0 deletions ni-syscfg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod hardware_filter;
mod parameters;
mod resources;
mod session;
mod software;
pub(crate) mod types;

pub use experts::ExpertType;
pub use hardware_filter::{FilterMode, HardwareFilter};
Expand Down
65 changes: 65 additions & 0 deletions ni-syscfg/src/software.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Module for managing software on NI systems.
//!
use std::ffi::CString;
use std::os::raw::c_char;
use std::path::Path;

use ni_syscfg_sys::{NISysCfgCreateSystemImageAsFolder, NISysCfgSetSystemImageFromFolder2};

use crate::error::{api_status, Result};
use crate::types::FfiBoolean;
use crate::Session;

type Uuid = String;

struct ImageInfo {
name: String,
id: Uuid,
}

impl Session {
pub fn get_software_image(&self, image: &Path) -> Result<()> {
let handle = self.handle();
let path = CString::new(image.as_os_str().to_string_lossy().as_ref())?;
let title = std::ptr::null();
let id = std::ptr::null();
let version = std::ptr::null();
let description = std::ptr::null();

unsafe {
api_status(NISysCfgCreateSystemImageAsFolder(
*handle,
title,
id,
version,
description,
FfiBoolean::True as i32,
path.as_ptr(),
std::ptr::null(),
0,
std::ptr::null_mut(),
FfiBoolean::False as i32,
))?;
}
Ok(())
}
pub fn set_software_image(&self, image: &Path) -> Result<()> {
let handle = self.handle();
let path = CString::new(image.as_os_str().to_string_lossy().as_ref())?;

unsafe {
api_status(NISysCfgSetSystemImageFromFolder2(
*handle,
FfiBoolean::True as i32,
path.as_ptr(),
std::ptr::null(),
0,
std::ptr::null_mut(),
FfiBoolean::False as i32,
2,
))?;
}
Ok(())
}
}
11 changes: 11 additions & 0 deletions ni-syscfg/src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Wrappers for a few utility types.
//!
use ni_syscfg_sys::{NISysCfgBool_NISysCfgBoolFalse, NISysCfgBool_NISysCfgBoolTrue};

/// Wraps the constant values for true and false elements.
#[repr(i32)]
pub enum FfiBoolean {
True = NISysCfgBool_NISysCfgBoolTrue,
False = NISysCfgBool_NISysCfgBoolFalse,
}

0 comments on commit 1337e29

Please sign in to comment.