--- trunk/FlisServer/FlisServerDlg.cpp 2007/12/03 11:46:03 132 +++ trunk/FlisServer/FlisServerDlg.cpp 2007/12/03 14:13:20 136 @@ -63,7 +63,6 @@ ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() - ON_MESSAGE(UWM_MYMESSAGE, OnShowString) //}}AFX_MSG_MAP ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin) @@ -158,20 +157,45 @@ } int CFlisServerDlg::StartSerial(void) { + int Baud; - CString SerialPort = "COM3"; + ConfigFile config; + try { + config.ReadSettings(); + } catch(...) { + MessageBox("Could not open config file"); + OnOK(); + return true; + } + Baud = 1200; if( Serial.isOpen() ) { - Serial.close(); - Serial.open( SerialPort, Baud ); + try + { + Serial.close(); + Serial.open( config.comport, Baud ); + } + catch (exception* e) + { + MessageBox( "Serial.open() exception" ); + return 0; + } } - else + else { - Serial.open( SerialPort, Baud ); + try + { + Serial.open( config.comport, Baud ); + } + catch (exception* e) + { + MessageBox( "Serial.open() exception 2" ); + return 0; + } } - + return 0; } @@ -232,25 +256,19 @@ CString tekst; std::vector answer = readFrame(); Sleep(50); - char array1[150]; - int i; - for (int i=0; i data) +void CFlisServerDlg::SendSmsHead(std::vector tlfnr) { vector atcommand; atcommand.push_back('a'); @@ -270,9 +288,9 @@ Sleep(5); } - for (int i=0; i CFlisServerDlg::DBRead(void) +vector CFlisServerDlg::DBReadCommands(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;"; + SQL = "select id,date_trunc('second', created) as created,executed,commandid,installationid from command WHERE executed IS NULL ORDER BY created ASC LIMIT 1;"; 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; + 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(); - buffer.push_back(Mycom); - rs.MoveNext(); - } } rs.Close(); return buffer; @@ -318,30 +341,21 @@ void CFlisServerDlg::ReadSms() { CString tekst, oldtekst; - Sleep(950); + Sleep(950); //Holder en pause for at lade hele sms'en komme ind i serial køen. if(Serial.getComstat().cbInQue > 0) { std::vector answer = readFrame(); - Sleep(50); - char array1[250]; - int i; - for (int i=0; iSetWindowText(*s); - - delete s; - return 0; - -}UINT threadWrapper(LPVOID thread) +UINT threadWrapper(LPVOID thread) { CFlisServerDlg *t = (CFlisServerDlg*) thread; t->runthread(); @@ -497,18 +487,12 @@ Sleep(500); CString tekst, oldtekst; int lol; - char array1[250]; - int i; - for (int i=0; i data; - data = DBRead(); + data = DBReadCommands(); for (int i=0; i 1) { - testdata.Append(data[i].InstallationsID); - testdata.Append(":"); + sInstallationsID = data[i].InstallationsID; } } sIDnr = Splitter(testdata); @@ -642,12 +617,12 @@ if (sIDnr.GetLength() > 0) { - DBReadData(sIDnr,sCommandID,sInstallationsID); + SendConfig(sIDnr,sCommandID,sInstallationsID); } Sleep(500); } } -void CFlisServerDlg::DBReadData(CString IDnr,CString CommandID,CString InstallationsID) +void CFlisServerDlg::SendConfig(CString IDnr,CString CommandID,CString InstallationsID) { CString ServerTlfNr; int i = 0; @@ -713,10 +688,7 @@ CString SQL, Textwindow; SQL.Format("update command set executed=now() where id=%s",IDnr); db.ExecuteSQL(SQL); - m_Textwindow.GetWindowText(Textwindow); - Textwindow.Append("\r\n"); - Textwindow.Append("Command executed"); - m_Textwindow.SetWindowText(Textwindow); + AppendText("Command executed"); Sleep(150); } @@ -777,3 +749,47 @@ m_Textwindow.SetWindowText("Started"); AfxBeginThread(threadWrapper,AfxGetMainWnd()); } +void CFlisServerDlg::AppendText(CString s) +{ + CString Tekst; + m_Textwindow.GetWindowText(Tekst); + Tekst.Append("\r\n"); + Tekst.Append(s); + m_Textwindow.SetWindowText(Tekst); + +} +void ConfigFile::ReadSettings() +{ + ifstream file("Server-Settings.ini"); + if (!file.is_open()) + throw("Could not open file"); + + char buf[200]; + while (!file.eof() ) { + file.getline(buf,200); + CString tmp(buf); + + if (tmp.GetAt(0) == '#') + continue; + + int pos = tmp.Find('='); + if (pos>0) { + CString key = tmp.Left(pos).Trim().MakeLower();; + CString value = tmp.Right(tmp.GetLength()-pos-1).Trim(); + + if (key == "host") + host = value; + else if (key == "username") + username = value; + else if (key == "password") + password = value; + else if (key == "database") + database = value; + else if (key == "comport") + comport = value; + } + + } + + file.close(); +} \ No newline at end of file