Added user-selection of IP address via M502.
This commit is contained in:
parent
c7286905b2
commit
104528ab66
8 changed files with 151 additions and 17 deletions
47
GCodes.cpp
47
GCodes.cpp
|
@ -648,6 +648,44 @@ bool GCodes::StandbyHeaters()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GCodes::SetIPAddress(GCodeBuffer *gb)
|
||||||
|
{
|
||||||
|
byte ip[4];
|
||||||
|
char* ipString = gb->GetString();
|
||||||
|
uint8_t sp = 0;
|
||||||
|
uint8_t spp = 0;
|
||||||
|
uint8_t ipp = 0;
|
||||||
|
while(ipString[sp])
|
||||||
|
{
|
||||||
|
if(ipString[sp] == '.')
|
||||||
|
{
|
||||||
|
ipString[sp] = 0;
|
||||||
|
ip[ipp] = atoi(&ipString[spp]);
|
||||||
|
ipString[sp] = '.';
|
||||||
|
ipp++;
|
||||||
|
if(ipp > 3)
|
||||||
|
{
|
||||||
|
platform->Message(HOST_MESSAGE, "Dud IP address: ");
|
||||||
|
platform->Message(HOST_MESSAGE, gb->Buffer());
|
||||||
|
platform->Message(HOST_MESSAGE, "\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sp++;
|
||||||
|
spp = sp;
|
||||||
|
}else
|
||||||
|
sp++;
|
||||||
|
}
|
||||||
|
ip[ipp] = atoi(&ipString[spp]);
|
||||||
|
if(ipp == 3)
|
||||||
|
platform->SetIPAddress(ip);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
platform->Message(HOST_MESSAGE, "Dud IP address: ");
|
||||||
|
platform->Message(HOST_MESSAGE, gb->Buffer());
|
||||||
|
platform->Message(HOST_MESSAGE, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GCodes::HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code)
|
void GCodes::HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code)
|
||||||
{
|
{
|
||||||
Compatibility c = platform->Emulating();
|
Compatibility c = platform->Emulating();
|
||||||
|
@ -1051,7 +1089,14 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
|
||||||
reprap.GetWebserver()->SetName(gb->GetString());
|
reprap.GetWebserver()->SetName(gb->GetString());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 502: // Set IP address
|
case 502: // Set/Get IP address
|
||||||
|
if(gb->Seen('P'))
|
||||||
|
SetIPAddress(gb);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
byte *ip = platform->IPAddress();
|
||||||
|
snprintf(reply, STRING_LENGTH, "IP address: %d.%d.%d.%d\n ", ip[0], ip[1], ip[2], ip[3]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 503: // Set firmware type to emulate
|
case 503: // Set firmware type to emulate
|
||||||
|
|
1
GCodes.h
1
GCodes.h
|
@ -92,6 +92,7 @@ class GCodes
|
||||||
bool Pop();
|
bool Pop();
|
||||||
bool DisableDrives();
|
bool DisableDrives();
|
||||||
bool StandbyHeaters();
|
bool StandbyHeaters();
|
||||||
|
void SetIPAddress(GCodeBuffer *gb);
|
||||||
void HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code);
|
void HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code);
|
||||||
|
|
||||||
int8_t Heater(int8_t head);
|
int8_t Heater(int8_t head);
|
||||||
|
|
|
@ -79,6 +79,8 @@ void Platform::Init()
|
||||||
sysDir = SYS_DIR;
|
sysDir = SYS_DIR;
|
||||||
configFile = CONFIG_FILE;
|
configFile = CONFIG_FILE;
|
||||||
|
|
||||||
|
ipAddress = IP_ADDRESS;
|
||||||
|
|
||||||
// DRIVES
|
// DRIVES
|
||||||
|
|
||||||
stepPins = STEP_PINS;
|
stepPins = STEP_PINS;
|
||||||
|
@ -906,7 +908,6 @@ bool RepRapNetworkHasALiveClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Network::Network()
|
Network::Network()
|
||||||
{
|
{
|
||||||
ethPinsInit();
|
ethPinsInit();
|
||||||
|
@ -947,7 +948,7 @@ void Network::Init()
|
||||||
{
|
{
|
||||||
// alternateInput = NULL;
|
// alternateInput = NULL;
|
||||||
// alternateOutput = NULL;
|
// alternateOutput = NULL;
|
||||||
init_ethernet();
|
init_ethernet(reprap.GetPlatform()->IPAddress());
|
||||||
CleanRing();
|
CleanRing();
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
16
Platform.h
16
Platform.h
|
@ -162,6 +162,8 @@ Licence: GPL
|
||||||
|
|
||||||
#define HTTP_STATE_SIZE 5
|
#define HTTP_STATE_SIZE 5
|
||||||
|
|
||||||
|
#define IP_ADDRESS { 192, 168, 1, 10 } // Need some sort of default...
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************************************/
|
/****************************************************************************************************/
|
||||||
|
|
||||||
|
@ -415,6 +417,8 @@ class Platform
|
||||||
|
|
||||||
Network* GetNetwork();
|
Network* GetNetwork();
|
||||||
Line* GetLine();
|
Line* GetLine();
|
||||||
|
void SetIPAddress(byte ip[]);
|
||||||
|
byte* IPAddress();
|
||||||
|
|
||||||
friend class FileStore;
|
friend class FileStore;
|
||||||
|
|
||||||
|
@ -571,6 +575,7 @@ class Platform
|
||||||
// Network connection
|
// Network connection
|
||||||
|
|
||||||
Network* network;
|
Network* network;
|
||||||
|
byte ipAddress[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
inline float Platform::Time()
|
inline float Platform::Time()
|
||||||
|
@ -878,6 +883,17 @@ inline Network* Platform::GetNetwork()
|
||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Platform::SetIPAddress(byte ip[])
|
||||||
|
{
|
||||||
|
for(uint8_t i = 0; i < 4; i++)
|
||||||
|
ipAddress[i] = ip[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline byte* Platform::IPAddress()
|
||||||
|
{
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
inline Line* Platform::GetLine()
|
inline Line* Platform::GetLine()
|
||||||
{
|
{
|
||||||
return line;
|
return line;
|
||||||
|
|
|
@ -177,11 +177,10 @@ void RepRap::Init()
|
||||||
heat->Init();
|
heat->Init();
|
||||||
active = true;
|
active = true;
|
||||||
gCodes->RunConfigurationGCodes();
|
gCodes->RunConfigurationGCodes();
|
||||||
platform->StartNetwork(); // Need to do this hare, as the configuration GCodes may set IP address etc.
|
while(gCodes->PrintingAFile()) // Wait till the file is finished
|
||||||
|
Spin();
|
||||||
|
platform->StartNetwork(); // Need to do this here, as the configuration GCodes may set IP address etc.
|
||||||
platform->Message(HOST_MESSAGE, "RepRapPro RepRap Firmware (Re)Started\n");
|
platform->Message(HOST_MESSAGE, "RepRapPro RepRap Firmware (Re)Started\n");
|
||||||
// platform->Message(HOST_MESSAGE, "Free memory: ");
|
|
||||||
// snprintf(scratchString,STRING_LENGTH,"%d\n",platform->GetFreeMemory());
|
|
||||||
// platform->Message(HOST_MESSAGE, scratchString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepRap::Exit()
|
void RepRap::Exit()
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
; RepRapPro Ormerod
|
; RepRapPro Ormerod
|
||||||
; Standard configuration G Codes
|
; Standard configuration G Codes
|
||||||
M111 S1; Debug on
|
M111 S1; Debug on
|
||||||
M501 POrmerod
|
M500 Preprap; Set the password
|
||||||
M500 Preprap
|
M501 POrmerod; Set the machine's name
|
||||||
G21 ; mm
|
M502 P192.168.1.14; Set the IP address
|
||||||
|
G21 ; Work in mm
|
||||||
G90 ; Absolute positioning
|
G90 ; Absolute positioning
|
||||||
M83 ; Extrusion relative
|
M83 ; Extrusions relative
|
||||||
G31 Z0.0 P500 ; Set Z probe height and threshold
|
G31 Z0.0 P500 ; Set Z probe height and threshold
|
||||||
M906 X800 Y800 Z800 E800 ; Motor currents (mA)
|
M906 X800 Y800 Z800 E800 ; Motor currents (mA)
|
||||||
T0 ; Extruder 0
|
T0 ; Select extruder 0
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,71 @@ static void timers_update(void)
|
||||||
//err_t ethernetif_init_(struct netif *netif){return ERR_OK;};
|
//err_t ethernetif_init_(struct netif *netif){return ERR_OK;};
|
||||||
//err_t ethernet_input_(struct pbuf *p, struct netif *netif){return ERR_OK;};
|
//err_t ethernet_input_(struct pbuf *p, struct netif *netif){return ERR_OK;};
|
||||||
|
|
||||||
static void ethernet_configure_interface(void)
|
//static void ethernet_configure_interface(void)
|
||||||
|
//{
|
||||||
|
// struct ip_addr x_ip_addr, x_net_mask, x_gateway;
|
||||||
|
// extern err_t ethernetif_init(struct netif *netif);
|
||||||
|
//
|
||||||
|
//#if defined(DHCP_USED)
|
||||||
|
// x_ip_addr.addr = 0;
|
||||||
|
// x_net_mask.addr = 0;
|
||||||
|
//#else
|
||||||
|
// /* Default ip addr */
|
||||||
|
// IP4_ADDR(&x_ip_addr, ETHERNET_CONF_IPADDR0, ETHERNET_CONF_IPADDR1, ETHERNET_CONF_IPADDR2, ETHERNET_CONF_IPADDR3);
|
||||||
|
//
|
||||||
|
// /* Default subnet mask */
|
||||||
|
// IP4_ADDR(&x_net_mask, ETHERNET_CONF_NET_MASK0, ETHERNET_CONF_NET_MASK1, ETHERNET_CONF_NET_MASK2, ETHERNET_CONF_NET_MASK3);
|
||||||
|
//
|
||||||
|
// /* Default gateway addr */
|
||||||
|
// IP4_ADDR(&x_gateway, ETHERNET_CONF_GATEWAY_ADDR0, ETHERNET_CONF_GATEWAY_ADDR1, ETHERNET_CONF_GATEWAY_ADDR2, ETHERNET_CONF_GATEWAY_ADDR3);
|
||||||
|
//#endif
|
||||||
|
//
|
||||||
|
// /* Add data to netif */
|
||||||
|
// netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL,
|
||||||
|
// ethernetif_init, ethernet_input);
|
||||||
|
//
|
||||||
|
// /* Make it the default interface */
|
||||||
|
// netif_set_default(&gs_net_if);
|
||||||
|
//
|
||||||
|
// /* Setup callback function for netif status change */
|
||||||
|
// netif_set_status_callback(&gs_net_if, status_callback);
|
||||||
|
//
|
||||||
|
// /* Bring it up */
|
||||||
|
//#if defined(DHCP_USED)
|
||||||
|
// printf("LwIP: DHCP Started");
|
||||||
|
// dhcp_start(&gs_net_if);
|
||||||
|
//#else
|
||||||
|
//// printf("LwIP: Static IP Address Assigned\r\n");
|
||||||
|
// netif_set_up(&gs_net_if);
|
||||||
|
//#endif
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
///** \brief Create ethernet task, for ethernet management.
|
||||||
|
// *
|
||||||
|
// */
|
||||||
|
//void init_ethernet(void)
|
||||||
|
//{
|
||||||
|
// /* Initialize lwIP */
|
||||||
|
// lwip_init();
|
||||||
|
//
|
||||||
|
// /* Set hw and IP parameters, initialize MAC too */
|
||||||
|
// ethernet_configure_interface();
|
||||||
|
//
|
||||||
|
// /* Init timer service */
|
||||||
|
// sys_init_timing();
|
||||||
|
//
|
||||||
|
//#if defined(HTTP_RAW_USED)
|
||||||
|
// /* Bring up the web server */
|
||||||
|
// httpd_init();
|
||||||
|
//#endif
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
//************************************************************************************************************
|
||||||
|
|
||||||
|
// Added by AB.
|
||||||
|
|
||||||
|
static void ethernet_configure_interface(unsigned char ipAddress[])
|
||||||
{
|
{
|
||||||
struct ip_addr x_ip_addr, x_net_mask, x_gateway;
|
struct ip_addr x_ip_addr, x_net_mask, x_gateway;
|
||||||
extern err_t ethernetif_init(struct netif *netif);
|
extern err_t ethernetif_init(struct netif *netif);
|
||||||
|
@ -158,7 +222,9 @@ static void ethernet_configure_interface(void)
|
||||||
x_net_mask.addr = 0;
|
x_net_mask.addr = 0;
|
||||||
#else
|
#else
|
||||||
/* Default ip addr */
|
/* Default ip addr */
|
||||||
IP4_ADDR(&x_ip_addr, ETHERNET_CONF_IPADDR0, ETHERNET_CONF_IPADDR1, ETHERNET_CONF_IPADDR2, ETHERNET_CONF_IPADDR3);
|
//IP4_ADDR(&x_ip_addr, ETHERNET_CONF_IPADDR0, ETHERNET_CONF_IPADDR1, ETHERNET_CONF_IPADDR2, ETHERNET_CONF_IPADDR3);
|
||||||
|
|
||||||
|
IP4_ADDR(&x_ip_addr, ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3]);
|
||||||
|
|
||||||
/* Default subnet mask */
|
/* Default subnet mask */
|
||||||
IP4_ADDR(&x_net_mask, ETHERNET_CONF_NET_MASK0, ETHERNET_CONF_NET_MASK1, ETHERNET_CONF_NET_MASK2, ETHERNET_CONF_NET_MASK3);
|
IP4_ADDR(&x_net_mask, ETHERNET_CONF_NET_MASK0, ETHERNET_CONF_NET_MASK1, ETHERNET_CONF_NET_MASK2, ETHERNET_CONF_NET_MASK3);
|
||||||
|
@ -190,13 +256,13 @@ static void ethernet_configure_interface(void)
|
||||||
/** \brief Create ethernet task, for ethernet management.
|
/** \brief Create ethernet task, for ethernet management.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void init_ethernet(void)
|
void init_ethernet(unsigned char ipAddress[])
|
||||||
{
|
{
|
||||||
/* Initialize lwIP */
|
/* Initialize lwIP */
|
||||||
lwip_init();
|
lwip_init();
|
||||||
|
|
||||||
/* Set hw and IP parameters, initialize MAC too */
|
/* Set hw and IP parameters, initialize MAC too */
|
||||||
ethernet_configure_interface();
|
ethernet_configure_interface(ipAddress);
|
||||||
|
|
||||||
/* Init timer service */
|
/* Init timer service */
|
||||||
sys_init_timing();
|
sys_init_timing();
|
||||||
|
@ -207,6 +273,9 @@ void init_ethernet(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//*************************************************************************************************************
|
||||||
/**
|
/**
|
||||||
* \brief Status callback used to print address given by DHCP.
|
* \brief Status callback used to print address given by DHCP.
|
||||||
*
|
*
|
||||||
|
|
|
@ -58,7 +58,9 @@ extern "C" {
|
||||||
* \brief Initialize the ethernet interface.
|
* \brief Initialize the ethernet interface.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void init_ethernet(void);
|
//void init_ethernet(void);
|
||||||
|
|
||||||
|
void init_ethernet(unsigned char *ipAddress);
|
||||||
|
|
||||||
struct netif* GetConfiguration();
|
struct netif* GetConfiguration();
|
||||||
|
|
||||||
|
|
Reference in a new issue