3 |
#include <string> |
#include <string> |
4 |
|
|
5 |
#include <sstream> |
#include <sstream> |
6 |
|
#include <stdlib.h> |
7 |
|
|
8 |
#include "common.h" |
#include "common.h" |
9 |
|
|
10 |
#include "GsmModem.h" |
#include "ISmsTransceiver.h" |
11 |
|
|
12 |
#include "Plugin.h" |
#include "Plugin.h" |
13 |
#include "kbhit.h" |
#include "kbhit.h" |
24 |
void SmsDaemon::CreateLogMessage(SMS& sms,bool hasPlugin) |
void SmsDaemon::CreateLogMessage(SMS& sms,bool hasPlugin) |
25 |
{ |
{ |
26 |
ostringstream os; |
ostringstream os; |
27 |
os << "Recieved sms from " << sms.sender << " ; command=" << GetSmsCommand(sms); |
os << "Recieved sms from " << sms.GetSender() << " ; command=" << sms.ExtractCommand(); |
28 |
if (!hasPlugin) |
if (!hasPlugin) |
29 |
os << " -- PLUGIN NOT FOUND"; |
os << " -- PLUGIN NOT FOUND"; |
30 |
|
|
34 |
|
|
35 |
void SmsDaemon::CheckSms() |
void SmsDaemon::CheckSms() |
36 |
{ |
{ |
37 |
const int INTERVAL = 250; //no of milliseconds between sms checks |
const int INTERVAL = 1000; //no of milliseconds between sms checks |
38 |
timeval now = Util::GetTimeOfDay(); |
timeval now = Util::GetTimeOfDay(); |
39 |
|
|
40 |
if ( Util::mTimeDiff(_lastSmsCheck,now) < INTERVAL) |
if ( Util::mTimeDiff(_lastSmsCheck,now) < INTERVAL) |
49 |
|
|
50 |
for (unsigned int i=0; i<sms.size(); ++i) |
for (unsigned int i=0; i<sms.size(); ++i) |
51 |
{ |
{ |
52 |
string cmd = GetSmsCommand(sms[i]); |
string cmd = sms[i].ExtractCommand(); |
53 |
|
|
54 |
cmd = Util::str_tolower(cmd); |
cmd = Util::str_tolower(cmd); |
55 |
|
|
63 |
} |
} |
64 |
else |
else |
65 |
{ |
{ |
66 |
_modem.SendSms(sms[i].sender, "Unknown command!", false); |
_modem.SendSms(sms[i].GetSender(), "Unknown command!", false); |
67 |
} |
} |
68 |
|
|
69 |
_modem.DeleteSms(sms[i].sms_index); |
_modem.DeleteSms(sms[i].GetIndex()); |
70 |
cmn->smsCounter.incomming++; |
cmn->smsCounter.incomming++; |
71 |
} |
} |
72 |
} |
} |
80 |
|
|
81 |
mainContinue = true; |
mainContinue = true; |
82 |
|
|
|
int loopcount = 0; |
|
83 |
while (mainContinue) |
while (mainContinue) |
84 |
{ |
{ |
|
if (loopcount > 100 ) |
|
|
{ |
|
|
CheckSms(); |
|
85 |
|
|
86 |
cmn->GetTaskManager()->ExecuteTasks(_modem); |
CheckSms(); |
87 |
|
|
88 |
loopcount = 0; |
cmn->GetTaskManager()->ExecuteTasks(_modem); |
|
} |
|
89 |
|
|
90 |
if (cmn->isDebug && kbhit()) |
if (cmn->isDebug && kbhit()) |
91 |
break; |
break; |
92 |
|
|
93 |
Util::Sleep(10); |
Util::Sleep(100); |
94 |
|
|
95 |
} |
} |
96 |
} |
} |
99 |
{ |
{ |
100 |
Common* cmn = Common::instance(); |
Common* cmn = Common::instance(); |
101 |
|
|
102 |
|
srand(time(0)); |
103 |
|
|
104 |
cmn->daemonStart = time(0); |
cmn->daemonStart = time(0); |
105 |
_lastSmsCheck = Util::GetTimeOfDay(); |
_lastSmsCheck = Util::GetTimeOfDay(); |