Create a custom library which uses Arduino Extended Database Library

Hi,

I am still struggling...

Yes, it did compile, but only to crash the UC.

So I wanted to see what was going on inside, and added Hardware Serial features to debug.
And now it doesn't compile anymore and I am back to the multiple Struct declaration problem.

The worst is I don't understand why.

My INO sketch:

#include "Arduino.h"
#include "Runner.h"

//#include <EDB.h>
//#include "LSD.h"
//#include "LStorage.h"
//#include "LFlash.h"
//#include "DBrecord.h"
//#include "DBabstraction.h"
//#include "DBrecord.h"

// Define variables and constants
#define UsbSerial Serial // rename Serial ports
// Variables
Runner myRunner(&UsbSerial);

// Add setup code
void setup()
{
    UsbSerial.begin(115200);
    myRunner.begin();
}

// Add loop code
void loop()
{
    delay(500);
    myRunner.run();
}

Runner.h:

#ifndef Runner_h
#define Runner_h

#include "Arduino.h"
#include "DBabstraction.h"
#include "DBrecord.h"
#include "HardwareSerial.h"

class Runner {
  public:
    Runner(HardwareSerial *serial);
    void run();
    void begin();
    static DBabstraction *globalDB;
    HardwareSerial * _HardSerial;
    
    void globalConfigWriter( unsigned long address, byte data ) {
      globalDB->dbWriter(address, data);
    }
    byte globalConfigReader( unsigned long address ) {
      return globalDB->dbReader(address);
    }
    
};

#endif // Runner_h

Runner.cpp:

// Library header
#include "Runner.h"

// Code
/**************************************************/

DBabstraction *Runner::globalDB = NULL;

// public functions
Runner::Runner(HardwareSerial *serial) {
  _HardSerial = serial;
  if(_HardSerial) _HardSerial->printf("[Runner] constructor\n");
  globalDB = new DBabstraction(_HardSerial);
}

void Runner::run() {
  if(_HardSerial) _HardSerial->printf("[Runner] run()\n");
}

void Runner::begin() {
  if(_HardSerial) _HardSerial->printf("[Runner] begin()\n");
  if (globalDB) globalDB->begin();
}

DBabstraction.h:

#ifndef DBabstraction_h
#define DBabstraction_h

#include "Arduino.h"
#include <EDB.h>
#include "LSD.h"
#include "LStorage.h"
#include "LFlash.h"
#include "DBrecord.h"
#include "HardwareSerial.h"

#define Drv LFlash          // use Internal 10M Flash

#define TABLE_SIZE 8192     // arbitrary for now
#define FILE_PATH "db.txt"
#define RECORDS_TO_CREATE 10 // This should be less than (TABLE_SIZE - sizeof(EDB_Header)) / sizeof(LogEvent).


class DBabstraction {
  public:
    DBabstraction(HardwareSerial *serial);
    EDB *myDB;
    void begin();
    static LFile * myFile;
    static void dbWriter( unsigned long address, byte data );
    static byte dbReader( unsigned long address );
    static HardwareSerial * _HardSerial;
    
  private:
    static DBabstraction * pInstance; // pointer to the DBabstraction instance

};
#endif // DBabstraction_h

DBabstraction.cpp:

// Library header
#include "DBabstraction.h"

DBabstraction *DBabstraction::pInstance = NULL;
LFile *DBabstraction::myFile = NULL;
HardwareSerial *DBabstraction::_HardSerial = NULL;

//constructor
DBabstraction::DBabstraction(HardwareSerial *serial) {
  _HardSerial = serial;
  pInstance = this;
}

/* The raw writer function exposed to the EDB library */
void DBabstraction::dbWriter(unsigned long address, byte data ) {
  /* nothing */
  if(_HardSerial) _HardSerial->printf("[DBabstraction] dbWriter\n");
  if (myFile) {
    myFile->seek(address);
    myFile->write(data);
    myFile->flush();
  }
}

/* The raw writer function exposed to the EDB library */
byte DBabstraction::dbReader( unsigned long address) {
  /* nothing */
  if(_HardSerial) _HardSerial->printf("[DBabstraction] dbReader\n");
  if (myFile) {
    myFile->seek(address);
    return myFile->read();
  }
}

/* The Arduino Begin() function of the class */
void DBabstraction::begin() {
  if(_HardSerial) _HardSerial->printf("[DBabstraction] Begin\n");
  // start the flash drive
  Drv.begin();

  // try to open the DB file
  *myFile = Drv.open(FILE_PATH, FILE_WRITE);

  // if the file opened okay, set flag okay
  if (myFile) {
    myFile->close();
  } else {
    // if the file didn't open, tell it
    if(_HardSerial) _HardSerial->printf("[DBabstraction] error opening the db file\n");
  }

  // retry to open the file for reading:
  *myFile = Drv.open(FILE_PATH, FILE_WRITE);
  if (myFile) {
    if(_HardSerial) _HardSerial->printf("Opening current table\n");
    EDB_Status result = myDB->open(0);
    if (result == EDB_OK) //
      myFile->seek(0);
  } else {
    // if the file didn't open, print an error:
    if(_HardSerial) _HardSerial->printf("[DBabstraction] error opening the db file, aborted\n");
  }

  // create the EDB instance with the DBabstraction reader/writer
  myDB = new EDB(DBabstraction::dbWriter, DBabstraction::dbReader);
}
// Code DBabstraction.cpp