Skip to content

Commit

Permalink
1. add 'unsubscribe', 'getmachineobjects', 'setmachinesubscribefilter…
Browse files Browse the repository at this point in the history
…' 2. add 'async_send_gcodes' 3. show native dialog after conneting successfully or unseccessfully 4. add machine cover to web by sswcp 5. sign app and notary on mac with git push to 2.0.0
  • Loading branch information
womendoushihaoyin committed Jan 14, 2025
1 parent 6dec471 commit c2ba0f9
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_orca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
# Thanks to RaySajuuk, it's working now
- name: Sign app and notary
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')) && inputs.os == 'macos-14'
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || github.ref == 'refs/heads/2.0.0') && inputs.os == 'macos-14'
working-directory: ${{ github.workspace }}
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
Expand Down
80 changes: 78 additions & 2 deletions resources/web/flutter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
<script src="flutter_bootstrap.js" async></script>

<script>
function test_mqtt_unsubscribe() {
body = {
header:{
swquenceId: 202519,
},
payload:{
cmd: "sw_StopMachineStateSubscription",
params: {},
}
};

window.wx.postMessage(JSON.stringify(body));
}

function test_mqtt_subscribe() {
body = {
header:{
Expand All @@ -51,6 +65,44 @@
window.wx.postMessage(JSON.stringify(body));
}

function test_mqtt_subscribe_filter(){
body = {
header:{
sequenceId: 202510,
},
payload:{
cmd: "sw_SetSubscribeFilter",
params: {
"targets":{
"gcode_move": null,
"toolhead": ["position", "status"]
}
}
}
};
window.wx.postMessage(JSON.stringify(body));
}

function test_mqtt_send_gcodes(){
body = {
header:{
sequenceId: 202592,
},
payload:{
cmd: "sw_SendGCodes",
params: {
"script":[
"T0",
"T1",
"T2",
"T3",
]
}
}
};
window.wx.postMessage(JSON.stringify(body));
}

function test_mqtt_machine_info(){
body = {
header:{
Expand All @@ -69,6 +121,30 @@
window.wx.postMessage(JSON.stringify(body));
}

function test_mqtt_machine_objects(){
body = {
header:{
sequenceId: 202504,
},
payload:{
cmd: "sw_GetMachineObjects",
}
};
window.wx.postMessage(JSON.stringify(body));
}


function test_mqtt_disconnect() {
body = {
header:{
sequenceId: 202500,
},
payload:{
cmd: "sw_DisConnect",
}
}
window.wx.postMessage(JSON.stringify(body));
}

function test_mqtt_connect() {
body = {
Expand All @@ -78,9 +154,9 @@
payload:{
cmd: "sw_Connect",
params: {
ip: "172.18.1.46",
ip: "172.18.1.66",
port: 1883,
sn: "61BC45A47ED2BE8E",
sn: "BE667E5F8A060BDF",
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/GUI_App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ class GUI_App : public wxApp
bool m_show_gcode_window{true};
boost::thread m_check_network_thread;
public:
wxDialog* get_web_device_dialog() { return web_device_dialog; }
//try again when subscription fails
void on_start_subscribe_again(std::string dev_id);
void check_filaments_in_blacklist(std::string tag_supplier, std::string tag_material, bool& in_blacklist, std::string& action, std::string& info);
Expand Down
190 changes: 184 additions & 6 deletions src/slic3r/GUI/SSWCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void SSWCP_MachineFind_Instance::sw_StartMachineFind()
m_engines.push_back(nullptr);
}

Bonjour::TxtKeys txt_keys = {"sn", "version"};
Bonjour::TxtKeys txt_keys = {"sn", "version", "machine_type"};
std::string unique_key = "sn";

for (size_t i = 0; i < m_engines.size(); ++i) {
Expand Down Expand Up @@ -217,6 +217,23 @@ void SSWCP_MachineFind_Instance::sw_StartMachineFind()
machine_data[unique_key] = machine_data["unique_value"];
}

// 模拟一下
machine_data["cover"] = LOCALHOST_URL + std::to_string(PAGE_HTTP_PORT) +
"/profiles/Snapmaker/Snapmaker A350 Dual BKit_cover.png";

if (reply.txt_data.count("machine_type")) {
std::string machine_type = reply.txt_data["machine_type"];
size_t vendor_pos = machine_type.find_first_of(" ");
if (vendor_pos != std::string::npos) {
std::string vendor = machine_type.substr(0, vendor_pos);
std::string machine_cover = LOCALHOST_URL + std::to_string(PAGE_HTTP_PORT) + "/profiles/" +
vendor + machine_type + "_cover.png";

machine_data["cover"] = machine_cover;
}


}
json machine_object;
if (machine_data.count("unique_value")) {
this->add_machine_to_list(machine_object);
Expand Down Expand Up @@ -305,9 +322,40 @@ void SSWCP_MachineOption_Instance::process()
sw_GetMachineState();
} else if (m_cmd == "sw_SubscribeMachineState") {
sw_SubscribeMachineState();
} else if (m_cmd == "sw_GetMachineObjects") {
sw_GetMachineObjects();
} else if (m_cmd == "sw_SetSubscribeFilter") {
sw_SetMachineSubscribeFilter();
} else if (m_cmd == "sw_StopMachineStateSubscription") {
sw_UnSubscribeMachineState();
}
}

void SSWCP_MachineOption_Instance::sw_UnSubscribeMachineState() {
try {
std::shared_ptr<PrintHost> host(PrintHost::get_print_host(&wxGetApp().preset_bundle->printers.get_edited_preset().config));

if (!host) {
m_status = 1;
m_msg = "failure";
send_to_js();
finish_job();
}

host->async_unsubscribe_machine_info([this](const json& response) {
if (response.is_null()) {
m_status = -1;
m_msg = "failure";
send_to_js();
} else {
m_res_data = response;
send_to_js();
}
});

} catch (std::exception& e) {}
}

void SSWCP_MachineOption_Instance::sw_SubscribeMachineState() {
try {
std::shared_ptr<PrintHost> host(PrintHost::get_print_host(&wxGetApp().preset_bundle->printers.get_edited_preset().config));
Expand All @@ -320,7 +368,7 @@ void SSWCP_MachineOption_Instance::sw_SubscribeMachineState() {
}

host->async_subscribe_machine_info([this](const json& response) {
if (response.is_null() || response.empty()) {
if (response.is_null()) {
m_status = -1;
m_msg = "failure";
send_to_js();
Expand Down Expand Up @@ -396,10 +444,42 @@ void SSWCP_MachineOption_Instance::sw_GetMachineState() {

void SSWCP_MachineOption_Instance::sw_SendGCodes() {
try {
if (m_param_data.count("codes")) {
if (m_param_data.count("script")) {
std::shared_ptr<PrintHost> host(PrintHost::get_print_host(&wxGetApp().preset_bundle->printers.get_edited_preset().config));
std::vector<std::string> str_codes;


if (m_param_data["script"].is_array()) {
json codes = m_param_data["script"];
for (size_t i = 0; i < codes.size(); ++i) {
str_codes.push_back(codes[i].get<std::string>());
}
} else if (m_param_data["script"].is_string()) {
str_codes.push_back(m_param_data["script"].get<std::string>());
}

if (!host) {
// 错误处理
m_status = -1;
m_msg = "failure";
send_to_js();
finish_job();
} else {
host->async_send_gcodes(str_codes, [this](const json& response) {
if (response.is_null() || response.empty()) {
m_status = -1;
m_msg = "failure";
send_to_js();
finish_job();
} else {
m_res_data = response;
send_to_js();
finish_job();
}
});
}

/*http 同步做法
if (m_param_data["codes"].is_array()) {
json codes = m_param_data["codes"];
for (size_t i = 0; i < codes.size(); ++i) {
Expand Down Expand Up @@ -430,15 +510,96 @@ void SSWCP_MachineOption_Instance::sw_SendGCodes() {
} else {
// 错误处理
finish_job();
*/
}

} catch (const std::exception&) {}
}

void SSWCP_MachineOption_Instance::sw_SetMachineSubscribeFilter()
{
try {
if (m_param_data.count("targets")) {
std::shared_ptr<PrintHost> host(PrintHost::get_print_host(&wxGetApp().preset_bundle->printers.get_edited_preset().config));
std::vector<std::pair<std::string, std::vector<std::string>>> targets;

json items = m_param_data["targets"];
for (auto& [key, value] : items.items()) {
if (value.is_null()) {
targets.push_back({key, {}});
} else {
std::vector<std::string> items;
if (value.is_array()) {
for (size_t i = 0; i < value.size(); ++i) {
items.push_back(value[i].get<std::string>());
}
} else {
items.push_back(value.get<std::string>());
}
targets.push_back({key, items});
}
}

if (!host) {
// 错误处理
m_status = -1;
m_msg = "failure";
send_to_js();
finish_job();
} else {
host->async_set_machine_subscribe_filter(targets, [this](const json& response) {
if (response.is_null() || response.empty()) {
m_status = -1;
m_msg = "failure";
send_to_js();
finish_job();
} else {
m_res_data = response;
send_to_js();
finish_job();
}
});
}
} else {
finish_job();
}

} catch (std::exception& e) {}
}
void SSWCP_MachineOption_Instance::sw_GetMachineObjects()
{
try {
std::shared_ptr<PrintHost> host(PrintHost::get_print_host(&wxGetApp().preset_bundle->printers.get_edited_preset().config));

if (!host) {
m_status = -1;
m_msg = "failure";
send_to_js();
finish_job();
return;
}

host->async_get_machine_objects([this](const json& response) {
if (response.is_null() || response.empty()) {
m_status = -1;
m_msg = "failure";
send_to_js();
finish_job();
} else {
m_res_data = response;
send_to_js();
finish_job();
}
});

} catch (std::exception& e) {}
}

// SSWCP_MachineConnect_Instance
void SSWCP_MachineConnect_Instance::process() {
if (m_cmd == "sw_Test_connect") {
sw_test_connect();
} else if (m_cmd == "sw_Connect") {
} else if (m_cmd == "sw_SelectMachine") {
sw_connect();
} else if (m_cmd == "sw_DisConnect") {
sw_disconnect();
Expand Down Expand Up @@ -553,15 +714,29 @@ void SSWCP_MachineConnect_Instance::sw_connect() {
json params;
bool res = host->connect(msg, connect_params);

std::string ip_port = host->get_host();
if (res) {
// 后续应改成机器交互页的本地web服务器地址
std::string ip_port = host->get_host();
int pos = ip_port.find(':');
if (pos != std::string::npos) {
ip_port = ip_port.substr(0, pos);
}
wxGetApp().mainframe->load_printer_url("http://" + ip_port);

MessageDialog msg_window(nullptr,
ip_port + _L(" connected sucessfully !\n"),
L("Machine Connected"), wxICON_QUESTION | wxOK);
msg_window.ShowModal();

auto dialog = wxGetApp().get_web_device_dialog();
if (dialog) {
dialog->Hide();
}
} else {
MessageDialog msg_window(nullptr, ip_port + _L(" connected unseccessfully !\n"), L("Failed"),
wxICON_QUESTION | wxOK);
msg_window.ShowModal();

m_status = 1;
m_msg = msg.c_str();
}
Expand Down Expand Up @@ -612,11 +787,14 @@ std::unordered_set<std::string> SSWCP::m_machine_option_cmd_list = {
"sw_SendGCodes",
"sw_GetMachineState",
"sw_SubscribeMachineState",
"sw_GetMachineObjects",
"sw_SetSubscribeFilter",
"sw_StopMachineStateSubscription",
};

std::unordered_set<std::string> SSWCP::m_machine_connect_cmd_list = {
"sw_Test_connect",
"sw_Connect",
"sw_SelectMachine",
"sw_DisConnect",
};

Expand Down
Loading

0 comments on commit c2ba0f9

Please sign in to comment.