Teensy 4.1 Ethernet support (#19801)
This commit is contained in:
125
Marlin/src/gcode/feature/network/M552-M554.cpp
Normal file
125
Marlin/src/gcode/feature/network/M552-M554.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_ETHERNET
|
||||
|
||||
#include "../../../feature/ethernet.h"
|
||||
#include "../../../core/serial.h"
|
||||
#include "../../gcode.h"
|
||||
|
||||
void say_ethernet() { SERIAL_ECHOPGM(" Ethernet "); }
|
||||
|
||||
void ETH0_report() {
|
||||
say_ethernet();
|
||||
SERIAL_ECHO_TERNARY(ethernet.hardware_enabled, "port ", "en", "dis", "abled.\n");
|
||||
if (ethernet.hardware_enabled) {
|
||||
say_ethernet();
|
||||
SERIAL_ECHO_TERNARY(ethernet.have_telnet_client, "client ", "en", "dis", "abled.\n");
|
||||
}
|
||||
else
|
||||
SERIAL_ECHOLNPGM("Send 'M552 S1' to enable.");
|
||||
}
|
||||
|
||||
void MAC_report() {
|
||||
uint8_t mac[6];
|
||||
if (ethernet.hardware_enabled) {
|
||||
Ethernet.MACAddress(mac);
|
||||
SERIAL_ECHOPGM(" MAC: ");
|
||||
LOOP_L_N(i, 6) {
|
||||
SERIAL_PRINTF("%02X", mac[i]);
|
||||
if (i < 5) SERIAL_CHAR(':');
|
||||
}
|
||||
}
|
||||
SERIAL_EOL();
|
||||
}
|
||||
|
||||
// Display current values when the link is active,
|
||||
// otherwise show the stored values
|
||||
void ip_report(const uint16_t cmd, PGM_P const post, const IPAddress &ipo) {
|
||||
SERIAL_CHAR('M'); SERIAL_ECHO(cmd); SERIAL_CHAR(' ');
|
||||
LOOP_L_N(i, 4) {
|
||||
SERIAL_ECHO(ipo[i]);
|
||||
if (i < 3) SERIAL_CHAR('.');
|
||||
}
|
||||
SERIAL_ECHOPGM(" ; ");
|
||||
SERIAL_ECHOPGM_P(post);
|
||||
SERIAL_EOL();
|
||||
}
|
||||
void M552_report() {
|
||||
ip_report(552, PSTR("ip address"), Ethernet.linkStatus() == LinkON ? Ethernet.localIP() : ethernet.ip);
|
||||
}
|
||||
void M553_report() {
|
||||
ip_report(553, PSTR("subnet mask"), Ethernet.linkStatus() == LinkON ? Ethernet.subnetMask() : ethernet.subnet);
|
||||
}
|
||||
void M554_report() {
|
||||
ip_report(554, PSTR("gateway"), Ethernet.linkStatus() == LinkON ? Ethernet.gatewayIP() : ethernet.gateway);
|
||||
}
|
||||
|
||||
/**
|
||||
* M552: Set IP address, enable/disable network interface
|
||||
*
|
||||
* S0 : disable networking
|
||||
* S1 : enable networking
|
||||
* S-1 : reset network interface
|
||||
*
|
||||
* Pnnn : Set IP address, 0.0.0.0 means acquire an IP address using DHCP
|
||||
*/
|
||||
void GcodeSuite::M552() {
|
||||
const bool seenP = parser.seenval('P');
|
||||
if (seenP) ethernet.ip.fromString(parser.value_string());
|
||||
|
||||
const bool seenS = parser.seenval('S');
|
||||
if (seenS) {
|
||||
switch (parser.value_int()) {
|
||||
case -1:
|
||||
if (ethernet.telnetClient) ethernet.telnetClient.stop();
|
||||
ethernet.init();
|
||||
break;
|
||||
case 0: ethernet.hardware_enabled = false; break;
|
||||
case 1: ethernet.hardware_enabled = true; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
const bool nopar = !seenS && !seenP;
|
||||
if (nopar || seenS) ETH0_report();
|
||||
if (nopar || seenP) M552_report();
|
||||
}
|
||||
|
||||
/**
|
||||
* M553 Pnnn - Set netmask
|
||||
*/
|
||||
void GcodeSuite::M553() {
|
||||
if (parser.seenval('P')) ethernet.subnet.fromString(parser.value_string());
|
||||
M553_report();
|
||||
}
|
||||
|
||||
/**
|
||||
* M554 Pnnn - Set Gateway
|
||||
*/
|
||||
void GcodeSuite::M554() {
|
||||
if (parser.seenval('P')) ethernet.gateway.fromString(parser.value_string());
|
||||
M554_report();
|
||||
}
|
||||
|
||||
#endif // HAS_ETHERNET
|
@ -766,6 +766,12 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
|
||||
case 540: M540(); break; // M540: Set abort on endstop hit for SD printing
|
||||
#endif
|
||||
|
||||
#if HAS_ETHERNET
|
||||
case 552: M552(); break; // M552: Set IP address
|
||||
case 553: M553(); break; // M553: Set gateway
|
||||
case 554: M554(); break; // M554: Set netmask
|
||||
#endif
|
||||
|
||||
#if ENABLED(BAUD_RATE_GCODE)
|
||||
case 575: M575(); break; // M575: Set serial baudrate
|
||||
#endif
|
||||
|
@ -230,6 +230,9 @@
|
||||
* M512 - Set/Change/Remove Password
|
||||
* M524 - Abort the current SD print job started with M24. (Requires SDSUPPORT)
|
||||
* M540 - Enable/disable SD card abort on endstop hit: "M540 S<state>". (Requires SD_ABORT_ON_ENDSTOP_HIT)
|
||||
* M552 - Get or set IP address. Enable/disable network interface. (Requires enabled Ethernet port)
|
||||
* M553 - Get or set IP netmask. (Requires enabled Ethernet port)
|
||||
* M554 - Get or set IP gateway. (Requires enabled Ethernet port)
|
||||
* M569 - Enable stealthChop on an axis. (Requires at least one _DRIVER_TYPE to be TMC2130/2160/2208/2209/5130/5160)
|
||||
* M600 - Pause for filament change: "M600 X<pos> Y<pos> Z<raise> E<first_retract> L<later_retract>". (Requires ADVANCED_PAUSE_FEATURE)
|
||||
* M603 - Configure filament change: "M603 T<tool> U<unload_length> L<load_length>". (Requires ADVANCED_PAUSE_FEATURE)
|
||||
@ -778,6 +781,12 @@ private:
|
||||
|
||||
TERN_(SD_ABORT_ON_ENDSTOP_HIT, static void M540());
|
||||
|
||||
#if HAS_ETHERNET
|
||||
static void M552();
|
||||
static void M553();
|
||||
static void M554();
|
||||
#endif
|
||||
|
||||
TERN_(BAUD_RATE_GCODE, static void M575());
|
||||
|
||||
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
||||
|
@ -39,6 +39,10 @@ GCodeQueue queue;
|
||||
#include "../feature/leds/printer_event_leds.h"
|
||||
#endif
|
||||
|
||||
#if HAS_ETHERNET
|
||||
#include "../feature/ethernet.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(BINARY_FILE_TRANSFER)
|
||||
#include "../feature/binary_stream.h"
|
||||
#endif
|
||||
@ -312,15 +316,24 @@ void GCodeQueue::flush_and_request_resend() {
|
||||
}
|
||||
|
||||
inline bool serial_data_available() {
|
||||
return MYSERIAL0.available() || TERN0(HAS_MULTI_SERIAL, MYSERIAL1.available());
|
||||
byte data_available = 0;
|
||||
if (MYSERIAL0.available()) data_available++;
|
||||
#ifdef SERIAL_PORT_2
|
||||
const bool port2_open = TERN1(HAS_ETHERNET, ethernet.have_telnet_client);
|
||||
if (port2_open && MYSERIAL1.available()) data_available++;
|
||||
#endif
|
||||
return data_available > 0;
|
||||
}
|
||||
|
||||
inline int read_serial(const uint8_t index) {
|
||||
switch (index) {
|
||||
case 0: return MYSERIAL0.read();
|
||||
#if HAS_MULTI_SERIAL
|
||||
case 1: return MYSERIAL1.read();
|
||||
#endif
|
||||
case 1: {
|
||||
#if HAS_MULTI_SERIAL
|
||||
const bool port2_open = TERN1(HAS_ETHERNET, ethernet.have_telnet_client);
|
||||
if (port2_open) return MYSERIAL1.read();
|
||||
#endif
|
||||
}
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user