Merge remote-tracking branch 'upstream/duet' into duet

This commit is contained in:
Tony 2014-01-14 21:03:02 +00:00
commit 34a63f9968
14 changed files with 173 additions and 110 deletions

View file

@ -24,8 +24,8 @@ Licence: GPL
#define CONFIGURATION_H #define CONFIGURATION_H
#define NAME "RepRapFirmware" #define NAME "RepRapFirmware"
#define VERSION "0.54" #define VERSION "0.57"
#define DATE "2014-01-06" #define DATE "2014-01-13"
#define LAST_AUTHOR "reprappro.com" #define LAST_AUTHOR "reprappro.com"
// Other firmware that we might switch to be compatible with. // Other firmware that we might switch to be compatible with.
@ -67,7 +67,7 @@ enum Compatibility
// Webserver stuff // Webserver stuff
#define NETWORK true // Set true to turn the ethernet on //#define NETWORK true // Set true to turn the ethernet on
#define DEFAULT_PASSWORD "reprap" #define DEFAULT_PASSWORD "reprap"
#define DEFAULT_NAME "My RepRap 1" #define DEFAULT_NAME "My RepRap 1"

View file

@ -111,8 +111,6 @@ void GCodes::Spin()
if(!active) if(!active)
return; return;
char b;
// Check each of the sources of G Codes (web, serial, and file) to // Check each of the sources of G Codes (web, serial, and file) to
// see if what they are doing has been done. If it hasn't, return without // see if what they are doing has been done. If it hasn't, return without
// looking at anything else. // looking at anything else.
@ -147,7 +145,7 @@ void GCodes::Spin()
if(webserver->GCodeAvailable()) if(webserver->GCodeAvailable())
{ {
b = webserver->ReadGCode(); char b = webserver->ReadGCode();
if(webGCode->Put(b)) if(webGCode->Put(b))
{ {
if(webGCode->WritingFileDirectory() != NULL) if(webGCode->WritingFileDirectory() != NULL)
@ -166,6 +164,7 @@ void GCodes::Spin()
{ {
if(platform->GetLine()->Status() & byteAvailable) if(platform->GetLine()->Status() & byteAvailable)
{ {
char b;
platform->GetLine()->Read(b); platform->GetLine()->Read(b);
WriteHTMLToFile(b, serialGCode); WriteHTMLToFile(b, serialGCode);
} }
@ -175,14 +174,27 @@ void GCodes::Spin()
if(platform->GetLine()->Status() & byteAvailable) if(platform->GetLine()->Status() & byteAvailable)
{ {
platform->GetLine()->Read(b); // Read several bytes instead of just one. This is mainly to speed up file uploading.
if(serialGCode->Put(b)) int8_t i = 0;
do
{ {
if(serialGCode->WritingFileDirectory() != NULL) char b;
WriteGCodeToFile(serialGCode); platform->GetLine()->Read(b);
else if(serialGCode->Put(b)) // add char to buffer and test whether the gcode is complete
serialGCode->SetFinished(ActOnGcode(serialGCode)); {
} // we have a complete gcode
if(serialGCode->WritingFileDirectory() != NULL)
{
WriteGCodeToFile(serialGCode);
}
else
{
serialGCode->SetFinished(ActOnGcode(serialGCode));
}
break; // stop after receiving a complete gcode in case we haven't finished processing it
}
++i;
} while (i < 16 && (platform->GetLine()->Status() & byteAvailable));
platform->ClassReport("GCodes", longWait); platform->ClassReport("GCodes", longWait);
return; return;
} }
@ -1639,16 +1651,16 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
} }
break; break;
case 876: // TEMPORARY - this will go away... // case 876: // TEMPORARY - this will go away...
if(gb->Seen('P')) // if(gb->Seen('P'))
{ // {
iValue = gb->GetIValue(); // iValue = gb->GetIValue();
if(iValue != 1) // if(iValue != 1)
platform->SetHeatOn(0); // platform->SetHeatOn(0);
else // else
platform->SetHeatOn(1); // platform->SetHeatOn(1);
} // }
break; // break;
case 900: case 900:
result = DoFileCannedCycles("homex.g"); result = DoFileCannedCycles("homex.g");

View file

@ -41,9 +41,9 @@ class GCodeBuffer
char* GetUnprecedentedString(); char* GetUnprecedentedString();
char* GetString(); char* GetString();
char* Buffer(); char* Buffer();
bool Finished(); bool Finished() const;
void SetFinished(bool f); void SetFinished(bool f);
char* WritingFileDirectory(); char* WritingFileDirectory() const;
void SetWritingFileDirectory(char* wfd); void SetWritingFileDirectory(char* wfd);
private: private:
@ -75,8 +75,9 @@ class GCodes
void QueueFileToPrint(char* fileName); void QueueFileToPrint(char* fileName);
bool GetProbeCoordinates(int count, float& x, float& y, float& z); bool GetProbeCoordinates(int count, float& x, float& y, float& z);
char* GetCurrentCoordinates(); char* GetCurrentCoordinates();
bool PrintingAFile(); bool PrintingAFile() const;
void Diagnostics(); void Diagnostics();
bool HaveIncomingData() const;
private: private:
@ -97,7 +98,7 @@ class GCodes
bool SetOffsets(GCodeBuffer *gb); bool SetOffsets(GCodeBuffer *gb);
bool SetPositions(GCodeBuffer *gb); bool SetPositions(GCodeBuffer *gb);
void LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92); void LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92);
bool NoHome(); bool NoHome() const;
bool Push(); bool Push();
bool Pop(); bool Pop();
bool DisableDrives(); bool DisableDrives();
@ -110,7 +111,7 @@ class GCodes
void WriteHTMLToFile(char b, GCodeBuffer *gb); void WriteHTMLToFile(char b, GCodeBuffer *gb);
bool OffsetAxes(GCodeBuffer *gb); bool OffsetAxes(GCodeBuffer *gb);
int8_t Heater(int8_t head); int8_t Heater(int8_t head) const;
Platform* platform; Platform* platform;
bool active; bool active;
Webserver* webserver; Webserver* webserver;
@ -172,7 +173,7 @@ inline char* GCodeBuffer::Buffer()
return gcodeBuffer; return gcodeBuffer;
} }
inline bool GCodeBuffer::Finished() inline bool GCodeBuffer::Finished() const
{ {
return finished; return finished;
} }
@ -182,7 +183,7 @@ inline void GCodeBuffer::SetFinished(bool f)
finished = f; finished = f;
} }
inline char* GCodeBuffer::WritingFileDirectory() inline char* GCodeBuffer::WritingFileDirectory() const
{ {
return writingFileDirectory; return writingFileDirectory;
} }
@ -192,12 +193,17 @@ inline void GCodeBuffer::SetWritingFileDirectory(char* wfd)
writingFileDirectory = wfd; writingFileDirectory = wfd;
} }
inline bool GCodes::PrintingAFile() inline bool GCodes::PrintingAFile() const
{ {
return fileBeingPrinted != NULL; return fileBeingPrinted != NULL;
} }
inline bool GCodes::NoHome() inline bool GCodes::HaveIncomingData() const
{
return fileBeingPrinted != NULL || webserver->GCodeAvailable() || (platform->GetLine()->Status() & byteAvailable);
}
inline bool GCodes::NoHome() const
{ {
return !(homeX || homeY || homeZ || homeAxisMoveCount); return !(homeX || homeY || homeZ || homeAxisMoveCount);
} }
@ -205,7 +211,7 @@ inline bool GCodes::NoHome()
// This function takes care of the fact that the heater and head indices // This function takes care of the fact that the heater and head indices
// don't match because the bed is heater 0. // don't match because the bed is heater 0.
inline int8_t GCodes::Heater(int8_t head) inline int8_t GCodes::Heater(int8_t head) const
{ {
return head+1; return head+1;
} }

