--- trunk/FlisServer/FlisServerDlg.cpp 2007/11/27 15:26:42 70 +++ trunk/FlisServer/FlisServerDlg.cpp 2007/12/02 12:03:03 121 @@ -4,8 +4,8 @@ #include "stdafx.h" #include "FlisServer.h" #include "FlisServerDlg.h" -#include ".\flisserverdlg.h" #include +#include ".\flisserverdlg.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -63,10 +63,11 @@ ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() + ON_MESSAGE(UWM_MYMESSAGE, OnShowString) //}}AFX_MSG_MAP - ON_BN_CLICKED(IDOK, OnBnClickedOk) - ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel) - ON_BN_CLICKED(IDC_test, OnBnClickedtest) + ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) + ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin) + ON_BN_CLICKED(IDC_Start, OnBnClickedStart) END_MESSAGE_MAP() @@ -101,7 +102,8 @@ // TODO: Add extra initialization here StartSerial(); - SetPin(); + DBConnect(); + ResetSms = 0; return TRUE; // return TRUE unless you set the focus to a control } @@ -182,56 +184,7 @@ } return buf; } -void CFlisServerDlg::OnBnClickedOk() -{ - // TODO: Add your control notification handler code here - OnOK(); - if( Serial.isOpen() ){ - Serial.close(); - } -} - -void CFlisServerDlg::OnBnClickedCancel() -{ - // TODO: Add your control notification handler code here - OnCancel(); - if( Serial.isOpen() ){ - Serial.close(); - } -} - -void CFlisServerDlg::OnBnClickedtest() -{ - // TODO: Add your control notification handler code here - /* - std::vector data; - data.push_back('a'); - data.push_back('t'); - writeFrame(data); - - if(Serial.getComstat().cbInQue > 0) - { - std::vector answer = readFrame(); - Sleep(50); - if (answer.size() == 0){ - m_Textwindow.SetWindowText("ØV"); - } - else{ - CString ko; - char test[150]; - int i; - for (int i=0; i data) { for (int i=0; i data; data.push_back('a'); data.push_back('t'); @@ -261,7 +214,7 @@ data.push_back('5'); writeFrame(data); - Sleep(750); +/* Sleep(750); if(Serial.getComstat().cbInQue > 0) { std::vector answer = readFrame(); @@ -280,39 +233,518 @@ tekst.AppendChar(array1[i]); } } - - m_Textwindow.GetWindowText(oldtekst); - oldtekst.Append("\r\n"); - oldtekst.Append(tekst); - m_Textwindow.SetWindowText(oldtekst); + m_Textwindow.SetWindowText(tekst); } -return 0; +*/ } void CFlisServerDlg::SendSmsData(std::vector data) -{ +{ + for (int i=0; i 0) + { + CString tekst; + std::vector answer = readFrame(); + Sleep(50); + char array1[25]; + int i; + for (int i=0; i data) { + vector atcommand; + atcommand.push_back('a'); + atcommand.push_back('t'); + atcommand.push_back('+'); + atcommand.push_back('c'); + atcommand.push_back('m'); + atcommand.push_back('g'); + atcommand.push_back('s'); + atcommand.push_back('='); + atcommand.push_back('"'); + int s = (atcommand.size() -1 ); + + for (int i=0; i<(atcommand.size()); i++) + { + Serial.writeByte( atcommand[i] ); + Sleep(5); + } + for (int i=0; i CFlisServerDlg::DBRead(void) +{ + vector buffer; + + CString SQL, IDnr, CommandID, InstallationsID; + SQL = "select id,date_trunc('second', created) as created,executed,commandid,installationid from command WHERE executed IS NULL;"; + CRecordset rs(&db); + rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); + if (rs.GetRecordCount()>0) + { + rs.MoveFirst(); + while(!rs.IsEOF()) + { + Commands Mycom; + rs.GetFieldValue((short)0, IDnr); + rs.GetFieldValue(3, CommandID); + rs.GetFieldValue(4, InstallationsID); + + Mycom.IDnr = IDnr; + Mycom.CommandID = CommandID; + Mycom.InstallationsID = InstallationsID; + + buffer.push_back(Mycom); + rs.MoveNext(); + } + } + rs.Close(); + return buffer; +} +void CFlisServerDlg::ReadSms() +{ + CString tekst, oldtekst; + Sleep(950); + if(Serial.getComstat().cbInQue > 0) + { + std::vector answer = readFrame(); + Sleep(50); + char array1[250]; + int i; + for (int i=0; i atcommand; + atcommand.push_back('a'); + atcommand.push_back('t'); + atcommand.push_back('+'); + atcommand.push_back('c'); + atcommand.push_back('m'); + atcommand.push_back('g'); + atcommand.push_back('d'); + atcommand.push_back('='); + atcommand.push_back('1'); + atcommand.push_back(','); + atcommand.push_back('3'); + + writeFrame(atcommand); + Sleep(500); +} +LRESULT CFlisServerDlg::OnShowString(WPARAM wParam, LPARAM lParam) +{ + CString *s = (CString*) lParam; + GetDlgItem(IDC_Textwindow)->SetWindowText(*s); + + delete s; + return 0; + +}UINT threadWrapper(LPVOID thread) +{ + CFlisServerDlg *t = (CFlisServerDlg*) thread; + t->runthread(); + return 0; +} + +void CFlisServerDlg::startthread() +{ + AfxBeginThread(threadWrapper, (LPVOID) this); +} + +void CFlisServerDlg::runthread() +{ + while (continueThread != 0) + { + Reader(); + } +} +void CFlisServerDlg::Reader() +{ + if(Serial.getComstat().cbInQue > 0) + { + Sleep(250); + std::vector answer = readFrame(); + Sleep(500); + CString tekst, oldtekst; + int lol; + char array1[250]; + int i; + for (int i=0; i data; + data.push_back('a'); + data.push_back('t'); + data.push_back('+'); + data.push_back('c'); + data.push_back('m'); + data.push_back('g'); + data.push_back('r'); + data.push_back('='); + + for (int i=0; i< smscount.GetLength(); i++) + { + data.push_back(smscount[i]); + } + for (int i=0; i data; + data = DBRead(); + for (int i=0; i 0) + { + DBReadData(sIDnr,sCommandID,sInstallationsID); + } + Sleep(500); + ////////////////DBRead stuff////////////////// + } +} +void CFlisServerDlg::DBReadData(CString IDnr,CString CommandID,CString InstallationsID) +{ + CString TlfNr, Imei, ServerTlfNr, updaterate; + + ServerTlfNr = "29860132"; + + //kald dbreadphone som du kalder dbread + std::vector inst; + inst = DBReadPhone(InstallationsID); + for (int i=0; i tlfnr; + for (int i=0; i smsdata; + + for (int i=0; i CFlisServerDlg::DBReadPhone(CString sInstallationsID) +{ + vector buffer; + + CString SQL, phonenr, imei, updaterate; + SQL.Format("select installationphonenr, imei, updaterate from installation WHERE id = %s",sInstallationsID); + CRecordset rs(&db); + rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); + if (rs.GetRecordCount()>0) + { + rs.MoveFirst(); + while(!rs.IsEOF()) + { + Installation Myinst; + rs.GetFieldValue((short)0,phonenr); + rs.GetFieldValue(1,imei); + rs.GetFieldValue(2,updaterate); + + Myinst.InstPhoneNr.Append(phonenr); + Myinst.Imei.Append(imei); + Myinst.Updaterate.Append(updaterate); + + buffer.push_back(Myinst); + rs.MoveNext(); + } + } + rs.Close(); + return buffer; +} +int CFlisServerDlg::tversum(unsigned input) +{ + int sum = 0; + while (input > 0) + { + sum += (input %10); + input /= 10; + } + return sum; +} +void CFlisServerDlg::OnBnClickedStart() +{ +// TODO: Add your control notification handler code here + + continueThread = 1; + + AfxBeginThread(threadWrapper,AfxGetMainWnd()); +}