--- smsdaemon/main.cpp 2008/06/09 21:56:47 30 +++ smsdaemon/main.cpp 2008/06/13 10:10:06 75 @@ -1,4 +1,3 @@ -#include #include #include @@ -58,10 +57,11 @@ } else { - modem.SendSms(sms[i].sender, "Unknown command!"); + modem.SendSms(sms[i].sender, "Unknown command!", false); } modem.DeleteSms(sms[i].sms_index); + cmn->smsCounter.incomming++; } if (sms.size() == 0) @@ -73,6 +73,13 @@ } } +bool sms_exit(int exitcode) +{ + if (Common::instance()->isDaemon) + daemonCleanup(); + + exit(exitcode); +} int main(int argc, char* argv[]) { @@ -88,6 +95,7 @@ cmn->gid = 1000; cmn->loadConfig(argc,argv); + cmn->daemonStart = time(0); ///////////////////// @@ -104,16 +112,30 @@ SerialPort port("/dev/ttyS1" ); try { - port.Open( SerialPort::BAUD_9600 ); + port.Open( SerialPort::BAUD_9600, + SerialPort::CHAR_SIZE_8, + SerialPort::PARITY_NONE, + SerialPort::STOP_BITS_1, + SerialPort::FLOW_CONTROL_HARD ); } catch(std::exception &e) { cmn->logMessage( string("PortOpen Exception: ") + e.what() ); - exit(1); + sms_exit(1); } GsmModem modem(port); + try + { + modem.Init(); + } + catch (std::exception& e) + { + cmn->logMessage( string("GsmModem Exception: ") + e.what() ); + sms_exit(2); + } + ////////////////////////////////// @@ -123,6 +145,8 @@ main_loop(modem); + cmn->logMessage( cmn->getStatusMessage() ); + if (cmn->isDaemon) daemonCleanup();