Upload of reprap.htm implemented (M560). The file must end "<!-- **EoF** -->" without the quotes.
This commit is contained in:
parent
cad6c8d74e
commit
4c74c4eb30
8 changed files with 99 additions and 42 deletions
|
@ -67,13 +67,13 @@ enum Compatibility
|
|||
|
||||
#define DEFAULT_PASSWORD "reprap"
|
||||
#define DEFAULT_NAME "My RepRap 1"
|
||||
|
||||
/* Z PROBE CALIBRATION
|
||||
* Set = 1 to enable Z probe ADC output on SerialUSb
|
||||
*/
|
||||
#define CALIB_Z 0
|
||||
#define INDEX_PAGE "reprap.htm"
|
||||
#define MESSAGE_FILE "messages.txt"
|
||||
#define FOUR04_FILE "html404.htm"
|
||||
|
||||
#define LONG_TIME 300.0 // Seconds
|
||||
|
||||
#define EOF_STRING "<!-- **EoF** -->"
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Adrian Bowyer,ensab,Charles,20.11.2013 18:47,file:///home/ensab/.config/libreoffice/3;
|
Binary file not shown.
106
GCodes.cpp
106
GCodes.cpp
|
@ -61,6 +61,9 @@ void GCodes::Init()
|
|||
fileToPrint = NULL;
|
||||
fileBeingWritten = NULL;
|
||||
configFile = NULL;
|
||||
eofString = EOF_STRING;
|
||||
eofStringCounter = 0;
|
||||
eofStringLength = strlen(eofString);
|
||||
homeX = false;
|
||||
homeY = false;
|
||||
homeZ = false;
|
||||
|
@ -114,16 +117,17 @@ void GCodes::Spin()
|
|||
fileGCode->SetFinished(ActOnGcode(fileGCode));
|
||||
platform->ClassReport("GCodes", longWait);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Now check if a G Code byte is available from each of the sources
|
||||
// in the same order for the same reason.
|
||||
|
||||
if(webserver->GCodeAvailable())
|
||||
{
|
||||
if(webGCode->Put(webserver->ReadGCode()))
|
||||
b = webserver->ReadGCode();
|
||||
if(webGCode->Put(b))
|
||||
{
|
||||
if(webGCode->WritingFile())
|
||||
if(webGCode->WritingFileDirectory())
|
||||
WriteGCodeToFile(webGCode);
|
||||
else
|
||||
webGCode->SetFinished(ActOnGcode(webGCode));
|
||||
|
@ -132,19 +136,36 @@ void GCodes::Spin()
|
|||
return;
|
||||
}
|
||||
|
||||
if(platform->GetLine()->Status() & byteAvailable)
|
||||
// Now the serial interface. First check the special case of our
|
||||
// uploading the reprap.htm file
|
||||
|
||||
if(serialGCode->WritingFileDirectory() == platform->GetWebDir())
|
||||
{
|
||||
platform->GetLine()->Read(b);
|
||||
if(serialGCode->Put(b))
|
||||
{
|
||||
if(serialGCode->WritingFile())
|
||||
WriteGCodeToFile(serialGCode);
|
||||
else
|
||||
serialGCode->SetFinished(ActOnGcode(serialGCode));
|
||||
}
|
||||
platform->ClassReport("GCodes", longWait);
|
||||
return;
|
||||
}
|
||||
if(platform->GetLine()->Status() & byteAvailable)
|
||||
{
|
||||
platform->GetLine()->Read(b);
|
||||
WriteHTMLToFile(b, serialGCode);
|
||||
}
|
||||
} else
|
||||
{
|
||||
// Otherwise just deal in general with incoming bytes from the serial interface
|
||||
|
||||
if(platform->GetLine()->Status() & byteAvailable)
|
||||
{
|
||||
platform->GetLine()->Read(b);
|
||||
if(serialGCode->Put(b))
|
||||
{
|
||||
if(serialGCode->WritingFileDirectory())
|
||||
WriteGCodeToFile(serialGCode);
|
||||
else
|
||||
serialGCode->SetFinished(ActOnGcode(serialGCode));
|
||||
}
|
||||
platform->ClassReport("GCodes", longWait);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(fileBeingPrinted != NULL)
|
||||
{
|
||||
|
@ -500,18 +521,47 @@ char* GCodes::GetCurrentCoordinates()
|
|||
return scratchString;
|
||||
}
|
||||
|
||||
char* GCodes::OpenFileToWrite(char* fileName, GCodeBuffer *gb, bool configFile)
|
||||
char* GCodes::OpenFileToWrite(char* directory, char* fileName, GCodeBuffer *gb)
|
||||
{
|
||||
if(configFile)
|
||||
fileBeingWritten = platform->GetFileStore(platform->GetSysDir(), fileName, true);
|
||||
else
|
||||
fileBeingWritten = platform->GetFileStore(platform->GetGCodeDir(), fileName, true);
|
||||
fileBeingWritten = platform->GetFileStore(directory, fileName, true);
|
||||
if(fileBeingWritten == NULL)
|
||||
platform->Message(HOST_MESSAGE, "Can't open GCode file for writing.\n");
|
||||
else
|
||||
gb->SetWritingFile(true);
|
||||
gb->SetWritingFileDirectory(directory);
|
||||
|
||||
eofStringCounter = 0;
|
||||
}
|
||||
|
||||
void GCodes::WriteHTMLToFile(char b, GCodeBuffer *gb)
|
||||
{
|
||||
char reply[1];
|
||||
reply[0] = 0;
|
||||
|
||||
if(fileBeingWritten == NULL)
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "Attempt to write to a null file.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fileBeingWritten->Write(b);
|
||||
|
||||
if(b == eofString[eofStringCounter])
|
||||
{
|
||||
eofStringCounter++;
|
||||
if(eofStringCounter >= eofStringLength)
|
||||
{
|
||||
fileBeingWritten->Close();
|
||||
fileBeingWritten = NULL;
|
||||
gb->SetWritingFileDirectory(NULL);
|
||||
char* r = reply;
|
||||
if(platform->Emulating() == marlin)
|
||||
r = "Done saving file.";
|
||||
HandleReply(false, gb == serialGCode , r, 'M', 560, false);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
eofStringCounter = 0;
|
||||
}
|
||||
|
||||
void GCodes::WriteGCodeToFile(GCodeBuffer *gb)
|
||||
{
|
||||
|
@ -532,7 +582,7 @@ void GCodes::WriteGCodeToFile(GCodeBuffer *gb)
|
|||
{
|
||||
fileBeingWritten->Close();
|
||||
fileBeingWritten = NULL;
|
||||
gb->SetWritingFile(false);
|
||||
gb->SetWritingFileDirectory(NULL);
|
||||
char* r = reply;
|
||||
if(platform->Emulating() == marlin)
|
||||
r = "Done saving file.";
|
||||
|
@ -1033,7 +1083,7 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
|
|||
|
||||
case 28: // Write to file
|
||||
str = gb->GetUnprecedentedString();
|
||||
OpenFileToWrite(str, gb, false);
|
||||
OpenFileToWrite(platform->GetGCodeDir(), str, gb);
|
||||
snprintf(reply, STRING_LENGTH, "Writing to file: %s", str);
|
||||
break;
|
||||
|
||||
|
@ -1296,10 +1346,16 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
|
|||
|
||||
case 559: // Upload config.g
|
||||
str = platform->GetConfigFile();
|
||||
OpenFileToWrite(str, gb, true);
|
||||
OpenFileToWrite(platform->GetSysDir(), str, gb);
|
||||
snprintf(reply, STRING_LENGTH, "Writing to file: %s", str);
|
||||
break;
|
||||
|
||||
case 560: // Upload reprap.htm
|
||||
str = INDEX_PAGE;
|
||||
OpenFileToWrite(platform->GetWebDir(), str, gb);
|
||||
snprintf(reply, STRING_LENGTH, "Writing to file: %s", str);
|
||||
break;
|
||||
|
||||
case 906: // Set Motor currents
|
||||
for(uint8_t i = 0; i < DRIVES; i++)
|
||||
{
|
||||
|
@ -1376,7 +1432,7 @@ GCodeBuffer::GCodeBuffer(Platform* p, char* id)
|
|||
{
|
||||
platform = p;
|
||||
identity = id;
|
||||
writingFile = false; // Has to be done here as Init() is called every line.
|
||||
writingFileDirectory = NULL; // Has to be done here as Init() is called every line.
|
||||
}
|
||||
|
||||
void GCodeBuffer::Init()
|
||||
|
|
20
GCodes.h
20
GCodes.h
|
@ -43,8 +43,8 @@ class GCodeBuffer
|
|||
char* Buffer();
|
||||
bool Finished();
|
||||
void SetFinished(bool f);
|
||||
bool WritingFile();
|
||||
void SetWritingFile(bool wf);
|
||||
char* WritingFileDirectory();
|
||||
void SetWritingFileDirectory(char* wfd);
|
||||
|
||||
private:
|
||||
int CheckSum();
|
||||
|
@ -55,7 +55,7 @@ class GCodeBuffer
|
|||
int readPointer;
|
||||
bool inComment;
|
||||
bool finished;
|
||||
bool writingFile;
|
||||
char* writingFileDirectory;
|
||||
};
|
||||
|
||||
//****************************************************************************************************
|
||||
|
@ -98,9 +98,10 @@ class GCodes
|
|||
bool StandbyHeaters();
|
||||
void SetEthernetAddress(GCodeBuffer *gb, int mCode);
|
||||
void HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code, bool resend);
|
||||
char* OpenFileToWrite(char* fileName, GCodeBuffer *gb, bool configFile);
|
||||
char* OpenFileToWrite(char* directory, char* fileName, GCodeBuffer *gb);
|
||||
void WriteGCodeToFile(GCodeBuffer *gb);
|
||||
bool SendConfigToLine();
|
||||
void WriteHTMLToFile(char b, GCodeBuffer *gb);
|
||||
|
||||
int8_t Heater(int8_t head);
|
||||
Platform* platform;
|
||||
|
@ -127,6 +128,9 @@ class GCodes
|
|||
FileStore* fileToPrint;
|
||||
FileStore* fileBeingWritten;
|
||||
FileStore* configFile;
|
||||
char* eofString;
|
||||
uint8_t eofStringCounter;
|
||||
uint8_t eofStringLength;
|
||||
int8_t selectedHead;
|
||||
bool homeX;
|
||||
bool homeY;
|
||||
|
@ -165,14 +169,14 @@ inline void GCodeBuffer::SetFinished(bool f)
|
|||
finished = f;
|
||||
}
|
||||
|
||||
inline bool GCodeBuffer::WritingFile()
|
||||
inline char* GCodeBuffer::WritingFileDirectory()
|
||||
{
|
||||
return writingFile;
|
||||
return writingFileDirectory;
|
||||
}
|
||||
|
||||
inline void GCodeBuffer::SetWritingFile(bool wf)
|
||||
inline void GCodeBuffer::SetWritingFileDirectory(char* wfd)
|
||||
{
|
||||
writingFile = wf;
|
||||
writingFileDirectory = wfd;
|
||||
}
|
||||
|
||||
inline bool GCodes::PrintingAFile()
|
||||
|
|
Binary file not shown.
|
@ -777,3 +777,4 @@ poll();
|
|||
|
||||
|
||||
</html>
|
||||
<!-- **EoF** -->
|
||||
|
|
|
@ -31,9 +31,6 @@ Licence: GPL
|
|||
#define WEBSERVER_H
|
||||
|
||||
|
||||
#define INDEX_PAGE "reprap.htm"
|
||||
#define MESSAGE_FILE "messages.txt"
|
||||
#define FOUR04_FILE "html404.htm"
|
||||
#define KO_START "rr_"
|
||||
#define KO_FIRST 3
|
||||
#define POST_LENGTH 200
|
||||
|
|
Reference in a new issue