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: CMDB EthernetInterface HTTPD dconfig mbed-rpc mbed-rtos mbed storage_on_flash
MainConfig.cpp
00001 /** 00002 * @file MainConfig.cpp 00003 * 00004 * @brief main configuration 00005 * 00006 */ 00007 00008 #include "MainConfig.h" 00009 #include "SOFBlock.h" 00010 00011 // main configuration sector index of flash memory. 00012 const uint8_t config_sector_index = 7; 00013 00014 void MainConfig::reset_default(void) 00015 { 00016 clear(); 00017 (*this)["eth"] = "dhcp"; 00018 (*this)["ip"] = ""; 00019 (*this)["mask"] = "255.255.255.0"; 00020 (*this)["gw"] = ""; 00021 } 00022 00023 bool MainConfig::load_config() 00024 { 00025 SOFReader reader; 00026 00027 if (reader.open(config_sector_index) != kSOF_ErrNone) { 00028 return false; 00029 } 00030 00031 return load_from((char *)reader.get_physical_data_addr(), reader.get_data_size()); 00032 } 00033 00034 static bool save_func(void *user_data, char c) 00035 { 00036 SOFWriter *writer = (SOFWriter*)user_data; 00037 00038 return writer->write_byte_data((uint8_t)c); 00039 } 00040 00041 bool MainConfig::save_config() 00042 { 00043 size_t need_bytes = estimate_save(); 00044 SOFWriter writer; 00045 00046 if (writer.open(config_sector_index) != kSOF_ErrNone) { 00047 printf("open(%d) fail: format\r\n", config_sector_index); 00048 SOFBlock::format(config_sector_index); 00049 writer.open(config_sector_index); 00050 } else { 00051 if (need_bytes > writer.get_free_size()) { 00052 printf("too small free size(%u/%u): format\r\n", need_bytes, writer.get_free_size()); 00053 writer.close(); 00054 SOFBlock::format(config_sector_index); 00055 writer.open(config_sector_index); 00056 } 00057 } 00058 00059 return save_to(save_func, &writer); 00060 } 00061 00062 00063 00064
Generated on Tue Jul 12 2022 20:32:58 by
1.7.2