SoyuzCapsule/Soyuz/ViewModels/PrinterObjectsQuery.swift

79 lines
1.8 KiB
Swift
Raw Permalink Normal View History

2023-07-10 18:14:24 +00:00
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
2023-02-07 20:04:01 +00:00
import Foundation
// Root struct to decode for REST response
2023-02-07 20:04:01 +00:00
struct PrinterObjectsQuery: Decodable {
let result: ResultsData
}
struct ResultsData: Decodable {
let eventtime: Double
let status: StatusData
}
// Individual update replies for JSON-RPC
struct jsonRpcUpdate: Decodable {
let method: String?
let params: jsonRpcParams
}
struct jsonRpcParams: Decodable {
let status: StatusData?
let timestamp: Double?
init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
self.status = try container.decode(StatusData.self)
self.timestamp = try container.decode(Double.self)
}
}
// Root structs to decode for JSON-RPC response
struct jsonRpcResponse: Decodable {
let result: jsonRpcResult
}
struct jsonRpcResult: Decodable {
let eventtime: Double
let status: StatusData
}
// Shared data sub-structs
2023-02-07 20:04:01 +00:00
struct StatusData: Decodable {
let virtual_sdcard: VirtualSDCardData?
let extruder: ExtruderData?
let print_stats: PrintStatsData?
let heater_bed: HeaterBedData?
}
struct VirtualSDCardData: Decodable {
let file_path: String?
let progress: Double?
let is_active: Bool?
2023-02-07 20:04:01 +00:00
}
struct ExtruderData: Decodable {
let temperature: Double?
let target: Double?
let power: Double?
}
struct PrintStatsData: Decodable {
let filename: String?
let print_duration: Double?
let filament_used: Double?
let state: String?
}
struct HeaterBedData: Decodable {
let temperature: Double?
let target: Double?
let power: Double?
2023-02-07 20:04:01 +00:00
}