--- trunk/FlisServer/FlisServerDlg.cpp 2007/12/04 13:48:52 146 +++ trunk/FlisServer/FlisServerDlg.cpp 2007/12/10 07:25:35 209 @@ -6,6 +6,7 @@ #include "FlisServerDlg.h" #include #include ".\flisserverdlg.h" +#include #ifdef _DEBUG #define new DEBUG_NEW @@ -65,7 +66,6 @@ ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) - ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin) ON_BN_CLICKED(IDC_Start, OnBnClickedStart) END_MESSAGE_MAP() @@ -224,8 +224,10 @@ } void CFlisServerDlg::SetPin() { + bool ready = true; CString tekst; std::vector data; + data.push_back('a'); data.push_back('t'); data.push_back('+'); @@ -233,13 +235,96 @@ data.push_back('p'); data.push_back('i'); data.push_back('n'); - data.push_back('='); - data.push_back('2'); - data.push_back('5'); - data.push_back('9'); - data.push_back('5'); + data.push_back('?'); writeFrame(data); + Sleep(100); + if(Serial.getComstat().cbInQue > 0) + { + std::vector answer = readFrame(); + Sleep(50); + + for (int i=0; i 0) { @@ -361,9 +446,7 @@ } void CFlisServerDlg::SmsSplit(CString data) { - CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail, oldtekst; - char CharData[150]; - strcpy(CharData,data); + CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail; TlfNr = data.Mid(24,8); FyrData = data.Mid(57,data.GetLength()-59); FyrData.Append(":"); @@ -373,7 +456,23 @@ HandleAcknowledge(TlfNr); return; } - + CAtlRegExp<> regex; + if (regex.Parse("^{[0-9]+}:{[0-9]+}:[0-1]:[0-1]:[0-1]:[0-1]:$") == REPARSE_ERROR_OK) + { + + CAtlREMatchContext<> pContext; + + if (!regex.Match(FyrData, &pContext)) + { + AppendText("Invalid SMS recieved"); + return; + } + } + else + { + AppendText("Regex PARSE error!!!"); //Burde aldrig kunne ske ! + } + SmsCount = Splitter(FyrData); Temper = Splitter(FyrData); Flamme = Splitter(FyrData); @@ -421,6 +520,7 @@ { // TODO: Add your control notification handler code here continueThread = 0; + Sleep(250); DeleteSms(); Sleep(500); @@ -437,49 +537,6 @@ OnOK(); } - -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 answer = readFrame(); - CString tekst; - - for (int i=0; i -1) - { - ready = false; - } - else - { - AppendText(tekst); - } - } - } - 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(); -} void CFlisServerDlg::DeleteSms() { vector atcommand; @@ -514,18 +571,17 @@ { while (continueThread != 0) { - Reader(); + MyMainThread(); } } -void CFlisServerDlg::Reader() +void CFlisServerDlg::MyMainThread() { if(Serial.getComstat().cbInQue > 0) { Sleep(250); std::vector answer = readFrame(); Sleep(500); - CString tekst, oldtekst; - int lol; + CString tekst; 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]); - } - m_Textwindow.GetWindowText(oldteskst); - oldteskst.Append("\r\n"); - 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]); + } + AppendText(CString(&data[0])); + writeFrame(data); + Sleep(200); + ReadSms(); } else if(command.MakeLower() == "wind") @@ -652,7 +701,7 @@ { SendConfig(sIDnr,sCommandID,sInstallationsID); } - Sleep(500); + Sleep(300); CheckAcknowledges(); Sleep(500); @@ -740,6 +789,7 @@ CString SQL, Textwindow; SQL.Format("update command set executed=now() where id=%s",IDnr); db.ExecuteSQL(SQL); + Sleep(100); AppendText("Command executed"); } Sleep(150); @@ -802,21 +852,42 @@ void CFlisServerDlg::OnBnClickedStart() { // TODO: Add your control notification handler code here - + + AppendText("Indsætter Pinkode, og venter på modem bliver klar, hvis pinkode er nødvendig"); + UpdateWindow(); + SetPin(); + + 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); + } + Sleep(5); + continueThread = 1; keepaliveandread(); Sleep(150); - m_Textwindow.SetWindowText(CString("Server phonenr read from db: ") + Alive.Phonenr ); + AppendText(CString("Server phonenr read from db: ") + Alive.Phonenr ); AppendText("Started"); AfxBeginThread(threadWrapper,AfxGetMainWnd()); } void CFlisServerDlg::AppendText(CString s) { + CTime now = CTime::GetCurrentTime(); CString Tekst; m_Textwindow.GetWindowText(Tekst); - Tekst.Append("\r\n"); + Tekst.AppendFormat("%02d:%02d:%02d : ", now.GetHour(), now.GetMinute(), now.GetSecond()); Tekst.Append(s); + Tekst.Append("\r\n"); + m_Textwindow.SetWindowText(Tekst); + Sleep(5); + int g = m_Textwindow.GetScrollLimit(SB_VERT); + if (g > 0) + { + m_Textwindow.SetSel(m_Textwindow.GetWindowTextLength() -1,m_Textwindow.GetWindowTextLength(),false); + } } void ConfigFile::ReadSettings() @@ -848,6 +919,8 @@ database = value; else if (key == "comport") comport = value; + else if (key == "pincode") + pincode = value; } } @@ -903,8 +976,9 @@ } } -void CFlisServerDlg::DumpAckList() +void CFlisServerDlg::DumpAckList() /* Debug tool */ { + CTime now = CTime::GetCurrentTime(); OutputDebugString("-------------------------------\n"); int count = 0; @@ -961,7 +1035,8 @@ DBConnect(); AppendText("DB connection started again"); } + return buffer; } -} \ No newline at end of file +}