Skip to content

Commit

Permalink
Merge pull request #1 from Simworx/feature/twincat_bsd_os_version
Browse files Browse the repository at this point in the history
Added addtional check for if bsd or not
  • Loading branch information
SWX-Callum authored Dec 4, 2024
2 parents 5a0a71d + b254cf8 commit 898733b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ pub fn get_info(target: (&str, u16)) -> Result<SysInfo> {
(0, 0, 0)
};

Check warning on line 262 in src/udp.rs

View workflow job for this annotation

GitHub Actions / Test (1.63.0)

Diff in /home/runner/work/ads-rs/ads-rs/src/udp.rs

Check warning on line 262 in src/udp.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

Diff in /home/runner/work/ads-rs/ads-rs/src/udp.rs

Check warning on line 262 in src/udp.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

Diff in /home/runner/work/ads-rs/ads-rs/src/udp.rs
// Parse OS version. This is a Windows OSVERSIONINFO structure, which
// Parse OS version. If Windows OSVERSIONINFO structure, it will
// consists of major/minor/build versions, the platform, and a "service
// pack" string, coded as UTF-16. It is not known how the data looks on
// non-Windows devices, but hopefully the format is kept the same.
// pack" string, coded as UTF-16.
// If TwinCAT/BSD currently it will give major minor and build that is displayed
let os_version = if let Some(mut bytes) = reply.get_bytes(Tag::OSVersion) {
if bytes.len() >= 22 {
// Size of the structure (redundant).
Expand All @@ -272,20 +272,26 @@ pub fn get_info(target: (&str, u16)) -> Result<SysInfo> {
let minor = bytes.read_u32::<LE>().expect("size");
let build = bytes.read_u32::<LE>().expect("size");
let platform = match bytes.read_u32::<LE>().expect("size") {
0 => "TwinCAT/BSD",
1 => "TC/RTOS",
2 => "Windows NT",
3 => "Windows CE",
_ => "Unknown platform",
};

Check warning on line 280 in src/udp.rs

View workflow job for this annotation

GitHub Actions / Test (1.63.0)

Diff in /home/runner/work/ads-rs/ads-rs/src/udp.rs

Check warning on line 280 in src/udp.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

Diff in /home/runner/work/ads-rs/ads-rs/src/udp.rs

Check warning on line 280 in src/udp.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

Diff in /home/runner/work/ads-rs/ads-rs/src/udp.rs
let string = if platform == "TC/RTOS" {
bytes.iter().take_while(|&&b| b != 0).map(|&b| b as char).collect()
}
else if platform == "TwinCAT/BSD" {
// The following data is TwinCAT/BSD in bytes. But we know the platform from 0.
"".into()
} else {
iter::from_fn(|| bytes.read_u16::<LE>().ok())
.take_while(|&ch| ch != 0)
.filter_map(|ch| char::from_u32(ch as u32))
.collect()

Check warning on line 291 in src/udp.rs

View workflow job for this annotation

GitHub Actions / Test (1.63.0)

Diff in /home/runner/work/ads-rs/ads-rs/src/udp.rs

Check warning on line 291 in src/udp.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

Diff in /home/runner/work/ads-rs/ads-rs/src/udp.rs

Check warning on line 291 in src/udp.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

Diff in /home/runner/work/ads-rs/ads-rs/src/udp.rs
};
(platform, major, minor, build, string)

} else {
("Unknown OS info format", 0, 0, 0, "".into())
}
Expand Down

0 comments on commit 898733b

Please sign in to comment.