My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M552-M554.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfigPre.h"
  23. #if HAS_ETHERNET
  24. #include "../../../feature/ethernet.h"
  25. #include "../../../core/serial.h"
  26. #include "../../gcode.h"
  27. void say_ethernet() { SERIAL_ECHOPGM(" Ethernet "); }
  28. void ETH0_report() {
  29. say_ethernet();
  30. SERIAL_ECHO_TERNARY(ethernet.hardware_enabled, "port ", "en", "dis", "abled.\n");
  31. if (ethernet.hardware_enabled) {
  32. say_ethernet();
  33. SERIAL_ECHO_TERNARY(ethernet.have_telnet_client, "client ", "en", "dis", "abled.\n");
  34. }
  35. else
  36. SERIAL_ECHOLNPGM("Send 'M552 S1' to enable.");
  37. }
  38. void MAC_report() {
  39. uint8_t mac[6];
  40. if (ethernet.hardware_enabled) {
  41. Ethernet.MACAddress(mac);
  42. SERIAL_ECHOPGM(" MAC: ");
  43. LOOP_L_N(i, 6) {
  44. if (mac[i] < 16) SERIAL_CHAR('0');
  45. SERIAL_PRINT(mac[i], HEX);
  46. if (i < 5) SERIAL_CHAR(':');
  47. }
  48. }
  49. SERIAL_EOL();
  50. }
  51. // Display current values when the link is active,
  52. // otherwise show the stored values
  53. void ip_report(const uint16_t cmd, PGM_P const post, const IPAddress &ipo) {
  54. SERIAL_CHAR('M'); SERIAL_ECHO(cmd); SERIAL_CHAR(' ');
  55. LOOP_L_N(i, 4) {
  56. SERIAL_ECHO(ipo[i]);
  57. if (i < 3) SERIAL_CHAR('.');
  58. }
  59. SERIAL_ECHOPGM(" ; ");
  60. SERIAL_ECHOPGM_P(post);
  61. SERIAL_EOL();
  62. }
  63. void M552_report() {
  64. ip_report(552, PSTR("ip address"), Ethernet.linkStatus() == LinkON ? Ethernet.localIP() : ethernet.ip);
  65. }
  66. void M553_report() {
  67. ip_report(553, PSTR("subnet mask"), Ethernet.linkStatus() == LinkON ? Ethernet.subnetMask() : ethernet.subnet);
  68. }
  69. void M554_report() {
  70. ip_report(554, PSTR("gateway"), Ethernet.linkStatus() == LinkON ? Ethernet.gatewayIP() : ethernet.gateway);
  71. }
  72. /**
  73. * M552: Set IP address, enable/disable network interface
  74. *
  75. * S0 : disable networking
  76. * S1 : enable networking
  77. * S-1 : reset network interface
  78. *
  79. * Pnnn : Set IP address, 0.0.0.0 means acquire an IP address using DHCP
  80. */
  81. void GcodeSuite::M552() {
  82. const bool seenP = parser.seenval('P');
  83. if (seenP) ethernet.ip.fromString(parser.value_string());
  84. const bool seenS = parser.seenval('S');
  85. if (seenS) {
  86. switch (parser.value_int()) {
  87. case -1:
  88. if (ethernet.telnetClient) ethernet.telnetClient.stop();
  89. ethernet.init();
  90. break;
  91. case 0: ethernet.hardware_enabled = false; break;
  92. case 1: ethernet.hardware_enabled = true; break;
  93. default: break;
  94. }
  95. }
  96. const bool nopar = !seenS && !seenP;
  97. if (nopar || seenS) ETH0_report();
  98. if (nopar || seenP) M552_report();
  99. }
  100. /**
  101. * M553 Pnnn - Set netmask
  102. */
  103. void GcodeSuite::M553() {
  104. if (parser.seenval('P')) ethernet.subnet.fromString(parser.value_string());
  105. M553_report();
  106. }
  107. /**
  108. * M554 Pnnn - Set Gateway
  109. */
  110. void GcodeSuite::M554() {
  111. if (parser.seenval('P')) ethernet.gateway.fromString(parser.value_string());
  112. M554_report();
  113. }
  114. #endif // HAS_ETHERNET