Native tests run again

This commit is contained in:
Martin Bauer
2020-06-07 10:59:16 +02:00
parent d895d85273
commit 5558151c91
13 changed files with 95 additions and 75 deletions

View File

@@ -1,6 +1,12 @@
#pragma once
inline void _assert(const char* expression, const char* message, const char* file, int line)
#ifndef PLATFORM_NATIVE
// ---------------------------------- Arduino -------------------------------------------------------------
#include <Arduino.h>
inline void _assert(const char *expression, const char *message, const char *file, int line)
{
Serial.print("Assert ");
Serial.print(file);
@@ -12,9 +18,58 @@ inline void _assert(const char* expression, const char* message, const char* fil
Serial.println(message);
}
template< typename T>
inline String toString(const T & t) {
template <typename T>
inline String toString(const T &t)
{
return String(t);
}
#define assert_msg(EXPRESSION, MSG) ((EXPRESSION) ? (void)0 : _assert(#EXPRESSION, #MSG, __FILE__, __LINE__))
#else
// ---------------------------------- Native -----------------------------------------------------------------
#include <string>
#include <cstdint>
#include <cstring>
#include <arpa/inet.h>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
typedef uint32_t uint_t;
typedef std::string String;
typedef uint8_t byte;
typedef const char *PGM_P;
using std::max;
using std::min;
inline uint32_t strlen_P(PGM_P str)
{
return std::strlen(str);
}
inline const char *F(const char *in) { return in; }
inline void _assert(const char *expression, const char *message, const char *file, int line)
{
std::cerr << "Assert " << file << ":" << line << " '" << expression << "' failed." << std::endl;
std::cerr << message << std::endl;
abort();
}
template <typename T>
inline std::string toString(const T &t)
{
std::stringstream stream;
stream << t;
return stream.str();
}
#define assert_msg(EXPRESSION, MSG) ((EXPRESSION) ? (void)0 : _assert(#EXPRESSION, #MSG, __FILE__, __LINE__))
#endif

View File

@@ -1,5 +1,7 @@
#pragma once
#include "Dtypes.h"
#ifdef PLATFORM_ESP32
#include "SPIFFS.h"
@@ -93,7 +95,6 @@ namespace portablefs
#include <string>
#include <fstream>
#include <filesystem>
#include "MockDtypes.h"
namespace fs = std::filesystem;

View File

@@ -1,46 +0,0 @@
#pragma once
#include <string>
#include <cstdint>
#include <cstring>
#include <arpa/inet.h>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
typedef uint32_t uint_t;
typedef std::string String;
typedef uint8_t byte;
typedef const char * PGM_P;
using std::min;
using std::max;
inline uint32_t strlen_P(PGM_P str) {
return std::strlen(str);
}
inline const char * F( const char * in) { return in; }
inline void _assert(const char* expression, const char* message, const char* file, int line)
{
std::cerr << "Assert " << file << ":" << line << " '" << expression << "' failed." << std::endl;
std::cerr << message << std::endl;
abort();
}
template< typename T>
inline std::string toString(const T & t) {
std::stringstream stream;
stream << t;
return stream.str();
}
class String : public std::string
{};
#define assert(EXPRESSION, MSG) ((EXPRESSION) ? (void)0 : _assert(#EXPRESSION, #MSG, __FILE__, __LINE__))

View File

@@ -11,8 +11,8 @@ public:
if (hx711_.is_ready())
{
long value = hx711_.read_average(CONFIG_MEASUREMENT_AVG_COUNT) - offset_;
if(value > 0)
measurementOut = (int16_t)(value / DIVIDER);
if(value < 0)
measurementOut = (int16_t)(-value / DIVIDER);
else
measurementOut = 0;
return true;

View File

@@ -126,7 +126,7 @@ private:
}
static String chunkFileName(uint32_t chunkNr, uint32_t startTime) {
return("/dat/" + toString(startTime) + "_" + toString(chunkNr));
return("/dat/" + toString(startTime) + String("_") + toString(chunkNr));
}
Chunk_T chunks[2];

View File

@@ -1,9 +1,6 @@
#pragma once
#ifndef PLATFORM_NATIVE
#include <Arduino.h>
#endif
#include "Dtypes.h"
using SessionIdType = uint32_t;
constexpr size_t MAX_USERS = 64;

View File

@@ -41,8 +41,7 @@ public:
size_t operator()(uint8_t *buffer, size_t maxLen, size_t index)
{
Serial.print("index ");
Serial.println(index);
Serial.printf("%ld index %u\n", millis(), index);
using namespace webdav_constants;
uint8_t *bufferStart = buffer;
@@ -57,6 +56,7 @@ public:
}
bool fileFound = false;
Serial.printf("%ld (0)\n", millis());
while (dir_.next())
{
if (isFirstFileOfTrainingGroup())
@@ -71,10 +71,12 @@ public:
//toBuffer(buffer, path_.c_str());
toBuffer(buffer, RESPONSE_START);
toBuffer(buffer, HREF_START);
Serial.printf("%ld (1)\n", millis());
const auto fileName = dir_.fileName();
const auto fileNameWithoutDir = fileName.substring(fileName.lastIndexOf("/") + 1);
String fileBaseName = fileNameWithoutDir.substring(0, fileNameWithoutDir.indexOf('_'));
fileBaseName += ".st";
Serial.printf("%ld (2)\n", millis());
toBuffer(buffer, fileBaseName.c_str());
toBuffer(buffer, HREF_END);
toBuffer(buffer, PROPSTAT_START);
@@ -89,9 +91,11 @@ public:
{
toBuffer(buffer, CONTENTLEN_START);
String fileSizeStr(getFileSize(fileName));
toBuffer(buffer, fileSizeStr.c_str());
//toBuffer(buffer, fileSizeStr.c_str());
toBuffer(buffer, "1");
toBuffer(buffer, CONTENTLEN_END);
}
Serial.printf("%ld (3)\n", millis());
toBuffer(buffer, PROP_END);
toBuffer(buffer, STATUS_OK);
@@ -104,10 +108,10 @@ public:
finished_ = true;
}
size_t bytesWritten = buffer - bufferStart;
assert_msg(bytesWritten < maxLen, "Written too much!");
//Serial.print("Bytes written ");
//Serial.println(bytesWritten);
Serial.printf("%ld Bytes written %u\n", millis(), bytesWritten);
//Serial.print("Max bytes ");
//Serial.println(maxLen);
return bytesWritten;