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: ulaw mbed ConfigFile
config.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "ConfigFile.h" 00004 #include "phone.h" 00005 00006 LocalFileSystem local("local"); 00007 00008 extern EthernetNetIf *eth; 00009 extern int useipline; 00010 extern struct PhoneBook phonebook[]; 00011 00012 char* chop (char *s) { 00013 int i; 00014 00015 for (i = strlen(s) - 1; i >= 0; i --) { 00016 if (s[i] == ' ' || s[i] == '\n' || s[i] == '\r') { 00017 s[i] = 0; 00018 } else { 00019 break; 00020 } 00021 } 00022 return s; 00023 } 00024 00025 int config () { 00026 int i, j; 00027 ConfigFile cfg; 00028 char buf[80], key[20]; 00029 int ip0, ip1, ip2, ip3; 00030 EthernetErr r; 00031 IpAddr ipaddr, netmask, gateway, nameserver; 00032 00033 if (! cfg.read("/local/phone.cfg")) { 00034 printf("config err\r\n"); 00035 return -1; 00036 } 00037 00038 if (cfg.getValue("IPADDRESS", buf, sizeof(buf))) { 00039 chop(buf); 00040 if (strcmp(buf, "DHCP") == 0) { 00041 eth = new EthernetNetIf; 00042 } else { 00043 sscanf(buf, "%d.%d.%d.%d", &ip0, &ip1, &ip2, &ip3); 00044 ipaddr = IpAddr(ip0, ip1, ip2, ip3); 00045 if (cfg.getValue("NETMASK", buf, sizeof(buf))) { 00046 sscanf(chop(buf), "%d.%d.%d.%d", &ip0, &ip1, &ip2, &ip3); 00047 netmask = IpAddr(ip0, ip1, ip2, ip3); 00048 } 00049 if (cfg.getValue("GATEWAY", buf, sizeof(buf))) { 00050 sscanf(chop(buf), "%d.%d.%d.%d", &ip0, &ip1, &ip2, &ip3); 00051 gateway = IpAddr(ip0, ip1, ip2, ip3); 00052 } 00053 if (cfg.getValue("NAMESERVER", buf, sizeof(buf))) { 00054 sscanf(chop(buf), "%d.%d.%d.%d", &ip0, &ip1, &ip2, &ip3); 00055 nameserver = IpAddr(ip0, ip1, ip2, ip3); 00056 } 00057 eth = new EthernetNetIf(ipaddr, netmask, gateway, nameserver); 00058 } 00059 r = eth->setup(); 00060 if (! r) { 00061 useipline = 1; 00062 } 00063 } 00064 00065 for (i = 0; i < PB_SIZE; i ++) { 00066 sprintf(key, "DIAL[%d]", i); 00067 if (cfg.getValue(key, buf, sizeof(buf))) { 00068 for (j = 0; j < strlen(buf) && j < DIAL_SIZE; j ++) { 00069 if (buf[j] == '0') { 00070 phonebook[i].dial[j] = 10; 00071 } else 00072 if (buf[j] >= '1' && buf[j] <= '9') { 00073 phonebook[i].dial[j] = buf[j] - '0'; 00074 } 00075 } 00076 phonebook[i].dial[j] = 0; 00077 } 00078 sprintf(key, "TYPE[%d]", i); 00079 if (cfg.getValue(key, buf, sizeof(buf))) { 00080 phonebook[i].target = (enum PhoneType)atoi(buf); 00081 } 00082 sprintf(key, "ADDR[%d]", i); 00083 cfg.getValue(key, phonebook[i].hostname, sizeof(phonebook[i].hostname)); 00084 } 00085 00086 return 0; 00087 } 00088
Generated on Wed Jul 13 2022 04:31:14 by
1.7.2