Fixes in firmware

This commit is contained in:
Martin Bauer
2020-05-16 12:33:53 +02:00
parent d0ba98f12e
commit f20ab7ac9a
6 changed files with 103 additions and 60 deletions

View File

@@ -12,7 +12,9 @@ public:
void init(uint32_t epochStartTime) {
currentChunk = &chunks[0];
otherChunk = &chunks[1];
currentChunk->init(epochStartTime, 0);
otherChunk->init(0, 0);
}
bool addPoint(Measurement_T measurement) {
@@ -22,7 +24,7 @@ public:
rotate();
const bool secondInsertSuccess = currentChunk->addPoint(measurement);
assert(secondInsertSuccess, "Session: insertion after rotation failed");
//TODO check that there is place for file - remove old files
// TODO check that there is place for file - remove old files
}
return true;
}
@@ -80,7 +82,7 @@ private:
const auto fileName = chunkFileName(chunkNr, chunk->getStartTime());
Serial.print("Writing session to file ");
Serial.println(fileName);
Writer writer( fileName );
Writer writer(fileName);
chunk->serialize(writer.encoder());
};
@@ -91,7 +93,7 @@ private:
if( startIdx >= currentChunk->getStartIndex() ) {
encoder.sendArrayPartialContents( currentChunk->getDataPointer(), currentChunk->numMeasurements() );
return currentChunk->getStartIndex() + currentChunk->numMeasurements();
return currentChunk->getStartIndex() + currentChunk->numMeasurements();
} else if( startIdx >= otherChunk->getStartIndex() && otherChunkFilled() ) {
encoder.sendArrayPartialContents( otherChunk->getDataPointer(), otherChunk->numMeasurements() );
assert( otherChunk->numMeasurements(), CHUNK_SIZE );

View File

@@ -10,15 +10,12 @@ public:
encoder_(&f_),
fileName_(fileName)
{
Serial.println("Opened file for writing successful?");
bool success = f_;
Serial.println(success);
}
~SpiffsStorageWriter() {
f_.close();
Serial.print("Closing file: ");
Serial.println(fileName_);
Serial.print("File exists: ");
Serial.println(SPIFFS.exists(fileName_));
}
StreamingMsgPackEncoder<File> &encoder() { return encoder_; }
@@ -34,7 +31,7 @@ class SpiffsStorageReader
{
public:
SpiffsStorageReader(const String &fileName) :
f_(SPIFFS.open(fileName, "w"))
f_(SPIFFS.open(fileName, "r"))
{}
~SpiffsStorageReader() {
f_.close();

View File

@@ -17,6 +17,7 @@ namespace webdav_constants {
FLASH_TEXT(RESOURCETYPE_START) = "<D:resourcetype>";
FLASH_TEXT(RESOURCETYPE_END) = "</D:resourcetype>";
FLASH_TEXT(RESOURCE_COLLECTION) = "<D:collection/>";
FLASH_TEXT(HTTP_204_NO_CONTENT) = "HTTP/1.1 204 No Content";
FLASH_TEXT(CONTENTLEN_START) = "<D:getcontentlength>";
FLASH_TEXT(CONTENTLEN_END) = "</D:getcontentlength>";
@@ -31,8 +32,14 @@ void listFiles(AsyncResponseStream * response, const char *folderPath, Dir * dir
{
using namespace webdav_constants;
response->println(MULTISTATUS_START);
Serial.println("Before rewind");
dir->rewind();
Serial.println("After rewind");
while (dir->next()) {
Serial.println("Inside dir loop");
Serial.println(folderPath);
Serial.println(dir->fileName());
response->print(RESPONSE_START);
response->print(HREF_START);
response->print(folderPath);
@@ -53,7 +60,7 @@ void listFiles(AsyncResponseStream * response, const char *folderPath, Dir * dir
response->print(PROP_END);
response->print(STATUS_OK);
response->print(PROPSTAT_END);
response->print(webdav_constants::RESPONSE_END);
response->println(webdav_constants::RESPONSE_END);
}
response->println(MULTISTATUS_END);
}
@@ -75,14 +82,14 @@ public:
virtual void handleRequest(AsyncWebServerRequest *request) override final
{
if (request->url() == prefix_ && request->method() == HTTP_PROPFIND) {
if (request->url() == prefix_ + "/" && request->method() == HTTP_PROPFIND) {
Serial.println("Propfind start");
AsyncResponseStream * response = request->beginResponseStream("application/xml");
Dir dir = SPIFFS.openDir(folder_);
listFiles(response, "/", &dir);
request->send(response);
} else if(request->url() == prefix_ && request->method() == HTTP_GET) {
AsyncResponseStream * response = request->beginResponseStream("text/plain");
} else if(request->url() == prefix_ + "/" && request->method() == HTTP_GET) {
AsyncResponseStream * response = request->beginResponseStream("text/plain", 1460*10);
Dir dir = SPIFFS.openDir(folder_);
Serial.print("Opening folder ");
Serial.println(folder_);
@@ -95,15 +102,21 @@ public:
}
else if (request->method() == HTTP_GET) {
auto path = folder_ + request->url().substring(prefix_.length());
Serial.print("Testing if path exists: ");
Serial.println(path);
if (SPIFFS.exists(path)) {
Serial.println("Exists!");
request->send(SPIFFS, path, "application/x-msgpack");
} else {
Serial.println("Does not exist :(");
request->send(404, "text/plain", "Webdav: File not found");
}
} else if (request->method() == HTTP_DELETE) {
auto path = folder_ + request->url().substring(prefix_.length());
if (SPIFFS.exists(path)) {
if(SPIFFS.remove(path))
request->send(204, "text/plain", "Success");
else
request->send(404, "text/plain", "Webdav: Invalid delete request");
} else {
request->send(404, "text/plain", "Webdav: File to delete not found");
}
} else {
request->send(404, "text/plain", "Webdav: Invalid request");
}