/[H9]/trunk/FlisServer/FlisServerDlg.cpp
ViewVC logotype

Diff of /trunk/FlisServer/FlisServerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 70 by kevin, Tue Nov 27 15:26:42 2007 UTC revision 105 by kevin, Fri Nov 30 07:24:35 2007 UTC
# Line 64  BEGIN_MESSAGE_MAP(CFlisServerDlg, CDialo Line 64  BEGIN_MESSAGE_MAP(CFlisServerDlg, CDialo
64          ON_WM_PAINT()          ON_WM_PAINT()
65          ON_WM_QUERYDRAGICON()          ON_WM_QUERYDRAGICON()
66          //}}AFX_MSG_MAP          //}}AFX_MSG_MAP
         ON_BN_CLICKED(IDOK, OnBnClickedOk)  
         ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)  
67          ON_BN_CLICKED(IDC_test, OnBnClickedtest)          ON_BN_CLICKED(IDC_test, OnBnClickedtest)
68            ON_BN_CLICKED(IDCLOSE, OnBnClickedClose)
69            ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin)
70  END_MESSAGE_MAP()  END_MESSAGE_MAP()
71    
72    
# Line 101  BOOL CFlisServerDlg::OnInitDialog() Line 101  BOOL CFlisServerDlg::OnInitDialog()
101    
102          // TODO: Add extra initialization here          // TODO: Add extra initialization here
103          StartSerial();          StartSerial();
104          SetPin();          DBConnect();
105                    
106          return TRUE;  // return TRUE  unless you set the focus to a control          return TRUE;  // return TRUE  unless you set the focus to a control
107  }  }
# Line 182  std::vector<unsigned char> CFlisServerDl Line 182  std::vector<unsigned char> CFlisServerDl
182          }          }
183          return buf;          return buf;
184  }  }
 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();  
         }  
 }  
   
185  void CFlisServerDlg::OnBnClickedtest()  void CFlisServerDlg::OnBnClickedtest()
186  {  {
187          // TODO: Add your control notification handler code here          // TODO: Add your control notification handler code here
188          /*  /*      
189    ////////////////Read sms ting//////////////////
190            CString tekst;
191          std::vector<unsigned char> data;          std::vector<unsigned char> data;
192          data.push_back('a');          data.push_back('a');
193          data.push_back('t');          data.push_back('t');
194            data.push_back('+');
195            data.push_back('c');
196            data.push_back('m');
197            data.push_back('g');
198            data.push_back('r');
199            data.push_back('=');
200            data.push_back('1');
201    
202          writeFrame(data);          writeFrame(data);
203            ReadSms();
204          if(Serial.getComstat().cbInQue > 0)  ////////////////Read sms ting//////////////////
205    */
206    /*
207    ////////////////DBRead stuff//////////////////
208            CString testdata;
209            std::vector<Commands> data;
210            data = DBRead();
211            for (int i=0; i<data.size(); i++)
212          {          {
213          std::vector<unsigned char> answer = readFrame();                  testdata.Append(data[i].IDnr);
214          Sleep(50);                  testdata.Append(data[i].CommandID);
215          if (answer.size() == 0){                  testdata.Append(data[i].InstallationsID);
216                  m_Textwindow.SetWindowText("ØV");          }
217          }          m_Textwindow.SetWindowText(testdata);
218          else{  ////////////////DBRead stuff//////////////////  
219                  CString ko;  */
220                  char test[150];  /*      
221                  int i;  ///////////////Send sms stuff/////////////////
222                  for (int i=0; i<answer.size(); i++)          vector<unsigned char> tlfnr;
223                  {          vector<unsigned char> smsdata;
224                          test[i] = answer[i];          tlfnr.push_back('2');
225                  }          tlfnr.push_back('9');
226                  ko = test;          tlfnr.push_back('7');
227                  m_Textwindow.SetWindowText(ko);          tlfnr.push_back('2');
228          }          tlfnr.push_back('2');
229          }          tlfnr.push_back('6');
230          */          tlfnr.push_back('0');
231          SetPin();          tlfnr.push_back('3');
232    
233            SendSmsHead(tlfnr);
234    
235             //35:29860132:75 <--- demo pakke;
236            smsdata.push_back('3');
237            smsdata.push_back('5');
238            smsdata.push_back(':');
239            smsdata.push_back('2');
240            smsdata.push_back('9');
241            smsdata.push_back('8');
242            smsdata.push_back('6');
243            smsdata.push_back('0');
244            smsdata.push_back('1');
245            smsdata.push_back('3');
246            smsdata.push_back('2');
247            smsdata.push_back(':');
248            smsdata.push_back('7');
249            smsdata.push_back('5');
250    
251            SendSmsData(smsdata);
252    ///////////////Send sms stuff/////////////////
253    */
254  }  }
255  void CFlisServerDlg::writeFrame(std::vector<unsigned char> data)  void CFlisServerDlg::writeFrame(std::vector<unsigned char> data)
256  {  {
# Line 245  void CFlisServerDlg::writeFrame(std::vec Line 265  void CFlisServerDlg::writeFrame(std::vec
265  }  }
266  int CFlisServerDlg::SetPin(void)  int CFlisServerDlg::SetPin(void)
267  {  {
268          CString tekst, oldtekst;          CString tekst;
269          std::vector<unsigned char> data;          std::vector<unsigned char> data;
270          data.push_back('a');          data.push_back('a');
271          data.push_back('t');          data.push_back('t');
# Line 280  int CFlisServerDlg::SetPin(void) Line 300  int CFlisServerDlg::SetPin(void)
300                                          tekst.AppendChar(array1[i]);                                          tekst.AppendChar(array1[i]);
301                                  }                                  }
302                          }                          }
303                            m_Textwindow.SetWindowText(tekst);
                         m_Textwindow.GetWindowText(oldtekst);  
                         oldtekst.Append("\r\n");  
                         oldtekst.Append(tekst);  
                         m_Textwindow.SetWindowText(oldtekst);  
