Upload of reprap.htm implemented (M560). The file must end "<!-- **EoF** -->" without the quotes.

This commit is contained in:
Adrian Bowyer 2013-11-20 22:13:23 +00:00
parent cad6c8d74e
commit 4c74c4eb30
8 changed files with 99 additions and 42 deletions

View file

@ -67,13 +67,13 @@ enum Compatibility
#define DEFAULT_PASSWORD "reprap" #define DEFAULT_PASSWORD "reprap"
#define DEFAULT_NAME "My RepRap 1" #define DEFAULT_NAME "My RepRap 1"
#define INDEX_PAGE "reprap.htm"
/* Z PROBE CALIBRATION #define MESSAGE_FILE "messages.txt"
* Set = 1 to enable Z probe ADC output on SerialUSb #define FOUR04_FILE "html404.htm"
*/
#define CALIB_Z 0
#define LONG_TIME 300.0 // Seconds #define LONG_TIME 300.0 // Seconds
#define EOF_STRING "<!-- **EoF** -->"
#endif #endif

View file

@ -1 +0,0 @@
Adrian Bowyer,ensab,Charles,20.11.2013 18:47,file:///home/ensab/.config/libreoffice/3;

Binary file not shown.

View file

@ -61,6 +61,9 @@ void GCodes::Init()
fileToPrint = NULL; fileToPrint = NULL;
fileBeingWritten = NULL; fileBeingWritten = NULL;
configFile = NULL; configFile = NULL;
eofString = EOF_STRING;
eofStringCounter = 0;
eofStringLength = strlen(eofString);
homeX = false; homeX = false;
homeY = false; homeY = false;
homeZ = false; homeZ = false;
@ -121,9 +124,10 @@ void GCodes::Spin()
if(webserver->GCodeAvailable()) if(webserver->GCodeAvailable())
{ {
if(webGCode->Put(webserver->ReadGCode())) b = webserver->ReadGCode();
if(webGCode->Put(b))
{ {
if(webGCode->WritingFile()) if(webGCode->WritingFileDirectory())
WriteGCodeToFile(webGCode); WriteGCodeToFile(webGCode);
else else
webGCode->SetFinished(ActOnGcode(webGCode)); webGCode->SetFinished(ActOnGcode(webGCode));
@ -132,12 +136,26 @@ void GCodes::Spin()
return; return;
} }
// Now the serial interface. First check the special case of our
// uploading the reprap.htm file
if(serialGCode->WritingFileDirectory() == platform->GetWebDir())
{
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) if(platform->GetLine()->Status() & byteAvailable)
{ {
platform->GetLine()->Read(b); platform->GetLine()->Read(b);
if(serialGCode->Put(b)) if(serialGCode->Put(b))
{ {
if(serialGCode->WritingFile()) if(serialGCode->WritingFileDirectory())
WriteGCodeToFile(serialGCode); WriteGCodeToFile(serialGCode);
else else
serialGCode->SetFinished(ActOnGcode(serialGCode)); serialGCode->SetFinished(ActOnGcode(serialGCode));
@ -145,6 +163,9 @@ void GCodes::Spin()
platform->ClassReport("GCodes", longWait); platform->ClassReport("GCodes", longWait);
return; return;
} }
}
if(fileBeingPrinted != NULL) if(fileBeingPrinted != NULL)
{ {
@ -500,18 +521,47 @@ char* GCodes::GetCurrentCoordinates()
return scratchString; 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(directory, fileName, true);
fileBeingWritten = platform->GetFileStore(platform->GetSysDir(), fileName, true);
else
fileBeingWritten = platform->GetFileStore(platform->GetGCodeDir(), fileName, true);
if(fileBeingWritten == NULL) if(fileBeingWritten == NULL)
platform->Message(HOST_MESSAGE, "Can't open GCode file for writing.\n"); platform->Message(HOST_MESSAGE, "Can't open GCode file for writing.\n");
else 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) void GCodes::WriteGCodeToFile(GCodeBuffer *gb)
{ {
@ -532,7 +582,7 @@ void GCodes::WriteGCodeToFile(GCodeBuffer *gb)
{ {
fileBeingWritten->Close(); fileBeingWritten->Close();
fileBeingWritten = NULL; fileBeingWritten = NULL;
gb->SetWritingFile(false); gb->SetWritingFileDirectory(NULL);
char* r = reply; char* r = reply;
if(platform->Emulating() == marlin) if(platform->Emulating() == marlin)
r = "Done saving file."; r = "Done saving file.";
@ -1033,7 +1083,7 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
case 28: // Write to file case 28: // Write to file
str = gb->GetUnprecedentedString(); str = gb->GetUnprecedentedString();
OpenFileToWrite(str, gb, false); OpenFileToWrite(platform->GetGCodeDir(), str, gb);
snprintf(reply, STRING_LENGTH, "Writing to file: %s", str); snprintf(reply, STRING_LENGTH, "Writing to file: %s", str);
break; break;
@ -1296,7 +1346,13 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
case 559: // Upload config.g case 559: // Upload config.g
str = platform->GetConfigFile(); 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); snprintf(reply, STRING_LENGTH, "Writing to file: %s", str);
break; break;
@ -1376,7 +1432,7 @@ GCodeBuffer::GCodeBuffer(Platform* p, char* id)
{ {
platform = p; platform = p;
identity = id; 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() void GCodeBuffer::Init()

View file

@ -43,8 +43,8 @@ class GCodeBuffer
char* Buffer(); char* Buffer();
bool Finished(); bool Finished();
void SetFinished(bool f); void SetFinished(bool f);
bool WritingFile(); char* WritingFileDirectory();
void SetWritingFile(bool wf); void SetWritingFileDirectory(char* wfd);
private: private:
int CheckSum(); int CheckSum();
@ -55,7 +55,7 @@ class GCodeBuffer
int readPointer; int readPointer;
bool inComment; bool inComment;
bool finished; bool finished;
bool writingFile; char* writingFileDirectory;
}; };
//**************************************************************************************************** //****************************************************************************************************
@ -98,9 +98,10 @@ class GCodes
bool StandbyHeaters(); bool StandbyHeaters();
void SetEthernetAddress(GCodeBuffer *gb, int mCode); void SetEthernetAddress(GCodeBuffer *gb, int mCode);
void HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code, bool resend); 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); void WriteGCodeToFile(GCodeBuffer *gb);
bool SendConfigToLine(); bool SendConfigToLine();
void WriteHTMLToFile(char b, GCodeBuffer *gb);
int8_t Heater(int8_t head); int8_t Heater(int8_t head);
Platform* platform; Platform* platform;
@ -127,6 +128,9 @@ class GCodes
FileStore* fileToPrint; FileStore* fileToPrint;
FileStore* fileBeingWritten; FileStore* fileBeingWritten;
FileStore* configFile; FileStore* configFile;
char* eofString;
uint8_t eofStringCounter;
uint8_t eofStringLength;
int8_t selectedHead; int8_t selectedHead;
bool homeX; bool homeX;
bool homeY; bool homeY;
@ -165,14 +169,14 @@ inline void GCodeBuffer::SetFinished(bool f)
finished = 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() inline bool GCodes::PrintingAFile()

Binary file not shown.

View file

@ -777,3 +777,4 @@ poll();
</html> </html>
<!-- **EoF** -->

View file

@ -31,9 +31,6 @@ Licence: GPL
#define WEBSERVER_H #define WEBSERVER_H
#define INDEX_PAGE "reprap.htm"
#define MESSAGE_FILE "messages.txt"
#define FOUR04_FILE "html404.htm"
#define KO_START "rr_" #define KO_START "rr_"
#define KO_FIRST 3 #define KO_FIRST 3
#define POST_LENGTH 200 #define POST_LENGTH 200