Central Heating controller using the real time clock, PHY module for internet, 1-wire interface for temperature sensors, a system log and a configuration file

Dependencies:   net 1-wire lpc1768 crypto clock web fram log

/media/uploads/andrewboyson/heating.sch

/media/uploads/andrewboyson/heating.brd

/media/uploads/andrewboyson/eagle.epf

Revision:
106:41ed3ea0bbba
Parent:
105:1899f7ed17ec
--- a/heating/values.c	Tue Feb 23 20:35:07 2021 +0000
+++ b/heating/values.c	Fri Apr 23 08:36:42 2021 +0000
@@ -4,7 +4,7 @@
 
 #include "tftp.h"
 #include "dnslabel.h"
-#include "fram.h"
+//#include "fram.h"
 #include "clk.h"
 #include "clktime.h"
 #include "mstimer.h"
@@ -15,44 +15,42 @@
 #include "hot-water.h"
 #include "log.h"
 #include "net.h"
+#include "settings.h"
 
 bool ValuesTrace = false;
 
-static char    serverName[DNS_MAX_LABEL_LENGTH+1]; static int iServerName;
-static char      fileName[DNS_MAX_LABEL_LENGTH+1]; static int iFileName;
-static int32_t writeSize;                          static int iWriteSize;
-static int32_t readInterval;                       static int iReadInterval;
-static int64_t startTime;                          static int iStartTime;
-static int32_t count;                              static int iCount;
-                                                   static int iData;
+static char    serverName[DNS_MAX_LABEL_LENGTH+1];
+static char    fileName  [DNS_MAX_LABEL_LENGTH+1];
+static int32_t writeSize;
+static int32_t readInterval;
+static int64_t startTime;
+static int32_t count;
 
 char*   ValuesGetServerName   (              ) { return         serverName;                    }
-char*   ValuesGetFileName     (              ) { return           fileName;                    }
-int     ValuesGetWriteSize    (              ) { return (int)    writeSize;                    }
-int     ValuesGetReadInterval (              ) { return (int)     readInterval;                }
+char*   ValuesGetFileName     (              ) { return         fileName;                      }
+int     ValuesGetWriteSize    (              ) { return (int)   writeSize;                     }
+int     ValuesGetReadInterval (              ) { return (int)   readInterval;                  }
 void    ValuesGetStartTm      (struct tm* ptm) { ClkTimeToTmUtc(startTime, ptm);               }
 int64_t ValuesGetStartTime    (              ) { return startTime >> CLK_TIME_ONE_SECOND_SHIFT;}
-int     ValuesGetCount        (              ) { return (int)        count;                    }
+int     ValuesGetCount        (              ) { return (int)   count;                         }
 
-void ValuesSetServerName    (char*   value) { DnsLabelCopy(serverName, value); FramWrite(iServerName  , DNS_MAX_LABEL_LENGTH,  serverName   ); }
-void ValuesSetFileName      (char*   value) { DnsLabelCopy(  fileName, value); FramWrite(iFileName    , DNS_MAX_LABEL_LENGTH,    fileName   ); }
-void ValuesSetWriteSize     (int     value) { writeSize     =          value ; FramWrite(iWriteSize   ,                    4, &writeSize    ); }
-void ValuesSetReadInterval  (int     value) { readInterval  =          value ; FramWrite(iReadInterval,                    4, &readInterval ); }
-static void    setStartTime (int64_t value) { startTime     =          value ; FramWrite(iStartTime   ,                    8, &startTime    ); }
-static void    setCount     (int     value) { count         =          value ; FramWrite(iCount       ,                    4, &count        ); }
+void ValuesSetServerName    (char*   value) { DnsLabelCopy(serverName, value); SetValuesServerName  ( value); }
+void ValuesSetFileName      (char*   value) { DnsLabelCopy(  fileName, value); SetValuesFileName    ( value); }
+void ValuesSetWriteSize     (int     value) { writeSize     =          value ; SetValuesWriteSize   (&value); }
+void ValuesSetReadInterval  (int     value) { readInterval  =          value ; SetValuesReadInterval(&value); }
+static void    setStartTime (int64_t value) { startTime     =          value ; SetValuesStartTime   (&value); }
+static void    setCount     (int     value) { count         =          value ; SetValuesCount       (&value); }
 
 static int readValuesFromFram()
 {
     int address;
     int32_t def4;
-    
-                 address = FramLoad( DNS_MAX_LABEL_LENGTH+1,  serverName  , NULL ); if (address < 0) return -1; iServerName   = address;
-                 address = FramLoad( DNS_MAX_LABEL_LENGTH+1,    fileName  , NULL ); if (address < 0) return -1; iFileName     = address;
-    def4 =  100; address = FramLoad(                      4, &writeSize   , &def4); if (address < 0) return -1; iWriteSize    = address;
-    def4 =   15; address = FramLoad(                      4, &readInterval, &def4); if (address < 0) return -1; iReadInterval = address;
-                 address = FramLoad(                      8, &startTime   , NULL ); if (address < 0) return -1; iStartTime    = address;
-                 address = FramLoad(                      4, &count       , NULL ); if (address < 0) return -1; iCount        = address;
-                 address = FramAllocate(                  1                      ); if (address < 0) return -1; iData         = address;
+    GetValuesServerName  (   serverName);
+    GetValuesFileName    (     fileName);
+    GetValuesWriteSize   (   &writeSize);
+    GetValuesReadInterval(&readInterval);
+    GetValuesStartTime   (   &startTime);
+    GetValuesCount       (       &count);
     return 0;
 }
 
@@ -64,13 +62,13 @@
 static int nextByteOfWriteStream()
 {
     int byteAfterData = count * 8;
-    if (writeIndex >= byteAfterData || writeIndex + iData >= FRAM_SIZE)
+    if (writeIndex >= byteAfterData)
     {
         setCount(0);
         return -1;
     }
     char c;
-    FramRead(writeIndex + iData, 1, &c);
+    GetValuesData(writeIndex, &c);
     writeIndex++;
     return c;
 }
@@ -105,9 +103,13 @@
     record |= BoilerCall   << 1;
     record |= BoilerPump   << 2;   //AAAB BBCC CDDD EEEF
     
-    if (count == 0) setStartTime(ClkNowTai());
+    if (count <= 0)
+    {
+        count = 0;
+        setStartTime(ClkNowTai());
+    }
     
-    FramWrite(iData + 8 * count, 8, &record);
+    SetValuesData(count, &record);
     setCount(count + 1);
 }