Skip to content
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

megarefactor #69

Merged
merged 163 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
e8ffdda
Start to think about new traits
paultag Aug 8, 2024
a06d8fb
more noodling
paultag Aug 8, 2024
6033e14
start a massive restructure
paultag Aug 8, 2024
40dd71b
add in skel for printers
paultag Aug 8, 2024
c48e728
chunks of work at a time
paultag Aug 8, 2024
445d77f
continue reworking names
paultag Aug 8, 2024
ac7db9b
docs
paultag Aug 8, 2024
de8c5ab
Start to re-add the slicers
paultag Aug 8, 2024
aed1ef7
delete the tmpfile after reading it
paultag Aug 8, 2024
a78673a
no longer todo
paultag Aug 8, 2024
6542f2e
fix up deps
paultag Aug 8, 2024
0e1e065
begin to re-add bambu a step at a time
paultag Aug 8, 2024
4f69ee2
O N T O L O G Y
paultag Aug 8, 2024
b20be3a
more hackery
paultag Aug 8, 2024
e661a84
export
paultag Aug 8, 2024
199bef0
more hackery
paultag Aug 8, 2024
4f17fed
make the control channel cloneable, since the client is in an arc
paultag Aug 8, 2024
effbf72
upd
paultag Aug 8, 2024
787ffab
start to work through traits
paultag Aug 8, 2024
3f729d4
mm
paultag Aug 8, 2024
42c92c1
fix
paultag Aug 8, 2024
e7115e9
start to add in more and more
paultag Aug 8, 2024
a1fd24c
this is gonna use some brain thinkin
paultag Aug 8, 2024
1446be5
change trait to accept a file for now
paultag Aug 8, 2024
d0e50e7
fix docs
paultag Aug 8, 2024
2c6c16b
start to re-add discovery
paultag Aug 9, 2024
18c0564
more
paultag Aug 9, 2024
5d2440a
add in discovery
paultag Aug 9, 2024
1ed6ec0
update
paultag Aug 9, 2024
294cb63
clips
paultag Aug 9, 2024
36d331e
add in MachineInfo loop
paultag Aug 9, 2024
e0e925e
remove control
paultag Aug 9, 2024
8e649e8
more refactor
paultag Aug 9, 2024
e0ecc8c
add connect helper
paultag Aug 9, 2024
cb33db3
move max
paultag Aug 10, 2024
8abaffa
fix
paultag Aug 10, 2024
7a41c84
Start to add in Moonraker based printers
paultag Aug 12, 2024
e66a5fe
neptune 4
paultag Aug 12, 2024
10da0a8
export Client
paultag Aug 12, 2024
fc35cb5
start to hack in Any
paultag Aug 12, 2024
7ec2cf9
fix clone
paultag Aug 12, 2024
fce8a20
fix import
paultag Aug 12, 2024
94bcaf0
any -> any machine
paultag Aug 12, 2024
801e45e
Update dependabot.yml
jessfraz Aug 12, 2024
d1b7821
clap bump
paultag Aug 13, 2024
f60c088
fix get version and skirt
jessfraz Aug 12, 2024
577ee42
update opena[pi
jessfraz Aug 12, 2024
269d938
re-add orca
paultag Aug 13, 2024
d0e7621
start to work on raw gcode interface
paultag Aug 13, 2024
9c29601
gcode
paultag Aug 13, 2024
714663e
update
paultag Aug 13, 2024
6447b68
whoops
paultag Aug 13, 2024
b1cf27d
crate
paultag Aug 13, 2024
72d565d
AnySlicer enum
paultag Aug 13, 2024
f672ff5
update
paultag Aug 13, 2024
f1b3510
no need
paultag Aug 13, 2024
c794552
add in new
paultag Aug 13, 2024
7cfbf24
punch through make/model
paultag Aug 13, 2024
02371bd
update to write more
paultag Aug 13, 2024
6b5298e
gcode
paultag Aug 13, 2024
b99388c
update
paultag Aug 13, 2024
b319f3c
add helper
paultag Aug 13, 2024
582cabf
start to re-add the API surface
paultag Aug 13, 2024
2fcb00c
forget slicer in the control, seperate them out
paultag Aug 14, 2024
4181914
start to build out the binding between machine and slicer
paultag Aug 14, 2024
16cb4e1
update note
paultag Aug 14, 2024
c6076dc
update
paultag Aug 14, 2024
4b3ba10
more mut
paultag Aug 14, 2024
b28bd98
list of machines
paultag Aug 14, 2024
40b03bf
jsonschema
paultag Aug 14, 2024
a99a8af
ok lets gooo
paultag Aug 14, 2024
34e2ebc
chip away
paultag Aug 14, 2024
c65c0d6
reduce mutexes
paultag Aug 14, 2024
f17cfe2
add in more tracing
paultag Aug 14, 2024
33956e6
machine endpoint
paultag Aug 14, 2024
a5e4e8d
more http
paultag Aug 14, 2024
d3de973
more hackery
paultag Aug 14, 2024
6020596
handle gcode
paultag Aug 14, 2024
d17390f
great trait rename; add .3mf
paultag Aug 14, 2024
c781fe7
start to add .3mf support
paultag Aug 14, 2024
9a1e801
continue to gut the formats
paultag Aug 14, 2024
6396bb7
stub out bambu
paultag Aug 14, 2024
5bbdade
chip away at more config
paultag Aug 14, 2024
56f7e18
update config more
paultag Aug 14, 2024
cfd6611
use the machines
paultag Aug 14, 2024
470574b
move bambu to 3mf
paultag Aug 14, 2024
94489d4
remove Discover trait
paultag Aug 14, 2024
b45c636
Merge remote-tracking branch 'origin/main' into paultag/refactor
paultag Aug 14, 2024
8dfa42f
fix docs
paultag Aug 14, 2024
6c6f603
re-add old tests
paultag Aug 15, 2024
407992d
clap clap
paultag Aug 15, 2024
571f224
hack more in
paultag Aug 15, 2024
e93698a
Revert "hack more in"
paultag Aug 15, 2024
36a7cc3
fix bind
paultag Aug 15, 2024
8a921e2
more
paultag Aug 15, 2024
eeb0dfd
tweaks to readme
paultag Aug 15, 2024
17ec560
add in extras
paultag Aug 15, 2024
332f39e
stub in extras
paultag Aug 15, 2024
a010a01
Merge remote-tracking branch 'origin/main' into paultag/refactor
paultag Aug 15, 2024
68d2fb6
fuckin hell
paultag Aug 15, 2024
7f64a3d
remove borrow
paultag Aug 15, 2024
8de0c57
add in noop stub
paultag Aug 15, 2024
37c4408
add in a slicer noop
paultag Aug 15, 2024
b609bf3
fix openapi
paultag Aug 15, 2024
e239cf1
add more example in
paultag Aug 15, 2024
dedabaa
Merge remote-tracking branch 'origin/main' into paultag/refactor
paultag Aug 15, 2024
80816dd
switch back to toml
paultag Aug 15, 2024
5487f59
start to re-add Bambu
paultag Aug 15, 2024
1a1e94d
Improve error when missing config file
iterion Aug 15, 2024
e7bbfce
start to re-add stubs
paultag Aug 15, 2024
1106904
Merge branch 'paultag/refactor' of github.com:kittycad/machine-api in…
paultag Aug 15, 2024
3f367b4
Revert "start to re-add stubs"
paultag Aug 15, 2024
99e7ed7
Revert "start to re-add Bambu"
paultag Aug 15, 2024
912de4e
re-add discover
paultag Aug 15, 2024
51b19a6
Fix prusa slicer params
iterion Aug 15, 2024
4b95680
start to re-add discovery
paultag Aug 15, 2024
633baf9
wip discovery
paultag Aug 15, 2024
486718c
chip away more on usb
paultag Aug 15, 2024
08f0461
more busted discover half done stuff
paultag Aug 16, 2024
bbaa085
more discovery shims
paultag Aug 16, 2024
d948a4b
start to re-add usb enumeration
paultag Aug 16, 2024
1dde7b1
fix enumeration
paultag Aug 16, 2024
c23c5e9
start moonraker
paultag Aug 16, 2024
d060def
wip
paultag Aug 17, 2024
168e4b0
partal clippy
paultag Aug 17, 2024
b2db514
clippy lints
paultag Aug 17, 2024
c972cb8
more lints
paultag Aug 17, 2024
5941387
more fixerating
paultag Aug 17, 2024
7f571bc
fix docs
paultag Aug 17, 2024
539a186
add a healthy call
paultag Aug 17, 2024
0d610f5
add in a wrapper for an async locked Control
paultag Aug 17, 2024
3ba24bb
going to gut discovery
paultag Aug 19, 2024
ce645e1
start to gut and re-add discovery
paultag Aug 19, 2024
e9a970d
add when discovered
paultag Aug 19, 2024
b527f26
wedge all the way through
paultag Aug 19, 2024
afd8f03
add noop back
paultag Aug 19, 2024
eeba7d6
easy lint
paultag Aug 19, 2024
24e3540
whoops
paultag Aug 19, 2024
1e5fe91
flipx
paultag Aug 19, 2024
452f373
re-add moonraker
paultag Aug 19, 2024
5a88fda
whoops
paultag Aug 19, 2024
6d6c570
Merge branch 'main' into paultag/refactor
paultag Aug 19, 2024
849fc67
add in id
paultag Aug 20, 2024
d2d272b
move from HashMap to Vec
paultag Aug 20, 2024
ff968dd
add in MK4 maybe
paultag Aug 20, 2024
05374bc
whoops
paultag Aug 20, 2024
4806ec0
remove eprintln
paultag Aug 20, 2024
0343271
Merge remote-tracking branch 'origin/main' into paultag/refactor
paultag Aug 20, 2024
17b6059
re-add mDNS
paultag Aug 20, 2024
9f9a6c1
add in a CORS hack
paultag Aug 22, 2024
76c9e37
Merge branch 'main' of github.com:kittycad/machine-api into paultag/r…
paultag Aug 22, 2024
fdc4e6f
re-add bambu shell
paultag Aug 22, 2024
2797f6b
re-add otel
paultag Aug 22, 2024
493cca8
spawn bambu
paultag Aug 22, 2024
4c198bd
clippy
paultag Aug 22, 2024
5d264a5
thanks clippy
paultag Aug 22, 2024
fa288eb
tag a few enums non_exhaustive
paultag Aug 23, 2024
babf5e2
more
paultag Aug 23, 2024
cade9d7
spawn the gcode render
paultag Aug 23, 2024
34578a1
take a stab at spawning the print task
paultag Aug 23, 2024
fec71fa
clippy lint
paultag Aug 23, 2024
5caa6ce
Merge branch 'main' of github.com:kittycad/machine-api into paultag/r…
paultag Aug 26, 2024
c23414c
.
paultag Aug 26, 2024
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
263 changes: 187 additions & 76 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 21 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ edition = "2021"
[profile.dev]
panic = "abort"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace]
members = [
"bambulabs",
"moonraker"
]

