#[repr(i32)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Status {
Success = 0,
Done = 1,
Unsupported = -1,
InvalidArgs = -2,
NoMemory = -3,
NoDevice = -4,
NoAccess = -5,
Io = -6,
Timeout = -7,
Protocol = -8,
DataFormat = -9,
Cancelled = -10,
}
impl TryFrom<i32> for Status {
type Error = String;
fn try_from(value: i32) -> Result<Status, Self::Error> {
let result = match value {
0 => Self::Success,
1 => Self::Done,
-1 => Self::Unsupported,
-2 => Self::InvalidArgs,
-3 => Self::NoMemory,
-4 => Self::NoDevice,
-5 => Self::NoAccess,
-6 => Self::Io,
-7 => Self::Timeout,
-8 => Self::Protocol,
-9 => Self::DataFormat,
-10 => Self::Cancelled,
_ => return Err(format!("Invalid status: {value}")),
};
Ok(result)
}
}
#[repr(u32)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Transport {
None = 0,
Serial = 1 << 0,
Usb = 1 << 1,
UsbHid = 1 << 2,
Irda = 1 << 3,
Bluetooth = 1 << 4,
Ble = 1 << 5,
}
impl From<u32> for Transport {
fn from(value: u32) -> Self {
match value {
0x00000001 => Self::Serial,
0x00000010 => Self::Usb,
0x00000100 => Self::UsbHid,
0x00001000 => Self::Irda,
0x00010000 => Self::Bluetooth,
0x00100000 => Self::Ble,
_ => Self::None,
}
}
}
impl Transport {
pub fn vec_from_bitflag(value: u32) -> Vec<Transport> {
let mut transports = Vec::new();
if value & (Transport::Usb as u32) != 0 {
transports.push(Self::Usb);
}
if value & (Self::UsbHid as u32) != 0 {
transports.push(Self::UsbHid);
}
if value & (Self::Ble as u32) != 0 {
transports.push(Self::Ble);
}
if value & (Self::Bluetooth as u32) != 0 {
transports.push(Self::Bluetooth);
}
if value & (Self::Serial as u32) != 0 {
transports.push(Self::Serial);
}
if value & (Self::Irda as u32) != 0 {
transports.push(Self::Irda);
}
transports
}
}
#[repr(u32)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Family {
None = 0,
SuuntoSolution = 1 << 16,
SuuntoEon,
SuuntoVyper,
SuuntoVyper2,
SuuntoD9,
SuuntoEonSteel,
ReefnetSensus = 2 << 16,
ReefnetSensusPro,
ReefnetSensusUltra,
UwatecAladin = 3 << 16,
UwatecMemoMouse,
UwatecSmart,
UwatecMeridian,
UwatecG2,
OceanicVtPro = 4 << 16,
OceanicVeo250,
OceanicAtom2,
MaresNemo = 5 << 16,
MaresPuck,
MaresDarwin,
MaresIconHD,
HwOstc = 6 << 16,
HwFrog,
HwOstc3,
CressiEdy = 7 << 16,
CressiLeonardo,
CressiGoa,
ZeagleN2ition3 = 8 << 16,
AtomicsCobalt = 9 << 16,
ShearwaterPredator = 10 << 16,
ShearwaterPetrel,
DiveRiteNitekQ = 11 << 16,
CitizenAqualand = 12 << 16,
DiveSystemIDive = 13 << 16,
CochranCommander = 14 << 16,
TecdivingDivecomputerEu = 15 << 16,
McLeanExtreme = 16 << 16,
LiquivisionLynx = 17 << 16,
SporasubSp2 = 18 << 16,
DeepSixExcursion = 19 << 16,
SeacScreen = 20 << 16,
DeepbluCosmiq = 21 << 16,
OceansS1 = 22 << 16,
DivesoftFreedom = 23 << 16,
}
impl From<u32> for Family {
fn from(value: u32) -> Self {
match value {
0 => Family::None,
0x00010000 => Family::SuuntoSolution,
0x00010001 => Family::SuuntoEon,
0x00010002 => Family::SuuntoVyper,
0x00010003 => Family::SuuntoVyper2,
0x00010004 => Family::SuuntoD9,
0x00010005 => Family::SuuntoEonSteel,
0x00020000 => Family::ReefnetSensus,
0x00020001 => Family::ReefnetSensusPro,
0x00020002 => Family::ReefnetSensusUltra,
0x00030000 => Family::UwatecAladin,
0x00030001 => Family::UwatecMemoMouse,
0x00030002 => Family::UwatecSmart,
0x00030003 => Family::UwatecMeridian,
0x00030004 => Family::UwatecG2,
0x00040000 => Family::OceanicVtPro,
0x00040001 => Family::OceanicVeo250,
0x00040002 => Family::OceanicAtom2,
0x00050000 => Family::MaresNemo,
0x00050001 => Family::MaresPuck,
0x00050002 => Family::MaresDarwin,
0x00050003 => Family::MaresIconHD,
0x00060000 => Family::HwOstc,
0x00060001 => Family::HwFrog,
0x00060002 => Family::HwOstc3,
0x00070000 => Family::CressiEdy,
0x00070001 => Family::CressiLeonardo,
0x00070002 => Family::CressiGoa,
0x00080000 => Family::ZeagleN2ition3,
0x00090000 => Family::AtomicsCobalt,
0x000A0000 => Family::ShearwaterPredator,
0x000A0001 => Family::ShearwaterPetrel,
0x000B0000 => Family::DiveRiteNitekQ,
0x000C0000 => Family::CitizenAqualand,
0x000D0000 => Family::DiveSystemIDive,
0x000E0000 => Family::CochranCommander,
0x000F0000 => Family::TecdivingDivecomputerEu,
0x00100000 => Family::McLeanExtreme,
0x00110000 => Family::LiquivisionLynx,
0x00120000 => Family::SporasubSp2,
0x00130000 => Family::DeepSixExcursion,
0x00140000 => Family::SeacScreen,
0x00150000 => Family::DeepbluCosmiq,
0x00160000 => Family::OceansS1,
0x00170000 => Family::DivesoftFreedom,
_ => Family::None, }
}
}