Skip to content

Commit

Permalink
broadcast improvements and cleaning
Browse files Browse the repository at this point in the history
- broadcast improvements with broadcast auto reset
- code cleaning
  • Loading branch information
Paciente8159 committed Sep 24, 2024
1 parent afa2511 commit ecd7fec
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 418 deletions.
2 changes: 1 addition & 1 deletion uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ void cnc_reset(void)
#ifdef ENABLE_MAIN_LOOP_MODULES
EVENT_INVOKE(cnc_reset, NULL);
#endif
grbl_stream_broadcast(true);
grbl_stream_start_broadcast();
grbl_protocol_print(MSG_STARTUP);
}

Expand Down
11 changes: 5 additions & 6 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static uint8_t parser_grbl_command(void)

settings_save(block_address, NULL, UINT16_MAX);
// run startup block
grbl_stream_broadcast(true);
grbl_stream_start_broadcast();
grbl_stream_eeprom(block_address);
// checks the command validity
error = parser_fetch_command(&next_state, &words, &cmd);
Expand All @@ -493,7 +493,7 @@ static uint8_t parser_grbl_command(void)
// error = parser_validate_command(&next_state, &words, &cmd);
// }

grbl_stream_broadcast(false);

// reset streams
grbl_stream_change(NULL);

Expand Down Expand Up @@ -721,7 +721,7 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w
#ifdef ECHO_CMD
if (!wordcount)
{
grbl_stream_broadcast(true);
grbl_stream_start_broadcast();
grbl_protocol_print(MSG_ECHO);
}
#endif
Expand All @@ -733,7 +733,7 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w
parser_discard_command();
#ifdef ECHO_CMD
grbl_protocol_print(MSG_END);
grbl_stream_broadcast(false);

#endif
return error;
}
Expand Down Expand Up @@ -791,7 +791,7 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w
DEBUG_PUTC('\n');
#ifdef ECHO_CMD
grbl_protocol_print(MSG_END);
grbl_stream_broadcast(false);

#endif
return STATUS_OK;
case 'G':
Expand Down Expand Up @@ -835,7 +835,6 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w
parser_discard_command();
#ifdef ECHO_CMD
grbl_protocol_print(MSG_END);
grbl_stream_broadcast(false);
#endif
return error;
}
Expand Down
26 changes: 13 additions & 13 deletions uCNC/src/hal/mcus/esp32/esp32_arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ extern "C"
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
default:
WiFi.mode(WIFI_AP_STA);
Expand All @@ -163,7 +163,7 @@ extern "C"
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
}

Expand Down Expand Up @@ -206,7 +206,7 @@ extern "C"
else
{
sprintf((char *)str, "SSID>%s", wifi_settings.ssid);
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
}
*(cmd_params->error) = STATUS_OK;
return EVENT_HANDLED;
Expand All @@ -225,13 +225,13 @@ extern "C"

// print the list of networks seen:
sprintf((char *)str, "%d available networks", numSsid);
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);

// print the network number and name for each network found:
for (int netid = 0; netid < numSsid; netid++)
{
sprintf((char *)str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid).c_str(), WiFi.RSSI(netid));
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
}
*(cmd_params->error) = STATUS_OK;
return EVENT_HANDLED;
Expand Down Expand Up @@ -320,17 +320,17 @@ extern "C"
{
case 1:
sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
case 2:
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
default:
sprintf((char *)str, "STA IP>%s", WiFi.localIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
sprintf((char *)str, "AP IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
}
}
Expand Down Expand Up @@ -379,9 +379,9 @@ extern "C"
connected = true;
grbl_protocol_feedback("Connected to WiFi");
sprintf((char *)str, "SSID>%s", wifi_settings.ssid);
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
}

if (telnet_server.hasClient())
Expand Down Expand Up @@ -812,7 +812,7 @@ extern "C"
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
default:
WiFi.mode(WIFI_AP_STA);
Expand All @@ -822,7 +822,7 @@ extern "C"
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
}
}
Expand Down
26 changes: 13 additions & 13 deletions uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extern "C"
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
default:
WiFi.mode(WIFI_AP_STA);
Expand All @@ -125,7 +125,7 @@ extern "C"
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ extern "C"
else
{
sprintf((char *)str, "SSID>%s", wifi_settings.ssid);
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
}
*(cmd_params->error) = STATUS_OK;
return EVENT_HANDLED;
Expand All @@ -187,13 +187,13 @@ extern "C"

