diff --git a/include/controller.h b/include/controller.h index 342a648..0230f75 100644 --- a/include/controller.h +++ b/include/controller.h @@ -24,13 +24,8 @@ private: // UDP - // buffers for receiving and sending data - char udpReceiveBuffer[SIGNED_MESSAGE_SIZE]; // buffer to hold incoming packet - // An EthernetUDP instance to send and receive packets over UDP - EthernetUDP Udp; - - + EthernetUDP udp; EthernetConfiguration ethernetConfig; bool ethernetIsConfigured = false; diff --git a/src/controller.cpp b/src/controller.cpp index 399fc15..92d59c3 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -52,7 +52,7 @@ void SesameController::configure(ServoConfiguration servoConfig, ServerConfigura server.configure(serverConfig, this); Serial.println("[INFO] Server connection configured"); - Udp.begin(ethernetConfig.udpPort); + udp.begin(ethernetConfig.udpPort); Serial.println("[INFO] Local UDP connection configured"); } @@ -73,32 +73,33 @@ void SesameController::checkLocalMessage() { bool SesameController::readLocalMessage() { // if there's data available, read a packet - int packetSize = Udp.parsePacket(); + int packetSize = udp.parsePacket(); if (packetSize == 0) { return false; } if (packetSize != SIGNED_MESSAGE_SIZE) { - Serial.print("Received packet of invalid size "); + Serial.print("[WARN] Received UDP packet of invalid size "); Serial.println(packetSize); prepareResponseBuffer(MessageResult::InvalidMessageSizeFromRemote); return true; } - int bytesRead = Udp.read((uint8_t*) &receivedLocalMessage, SIGNED_MESSAGE_SIZE); + int bytesRead = udp.read((uint8_t*) &receivedLocalMessage, SIGNED_MESSAGE_SIZE); if (bytesRead != SIGNED_MESSAGE_SIZE) { - Serial.println("Failed to read full local message"); + Serial.println("[WARN] Failed to read full local message"); prepareResponseBuffer(MessageResult::InvalidMessageSizeFromRemote); return true; } - Serial.println("Received local message"); + Serial.println("[INFO] Received local message"); processMessage(&receivedLocalMessage, true); return true; } void SesameController::sendPreparedLocalResponse() { // send a reply to the IP address and port that sent us the packet we received - Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); - Udp.write((uint8_t*) &outgoingMessage, SIGNED_MESSAGE_SIZE); - Udp.endPacket(); + udp.beginPacket(udp.remoteIP(), udp.remotePort()); + udp.write((uint8_t*) &outgoingMessage, SIGNED_MESSAGE_SIZE); + udp.endPacket(); + Serial.println("[INFO] Sent local response"); } // MARK: Server