Native tests run again
This commit is contained in:
parent
d895d85273
commit
5558151c91
|
@ -9,4 +9,4 @@ build:
|
||||||
script:
|
script:
|
||||||
- cd firmware
|
- cd firmware
|
||||||
- platformio run
|
- platformio run
|
||||||
#- platformio test -v -e native
|
- platformio test -v -e native
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef PLATFORM_NATIVE
|
||||||
|
|
||||||
|
// ---------------------------------- Arduino -------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
inline void _assert(const char *expression, const char *message, const char *file, int line)
|
inline void _assert(const char *expression, const char *message, const char *file, int line)
|
||||||
{
|
{
|
||||||
Serial.print("Assert ");
|
Serial.print("Assert ");
|
||||||
|
@ -13,8 +19,57 @@ inline void _assert(const char* expression, const char* message, const char* fil
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline String toString(const T & t) {
|
inline String toString(const T &t)
|
||||||
|
{
|
||||||
return String(t);
|
return String(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define assert_msg(EXPRESSION, MSG) ((EXPRESSION) ? (void)0 : _assert(#EXPRESSION, #MSG, __FILE__, __LINE__))
|
#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
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Dtypes.h"
|
||||||
|
|
||||||
#ifdef PLATFORM_ESP32
|
#ifdef PLATFORM_ESP32
|
||||||
#include "SPIFFS.h"
|
#include "SPIFFS.h"
|
||||||
|
|
||||||
|
@ -93,7 +95,6 @@ namespace portablefs
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "MockDtypes.h"
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
|
|
@ -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__))
|
|
|
@ -11,8 +11,8 @@ public:
|
||||||
if (hx711_.is_ready())
|
if (hx711_.is_ready())
|
||||||
{
|
{
|
||||||
long value = hx711_.read_average(CONFIG_MEASUREMENT_AVG_COUNT) - offset_;
|
long value = hx711_.read_average(CONFIG_MEASUREMENT_AVG_COUNT) - offset_;
|
||||||
if(value > 0)
|
if(value < 0)
|
||||||
measurementOut = (int16_t)(value / DIVIDER);
|
measurementOut = (int16_t)(-value / DIVIDER);
|
||||||
else
|
else
|
||||||
measurementOut = 0;
|
measurementOut = 0;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -126,7 +126,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
static String chunkFileName(uint32_t chunkNr, uint32_t startTime) {
|
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];
|
Chunk_T chunks[2];
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef PLATFORM_NATIVE
|
#include "Dtypes.h"
|
||||||
#include <Arduino.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
using SessionIdType = uint32_t;
|
using SessionIdType = uint32_t;
|
||||||
constexpr size_t MAX_USERS = 64;
|
constexpr size_t MAX_USERS = 64;
|
||||||
|
|
|
@ -41,8 +41,7 @@ public:
|
||||||
|
|
||||||
size_t operator()(uint8_t *buffer, size_t maxLen, size_t index)
|
size_t operator()(uint8_t *buffer, size_t maxLen, size_t index)
|
||||||
{
|
{
|
||||||
Serial.print("index ");
|
Serial.printf("%ld index %u\n", millis(), index);
|
||||||
Serial.println(index);
|
|
||||||
|
|
||||||
using namespace webdav_constants;
|
using namespace webdav_constants;
|
||||||
uint8_t *bufferStart = buffer;
|
uint8_t *bufferStart = buffer;
|
||||||
|
@ -57,6 +56,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fileFound = false;
|
bool fileFound = false;
|
||||||
|
Serial.printf("%ld (0)\n", millis());
|
||||||
while (dir_.next())
|
while (dir_.next())
|
||||||
{
|
{
|
||||||
if (isFirstFileOfTrainingGroup())
|
if (isFirstFileOfTrainingGroup())
|
||||||
|
@ -71,10 +71,12 @@ public:
|
||||||
//toBuffer(buffer, path_.c_str());
|
//toBuffer(buffer, path_.c_str());
|
||||||
toBuffer(buffer, RESPONSE_START);
|
toBuffer(buffer, RESPONSE_START);
|
||||||
toBuffer(buffer, HREF_START);
|
toBuffer(buffer, HREF_START);
|
||||||
|
Serial.printf("%ld (1)\n", millis());
|
||||||
const auto fileName = dir_.fileName();
|
const auto fileName = dir_.fileName();
|
||||||
const auto fileNameWithoutDir = fileName.substring(fileName.lastIndexOf("/") + 1);
|
const auto fileNameWithoutDir = fileName.substring(fileName.lastIndexOf("/") + 1);
|
||||||
String fileBaseName = fileNameWithoutDir.substring(0, fileNameWithoutDir.indexOf('_'));
|
String fileBaseName = fileNameWithoutDir.substring(0, fileNameWithoutDir.indexOf('_'));
|
||||||
fileBaseName += ".st";
|
fileBaseName += ".st";
|
||||||
|
Serial.printf("%ld (2)\n", millis());
|
||||||
toBuffer(buffer, fileBaseName.c_str());
|
toBuffer(buffer, fileBaseName.c_str());
|
||||||
toBuffer(buffer, HREF_END);
|
toBuffer(buffer, HREF_END);
|
||||||
toBuffer(buffer, PROPSTAT_START);
|
toBuffer(buffer, PROPSTAT_START);
|
||||||
|
@ -89,9 +91,11 @@ public:
|
||||||
{
|
{
|
||||||
toBuffer(buffer, CONTENTLEN_START);
|
toBuffer(buffer, CONTENTLEN_START);
|
||||||
String fileSizeStr(getFileSize(fileName));
|
String fileSizeStr(getFileSize(fileName));
|
||||||
toBuffer(buffer, fileSizeStr.c_str());
|
//toBuffer(buffer, fileSizeStr.c_str());
|
||||||
|
toBuffer(buffer, "1");
|
||||||
toBuffer(buffer, CONTENTLEN_END);
|
toBuffer(buffer, CONTENTLEN_END);
|
||||||
}
|
}
|
||||||
|
Serial.printf("%ld (3)\n", millis());
|
||||||
|
|
||||||
toBuffer(buffer, PROP_END);
|
toBuffer(buffer, PROP_END);
|
||||||
toBuffer(buffer, STATUS_OK);
|
toBuffer(buffer, STATUS_OK);
|
||||||
|
@ -104,10 +108,10 @@ public:
|
||||||
finished_ = true;
|
finished_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t bytesWritten = buffer - bufferStart;
|
size_t bytesWritten = buffer - bufferStart;
|
||||||
assert_msg(bytesWritten < maxLen, "Written too much!");
|
assert_msg(bytesWritten < maxLen, "Written too much!");
|
||||||
//Serial.print("Bytes written ");
|
Serial.printf("%ld Bytes written %u\n", millis(), bytesWritten);
|
||||||
//Serial.println(bytesWritten);
|
|
||||||
//Serial.print("Max bytes ");
|
//Serial.print("Max bytes ");
|
||||||
//Serial.println(maxLen);
|
//Serial.println(maxLen);
|
||||||
return bytesWritten;
|
return bytesWritten;
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
//#define _HW_V_20
|
#define _HW_V_20
|
||||||
|
|
||||||
// HX711 load cell
|
// HX711 load cell
|
||||||
#ifdef USE_ESP32
|
#ifdef PLATFORM_ESP32
|
||||||
|
|
||||||
#ifdef _HW_V_20
|
#ifdef _HW_V_20
|
||||||
const int CONFIG_SCALE_DOUT_PIN = 23;
|
const int CONFIG_SCALE_DOUT_PIN = 23;
|
||||||
|
@ -24,6 +24,6 @@ const uint8_t CONFIG_MEASUREMENT_AVG_COUNT = 1; // number of measurements in nor
|
||||||
const uint8_t CONFIG_TARE_AVG_COUNT = 6; // number of measurements in tare-phase (to find 0 )
|
const uint8_t CONFIG_TARE_AVG_COUNT = 6; // number of measurements in tare-phase (to find 0 )
|
||||||
const int CONFIG_MEASURE_DELAY = 100; // interval in ms between measurements
|
const int CONFIG_MEASURE_DELAY = 100; // interval in ms between measurements
|
||||||
//const int CONFIG_VALUE_DIVIDER = 8; // uint32 measurements are divided by this factor, before stored in uint16_t
|
//const int CONFIG_VALUE_DIVIDER = 8; // uint32 measurements are divided by this factor, before stored in uint16_t
|
||||||
const int CONFIG_VALUE_DIVIDER = 256; // uint32 measurements are divided by this factor, before stored in uint16_t
|
const int CONFIG_VALUE_DIVIDER = 128; // uint32 measurements are divided by this factor, before stored in uint16_t
|
||||||
|
|
||||||
const uint32_t CONFIG_SESSION_CHUNK_SIZE = 1024; //1024*8 - 16 * sizeof(uint32_t);
|
const uint32_t CONFIG_SESSION_CHUNK_SIZE = 1024; //1024*8 - 16 * sizeof(uint32_t);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#define USE_ESP32
|
|
||||||
|
|
||||||
// Arduino & ESP headers
|
// Arduino & ESP headers
|
||||||
#include <Arduino.h>
|
#include "Dtypes.h"
|
||||||
#ifdef USE_ESP32
|
|
||||||
|
#ifdef PLATFORM_ESP32
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#else
|
#else
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
@ -13,7 +13,6 @@
|
||||||
#include <NTPClient.h> // for NTP
|
#include <NTPClient.h> // for NTP
|
||||||
|
|
||||||
// Own libs
|
// Own libs
|
||||||
#include "Dtypes.h"
|
|
||||||
#include "MockScale.h"
|
#include "MockScale.h"
|
||||||
#include "Scale.h"
|
#include "Scale.h"
|
||||||
#include "MeasurementSession.h"
|
#include "MeasurementSession.h"
|
||||||
|
@ -207,7 +206,7 @@ void setup()
|
||||||
// WiFi
|
// WiFi
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
|
WiFi.begin(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
|
||||||
#ifdef USE_ESP32
|
#ifdef PLATFORM_ESP32
|
||||||
WiFi.setHostname(CONFIG_HOSTNAME);
|
WiFi.setHostname(CONFIG_HOSTNAME);
|
||||||
#else
|
#else
|
||||||
WIFI.hostname(CONFIG_HOSTNAME);
|
WIFI.hostname(CONFIG_HOSTNAME);
|
||||||
|
@ -232,6 +231,10 @@ void setup()
|
||||||
|
|
||||||
Serial.println("Spiffs listing:");
|
Serial.println("Spiffs listing:");
|
||||||
listDir(SPIFFS, "/", 3);
|
listDir(SPIFFS, "/", 3);
|
||||||
|
|
||||||
|
//
|
||||||
|
Serial.print("Free Heap");
|
||||||
|
Serial.println(ESP.getFreeHeap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "MockDtypes.h"
|
#include "Dtypes.h"
|
||||||
#include "MockSerial.h"
|
#include "MockSerial.h"
|
||||||
#include "MeasurementSession.h"
|
#include "MeasurementSession.h"
|
||||||
#include "MockStorage.h"
|
#include "MockStorage.h"
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
Old load cell
|
||||||
|
const int CONFIG_VALUE_DIVIDER = 128;
|
||||||
|
1kg ~= 700
|
||||||
|
=> overflow at 93 kg
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue