![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Code APP3
Dependencies: mbed EthernetInterface WebSocketClient mbed-rtos BufferedSerial
Fork of APP3_Lab by
Diff: parser.cpp
- Revision:
- 13:5f21dd134bd2
- Parent:
- 6:9ed8153f1328
- Child:
- 14:cd488eba8bba
--- a/parser.cpp Sun Oct 01 01:34:37 2017 +0000 +++ b/parser.cpp Sun Oct 01 16:34:11 2017 +0000 @@ -1,10 +1,7 @@ #include "parser.h" -unsigned int PanID; -char URL[255] = {0}; - LocalFileSystem local("local"); - +/* void ReadFile() { Serial pc(USBTX, USBRX); // tx, rx @@ -24,4 +21,58 @@ pc.printf("ServeurURL : %s\r\n",URL); // Display URL fclose(fp); } -} \ No newline at end of file +} */ + +coordinator_config_t read_coordinator_config() +{ + coordinator_config_t config; + + Serial pc(USBTX, USBRX); // tx, rx + FILE *fp = fopen("/local/config.txt", "r"); // Ouvrir config.txt pour lecture seulement + pc.printf("Opening configuration file for the coordinator\n\r"); + if (fp == NULL) + { + pc.printf("Failed to find configuration file. Setting default configuration\n\r"); + + sprintf(config.server_url, "localhost"); + config.pan_id = 0x1; + } + else + { + pc.printf("Config file opened. \n\r"); + fscanf(fp,"0x%x", &config.pan_id); + fscanf(fp,"%s", config.server_url); // read URL + fclose(fp); + + pc.printf("PanId : 0x%x value : %u\r\n", config.pan_id, config.pan_id); // Display PanId + pc.printf("ServeurURL : %s\r\n",config.server_url); // Display URL + } + return config; +} + +router_config_t read_router_config() +{ + router_config_t config; + + Serial pc(USBTX, USBRX); // tx, rx + FILE *fp = fopen("/local/config.txt", "r"); // Ouvrir config.txt pour lecture seulement + pc.printf("Opening configuration file for the router\n\r"); + if (fp == NULL) + { + pc.printf("Failed to find configuration file. Setting default configuration\n\r"); + + config.refresh_freq = 0x1; + config.pan_id = 0x1; + } + else + { + pc.printf("Config file opened. \n\r"); + fscanf(fp,"0x%x", &config.pan_id); + fscanf(fp,"%u", &config.refresh_freq); // read URL + fclose(fp); + + pc.printf("PanId : 0x%x value : %u\r\n", config.pan_id, config.pan_id); // Display PanId + pc.printf("Sensor refresh rate : %u\r\n",config.refresh_freq); // Display URL + } + return config; +}