Skip to content

start to fix a1 support #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions bambulabs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,26 @@
let msg_opt = match ep.poll().await {
Ok(msg_opt) => msg_opt,
Err(err) => {
if let rumqttc::ConnectionError::MqttState(rumqttc::StateError::Io(err)) = err {
tracing::error!("Error polling for message: {:?}", err);
tracing::warn!("Reconnecting...");
// We are in a bad state and should reconnect.
let opts = Self::get_config(&self.ip, &self.access_code)?;
let (client, event_loop) = rumqttc::AsyncClient::new(opts, 25);
drop(ep);
self.client = Arc::new(client);
self.event_loop = Arc::new(Mutex::new(event_loop));
tracing::warn!("Reconnected.");
return Ok(());
match err {
rumqttc::ConnectionError::MqttState(rumqttc::StateError::Io(err)) => {
tracing::error!("Error polling for message: {:?}", err);

Check warning on line 96 in bambulabs/src/client.rs

View check run for this annotation

Codecov / codecov/patch

bambulabs/src/client.rs#L94-L96

Added lines #L94 - L96 were not covered by tests
}
rumqttc::ConnectionError::MqttState(rumqttc::StateError::AwaitPingResp) => {
tracing::error!("Error polling for message: AwaitPingResp");

Check warning on line 99 in bambulabs/src/client.rs

View check run for this annotation

Codecov / codecov/patch

bambulabs/src/client.rs#L99

Added line #L99 was not covered by tests
}
_ => {
tracing::error!("Error polling for message: {:?}; aborting", err);
return Ok(());

Check warning on line 103 in bambulabs/src/client.rs

View check run for this annotation

Codecov / codecov/patch

bambulabs/src/client.rs#L102-L103

Added lines #L102 - L103 were not covered by tests
}
}

tracing::error!("Error polling for message: {:?}", err);
tracing::warn!("Reconnecting...");

Check warning on line 106 in bambulabs/src/client.rs

View check run for this annotation

Codecov / codecov/patch

bambulabs/src/client.rs#L106

Added line #L106 was not covered by tests
// We are in a bad state and should reconnect.
let opts = Self::get_config(&self.ip, &self.access_code)?;
let (client, event_loop) = rumqttc::AsyncClient::new(opts, 25);
drop(ep);
self.client = Arc::new(client);
self.event_loop = Arc::new(Mutex::new(event_loop));
tracing::warn!("Reconnected.");

Check warning on line 113 in bambulabs/src/client.rs

View check run for this annotation

Codecov / codecov/patch

bambulabs/src/client.rs#L108-L113

Added lines #L108 - L113 were not covered by tests
return Ok(());
}
};
Expand Down
4 changes: 2 additions & 2 deletions bambulabs/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ pub struct PushStatus {
/// The upload.
pub upload: Option<PrintUpload>,
/// The nozzle diameter.
pub nozzle_diameter: NozzleDiameter,
pub nozzle_diameter: Option<NozzleDiameter>,
/// The nozzle temperature.
pub nozzle_temper: Option<f64>,
/// The nozzle type.
Expand Down Expand Up @@ -558,7 +558,7 @@ pub enum GcodeState {
#[derive(Debug, Clone, PartialEq, Eq, Deserialize_repr, JsonSchema, Copy, FromStr, Display)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
#[repr(i8)]
#[repr(i16)]
pub enum Stage {
/// Nothing.
Nothing = -1,
Expand Down
1 change: 1 addition & 0 deletions bambulabs/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
let payload = publish.payload.clone();

if let Ok(payload) = std::str::from_utf8(&payload) {
tracing::warn!("{}", payload);

Check warning on line 11 in bambulabs/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

bambulabs/src/parser.rs#L11

Added line #L11 was not covered by tests
match serde_json::from_str::<Message>(payload)
.map_err(|err| format_serde_error::SerdeError::new(payload.to_string(), err))
{
Expand Down
42 changes: 0 additions & 42 deletions openapi/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@
"description": "The current stage of the machine as defined by Bambu which can include errors, etc.",
"nullable": true
},
"nozzle_diameter": {
"allOf": [
{
"$ref": "#/components/schemas/NozzleDiameter"
}
],
"description": "The nozzle diameter of the machine."
},
"type": {
"enum": [
"bambu"
Expand All @@ -90,7 +82,6 @@
}
},
"required": [
"nozzle_diameter",
"type"
],
"type": "object"
Expand Down Expand Up @@ -589,39 +580,6 @@
}
]
},
"NozzleDiameter": {
"description": "A nozzle diameter.",
"oneOf": [
{
"description": "0.2mm.",
"enum": [
"0.2"
],
"type": "string"
},
{
"description": "0.4mm.",
"enum": [
"0.4"
],
"type": "string"
},
{
"description": "0.6mm.",
"enum": [
"0.6"
],
"type": "string"
},
{
"description": "0.8mm.",
"enum": [
"0.8"
],
"type": "string"
}
]
},
"Pong": {
"description": "The response from the `/ping` endpoint.",
"properties": {
Expand Down
14 changes: 12 additions & 2 deletions src/bambu/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,19 @@
anyhow::bail!("Failed to get status");
};

let nozzle_diameter: f64 = match self.config.nozzle_diameter {
Some(nozzle_diameter) => nozzle_diameter,
None => status
.nozzle_diameter
.ok_or(anyhow::anyhow!(
"no nozzle in printer api response, and none set in the config"
))?
.into(),

Check warning on line 122 in src/bambu/control.rs

View check run for this annotation

Codecov / codecov/patch

src/bambu/control.rs#L115-L122

Added lines #L115 - L122 were not covered by tests
};

let default = HardwareConfiguration::Fdm {
config: FdmHardwareConfiguration {
nozzle_diameter: status.nozzle_diameter.into(),
nozzle_diameter,

Check warning on line 127 in src/bambu/control.rs

View check run for this annotation

Codecov / codecov/patch

src/bambu/control.rs#L127

Added line #L127 was not covered by tests
filaments: vec![Filament {
material: FilamentMaterial::Pla,
..Default::default()
Expand Down Expand Up @@ -160,7 +170,7 @@

Ok(HardwareConfiguration::Fdm {
config: FdmHardwareConfiguration {
nozzle_diameter: status.nozzle_diameter.into(),
nozzle_diameter,

Check warning on line 173 in src/bambu/control.rs

View check run for this annotation

Codecov / codecov/patch

src/bambu/control.rs#L173

Added line #L173 was not covered by tests
filaments,
loaded_filament_idx: nams.tray_now.map(|v| v.parse().unwrap_or(0)),
},
Expand Down
5 changes: 5 additions & 0 deletions src/bambu/discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@

/// The access code for the printer.
pub access_code: String,

/// If set, override returned Nozzle Diameter (or if the printer
/// does not return one).
pub nozzle_diameter: Option<f64>,
}

const BAMBU_URN: &str = "urn:bambulab-com:device:3dprinter:1";
Expand Down Expand Up @@ -258,6 +262,7 @@
machine_api_id.clone(),
RwLock::new(Machine::new(
Bambu {
config: config.clone(),

Check warning on line 265 in src/bambu/discover.rs

View check run for this annotation

Codecov / codecov/patch

src/bambu/discover.rs#L265

Added line #L265 was not covered by tests
info,
client: Arc::new(client),
},
Expand Down
1 change: 1 addition & 0 deletions src/bambu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::MachineMakeModel;
pub struct Bambu {
client: Arc<Client>,
info: PrinterInfo,
config: Config,
}

/// Information regarding a discovered Bambu Labs printer.
Expand Down
4 changes: 1 addition & 3 deletions src/server/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ pub enum ExtraMachineInfoResponse {
Bambu {
/// The current stage of the machine as defined by Bambu which can include errors, etc.
current_stage: Option<bambulabs::message::Stage>,
/// The nozzle diameter of the machine.
nozzle_diameter: bambulabs::message::NozzleDiameter,

// Only run in debug mode. This is just to help us know what information we have.
#[cfg(debug_assertions)]
#[cfg(not(test))]
Expand Down Expand Up @@ -122,7 +121,6 @@ impl MachineInfoResponse {
.ok_or_else(|| anyhow::anyhow!("no status for bambu"))?;
Some(ExtraMachineInfoResponse::Bambu {
current_stage: status.stg_cur,
nozzle_diameter: status.nozzle_diameter,
#[cfg(debug_assertions)]
#[cfg(not(test))]
raw_status: status,
Expand Down