5 |
#include "FlisServer.h" |
#include "FlisServer.h" |
6 |
#include "FlisServerDlg.h" |
#include "FlisServerDlg.h" |
7 |
#include <vector> |
#include <vector> |
8 |
|
#include ".\flisserverdlg.h" |
9 |
|
|
10 |
#ifdef _DEBUG |
#ifdef _DEBUG |
11 |
#define new DEBUG_NEW |
#define new DEBUG_NEW |
65 |
ON_WM_QUERYDRAGICON() |
ON_WM_QUERYDRAGICON() |
66 |
ON_MESSAGE(UWM_MYMESSAGE, OnShowString) |
ON_MESSAGE(UWM_MYMESSAGE, OnShowString) |
67 |
//}}AFX_MSG_MAP |
//}}AFX_MSG_MAP |
|
ON_BN_CLICKED(IDC_test, OnBnClickedtest) |
|
68 |
ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) |
ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) |
69 |
ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin) |
ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin) |
70 |
|
ON_BN_CLICKED(IDC_Start, OnBnClickedStart) |
71 |
END_MESSAGE_MAP() |
END_MESSAGE_MAP() |
72 |
|
|
73 |
|
|
103 |
// TODO: Add extra initialization here |
// TODO: Add extra initialization here |
104 |
StartSerial(); |
StartSerial(); |
105 |
DBConnect(); |
DBConnect(); |
|
continueThread = 1; |
|
106 |
ResetSms = 0; |
ResetSms = 0; |
|
/* |
|
|
////////////Start Tråd//////////////////////// |
|
|
MyThread *t = new MyThread(AfxGetMainWnd()); |
|
|
t->start(); |
|
|
////////////Start Tråd//////////////////////// |
|
|
*/ |
|
|
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
|
107 |
|
|
108 |
return TRUE; // return TRUE unless you set the focus to a control |
return TRUE; // return TRUE unless you set the focus to a control |
109 |
} |
} |
184 |
} |
} |
185 |
return buf; |
return buf; |
186 |
} |
} |
|
void CFlisServerDlg::OnBnClickedtest() |
|
|
{ |
|
|
// TODO: Add your control notification handler code here |
|
|
|
|
|
/* |
|
|
///////////////Send sms stuff///////////////// |
|
|
vector<unsigned char> tlfnr; |
|
|
vector<unsigned char> smsdata; |
|
|
tlfnr.push_back('2'); |
|
|
tlfnr.push_back('9'); |
|
|
tlfnr.push_back('7'); |
|
|
tlfnr.push_back('2'); |
|
|
tlfnr.push_back('2'); |
|
|
tlfnr.push_back('6'); |
|
|
tlfnr.push_back('0'); |
|
|
tlfnr.push_back('3'); |
|
|
|
|
|
SendSmsHead(tlfnr); |
|
187 |
|
|
|
//35:29860132:75 <--- demo pakke; |
|
|
vector<unsigned char> smsdata; |
|
|
smsdata.push_back('3'); |
|
|
smsdata.push_back('5'); |
|
|
smsdata.push_back(':'); |
|
|
smsdata.push_back('2'); |
|
|
smsdata.push_back('9'); |
|
|
smsdata.push_back('8'); |
|
|
smsdata.push_back('6'); |
|
|
smsdata.push_back('0'); |
|
|
smsdata.push_back('1'); |
|
|
smsdata.push_back('3'); |
|
|
smsdata.push_back('2'); |
|
|
smsdata.push_back(':'); |
|
|
smsdata.push_back('7'); |
|
|
smsdata.push_back('5'); |
|
|
|
|
|
SendSmsData(smsdata); |
|
|
///////////////Send sms stuff///////////////// |
|
|
*/ |
|
|
|
|
|
} |
|
188 |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
189 |
{ |
{ |
190 |
for (int i=0; i<data.size(); i++) |
for (int i=0; i<data.size(); i++) |
391 |
FremFejl = Splitter(FyrData); |
FremFejl = Splitter(FyrData); |
392 |
PowerFail = Splitter(FyrData); |
PowerFail = Splitter(FyrData); |
393 |
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
394 |
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
///////////////////// Her skal sendes data til databasen ////NÅR HEDIN KAN SENDE SMS/////////////////// |
395 |
m_Textwindow.GetWindowText(oldtekst); |
m_Textwindow.GetWindowText(oldtekst); |
396 |
oldtekst.Append("\r\n"); |
oldtekst.Append("\r\n"); |
397 |
oldtekst.Append("På næste linie kommer SmsCount. \r\n"); |
oldtekst.Append("På næste linie kommer SmsCount. \r\n"); |
455 |
{ |
{ |
456 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
457 |
SetPin(); |
SetPin(); |
458 |
//Sleep(5000); |
Sleep(35000); |
459 |
|
OnBnClickedStart(); |
460 |
} |
} |
461 |
void CFlisServerDlg::DeleteSms() |
void CFlisServerDlg::DeleteSms() |
462 |
{ |
{ |
591 |
writeFrame(data); |
writeFrame(data); |
592 |
Sleep(200); |
Sleep(200); |
593 |
ReadSms(); |
ReadSms(); |
594 |
|
ResetSms++; |
595 |
|
|
596 |
} |
} |
597 |
else if(command = "wind") |
else if(command = "wind") |
613 |
{ |
{ |
614 |
|
|
615 |
////////////////DBRead stuff////////////////// |
////////////////DBRead stuff////////////////// |
616 |
CString testdata, dataframe,testprint, sIDnr, sCommandID, sInstallationsID; |
CString testdata, dataframe,testprint, sIDnr, sCommandID, sInstallationsID, sImei; |
617 |
std::vector<Commands> data; |
std::vector<Commands> data; |
618 |
data = DBRead(); |
data = DBRead(); |
619 |
for (int i=0; i<data.size(); i++) |
for (int i=0; i<data.size(); i++) |
629 |
sCommandID = Splitter(testdata); |
sCommandID = Splitter(testdata); |
630 |
sInstallationsID = Splitter(testdata); |
sInstallationsID = Splitter(testdata); |
631 |
|
|
|
testprint.Append("sIDnr på næste linie\r\n"); |
|
|
testprint.Append(sIDnr); |
|
|
testprint.Append("\r\n"); |
|
|
testprint.Append("sCommandID på næste linie\r\n"); |
|
|
testprint.Append(sCommandID); |
|
|
testprint.Append("\r\n"); |
|
|
testprint.Append("sInstallationsID på næste linie\r\n"); |
|
|
testprint.Append(sInstallationsID); |
|
|
m_Textwindow.SetWindowText(testprint); |
|
|
|
|
|
|
|
632 |
if (sIDnr.GetLength() > 0) |
if (sIDnr.GetLength() > 0) |
633 |
{ |
{ |
634 |
DBReadData(sIDnr,sCommandID,sInstallationsID); |
DBReadData(sIDnr,sCommandID,sInstallationsID); |
639 |
} |
} |
640 |
void CFlisServerDlg::DBReadData(CString IDnr,CString CommandID,CString InstallationsID) |
void CFlisServerDlg::DBReadData(CString IDnr,CString CommandID,CString InstallationsID) |
641 |
{ |
{ |
642 |
CString TlfNr; |
CString TlfNr, Imei, ServerTlfNr, updaterate; |
643 |
|
|
644 |
|
ServerTlfNr = "29860132"; |
645 |
|
|
646 |
//kald dbreadphone som du kalder dbread |
//kald dbreadphone som du kalder dbread |
647 |
std::vector<Installation> inst; |
std::vector<Installation> inst; |
650 |
{ |
{ |
651 |
CString dataen = inst[i].InstPhoneNr; |
CString dataen = inst[i].InstPhoneNr; |
652 |
TlfNr.Append(dataen); |
TlfNr.Append(dataen); |
653 |
|
CString Imeidata = inst[i].Imei; |
654 |
|
Imei.Append(Imeidata); |
655 |
|
CString updaterat = inst[i].Updaterate; |
656 |
|
updaterate.Append(updaterat); |
657 |
} |
} |
658 |
vector<unsigned char> tlfnr; |
vector<unsigned char> tlfnr; |
659 |
for (int i=0; i<TlfNr.GetLength(); i++) |
for (int i=0; i<TlfNr.GetLength(); i++) |
660 |
{ |
{ |
661 |
tlfnr.push_back(TlfNr[i]); |
tlfnr.push_back(TlfNr[i]); |
662 |
} |
} |
663 |
|
|
664 |
|
int calcimei; |
665 |
|
double buf; |
666 |
|
Imei.Remove('0'); |
667 |
|
|
668 |
|
buf = atof(Imei); |
669 |
|
|
670 |
|
calcimei = tversum(buf); |
671 |
|
|
672 |
|
Imei.Format("%d",calcimei); |
673 |
|
|
674 |
SendSmsHead(tlfnr); |
SendSmsHead(tlfnr); |
675 |
Sleep(500); |
Sleep(500); |
676 |
//35:29860132:75 <--- demo pakke; |
//35:29860132:75 <--- demo pakke; |
677 |
vector<unsigned char> smsdata; |
vector<unsigned char> smsdata; |
678 |
smsdata.push_back('3'); |
|
679 |
smsdata.push_back('5'); |
for (int i=0; i<Imei.GetLength(); i++) |
680 |
|
{ |
681 |
|
smsdata.push_back(Imei[i]); |
682 |
|
} |
683 |
smsdata.push_back(':'); |
smsdata.push_back(':'); |
684 |
smsdata.push_back('2'); |
for (int i=0; i<ServerTlfNr.GetLength(); i++) |
685 |
smsdata.push_back('9'); |
{ |
686 |
smsdata.push_back('8'); |
smsdata.push_back(ServerTlfNr[i]); |
687 |
smsdata.push_back('6'); |
} |
|
smsdata.push_back('0'); |
|
|
smsdata.push_back('1'); |
|
|
smsdata.push_back('3'); |
|
|
smsdata.push_back('2'); |
|
688 |
smsdata.push_back(':'); |
smsdata.push_back(':'); |
689 |
smsdata.push_back('7'); |
for (int i=0; i<updaterate.GetLength(); i++) |
690 |
smsdata.push_back('5'); |
{ |
691 |
|
smsdata.push_back(updaterate[i]); |
692 |
|
} |
693 |
|
|
694 |
SendSmsData(smsdata); |
SendSmsData(smsdata); |
695 |
Sleep(250); |
Sleep(250); |
699 |
SQL.Format("update command set executed=now() where id=%s",IDnr); |
SQL.Format("update command set executed=now() where id=%s",IDnr); |
700 |
db.ExecuteSQL(SQL); |
db.ExecuteSQL(SQL); |
701 |
Sleep(150); |
Sleep(150); |
702 |
|
|
703 |
} |
} |
704 |
vector<Installation> CFlisServerDlg::DBReadPhone(CString sInstallationsID) |
vector<Installation> CFlisServerDlg::DBReadPhone(CString sInstallationsID) |
705 |
{ |
{ |
706 |
vector<Installation> buffer; |
vector<Installation> buffer; |
707 |
|
|
708 |
CString SQL, phonenr; |
CString SQL, phonenr, imei, updaterate; |
709 |
SQL.Format("select installationphonenr from installation WHERE id = %s",sInstallationsID); |
SQL.Format("select installationphonenr, imei, updaterate from installation WHERE id = %s",sInstallationsID); |
710 |
CRecordset rs(&db); |
CRecordset rs(&db); |
711 |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
712 |
if (rs.GetRecordCount()>0) |
if (rs.GetRecordCount()>0) |
716 |
{ |
{ |
717 |
Installation Myinst; |
Installation Myinst; |
718 |
rs.GetFieldValue((short)0,phonenr); |
rs.GetFieldValue((short)0,phonenr); |
719 |
|
rs.GetFieldValue(1,imei); |
720 |
|
rs.GetFieldValue(2,updaterate); |
721 |
|
|
722 |
Myinst.InstPhoneNr.Append(phonenr); |
Myinst.InstPhoneNr.Append(phonenr); |
723 |
|
Myinst.Imei.Append(imei); |
724 |
|
Myinst.Updaterate.Append(updaterate); |
725 |
|
|
726 |
buffer.push_back(Myinst); |
buffer.push_back(Myinst); |
727 |
rs.MoveNext(); |
rs.MoveNext(); |
729 |
} |
} |
730 |
rs.Close(); |
rs.Close(); |
731 |
return buffer; |
return buffer; |
|
} |
|
732 |
|
} |
733 |
|
int CFlisServerDlg::tversum(unsigned input) |
734 |
|
{ |
735 |
|
int sum = 0; |
736 |
|
while (input > 0) |
737 |
|
{ |
738 |
|
sum += (input %10); |
739 |
|
input /= 10; |
740 |
|
} |
741 |
|
return sum; |
742 |
|
} |
743 |
|
void CFlisServerDlg::OnBnClickedStart() |
744 |
|
{ |
745 |
|
// TODO: Add your control notification handler code here |
746 |
|
|
747 |
|
continueThread = 1; |
748 |
|
|
749 |
|
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
750 |
|
} |