#![allow(unused, clippy::comparison_to_empty, clippy::manual_range_patterns)]
use crate::profile::{ProfileType, typedef};
use crate::proto::*;
#[derive(Debug, Clone)]
pub struct DiveSettings {
pub timestamp: typedef::DateTime,
pub message_index: typedef::MessageIndex,
pub name: String,
pub model: typedef::TissueModelType,
pub gf_low: u8,
pub gf_high: u8,
pub water_type: typedef::WaterType,
pub water_density: f32,
pub po2_warn: u8,
pub po2_critical: u8,
pub po2_deco: u8,
pub safety_stop_enabled: typedef::Bool,
pub bottom_depth: f32,
pub bottom_time: u32,
pub apnea_countdown_enabled: typedef::Bool,
pub apnea_countdown_time: u32,
pub backlight_mode: typedef::DiveBacklightMode,
pub backlight_brightness: u8,
pub backlight_timeout: typedef::BacklightTimeout,
pub repeat_dive_interval: u16,
pub safety_stop_time: u16,
pub heart_rate_source_type: typedef::SourceType,
pub heart_rate_source: u8,
pub travel_gas: typedef::MessageIndex,
pub ccr_low_setpoint_switch_mode: typedef::CcrSetpointSwitchMode,
pub ccr_low_setpoint: u8,
pub ccr_low_setpoint_depth: u32,
pub ccr_high_setpoint_switch_mode: typedef::CcrSetpointSwitchMode,
pub ccr_high_setpoint: u8,
pub ccr_high_setpoint_depth: u32,
pub gas_consumption_display: typedef::GasConsumptionRateType,
pub up_key_enabled: typedef::Bool,
pub dive_sounds: typedef::Tone,
pub last_stop_multiple: u8,
pub no_fly_time_mode: typedef::NoFlyTimeMode,
pub unknown_fields: Vec<Field>,
pub developer_fields: Vec<DeveloperField>,
}
impl DiveSettings {
pub const TIMESTAMP: u8 = 253;
pub const MESSAGE_INDEX: u8 = 254;
pub const NAME: u8 = 0;
pub const MODEL: u8 = 1;
pub const GF_LOW: u8 = 2;
pub const GF_HIGH: u8 = 3;
pub const WATER_TYPE: u8 = 4;
pub const WATER_DENSITY: u8 = 5;
pub const PO2_WARN: u8 = 6;
pub const PO2_CRITICAL: u8 = 7;
pub const PO2_DECO: u8 = 8;
pub const SAFETY_STOP_ENABLED: u8 = 9;
pub const BOTTOM_DEPTH: u8 = 10;
pub const BOTTOM_TIME: u8 = 11;
pub const APNEA_COUNTDOWN_ENABLED: u8 = 12;
pub const APNEA_COUNTDOWN_TIME: u8 = 13;
pub const BACKLIGHT_MODE: u8 = 14;
pub const BACKLIGHT_BRIGHTNESS: u8 = 15;
pub const BACKLIGHT_TIMEOUT: u8 = 16;
pub const REPEAT_DIVE_INTERVAL: u8 = 17;
pub const SAFETY_STOP_TIME: u8 = 18;
pub const HEART_RATE_SOURCE_TYPE: u8 = 19;
pub const HEART_RATE_SOURCE: u8 = 20;
pub const TRAVEL_GAS: u8 = 21;
pub const CCR_LOW_SETPOINT_SWITCH_MODE: u8 = 22;
pub const CCR_LOW_SETPOINT: u8 = 23;
pub const CCR_LOW_SETPOINT_DEPTH: u8 = 24;
pub const CCR_HIGH_SETPOINT_SWITCH_MODE: u8 = 25;
pub const CCR_HIGH_SETPOINT: u8 = 26;
pub const CCR_HIGH_SETPOINT_DEPTH: u8 = 27;
pub const GAS_CONSUMPTION_DISPLAY: u8 = 29;
pub const UP_KEY_ENABLED: u8 = 30;
pub const DIVE_SOUNDS: u8 = 35;
pub const LAST_STOP_MULTIPLE: u8 = 36;
pub const NO_FLY_TIME_MODE: u8 = 37;
pub const fn new() -> Self {
Self {
timestamp: typedef::DateTime(u32::MAX),
message_index: typedef::MessageIndex(u16::MAX),
name: String::new(),
model: typedef::TissueModelType(u8::MAX),
gf_low: u8::MAX,
gf_high: u8::MAX,
water_type: typedef::WaterType(u8::MAX),
water_density: f32::MAX,
po2_warn: u8::MAX,
po2_critical: u8::MAX,
po2_deco: u8::MAX,
safety_stop_enabled: typedef::Bool(u8::MAX),
bottom_depth: f32::MAX,
bottom_time: u32::MAX,
apnea_countdown_enabled: typedef::Bool(u8::MAX),
apnea_countdown_time: u32::MAX,
backlight_mode: typedef::DiveBacklightMode(u8::MAX),
backlight_brightness: u8::MAX,
backlight_timeout: typedef::BacklightTimeout(u8::MAX),
repeat_dive_interval: u16::MAX,
safety_stop_time: u16::MAX,
heart_rate_source_type: typedef::SourceType(u8::MAX),
heart_rate_source: u8::MAX,
travel_gas: typedef::MessageIndex(u16::MAX),
ccr_low_setpoint_switch_mode: typedef::CcrSetpointSwitchMode(u8::MAX),
ccr_low_setpoint: u8::MAX,
ccr_low_setpoint_depth: u32::MAX,
ccr_high_setpoint_switch_mode: typedef::CcrSetpointSwitchMode(u8::MAX),
ccr_high_setpoint: u8::MAX,
ccr_high_setpoint_depth: u32::MAX,
gas_consumption_display: typedef::GasConsumptionRateType(u8::MAX),
up_key_enabled: typedef::Bool(u8::MAX),
dive_sounds: typedef::Tone(u8::MAX),
last_stop_multiple: u8::MAX,
no_fly_time_mode: typedef::NoFlyTimeMode(u8::MAX),
unknown_fields: Vec::new(),
developer_fields: Vec::new(),
}
}
pub fn po2_warn_scaled(&self) -> f64 {
if self.po2_warn == u8::MAX {
return f64::from_bits(u64::MAX);
}
self.po2_warn as f64 / 100.0 - 0.0
}
pub fn set_po2_warn_scaled(&mut self, v: f64) -> &mut DiveSettings {
let unscaled = (v + 0.0) * 100.0;
if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
self.po2_warn = u8::MAX;
return self;
}
self.po2_warn = unscaled as u8;
self
}
pub fn po2_critical_scaled(&self) -> f64 {
if self.po2_critical == u8::MAX {
return f64::from_bits(u64::MAX);
}
self.po2_critical as f64 / 100.0 - 0.0
}
pub fn set_po2_critical_scaled(&mut self, v: f64) -> &mut DiveSettings {
let unscaled = (v + 0.0) * 100.0;
if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
self.po2_critical = u8::MAX;
return self;
}
self.po2_critical = unscaled as u8;
self
}
pub fn po2_deco_scaled(&self) -> f64 {
if self.po2_deco == u8::MAX {
return f64::from_bits(u64::MAX);
}
self.po2_deco as f64 / 100.0 - 0.0
}
pub fn set_po2_deco_scaled(&mut self, v: f64) -> &mut DiveSettings {
let unscaled = (v + 0.0) * 100.0;
if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
self.po2_deco = u8::MAX;
return self;
}
self.po2_deco = unscaled as u8;
self
}
pub fn ccr_low_setpoint_scaled(&self) -> f64 {
if self.ccr_low_setpoint == u8::MAX {
return f64::from_bits(u64::MAX);
}
self.ccr_low_setpoint as f64 / 100.0 - 0.0
}
pub fn set_ccr_low_setpoint_scaled(&mut self, v: f64) -> &mut DiveSettings {
let unscaled = (v + 0.0) * 100.0;
if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
self.ccr_low_setpoint = u8::MAX;
return self;
}
self.ccr_low_setpoint = unscaled as u8;
self
}
pub fn ccr_low_setpoint_depth_scaled(&self) -> f64 {
if self.ccr_low_setpoint_depth == u32::MAX {
return f64::from_bits(u64::MAX);
}
self.ccr_low_setpoint_depth as f64 / 1000.0 - 0.0
}
pub fn set_ccr_low_setpoint_depth_scaled(&mut self, v: f64) -> &mut DiveSettings {
let unscaled = (v + 0.0) * 1000.0;
if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u32::MAX as f64 {
self.ccr_low_setpoint_depth = u32::MAX;
return self;
}
self.ccr_low_setpoint_depth = unscaled as u32;
self
}
pub fn ccr_high_setpoint_scaled(&self) -> f64 {
if self.ccr_high_setpoint == u8::MAX {
return f64::from_bits(u64::MAX);
}
self.ccr_high_setpoint as f64 / 100.0 - 0.0
}
pub fn set_ccr_high_setpoint_scaled(&mut self, v: f64) -> &mut DiveSettings {
let unscaled = (v + 0.0) * 100.0;
if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
self.ccr_high_setpoint = u8::MAX;
return self;
}
self.ccr_high_setpoint = unscaled as u8;
self
}
pub fn ccr_high_setpoint_depth_scaled(&self) -> f64 {
if self.ccr_high_setpoint_depth == u32::MAX {
return f64::from_bits(u64::MAX);
}
self.ccr_high_setpoint_depth as f64 / 1000.0 - 0.0
}
pub fn set_ccr_high_setpoint_depth_scaled(&mut self, v: f64) -> &mut DiveSettings {
let unscaled = (v + 0.0) * 1000.0;
if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u32::MAX as f64 {
self.ccr_high_setpoint_depth = u32::MAX;
return self;
}
self.ccr_high_setpoint_depth = unscaled as u32;
self
}
pub fn last_stop_multiple_scaled(&self) -> f64 {
if self.last_stop_multiple == u8::MAX {
return f64::from_bits(u64::MAX);
}
self.last_stop_multiple as f64 / 10.0 - 0.0
}
pub fn set_last_stop_multiple_scaled(&mut self, v: f64) -> &mut DiveSettings {
let unscaled = (v + 0.0) * 10.0;
if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
self.last_stop_multiple = u8::MAX;
return self;
}
self.last_stop_multiple = unscaled as u8;
self
}
}
impl Default for DiveSettings {
fn default() -> Self {
Self::new()
}
}
impl From<&Message> for DiveSettings {
fn from(mesg: &Message) -> Self {
let mut vals: [&Value; 255] = [const { &Value::Invalid }; 255];
const KNOWN_NUMS: [u64; 4] = [242397216767, 0, 0, 6917529027641081856];
let mut n = 0u64;
for field in &mesg.fields {
n += (KNOWN_NUMS[field.num as usize >> 6] >> (field.num & 63)) & 1 ^ 1
}
let mut unknown_fields: Vec<Field> = Vec::with_capacity(n as usize);
for field in &mesg.fields {
if (KNOWN_NUMS[field.num as usize >> 6] >> (field.num & 63)) & 1 == 0 {
unknown_fields.push(field.clone());
continue;
}
vals[field.num as usize] = &field.value;
}
Self {
timestamp: typedef::DateTime(vals[253].as_u32()),
message_index: typedef::MessageIndex(vals[254].as_u16()),
name: vals[0].as_string(),
model: typedef::TissueModelType(vals[1].as_u8()),
gf_low: vals[2].as_u8(),
gf_high: vals[3].as_u8(),
water_type: typedef::WaterType(vals[4].as_u8()),
water_density: vals[5].as_f32(),
po2_warn: vals[6].as_u8(),
po2_critical: vals[7].as_u8(),
po2_deco: vals[8].as_u8(),
safety_stop_enabled: typedef::Bool(vals[9].as_u8()),
bottom_depth: vals[10].as_f32(),
bottom_time: vals[11].as_u32(),
apnea_countdown_enabled: typedef::Bool(vals[12].as_u8()),
apnea_countdown_time: vals[13].as_u32(),
backlight_mode: typedef::DiveBacklightMode(vals[14].as_u8()),
backlight_brightness: vals[15].as_u8(),
backlight_timeout: typedef::BacklightTimeout(vals[16].as_u8()),
repeat_dive_interval: vals[17].as_u16(),
safety_stop_time: vals[18].as_u16(),
heart_rate_source_type: typedef::SourceType(vals[19].as_u8()),
heart_rate_source: vals[20].as_u8(),
travel_gas: typedef::MessageIndex(vals[21].as_u16()),
ccr_low_setpoint_switch_mode: typedef::CcrSetpointSwitchMode(vals[22].as_u8()),
ccr_low_setpoint: vals[23].as_u8(),
ccr_low_setpoint_depth: vals[24].as_u32(),
ccr_high_setpoint_switch_mode: typedef::CcrSetpointSwitchMode(vals[25].as_u8()),
ccr_high_setpoint: vals[26].as_u8(),
ccr_high_setpoint_depth: vals[27].as_u32(),
gas_consumption_display: typedef::GasConsumptionRateType(vals[29].as_u8()),
up_key_enabled: typedef::Bool(vals[30].as_u8()),
dive_sounds: typedef::Tone(vals[35].as_u8()),
last_stop_multiple: vals[36].as_u8(),
no_fly_time_mode: typedef::NoFlyTimeMode(vals[37].as_u8()),
unknown_fields,
developer_fields: mesg.developer_fields.clone(),
}
}
}
impl From<DiveSettings> for Message {
fn from(m: DiveSettings) -> Self {
let mut arr = [const {
Field {
num: 0,
profile_type: ProfileType(0),
value: Value::Invalid,
is_expanded: false,
}
}; 35];
let mut len = 0usize;
if m.timestamp != typedef::DateTime(u32::MAX) {
arr[len] = Field {
num: 253,
profile_type: ProfileType::DATE_TIME,
value: Value::Uint32(m.timestamp.0),
is_expanded: false,
};
len += 1;
}
if m.message_index != typedef::MessageIndex(u16::MAX) {
arr[len] = Field {
num: 254,
profile_type: ProfileType::MESSAGE_INDEX,
value: Value::Uint16(m.message_index.0),
is_expanded: false,
};
len += 1;
}
if m.name != String::new() {
arr[len] = Field {
num: 0,
profile_type: ProfileType::STRING,
value: Value::String(m.name),
is_expanded: false,
};
len += 1;
}
if m.model != typedef::TissueModelType(u8::MAX) {
arr[len] = Field {
num: 1,
profile_type: ProfileType::TISSUE_MODEL_TYPE,
value: Value::Uint8(m.model.0),
is_expanded: false,
};
len += 1;
}
if m.gf_low != u8::MAX {
arr[len] = Field {
num: 2,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.gf_low),
is_expanded: false,
};
len += 1;
}
if m.gf_high != u8::MAX {
arr[len] = Field {
num: 3,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.gf_high),
is_expanded: false,
};
len += 1;
}
if m.water_type != typedef::WaterType(u8::MAX) {
arr[len] = Field {
num: 4,
profile_type: ProfileType::WATER_TYPE,
value: Value::Uint8(m.water_type.0),
is_expanded: false,
};
len += 1;
}
if m.water_density != f32::MAX {
arr[len] = Field {
num: 5,
profile_type: ProfileType::FLOAT32,
value: Value::Float32(m.water_density),
is_expanded: false,
};
len += 1;
}
if m.po2_warn != u8::MAX {
arr[len] = Field {
num: 6,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.po2_warn),
is_expanded: false,
};
len += 1;
}
if m.po2_critical != u8::MAX {
arr[len] = Field {
num: 7,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.po2_critical),
is_expanded: false,
};
len += 1;
}
if m.po2_deco != u8::MAX {
arr[len] = Field {
num: 8,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.po2_deco),
is_expanded: false,
};
len += 1;
}
if m.safety_stop_enabled != typedef::Bool(u8::MAX) {
arr[len] = Field {
num: 9,
profile_type: ProfileType::BOOL,
value: Value::Uint8(m.safety_stop_enabled.0),
is_expanded: false,
};
len += 1;
}
if m.bottom_depth != f32::MAX {
arr[len] = Field {
num: 10,
profile_type: ProfileType::FLOAT32,
value: Value::Float32(m.bottom_depth),
is_expanded: false,
};
len += 1;
}
if m.bottom_time != u32::MAX {
arr[len] = Field {
num: 11,
profile_type: ProfileType::UINT32,
value: Value::Uint32(m.bottom_time),
is_expanded: false,
};
len += 1;
}
if m.apnea_countdown_enabled != typedef::Bool(u8::MAX) {
arr[len] = Field {
num: 12,
profile_type: ProfileType::BOOL,
value: Value::Uint8(m.apnea_countdown_enabled.0),
is_expanded: false,
};
len += 1;
}
if m.apnea_countdown_time != u32::MAX {
arr[len] = Field {
num: 13,
profile_type: ProfileType::UINT32,
value: Value::Uint32(m.apnea_countdown_time),
is_expanded: false,
};
len += 1;
}
if m.backlight_mode != typedef::DiveBacklightMode(u8::MAX) {
arr[len] = Field {
num: 14,
profile_type: ProfileType::DIVE_BACKLIGHT_MODE,
value: Value::Uint8(m.backlight_mode.0),
is_expanded: false,
};
len += 1;
}
if m.backlight_brightness != u8::MAX {
arr[len] = Field {
num: 15,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.backlight_brightness),
is_expanded: false,
};
len += 1;
}
if m.backlight_timeout != typedef::BacklightTimeout(u8::MAX) {
arr[len] = Field {
num: 16,
profile_type: ProfileType::BACKLIGHT_TIMEOUT,
value: Value::Uint8(m.backlight_timeout.0),
is_expanded: false,
};
len += 1;
}
if m.repeat_dive_interval != u16::MAX {
arr[len] = Field {
num: 17,
profile_type: ProfileType::UINT16,
value: Value::Uint16(m.repeat_dive_interval),
is_expanded: false,
};
len += 1;
}
if m.safety_stop_time != u16::MAX {
arr[len] = Field {
num: 18,
profile_type: ProfileType::UINT16,
value: Value::Uint16(m.safety_stop_time),
is_expanded: false,
};
len += 1;
}
if m.heart_rate_source_type != typedef::SourceType(u8::MAX) {
arr[len] = Field {
num: 19,
profile_type: ProfileType::SOURCE_TYPE,
value: Value::Uint8(m.heart_rate_source_type.0),
is_expanded: false,
};
len += 1;
}
if m.heart_rate_source != u8::MAX {
arr[len] = Field {
num: 20,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.heart_rate_source),
is_expanded: false,
};
len += 1;
}
if m.travel_gas != typedef::MessageIndex(u16::MAX) {
arr[len] = Field {
num: 21,
profile_type: ProfileType::MESSAGE_INDEX,
value: Value::Uint16(m.travel_gas.0),
is_expanded: false,
};
len += 1;
}
if m.ccr_low_setpoint_switch_mode != typedef::CcrSetpointSwitchMode(u8::MAX) {
arr[len] = Field {
num: 22,
profile_type: ProfileType::CCR_SETPOINT_SWITCH_MODE,
value: Value::Uint8(m.ccr_low_setpoint_switch_mode.0),
is_expanded: false,
};
len += 1;
}
if m.ccr_low_setpoint != u8::MAX {
arr[len] = Field {
num: 23,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.ccr_low_setpoint),
is_expanded: false,
};
len += 1;
}
if m.ccr_low_setpoint_depth != u32::MAX {
arr[len] = Field {
num: 24,
profile_type: ProfileType::UINT32,
value: Value::Uint32(m.ccr_low_setpoint_depth),
is_expanded: false,
};
len += 1;
}
if m.ccr_high_setpoint_switch_mode != typedef::CcrSetpointSwitchMode(u8::MAX) {
arr[len] = Field {
num: 25,
profile_type: ProfileType::CCR_SETPOINT_SWITCH_MODE,
value: Value::Uint8(m.ccr_high_setpoint_switch_mode.0),
is_expanded: false,
};
len += 1;
}
if m.ccr_high_setpoint != u8::MAX {
arr[len] = Field {
num: 26,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.ccr_high_setpoint),
is_expanded: false,
};
len += 1;
}
if m.ccr_high_setpoint_depth != u32::MAX {
arr[len] = Field {
num: 27,
profile_type: ProfileType::UINT32,
value: Value::Uint32(m.ccr_high_setpoint_depth),
is_expanded: false,
};
len += 1;
}
if m.gas_consumption_display != typedef::GasConsumptionRateType(u8::MAX) {
arr[len] = Field {
num: 29,
profile_type: ProfileType::GAS_CONSUMPTION_RATE_TYPE,
value: Value::Uint8(m.gas_consumption_display.0),
is_expanded: false,
};
len += 1;
}
if m.up_key_enabled != typedef::Bool(u8::MAX) {
arr[len] = Field {
num: 30,
profile_type: ProfileType::BOOL,
value: Value::Uint8(m.up_key_enabled.0),
is_expanded: false,
};
len += 1;
}
if m.dive_sounds != typedef::Tone(u8::MAX) {
arr[len] = Field {
num: 35,
profile_type: ProfileType::TONE,
value: Value::Uint8(m.dive_sounds.0),
is_expanded: false,
};
len += 1;
}
if m.last_stop_multiple != u8::MAX {
arr[len] = Field {
num: 36,
profile_type: ProfileType::UINT8,
value: Value::Uint8(m.last_stop_multiple),
is_expanded: false,
};
len += 1;
}
if m.no_fly_time_mode != typedef::NoFlyTimeMode(u8::MAX) {
arr[len] = Field {
num: 37,
profile_type: ProfileType::NO_FLY_TIME_MODE,
value: Value::Uint8(m.no_fly_time_mode.0),
is_expanded: false,
};
len += 1;
}
Message {
header: 0,
num: typedef::MesgNum::DIVE_SETTINGS,
fields: {
let mut fields: Vec<Field> = Vec::with_capacity(len + m.unknown_fields.len());
fields.extend_from_slice(&arr[..len]);
fields.extend_from_slice(&m.unknown_fields);
fields
},
developer_fields: m.developer_fields,
}
}
}