// print the list of networks seen:
sprintf((char *)str, "%d available networks", numSsid);
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);

// print the network number and name for each network found:
for (int netid = 0; netid < numSsid; netid++)
{
sprintf((char *)str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid).c_str(), WiFi.RSSI(netid));
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
}
*(cmd_params->error) = STATUS_OK;
return EVENT_HANDLED;
Expand Down Expand Up @@ -284,17 +284,17 @@ extern "C"
{
case 1:
sprintf((char *)str, "STA IP>%s", WiFi.localIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
sprintf((char *)str, "AP IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
case 2:
sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
default:
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
}
}
Expand Down Expand Up @@ -343,9 +343,9 @@ extern "C"
connected = true;
grbl_protocol_feedback("Connected to WiFi");
sprintf((char *)str, "SSID>%s", wifi_settings.ssid);
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
}

if (telnet_server.hasClient())
Expand Down Expand Up @@ -756,7 +756,7 @@ extern "C"
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
default:
WiFi.mode(WIFI_AP_STA);
Expand All @@ -766,7 +766,7 @@ extern "C"
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
}
}
Expand Down
26 changes: 13 additions & 13 deletions uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ bool mcu_custom_grbl_cmd(void *args)
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
default:
WiFi.mode(WIFI_AP_STA);
Expand All @@ -165,7 +165,7 @@ bool mcu_custom_grbl_cmd(void *args)
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
}

Expand Down Expand Up @@ -207,7 +207,7 @@ bool mcu_custom_grbl_cmd(void *args)
else
{
sprintf((char *)str, "SSID>%s", wifi_settings.ssid);
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
}
*(cmd_params->error) = STATUS_OK;
return EVENT_HANDLED;
Expand All @@ -226,13 +226,13 @@ bool mcu_custom_grbl_cmd(void *args)

// print the list of networks seen:
sprintf((char *)str, "%d available networks", numSsid);
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);

// print the network number and name for each network found:
for (int netid = 0; netid < numSsid; netid++)
{
sprintf((char *)str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid), WiFi.RSSI(netid));
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
}
*(cmd_params->error) = STATUS_OK;
return EVENT_HANDLED;
Expand Down Expand Up @@ -320,17 +320,17 @@ bool mcu_custom_grbl_cmd(void *args)
{
case 1:
sprintf((char *)str, "STA IP>%s", WiFi.localIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
sprintf((char *)str, "AP IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
case 2:
sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
default:
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
}
}
Expand Down Expand Up @@ -379,9 +379,9 @@ bool rp2040_wifi_clientok(void)
connected = true;
grbl_protocol_feedback("Connected to WiFi");
sprintf((char *)str, "SSID>%s", wifi_settings.ssid);
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
}

if (telnet_server.hasClient())
Expand Down Expand Up @@ -789,7 +789,7 @@ void rp2040_wifi_bt_init(void)
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
default:
WiFi.mode(WIFI_AP_STA);
Expand All @@ -799,7 +799,7 @@ void rp2040_wifi_bt_init(void)
grbl_protocol_feedback("AP started");
grbl_protocol_feedback("SSID>" BOARD_NAME);
sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str());
grbl_protocol_sprintf(str);
grbl_protocol_feedback("%s", str);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/interface/grbl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ extern "C"
#define MSG_HELP "[HLP:$$ $# $G $I $N $x=val $Nx=line $J=line $C $X $H ~ ! ? ctrl-x]" MSG_EOL

// Non query feedback messages
#define MSG_START "[MSG:"
#define MSG_START "MSG:"
#define MSG_END "]" MSG_EOL
#define MSG_FEEDBACK MSG_START "%S" MSG_END
#define MSG_FEEDBACK_PRINTF MSG_START "%s" MSG_END
Expand Down
Loading

0 comments on commit ecd7fec

Please sign in to comment.