Typical controller demo program based on Seeed Arch Max. Features: - Multi-thread architecture - Inter-thread message communication - Independent command shell using thread - HTTPD with CGI, WS, RPC - Key & value pair configuration load/save

Dependencies:   CMDB EthernetInterface HTTPD dconfig mbed-rpc mbed-rtos mbed storage_on_flash

Committer:
hillkim7
Date:
Wed Mar 25 21:56:51 2015 +0000
Revision:
0:2ffd10976643
Child:
2:d7ffadba49b9
Typical controller demo program based on Seeed Arch Max.; Features:; - Multi-thread architecture; - Inter-thread message communication; - Independent command shell using thread; - HTTPD with CGI, WS, RPC; - Key & value pair configuration load/save

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hillkim7 0:2ffd10976643 1 /**
hillkim7 0:2ffd10976643 2 * @file MainConfig.cpp
hillkim7 0:2ffd10976643 3 *
hillkim7 0:2ffd10976643 4 * @brief main configuration
hillkim7 0:2ffd10976643 5 *
hillkim7 0:2ffd10976643 6 */
hillkim7 0:2ffd10976643 7
hillkim7 0:2ffd10976643 8 #include "MainConfig.h"
hillkim7 0:2ffd10976643 9 #include "SOFBlock.h"
hillkim7 0:2ffd10976643 10
hillkim7 0:2ffd10976643 11 // main configuration sector index of flash memory.
hillkim7 0:2ffd10976643 12 const uint8_t config_sector_index = 7;
hillkim7 0:2ffd10976643 13
hillkim7 0:2ffd10976643 14 void MainConfig::reset_default(void)
hillkim7 0:2ffd10976643 15 {
hillkim7 0:2ffd10976643 16 (*this)["eth"] = "dhcp";
hillkim7 0:2ffd10976643 17 (*this)["ip"] = "";
hillkim7 0:2ffd10976643 18 (*this)["mask"] = "255.255.255.0";
hillkim7 0:2ffd10976643 19 (*this)["gw"] = "";
hillkim7 0:2ffd10976643 20 }
hillkim7 0:2ffd10976643 21
hillkim7 0:2ffd10976643 22 bool MainConfig::load_config()
hillkim7 0:2ffd10976643 23 {
hillkim7 0:2ffd10976643 24 SOFReader reader;
hillkim7 0:2ffd10976643 25
hillkim7 0:2ffd10976643 26 if (reader.open(config_sector_index) != kSOF_ErrNone) {
hillkim7 0:2ffd10976643 27 return false;
hillkim7 0:2ffd10976643 28 }
hillkim7 0:2ffd10976643 29
hillkim7 0:2ffd10976643 30 return load_from((char *)reader.get_physical_data_addr(), reader.get_data_size());
hillkim7 0:2ffd10976643 31 }
hillkim7 0:2ffd10976643 32
hillkim7 0:2ffd10976643 33 static bool save_func(void *user_data, char c)
hillkim7 0:2ffd10976643 34 {
hillkim7 0:2ffd10976643 35 SOFWriter *writer = (SOFWriter*)user_data;
hillkim7 0:2ffd10976643 36
hillkim7 0:2ffd10976643 37 return writer->write_byte_data((uint8_t)c);
hillkim7 0:2ffd10976643 38 }
hillkim7 0:2ffd10976643 39
hillkim7 0:2ffd10976643 40 bool MainConfig::save_config()
hillkim7 0:2ffd10976643 41 {
hillkim7 0:2ffd10976643 42 size_t need_bytes = estimate_save();
hillkim7 0:2ffd10976643 43 SOFWriter writer;
hillkim7 0:2ffd10976643 44
hillkim7 0:2ffd10976643 45 if (writer.open(config_sector_index) != kSOF_ErrNone) {
hillkim7 0:2ffd10976643 46 printf("open(%d) fail: format\r\n", config_sector_index);
hillkim7 0:2ffd10976643 47 SOFBlock::format(config_sector_index);
hillkim7 0:2ffd10976643 48 writer.open(config_sector_index);
hillkim7 0:2ffd10976643 49 } else {
hillkim7 0:2ffd10976643 50 if (need_bytes > writer.get_free_size()) {
hillkim7 0:2ffd10976643 51 printf("too small free size(%u/%u): format\r\n", need_bytes, writer.get_free_size());
hillkim7 0:2ffd10976643 52 writer.close();
hillkim7 0:2ffd10976643 53 SOFBlock::format(config_sector_index);
hillkim7 0:2ffd10976643 54 writer.open(config_sector_index);
hillkim7 0:2ffd10976643 55 }
hillkim7 0:2ffd10976643 56 }
hillkim7 0:2ffd10976643 57
hillkim7 0:2ffd10976643 58 return save_to(save_func, &writer);
hillkim7 0:2ffd10976643 59 }
hillkim7 0:2ffd10976643 60
hillkim7 0:2ffd10976643 61
hillkim7 0:2ffd10976643 62