Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: net lpc1768 crypto clock web fram log
Diff: heating/values.c
- Revision:
- 4:f38b5bb8adac
- Parent:
- 0:b843d647695c
--- a/heating/values.c Sun Apr 18 19:05:35 2021 +0000
+++ b/heating/values.c Sat Apr 24 10:59:17 2021 +0000
@@ -4,7 +4,6 @@
#include "tftp.h"
#include "dnslabel.h"
-#include "fram.h"
#include "clk.h"
#include "clktime.h"
#include "mstimer.h"
@@ -15,44 +14,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 +61,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;
}
@@ -91,6 +88,7 @@
value &= 0x0FFF;
record |= value; //0000 000A AABB BCCC
record <<= 12; //0000 AAAB BBCC C000
+ //value = BoilerGetReturnDS18B20Value();
value = BoilerGetReturnDS18B20Value();
value &= 0x0FFF;
record |= value; //0000 AAAB BBCC CDDD
@@ -104,9 +102,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);
}