View file

@ -441,7 +441,7 @@ void Move::DoLookAhead()
// or both to the maximum that can be achieved because of the requirements of // or both to the maximum that can be achieved because of the requirements of
// the adjacent moves. // the adjacent moves.
if(addNoMoreMoves || !gCodes->PrintingAFile() || lookAheadRingCount > LOOK_AHEAD) if(addNoMoreMoves || !gCodes->HaveIncomingData() || lookAheadRingCount > LOOK_AHEAD)
{ {
// Run up the moves // Run up the moves
@ -497,7 +497,7 @@ void Move::DoLookAhead()
// If there are any new unprocessed moves in there, set their end speeds // If there are any new unprocessed moves in there, set their end speeds
// according to the cosine of the angle between them. // according to the cosine of the angle between them.
if(addNoMoreMoves || !gCodes->PrintingAFile() || lookAheadRingCount > 1) if(addNoMoreMoves || !gCodes->HaveIncomingData() || lookAheadRingCount > 1)
{ {
n1 = lookAheadRingGetPointer; n1 = lookAheadRingGetPointer;
n0 = n1->Previous(); n0 = n1->Previous();
@ -531,7 +531,7 @@ void Move::DoLookAhead()
// If we are just doing one isolated move, set its end velocity to InstantDv(Z_AXIS). // If we are just doing one isolated move, set its end velocity to InstantDv(Z_AXIS).
if(addNoMoreMoves || !gCodes->PrintingAFile()) if(addNoMoreMoves || !gCodes->HaveIncomingData())
{ {
n1->SetV(platform->InstantDv(Z_AXIS)); n1->SetV(platform->InstantDv(Z_AXIS));
n1->SetProcessed(complete); n1->SetProcessed(complete);
@ -988,18 +988,18 @@ MovementProfile DDA::Init(LookAhead* lookAhead, float& u, float& v)
} else // Must be extruders only } else // Must be extruders only
SetEAcceleration(eDistance); SetEAcceleration(eDistance);
// If we are going from an XY move to a Z move, u needs to be platform->InstantDv(Z_AXIS). // If we are going from an XY move or extruder move to a Z move, u needs to be platform->InstantDv(Z_AXIS).
if((myLookAheadEntry->Previous()->GetMovementType() & xyMove) && (mt & zMove)) if((myLookAheadEntry->Previous()->GetMovementType() & (xyMove | eMove)) && (mt & zMove))
{ {
u = platform->InstantDv(Z_AXIS); u = platform->InstantDv(Z_AXIS);
result = change; result = change;
} }
// if we are going from a Z move to an XY move, v needs to be platform->InstantDv(Z_AXIS), // if we are going from a Z move to an XY move or E move, v needs to be platform->InstantDv(Z_AXIS),
// as does instantDv. // as does instantDv.
if((myLookAheadEntry->Previous()->GetMovementType() & zMove) && (mt & xyMove)) if((myLookAheadEntry->Previous()->GetMovementType() & zMove) && (mt & (xyMove | eMove)))
{ {
v = platform->InstantDv(Z_AXIS); v = platform->InstantDv(Z_AXIS);
instantDv = v; instantDv = v;
@ -1163,7 +1163,7 @@ void LookAhead::Init(long ep[], float f, float vv, bool ce, int8_t mt)
// are printing a file, so set processed // are printing a file, so set processed
// complete when we aren't. // complete when we aren't.
if(reprap.GetGCodes()->PrintingAFile()) if(reprap.GetGCodes()->HaveIncomingData())
processed = unprocessed; processed = unprocessed;
else else
processed = complete|vCosineSet|upPass; processed = complete|vCosineSet|upPass;
@ -1198,7 +1198,7 @@ float LookAhead::Cosine()
if(a2 <= 0.0 || b2 <= 0.0) if(a2 <= 0.0 || b2 <= 0.0)
{ {
cosine = 0.5; // Why not? cosine = 0.0; // one of the moves is just an extruder move (probably a retraction), so orthogonal (in 4D space!) to XYZ moves
return cosine; return cosine;
} }

2
Move.h
View file

@ -302,7 +302,6 @@ inline void LookAhead::SetProcessed(MovementState ms)
inline void LookAhead::Release() inline void LookAhead::Release()
{ {
//SetProcessed(released);
processed = released; processed = released;
} }
@ -409,7 +408,6 @@ inline void Move::SetLiveCoordinates(float coords[])
{ {
for(int8_t drive = 0; drive <= DRIVES; drive++) for(int8_t drive = 0; drive <= DRIVES; drive++)
liveCoordinates[drive] = coords[drive]; liveCoordinates[drive] = coords[drive];
//Transform(liveCoordinates);
} }
// To wait until all the current moves in the buffers are // To wait until all the current moves in the buffers are

View file

@ -66,8 +66,6 @@ void Platform::Init()
line->Init(); line->Init();
messageIndent = 0; messageIndent = 0;
//network->Init();
massStorage->Init(); massStorage->Init();
for(i=0; i < MAX_FILES; i++) for(i=0; i < MAX_FILES; i++)
@ -131,7 +129,7 @@ void Platform::Init()
standbyTemperatures = STANDBY_TEMPERATURES; standbyTemperatures = STANDBY_TEMPERATURES;
activeTemperatures = ACTIVE_TEMPERATURES; activeTemperatures = ACTIVE_TEMPERATURES;
coolingFanPin = COOLING_FAN_PIN; coolingFanPin = COOLING_FAN_PIN;
turnHeatOn = HEAT_ON; //turnHeatOn = HEAT_ON;
webDir = WEB_DIR; webDir = WEB_DIR;
gcodeDir = GCODE_DIR; gcodeDir = GCODE_DIR;
@ -312,7 +310,7 @@ void Platform::ClassReport(char* className, float &lastTime)
// should compute it for you (i.e. it won't need to be calculated at run time). // should compute it for you (i.e. it won't need to be calculated at run time).
// If the A->D converter has a range of 0..1023 and the measured voltage is V (between 0 and 1023) // If the A->D converter has a range of 0..1023 and the measured voltage is V (between 0 and 1023)
// then the thermistor resistance, R = V.RS/(1023 - V) // then the thermistor resistance, R = V.RS/(1024 - V)
// and the temperature, T = BETA/ln(R/R_INF) // and the temperature, T = BETA/ln(R/R_INF)
// To get degrees celsius (instead of kelvin) add -273.15 to T // To get degrees celsius (instead of kelvin) add -273.15 to T
//#define THERMISTOR_R_INFS ( THERMISTOR_25_RS*exp(-THERMISTOR_BETAS/298.15) ) // Compute in Platform constructor //#define THERMISTOR_R_INFS ( THERMISTOR_25_RS*exp(-THERMISTOR_BETAS/298.15) ) // Compute in Platform constructor
@ -321,8 +319,10 @@ void Platform::ClassReport(char* className, float &lastTime)
float Platform::GetTemperature(int8_t heater) float Platform::GetTemperature(int8_t heater)
{ {
float r = (float)GetRawTemperature(heater); // If the ADC reading is N then for an ideal ADC, the input voltage is at least N/(ADC_RANGE + 1) and less than (N + 1)/(ADC_RANGE + 1), times the analog reference.
return ABS_ZERO + thermistorBetas[heater]/log( (r*thermistorSeriesRs[heater]/(AD_RANGE - r))/thermistorInfRs[heater] ); // So we add 0.5 to to the reading to get a better estimate of the input. We don't care whether or not we get exactly zero with the thermistor disconnected.
float r = (float)GetRawTemperature(heater) + 0.5;
return ABS_ZERO + thermistorBetas[heater]/log( (r*thermistorSeriesRs[heater]/((AD_RANGE + 1) - r))/thermistorInfRs[heater] );
} }
@ -334,7 +334,7 @@ void Platform::SetHeater(int8_t heater, const float& power)
return; return;
byte p = (byte)(255.0*fmin(1.0, fmax(0.0, power))); byte p = (byte)(255.0*fmin(1.0, fmax(0.0, power)));
if(turnHeatOn == 0) if(HEAT_ON == 0)
p = 255 - p; p = 255 - p;
if(heater == 0) if(heater == 0)
analogWrite(heatOnPins[heater], p); analogWrite(heatOnPins[heater], p);
@ -386,7 +386,7 @@ void MassStorage::Init()
hsmciPinsinit(); hsmciPinsinit();
// Initialize SD MMC stack // Initialize SD MMC stack
sd_mmc_init(); sd_mmc_init();
delay(5); delay(20);
int sdPresentCount = 0; int sdPresentCount = 0;
while ((CTRL_NO_PRESENT == sd_mmc_check(0)) && (sdPresentCount < 5)) while ((CTRL_NO_PRESENT == sd_mmc_check(0)) && (sdPresentCount < 5))
{ {
@ -833,6 +833,8 @@ Line::Line()
void Line::Init() void Line::Init()
{ {
getIndex = 0;
numChars = 0;
// alternateInput = NULL; // alternateInput = NULL;
// alternateOutput = NULL; // alternateOutput = NULL;
SerialUSB.begin(BAUD_RATE); SerialUSB.begin(BAUD_RATE);
@ -864,9 +866,10 @@ void RepRapNetworkInputBufferReleased(void* pb)
reprap.GetPlatform()->GetNetwork()->InputBufferReleased(pb); reprap.GetPlatform()->GetNetwork()->InputBufferReleased(pb);
} }
void RepRapNetworkHttpStateReleased(void* h) void RepRapNetworkConnectionError(void* h)
{ {
reprap.GetPlatform()->GetNetwork()->HttpStateReleased(h); reprap.GetPlatform()->GetNetwork()->ConnectionError(h);
reprap.GetWebserver()->ConnectionError();
} }
// Called to put out a message via the RepRap firmware. // Called to put out a message via the RepRap firmware.
@ -943,12 +946,7 @@ void Network::Init()
{ {
CleanRing(); CleanRing();
Reset(); Reset();
// if(LinkIsUp())
// reprap.GetPlatform()->SetHeater(0,1.0);
// else
// reprap.GetPlatform()->SetHeater(0,0.0);
if(!NETWORK) // NETWORK needs to be true to turn on the ethernet. It is defined in Configuration.h
return;
init_ethernet(reprap.GetPlatform()->IPAddress(), reprap.GetPlatform()->NetMask(), reprap.GetPlatform()->GateWay()); init_ethernet(reprap.GetPlatform()->IPAddress(), reprap.GetPlatform()->NetMask(), reprap.GetPlatform()->GateWay());
active = true; active = true;
} }
@ -1053,14 +1051,19 @@ void Network::InputBufferReleased(void* pb)
netRingGetPointer->ReleasePbuf(); netRingGetPointer->ReleasePbuf();
} }
void Network::HttpStateReleased(void* h) void Network::ConnectionError(void* h)
{ {
if(netRingGetPointer->Hs() != h) // h points to an http state block that the caller is about to release, so we need to stop referring to it.
// The state block is usually but not always in use by the current http request being processed, in which case we abandon the current request.
if (netRingGetPointer != netRingAddPointer && netRingGetPointer->Hs() == h)
{ {
reprap.GetPlatform()->Message(HOST_MESSAGE, "Network::HttpStateReleased() - Pointers don't match!\n"); netRingGetPointer->Free();
return; netRingGetPointer = netRingGetPointer->Next();
} }
netRingGetPointer->ReleaseHs();
// Reset the network layer. In particular, this clears the output buffer to make sure nothing more gets sent,
// and sets statue to 'nothing' so that we can accept another connection attempt.
Reset();
} }
@ -1079,7 +1082,7 @@ void Network::ReceiveInput(char* data, int length, void* pbuf, void* pcb, void*
bool Network::CanWrite() bool Network::CanWrite() const
{ {
return writeEnabled; return writeEnabled;
} }
@ -1130,7 +1133,7 @@ void Network::Close()
//Reset(); //Reset();
} }
int8_t Network::Status() int8_t Network::Status() const
{ {
if(inputPointer >= inputLength) if(inputPointer >= inputLength)
return status; return status;
@ -1229,6 +1232,27 @@ void NetRing::ReleaseHs()
hs = 0; hs = 0;
} }
void Line::Spin()
{
// Read the serial data in blocks to avoid excessive flow control
if (numChars <= lineBufsize/2)
{
int16_t target = SerialUSB.available() + (int16_t)numChars;
if (target > lineBufsize)
{
target = lineBufsize;
}
while ((int16_t)numChars < target)
{
int incomingByte = SerialUSB.read();
if (incomingByte < 0) break;
buffer[(getIndex + numChars) % lineBufsize] = (char)incomingByte;
++numChars;
}
}
}

View file

@ -183,13 +183,15 @@ Licence: GPL
#define BAUD_RATE 115200 // Communication speed of the USB if needed. #define BAUD_RATE 115200 // Communication speed of the USB if needed.
const uint16_t lineBufsize = 256; // use a power of 2 for good performance
/****************************************************************************************************/ /****************************************************************************************************/
enum EndStopHit enum EndStopHit
{ {
noStop = 0, noStop = 0, // no enstop hit
lowHit = 1, lowHit = 1, // low switch hit, or Z-probe in use and above threshold
highHit = 2 highHit = 2 // high stop hit
}; };
/***************************************************************************************************/ /***************************************************************************************************/
@ -264,17 +266,17 @@ class Network //: public InputOutput
{ {
public: public:
int8_t Status(); // Returns OR of IOStatus int8_t Status() const; // Returns OR of IOStatus
bool Read(char& b); bool Read(char& b);
bool CanWrite(); bool CanWrite() const;
void SetWriteEnable(bool enable); void SetWriteEnable(bool enable);
void Write(char b); void Write(char b);
void Write(char* s); void Write(char* s);
void Close(); void Close();
void ReceiveInput(char* data, int length, void* pb, void* pc, void* h); void ReceiveInput(char* data, int length, void* pb, void* pc, void* h);
void InputBufferReleased(void* pb); void InputBufferReleased(void* pb);
void HttpStateReleased(void* h); void ConnectionError(void* h);
bool Active(); bool Active() const;
bool LinkIsUp(); bool LinkIsUp();
friend class Platform; friend class Platform;
@ -308,7 +310,7 @@ class Line //: public InputOutput
{ {
public: public:
int8_t Status(); // Returns OR of IOStatus int8_t Status() const; // Returns OR of IOStatus
int Read(char& b); int Read(char& b);
void Write(char b); void Write(char b);
void Write(char* s); void Write(char* s);
@ -324,6 +326,9 @@ protected:
void Spin(); void Spin();
private: private:
char buffer[lineBufsize];
uint16_t getIndex;
uint16_t numChars;
}; };
class MassStorage class MassStorage
@ -494,7 +499,7 @@ class Platform
bool UsePID(int8_t heater); bool UsePID(int8_t heater);
float HeatSampleTime(); float HeatSampleTime();
void CoolingFan(float speed); void CoolingFan(float speed);
void SetHeatOn(int8_t ho); //TEMPORARY - this will go away... //void SetHeatOn(int8_t ho); //TEMPORARY - this will go away...
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------
protected: protected:
@ -573,7 +578,7 @@ class Platform
float standbyTemperatures[HEATERS]; float standbyTemperatures[HEATERS];
float activeTemperatures[HEATERS]; float activeTemperatures[HEATERS];
int8_t coolingFanPin; int8_t coolingFanPin;
int8_t turnHeatOn; //int8_t turnHeatOn;
// Serial/USB // Serial/USB
@ -909,10 +914,10 @@ inline void Platform::CoolingFan(float speed)
analogWrite(coolingFanPin, (uint8_t)(speed*255.0)); analogWrite(coolingFanPin, (uint8_t)(speed*255.0));
} }
inline void Platform::SetHeatOn(int8_t ho) //inline void Platform::SetHeatOn(int8_t ho)
{ //{
turnHeatOn = ho; // turnHeatOn = ho;
} //}
//********************************************************************************************************* //*********************************************************************************************************
@ -979,18 +984,11 @@ inline Line* Platform::GetLine()
return line; return line;
} }
inline void Line::Spin() inline int8_t Line::Status() const
{
}
inline int8_t Line::Status()
{ {
// if(alternateInput != NULL) // if(alternateInput != NULL)
// return alternateInput->Status(); // return alternateInput->Status();
return numChars == 0 ? nothing : byteAvailable;
if(SerialUSB.available() > 0)
return byteAvailable;
return nothing;
} }
inline int Line::Read(char& b) inline int Line::Read(char& b)
@ -998,11 +996,11 @@ inline int Line::Read(char& b)
// if(alternateInput != NULL) // if(alternateInput != NULL)
// return alternateInput->Read(b); // return alternateInput->Read(b);
int incomingByte = SerialUSB.read(); if (numChars == 0) return 0;
if(incomingByte < 0) b = buffer[getIndex];
return 0; getIndex = (getIndex + 1) % lineBufsize;
b = (char)incomingByte; --numChars;
return true; return 1;
} }
inline void Line::Write(char b) inline void Line::Write(char b)
@ -1046,7 +1044,7 @@ inline bool Network::LinkIsUp()
return status_link_up(); return status_link_up();
} }
inline bool Network::Active() inline bool Network::Active() const
{ {
return active; return active;
} }

