The field version of the solarnano grid on the ionQubes

Fork of SolarNanoGridv3 by SONG Project

Revision:
1:df924e0126d1
Parent:
0:dc8a45ec969a
Child:
2:929cf7fc6998
--- a/SolarNanoGrid.cpp	Thu May 05 13:44:24 2016 +0000
+++ b/SolarNanoGrid.cpp	Fri May 06 14:56:20 2016 +0000
@@ -1,3 +1,98 @@
+#include "pinmap.h"
 #include "battery.h"
 #include "locker.h"
-#include "SolarNanoGrid.h"
\ No newline at end of file
+#include "SolarNanoGrid.h"
+
+#define DEBUG
+#define INFOMESSAGES
+#define WARNMESSAGES
+#define ERRMESSAGES
+
+#ifdef DEBUG
+#define DBG(x, ...) printf("[SNG : DBG] "x"\r\n", ##__VA_ARGS__); 
+#else
+#define DBG(x, ...) 
+#endif
+
+#ifdef ERRMESSAGES
+#define ERR(x, ...) printf("[SNG : ERR] "x"\r\n", ##__VA_ARGS__); 
+#else
+#define ERR(x, ...) 
+#endif
+
+#ifdef WARNMESSAGES
+#define WARN(x, ...) printf("[SNG : WARN] "x"\r\n", ##__VA_ARGS__); 
+#else
+#define WARN(x, ...) 
+#endif
+
+#ifdef INFOMESSAGES
+#define INFO(x, ...) printf("[SNG : INFO] "x"\r\n", ##__VA_ARGS__); 
+#else
+#define INFO(x, ...) 
+#endif
+
+// Constructor:
+SolarNanoGrid::SolarNanoGrid(SDFileSystem* sd){
+    // Save the sd card pointer:
+    _sd = sd;
+    
+    // initialize the SNG module:
+    char * name = "/sd/config.ini";
+    FILE *fp;
+
+    spiSD();
+    mkdir("/sd/binData",777);
+    mkdir("/sd/data",777);
+    mkdir("/sd/compress",777);
+
+    //Configuration
+
+    INFO("Reading config file...");
+
+    fp = fopen(name, "r");
+    if (fp == NULL) {
+        ERR("Config file cannot be read");
+        return;
+    }
+    if (fscanf (fp,"%c %*c %*s",&role )!=1) WARN("Config: cannot read role");
+    if (fscanf (fp,"%d %*c %*s",&sdVersion )!=1) WARN("Config: cannot read version");
+    if (fscanf (fp,"%x %*c %*s",&id )!=1) WARN("Config: cannot read id");
+    id = 1;
+
+    INFO("  Type:%c, Version %u, ID %d",role,sdVersion,id);
+
+
+    switch (role) {
+        case('B'):
+        case('b'):
+            SongBat = new battery(nrf1);
+            SongBat.initialiseBattery(fp);
+            break;
+        case('L'):
+        case('l'):
+            initialiseLocker(fp);
+            break;
+    }
+    
+    return;
+}
+
+void SolarNanoGrid::loop(void)
+{
+    switch (role) {
+        case('B'): { // Battery
+            loopBattery();
+            break;
+        }
+        case('M'): { // Master
+            // loopMaster();
+            break;
+        }
+        case('L'): { // Locker
+            loopLocker();
+            break;
+        }
+    }
+}
+