Andrew Boyson / Mbed 2 deprecated heating

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers settings.c Source File

settings.c

00001 #include <stdbool.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 
00005 #include     "clkgov.h"
00006 #include       "fram.h"
00007 #include        "log.h"
00008 #include        "net.h"
00009 #include       "link.h"
00010 #include    "dnsname.h"
00011 #include   "dnsquery.h"
00012 #include   "dnsreply.h"
00013 #include  "dnsserver.h"
00014 #include   "dnslabel.h"
00015 #include        "ntp.h"
00016 #include       "dhcp.h"
00017 #include         "ns.h"
00018 #include         "nr.h"
00019 #include  "ntpclient.h"
00020 #include     "1-wire.h"
00021 #include      "echo4.h"
00022 #include      "echo6.h"
00023 #include      "dest6.h"
00024 #include         "ra.h"
00025 #include         "rs.h"
00026 #include        "ar4.h"
00027 #include        "ar6.h"
00028 #include        "arp.h"
00029 #include        "ip4.h"
00030 #include        "ip6.h"
00031 #include        "udp.h"
00032 #include        "tcp.h"
00033 #include        "web.h"
00034 #include       "tftp.h"
00035 #include        "dns.h"
00036 #include        "led.h"
00037 #include    "program.h"
00038 #include        "wiz.h"
00039 #include   "wiz-list.h"
00040 #include  "wiz-sched.h"
00041 
00042 static int iClkGovSlewDivisor      ;
00043 static int iClkGovSlewMaxMs        ;
00044 static int iClkGovPpbDivisor       ;
00045 static int iClkGovPpbChangeMax     ;
00046 static int iClkGovSyncedLimitNs    ;
00047 static int iClkGovSyncedLimitPpb   ;
00048 static int iClkGovSyncedHysterisNs ;
00049 static int iClkGovSyncedHysterisPpb;
00050 static int iClkGovMaxOffsetSecs    ;
00051 static int iClkGov;
00052 
00053 static int iOneWire;
00054 
00055 static int iDnsSendRequestsViaIp4 ;
00056 static int iNtpSendRequestsViaIp4 ;
00057 static int iTftpSendRequestsViaIp4;
00058 
00059 static int iNetHost;
00060 static int iLogUart;
00061 static int iNetStack;
00062 static int iNetNewLine;
00063 static int iNetVerbose;
00064 static int iLink;
00065 static int iDnsName;
00066 static int iDnsQuery;
00067 static int iDnsReply;
00068 static int iDnsServer;
00069 static int iNtp;
00070 static int iDhcp;
00071 static int iNsRecvSol;
00072 static int iNsRecvAdv;
00073 static int iNsSendSol;
00074 static int iNr4;
00075 static int iNr;
00076 static int iNtpClient;
00077 static int iEcho4;
00078 static int iEcho6;
00079 static int iDest6;
00080 static int iRa;
00081 static int iRs;
00082 static int iAr4;
00083 static int iAr6;
00084 static int iArp;
00085 static int iIp4;
00086 static int iIp6;
00087 static int iUdp;
00088 static int iTcp;
00089 static int iHttp;
00090 static int iTftp;
00091 
00092 //Values
00093 static int iValuesServerName;
00094 void SetValuesServerName(char* value) { FramWrite(iValuesServerName, DNS_MAX_LABEL_LENGTH, value); }
00095 void GetValuesServerName(char* value) { FramRead (iValuesServerName, DNS_MAX_LABEL_LENGTH, value); value[DNS_MAX_LABEL_LENGTH] = 0; }
00096 
00097 static int iValuesFileName;
00098 void SetValuesFileName(char* value) { FramWrite(iValuesFileName, DNS_MAX_LABEL_LENGTH, value); }
00099 void GetValuesFileName(char* value) { FramRead (iValuesFileName, DNS_MAX_LABEL_LENGTH, value); value[DNS_MAX_LABEL_LENGTH] = 0; }
00100 
00101 static int iValuesWriteSize;
00102 void SetValuesWriteSize(int* pValue) { FramWrite(iValuesWriteSize, 4, pValue); }
00103 void GetValuesWriteSize(int* pValue) { FramRead (iValuesWriteSize, 4, pValue); }
00104 
00105 static int iValuesReadInterval;
00106 void SetValuesReadInterval(int* pValue) { FramWrite(iValuesReadInterval, 4, pValue); }
00107 void GetValuesReadInterval(int* pValue) { FramRead (iValuesReadInterval, 4, pValue); }
00108 
00109 static int iValuesStartTime;
00110 void SetValuesStartTime(int64_t* pValue) { FramWrite(iValuesStartTime, 8, pValue); }
00111 void GetValuesStartTime(int64_t* pValue) { FramRead (iValuesStartTime, 8, pValue); }
00112 
00113 static int iValuesCount;
00114 void SetValuesCount(int* pValue) { FramWrite(iValuesCount, 4, pValue); }
00115 void GetValuesCount(int* pValue) { FramRead (iValuesCount, 4, pValue); }
00116 
00117 static int iValuesData;
00118 void GetValuesData(int index, char* pValue) { FramRead (iValuesData +     index, 1, pValue); }
00119 void SetValuesData(int count, void* pValue) { FramWrite(iValuesData + 8 * count, 8, pValue); }
00120 
00121 //Wiz settings
00122 static int iWizTrace;
00123 static int iWizMacs           [WIZ_LIST_MAX_ITEMS];
00124 static int iWizNames          [WIZ_LIST_MAX_ITEMS];
00125 static int iWizRooms          [WIZ_LIST_MAX_ITEMS];
00126 static int iWizSchedNames     [WIZ_SCHED_MAX_ITEMS];
00127 static int iWizSchedOnDatums  [WIZ_SCHED_MAX_ITEMS];
00128 static int iWizSchedOnMinutes [WIZ_SCHED_MAX_ITEMS];
00129 static int iWizSchedOffDatums [WIZ_SCHED_MAX_ITEMS];
00130 static int iWizSchedOffMinutes[WIZ_SCHED_MAX_ITEMS];
00131 
00132 void ChgTraceWiz                           () { WizTrace = !WizTrace; FramWrite(iWizTrace,                       1, &WizTrace); }
00133 void SetWizListMac        (int i,    char* pMac    ) { FramWrite(iWizMacs           [i],                    6, pMac    ); }
00134 void GetWizListMac        (int i,    char* pMac    ) { FramRead (iWizMacs           [i],                    6, pMac    ); }
00135 void SetWizListName       (int i,    char* pText   ) { FramWrite(iWizNames          [i], WIZ_LIST_NAME_LENGTH, pText   ); }
00136 void GetWizListName       (int i,    char* pText   ) { FramRead (iWizNames          [i], WIZ_LIST_NAME_LENGTH, pText   ); }
00137 void SetWizListRoom       (int i,    char* pText   ) { FramWrite(iWizRooms          [i], WIZ_LIST_NAME_LENGTH, pText   ); }
00138 void GetWizListRoom       (int i,    char* pText   ) { FramRead (iWizRooms          [i], WIZ_LIST_NAME_LENGTH, pText   ); }
00139 void SetWizSchedName      (int i,    char* pText   ) { FramWrite(iWizSchedNames     [i], WIZ_LIST_NAME_LENGTH, pText   ); }
00140 void GetWizSchedName      (int i,    char* pText   ) { FramRead (iWizSchedNames     [i], WIZ_LIST_NAME_LENGTH, pText   ); }
00141 void SetWizSchedOnDatum   (int i,    char* pDatum  ) { FramWrite(iWizSchedOnDatums  [i],                    1, pDatum  ); }
00142 void GetWizSchedOnDatum   (int i,    char* pDatum  ) { FramRead (iWizSchedOnDatums  [i],                    1, pDatum  ); }
00143 void SetWizSchedOnMinutes (int i, int16_t* pMinutes) { FramWrite(iWizSchedOnMinutes [i],                    2, pMinutes); }
00144 void GetWizSchedOnMinutes (int i, int16_t* pMinutes) { FramRead (iWizSchedOnMinutes [i],                    2, pMinutes); }
00145 void SetWizSchedOffDatum  (int i,    char* pDatum  ) { FramWrite(iWizSchedOffDatums [i],                    1, pDatum  ); }
00146 void GetWizSchedOffDatum  (int i,    char* pDatum  ) { FramRead (iWizSchedOffDatums [i],                    1, pDatum  ); }
00147 void SetWizSchedOffMinutes(int i, int16_t* pMinutes) { FramWrite(iWizSchedOffMinutes[i],                    2, pMinutes); }
00148 void GetWizSchedOffMinutes(int i, int16_t* pMinutes) { FramRead (iWizSchedOffMinutes[i],                    2, pMinutes); }
00149 
00150 //Clock settings
00151 void SetClockSlewDivisor      (int  value) { ClkGovSlewDivisor       = value; FramWrite(iClkGovSlewDivisor,       4, &ClkGovSlewDivisor      ); }
00152 void SetClockSlewMaxMs        (int  value) { ClkGovSlewChangeMaxMs   = value; FramWrite(iClkGovSlewMaxMs,         4, &ClkGovSlewChangeMaxMs  ); }
00153 void SetClockPpbDivisor       (int  value) { ClkGovFreqDivisor       = value; FramWrite(iClkGovPpbDivisor,        4, &ClkGovFreqDivisor      ); }
00154 void SetClockPpbChangeMax     (int  value) { ClkGovFreqChangeMaxPpb  = value; FramWrite(iClkGovPpbChangeMax,      4, &ClkGovFreqChangeMaxPpb ); }
00155 void SetClockSyncedLimitNs    (int  value) { ClkGovSlewSyncedLimNs   = value; FramWrite(iClkGovSyncedLimitNs,     4, &ClkGovSlewSyncedLimNs  ); }
00156 void SetClockSyncedLimitPpb   (int  value) { ClkGovFreqSyncedLimPpb  = value; FramWrite(iClkGovSyncedLimitPpb,    4, &ClkGovFreqSyncedLimPpb ); }
00157 void SetClockSyncedHysterisNs (int  value) { ClkGovSlewSyncedHysNs   = value; FramWrite(iClkGovSyncedHysterisNs,  4, &ClkGovSlewSyncedHysNs  ); }
00158 void SetClockSyncedHysterisPpb(int  value) { ClkGovFreqSyncedHysPpb  = value; FramWrite(iClkGovSyncedHysterisPpb, 4, &ClkGovFreqSyncedHysPpb ); }
00159 void SetClockMaxOffsetSecs    (int  value) { ClkGovSlewOffsetMaxSecs = value; FramWrite(iClkGovMaxOffsetSecs,     4, &ClkGovSlewOffsetMaxSecs); }
00160 void ChgTraceSync             ()           { ClkGovTrace = !ClkGovTrace     ; FramWrite(iClkGov,                  1, &ClkGovTrace            ); }
00161 
00162 //Log settings
00163 void ChgLogUart               () {       LogUart         =       !LogUart;         FramWrite(iLogUart,    1,        &LogUart       ); }
00164 
00165 //Heating settings
00166 void ChgTraceOneWire          () {   OneWireTrace        =   !OneWireTrace       ; FramWrite(iOneWire,    1,   &OneWireTrace       ); }
00167 
00168 //Net settings
00169 void ChgDnsSendRequestsViaIp4    () {            DnsSendRequestsViaIp4 =             !DnsSendRequestsViaIp4; FramWrite( iDnsSendRequestsViaIp4,    1,             &DnsSendRequestsViaIp4); }
00170 void ChgNtpSendRequestsViaIp4    () { NtpClientQuerySendRequestsViaIp4 =  !NtpClientQuerySendRequestsViaIp4; FramWrite( iNtpSendRequestsViaIp4,    1,  &NtpClientQuerySendRequestsViaIp4); }
00171 void ChgTftpSendRequestsViaIp4   () {           TftpSendRequestsViaIp4 =            !TftpSendRequestsViaIp4; FramWrite(iTftpSendRequestsViaIp4,    1,            &TftpSendRequestsViaIp4); }
00172 
00173 void SetTraceNetHost (char* text)
00174 {
00175     int value = strtol(text, NULL, 16);
00176     NetTraceHost[1] =  value       & 0xFF;
00177     NetTraceHost[0] = (value >> 8) & 0xFF;
00178     FramWrite(iNetHost, 2, NetTraceHost);
00179 }
00180 void ChgTraceNetStack  () {       NetTraceStack   =       !NetTraceStack;   FramWrite(iNetStack,   1,        &NetTraceStack ); }
00181 void ChgTraceNetNewLine() {       NetTraceNewLine =       !NetTraceNewLine; FramWrite(iNetNewLine, 1,       &NetTraceNewLine); }
00182 void ChgTraceNetVerbose() {       NetTraceVerbose =       !NetTraceVerbose; FramWrite(iNetVerbose, 1,       &NetTraceVerbose); }
00183 void ChgTraceLink      () {      LinkTrace        =      !LinkTrace;        FramWrite(iLink,       1,      &LinkTrace       ); }
00184 void ChgTraceDnsName   () {   DnsNameTrace        =   !DnsNameTrace;        FramWrite(iDnsName,    1,   &DnsNameTrace       ); }
00185 void ChgTraceDnsQuery  () {  DnsQueryTrace        =  !DnsQueryTrace;        FramWrite(iDnsQuery,   1,  &DnsQueryTrace       ); }
00186 void ChgTraceDnsReply  () {  DnsReplyTrace        =  !DnsReplyTrace;        FramWrite(iDnsReply,   1,  &DnsReplyTrace       ); }
00187 void ChgTraceDnsServer () { DnsServerTrace        = !DnsServerTrace;        FramWrite(iDnsServer,  1, &DnsServerTrace       ); }
00188 void ChgTraceNtp       () {       NtpTrace        =       !NtpTrace;        FramWrite(iNtp,        1,       &NtpTrace       ); }
00189 void ChgTraceDhcp      () {      DhcpTrace        =      !DhcpTrace;        FramWrite(iDhcp,       1,      &DhcpTrace       ); }
00190 void ChgTraceNsRecvSol () {        NsTraceRecvSol =        !NsTraceRecvSol; FramWrite(iNsRecvSol,  1,        &NsTraceRecvSol); }
00191 void ChgTraceNsRecvAdv () {        NsTraceRecvAdv =        !NsTraceRecvAdv; FramWrite(iNsRecvAdv,  1,        &NsTraceRecvAdv); }
00192 void ChgTraceNsSendSol () {        NsTraceSendSol =        !NsTraceSendSol; FramWrite(iNsSendSol,  1,        &NsTraceSendSol); }
00193 void ChgTraceNr4       () {       Nr4Trace        =       !Nr4Trace       ; FramWrite(iNr4,        1,       &Nr4Trace       ); }
00194 void ChgTraceNr        () {        NrTrace        =        !NrTrace       ; FramWrite(iNr,         1,        &NrTrace       ); }
00195 void ChgTraceNtpClient () { NtpClientTrace        = !NtpClientTrace       ; FramWrite(iNtpClient,  1, &NtpClientTrace       ); }
00196 void ChgTraceEcho4     () {     Echo4Trace        =     !Echo4Trace       ; FramWrite(iEcho4,      1,     &Echo4Trace       ); }
00197 void ChgTraceEcho6     () {     Echo6Trace        =     !Echo6Trace       ; FramWrite(iEcho6,      1,     &Echo6Trace       ); }
00198 void ChgTraceDest6     () {     Dest6Trace        =     !Dest6Trace       ; FramWrite(iDest6,      1,     &Dest6Trace       ); }
00199 void ChgTraceRa        () {        RaTrace        =        !RaTrace       ; FramWrite(iRa,         1,        &RaTrace       ); }
00200 void ChgTraceRs        () {        RsTrace        =        !RsTrace       ; FramWrite(iRs,         1,        &RsTrace       ); }
00201 void ChgTraceAr4       () {       Ar4Trace        =       !Ar4Trace       ; FramWrite(iAr4,        1,       &Ar4Trace       ); }
00202 void ChgTraceAr6       () {       Ar6Trace        =       !Ar6Trace       ; FramWrite(iAr6,        1,       &Ar6Trace       ); }
00203 void ChgTraceArp       () {       ArpTrace        =       !ArpTrace       ; FramWrite(iArp,        1,       &ArpTrace       ); }
00204 void ChgTraceIp4       () {       Ip4Trace        =       !Ip4Trace       ; FramWrite(iIp4,        1,       &Ip4Trace       ); }
00205 void ChgTraceIp6       () {       Ip6Trace        =       !Ip6Trace       ; FramWrite(iIp6,        1,       &Ip6Trace       ); }
00206 void ChgTraceUdp       () {       UdpTrace        =       !UdpTrace       ; FramWrite(iUdp,        1,       &UdpTrace       ); }
00207 void ChgTraceTcp       () {       TcpTrace        =       !TcpTrace       ; FramWrite(iTcp,        1,       &TcpTrace       ); }
00208 void ChgTraceHttp      () {       WebTrace        =       !WebTrace       ; FramWrite(iHttp,       1,       &WebTrace       ); }
00209 void ChgTraceTftp      () {      TftpTrace        =      !TftpTrace       ; FramWrite(iTftp,       1,      &TftpTrace       ); }
00210 
00211 static int iServerName;
00212 static int iInitialInterval;
00213 static int iNormalInterval;
00214 static int iRetryInterval;
00215 static int iOffsetMs;
00216 static int iMaxDelayMs;
00217 
00218 void SetNtpClientServerName      ( char* value) { DnsLabelCopy(NtpClientQueryServerName,      value); FramWrite(iServerName,      DNS_MAX_LABEL_LENGTH,  NtpClientQueryServerName      ); }
00219 void SetNtpClientInitialInterval ( int   value) { NtpClientQueryInitialInterval    = (int32_t)value ; FramWrite(iInitialInterval,                    4, &NtpClientQueryInitialInterval ); }
00220 void SetNtpClientNormalInterval  ( int   value) { NtpClientQueryNormalInterval     = (int32_t)value ; FramWrite(iNormalInterval,                     4, &NtpClientQueryNormalInterval  ); }
00221 void SetNtpClientRetryInterval   ( int   value) { NtpClientQueryRetryInterval      = (int32_t)value ; FramWrite(iRetryInterval,                      4, &NtpClientQueryRetryInterval   ); }
00222 void SetNtpClientOffsetMs        ( int   value) { NtpClientReplyOffsetMs           = (int32_t)value ; FramWrite(iOffsetMs,                           4, &NtpClientReplyOffsetMs        ); }
00223 void SetNtpClientMaxDelayMs      ( int   value) { NtpClientReplyMaxDelayMs         = (int32_t)value ; FramWrite(iMaxDelayMs,                         4, &NtpClientReplyMaxDelayMs      ); }
00224 
00225 static int iTankRom;
00226 static int iOutputRom;
00227 static int iReturnRom;
00228 static int iFullSpeedSecs;
00229 static int iTankSetPoint;
00230 static int iTankHysteresis;
00231 static int iRunOnDeltaT;
00232 static int iRunOnTime2s;
00233 static int iPumpSpeedCalling;
00234 static int iRampDownTime;
00235 static int iBoilerTarget;
00236 static int iMinSpeed;
00237 static int iMidSpeedPwm;
00238 static int iFullSpeedDeltaT;
00239 
00240 static int iWinter;
00241 static int iHallRom;
00242 static int iOverrideCancelHour;
00243 static int iOverrideCancelMinute;
00244 static int iHotWaterProtectTemp;
00245 static int iHotWaterProtectOn;
00246 static int iNightTemperature;
00247 static int iFrostTemperature;
00248 
00249 static int iProgramDay;
00250 static int iPrograms;
00251 static int iProgramNewDayHour;
00252 
00253 static int iHotWaterRom;
00254 
00255 void SetTankRom               (char*     value) { FramWrite(iTankRom,              8,  value); }
00256 void GetTankRom               (char*     value) { FramRead (iTankRom,              8,  value); }
00257 void SetOutputRom             (char*     value) { FramWrite(iOutputRom,            8,  value); }
00258 void GetOutputRom             (char*     value) { FramRead (iOutputRom,            8,  value); }
00259 void SetReturnRom             (char*     value) { FramWrite(iReturnRom,            8,  value); }
00260 void GetReturnRom             (char*     value) { FramRead (iReturnRom,            8,  value); }
00261 void SetBoilerFullSpeedSecs   (int8_t*  pValue) { FramWrite(iFullSpeedSecs,        1, pValue); }
00262 void GetBoilerFullSpeedSecs   (int8_t*  pValue) { FramRead (iFullSpeedSecs,        1, pValue); }
00263 void SetTankSetPoint          (int8_t*  pValue) { FramWrite(iTankSetPoint,         1, pValue); }
00264 void GetTankSetPoint          (int8_t*  pValue) { FramRead (iTankSetPoint,         1, pValue); }
00265 void SetTankHysteresis        (int16_t* pValue) { FramWrite(iTankHysteresis,       2, pValue); }
00266 void GetTankHysteresis        (int16_t* pValue) { FramRead (iTankHysteresis,       2, pValue); }
00267 void SetBoilerRunOnDeltaT     (int16_t* pValue) { FramWrite(iRunOnDeltaT,          2, pValue); }
00268 void GetBoilerRunOnDeltaT     (int16_t* pValue) { FramRead (iRunOnDeltaT,          2, pValue); }
00269 void SetBoilerRunOnTime2s     (uint8_t* pValue) { FramWrite(iRunOnTime2s,          1, pValue); }
00270 void GetBoilerRunOnTime2s     (uint8_t* pValue) { FramRead (iRunOnTime2s,          1, pValue); }
00271 void SetBoilerPumpSpeedCalling(int8_t*  pValue) { FramWrite(iPumpSpeedCalling,     1, pValue); }
00272 void GetBoilerPumpSpeedCalling(int8_t*  pValue) { FramRead (iPumpSpeedCalling,     1, pValue); }
00273 void SetBoilerRampDownTime    (int8_t*  pValue) { FramWrite(iRampDownTime,         1, pValue); }
00274 void GetBoilerRampDownTime    (int8_t*  pValue) { FramRead (iRampDownTime,         1, pValue); }
00275 void SetBoilerTarget          (int8_t*  pValue) { FramWrite(iBoilerTarget,         1, pValue); }
00276 void GetBoilerTarget          (int8_t*  pValue) { FramRead (iBoilerTarget,         1, pValue); }
00277 void SetBoilerMinSpeed        (int8_t*  pValue) { FramWrite(iMinSpeed,             1, pValue); }
00278 void GetBoilerMinSpeed        (int8_t*  pValue) { FramRead (iMinSpeed,             1, pValue); }
00279 void SetBoilerMidSpeedPwm     (int8_t*  pValue) { FramWrite(iMidSpeedPwm,          1, pValue); }
00280 void GetBoilerMidSpeedPwm     (int8_t*  pValue) { FramRead (iMidSpeedPwm,          1, pValue); }
00281 void SetBoilerFullSpeedDeltaT (int16_t* pValue) { FramWrite(iFullSpeedDeltaT,      2, pValue); }
00282 void GetBoilerFullSpeedDeltaT (int16_t* pValue) { FramRead (iFullSpeedDeltaT,      2, pValue); }
00283 void SetRadiatorWinter        (char*    pValue) { FramWrite(iWinter,               1, pValue); }
00284 void GetRadiatorWinter        (char*    pValue) { FramRead (iWinter,               1, pValue); }
00285 void SetHallRom               (char*     value) { FramWrite(iHallRom,              8,  value); }
00286 void GetHallRom               (char*     value) { FramRead (iHallRom,              8,  value); }
00287 void SetOverrideCancelHour    (uint8_t* pValue) { FramWrite(iOverrideCancelHour,   1, pValue); }
00288 void GetOverrideCancelHour    (uint8_t* pValue) { FramRead (iOverrideCancelHour,   1, pValue); }
00289 void SetOverrideCancelMinute  (uint8_t* pValue) { FramWrite(iOverrideCancelMinute, 1, pValue); }
00290 void GetOverrideCancelMinute  (uint8_t* pValue) { FramRead (iOverrideCancelMinute, 1, pValue); }
00291 void SetHotWaterProtectTemp   (int8_t*  pValue) { FramWrite(iHotWaterProtectTemp,  1, pValue); }
00292 void GetHotWaterProtectTemp   (int8_t*  pValue) { FramRead (iHotWaterProtectTemp,  1, pValue); }
00293 void SetHotWaterProtectOn     (char*    pValue) { FramWrite(iHotWaterProtectOn,    1, pValue); }
00294 void GetHotWaterProtectOn     (char*    pValue) { FramRead (iHotWaterProtectOn,    1, pValue); }
00295 void SetNightTemperature      (int16_t* pValue) { FramWrite(iNightTemperature,     2, pValue); }
00296 void GetNightTemperature      (int16_t* pValue) { FramRead (iNightTemperature,     2, pValue); }
00297 void SetFrostTemperature      (int16_t* pValue) { FramWrite(iFrostTemperature,     2, pValue); }
00298 void GetFrostTemperature      (int16_t* pValue) { FramRead (iFrostTemperature,     2, pValue); }
00299 
00300 void SetProgramDay            (int index, char*    pValue) { FramWrite(iProgramDay + index,   1, pValue); }
00301 void GetProgramDay            (int index, char*    pValue) { FramRead (iProgramDay + index,   1, pValue); }
00302 void SetProgram               (int index, int16_t* pValue) { FramWrite(iPrograms + index * 8, 8, pValue); }
00303 void GetProgram               (int index, int16_t* pValue) { FramRead (iPrograms + index * 8, 8, pValue); }
00304 void SetProgramNewDayHour     (char*    pValue) { FramWrite(iProgramNewDayHour,    1, pValue); }
00305 void GetProgramNewDayHour     (char*    pValue) { FramRead (iProgramNewDayHour,    1, pValue); }
00306 
00307 void SetHotWaterRom           (char*     value) { FramWrite(iHotWaterRom,          8,  value); }
00308 void GetHotWaterRom           (char*     value) { FramRead (iHotWaterRom,          8,  value); }
00309 
00310 int SettingsInit()
00311 {
00312     int address;
00313     char b;
00314     int8_t  def1;
00315     int16_t def2;
00316     int32_t def4;
00317     int64_t def8;
00318     
00319     if (FramInit()) return -1; //Reserves 1 FRAM byte to detect if empty
00320     FramAllocate(4);           //Reserves 4 FRAM bytes where the watchdog used to hold the last program position
00321     
00322     def4 =    0; address = FramLoad( DNS_MAX_LABEL_LENGTH+1,  NtpClientQueryServerName,      NULL ); if (address < 0) return -1; iServerName      = address;
00323     def4 =    1; address = FramLoad(                      4, &NtpClientQueryInitialInterval, &def4); if (address < 0) return -1; iInitialInterval = address;
00324     def4 =  600; address = FramLoad(                      4, &NtpClientQueryNormalInterval,  &def4); if (address < 0) return -1; iNormalInterval  = address;
00325     def4 =   60; address = FramLoad(                      4, &NtpClientQueryRetryInterval,   &def4); if (address < 0) return -1; iRetryInterval   = address; 
00326     def4 =    0; address = FramLoad(                      4, &NtpClientReplyOffsetMs,        &def4); if (address < 0) return -1; iOffsetMs        = address; 
00327     def4 =   50; address = FramLoad(                      4, &NtpClientReplyMaxDelayMs,      &def4); if (address < 0) return -1; iMaxDelayMs      = address; 
00328     
00329     //Boiler
00330     address = FramAllocate(8); if (address < 0) return -1; iTankRom              = address;
00331     address = FramAllocate(8); if (address < 0) return -1; iOutputRom            = address;
00332     address = FramAllocate(8); if (address < 0) return -1; iReturnRom            = address;
00333     address = FramAllocate(1); if (address < 0) return -1; iFullSpeedSecs        = address;
00334     address = FramAllocate(1); if (address < 0) return -1; iTankSetPoint         = address;
00335     address = FramAllocate(2); if (address < 0) return -1; iTankHysteresis       = address;
00336     address = FramAllocate(2); if (address < 0) return -1; iRunOnDeltaT          = address;
00337     address = FramAllocate(1); if (address < 0) return -1; iRunOnTime2s          = address;
00338     address = FramAllocate(1); if (address < 0) return -1; iPumpSpeedCalling     = address;
00339     address = FramAllocate(1); if (address < 0) return -1; iRampDownTime         = address;
00340     address = FramAllocate(1); if (address < 0) return -1; iBoilerTarget         = address;
00341     address = FramAllocate(1); if (address < 0) return -1; iMinSpeed             = address;
00342               FramAllocate(1); //Spare byte
00343     address = FramAllocate(1); if (address < 0) return -1; iMidSpeedPwm          = address;
00344               FramAllocate(1); //Spare byte
00345     address = FramAllocate(2); if (address < 0) return -1; iFullSpeedDeltaT      = address;
00346     
00347     //Radiator
00348     address = FramAllocate(1); if (address < 0) return -1; iWinter               = address; 
00349               FramAllocate(1); //Spare byte
00350     address = FramAllocate(8); if (address < 0) return -1; iHallRom              = address;
00351     address = FramAllocate(1); if (address < 0) return -1; iOverrideCancelHour   = address;
00352     address = FramAllocate(1); if (address < 0) return -1; iOverrideCancelMinute = address;
00353     address = FramAllocate(1); if (address < 0) return -1; iHotWaterProtectTemp  = address;
00354     address = FramAllocate(1); if (address < 0) return -1; iHotWaterProtectOn    = address;
00355     address = FramAllocate(2); if (address < 0) return -1; iNightTemperature     = address; 
00356     address = FramAllocate(2); if (address < 0) return -1; iFrostTemperature     = address; 
00357     address = FramAllocate(7); if (address < 0) return -1; iProgramDay           = address;
00358     
00359     int programSize = PROGRAM_COUNT * PROGRAM_TRANSITIONS_COUNT * sizeof(int16_t);
00360     address = FramAllocate(programSize); if (address < 0) return -1; iPrograms   = address; //3 x 4 x 2
00361     address = FramAllocate(1); if (address < 0) return -1; iProgramNewDayHour = address;
00362 
00363     address = FramAllocate(8); if (address < 0) return -1; iHotWaterRom          = address;
00364                  
00365     if (FramEmpty)
00366     {
00367         def1 =    100; FramWrite(iFullSpeedSecs,        1, &def1);
00368         def1 =     65; FramWrite(iTankSetPoint,         1, &def1);
00369         def2 =      3; FramWrite(iTankHysteresis,       2, &def2);
00370         def2 =   2<<4; FramWrite(iRunOnDeltaT,          2, &def2);
00371         def1 = 180>>2; FramWrite(iRunOnTime2s,          1, &def1); //3 minutes = 2 * 90 2 seconds
00372         def1 =    100; FramWrite(iPumpSpeedCalling,     1, &def1);
00373         def1 =     10; FramWrite(iRampDownTime,         1, &def1);
00374         def1 =     60; FramWrite(iBoilerTarget,         1, &def1);
00375         def1 =     50; FramWrite(iMinSpeed,             1, &def1);
00376         def1 =     50; FramWrite(iMidSpeedPwm,          1, &def1);
00377         def2 =  10<<4; FramWrite(iFullSpeedDeltaT,      2, &def2);
00378         def1 =      0; FramWrite(iWinter,               1, &def1);
00379         def1 =     23; FramWrite(iOverrideCancelHour,   1, &def1);
00380         def1 =      0; FramWrite(iOverrideCancelMinute, 1, &def1);
00381         def1 =     50; FramWrite(iHotWaterProtectTemp,  1, &def1);
00382         def1 =      0; FramWrite(iHotWaterProtectOn,    1, &def1);
00383         def2 =     15; FramWrite(iNightTemperature,     2, &def2);
00384         def2 =      8; FramWrite(iFrostTemperature,     2, &def2);
00385         def1 =      2; FramWrite(iProgramNewDayHour,    1, &def1);
00386     }
00387     
00388     def4 =       10; address = FramLoad( 4, &ClkGovSlewDivisor,       &def4);    if (address < 0) return -1; iClkGovSlewDivisor       = address;
00389     def4 =       20; address = FramLoad( 4, &ClkGovSlewChangeMaxMs,   &def4);    if (address < 0) return -1; iClkGovSlewMaxMs         = address;
00390     def4 =     1000; address = FramLoad( 4, &ClkGovFreqDivisor,       &def4);    if (address < 0) return -1; iClkGovPpbDivisor        = address;
00391     def4 = 10000000; address = FramLoad( 4, &ClkGovFreqChangeMaxPpb,  &def4);    if (address < 0) return -1; iClkGovPpbChangeMax      = address;
00392     def4 =   100000; address = FramLoad( 4, &ClkGovSlewSyncedLimNs,   &def4);    if (address < 0) return -1; iClkGovSyncedLimitNs     = address;
00393     def4 =   100000; address = FramLoad( 4, &ClkGovFreqSyncedLimPpb,  &def4);    if (address < 0) return -1; iClkGovSyncedLimitPpb    = address;
00394     def4 =    10000; address = FramLoad( 4, &ClkGovSlewSyncedHysNs,   &def4);    if (address < 0) return -1; iClkGovSyncedHysterisNs  = address;
00395     def4 =     1000; address = FramLoad( 4, &ClkGovFreqSyncedHysPpb,  &def4);    if (address < 0) return -1; iClkGovSyncedHysterisPpb = address;
00396     def4 =        3; address = FramLoad( 4, &ClkGovSlewOffsetMaxSecs, &def4);    if (address < 0) return -1; iClkGovMaxOffsetSecs     = address;
00397     address = FramLoad( 1, &b, NULL);   ClkGovTrace                     = b; if (address < 0) return -1; iClkGov      = address;
00398     address = FramLoad( 1, &b, NULL);  OneWireTrace                     = b; if (address < 0) return -1; iOneWire     = address;
00399     address = FramLoad( 1, &b, NULL);             DnsSendRequestsViaIp4 = b; if (address < 0) return -1; iDnsSendRequestsViaIp4  = address;
00400     address = FramLoad( 1, &b, NULL);  NtpClientQuerySendRequestsViaIp4 = b; if (address < 0) return -1; iNtpSendRequestsViaIp4  = address;
00401     address = FramLoad( 1, &b, NULL);            TftpSendRequestsViaIp4 = b; if (address < 0) return -1; iTftpSendRequestsViaIp4 = address;
00402     address = FramLoad( 1, &b, NULL);       LogUart          = b; if (address < 0) return -1; iLogUart     = address;
00403     address = FramLoad( 2,                  NetTraceHost, NULL) ; if (address < 0) return -1; iNetHost     = address;
00404     address = FramLoad( 1, &b, NULL);       NetTraceStack    = b; if (address < 0) return -1; iNetStack    = address;
00405     address = FramLoad( 1, &b, NULL);       NetTraceNewLine  = b; if (address < 0) return -1; iNetNewLine  = address;
00406     address = FramLoad( 1, &b, NULL);       NetTraceVerbose  = b; if (address < 0) return -1; iNetVerbose  = address;
00407     address = FramLoad( 1, &b, NULL);      LinkTrace         = b; if (address < 0) return -1; iLink        = address;
00408     address = FramLoad( 1, &b, NULL);   DnsNameTrace         = b; if (address < 0) return -1; iDnsName     = address;
00409     address = FramLoad( 1, &b, NULL);  DnsQueryTrace         = b; if (address < 0) return -1; iDnsQuery    = address;
00410     address = FramLoad( 1, &b, NULL);  DnsReplyTrace         = b; if (address < 0) return -1; iDnsReply    = address;
00411     address = FramLoad( 1, &b, NULL); DnsServerTrace         = b; if (address < 0) return -1; iDnsServer   = address;
00412     address = FramLoad( 1, &b, NULL);       NtpTrace         = b; if (address < 0) return -1; iNtp         = address;
00413     address = FramLoad( 1, &b, NULL);      DhcpTrace         = b; if (address < 0) return -1; iDhcp        = address;
00414     address = FramLoad( 1, &b, NULL);        NsTraceRecvSol  = b; if (address < 0) return -1; iNsRecvSol   = address;
00415     address = FramLoad( 1, &b, NULL);        NsTraceRecvAdv  = b; if (address < 0) return -1; iNsRecvAdv   = address;
00416     address = FramLoad( 1, &b, NULL);        NsTraceSendSol  = b; if (address < 0) return -1; iNsSendSol   = address;
00417     address = FramLoad( 1, &b, NULL);       Nr4Trace         = b; if (address < 0) return -1; iNr4         = address;
00418     address = FramLoad( 1, &b, NULL);        NrTrace         = b; if (address < 0) return -1; iNr          = address;
00419     address = FramLoad( 1, &b, NULL); NtpClientTrace         = b; if (address < 0) return -1; iNtpClient   = address;
00420     address = FramLoad( 1, &b, NULL);     Echo4Trace         = b; if (address < 0) return -1; iEcho4       = address;
00421     address = FramLoad( 1, &b, NULL);     Echo6Trace         = b; if (address < 0) return -1; iEcho6       = address;
00422     address = FramLoad( 1, &b, NULL);     Dest6Trace         = b; if (address < 0) return -1; iDest6       = address;
00423     address = FramLoad( 1, &b, NULL);        RaTrace         = b; if (address < 0) return -1; iRa          = address;
00424     address = FramLoad( 1, &b, NULL);        RsTrace         = b; if (address < 0) return -1; iRs          = address;
00425     address = FramLoad( 1, &b, NULL);       Ar4Trace         = b; if (address < 0) return -1; iAr4         = address;
00426     address = FramLoad( 1, &b, NULL);       Ar6Trace         = b; if (address < 0) return -1; iAr6         = address;
00427     address = FramLoad( 1, &b, NULL);       ArpTrace         = b; if (address < 0) return -1; iArp         = address;
00428     address = FramLoad( 1, &b, NULL);       Ip4Trace         = b; if (address < 0) return -1; iIp4         = address;
00429     address = FramLoad( 1, &b, NULL);       Ip6Trace         = b; if (address < 0) return -1; iIp6         = address;
00430     address = FramLoad( 1, &b, NULL);       UdpTrace         = b; if (address < 0) return -1; iUdp         = address;
00431     address = FramLoad( 1, &b, NULL);       TcpTrace         = b; if (address < 0) return -1; iTcp         = address;
00432     address = FramLoad( 1, &b, NULL);       WebTrace         = b; if (address < 0) return -1; iHttp        = address;
00433     address = FramLoad( 1, &b, NULL);      TftpTrace         = b; if (address < 0) return -1; iTftp        = address;
00434 
00435     address = FramAllocate(DNS_MAX_LABEL_LENGTH); if (address < 0) return -1; iValuesServerName   = address;
00436     FramAllocate(1); //Spare
00437     address = FramAllocate(DNS_MAX_LABEL_LENGTH); if (address < 0) return -1; iValuesFileName     = address;
00438     FramAllocate(1); //Spare
00439     address = FramAllocate(                   4); if (address < 0) return -1; iValuesWriteSize    = address;
00440     address = FramAllocate(                   4); if (address < 0) return -1; iValuesReadInterval = address;
00441     address = FramAllocate(                   8); if (address < 0) return -1; iValuesStartTime    = address;
00442     address = FramAllocate(                   4); if (address < 0) return -1; iValuesCount        = address;
00443     if (FramEmpty)
00444     {
00445         b    =   0; FramWrite(iValuesServerName  , 1, &b   );
00446         b    =   0; FramWrite(iValuesFileName    , 1, &b   );
00447         def4 = 100; FramWrite(iValuesWriteSize   , 4, &def4);
00448         def4 =  15; FramWrite(iValuesReadInterval, 4, &def4);
00449         def8 =   0; FramWrite(iValuesStartTime   , 8, &def8);
00450         def4 =   0; FramWrite(iValuesCount       , 4, &def4);
00451     }
00452     address = FramLoad( 1, &b, NULL);       WizTrace         = b; if (address < 0) return -1; iWizTrace    = address;
00453     
00454     for (int i = 0; i < WIZ_LIST_MAX_ITEMS; i++)
00455     {
00456         address = FramAllocate(                   6); if (address < 0) return -1; iWizMacs [i] = address;
00457         address = FramAllocate(WIZ_LIST_NAME_LENGTH); if (address < 0) return -1; iWizNames[i] = address;
00458         address = FramAllocate(WIZ_LIST_NAME_LENGTH); if (address < 0) return -1; iWizRooms[i] = address;
00459     }
00460     for (int i = 0; i < WIZ_SCHED_MAX_ITEMS; i++)
00461     {
00462         address = FramAllocate(WIZ_LIST_NAME_LENGTH); if (address < 0) return -1; iWizSchedNames     [i] = address;
00463         address = FramAllocate(                   1); if (address < 0) return -1; iWizSchedOnDatums  [i] = address;
00464         address = FramAllocate(                   2); if (address < 0) return -1; iWizSchedOnMinutes [i] = address;
00465         address = FramAllocate(                   1); if (address < 0) return -1; iWizSchedOffDatums [i] = address;
00466         address = FramAllocate(                   2); if (address < 0) return -1; iWizSchedOffMinutes[i] = address;
00467     }
00468     
00469     iValuesData = FramUsed;
00470     
00471     return 0;
00472     
00473 }