102 |
// TODO: Add extra initialization here |
// TODO: Add extra initialization here |
103 |
StartSerial(); |
StartSerial(); |
104 |
DBConnect(); |
DBConnect(); |
105 |
continueThread = true; |
continueThread = 1; |
106 |
//AfxBeginThread(MyMainThread,0,THREAD_PRIORITY_NORMAL,0,0,NULL); |
ResetSms = 0; |
107 |
|
/* |
108 |
|
////////////Start Tråd//////////////////////// |
109 |
|
MyThread *t = new MyThread(AfxGetMainWnd()); |
110 |
|
t->start(); |
111 |
|
////////////Start Tråd//////////////////////// |
112 |
|
*/ |
113 |
|
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
114 |
|
|
115 |
return TRUE; // return TRUE unless you set the focus to a control |
return TRUE; // return TRUE unless you set the focus to a control |
116 |
} |
} |
195 |
{ |
{ |
196 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
197 |
|
|
|
/* |
|
|
////////////////DBRead stuff////////////////// |
|
|
CString testdata; |
|
|
std::vector<Commands> data; |
|
|
data = DBRead(); |
|
|
for (int i=0; i<data.size(); i++) |
|
|
{ |
|
|
testdata.Append(data[i].IDnr); |
|
|
testdata.Append(data[i].CommandID); |
|
|
testdata.Append(data[i].InstallationsID); |
|
|
} |
|
|
m_Textwindow.SetWindowText(testdata); |
|
|
////////////////DBRead stuff////////////////// |
|
|
*/ |
|
198 |
/* |
/* |
199 |
///////////////Send sms stuff///////////////// |
///////////////Send sms stuff///////////////// |
200 |
vector<unsigned char> tlfnr; |
vector<unsigned char> tlfnr; |
211 |
SendSmsHead(tlfnr); |
SendSmsHead(tlfnr); |
212 |
|
|
213 |
//35:29860132:75 <--- demo pakke; |
//35:29860132:75 <--- demo pakke; |
214 |
|
vector<unsigned char> smsdata; |
215 |
smsdata.push_back('3'); |
smsdata.push_back('3'); |
216 |
smsdata.push_back('5'); |
smsdata.push_back('5'); |
217 |
smsdata.push_back(':'); |
smsdata.push_back(':'); |
230 |
SendSmsData(smsdata); |
SendSmsData(smsdata); |
231 |
///////////////Send sms stuff///////////////// |
///////////////Send sms stuff///////////////// |
232 |
*/ |
*/ |
|
/* |
|
|
////////////Start Tråd//////////////////////// |
|
|
MyThread *t = new MyThread(AfxGetMainWnd()); |
|
|
t->start(); |
|
|
////////////Start Tråd//////////////////////// |
|
|
*/ |
|
|
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
|
233 |
|
|
234 |
} |
} |
235 |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
261 |
data.push_back('5'); |
data.push_back('5'); |
262 |
|
|
263 |
writeFrame(data); |
writeFrame(data); |
264 |
Sleep(750); |
/* Sleep(750); |
265 |
if(Serial.getComstat().cbInQue > 0) |
if(Serial.getComstat().cbInQue > 0) |
266 |
{ |
{ |
267 |
std::vector<unsigned char> answer = readFrame(); |
std::vector<unsigned char> answer = readFrame(); |
282 |
} |
} |
283 |
m_Textwindow.SetWindowText(tekst); |
m_Textwindow.SetWindowText(tekst); |
284 |
} |
} |
285 |
|
*/ |
286 |
} |
} |
287 |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
288 |
{ |
{ |
418 |
char CharData[150]; |
char CharData[150]; |
419 |
strcpy(CharData,data); |
strcpy(CharData,data); |
420 |
|
|
421 |
int s=22; |
int s=24; |
422 |
for (int i=0; i<=7; i++) |
for (int i=0; i<=7; i++) |
423 |
{ |
{ |
424 |
TlfNr.AppendChar(CharData[s]); |
TlfNr.AppendChar(CharData[s]); |
425 |
s++; |
s++; |
426 |
} |
} |
427 |
|
|
428 |
for (int s=55; s<=(data.GetLength()-3); s++) |
for (int s=57; s<=(data.GetLength()-3); s++) |
429 |
{ |
{ |
430 |
FyrData.AppendChar(CharData[s]); |
FyrData.AppendChar(CharData[s]); |
431 |
} |
} |
480 |
void CFlisServerDlg::OnBnClickedClose() |
void CFlisServerDlg::OnBnClickedClose() |
481 |
{ |
{ |
482 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
483 |
continueThread = false; |
continueThread = 0; |
484 |
|
DeleteSms(); //<--- crasher, men gider ikke bruge flere af mine penge på at teste det med sms'er, hele close laver crash, bare ikke når jeg stepper. :S |
485 |
|
|
486 |
|
Sleep(500); |
487 |
if( Serial.isOpen() ) |
if( Serial.isOpen() ) |
488 |
{ |
{ |
489 |
Serial.close(); |
Serial.close(); |
493 |
{ |
{ |
494 |
db.Close(); |
db.Close(); |
495 |
} |
} |
496 |
DeleteSms(); |
|
497 |
OnOK(); |
OnOK(); |
498 |
|
|
499 |
} |
} |
500 |
|
|
501 |
void CFlisServerDlg::OnBnClickedGsmpin() |
void CFlisServerDlg::OnBnClickedGsmpin() |
502 |
{ |
{ |
503 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
504 |
SetPin(); |
SetPin(); |
505 |
Sleep(5000); |
//Sleep(5000); |
506 |
} |
} |
507 |
void CFlisServerDlg::DeleteSms() |
void CFlisServerDlg::DeleteSms() |
508 |
{ |
{ |
521 |
|
|
522 |
writeFrame(atcommand); |
writeFrame(atcommand); |
523 |
Sleep(500); |
Sleep(500); |
|
if(Serial.getComstat().cbInQue > 0) |
|
|
{ |
|
|
std::vector<unsigned char> answer = readFrame(); |
|
|
Sleep(50); |
|
|
CString tekst, oldtekst; |
|
|
char array1[250]; |
|
|
int i; |
|
|
for (int i=0; i<answer.size(); i++) |
|
|
{ |
|
|
array1[i] = answer[i]; |
|
|
} |
|
|
|
|
|
for (int i=0; i<answer.size(); i++) |
|
|
{ |
|
|
if ((array1[i] != 0x0A) && (array1[i] != 0x0D)) |
|
|
{ |
|
|
tekst.AppendChar(array1[i]); |
|
|
} |
|
|
} |
|
|
if(tekst == "OK") |
|
|
{ |
|
|
m_Textwindow.GetWindowText(oldtekst); |
|
|
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append("Old Sms messages deleted"); |
|
|
m_Textwindow.SetWindowText(oldtekst); |
|
|
} |
|
|
else |
|
|
{ |
|
|
m_Textwindow.GetWindowText(oldtekst); |
|
|
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append(tekst); |
|
|
m_Textwindow.SetWindowText(oldtekst); |
|
|
} |
|
|
} |
|
524 |
} |
} |
525 |
LRESULT CFlisServerDlg::OnShowString(WPARAM wParam, LPARAM lParam) |
LRESULT CFlisServerDlg::OnShowString(WPARAM wParam, LPARAM lParam) |
526 |
{ |
{ |
544 |
|
|
545 |
void CFlisServerDlg::runthread() |
void CFlisServerDlg::runthread() |
546 |
{ |
{ |
547 |
int count = 0; |
while (continueThread != 0) |
|
while (continueThread = true) |
|
548 |
{ |
{ |
549 |
Reader(); |
Reader(); |
550 |
} |
} |
551 |
} |
} |
552 |
void CFlisServerDlg::Reader() |
void CFlisServerDlg::Reader() |
553 |
{ |
{ |
554 |
int ResetSms = 0; |
if(Serial.getComstat().cbInQue > 0) |
|
while(1) |
|
|
{ |
|
|
if(Serial.getComstat().cbInQue > 0) |
|
555 |
{ |
{ |
556 |
|
Sleep(250); |
557 |
std::vector<unsigned char> answer = readFrame(); |
std::vector<unsigned char> answer = readFrame(); |
558 |
Sleep(500); |
Sleep(500); |
559 |
CString tekst, oldtekst; |
CString tekst, oldtekst; |
606 |
{ |
{ |
607 |
if (command = "cmti") |
if (command = "cmti") |
608 |
{ |
{ |
609 |
CString smscount; |
CString smscount, oldteskst; |
610 |
int pos = tekst.Find(',',0); |
int pos = tekst.Find(',',0); |
611 |
if (pos != -1) |
if (pos != -1) |
612 |
{ |
{ |
629 |
{ |
{ |
630 |
data.push_back(smscount[i]); |
data.push_back(smscount[i]); |
631 |
} |
} |
632 |
|
for (int i=0; i<data.size();i++) |
633 |
|
{ |
634 |
|
oldteskst.AppendChar(data[i]); |
635 |
|
} |
636 |
|
m_Textwindow.SetWindowText(oldteskst); |
637 |
writeFrame(data); |
writeFrame(data); |
638 |
|
Sleep(200); |
639 |
ReadSms(); |
ReadSms(); |
640 |
|
|
641 |
} |
} |
642 |
|
else if(command = "wind") |
643 |
|
{ |
644 |
|
m_Textwindow.GetWindowText(oldtekst); |
645 |
|
oldtekst.Append("\r\n"); |
646 |
|
oldtekst.Append("Først lidt tekst på næste linie\r\n"); |
647 |
|
oldtekst.Append(tekst); |
648 |
|
m_Textwindow.SetWindowText(oldtekst); |
649 |
|
} |
650 |
} |
} |
651 |
if(ResetSms >= 50) |
if(ResetSms == 50) |
652 |
{ |
{ |
653 |
DeleteSms(); |
DeleteSms(); |
654 |
} |
} |
655 |
|
|
656 |
|
} |
657 |
|
if (continueThread = 1) |
658 |
|
{ |
659 |
|
|
660 |
|
////////////////DBRead stuff////////////////// |
661 |
|
CString testdata, dataframe,testprint, sIDnr, sCommandID, sInstallationsID; |
662 |
|
std::vector<Commands> data; |
663 |
|
data = DBRead(); |
664 |
|
for (int i=0; i<data.size(); i++) |
665 |
|
{ |
666 |
|
testdata.Append(data[i].IDnr); |
667 |
|
testdata.Append(":"); |
668 |
|
testdata.Append(data[i].CommandID); |
669 |
|
testdata.Append(":"); |
670 |
|
testdata.Append(data[i].InstallationsID); |
671 |
|
testdata.Append(":"); |
672 |
|
} |
673 |
|
sIDnr = Splitter(testdata); |
674 |
|
sCommandID = Splitter(testdata); |
675 |
|
sInstallationsID = Splitter(testdata); |
676 |
|
|
677 |
|
testprint.Append("sIDnr på næste linie\r\n"); |
678 |
|
testprint.Append(sIDnr); |
679 |
|
testprint.Append("\r\n"); |
680 |
|
testprint.Append("sCommandID på næste linie\r\n"); |
681 |
|
testprint.Append(sCommandID); |
682 |
|
testprint.Append("\r\n"); |
683 |
|
testprint.Append("sInstallationsID på næste linie\r\n"); |
684 |
|
testprint.Append(sInstallationsID); |
685 |
|
m_Textwindow.SetWindowText(testprint); |
686 |
|
|
687 |
|
|
688 |
|
if (sIDnr.GetLength() > 0) |
689 |
|
{ |
690 |
|
DBReadData(sIDnr,sCommandID,sInstallationsID); |
691 |
|
} |
692 |
|
Sleep(500); |
693 |
|
////////////////DBRead stuff////////////////// |
694 |
} |
} |
695 |
|
} |
696 |
|
void CFlisServerDlg::DBReadData(CString IDnr,CString CommandID,CString InstallationsID) |
697 |
|
{ |
698 |
|
CString TlfNr; |
699 |
|
|
700 |
|
//kald dbreadphone som du kalder dbread |
701 |
|
std::vector<Installation> inst; |
702 |
|
inst = DBReadPhone(InstallationsID); |
703 |
|
for (int i=0; i<inst.size(); i++) |
704 |
|
{ |
705 |
|
CString dataen = inst[i].InstPhoneNr; |
706 |
|
TlfNr.Append(dataen); |
707 |
} |
} |
708 |
|
vector<unsigned char> tlfnr; |
709 |
|
for (int i=0; i<TlfNr.GetLength(); i++) |
710 |
|
{ |
711 |
|
tlfnr.push_back(TlfNr[i]); |
712 |
|
} |
713 |
|
|
714 |
|
SendSmsHead(tlfnr); |
715 |
|
Sleep(500); |
716 |
|
//35:29860132:75 <--- demo pakke; |
717 |
|
vector<unsigned char> smsdata; |
718 |
|
smsdata.push_back('3'); |
719 |
|
smsdata.push_back('5'); |
720 |
|
smsdata.push_back(':'); |
721 |
|
smsdata.push_back('2'); |
722 |
|
smsdata.push_back('9'); |
723 |
|
smsdata.push_back('8'); |
724 |
|
smsdata.push_back('6'); |
725 |
|
smsdata.push_back('0'); |
726 |
|
smsdata.push_back('1'); |
727 |
|
smsdata.push_back('3'); |
728 |
|
smsdata.push_back('2'); |
729 |
|
smsdata.push_back(':'); |
730 |
|
smsdata.push_back('7'); |
731 |
|
smsdata.push_back('5'); |
732 |
|
|
733 |
|
SendSmsData(smsdata); |
734 |
|
Sleep(250); |
735 |
|
|
736 |
|
CString SQL; |
737 |
|
|
738 |
|
SQL.Format("update command set executed=now() where id=%s",IDnr); |
739 |
|
db.ExecuteSQL(SQL); |
740 |
|
Sleep(150); |
741 |
|
} |
742 |
|
vector<Installation> CFlisServerDlg::DBReadPhone(CString sInstallationsID) |
743 |
|
{ |
744 |
|
vector<Installation> buffer; |
745 |
|
|
746 |
|
CString SQL, phonenr; |
747 |
|
SQL.Format("select installationphonenr from installation WHERE id = %s",sInstallationsID); |
748 |
|
CRecordset rs(&db); |
749 |
|
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
750 |
|
if (rs.GetRecordCount()>0) |
751 |
|
{ |
752 |
|
rs.MoveFirst(); |
753 |
|
while(!rs.IsEOF()) |
754 |
|
{ |
755 |
|
Installation Myinst; |
756 |
|
rs.GetFieldValue((short)0,phonenr); |
757 |
|
|
758 |
|
Myinst.InstPhoneNr.Append(phonenr); |
759 |
|
|
760 |
|
buffer.push_back(Myinst); |
761 |
|
rs.MoveNext(); |
762 |
|
} |
763 |
|
} |
764 |
|
rs.Close(); |
765 |
|
return buffer; |
766 |
} |
} |