304          }          }
305  return 0;  return 0;
306  }  }
307  void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data)  void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data)
308  {  {      
309            
310          for (int i=0; i<data.size(); i++)          for (int i=0; i<data.size(); i++)
311          {          {
312                  Serial.writeByte( data[i] );                  Serial.writeByte( data[i] );
313                  Sleep(5);                  Sleep(5);
314          }          }
315          Serial.writeByte(0x1A);          Serial.writeByte(0x1A);
316          Sleep(100);          Sleep(3000);
317            if(Serial.getComstat().cbInQue > 0)
318            {
319                    CString tekst;
320                    std::vector<unsigned char> answer = readFrame();
321                    Sleep(50);
322                            char array1[25];
323                            int i;
324                            for (int i=0; i<answer.size(); i++)
325                            {
326                                    array1[i] = answer[i];
327                            }
328                    
329                            for (int i=0; i<answer.size(); i++)
330                            {
331                                    if ((array1[i] != 0x0A) && (array1[i] != 0x0D))
332                                    {
333                                            tekst.AppendChar(array1[i]);
334                                    }
335                            }
336                            m_Textwindow.SetWindowText(tekst);
337            }
338    
339  }  }
340  void CFlisServerDlg::SendSmsHead(std::vector<unsigned char> data)  void CFlisServerDlg::SendSmsHead(std::vector<unsigned char> data)
341  {  {
342            vector<unsigned char> atcommand;
343            atcommand.push_back('a');
344            atcommand.push_back('t');
345            atcommand.push_back('+');
346            atcommand.push_back('c');
347            atcommand.push_back('m');
348            atcommand.push_back('g');
349            atcommand.push_back('s');
350            atcommand.push_back('=');
351            atcommand.push_back('"');
352            int s = (atcommand.size() -1 );
353            
354            for (int i=0; i<(atcommand.size()); i++)
355            {
356                    Serial.writeByte( atcommand[i] );
357                    Sleep(5);
358            }
359            
360          for (int i=0; i<data.size(); i++)          for (int i=0; i<data.size(); i++)
361          {          {
362                  Serial.writeByte( data[i] );                  Serial.writeByte( data[i] );
363                  Sleep(5);                  Sleep(5);
364          }          }
365            Serial.writeByte(atcommand[s]);
366          Serial.writeByte(0x0D);          Serial.writeByte(0x0D);
367          Sleep(100);          Sleep(250);
   
368  }  }
369  void CFlisServerDlg::DBconnect()  void CFlisServerDlg::DBConnect()
370  {  {
371          CString dsn;          CString dsn;
372          dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=%s; uid=%s;password=%s;database=%s",config.host, config.username, config.password, config.database);          dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=192.168.134.132; uid=serrenab;password=furnacemonitor;database=flisfyr;sslmode=prefer");
373          db.OpenEx(dsn, CDatabase::noOdbcDialog);          db.OpenEx(dsn, CDatabase::noOdbcDialog);
 }  
