From 1c749dba9eccf901617a6ed81de4b48e9867c52f Mon Sep 17 00:00:00 2001 From: Adrian Bowyer Date: Sun, 23 Feb 2014 16:50:58 +0000 Subject: [PATCH] Continuing with adding comments to .h files --- Platform.cpp | 43 ++++++++++++++--------------- Platform.h | 77 ++++++++++++++++++++++++++++------------------------ 2 files changed, 62 insertions(+), 58 deletions(-) diff --git a/Platform.cpp b/Platform.cpp index 7fb1956..89bdedb 100644 --- a/Platform.cpp +++ b/Platform.cpp @@ -1028,6 +1028,7 @@ void Network::Init() init_ethernet(reprap.GetPlatform()->IPAddress(), reprap.GetPlatform()->NetMask(), reprap.GetPlatform()->GateWay()); active = true; sentPacketsOutstanding = 0; + windowedSendPackets = WINDOWED_SEND_PACKETS; } void Network::Spin() @@ -1109,11 +1110,11 @@ void Network::Write(char b) if(outputPointer == ARRAY_SIZE(outputBuffer)) { -#if WINDOWED_SEND_PACKETS > 1 - ++sentPacketsOutstanding; -#else - SetWriteEnable(false); // Stop further writing from Webserver until the network tells us that this has gone -#endif + if(windowedSendPackets > 1) + ++sentPacketsOutstanding; + else + SetWriteEnable(false); // Stop further writing from Webserver until the network tells us that this has gone + RepRapNetworkSendOutput(outputBuffer, outputPointer, netRingGetPointer->Pbuf(), netRingGetPointer->Pcb(), netRingGetPointer->Hs()); outputPointer = 0; } @@ -1153,7 +1154,7 @@ void Network::ReceiveInput(char* data, int length, void* pbuf, void* pcb, void* reprap.GetPlatform()->Message(HOST_MESSAGE, "Network::ReceiveInput() - Ring buffer full!\n"); return; } - netRingAddPointer->Set(data, length, pbuf, pcb, hs); + netRingAddPointer->Init(data, length, pbuf, pcb, hs); netRingAddPointer = netRingAddPointer->Next(); //reprap.GetPlatform()->Message(HOST_MESSAGE, "Network - input received.\n"); } @@ -1161,11 +1162,9 @@ void Network::ReceiveInput(char* data, int length, void* pbuf, void* pcb, void* bool Network::CanWrite() const { -#if WINDOWED_SEND_PACKETS > 1 - return writeEnabled && sentPacketsOutstanding < WINDOWED_SEND_PACKETS; -#else + if(windowedSendPackets > 1) + return writeEnabled && sentPacketsOutstanding < windowedSendPackets; return writeEnabled; -#endif } void Network::SetWriteEnable(bool enable) @@ -1179,18 +1178,18 @@ void Network::SetWriteEnable(bool enable) void Network::SentPacketAcknowledged() { -#if WINDOWED_SEND_PACKETS > 1 - if (sentPacketsOutstanding != 0) + if(windowedSendPackets > 1) { - --sentPacketsOutstanding; - } - if (closePending && sentPacketsOutstanding == 0) - { - Close(); - } -#else - SetWriteEnable(true); -#endif + if (sentPacketsOutstanding != 0) + { + --sentPacketsOutstanding; + } + if (closePending && sentPacketsOutstanding == 0) + { + Close(); + } + } else + SetWriteEnable(true); } @@ -1255,7 +1254,7 @@ void NetRing::Free() active = false; } -bool NetRing::Set(char* d, int l, void* pb, void* pc, void* h) +bool NetRing::Init(char* d, int l, void* pb, void* pc, void* h) { if(active) return false; diff --git a/Platform.h b/Platform.h index edf75ac..f2d95b6 100644 --- a/Platform.h +++ b/Platform.h @@ -224,32 +224,35 @@ class NetRing friend class Network; protected: + NetRing(NetRing* n); - NetRing* Next(); - bool Set(char* d, int l, void* pb, void* pc, void* h); - char* Data(); - int Length(); - bool ReadFinished(); - void SetReadFinished(); - void* Pbuf(); - void* Pcb(); - void* Hs(); - bool Active(); - void Free(); - void SetNext(NetRing* n); - void ReleasePbuf(); - void ReleaseHs(); + NetRing* Next(); // Next ring entry + bool Init(char* d, int l, // Set up a ring entry + void* pb, void* pc, void* h); + char* Data(); // Pointer to the data + int Length(); // How much data + bool ReadFinished(); // Have we read the data? + void SetReadFinished(); // Set if we've read the data + void* Pbuf(); // Ethernet structure pointer that needs to be preserved + void* Pcb(); // Ethernet structure pointer that needs to be preserved + void* Hs(); // Ethernet structure pointer that needs to be preserved + bool Active(); // Is this ring entry live? + void Free(); // Is this ring entry in use? + void SetNext(NetRing* n); // Set the next ring entry - only used at the start + void ReleasePbuf(); // Set the ethernet structure pointer null + void ReleaseHs(); // Set the ethernet structure pointer null private: - void Reset(); - void* pbuf; - void* pcb; - void* hs; - char* data; - int length; - bool read; - bool active; - NetRing* next; + + //void Reset(); + void* pbuf; // Ethernet structure pointer that needs to be preserved + void* pcb; // Ethernet structure pointer that needs to be preserved + void* hs; // Ethernet structure pointer that needs to be preserved + char* data; // Pointer to the data + int length; // How much data + bool read; // Have we read the data? + bool active; // Is this ring entry live? + NetRing* next; // Next ring entry }; // The main network class that drives the network. @@ -258,19 +261,20 @@ class Network { public: - int8_t Status() const; // Returns OR of IOStatus - bool Read(char& b); - bool CanWrite() const; - void SetWriteEnable(bool enable); - void SentPacketAcknowledged(); - void Write(char b); - void Write(const char* s); - void Close(); - void ReceiveInput(char* data, int length, void* pb, void* pc, void* h); - void InputBufferReleased(void* pb); - void ConnectionError(void* h); - bool Active() const; - bool LinkIsUp(); + int8_t Status() const; // Returns OR of IOStatus + bool Read(char& b); // Called to read a byte from the network + bool CanWrite() const; // Can we send data? + void SetWriteEnable(bool enable); // Set the enabling of data writing + void SentPacketAcknowledged(); // Called to tell us a packet has gone + void Write(char b); // Send a byte to the network + void Write(const char* s); // Send a string to the network + void Close(); // Close the connection represented by this ring entry + void ReceiveInput(char* data, int length,// Called to give us some input + void* pb, void* pc, void* h); + void InputBufferReleased(void* pb); // Called to release the input buffer + void ConnectionError(void* h); // Called when a network error has occured + bool Active() const; // Is the network connection live? + bool LinkIsUp(); // Is the network link up? friend class Platform; @@ -296,6 +300,7 @@ private: NetRing* netRingAddPointer; bool active; uint8_t sentPacketsOutstanding; // count of TCP packets we have sent that have not been acknowledged + uint8_t windowedSendPackets; }; // This class handles serial I/O - typically via USB