--- trunk/FlisServer/FlisServerDlg.cpp 2007/12/04 17:32:44 149 +++ trunk/FlisServer/FlisServerDlg.cpp 2007/12/08 09:45:58 191 @@ -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,7 +446,7 @@ } void CFlisServerDlg::SmsSplit(CString data) { - CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail, oldtekst; + CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail; char CharData[150]; strcpy(CharData,data); TlfNr = data.Mid(24,8); @@ -373,7 +458,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 +522,7 @@ { // TODO: Add your control notification handler code here continueThread = 0; + Sleep(250); DeleteSms(); Sleep(500); @@ -437,50 +539,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(5); //Small delay to avoid busy wait - } - 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; @@ -515,18 +573,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 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() @@ -849,6 +922,8 @@ database = value; else if (key == "comport") comport = value; + else if (key == "pincode") + pincode = value; } } @@ -904,8 +979,9 @@ } } -void CFlisServerDlg::DumpAckList() +void CFlisServerDlg::DumpAckList() /* Debug tool */ { + CTime now = CTime::GetCurrentTime(); OutputDebugString("-------------------------------\n"); int count = 0; @@ -962,7 +1038,8 @@ DBConnect(); AppendText("DB connection started again"); } + return buffer; } -} \ No newline at end of file +}