374    }
375    vector<Commands> CFlisServerDlg::DBRead(void)
376    {
377            vector<Commands> buffer;
378    
379            CString SQL, IDnr, CommandID, InstallationsID;
380            SQL = "select id,date_trunc('second', created) as created,executed,commandid,installationid from command WHERE executed IS NULL;";
381            CRecordset rs(&db);
382            rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL);
383            if (rs.GetRecordCount()>0)
384            {
385                    rs.MoveFirst();
386                    while(!rs.IsEOF())
387                    {
388                    Commands Mycom;
389                    rs.GetFieldValue((short)0, IDnr);
390                    rs.GetFieldValue(3, CommandID);
391                    rs.GetFieldValue(4, InstallationsID);
392                    
393                    Mycom.IDnr = IDnr;
394                    Mycom.CommandID = CommandID;
395                    Mycom.InstallationsID = InstallationsID;
396    
397                    buffer.push_back(Mycom);
398                    rs.MoveNext();
399                    }
400            }
401            rs.Close();
402            return buffer;
403    }
404    void CFlisServerDlg::ReadSms()
405    {
406            CString tekst, oldtekst;
407            Sleep(950);
408            if(Serial.getComstat().cbInQue > 0)
409            {
410                    std::vector<unsigned char> answer = readFrame();
411                    Sleep(50);
412                            char array1[250];
413                            int i;
414                            for (int i=0; i<answer.size(); i++)
415                            {
416                                    array1[i] = answer[i];
417                            }
418                    
419                            for (int i=0; i<answer.size(); i++)
420                            {
421                                    if ((array1[i] != 0x0A) && (array1[i] != 0x0D))
422                                    {
423                                            tekst.AppendChar(array1[i]);
424                                    }
425                            }
426    
427                            m_Textwindow.GetWindowText(oldtekst);
428                            oldtekst.Append("\r\n");
429                            oldtekst.Append(tekst);
430                            m_Textwindow.SetWindowText(oldtekst);
431                            SmsSplit(tekst);
432            }
433    }
434    void CFlisServerDlg::SmsSplit(CString data)
435    {
436            CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail, oldtekst;
437            char CharData[150];
438            strcpy(CharData,data);
439    
440            int s=22;
441            for (int i=0; i<=7; i++)
442            {
443                    TlfNr.AppendChar(CharData[s]);
444                    s++;
445            }
446    
447            for (int s=55; s<=(data.GetLength()-3); s++)
448            {
449                    FyrData.AppendChar(CharData[s]);
450            }
451            FyrData.Append(":");
452            
453            SmsCount = Splitter(FyrData);
454            Temper = Splitter(FyrData);
455            Flamme = Splitter(FyrData);
456            Flis = Splitter(FyrData);
457            FremFejl = Splitter(FyrData);
458            PowerFail = Splitter(FyrData);
459    ///////////////////////////////////////////////////////////////////////////////////////////////////////
460    ///////////////////// Her skal sendes data til databasen //////////////////////////////////////////////
461                    m_Textwindow.GetWindowText(oldtekst);
462                    oldtekst.Append("\r\n");
463                    oldtekst.Append("På næste linie kommer SmsCount. \r\n");
464                    oldtekst.Append(SmsCount);
465                    oldtekst.Append("\r\n");
466                    oldtekst.Append("På næste linie kommer Temper. \r\n");
467                    oldtekst.Append(Temper);
468                    oldtekst.Append("\r\n");
469                    oldtekst.Append("På næste linie kommer Flamme. \r\n");
470                    oldtekst.Append(Flamme);
471                    oldtekst.Append("\r\n");
472                    oldtekst.Append("På næste linie kommer Flis. \r\n");
473                    oldtekst.Append(Flis);
474                    oldtekst.Append("\r\n");
475                    oldtekst.Append("På næste linie kommer FremFejl. \r\n");
476                    oldtekst.Append(FremFejl);
477                    oldtekst.Append("\r\n");
478                    oldtekst.Append("På næste linie kommer PowerFail. \r\n");
479                    oldtekst.Append(PowerFail);
480                    m_Textwindow.SetWindowText(oldtekst);
481    ///////////////////////////////////////////////////////////////////////////////////////////////////////
482    ///////////////////// Her skal sendes data til databasen //////////////////////////////////////////////
483    }
484    CString CFlisServerDlg::Splitter(CString& fyrdata)
485    {
486            CString Output;
487    
488            int pos = fyrdata.Find(':',0);
489            if (pos != -1)
490                    {
491                            Output = fyrdata.Left(pos);
492                            fyrdata = fyrdata.Right( fyrdata.GetLength() - pos -1);
493                    }
494            return Output;
495    }
496    void CFlisServerDlg::OnBnClickedClose()
497    {
498            // TODO: Add your control notification handler code here
499            
500            if( Serial.isOpen() )
501            {
502                    Serial.close();
503            }
504            
505            if(db.IsOpen())
506            {
507            db.Close();
508            }
509            OnOK();
510    }
511    
512    void CFlisServerDlg::OnBnClickedGsmpin()
513    {
514            // TODO: Add your control notification handler code here
515            SetPin();
516    }

Legend:
Removed from v.70  
changed lines
  Added in v.105

  ViewVC Help
Powered by ViewVC 1.1.20