[features]
default = ["bambu", "formlabs", "moonraker", "serial"]
debug = ["dep:delouse", "dep:console-subscriber"]
bambu = ["dep:bambulabs"]
formlabs = []
serial = ["dep:tokio-serial"]
moonraker = ["dep:moonraker"]

[dependencies]
anyhow = "1.0.86"
async-trait = "0.1.81"
bambulabs = { path = "bambulabs" }
bambulabs = { path = "bambulabs", optional = true }
bytes = "1.7.1"
chrono = { version = "0.4", default-features = false, features = ["serde"] }
clap = { version = "4.5.16", features = ["cargo", "derive", "env", "unicode"] }
Expand All @@ -22,18 +34,18 @@ dropshot = "0.11"
futures = "0.3.28"
futures-util = "0.3.30"
git_rev = "0.1.0"
http = "1.1.0"
libmdns = "0.9.1"
libmdns = "0.8.0"
mdns = "3.0.0"
multer = { version = "3.1.0", features = ["json"] }
moonraker = { path = "moonraker", optional = true }
opentelemetry = "0.24.0"
opentelemetry-otlp = "0.17.0"
opentelemetry_sdk = { version = "0.24.1", features = ["rt-tokio"] }
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
schemars = { version = "0.8", features = ["chrono", "uuid1", "bigdecimal"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serialport = "4.5.0"
signal-hook = "0.3"
slog = "2.7.0"
slog-async = "2.7.0"
slog-json = "2.6.1"
Expand All @@ -46,6 +58,10 @@ tracing = "0.1"
tracing-opentelemetry = "0.25.0"
tracing-subscriber = { version = "0.3.18", features = ["registry", "std", "fmt", "smallvec", "ansi", "tracing-log", "json", "env-filter"] }
uuid = "1.10.0"
tokio-serial = { version = "5", optional = true, features = ["tokio-util", "libudev"] }
tracing-slog = "0.3.0"
http = "0.2.9"
hyper = "0.14"

[dev-dependencies]
async-trait = "0.1"
Expand All @@ -56,13 +72,3 @@ pretty_assertions = "1"
rand = "0.8"
test-context = "0.3.0"
testresult = "0.4.1"

[features]
debug = ["dep:delouse", "dep:console-subscriber"]

[workspace]
members = [
"bambulabs",
"moonraker"
]

27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ This API intends to provide a standardized local interface to any machines used
Here is a sample config file:

```toml
[bambulabs]
machines = [
{ id = "YOUR_ID_HERE", access_code = "YOUR_ACCESS_CODE_HERE", slicer_config = "./config/bambu/" },
{ id = "YOUR_ID_HERE", access_code = "YOUR_ACCESS_CODE_HERE", slicer_config = "./config/bambu/" },
]

[formlabs]
[machines.mk3]
type = "Usb"
port = "/dev/ttyUSB0"
baud = 115200
variant = "PrusaMk3"
slicer.type = "Prusa"
slicer.config = "config/prusa/mk3.ini"

[machines.nada]
type = "Noop"

[machines.neptune"]
type = "Moonraker"
endpoint = "http://192.168.1.102"
variant = "Neptune4"
slicer.type = "Prusa"
slicer.config = "config/prusa/neptune4.ini"
```

The cli looks by default for a file called `machine-api.toml` in the current
Expand All @@ -27,14 +37,13 @@ directory. You can also specify a different file with the `--config` flag.
You can run this server locally assuming rust is installed:

```
cargo run server --address 0.0.0.0:8585
cargo run -- serve --bind 0.0.0.0:8585
```

The full API is described by the OpenAPI spec, but to start you can list the connected machines:

```bash
$ curl http://localhost:8585/machines
# [{"port":"/dev/ttyACM0","id":"CZPX2418X004XK68718","manufacturer":"Prusa Research (prusa3d.com)","model":"Original Prusa i3 MK3"}]
```

The ID is what you'll use to identify the machine. You can use that ID to start a print job.
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
# dependencies for machine-api
just
pkg-config
openssl
]) ++ pkgs.lib.optionals pkgs.stdenv.isLinux (with pkgs; [
udev
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [
Expand Down
6 changes: 4 additions & 2 deletions moonraker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ edition = "2021"

[dependencies]
anyhow = "1"
bytes = "1.7.1"
bytes = "1"
reqwest = { version = "0", features = ["json", "multipart"] }
serde = { version = "1.0.209", features = ["derive"] }

serde = { version = "1.0.208", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
tracing = "0"
2 changes: 1 addition & 1 deletion moonraker/src/bin/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
async fn main() -> Result<()> {
let args: Vec<String> = std::env::args().collect();

let printer = moonraker::PrintManager::new(&args[1])?;
let printer = moonraker::Client::new(&args[1])?;

Check warning on line 9 in moonraker/src/bin/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/bin/print.rs#L9

Added line #L9 was not covered by tests
let path: PathBuf = args[2].parse().unwrap();
let path: PathBuf = printer.upload_file(&path).await?.item.path.parse().unwrap();
eprintln!("Uploaded {}", path.display());
Expand Down
10 changes: 6 additions & 4 deletions moonraker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
pub use print::InfoResponse;
pub use upload::{DeleteResponse, DeleteResponseItem, UploadResponse, UploadResponseItem};

/// PrintManager is a moonraker instance which can accept gcode for printing.
pub struct PrintManager {
/// Client is a moonraker instance which can accept gcode for printing.
pub struct Client {
pub(crate) url_base: String,
}

impl PrintManager {
/// Create a new PrintManager handle to control the printer via the
impl Client {
/// Create a new Client handle to control the printer via the
/// moonraker interface.
pub fn new(url_base: &str) -> Result<Self> {
tracing::debug!(base = url_base, "new");

Check warning on line 31 in moonraker/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/lib.rs#L31

Added line #L31 was not covered by tests

Ok(Self {
url_base: url_base.to_owned(),
})
Expand Down
11 changes: 6 additions & 5 deletions moonraker/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};

use super::PrintManager;
use super::Client;

/// Temperature readings from a heated element controlled by klipper.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 7 in moonraker/src/metrics.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/metrics.rs#L7

Added line #L7 was not covered by tests
pub struct ControlledTemperatureReadings {
/// Observed temperatures, from oldest (0th) to latest (last)
pub temperatures: Vec<f64>,
Expand All @@ -17,7 +17,7 @@
}

/// TemperatureReadings as reported by klipper.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 20 in moonraker/src/metrics.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/metrics.rs#L20

Added line #L20 was not covered by tests
pub struct TemperatureReadings {
/// Information about the 3D printer extruder head.
pub extruder: ControlledTemperatureReadings,
Expand All @@ -26,14 +26,15 @@
pub heater_bed: Option<ControlledTemperatureReadings>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 29 in moonraker/src/metrics.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/metrics.rs#L29

Added line #L29 was not covered by tests
struct TemperatureReadingsWrapper {
result: TemperatureReadings,
}

impl PrintManager {
impl Client {
/// Print an uploaded file.
pub async fn temperatures(&self) -> Result<TemperatureReadings> {
tracing::debug!(base = self.url_base, "requesting temperatures");

Check warning on line 37 in moonraker/src/metrics.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/metrics.rs#L37

Added line #L37 was not covered by tests
let client = reqwest::Client::new();

let resp: TemperatureReadingsWrapper = client
Expand Down
16 changes: 12 additions & 4 deletions moonraker/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};

use super::PrintManager;
use super::Client;

/// Information about the underlying Klipper runtime and host computer.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 9 in moonraker/src/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/print.rs#L9

Added line #L9 was not covered by tests
pub struct InfoResponse {
/// slug defining what state the printer is currently in, such as
/// `ready`.
Expand All @@ -25,14 +25,16 @@
pub cpu_info: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 28 in moonraker/src/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/print.rs#L28

Added line #L28 was not covered by tests
struct InfoResponseWrapper {
pub result: InfoResponse,
}

impl PrintManager {
impl Client {
/// Print an uploaded file.
pub async fn print(&self, file_name: &Path) -> Result<()> {
tracing::debug!(base = self.url_base, "requesting print");

Check warning on line 36 in moonraker/src/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/print.rs#L36

Added line #L36 was not covered by tests

let file_name = file_name.to_str().unwrap();
let client = reqwest::Client::new();
client
Expand All @@ -48,6 +50,7 @@
/// button and also used if a user enters M112(emergency stop) via a
/// console.
pub async fn emergency_stop(&self) -> Result<()> {
tracing::warn!(base = self.url_base, "requesting emergency stop");

Check warning on line 53 in moonraker/src/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/print.rs#L53

Added line #L53 was not covered by tests
let client = reqwest::Client::new();
client
.post(format!("{}/printer/emergency_stop", self.url_base))
Expand All @@ -58,6 +61,7 @@

/// Get information regarding the processor and its state.
pub async fn info(&self) -> Result<InfoResponse> {
tracing::debug!(base = self.url_base, "requesting info");

Check warning on line 64 in moonraker/src/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/print.rs#L64

Added line #L64 was not covered by tests
let client = reqwest::Client::new();
let resp: InfoResponseWrapper = client
.post(format!("{}/printer/info", self.url_base))
Expand All @@ -70,13 +74,15 @@

/// Restart the printer (shut down and reboot).
pub async fn restart(&self) -> Result<()> {
tracing::debug!(base = self.url_base, "requesting restart");

Check warning on line 77 in moonraker/src/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/print.rs#L77

Added line #L77 was not covered by tests
let client = reqwest::Client::new();
client.post(format!("{}/printer/restart", self.url_base)).send().await?;
Ok(())
}

/// Cancel a print job.
pub async fn cancel_print(&self) -> Result<()> {
tracing::debug!(base = self.url_base, "requesting cancel");

Check warning on line 85 in moonraker/src/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/print.rs#L85

Added line #L85 was not covered by tests
let client = reqwest::Client::new();
client
.post(format!("{}/printer/print/cancel", self.url_base))
Expand All @@ -87,6 +93,7 @@

/// Pause a print job.
pub async fn pause_print(&self) -> Result<()> {
tracing::debug!(base = self.url_base, "requesting pause");

Check warning on line 96 in moonraker/src/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/print.rs#L96

Added line #L96 was not covered by tests
let client = reqwest::Client::new();
client
.post(format!("{}/printer/print/pause", self.url_base))
Expand All @@ -97,6 +104,7 @@

/// Resume a print job.
pub async fn resume_print(&self) -> Result<()> {
tracing::debug!(base = self.url_base, "requesting resume");

Check warning on line 107 in moonraker/src/print.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/print.rs#L107

Added line #L107 was not covered by tests
let client = reqwest::Client::new();
client
.post(format!("{}/printer/print/resume", self.url_base))
Expand Down
23 changes: 10 additions & 13 deletions moonraker/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use reqwest::multipart;
use serde::{Deserialize, Serialize};

use super::PrintManager;
use super::Client;

/// File that has been uploaded to Moonraker.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 11 in moonraker/src/upload.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/upload.rs#L11

Added line #L11 was not covered by tests
pub struct UploadResponseItem {
/// Path of the file relative to the root directory.
pub path: String,
Expand All @@ -20,20 +20,14 @@
}

/// Response to an upload request.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 23 in moonraker/src/upload.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/upload.rs#L23

Added line #L23 was not covered by tests
pub struct UploadResponse {
/// `gcode` file uploaded to the printer.
pub item: UploadResponseItem,

/// Has this print been started?
pub print_started: bool,

/// Has this print been enqueued?
pub print_queued: bool,
}

/// File that has been deleted from Moonraker.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 30 in moonraker/src/upload.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/upload.rs#L30

Added line #L30 was not covered by tests
pub struct DeleteResponseItem {
/// Path of the file relative to the root directory.
pub path: String,
Expand All @@ -45,20 +39,21 @@
}

/// Response to a delete request.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 42 in moonraker/src/upload.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/upload.rs#L42

Added line #L42 was not covered by tests
pub struct DeleteResponse {
/// `gcode` file that has been deleted.
pub item: DeleteResponseItem,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Check warning on line 48 in moonraker/src/upload.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/upload.rs#L48

Added line #L48 was not covered by tests
struct DeleteResponseWrapper {
result: DeleteResponse,
}

impl PrintManager {
impl Client {
/// Upload a file with some gcode to the server.
pub async fn upload_file(&self, file_name: &Path) -> Result<UploadResponse> {
tracing::info!(file_path = file_name.to_str().unwrap(), "uploading file");

Check warning on line 56 in moonraker/src/upload.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/upload.rs#L56

Added line #L56 was not covered by tests
self.upload(
&PathBuf::from(file_name.file_name().unwrap().to_str().unwrap()),
&std::fs::read(file_name)?,
Expand All @@ -69,6 +64,7 @@
/// Upload a byte array of gcode to the print queue.
pub async fn upload(&self, file_name: &Path, gcode: &[u8]) -> Result<UploadResponse> {
let file_name = file_name.to_str().unwrap();
tracing::info!(file_name = file_name, "uploading gcode to the printer");

Check warning on line 67 in moonraker/src/upload.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/upload.rs#L67

Added line #L67 was not covered by tests
let gcode = multipart::Part::bytes(gcode.to_owned())
.file_name(file_name.to_owned())
.mime_str("text/x-gcode")?;
Expand Down Expand Up @@ -100,6 +96,7 @@

/// Delete an uploaded file from the print queue.
pub async fn delete(&self, file_name: &Path) -> Result<DeleteResponse> {
tracing::info!(file_path = file_name.to_str().unwrap(), "deleting file");

Check warning on line 99 in moonraker/src/upload.rs

View check run for this annotation

Codecov / codecov/patch

moonraker/src/upload.rs#L99

Added line #L99 was not covered by tests
let file_name = file_name.to_str().unwrap();
let client = reqwest::Client::new();
let resp: DeleteResponseWrapper = client
Expand Down
Loading