-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfread.cpp
63 lines (59 loc) · 1.43 KB
/
confread.cpp
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
#include "confread.h"
#include "string.h"
#include <SD.h>
extern byte mac[6], ip[4], netmask[4], gateway[4], dns[4];
void readConfig()
{
byte err=0;
File f = SD.open("config.txt");
while(!err && f.available()) {
byte c=f.read();
switch(c) {
case '\n':
case '\r':
case ' ':
case '\t':
break; // Ignore whitespace
case '#':
nextline(f); // Ignore comment lines
break;
case 'h': // HW address (MAC)
mac[0]=parsehex(f);
f.read();
mac[1]=parsehex(f);
f.read();
mac[2]=parsehex(f);
f.read();
mac[3]=parsehex(f);
f.read();
mac[4]=parsehex(f);
f.read();
mac[5]=parsehex(f);
//nextline(f); // Don't require a new line
break;
case 'i': // IP address
err=parseip(f, ip);
//nextline(f); // Don't require a new line
break;
case 'm': // MASK
err=parseip(f, netmask);
//nextline(f); // Don't require a new line
break;
case 'g': // GW
err=parseip(f, gateway);
//nextline(f); // Don't require a new line
break;
case 'd': // DNS
err=parseip(f, dns);
//nextline(f); // Don't require a new line
break;
default:
Serial.print(F("Unexpected char: "));
Serial.println(c);
}
}
}
/* Halts after an error */
void lockup() {
while(true) delay(1000);
}