<commit_before>
#include "ServerConnection.h"
#include "ObjectStore.h"
#include "Configuration.h"
#include <EEPROM.h>
#include <avr/wdt.h>

const long reconnectTime = 1000;

void reboot() {
  wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it.
  while (true); // do nothing and wait for the eventual...
}

ServerConnection::ServerConnection()
{
  this->lastReconnect = millis() - reconnectTime;
  Serial.print("Attempting to aquire IP from DHCP...");
  byte mac[6];
  Configuration::getMAC(mac);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("");
    Serial.println("Failed to configure Ethernet using DHCP, rebooting");
    Serial.flush();
    reboot();
  }
  //Print IP address
  Serial.print(" ");
  Serial.println(Ethernet.localIP());
}

void ServerConnection::loadSaved()
{
  IPAddress ip = Configuration::getServer();
  this->setServer(ip);
}

void ServerConnection::setServer(IPAddress serverIP)
{
  this->serverIP = serverIP;
}

void ServerConnection::println(String data)
{
  if (!this->server.connected())
  {
    return;
  }
  this->server.println(data);
}

void ServerConnection::loop()
{
  if (!this->server.connected() && (millis() - this->lastReconnect > reconnectTime)) {
    Serial.print("(Re)connecting...");
    this->server.stop();
    this->server.setClientTimeout(100);
    byte returnVal = this->server.connect(this->serverIP, 9999);
    if (returnVal == 1)
    {
      Serial.println(" done");
      this->inputString = "";
    }
    else
    {
      Serial.println(" failed");
    }
    this->lastReconnect = millis();
  } else if (this->server) {
    while (this->server.available()) {
      // get the new byte:
      char inChar = (char)this->server.read();
      // add it to the inputString:
      if (inChar == 'E') {
        long order = strtoul(this->inputString.c_str(), NULL, 16);
        // Reset the input
        this->inputString = "";
        if (order != 0) {
          int orderVal = order & 0x0F;
          int objectNum = order / 10;
          if ((objectNum > 0) && (objectNum <= 4)) {
            byte orderData[] = {orderVal};
            ObjectStore::getInstance().handleOrder(String("Points " + String(objectNum)), orderData, 1);
          }
          order = 0;
        }
      } else
        this->inputString += inChar;
    }
  }
}
<commit_msg>Fixes to ServerConnection<commit_after>
#include "ServerConnection.h"
#include "ObjectStore.h"
#include "Configuration.h"
#include <EEPROM.h>
#include <avr/wdt.h>

const long reconnectTime = 1000;

void reboot() {
  wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it.
  while (true); // do nothing and wait for the eventual...
}

ServerConnection::ServerConnection()
{
  this->lastReconnect = millis() - reconnectTime;
  Serial.print("Attempting to aquire IP from DHCP... ");
  byte mac[6];
  Configuration::getMAC(mac);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println(" failed, rebooting");
    Serial.flush();
    reboot();
  }
  // Print IP address
  Serial.println(Ethernet.localIP());
}

void ServerConnection::loadSaved()
{
  IPAddress ip = Configuration::getServer();
  this->setServer(ip);
}

void ServerConnection::setServer(IPAddress serverIP)
{
  this->serverIP = serverIP;
}

void ServerConnection::println(String data)
{
  if (!this->server.connected())
  {
    return;
  }
  this->server.println(data);
}

void ServerConnection::loop()
{
  if (!this->server.connected() && (millis() - this->lastReconnect > reconnectTime)) {
    Serial.print("(Re)connecting...");
    this->server.stop();
    this->server.setClientTimeout(100);
    byte returnVal = this->server.connect(this->serverIP, 9999);
    if (returnVal == 1)
    {
      Serial.println(" done");
      this->inputString = "";
    }
    else
    {
      Serial.println(" failed");
    }
    this->lastReconnect = millis();
  } else if (this->server) {
    while (this->server.available()) {
      // get the new byte:
      char inChar = (char)this->server.read();
      // add it to the inputString:
      if (inChar == 'E') {
        int objectNum = String(this->inputString[0]).toInt();
        int orderVal = String(this->inputString[1]).toInt();
        // Reset the input
        this->inputString = "";
        if ((objectNum > 0) && (objectNum <= 4)) {
          byte orderData[] = {orderVal};
          ObjectStore::getInstance().handleOrder(String("Points " + String(objectNum)), orderData, 1);
        }
      } else
        this->inputString += inChar;
    }
  }
}

{'fraction_non_alphanumeric': 0.16114887086165314, 'fraction_numerical': 0.01052400789300592, 'mean_word_length': 3.001754385964912, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5736930', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1437, 'n_words': 324}