-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDNOCR_Config.h
71 lines (57 loc) · 2.7 KB
/
DNOCR_Config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// DNOCR_Config.h
//
// Created by Simon Hewitt on 08/01/2015.
// Copyright (c) 2015 Simon Hewitt. All rights reserved.
//
// Utility classes for object serialisation/deserialisation, and managing the config files in LinkIt flash memory
// Flash is non-volatile, so it is necessary to save and reload the configuration data over a power cycle.
//
#ifndef __DNOCR_Config__
#define __DNOCR_Config__
#include <stdio.h>
#include "WHD_Util.h"
#include "LFlash.h"
#include "DNOCR_Rmac.h"
class DNOCR_Config
{
// This class manages the config files
// config files are stored in flash memory, a current and a single backup file, see CONFIG defines
// Files are ASCII name:value pairs, one per line, Windows CR LF line-ending
// Note the LFlash class is pretty basic, not even rename, and all bhyte-by-byte read/write
// so much of this class just delivers line read/write, rename etc
// Every class that needs save/restore must contain a saveClass and restoreClass method like:
// which must write:
// class:className
// elementname:<data>
// classEnd:className
//
// The save and restore is implemented from top level functions that marshall the number and order of classes written
// will work out version control later!
public:
DNOCR_Config (); // constructor
void startSave(); // creates backup, opens new file, writes header
int writeSaveLine (const char *line);
int writeSaveString (const char *line);
// convenience methods to write the Name Value Pair eg writeNVP ("SiteID", 99);
int writeNVP (const char * name, const char *v);
int writeNVP (const char * name, const long v); // NOTE to save an int, cast to (long)
int writeNVP (const char * name, const float v);
int writeNVP (const char * name, const bool v);
int writeNVP (const char * name, ardTime &dt);
int closeSave();
int startRestoreConfig();
bool readNVPCheck (const char *name, const char *value); // returns error if file NVP does not match name:value
bool readNVPString (const char *name, char *val, int valLength); // returns the value as a string
bool readNVPInt (const char *name, int *val); // returns the value as a int
bool readNVPLong (const char *name, long *val); // returns the value as a long
bool readNVPBool (const char *name, bool *val); // bool
bool readNVPDateTime (const char * name, ardTime &dt);
int closeRecover();
private:
static void renameFile (const char *newFile, const char * oldFile); // actually copies byte by byte
static void makeBackup(); // calls renameFile() to move .dat to .bck
LFile *saveFile;
LFile *loadFile;
};
#endif /* defined(__DNOCR_Config__) */