Upload files to "/"
This commit is contained in:
parent
aa0b4d208c
commit
94f2c99da4
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
0 No Flow fault
|
||||
1 Flow fault (leak)
|
||||
2 Power Up
|
||||
3 Expansion comms fault
|
||||
4 Display Ping fault
|
||||
5 Wifi Timeout
|
||||
6 No AT200 RX Timeout
|
||||
*/
|
||||
|
||||
#define MAXFAULTS 100
|
||||
int faultCount[MAXFAULTS];
|
||||
const int faultLimits[MAXFAULTS] = // how many consective faults befor it's real
|
||||
{
|
||||
1, // 0 powerup
|
||||
2, // 1 SD card error
|
||||
1, // 2 low battery
|
||||
4, // 3
|
||||
1, // 4
|
||||
1, // 5
|
||||
1, // 6
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 10
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 15
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 20
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 24
|
||||
1, // 25 Obstruction Fault
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 30
|
||||
1,
|
||||
1,
|
||||
1, // 33 Get motor error
|
||||
1, // 34 motor fault
|
||||
1, // 35 Lidar obstruction fault
|
||||
1, // 36 No display 1
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 40
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 45
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 49
|
||||
1, // 50
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 55
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 60
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 65
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 69
|
||||
1, // 70
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 75
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 80
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 85
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 89
|
||||
1, // 90
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // 95
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1 // 99
|
||||
};
|
||||
|
||||
#define fault_QSIZ 40
|
||||
struct faultQ
|
||||
{
|
||||
uint16_t faultnum;
|
||||
uint32_t etime;
|
||||
int32_t data[6];
|
||||
} fault_Q[fault_QSIZ], fault_Qtempdata;
|
||||
|
||||
int fault_Qhead = 0;
|
||||
int fault_Qtail = 0;
|
||||
|
||||
#define RENLITAOFFSET 400 // Renlita fault num offset in cloud
|
||||
|
||||
void initFaults(void)
|
||||
{
|
||||
// int fi;
|
||||
// for (fi = 0; fi < MAXFAULTS; fi++) faultCount[fi] = 0;
|
||||
memset(faultCount, 0, sizeof(faultCount));
|
||||
memset(fault_Q, 0, sizeof(fault_Q));
|
||||
fault_Qhead = 0;
|
||||
fault_Qtail = 0;
|
||||
}
|
||||
|
||||
void qualifyFault(int fnum, int32_t fdat)
|
||||
{
|
||||
|
||||
if (fnum < MAXFAULTS)
|
||||
{
|
||||
if (faultCount[fnum] < faultLimits[fnum]) // no fault last time
|
||||
if (++faultCount[fnum] >= faultLimits[fnum]) // no previous fault
|
||||
{
|
||||
faultQ_push(fnum + RENLITAOFFSET, fdat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void restoreFault(int fnum)
|
||||
{
|
||||
|
||||
if (fnum < MAXFAULTS)
|
||||
if (faultCount[fnum] > 0)
|
||||
{
|
||||
faultCount[fnum] = 0;
|
||||
Serial.print("Fault Restored ");
|
||||
Serial.println(fnum);
|
||||
}
|
||||
}
|
||||
|
||||
void faultQ_push(int fnum, int32_t fdat) // load tempdata struct first.. pointer sits on next one to add
|
||||
{
|
||||
|
||||
fault_Q[fault_Qhead].faultnum = fnum;
|
||||
fault_Q[fault_Qhead].etime = getEpochRtc();
|
||||
fault_Q[fault_Qhead].data[0] = fdat;
|
||||
|
||||
Serial.println("Fault Push");
|
||||
Serial.println(fnum);
|
||||
|
||||
if (++fault_Qhead >= fault_QSIZ)
|
||||
fault_Qhead = 0; // if at end then wrap
|
||||
|
||||
if (fault_Qhead == fault_Qtail)
|
||||
fault_Qtail++; // if hit other pointer then we full
|
||||
if (fault_Qtail == fault_QSIZ)
|
||||
fault_Qtail = 0; // if at end then wrap
|
||||
}
|
||||
|
||||
void faultQ_pull(void) // dumps into tempdata struct pointer sits on next on to pull
|
||||
{
|
||||
int f;
|
||||
fault_Qtempdata.faultnum = fault_Q[fault_Qtail].faultnum;
|
||||
fault_Qtempdata.etime = fault_Q[fault_Qtail].etime;
|
||||
|
||||
for (f = 0; f < 6; f++)
|
||||
fault_Qtempdata.data[f] = fault_Q[fault_Qtail].data[f];
|
||||
|
||||
Serial.println("Fault Pull");
|
||||
Serial.println(fault_Qtempdata.faultnum);
|
||||
|
||||
if (++fault_Qtail == fault_QSIZ)
|
||||
fault_Qtail = 0; // if at end then wrap
|
||||
}
|
||||
|
||||
int faultQ_size(void)
|
||||
{
|
||||
if (fault_Qhead >= fault_Qtail)
|
||||
return (fault_Qhead - fault_Qtail);
|
||||
else
|
||||
return ((fault_QSIZ - fault_Qtail) + fault_Qhead);
|
||||
}
|
||||
|
|
@ -0,0 +1,191 @@
|
|||
#ifndef FILE_LIB_H
|
||||
#define FILE_LIB_H
|
||||
|
||||
#include <FS.h>
|
||||
#include <LITTLEFS.h>
|
||||
#include <SD_MMC.h>
|
||||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
|
||||
/**
|
||||
* @enum StorageType
|
||||
*/
|
||||
enum StorageType
|
||||
{
|
||||
/**
|
||||
* Use onboard SPIFFS
|
||||
*/
|
||||
FL_SPIFFS,
|
||||
/**
|
||||
* Use the SD library
|
||||
*/
|
||||
FL_SD,
|
||||
/**
|
||||
* Use the SD_MMC library
|
||||
*/
|
||||
FL_MMC
|
||||
};
|
||||
|
||||
/**
|
||||
* @class FileLibClass
|
||||
* @brief Wrapper for SPIFFS and SD file systems
|
||||
*/
|
||||
class FileLibClass
|
||||
{
|
||||
private:
|
||||
fs::FS *_filesystem = nullptr;
|
||||
SPIClass _spi = SPIClass(VSPI);
|
||||
StorageType _type;
|
||||
|
||||
bool _verbose = false;
|
||||
|
||||
/**
|
||||
* Print out message, if verbose mode is enabled
|
||||
*/
|
||||
void _printMessage(const char *message, ...);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param type StorageType::SPIFFS or StorageType::SD
|
||||
*/
|
||||
FileLibClass(StorageType type);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~FileLibClass();
|
||||
|
||||
/**
|
||||
* Begin the file system
|
||||
* @param csPin Optional, default 5. Chip select pin for SD card
|
||||
* @param misoPin Optional, default 19. MISO pin for SD card
|
||||
* @param mosiPin Optional, default 23. MOSI pin for SD card
|
||||
* @param sckPin Optional, default 18. SCK pin for SD card
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
bool begin(uint8_t csPin = 5, uint8_t misoPin = 19, uint8_t mosiPin = 23, uint8_t sckPin = 18);
|
||||
|
||||
/**
|
||||
* Enable or disable verbose mode
|
||||
* @param verbose True to enable verbose mode
|
||||
*/
|
||||
void setVerbose(bool verbose) { _verbose = verbose; }
|
||||
|
||||
/**
|
||||
* Open the file
|
||||
* @param fileName Path and filename to open
|
||||
*
|
||||
* @return File object
|
||||
*/
|
||||
File openForWriting(const char *fileName);
|
||||
|
||||
/**
|
||||
* Open the file
|
||||
* @param fileName Filename to open
|
||||
*
|
||||
* @return File object
|
||||
*/
|
||||
File open(const char *fileName, const char *mode = FILE_READ);
|
||||
|
||||
/**
|
||||
* List the contents of a directory
|
||||
* @param dirName Path to the directory
|
||||
* @param levels Optional, default 0. How many levels deep to list
|
||||
*/
|
||||
void listDir(const char *dirName, uint8_t levels = 0);
|
||||
|
||||
/**
|
||||
* Read from a file. This opens the file and reads
|
||||
* the data into a buffer. Clears the buffer before reading
|
||||
* by default.
|
||||
* @param fileName Path and filename to read from
|
||||
* @param buffer Buffer to read to.
|
||||
* @param bufferSzie Size of the buffer.
|
||||
* @param clearBuffer Optional, default true. If true, the buffer will be cleared before reading
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
bool read(const char *fileName, uint8_t *buffer, uint16_t bufferSize, bool clearBuffer = true);
|
||||
|
||||
/**
|
||||
* Write to a file. This opens the file and
|
||||
* writes the bytes to the file.
|
||||
* @param fileName Path and filename to write to
|
||||
* @param data What will be written to the file
|
||||
* @param dataSize Size of the data
|
||||
* @param append Optional, default false. If true, the data will be appended to the file
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
bool write(const char *fileName, const uint8_t *data, size_t dataSize, bool append = false);
|
||||
|
||||
/**
|
||||
* Write to a file. This opens the file and
|
||||
* writes string data to the file. This is a wrapper
|
||||
* for write().
|
||||
* @param fileName Path and filename to write to
|
||||
* @param data What will be written to the file
|
||||
* @param dataSize Size of the data
|
||||
* @param append Optional, default false. If true, the data will be appended to the file
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
bool writeString(const char *fileName, const uint8_t *data, bool append = false);
|
||||
|
||||
/**
|
||||
* Delete a file
|
||||
* @param fileName Path and filename to delete
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
bool remove(const char *fileName);
|
||||
|
||||
/**
|
||||
* Rename a file
|
||||
* @param fileName Path and filename to rename
|
||||
* @param newName New path and filename
|
||||
* @param overwrite Optional, default false. If true, the new file will overwrite an existing file
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
bool rename(const char *fileName, const char *newName, bool overwrite = false);
|
||||
|
||||
/**
|
||||
* Create a directory. Spiff currently doesn't support this.
|
||||
* @param path Path to the directory
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
bool mkdir(const char *path);
|
||||
|
||||
/**
|
||||
* Get free space on the file system. Return
|
||||
*
|
||||
* @return Free space in bytes
|
||||
*/
|
||||
uint64_t getFreeSpace();
|
||||
|
||||
/**
|
||||
* Copy a file from a source to a destination
|
||||
*
|
||||
* @param source File object to copy from
|
||||
* @param dest File object to copy to
|
||||
*/
|
||||
bool copy(File &source, File &dest);
|
||||
|
||||
/**
|
||||
* Read a portion of a file
|
||||
*
|
||||
* @param fileName Path and filename to read from
|
||||
* @param startPos Starting position to read from
|
||||
* @param buffer Buffer to read to
|
||||
* @param bufferSize Size of the buffer
|
||||
*/
|
||||
bool readPartial(const char *fileName, uint32_t startPos, uint8_t *buffer, uint16_t bufferSize);
|
||||
|
||||
bool exists(const char* fileName);
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue