Added user-selection of IP address via M502.

This commit is contained in:
Adrian Bowyer 2013-11-17 17:58:30 +00:00
parent c7286905b2
commit 104528ab66
8 changed files with 151 additions and 17 deletions

View file

@ -648,6 +648,44 @@ bool GCodes::StandbyHeaters()
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)
{
Compatibility c = platform->Emulating();
@ -1051,7 +1089,14 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
reprap.GetWebserver()->SetName(gb->GetString());
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;
case 503: // Set firmware type to emulate

View file

@ -92,6 +92,7 @@ class GCodes
bool Pop();
bool DisableDrives();
bool StandbyHeaters();
void SetIPAddress(GCodeBuffer *gb);
void HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code);
int8_t Heater(int8_t head);

View file

@ -79,6 +79,8 @@ void Platform::Init()
sysDir = SYS_DIR;
configFile = CONFIG_FILE;
ipAddress = IP_ADDRESS;
// DRIVES
stepPins = STEP_PINS;
@ -906,7 +908,6 @@ bool RepRapNetworkHasALiveClient()
}
Network::Network()
{
ethPinsInit();
@ -947,7 +948,7 @@ void Network::Init()
{
// alternateInput = NULL;
// alternateOutput = NULL;
init_ethernet();
init_ethernet(reprap.GetPlatform()->IPAddress());
CleanRing();
Reset();
}

View file

@ -162,6 +162,8 @@ Licence: GPL
#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();
Line* GetLine();
void SetIPAddress(byte ip[]);
byte* IPAddress();
friend class FileStore;
@ -571,6 +575,7 @@ class Platform
// Network connection
Network* network;
byte ipAddress[4];
};
inline float Platform::Time()
@ -878,6 +883,17 @@ inline Network* Platform::GetNetwork()
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()
{
return line;

View file

@ -177,11 +177,10 @@ void RepRap::Init()
heat->Init();
active = true;
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, "Free memory: ");
// snprintf(scratchString,STRING_LENGTH,"%d\n",platform->GetFreeMemory());
// platform->Message(HOST_MESSAGE, scratchString);
}
void RepRap::Exit()

View file

@ -1,13 +1,14 @@
; RepRapPro Ormerod
; Standard configuration G Codes
M111 S1; Debug on
M501 POrmerod
M500 Preprap
G21 ; mm
M500 Preprap; Set the password
M501 POrmerod; Set the machine's name
M502 P192.168.1.14; Set the IP address
G21 ; Work in mm
G90 ; Absolute positioning
M83 ; Extrusion relative
M83 ; Extrusions relative
G31 Z0.0 P500 ; Set Z probe height and threshold
M906 X800 Y800 Z800 E800 ; Motor currents (mA)
T0 ; Extruder 0
T0 ; Select extruder 0

View file

@ -148,7 +148,71 @@ static void timers_update(void)
//err_t ethernetif_init_(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;
extern err_t ethernetif_init(struct netif *netif);
@ -158,7 +222,9 @@ static void ethernet_configure_interface(void)
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);
//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 */
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.
*
*/
void init_ethernet(void)
void init_ethernet(unsigned char ipAddress[])
{
/* Initialize lwIP */
lwip_init();
/* Set hw and IP parameters, initialize MAC too */
ethernet_configure_interface();
ethernet_configure_interface(ipAddress);
/* Init timer service */
sys_init_timing();
@ -207,6 +273,9 @@ void init_ethernet(void)
#endif
}
//*************************************************************************************************************
/**
* \brief Status callback used to print address given by DHCP.
*

View file

@ -58,7 +58,9 @@ extern "C" {
* \brief Initialize the ethernet interface.
*
*/
void init_ethernet(void);
//void init_ethernet(void);
void init_ethernet(unsigned char *ipAddress);
struct netif* GetConfiguration();