Binary file not shown.

View file

@ -186,12 +186,8 @@ void RepRap::Init()
platform->Message(HOST_MESSAGE, platform->GetConfigFile()); platform->Message(HOST_MESSAGE, platform->GetConfigFile());
platform->Message(HOST_MESSAGE, "...\n\n"); platform->Message(HOST_MESSAGE, "...\n\n");
platform->PushMessageIndent();
while(gCodes->RunConfigurationGCodes()); // Wait till the file is finished while(gCodes->RunConfigurationGCodes()); // Wait till the file is finished
platform->PopMessageIndent();
platform->Message(HOST_MESSAGE, "\nStarting network...\n"); platform->Message(HOST_MESSAGE, "\nStarting network...\n");
platform->StartNetwork(); // Need to do this here, as the configuration GCodes may set IP address etc. platform->StartNetwork(); // Need to do this here, as the configuration GCodes may set IP address etc.
@ -290,7 +286,7 @@ char* ftoa(char *a, const float& f, int prec)
while (*a != '\0') a++; while (*a != '\0') a++;
*a++ = '.'; *a++ = '.';
long decimal = abs((long)((f - (float)whole) * precision[prec])); long decimal = abs((long)((f - (float)whole) * precision[prec]));
snprintf(a, STRING_LENGTH, "%d", decimal); snprintf(a, STRING_LENGTH, "%0*d", prec, decimal);
return ret; return ret;
} }

