Skip to content

Commit

Permalink
TwinCAT/BSD for OS Version (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
SWX-Callum authored Dec 11, 2024
1 parent 5a0a71d commit e0d3bf9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 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)
};

// 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,13 +272,17 @@ 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",
};
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)
Expand Down

0 comments on commit e0d3bf9

Please sign in to comment.