For Terrance

Dependencies:   mbed

Committer:
emh203
Date:
Wed Jun 13 15:10:06 2012 +0000
Revision:
0:085749c8446f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emh203 0:085749c8446f 1 #include "System.h"
emh203 0:085749c8446f 2
emh203 0:085749c8446f 3 LocalFileSystem LocalFS("local");
emh203 0:085749c8446f 4
emh203 0:085749c8446f 5 CHAR LineBuf[128];
emh203 0:085749c8446f 6
emh203 0:085749c8446f 7 //Voltage Divider for the Li_poly Battery
emh203 0:085749c8446f 8 float R17,R15;
emh203 0:085749c8446f 9 #define R17_DEFAULT (float)(10000.0)
emh203 0:085749c8446f 10 #define R15_DEFAULT (float)(10000.0)
emh203 0:085749c8446f 11
emh203 0:085749c8446f 12 //Voltage Divider for input voltage measurement
emh203 0:085749c8446f 13 float R2,R4;
emh203 0:085749c8446f 14 #define R2_DEFAULT (float)(100000.0)
emh203 0:085749c8446f 15 #define R4_DEFAULT (float)(3300.0)
emh203 0:085749c8446f 16
emh203 0:085749c8446f 17 //Voltage Divider for current voltage measurement (to the 16-bit ADC)
emh203 0:085749c8446f 18 float R6,R7;
emh203 0:085749c8446f 19 #define R6_DEFAULT (float) (10000.0)
emh203 0:085749c8446f 20 #define R7_DEFAULT (float)(10000.0)
emh203 0:085749c8446f 21
emh203 0:085749c8446f 22 //Voltage Divider for current voltage measurement (to the 12-bit ADC)
emh203 0:085749c8446f 23 float R8,R9;
emh203 0:085749c8446f 24 #define R8_DEFAULT (float)(5100.0)
emh203 0:085749c8446f 25 #define R9_DEFAULT (float)(10000.0)
emh203 0:085749c8446f 26
emh203 0:085749c8446f 27 //value of the 2.5Voltage reference
emh203 0:085749c8446f 28 float U1_VREF;
emh203 0:085749c8446f 29 #define U1_VREF_DEFAULT (float)(2.5)
emh203 0:085749c8446f 30
emh203 0:085749c8446f 31 //value of the MBED Voltage reference
emh203 0:085749c8446f 32 float MBED_VREF;
emh203 0:085749c8446f 33 #define MBED_VREF_DEFAULT (float)(3.3)
emh203 0:085749c8446f 34
emh203 0:085749c8446f 35 //value of the input diode drop
emh203 0:085749c8446f 36 float INPUT_DIODE_DROP;
emh203 0:085749c8446f 37 #define INPUT_DIODE_DROP_DEFAULT (float)(0.601)
emh203 0:085749c8446f 38
emh203 0:085749c8446f 39
emh203 0:085749c8446f 40 //used for self current
emh203 0:085749c8446f 41 float R22;
emh203 0:085749c8446f 42 #define R22_DEFAULT 0.5
emh203 0:085749c8446f 43
emh203 0:085749c8446f 44 float R18;
emh203 0:085749c8446f 45 #define R18_DEFAULT 200
emh203 0:085749c8446f 46
emh203 0:085749c8446f 47 float R19;
emh203 0:085749c8446f 48 #define R19_DEFAULT 200
emh203 0:085749c8446f 49
emh203 0:085749c8446f 50 float R20;
emh203 0:085749c8446f 51 #define R20_DEFAULT 10000
emh203 0:085749c8446f 52
emh203 0:085749c8446f 53
emh203 0:085749c8446f 54 //Parameters for the ACS576 Current Sensor
emh203 0:085749c8446f 55
emh203 0:085749c8446f 56 float ACS576_VOFFSET;
emh203 0:085749c8446f 57 #define ACS576_VOFFSET_DEFAULT (2.5)
emh203 0:085749c8446f 58
emh203 0:085749c8446f 59 float ACS576_ISCALE;
emh203 0:085749c8446f 60 #define ACS576_ISCALE_DEFAULT (25.0)
emh203 0:085749c8446f 61
emh203 0:085749c8446f 62 float ACS576_ISCALE_ADJUST;
emh203 0:085749c8446f 63 #define ACS576_ISCALE_ADJUST_DEFAULT (1.0)
emh203 0:085749c8446f 64
emh203 0:085749c8446f 65 float ACS576_IOFFSET_TRIM;
emh203 0:085749c8446f 66 #define ACS576_IOFFSET_TRIM_DEFAULT (0.0)
emh203 0:085749c8446f 67
emh203 0:085749c8446f 68 //Used to correct the input voltage measurement
emh203 0:085749c8446f 69 float VSCALE_ADJUST;
emh203 0:085749c8446f 70 #define VSCALE_ADJUST_DEFAULT (1.0)
emh203 0:085749c8446f 71
emh203 0:085749c8446f 72 float VOFFSET_ADJUST;
emh203 0:085749c8446f 73 #define VOFFSET_ADJUST_DEFAULT (0.0)
emh203 0:085749c8446f 74
emh203 0:085749c8446f 75 //Sampling Parameters
emh203 0:085749c8446f 76 float SAMPLE_RATE;
emh203 0:085749c8446f 77 DWORD WRITE_BLOCK_THRESH;
emh203 0:085749c8446f 78
emh203 0:085749c8446f 79 CHAR ID[MAX_ID_LENGTH+1];
emh203 0:085749c8446f 80 #define ID_DEFAULT "No ID"
emh203 0:085749c8446f 81
emh203 0:085749c8446f 82 void LoadDefaults()
emh203 0:085749c8446f 83 {
emh203 0:085749c8446f 84 strcpy(ID,ID_DEFAULT);
emh203 0:085749c8446f 85
emh203 0:085749c8446f 86 VOFFSET_ADJUST = VOFFSET_ADJUST_DEFAULT;
emh203 0:085749c8446f 87 VSCALE_ADJUST = VSCALE_ADJUST_DEFAULT;
emh203 0:085749c8446f 88
emh203 0:085749c8446f 89 R17 = R17_DEFAULT;
emh203 0:085749c8446f 90 R15 = R15_DEFAULT;
emh203 0:085749c8446f 91
emh203 0:085749c8446f 92 R2 = R2_DEFAULT;
emh203 0:085749c8446f 93 R4 = R4_DEFAULT;
emh203 0:085749c8446f 94
emh203 0:085749c8446f 95 R6 = R6_DEFAULT;
emh203 0:085749c8446f 96 R7 = R7_DEFAULT;
emh203 0:085749c8446f 97
emh203 0:085749c8446f 98 R8 = R8_DEFAULT;
emh203 0:085749c8446f 99 R9 = R9_DEFAULT;
emh203 0:085749c8446f 100
emh203 0:085749c8446f 101 R18 = R18_DEFAULT;
emh203 0:085749c8446f 102 R19 = R19_DEFAULT;
emh203 0:085749c8446f 103 R20 = R20_DEFAULT;
emh203 0:085749c8446f 104 R22 = R22_DEFAULT;
emh203 0:085749c8446f 105
emh203 0:085749c8446f 106 U1_VREF = U1_VREF_DEFAULT;
emh203 0:085749c8446f 107 MBED_VREF = MBED_VREF_DEFAULT;
emh203 0:085749c8446f 108
emh203 0:085749c8446f 109 INPUT_DIODE_DROP = INPUT_DIODE_DROP_DEFAULT;
emh203 0:085749c8446f 110
emh203 0:085749c8446f 111 ACS576_VOFFSET = ACS576_VOFFSET_DEFAULT;
emh203 0:085749c8446f 112
emh203 0:085749c8446f 113 ACS576_ISCALE = ACS576_ISCALE_DEFAULT;
emh203 0:085749c8446f 114 ACS576_ISCALE_ADJUST = ACS576_ISCALE_ADJUST_DEFAULT;
emh203 0:085749c8446f 115
emh203 0:085749c8446f 116 ACS576_IOFFSET_TRIM = ACS576_IOFFSET_TRIM_DEFAULT;
emh203 0:085749c8446f 117
emh203 0:085749c8446f 118 SAMPLE_RATE = SAMPLE_RATE_DEFAULT;
emh203 0:085749c8446f 119 WRITE_BLOCK_THRESH = WRITE_BLOCK_THRESH_DEFAULT;
emh203 0:085749c8446f 120 }
emh203 0:085749c8446f 121
emh203 0:085749c8446f 122 void ExportConfigurationSettings()
emh203 0:085749c8446f 123 {
emh203 0:085749c8446f 124 FILE *MyConfigFile = fopen("/local/config.txt","w");
emh203 0:085749c8446f 125
emh203 0:085749c8446f 126
emh203 0:085749c8446f 127 fprintf(MyConfigFile,"ACS576_ISCALE_ADJUST = %.3f \r\n",ACS576_ISCALE_ADJUST);
emh203 0:085749c8446f 128 fprintf(MyConfigFile,"ACS576_IOFFSET_TRIM = %.3f \r\n",ACS576_IOFFSET_TRIM);
emh203 0:085749c8446f 129
emh203 0:085749c8446f 130 fprintf(MyConfigFile,"VSCALE_ADJUST = %.3f \r\n",VSCALE_ADJUST);
emh203 0:085749c8446f 131 fprintf(MyConfigFile,"VOFFSET_ADJUST = %.3f \r\n",VOFFSET_ADJUST);
emh203 0:085749c8446f 132
emh203 0:085749c8446f 133 fprintf(MyConfigFile,"R17 = %.1f \r\n",R17);
emh203 0:085749c8446f 134 fprintf(MyConfigFile,"R15 = %.1f \r\n",R15);
emh203 0:085749c8446f 135
emh203 0:085749c8446f 136 fprintf(MyConfigFile,"R2 = %.1f \r\n",R2);
emh203 0:085749c8446f 137 fprintf(MyConfigFile,"R4 = %.1f \r\n", R4);
emh203 0:085749c8446f 138
emh203 0:085749c8446f 139 fprintf(MyConfigFile,"R6 = %.1f \r\n",R6);
emh203 0:085749c8446f 140 fprintf(MyConfigFile,"R7 = %.1f \r\n",R7);
emh203 0:085749c8446f 141
emh203 0:085749c8446f 142 fprintf(MyConfigFile,"R8 = %.1f \r\n",R8);
emh203 0:085749c8446f 143 fprintf(MyConfigFile,"R9 = %.1f \r\n",R9);
emh203 0:085749c8446f 144
emh203 0:085749c8446f 145 fprintf(MyConfigFile,"R18 = %.1f \r\n",R18);
emh203 0:085749c8446f 146 fprintf(MyConfigFile,"R19 = %.1f \r\n",R19);
emh203 0:085749c8446f 147 fprintf(MyConfigFile,"R20 = %.1f \r\n",R20);
emh203 0:085749c8446f 148 fprintf(MyConfigFile,"R22 = %.1f \r\n",R22);
emh203 0:085749c8446f 149
emh203 0:085749c8446f 150 fprintf(MyConfigFile,"U1_VREF = %.3f \r\n",U1_VREF);
emh203 0:085749c8446f 151 fprintf(MyConfigFile,"MBED_VREF = %.3f \r\n",MBED_VREF);
emh203 0:085749c8446f 152
emh203 0:085749c8446f 153 fprintf(MyConfigFile,"INPUT_DIODE_DROP = %.3f \r\n",INPUT_DIODE_DROP);
emh203 0:085749c8446f 154
emh203 0:085749c8446f 155 fprintf(MyConfigFile,"ACS576_VOFFSET = %.3f \r\n",ACS576_VOFFSET);
emh203 0:085749c8446f 156
emh203 0:085749c8446f 157 fprintf(MyConfigFile,"ACS576_ISCALE = %.3f \r\n", ACS576_ISCALE_DEFAULT);
emh203 0:085749c8446f 158
emh203 0:085749c8446f 159
emh203 0:085749c8446f 160 fprintf(MyConfigFile,"SAMPLE_RATE = %.1f \r\n",SAMPLE_RATE);
emh203 0:085749c8446f 161 fprintf(MyConfigFile,"WRITE_BLOCK_THRESH = %d \r\n",WRITE_BLOCK_THRESH);
emh203 0:085749c8446f 162
emh203 0:085749c8446f 163 fprintf(MyConfigFile,"ID = %s \r\n",ID);
emh203 0:085749c8446f 164
emh203 0:085749c8446f 165
emh203 0:085749c8446f 166 fclose(MyConfigFile);
emh203 0:085749c8446f 167 }
emh203 0:085749c8446f 168
emh203 0:085749c8446f 169 //This is a very "static implementation. Just does string compares. Would be nice to have a table like feature in the future
emh203 0:085749c8446f 170 void ParseKeyValue(const CHAR *Key,const CHAR *Value)
emh203 0:085749c8446f 171 {
emh203 0:085749c8446f 172 WORD i;
emh203 0:085749c8446f 173
emh203 0:085749c8446f 174 if(!strcmp(Key,(CHAR *)"R17"))
emh203 0:085749c8446f 175 {
emh203 0:085749c8446f 176 R17 = atof(Value);
emh203 0:085749c8446f 177 PrintfEnqueue(&PCBackDoorTx,"R17 assigned a value of %.3f",R17);
emh203 0:085749c8446f 178 }
emh203 0:085749c8446f 179 else if(!strcmp(Key,"R15"))
emh203 0:085749c8446f 180 {
emh203 0:085749c8446f 181 R15 = atof(Value);
emh203 0:085749c8446f 182 PrintfEnqueue(&PCBackDoorTx,"R15 assigned a value of %.3f",R15);
emh203 0:085749c8446f 183 }
emh203 0:085749c8446f 184 else if(!strcmp(Key,"R2"))
emh203 0:085749c8446f 185 {
emh203 0:085749c8446f 186 R2 = atof(Value);
emh203 0:085749c8446f 187 PrintfEnqueue(&PCBackDoorTx,"R2 assigned a value of %.3f",R2);
emh203 0:085749c8446f 188 }
emh203 0:085749c8446f 189 else if(!strcmp(Key,"R4"))
emh203 0:085749c8446f 190 {
emh203 0:085749c8446f 191 R4 = atof(Value);
emh203 0:085749c8446f 192 PrintfEnqueue(&PCBackDoorTx,"R4 assigned a value of %.3f",R4);
emh203 0:085749c8446f 193 }
emh203 0:085749c8446f 194 else if(!strcmp(Key,"R6"))
emh203 0:085749c8446f 195 {
emh203 0:085749c8446f 196 R6 = atof(Value);
emh203 0:085749c8446f 197 PrintfEnqueue(&PCBackDoorTx,"R6 assigned a value of %.3f",R6);
emh203 0:085749c8446f 198 }
emh203 0:085749c8446f 199 else if(!strcmp(Key,"R7"))
emh203 0:085749c8446f 200 {
emh203 0:085749c8446f 201 R7 = atof(Value);
emh203 0:085749c8446f 202 PrintfEnqueue(&PCBackDoorTx,"R7 assigned a value of %.3f",R7);
emh203 0:085749c8446f 203 }
emh203 0:085749c8446f 204 else if(!strcmp(Key,"R8"))
emh203 0:085749c8446f 205 {
emh203 0:085749c8446f 206 R8 = atof(Value);
emh203 0:085749c8446f 207 PrintfEnqueue(&PCBackDoorTx,"R8 assigned a value of %.3f",R8);
emh203 0:085749c8446f 208 }
emh203 0:085749c8446f 209 else if(!strcmp(Key,"R9"))
emh203 0:085749c8446f 210 {
emh203 0:085749c8446f 211 R9 = atof(Value);
emh203 0:085749c8446f 212 PrintfEnqueue(&PCBackDoorTx,"R9 assigned a value of %.3f",R9);
emh203 0:085749c8446f 213 }
emh203 0:085749c8446f 214 else if(!strcmp(Key,"U1_VREF"))
emh203 0:085749c8446f 215 {
emh203 0:085749c8446f 216 U1_VREF = atof(Value);
emh203 0:085749c8446f 217 PrintfEnqueue(&PCBackDoorTx,"U1_VREF assigned a value of %.3f",U1_VREF);
emh203 0:085749c8446f 218 }
emh203 0:085749c8446f 219 else if(!strcmp(Key,"MBED_VREF"))
emh203 0:085749c8446f 220 {
emh203 0:085749c8446f 221 MBED_VREF = atof(Value);
emh203 0:085749c8446f 222 PrintfEnqueue(&PCBackDoorTx,"MBED_VREF assigned a value of %.3f",MBED_VREF);
emh203 0:085749c8446f 223 }
emh203 0:085749c8446f 224 else if(!strcmp(Key,"INPUT_DIODE_DROP"))
emh203 0:085749c8446f 225 {
emh203 0:085749c8446f 226 INPUT_DIODE_DROP = atof(Value);
emh203 0:085749c8446f 227 PrintfEnqueue(&PCBackDoorTx,"INPUT_DIODE_DROP assigned a value of %.3f",INPUT_DIODE_DROP);
emh203 0:085749c8446f 228 }
emh203 0:085749c8446f 229 else if(!strcmp(Key,"ACS576_VOFFSET"))
emh203 0:085749c8446f 230 {
emh203 0:085749c8446f 231 ACS576_VOFFSET = atof(Value);
emh203 0:085749c8446f 232 PrintfEnqueue(&PCBackDoorTx,"ACS576_VOFFSET assigned a value of %.3f", ACS576_VOFFSET);
emh203 0:085749c8446f 233 }
emh203 0:085749c8446f 234 else if(!strcmp(Key,"ACS576_ISCALE"))
emh203 0:085749c8446f 235 {
emh203 0:085749c8446f 236 ACS576_ISCALE = atof(Value);
emh203 0:085749c8446f 237 PrintfEnqueue(&PCBackDoorTx,"ACS576_ISCALE assigned a value of %.3f", ACS576_ISCALE);
emh203 0:085749c8446f 238 }
emh203 0:085749c8446f 239 else if(!strcmp(Key,"ACS576_ISCALE_ADJUST"))
emh203 0:085749c8446f 240 {
emh203 0:085749c8446f 241 ACS576_ISCALE_ADJUST = atof(Value);
emh203 0:085749c8446f 242 PrintfEnqueue(&PCBackDoorTx,"ACS576_ISCALE_ADJUST assigned a value of %.3f", ACS576_ISCALE_ADJUST);
emh203 0:085749c8446f 243 }
emh203 0:085749c8446f 244 else if(!strcmp(Key,"ACS576_IOFFSET_TRIM"))
emh203 0:085749c8446f 245 {
emh203 0:085749c8446f 246 ACS576_IOFFSET_TRIM = atof(Value);
emh203 0:085749c8446f 247 PrintfEnqueue(&PCBackDoorTx,"ACS576_IOFFSET_TRIM assigned a value of %.3f", ACS576_IOFFSET_TRIM);
emh203 0:085749c8446f 248 }
emh203 0:085749c8446f 249 else if(!strcmp(Key,"R18"))
emh203 0:085749c8446f 250 {
emh203 0:085749c8446f 251 R18 = atof(Value);
emh203 0:085749c8446f 252 PrintfEnqueue(&PCBackDoorTx,"R18 assigned a value of %.3f", R18);
emh203 0:085749c8446f 253 }
emh203 0:085749c8446f 254 else if(!strcmp(Key,"R19"))
emh203 0:085749c8446f 255 {
emh203 0:085749c8446f 256 R19 = atof(Value);
emh203 0:085749c8446f 257 PrintfEnqueue(&PCBackDoorTx,"R19 assigned a value of %.3f", R19);
emh203 0:085749c8446f 258 }
emh203 0:085749c8446f 259 else if(!strcmp(Key,"R20"))
emh203 0:085749c8446f 260 {
emh203 0:085749c8446f 261 R20 = atof(Value);
emh203 0:085749c8446f 262 PrintfEnqueue(&PCBackDoorTx,"R20 assigned a value of %.3f", R20);
emh203 0:085749c8446f 263 }
emh203 0:085749c8446f 264 else if(!strcmp(Key,"R22"))
emh203 0:085749c8446f 265 {
emh203 0:085749c8446f 266 R22 = atof(Value);
emh203 0:085749c8446f 267 PrintfEnqueue(&PCBackDoorTx,"R22 assigned a value of %.3f", R22);
emh203 0:085749c8446f 268 }
emh203 0:085749c8446f 269 else if(!strcmp(Key,"VSCALE_ADJUST"))
emh203 0:085749c8446f 270 {
emh203 0:085749c8446f 271 VSCALE_ADJUST = atof(Value);
emh203 0:085749c8446f 272 PrintfEnqueue(&PCBackDoorTx,"VSCALE_ADJUST assigned a value of %.3f", VSCALE_ADJUST);
emh203 0:085749c8446f 273 }
emh203 0:085749c8446f 274 else if(!strcmp(Key,"VOFFSET_ADJUST"))
emh203 0:085749c8446f 275 {
emh203 0:085749c8446f 276 VOFFSET_ADJUST = atof(Value);
emh203 0:085749c8446f 277 PrintfEnqueue(&PCBackDoorTx,"VOFFSET_ADJUST assigned a value of %.3f", VOFFSET_ADJUST);
emh203 0:085749c8446f 278 }
emh203 0:085749c8446f 279 else if(!strcmp(Key,"SAMPLE_RATE"))
emh203 0:085749c8446f 280 {
emh203 0:085749c8446f 281 SAMPLE_RATE = atof(Value);
emh203 0:085749c8446f 282
emh203 0:085749c8446f 283 if(SAMPLE_RATE < MIN_SAMPLE_RATE || SAMPLE_RATE > MAX_SAMPLE_RATE)
emh203 0:085749c8446f 284 {
emh203 0:085749c8446f 285 PrintfEnqueue(&PCBackDoorTx,"Illegal SAMPLE_RATE of %.1f was specified. %.1f is being used",SAMPLE_RATE,SAMPLE_RATE_DEFAULT);
emh203 0:085749c8446f 286 SAMPLE_RATE = SAMPLE_RATE_DEFAULT;
emh203 0:085749c8446f 287 }
emh203 0:085749c8446f 288 else
emh203 0:085749c8446f 289 {
emh203 0:085749c8446f 290 PrintfEnqueue(&PCBackDoorTx,"SAMPLE_RATE assigned a value of %.1f", SAMPLE_RATE);
emh203 0:085749c8446f 291 }
emh203 0:085749c8446f 292 }
emh203 0:085749c8446f 293
emh203 0:085749c8446f 294 else if(!strcmp(Key,"WRITE_BLOCK_THRESH"))
emh203 0:085749c8446f 295 {
emh203 0:085749c8446f 296 WRITE_BLOCK_THRESH = (DWORD)atof(Value);
emh203 0:085749c8446f 297
emh203 0:085749c8446f 298 if(WRITE_BLOCK_THRESH < MIN_WRITE_BLOCK_THRESH|| WRITE_BLOCK_THRESH > MAX_WRITE_BLOCK_THRESH)
emh203 0:085749c8446f 299 {
emh203 0:085749c8446f 300 PrintfEnqueue(&PCBackDoorTx,"Illegal WRITE_BLOCK_THRESH of %d was specified. %d is being used\r\n",WRITE_BLOCK_THRESH,WRITE_BLOCK_THRESH_DEFAULT);
emh203 0:085749c8446f 301 PrintfEnqueue(&PCBackDoorTx,"WRITE_BLOCK_THRESH must be between %d and %d",MIN_WRITE_BLOCK_THRESH, MAX_WRITE_BLOCK_THRESH);
emh203 0:085749c8446f 302
emh203 0:085749c8446f 303 WRITE_BLOCK_THRESH = WRITE_BLOCK_THRESH_DEFAULT;
emh203 0:085749c8446f 304 }
emh203 0:085749c8446f 305 else
emh203 0:085749c8446f 306 {
emh203 0:085749c8446f 307 PrintfEnqueue(&PCBackDoorTx,"WRITE_BLOCK_THRESH assigned a value of %d", WRITE_BLOCK_THRESH);
emh203 0:085749c8446f 308 }
emh203 0:085749c8446f 309 }
emh203 0:085749c8446f 310 else if(!strcmp(Key,"ID"))
emh203 0:085749c8446f 311 {
emh203 0:085749c8446f 312 if(strlen(Value)>MAX_ID_LENGTH)
emh203 0:085749c8446f 313 {
emh203 0:085749c8446f 314 PrintfEnqueue(&PCBackDoorTx,"ID must be %d characters or less. Truncating...", MAX_ID_LENGTH);
emh203 0:085749c8446f 315 for(i=0;i<MAX_ID_LENGTH;i++)
emh203 0:085749c8446f 316 {
emh203 0:085749c8446f 317 ID[i] = Value[i];
emh203 0:085749c8446f 318 ID[MAX_ID_LENGTH] = NULL;
emh203 0:085749c8446f 319 }
emh203 0:085749c8446f 320 }
emh203 0:085749c8446f 321 else
emh203 0:085749c8446f 322 {
emh203 0:085749c8446f 323 strcpy(ID,Value);
emh203 0:085749c8446f 324 }
emh203 0:085749c8446f 325
emh203 0:085749c8446f 326 PrintfEnqueue(&PCBackDoorTx,"ID assigned a value of %s", ID);
emh203 0:085749c8446f 327 }
emh203 0:085749c8446f 328 else
emh203 0:085749c8446f 329 {
emh203 0:085749c8446f 330 PrintfEnqueue(&PCBackDoorTx,"%s key is not recognized parameter",Key);
emh203 0:085749c8446f 331 }
emh203 0:085749c8446f 332
emh203 0:085749c8446f 333 PrintfEnqueue(&PCBackDoorTx,"\r\n");
emh203 0:085749c8446f 334
emh203 0:085749c8446f 335 }
emh203 0:085749c8446f 336
emh203 0:085749c8446f 337 void LoadConfiguration()
emh203 0:085749c8446f 338 {
emh203 0:085749c8446f 339 WORD CurrentLine = 1;
emh203 0:085749c8446f 340
emh203 0:085749c8446f 341 LoadDefaults();
emh203 0:085749c8446f 342
emh203 0:085749c8446f 343 SmartSwitch_SetBackLightColor(3,3,3);
emh203 0:085749c8446f 344 GFX_FullDisplayBufferClear(&BackBuffer);
emh203 0:085749c8446f 345 GFX_DrawString(&BackBuffer,"Loading Config",0,0,&Font3x5);
emh203 0:085749c8446f 346 GFX_DumpRenderContextToPhysicalScreen(&BackBuffer);
emh203 0:085749c8446f 347
emh203 0:085749c8446f 348 FILE *MyConfigFile = fopen("/local/config.txt","r");
emh203 0:085749c8446f 349
emh203 0:085749c8446f 350 if(!MyConfigFile)
emh203 0:085749c8446f 351 {
emh203 0:085749c8446f 352 PrintfEnqueue(&PCBackDoorTx,"Could not open configuration files. Using Defaults....\r\n");
emh203 0:085749c8446f 353 wait(1);
emh203 0:085749c8446f 354 return;
emh203 0:085749c8446f 355 }
emh203 0:085749c8446f 356
emh203 0:085749c8446f 357 PrintfEnqueue(&PCBackDoorTx,"Config file found. Parsing.....\r\n\r\n");
emh203 0:085749c8446f 358
emh203 0:085749c8446f 359 while(fgets(LineBuf,sizeof(LineBuf),MyConfigFile))
emh203 0:085749c8446f 360 {
emh203 0:085749c8446f 361 if(KeyValueSplit(LineBuf,Key,Value))
emh203 0:085749c8446f 362 {
emh203 0:085749c8446f 363 ParseKeyValue(Key,Value);
emh203 0:085749c8446f 364 }
emh203 0:085749c8446f 365 else
emh203 0:085749c8446f 366 {
emh203 0:085749c8446f 367 PrintfEnqueue(&PCBackDoorTx,"No valid key=value pair on line %d\r\n",CurrentLine);
emh203 0:085749c8446f 368 }
emh203 0:085749c8446f 369
emh203 0:085749c8446f 370 CurrentLine++;
emh203 0:085749c8446f 371 }
emh203 0:085749c8446f 372
emh203 0:085749c8446f 373 fclose(MyConfigFile);
emh203 0:085749c8446f 374
emh203 0:085749c8446f 375 PrintfEnqueue(&PCBackDoorTx,"\r\n\r\n>");
emh203 0:085749c8446f 376 }
emh203 0:085749c8446f 377
emh203 0:085749c8446f 378
emh203 0:085749c8446f 379