6 |
#include "FlisServerDlg.h" |
#include "FlisServerDlg.h" |
7 |
#include <vector> |
#include <vector> |
8 |
#include ".\flisserverdlg.h" |
#include ".\flisserverdlg.h" |
9 |
|
#include <atlrx.h> |
10 |
|
|
11 |
#ifdef _DEBUG |
#ifdef _DEBUG |
12 |
#define new DEBUG_NEW |
#define new DEBUG_NEW |
66 |
ON_WM_QUERYDRAGICON() |
ON_WM_QUERYDRAGICON() |
67 |
//}}AFX_MSG_MAP |
//}}AFX_MSG_MAP |
68 |
ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) |
ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) |
|
ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin) |
|
69 |
ON_BN_CLICKED(IDC_Start, OnBnClickedStart) |
ON_BN_CLICKED(IDC_Start, OnBnClickedStart) |
70 |
END_MESSAGE_MAP() |
END_MESSAGE_MAP() |
71 |
|
|
224 |
} |
} |
225 |
void CFlisServerDlg::SetPin() |
void CFlisServerDlg::SetPin() |
226 |
{ |
{ |
227 |
|
bool ready = true; |
228 |
CString tekst; |
CString tekst; |
229 |
std::vector<unsigned char> data; |
std::vector<unsigned char> data; |
230 |
|
|
231 |
data.push_back('a'); |
data.push_back('a'); |
232 |
data.push_back('t'); |
data.push_back('t'); |
233 |
data.push_back('+'); |
data.push_back('+'); |
235 |
data.push_back('p'); |
data.push_back('p'); |
236 |
data.push_back('i'); |
data.push_back('i'); |
237 |
data.push_back('n'); |
data.push_back('n'); |
238 |
data.push_back('='); |
data.push_back('?'); |
|
data.push_back('2'); |
|
|
data.push_back('5'); |
|
|
data.push_back('9'); |
|
|
data.push_back('5'); |
|
239 |
|
|
240 |
writeFrame(data); |
writeFrame(data); |
241 |
|
Sleep(100); |
242 |
|
if(Serial.getComstat().cbInQue > 0) |
243 |
|
{ |
244 |
|
std::vector<unsigned char> answer = readFrame(); |
245 |
|
Sleep(50); |
246 |
|
|
247 |
|
for (int i=0; i<answer.size(); i++) |
248 |
|
{ |
249 |
|
if ((answer[i] != 0x0A) && (answer[i] != 0x0D)) |
250 |
|
{ |
251 |
|
tekst.AppendChar(answer[i]); |
252 |
|
} |
253 |
|
} |
254 |
|
AppendText(tekst); |
255 |
|
} |
256 |
|
Sleep(5); |
257 |
|
if (tekst.MakeLower() == "+cpin: sim pin") |
258 |
|
{ |
259 |
|
data.clear(); |
260 |
|
data.push_back('a'); |
261 |
|
data.push_back('t'); |
262 |
|
data.push_back('+'); |
263 |
|
data.push_back('c'); |
264 |
|
data.push_back('p'); |
265 |
|
data.push_back('i'); |
266 |
|
data.push_back('n'); |
267 |
|
data.push_back('='); |
268 |
|
data.push_back('2'); |
269 |
|
data.push_back('5'); |
270 |
|
data.push_back('9'); |
271 |
|
data.push_back('5'); |
272 |
|
|
273 |
|
writeFrame(data); |
274 |
|
|
275 |
|
Sleep(500); |
276 |
|
|
277 |
|
while (ready == true) |
278 |
|
{ |
279 |
|
if (Serial.getComstat().cbInQue > 120) |
280 |
|
{ |
281 |
|
std::vector<unsigned char> answer = readFrame(); |
282 |
|
CString tekst; |
283 |
|
|
284 |
|
for (int i=0; i<answer.size(); i++) |
285 |
|
{ |
286 |
|
if ((answer[i] != 0x0A) && (answer[i] != 0x0D)) |
287 |
|
{ |
288 |
|
tekst.AppendChar(answer[i]); |
289 |
|
} |
290 |
|
} |
291 |
|
int n = tekst.Find("WIND: 11",0); |
292 |
|
if (n > -1) |
293 |
|
{ |
294 |
|
ready = false; |
295 |
|
} |
296 |
|
else |
297 |
|
{ |
298 |
|
AppendText(tekst); |
299 |
|
} |
300 |
|
} |
301 |
|
Sleep(10); //Small delay to avoid busy wait |
302 |
|
} |
303 |
|
} |
304 |
|
else if (tekst.MakeLower() == "+cpin: ready") |
305 |
|
{ |
306 |
|
AppendText("No pincode needed"); |
307 |
|
} |
308 |
|
else |
309 |
|
{ |
310 |
|
AppendText("Error in pincode message"); |
311 |
|
} |
312 |
} |
} |
313 |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
314 |
{ |
{ |
442 |
HandleAcknowledge(TlfNr); |
HandleAcknowledge(TlfNr); |
443 |
return; |
return; |
444 |
} |
} |
445 |
|
CAtlRegExp<> regex; |
446 |
|
if (regex.Parse("^{[0-9]+}:{[0-9]+}:[0-1]:[0-1]:[0-1]:[0-1]:$") == REPARSE_ERROR_OK) |
447 |
|
{ |
448 |
|
|
449 |
|
CAtlREMatchContext<> pContext; |
450 |
|
|
451 |
|
if (!regex.Match(FyrData, &pContext)) |
452 |
|
{ |
453 |
|
AppendText("Invalid SMS recieved"); |
454 |
|
return; |
455 |
|
} |
456 |
|
} |
457 |
|
else |
458 |
|
{ |
459 |
|
AppendText("Regex PARSE error!!!"); //Burde aldrig kunne ske ! |
460 |
|
} |
461 |
|
|
462 |
SmsCount = Splitter(FyrData); |
SmsCount = Splitter(FyrData); |
463 |
Temper = Splitter(FyrData); |
Temper = Splitter(FyrData); |
464 |
Flamme = Splitter(FyrData); |
Flamme = Splitter(FyrData); |
506 |
{ |
{ |
507 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
508 |
continueThread = 0; |
continueThread = 0; |
509 |
|
Sleep(250); |
510 |
DeleteSms(); |
DeleteSms(); |
511 |
|
|
512 |
Sleep(500); |
Sleep(500); |
523 |
OnOK(); |
OnOK(); |
524 |
|
|
525 |
} |
} |
|
|
|
|
void CFlisServerDlg::OnBnClickedGsmpin() |
|
|
{ |
|
|
// TODO: Add your control notification handler code here |
|
|
bool ready = true; |
|
|
m_Textwindow.SetWindowText("Indsætter Pinkode, og venter på modem bliver klar"); |
|
|
UpdateWindow(); |
|
|
SetPin(); |
|
|
Sleep(500); |
|
|
|
|
|
while (ready == true) |
|
|
{ |
|
|
if (Serial.getComstat().cbInQue > 120) |
|
|
{ |
|
|
std::vector<unsigned char> answer = readFrame(); |
|
|
CString tekst; |
|
|
|
|
|
for (int i=0; i<answer.size(); i++) |
|
|
{ |
|
|
if ((answer[i] != 0x0A) && (answer[i] != 0x0D)) |
|
|
{ |
|
|
tekst.AppendChar(answer[i]); |
|
|
} |
|
|
} |
|
|
int n = tekst.Find("WIND: 11",0); |
|
|
if (n > -1) |
|
|
{ |
|
|
ready = false; |
|
|
} |
|
|
else |
|
|
{ |
|
|
AppendText(tekst); |
|
|
} |
|
|
} |
|
|
Sleep(5); //Small delay to avoid busy wait |
|
|
} |
|
|
Sleep(100); //Give the modem a chance to send the last data |
|
|
while(Serial.getComstat().cbInQue > 0) |
|
|
{ |
|
|
Serial.readByte(); //Flush the incoming queue |
|
|
Sleep(1); |
|
|
} |
|
|
OnBnClickedStart(); |
|
|
} |
|
526 |
void CFlisServerDlg::DeleteSms() |
void CFlisServerDlg::DeleteSms() |
527 |
{ |
{ |
528 |
vector<unsigned char> atcommand; |
vector<unsigned char> atcommand; |
557 |
{ |
{ |
558 |
while (continueThread != 0) |
while (continueThread != 0) |
559 |
{ |
{ |
560 |
Reader(); |
MyMainThread(); |
561 |
} |
} |
562 |
} |
} |
563 |
void CFlisServerDlg::Reader() |
void CFlisServerDlg::MyMainThread() |
564 |
{ |
{ |
565 |
if(Serial.getComstat().cbInQue > 0) |
if(Serial.getComstat().cbInQue > 0) |
566 |
{ |
{ |
568 |
std::vector<unsigned char> answer = readFrame(); |
std::vector<unsigned char> answer = readFrame(); |
569 |
Sleep(500); |
Sleep(500); |
570 |
CString tekst, oldtekst; |
CString tekst, oldtekst; |
|
int lol; |
|
571 |
|
|
572 |
for (int i=0; i<answer.size(); i++) |
for (int i=0; i<answer.size(); i++) |
573 |
{ |
{ |
694 |
{ |
{ |
695 |
SendConfig(sIDnr,sCommandID,sInstallationsID); |
SendConfig(sIDnr,sCommandID,sInstallationsID); |
696 |
} |
} |
697 |
Sleep(500); |
Sleep(300); |
698 |
|
|
699 |
CheckAcknowledges(); |
CheckAcknowledges(); |
700 |
Sleep(500); |
Sleep(500); |
782 |
CString SQL, Textwindow; |
CString SQL, Textwindow; |
783 |
SQL.Format("update command set executed=now() where id=%s",IDnr); |
SQL.Format("update command set executed=now() where id=%s",IDnr); |
784 |
db.ExecuteSQL(SQL); |
db.ExecuteSQL(SQL); |
785 |
|
Sleep(100); |
786 |
AppendText("Command executed"); |
AppendText("Command executed"); |
787 |
} |
} |
788 |
Sleep(150); |
Sleep(150); |
845 |
void CFlisServerDlg::OnBnClickedStart() |
void CFlisServerDlg::OnBnClickedStart() |
846 |
{ |
{ |
847 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
848 |
|
|
849 |
|
m_Textwindow.SetWindowText("Indsætter Pinkode, og venter på modem bliver klar, hvis pinkode er nødvendig"); |
850 |
|
UpdateWindow(); |
851 |
|
SetPin(); |
852 |
|
|
853 |
|
Sleep(100); //Give the modem a chance to send the last data |
854 |
|
while(Serial.getComstat().cbInQue > 0) |
855 |
|
{ |
856 |
|
Serial.readByte(); //Flush the incoming queue |
857 |
|
Sleep(1); |
858 |
|
} |
859 |
|
|
860 |
continueThread = 1; |
continueThread = 1; |
861 |
keepaliveandread(); |
keepaliveandread(); |
871 |
Tekst.Append("\r\n"); |
Tekst.Append("\r\n"); |
872 |
Tekst.Append(s); |
Tekst.Append(s); |
873 |
m_Textwindow.SetWindowText(Tekst); |
m_Textwindow.SetWindowText(Tekst); |
874 |
|
Sleep(5); |
875 |
|
int g = m_Textwindow.GetScrollLimit(SB_VERT); |
876 |
|
if (g > 0) |
877 |
|
{ |
878 |
|
m_Textwindow.SetSel(m_Textwindow.GetWindowTextLength() -1,m_Textwindow.GetWindowTextLength(),false); |
879 |
|
} |
880 |
|
|
881 |
} |
} |
882 |
void ConfigFile::ReadSettings() |
void ConfigFile::ReadSettings() |
963 |
} |
} |
964 |
} |
} |
965 |
|
|
966 |
void CFlisServerDlg::DumpAckList() |
void CFlisServerDlg::DumpAckList() /* Debug tool */ |
967 |
{ |
{ |
968 |
|
|
969 |
CTime now = CTime::GetCurrentTime(); |
CTime now = CTime::GetCurrentTime(); |
970 |
OutputDebugString("-------------------------------\n"); |
OutputDebugString("-------------------------------\n"); |
971 |
int count = 0; |
int count = 0; |
1022 |
DBConnect(); |
DBConnect(); |
1023 |
AppendText("DB connection started again"); |
AppendText("DB connection started again"); |
1024 |
} |
} |
1025 |
|
return buffer; |
1026 |
} |
} |
1027 |
|
|
1028 |
|
|
|
} |
|
1029 |
|
} |