1 /*--------------------------------------------------------------------------*/
4 // This file is part of ruwai.
6 // If you use ruwai_parser in any program or publication, please inform and
7 // acknowledge its author Stefan Mertl (stefan@mertl-research.at).
9 // ruwai is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /*--------------------------------------------------------------------------*/
28 handle_sig_term(int signum
)
30 if ((signum
== SIGTERM
) || (signum
== SIGINT
))
32 LCDDisplay display
= LCDDisplay(66, 67, 45, 23, 47, 27);
36 display
.print("STOPPED", "RUWAICOM");
43 int main(int argc
, char* argv
[])
45 signal(SIGTERM
, handle_sig_term
);
46 signal(SIGINT
, handle_sig_term
);
47 std::string config_file
= "";
48 std::string debug_level
= "";
51 std::cout
<< "usage: " << argv
[0] << " CONFIG_FILENAME" << std::endl
;
55 if (strcmp(argv
[1], "--version") == 0)
57 std::cout
<< "version " << RUWAI_RECORD_VERSION
<< std::endl
;
61 // TODO: Add an exception handling if the config file can't be read.
62 config_file
= (std::string
)argv
[1];
64 boost::property_tree::ptree pt
;
65 boost::property_tree::ini_parser::read_ini(config_file
, pt
);
66 debug_level
= pt
.get
<std::string
>("log.level");
68 int log_level
= LOG_NOTICE
;
69 if(debug_level
== "emerg")
71 log_level
= LOG_EMERG
;
73 else if(debug_level
== "alert")
75 log_level
= LOG_ALERT
;
77 else if(debug_level
== "critical")
81 else if(debug_level
== "error")
85 else if(debug_level
== "warning")
87 log_level
= LOG_WARNING
;
89 else if(debug_level
== "notice")
91 log_level
= LOG_NOTICE
;
93 else if(debug_level
== "info")
97 else if(debug_level
== "debug")
99 log_level
= LOG_DEBUG
;
102 setlogmask(LOG_UPTO(log_level
));
103 openlog("ruwaicom", LOG_CONS
| LOG_PID
| LOG_NDELAY
, LOG_LOCAL1
);
104 syslog(LOG_NOTICE
, "Starting ruwaicom version %s.", RUWAI_RECORD_VERSION
);
105 syslog(LOG_NOTICE
, "Git revision: %s.", GIT_VERSION
);
107 Root root
= Root(config_file
);
108 syslog(LOG_NOTICE
, "Starting the root...");
110 if (root
.storage_mode
== "sd")
112 syslog(LOG_NOTICE
, "Initial check for the SD card.");
113 if (root
.is_sd_dev_available())
115 if (!root
.is_sd_mounted())
117 syslog(LOG_NOTICE
, "Mounting the SD card....");
118 // Try to mount the SD card.
121 syslog(LOG_ERR
, "Couldn't mount the SD card. No place to write the data to.");
129 root
.clear_tmp_dir();
134 syslog(LOG_ERR
, "The root is not ready. Can't start it. Good bye.");
135 root
.display
->print("Had a problem.", "Check log.");
138 syslog(LOG_NOTICE
, "Exiting ruwaicom.");
140 return(EXIT_SUCCESS
);