View file

@ -137,7 +137,7 @@ bool Webserver::LoadGcodeBuffer(char* gc, bool convertWeb)
{ {
if(!platform->GetMassStorage()->Delete(platform->GetGCodeDir(), &gcodeBuffer[4])) if(!platform->GetMassStorage()->Delete(platform->GetGCodeDir(), &gcodeBuffer[4]))
{ {
platform->Message(HOST_MESSAGE, "Unsuccsessful attempt to delete: "); platform->Message(HOST_MESSAGE, "Unsuccessful attempt to delete: ");
platform->Message(HOST_MESSAGE, &gcodeBuffer[4]); platform->Message(HOST_MESSAGE, &gcodeBuffer[4]);
platform->Message(HOST_MESSAGE, "\n"); platform->Message(HOST_MESSAGE, "\n");
} }
@ -711,6 +711,30 @@ void Webserver::Init()
//platform->GetMassStorage()->Delete(platform->GetWebDir(), MESSAGE_FILE); //platform->GetMassStorage()->Delete(platform->GetWebDir(), MESSAGE_FILE);
} }
// This is called when the connection has been lost.
// In particular, we must cancel any pending writes.
void Webserver::ConnectionError()
{
writing = false;
receivingPost = false;
postSeen = false;
getSeen = false;
jsonPointer = -1;
clientLineIsBlank = true;
needToCloseClient = false;
clientLinePointer = 0;
clientLine[0] = 0;
clientRequest[0] = 0;
gotPassword = false;
gcodeAvailable = false;
gcodePointer = 0;
InitialisePost();
lastTime = platform->Time();
longWait = lastTime;
active = true;
}
void Webserver::Exit() void Webserver::Exit()
{ {
platform->Message(HOST_MESSAGE, "Webserver class exited.\n"); platform->Message(HOST_MESSAGE, "Webserver class exited.\n");

View file

@ -50,6 +50,7 @@ class Webserver
void Diagnostics(); void Diagnostics();
void SetPassword(char* pw); void SetPassword(char* pw);
void SetName(char* nm); void SetName(char* nm);
void ConnectionError();
private: private:

View file

@ -72,7 +72,7 @@ struct http_state {
void RepRapNetworkReceiveInput(char* ip, int length, void* pbuf, void* pcb, void* hs); void RepRapNetworkReceiveInput(char* ip, int length, void* pbuf, void* pcb, void* hs);
void RepRapNetworkInputBufferReleased(void* pbuf); void RepRapNetworkInputBufferReleased(void* pbuf);
void RepRapNetworkHttpStateReleased(void* h); void RepRapNetworkConnectionError(void* h);
void RepRapNetworkMessage(char* s); void RepRapNetworkMessage(char* s);
void RepRapNetworkAllowWriting(); void RepRapNetworkAllowWriting();
bool RepRapNetworkHasALiveClient(); bool RepRapNetworkHasALiveClient();
@ -86,15 +86,19 @@ static int initCount = 0;
static void static void
conn_err(void *arg, err_t err) conn_err(void *arg, err_t err)
{ {
struct http_state *hs; // Report the error to the monitor
RepRapNetworkMessage("Network connection error, code ");
{
char tempBuf[10];
snprintf(tempBuf, sizeof(tempBuf)/sizeof(char), "%d\n", err);
RepRapNetworkMessage(tempBuf);
}
LWIP_UNUSED_ARG(err); struct http_state *hs = arg;
RepRapNetworkConnectionError(hs); // tell the higher levels about the error
hs = arg; mem_free(hs); // release the state data
mem_free(hs);
//RepRapNetworkHttpStateReleased(hs);
RepRapNetworkMessage("Network connection error.\n");
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
static void static void