Skip to content

Commit

Permalink
add the moonraker_mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
womendoushihaoyin committed Jan 13, 2025
1 parent dce1935 commit d8ffab7
Show file tree
Hide file tree
Showing 16 changed files with 832 additions and 65 deletions.
51 changes: 51 additions & 0 deletions resources/web/flutter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,57 @@
<script src="flutter_bootstrap.js" async></script>

<script>
function test_mqtt_subscribe() {
body = {
header:{
swquenceId: 202503,
},
payload:{
cmd: "sw_SubscribeMachineState",
params: {},
event_id: "subscribe1",
}
};

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

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


function test_mqtt_connect() {
body = {
header:{
sequenceId: 202501,
},
payload:{
cmd: "sw_Connect",
params: {
ip: "172.18.1.46",
port: 1883,
sn: "61BC45A47ED2BE8E",
}
}
}
window.wx.postMessage(JSON.stringify(body));
}


function getDeviceData() {
var devices = {
Expand Down
17 changes: 17 additions & 0 deletions resources/web/flutter0/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@
<script src="flutter_bootstrap.js" async></script>

<script>
function test_mqtt_connect() {
body = {
header:{
sequenceId: 202501,
},
payload:{
cmd: "sw_Connect",
params: {
ip: "172.18.1.46",
port: 1883,
sn: "61BC45A47ED2BE8E",
}
}
}
window.wx.postMessage(JSON.stringify(body));
}

// 接收来自于 Flutter 的消息
function on_machine_list_arrived(response){
console.log(response);
Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static t_config_enum_values s_keys_map_PrinterTechnology {
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(PrinterTechnology)

static t_config_enum_values s_keys_map_PrintHostType {
{ "moonraker_mqtt", htMoonRaker_mqtt},
{ "moonraker", htMoonRaker},
{ "prusalink", htPrusaLink },
{ "prusaconnect", htPrusaConnect },
Expand Down Expand Up @@ -3424,7 +3425,7 @@ void PrintConfigDef::init_fff_params()
def->enum_labels.push_back("SimplyPrint");
def->mode = comAdvanced;
def->cli = ConfigOptionDef::nocli;
def->set_default_value(new ConfigOptionEnum<PrintHostType>(htOctoPrint));
def->set_default_value(new ConfigOptionEnum<PrintHostType>(htMoonRaker_mqtt));


def = this->add("nozzle_volume", coFloat);
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ enum class FuzzySkinType {
};

enum PrintHostType {
htMoonRaker, htPrusaLink, htPrusaConnect, htOctoPrint, htDuet, htFlashAir, htAstroBox, htRepetier, htMKS, htESP3D, htCrealityPrint, htObico, htFlashforge, htSimplyPrint
htMoonRaker_mqtt, htMoonRaker, htPrusaLink, htPrusaConnect, htOctoPrint, htDuet, htFlashAir, htAstroBox, htRepetier, htMKS, htESP3D, htCrealityPrint, htObico, htFlashforge, htSimplyPrint
};

enum AuthorizationType {
Expand Down
20 changes: 10 additions & 10 deletions src/mqtt/externals/paho-mqtt-c/src/SHA1.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#if defined(_WIN32) || defined(_WIN64)
#pragma comment(lib, "crypt32.lib")

int SHA1_Init(SHA_CTX *c)
int SHA1_Init_mqtt(SHA_CTX *c)
{
if (!CryptAcquireContext(&c->hProv, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
Expand All @@ -33,15 +33,15 @@ int SHA1_Init(SHA_CTX *c)
return 1;
}

int SHA1_Update(SHA_CTX *c, const void *data, size_t len)
int SHA1_Update_mqtt(SHA_CTX *c, const void *data, size_t len)
{
int rv = 1;
if (!CryptHashData(c->hHash, data, (DWORD)len, 0))
rv = 0;
return rv;
}

int SHA1_Final(unsigned char *md, SHA_CTX *c)
int SHA1_Final_mqtt(unsigned char *md, SHA_CTX *c)
{
int rv = 0;
DWORD md_len = SHA1_DIGEST_LENGTH;
Expand Down Expand Up @@ -74,7 +74,7 @@ static unsigned char pad[64] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

int SHA1_Init(SHA_CTX *ctx)
int SHA1_Init_mqtt(SHA_CTX *ctx)
{
int ret = 0;
if ( ctx )
Expand Down Expand Up @@ -136,7 +136,7 @@ static void SHA1_ProcessBlock(SHA_CTX *ctx)
ctx->h[i] += blks[i];
}

int SHA1_Final(unsigned char *md, SHA_CTX *ctx)
int SHA1_Final_mqtt(unsigned char *md, SHA_CTX *ctx)
{
int i;
int ret = 0;
Expand All @@ -151,7 +151,7 @@ int SHA1_Final(unsigned char *md, SHA_CTX *ctx)
else
pad_amount = 64 + 56 - ctx->size;

SHA1_Update(ctx, pad, pad_amount);
SHA1_Update_mqtt(ctx, pad, pad_amount);

ctx->w[14] = htobe32((uint32_t)(total >> 32));
ctx->w[15] = htobe32((uint32_t)total);
Expand All @@ -170,7 +170,7 @@ int SHA1_Final(unsigned char *md, SHA_CTX *ctx)
return ret;
}

int SHA1_Update(SHA_CTX *ctx, const void *data, size_t len)
int SHA1_Update_mqtt(SHA_CTX *ctx, const void *data, size_t len)
{
while ( len > 0 )
{
Expand Down Expand Up @@ -229,9 +229,9 @@ int main(int argc, char *argv[])
char out[SHA1_DIGEST_LENGTH * 2 + 1];
SHA_CTX c;
int j;
r[0] = SHA1_Init( &c );
r[1] = SHA1_Update( &c, test_data[i].in, strlen(test_data[i].in));
r[2] = SHA1_Final( sha_out, &c );
r[0] = SHA1_Init_mqtt( &c );
r[1] = SHA1_Update_mqtt( &c, test_data[i].in, strlen(test_data[i].in));
r[2] = SHA1_Final_mqtt( sha_out, &c );
for ( j = 0u; j < SHA1_DIGEST_LENGTH; ++j )
snprintf( &out[j*2], 3u, "%02x", sha_out[j] );
out[SHA1_DIGEST_LENGTH * 2] = '\0';
Expand Down
12 changes: 6 additions & 6 deletions src/mqtt/externals/paho-mqtt-c/src/SHA1.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ typedef struct SHA_CTX_S {
*
* @param[in,out] ctx hashing context structure
*
* @see SHA1_Update
* @see SHA1_Update_mqtt
* @see SHA1_Final
*/
int SHA1_Init(SHA_CTX *ctx);
int SHA1_Init_mqtt(SHA_CTX *ctx);

/**
* Updates a block to the SHA1 hash
Expand All @@ -69,10 +69,10 @@ int SHA1_Init(SHA_CTX *ctx);
* @param[in] data block of data to hash
* @param[in] len length of block to hash
*
* @see SHA1_Init
* @see SHA1_Init_mqtt
* @see SHA1_Final
*/
int SHA1_Update(SHA_CTX *ctx, const void *data, size_t len);
int SHA1_Update_mqtt(SHA_CTX *ctx, const void *data, size_t len);

/**
* Produce final SHA1 hash
Expand All @@ -81,10 +81,10 @@ int SHA1_Update(SHA_CTX *ctx, const void *data, size_t len);
* @p SHA1_DIGEST_LENGTH in length)
* @param[in,out] ctx hashing context structure
*
* @see SHA1_Init
* @see SHA1_Init_mqtt
* @see SHA1_Final
*/
int SHA1_Final(unsigned char *md, SHA_CTX *ctx);
int SHA1_Final_mqtt(unsigned char *md, SHA_CTX *ctx);

#endif /* if defined(OPENSSL) */
#endif /* SHA1_H */
Expand Down
6 changes: 3 additions & 3 deletions src/mqtt/externals/paho-mqtt-c/src/WebSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1321,9 +1321,9 @@ int WebSocket_upgrade( networkHandles *net )

/* calculate the expected websocket key, expected from server */
snprintf( ws_key, sizeof(ws_key), "%s%s", net->websocket_key, ws_guid );
SHA1_Init( &ctx );
SHA1_Update( &ctx, ws_key, strlen(ws_key));
SHA1_Final( sha_hash, &ctx );
SHA1_Init_mqtt( &ctx );
SHA1_Update_mqtt( &ctx, ws_key, strlen(ws_key));
SHA1_Final_mqtt( sha_hash, &ctx );
Base64_encode( ws_key, sizeof(ws_key), sha_hash, SHA1_DIGEST_LENGTH );

read_buf = WebSocket_getRawSocketData( net, 12u, &rcv, &rc);
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ set(SLIC3R_GUI_SOURCES
GUI/TaskManager.hpp
Utils/Http.cpp
Utils/Http.hpp
Utils/MQTT.hpp
Utils/MQTT.cpp
Utils/FixModelByWin10.cpp
Utils/FixModelByWin10.hpp
Utils/EmbossStyleManager.cpp
Expand Down
Loading

0 comments on commit d8ffab7

Please sign in to comment.