mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-23 02:42:08 +00:00
NEW: print with emmc
jira: [STUDIO-14427] Change-Id: I8b0c56ce1c2b7b90949b72c49acfdbb31c876df1 (cherry picked from commit 76e45bde2540ee418719e00b999c5fd724baec71)
This commit is contained in:
@@ -4986,6 +4986,18 @@ void MachineObject::parse_new_info(json print)
|
||||
is_support_idelheadingprotect_detection = get_flag_bits(fun, 62);
|
||||
}
|
||||
|
||||
/*fun2*/
|
||||
std::string fun2;
|
||||
if (print.contains("fun2") && print["fun2"].is_string()) {
|
||||
fun2 = print["fun2"].get<std::string>();
|
||||
BOOST_LOG_TRIVIAL(info) << "new print data fun2 = " << fun;
|
||||
}
|
||||
|
||||
// fun2 may have infinite length, use get_flag_bits_no_border
|
||||
if (!fun2.empty()) {
|
||||
is_support_print_with_emmc = get_flag_bits_no_border(fun2, 0) == 1;
|
||||
}
|
||||
|
||||
/*aux*/
|
||||
std::string aux = print["aux"].get<std::string>();
|
||||
|
||||
@@ -4993,7 +5005,6 @@ void MachineObject::parse_new_info(json print)
|
||||
|
||||
if (!aux.empty()) {
|
||||
m_storage->set_sdcard_state(get_flag_bits(aux, 12, 2));
|
||||
//sdcard_state = MachineObject::SdcardState(get_flag_bits(aux, 12, 2));
|
||||
}
|
||||
|
||||
/*stat*/
|
||||
@@ -5036,6 +5047,10 @@ void MachineObject::parse_new_info(json print)
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_hex_digit(char c) {
|
||||
return std::isxdigit(static_cast<unsigned char>(c)) != 0;
|
||||
}
|
||||
|
||||
int MachineObject::get_flag_bits(std::string str, int start, int count) const
|
||||
{
|
||||
try {
|
||||
@@ -5043,7 +5058,94 @@ int MachineObject::get_flag_bits(std::string str, int start, int count) const
|
||||
unsigned long long mask = (1ULL << count) - 1;
|
||||
int flag = (decimal_value >> start) & mask;
|
||||
return flag;
|
||||
} catch (...) {
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MachineObject::get_flag_bits_no_border(std::string str, int start_idx, int count) const
|
||||
{
|
||||
if (start_idx < 0 || count <= 0) return 0;
|
||||
|
||||
try {
|
||||
// --- 1) trim ---
|
||||
auto ltrim = [](std::string& s) {
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
|
||||
[](unsigned char ch) { return !std::isspace(ch); }));
|
||||
};
|
||||
auto rtrim = [](std::string& s) {
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(),
|
||||
[](unsigned char ch) { return !std::isspace(ch); }).base(), s.end());
|
||||
};
|
||||
ltrim(str); rtrim(str);
|
||||
|
||||
// --- 2) remove 0x/0X prefix ---
|
||||
if (str.size() >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
|
||||
str.erase(0, 2);
|
||||
}
|
||||
|
||||
// --- 3) keep only hex digits ---
|
||||
std::string hex;
|
||||
hex.reserve(str.size());
|
||||
for (char c : str) {
|
||||
if (std::isxdigit(static_cast<unsigned char>(c))) hex.push_back(c);
|
||||
}
|
||||
if (hex.empty()) return 0;
|
||||
|
||||
// --- 4) use size_t for all index/bit math ---
|
||||
const size_t total_bits = hex.size() * 4ULL;
|
||||
|
||||
const size_t ustart = static_cast<size_t>(start_idx);
|
||||
if (ustart >= total_bits) return 0;
|
||||
|
||||
const int int_bits = std::numeric_limits<uint32_t>::digits; // typically 32
|
||||
const size_t need_bits = static_cast<size_t>(std::min(count, int_bits));
|
||||
|
||||
// [first_bit, last_bit]
|
||||
const size_t first_bit = ustart;
|
||||
const size_t last_bit = std::min(ustart + need_bits, total_bits) - 1ULL;
|
||||
if (last_bit < first_bit) return 0;
|
||||
|
||||
|
||||
const size_t right_index = hex.size() - 1ULL;
|
||||
|
||||
const size_t first_nibble = first_bit / 4ULL;
|
||||
const size_t last_nibble = last_bit / 4ULL;
|
||||
|
||||
const size_t start_idx = right_index - last_nibble;
|
||||
const size_t end_idx = right_index - first_nibble;
|
||||
if (end_idx < start_idx) return 0;
|
||||
|
||||
const size_t sub_len = end_idx - start_idx + 1ULL;
|
||||
if (end_idx >= hex.size()) return 0;
|
||||
|
||||
const std::string sub_hex = hex.substr(start_idx, sub_len);
|
||||
|
||||
unsigned long long chunk = std::stoull(sub_hex, nullptr, 16);
|
||||
|
||||
const unsigned nibble_offset = static_cast<unsigned>(first_bit % 4ULL);
|
||||
const unsigned long long shifted =
|
||||
(nibble_offset == 0U) ? chunk : (chunk >> nibble_offset);
|
||||
|
||||
uint32_t mask;
|
||||
if (need_bits >= static_cast<size_t>(std::numeric_limits<uint32_t>::digits)) {
|
||||
mask = std::numeric_limits<uint32_t>::max();
|
||||
}
|
||||
else {
|
||||
mask = static_cast<uint32_t>((1ULL << need_bits) - 1ULL);
|
||||
}
|
||||
|
||||
const uint32_t val = static_cast<uint32_t>(shifted & mask);
|
||||
return val;
|
||||
}
|
||||
catch (const std::invalid_argument&) {
|
||||
return 0;
|
||||
}
|
||||
catch (const std::out_of_range&) {
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,6 +605,9 @@ public:
|
||||
bool is_support_airprinting_detection{false};
|
||||
bool is_support_idelheadingprotect_detection{false};
|
||||
|
||||
// fun2
|
||||
bool is_support_print_with_emmc{false};
|
||||
|
||||
bool installed_upgrade_kit{false};
|
||||
int bed_temperature_limit = -1;
|
||||
|
||||
@@ -858,6 +861,7 @@ public:
|
||||
bool check_enable_np(const json& print) const;
|
||||
void parse_new_info(json print);
|
||||
int get_flag_bits(std::string str, int start, int count = 1) const;
|
||||
uint32_t get_flag_bits_no_border(std::string str, int start_idx, int count = 1) const;
|
||||
int get_flag_bits(int num, int start, int count = 1, int base = 10) const;
|
||||
|
||||
/* Device Filament Check */
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "slic3r/GUI/DeviceCore/DevManager.h"
|
||||
#include "slic3r/GUI/DeviceCore/DevUtil.h"
|
||||
|
||||
#include "slic3r/Utils/FileTransferUtils.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
@@ -206,13 +208,26 @@ void PrintJob::process(Ctl &ctl)
|
||||
|
||||
// check access code and ip address
|
||||
if (this->connection_type == "lan" && m_print_type == "from_normal") {
|
||||
params.dev_id = m_dev_id;
|
||||
params.project_name = "verify_job";
|
||||
params.filename = job_data._temp_path.string();
|
||||
params.connection_type = this->connection_type;
|
||||
bool emmc_ok = false;
|
||||
bool ftp_ok = false;
|
||||
if (could_emmc_print) {
|
||||
std::string devIP = m_dev_ip;
|
||||
std::string accessCode = m_access_code;
|
||||
std::string url = "bambu:///local/" + devIP + "?port=6000&user=" + "bblp" + "&passwd=" + accessCode;
|
||||
std::unique_ptr<FileTransferTunnel> tunnel = std::make_unique<FileTransferTunnel>(module(), url);
|
||||
emmc_ok = tunnel->sync_start_connect();
|
||||
}
|
||||
{
|
||||
params.dev_id = m_dev_id;
|
||||
params.project_name = "verify_job";
|
||||
params.filename = job_data._temp_path.string();
|
||||
params.connection_type = this->connection_type;
|
||||
|
||||
result = m_agent->start_send_gcode_to_sdcard(params, nullptr, nullptr, nullptr);
|
||||
if (result != 0) {
|
||||
result = m_agent->start_send_gcode_to_sdcard(params, nullptr, nullptr, nullptr);
|
||||
|
||||
ftp_ok = result == 0;
|
||||
}
|
||||
if (!emmc_ok && !ftp_ok) {
|
||||
BOOST_LOG_TRIVIAL(error) << "access code is invalid";
|
||||
m_enter_ip_address_fun_fail();
|
||||
m_job_finished = true;
|
||||
@@ -563,7 +578,7 @@ void PrintJob::process(Ctl &ctl)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this->has_sdcard) {
|
||||
if (this->has_sdcard || this->could_emmc_print) {
|
||||
ctl.update_status(curr_percent, _u8L("Sending print job over LAN"));
|
||||
result = m_agent->start_local_print(params, update_fn, cancel_fn);
|
||||
} else {
|
||||
|
||||
@@ -82,6 +82,7 @@ public:
|
||||
bool task_layer_inspect;
|
||||
bool cloud_print_only { false };
|
||||
bool has_sdcard { false };
|
||||
bool could_emmc_print { false };
|
||||
bool task_use_ams { true };
|
||||
bool task_ext_change_assist { false };
|
||||
|
||||
|
||||
@@ -2524,6 +2524,7 @@ void SelectMachineDialog::on_send_print()
|
||||
}
|
||||
|
||||
m_print_job->has_sdcard = obj_->GetStorage()->get_sdcard_state() == DevStorage::SdcardState::HAS_SDCARD_NORMAL;
|
||||
m_print_job->could_emmc_print = obj_->is_support_print_with_emmc;
|
||||
|
||||
|
||||
bool timelapse_option = m_checkbox_list["timelapse"]->IsShown()?true:false;
|
||||
@@ -3322,7 +3323,8 @@ void SelectMachineDialog::update_show_status(MachineObject* obj_)
|
||||
|
||||
/*check sdcard when if lan mode printer*/
|
||||
if (obj_->is_lan_mode_printer()) {
|
||||
if (obj_->GetStorage()->get_sdcard_state() == DevStorage::SdcardState::NO_SDCARD) {
|
||||
if (obj_->GetStorage()->get_sdcard_state() == DevStorage::SdcardState::NO_SDCARD
|
||||
&& !obj_->is_support_print_with_emmc) {
|
||||
show_status(PrintDialogStatus::PrintStatusLanModeNoSdcard);
|
||||
return;
|
||||
} else if (obj_->GetStorage()->get_sdcard_state() == DevStorage::SdcardState::HAS_SDCARD_ABNORMAL || obj_->GetStorage()->get_sdcard_state() == DevStorage::SdcardState::HAS_SDCARD_READONLY) {
|
||||
|
||||
Reference in New Issue
Block a user