Skip to content
Snippets Groups Projects
Commit 099ff4bb authored by Kyrre Ness Sjobaek's avatar Kyrre Ness Sjobaek
Browse files

Add DEFINE flagg NO_ETHERNET

parent 47ecf73e
No related branches found
No related tags found
1 merge request!21Allow to work without ethernet
......@@ -187,6 +187,6 @@ const unsigned int stepper_zeroseek_confirmHitDelay = 1000; //[us]
//#define DUMMY_TEMP
//#define DUMMY_SERVO
//#define DUMMY_STEPPER
//#define NO_ETHERNET
#endif
......@@ -8,6 +8,13 @@
void setup_networkIO() {
//Network setup
Serial.print("Starting networking...\n");
#ifdef NO_ETHERNET
Serial.print("NO_ETHERNET is enabled! Entering serial-only mode.\n");
#else
#ifdef USE_DHCP
Ethernet.begin(mac);
#else
......@@ -50,6 +57,8 @@ void setup_networkIO() {
//Server setup
telnet_socket.begin();
#endif
for (uint8_t i=0; i<telnet_numConnections; i++) {
memset(telnet_buff[i], '\0', sizeof(telnet_buff[i]));
telnet_buffCount[i] = 0;
......@@ -70,6 +79,7 @@ void telnet_server() {
// Program for running the telnet- and serial communication
//1. Check for new connections
#ifndef NO_ETHERNET
while (true) {
//Loop in case there are multiple new connections
EthernetClient newConnection = telnet_socket.accept();
......@@ -99,8 +109,10 @@ void telnet_server() {
break;
}
}
#endif
//2. Check for incoming data (telnet & serial) and buffer it
#ifndef NO_ETHERNET
for (size_t i = 0; i < telnet_numConnections; i++) {
while (telnet_connection[i] &&
telnet_connection[i].connected() &&
......@@ -119,6 +131,7 @@ void telnet_server() {
#endif
}
}
#endif
while (Serial.available() > 0) {
bufferWrite(serial_buff, sizeof(serial_buff), serial_buffCount, Serial.read());
......@@ -141,6 +154,7 @@ void telnet_server() {
bool keepParsing = true;
bool telnet_printReady[telnet_numConnections];
bool serial_printReady = false;
#ifndef NO_ETHERNET
for (size_t i = 0; (i < telnet_numConnections); i++) {
if (not (telnet_connection[i] &&
telnet_connection[i].connected()
......@@ -157,6 +171,7 @@ void telnet_server() {
keepParsing = input_parser(telnet_buff[i], sizeof(telnet_buff[i]), telnet_buffCount[i], &(telnet_connection[i]));
}
}
#endif
if (keepParsing) {
if (serial_buffCount == 0 and serial_buffCount_prev>0) {
serial_printReady = true;
......@@ -170,6 +185,7 @@ void telnet_server() {
output_buff_flush();
//5b. Notify client that TTY is ready for more
#ifndef NO_ETHERNET
for (size_t i = 0; i < telnet_numConnections; i++) {
if (not (telnet_connection[i] &&
telnet_connection[i].connected()
......@@ -180,11 +196,13 @@ void telnet_server() {
telnet_connection[i].print("$\n");
}
}
#endif
if(serial_printReady) {
Serial.print("$\n");
}
//6. Check for telnet disconnects & handle
#ifndef NO_ETHERNET
for (size_t i = 0; i < telnet_numConnections; i++) {
if ( telnet_connection[i] &&
!telnet_connection[i].connected() ) {
......@@ -206,6 +224,7 @@ void telnet_server() {
telnet_buffCount_prev[i]=1;
}
}
#endif
//7. Feed the clients & serial with disconnect messages
output_buff_flush();
}
......@@ -215,12 +234,15 @@ void output_buff_flush() {
// to all clients (TCP/IP and Serial)
if(output_buffCount) {
#ifndef NO_ETHERNET
for (size_t i = 0; i < telnet_numConnections; i++) {
if (telnet_connection[i] &&
telnet_connection[i].connected() ) {
telnet_connection[i].print(output_buff);
}
}
#endif
Serial.print(output_buff);
Serial.flush();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment