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

This commit is contained in:
Adrian Bowyer 2014-01-12 17:37:01 +00:00
commit e7afc883c2
9 changed files with 149 additions and 73 deletions

View file

@ -111,8 +111,6 @@ void GCodes::Spin()
if(!active)
return;
char b;
// 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
// looking at anything else.
@ -147,7 +145,7 @@ void GCodes::Spin()
if(webserver->GCodeAvailable())
{
b = webserver->ReadGCode();
char b = webserver->ReadGCode();
if(webGCode->Put(b))
{
if(webGCode->WritingFileDirectory() != NULL)
@ -166,6 +164,7 @@ void GCodes::Spin()
{
if(platform->GetLine()->Status() & byteAvailable)
{
char b;
platform->GetLine()->Read(b);
WriteHTMLToFile(b, serialGCode);
}
@ -175,14 +174,27 @@ void GCodes::Spin()
if(platform->GetLine()->Status() & byteAvailable)
{
platform->GetLine()->Read(b);
if(serialGCode->Put(b))
// Read several bytes instead of just one. This is mainly to speed up file uploading.
int8_t i = 0;
do
{
if(serialGCode->WritingFileDirectory() != NULL)
WriteGCodeToFile(serialGCode);
else
serialGCode->SetFinished(ActOnGcode(serialGCode));
}
char b;
platform->GetLine()->Read(b);
if(serialGCode->Put(b)) // add char to buffer and test whether the gcode is complete
{
// 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);
return;
}

View file

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

View file

@ -441,7 +441,7 @@ void Move::DoLookAhead()
// or both to the maximum that can be achieved because of the requirements of
// the adjacent moves.
if(addNoMoreMoves || !gCodes->PrintingAFile() || lookAheadRingCount > LOOK_AHEAD)
if(addNoMoreMoves || !gCodes->HaveIncomingData() || lookAheadRingCount > LOOK_AHEAD)
{
// Run up the moves
@ -497,7 +497,7 @@ void Move::DoLookAhead()
// If there are any new unprocessed moves in there, set their end speeds
// according to the cosine of the angle between them.
if(addNoMoreMoves || !gCodes->PrintingAFile() || lookAheadRingCount > 1)
if(addNoMoreMoves || !gCodes->HaveIncomingData() || lookAheadRingCount > 1)
{
n1 = lookAheadRingGetPointer;
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(addNoMoreMoves || !gCodes->PrintingAFile())
if(addNoMoreMoves || !gCodes->HaveIncomingData())
{
n1->SetV(platform->InstantDv(Z_AXIS));
n1->SetProcessed(complete);
@ -988,18 +988,18 @@ MovementProfile DDA::Init(LookAhead* lookAhead, float& u, float& v)
} else // Must be extruders only
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);
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.
if((myLookAheadEntry->Previous()->GetMovementType() & zMove) && (mt & xyMove))
if((myLookAheadEntry->Previous()->GetMovementType() & zMove) && (mt & (xyMove | eMove)))
{
v = platform->InstantDv(Z_AXIS);
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
// complete when we aren't.
if(reprap.GetGCodes()->PrintingAFile())
if(reprap.GetGCodes()->HaveIncomingData())
processed = unprocessed;
else
processed = complete|vCosineSet|upPass;
@ -1198,7 +1198,7 @@ float LookAhead::Cosine()
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;
}

View file

@ -310,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).
// 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)
// 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
@ -319,8 +319,10 @@ void Platform::ClassReport(char* className, float &lastTime)
float Platform::GetTemperature(int8_t heater)
{
float r = (float)GetRawTemperature(heater);
return ABS_ZERO + thermistorBetas[heater]/log( (r*thermistorSeriesRs[heater]/(AD_RANGE - r))/thermistorInfRs[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.
// 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] );
}
@ -831,6 +833,8 @@ Line::Line()
void Line::Init()
{
getIndex = 0;
numChars = 0;
// alternateInput = NULL;
// alternateOutput = NULL;
SerialUSB.begin(BAUD_RATE);
@ -862,9 +866,10 @@ void RepRapNetworkInputBufferReleased(void* 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.
@ -1046,14 +1051,19 @@ void Network::InputBufferReleased(void* pb)
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");
return;
netRingGetPointer->Free();
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();
}
@ -1072,7 +1082,7 @@ void Network::ReceiveInput(char* data, int length, void* pbuf, void* pcb, void*
bool Network::CanWrite()
bool Network::CanWrite() const
{
return writeEnabled;
}
@ -1123,7 +1133,7 @@ void Network::Close()
//Reset();
}
int8_t Network::Status()
int8_t Network::Status() const
{
if(inputPointer >= inputLength)
return status;
@ -1222,6 +1232,27 @@ void NetRing::ReleaseHs()
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.
const uint16_t lineBufsize = 256; // use a power of 2 for good performance
/****************************************************************************************************/
enum EndStopHit
{
noStop = 0,
lowHit = 1,
highHit = 2
noStop = 0, // no enstop hit
lowHit = 1, // low switch hit, or Z-probe in use and above threshold
highHit = 2 // high stop hit
};
/***************************************************************************************************/
@ -264,17 +266,17 @@ class Network //: public InputOutput
{
public:
int8_t Status(); // Returns OR of IOStatus
int8_t Status() const; // Returns OR of IOStatus
bool Read(char& b);
bool CanWrite();
bool CanWrite() const;
void SetWriteEnable(bool enable);
void Write(char b);
void Write(char* s);
void Close();
void ReceiveInput(char* data, int length, void* pb, void* pc, void* h);
void InputBufferReleased(void* pb);
void HttpStateReleased(void* h);
bool Active();
void ConnectionError(void* h);
bool Active() const;
bool LinkIsUp();
friend class Platform;
@ -308,7 +310,7 @@ class Line //: public InputOutput
{
public:
int8_t Status(); // Returns OR of IOStatus
int8_t Status() const; // Returns OR of IOStatus
int Read(char& b);
void Write(char b);
void Write(char* s);
@ -324,6 +326,9 @@ protected:
void Spin();
private:
char buffer[lineBufsize];
uint16_t getIndex;
uint16_t numChars;
};
class MassStorage
@ -979,18 +984,11 @@ inline Line* Platform::GetLine()
return line;
}
inline void Line::Spin()
{
}
inline int8_t Line::Status()
inline int8_t Line::Status() const
{
// if(alternateInput != NULL)
// return alternateInput->Status();
if(SerialUSB.available() > 0)
return byteAvailable;
return nothing;
return numChars == 0 ? nothing : byteAvailable;
}
inline int Line::Read(char& b)
@ -998,11 +996,11 @@ inline int Line::Read(char& b)
// if(alternateInput != NULL)
// return alternateInput->Read(b);
int incomingByte = SerialUSB.read();
if(incomingByte < 0)
return 0;
b = (char)incomingByte;
return true;
if (numChars == 0) return 0;
b = buffer[getIndex];
getIndex = (getIndex + 1) % lineBufsize;
--numChars;
return 1;
}
inline void Line::Write(char b)
@ -1046,7 +1044,7 @@ inline bool Network::LinkIsUp()
return status_link_up();
}
inline bool Network::Active()
inline bool Network::Active() const
{
return active;
}

Binary file not shown.

View file

@ -137,7 +137,7 @@ bool Webserver::LoadGcodeBuffer(char* gc, bool convertWeb)
{
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, "\n");
}
@ -711,6 +711,30 @@ void Webserver::Init()
//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()
{
platform->Message(HOST_MESSAGE, "Webserver class exited.\n");

View file

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

View file

@ -72,7 +72,7 @@ struct http_state {
void RepRapNetworkReceiveInput(char* ip, int length, void* pbuf, void* pcb, void* hs);
void RepRapNetworkInputBufferReleased(void* pbuf);
void RepRapNetworkHttpStateReleased(void* h);
void RepRapNetworkConnectionError(void* h);
void RepRapNetworkMessage(char* s);
void RepRapNetworkAllowWriting();
bool RepRapNetworkHasALiveClient();
@ -86,15 +86,19 @@ static int initCount = 0;
static void
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);
hs = arg;
mem_free(hs);
//RepRapNetworkHttpStateReleased(hs);
RepRapNetworkMessage("Network connection error.\n");
struct http_state *hs = arg;
RepRapNetworkConnectionError(hs); // tell the higher levels about the error
mem_free(hs); // release the state data
}
/*-----------------------------------------------------------------------------------*/
static void