/[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 103 by kevin, Thu Nov 29 16:16:34 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  END_MESSAGE_MAP()  END_MESSAGE_MAP()
70    
71    
# Line 101  BOOL CFlisServerDlg::OnInitDialog() Line 100  BOOL CFlisServerDlg::OnInitDialog()
100    
101          // TODO: Add extra initialization here          // TODO: Add extra initialization here
102          StartSerial();          StartSerial();
103          SetPin();          //SetPin();
104            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    ////////////////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                    testdata.Append(data[i].IDnr);
214                    testdata.Append(data[i].CommandID);
215                    testdata.Append(data[i].InstallationsID);
216            }
217            m_Textwindow.SetWindowText(testdata);
218    ////////////////DBRead stuff//////////////////  
219    */
220    /*      
221    ///////////////Send sms stuff/////////////////
222            vector<unsigned char> tlfnr;
223            vector<unsigned char> smsdata;
224            tlfnr.push_back('2');
225            tlfnr.push_back('9');
226            tlfnr.push_back('7');
227            tlfnr.push_back('2');
228            tlfnr.push_back('2');
229            tlfnr.push_back('6');
230            tlfnr.push_back('0');
231            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            Sleep(2000);
253          if(Serial.getComstat().cbInQue > 0)          if(Serial.getComstat().cbInQue > 0)
254          {          {
255          std::vector<unsigned char> answer = readFrame();                  CString tekst;
256          Sleep(50);                  std::vector<unsigned char> answer = readFrame();
257          if (answer.size() == 0){                  Sleep(50);
258                  m_Textwindow.SetWindowText("ØV");                          char array1[25];
259          }                          int i;
260          else{                          for (int i=0; i<answer.size(); i++)
261                  CString ko;                          {
262                  char test[150];                                  array1[i] = answer[i];
263                  int i;                          }
264                  for (int i=0; i<answer.size(); i++)                  
265                  {                          for (int i=0; i<answer.size(); i++)
266                          test[i] = answer[i];                          {
267                  }                                  if ((array1[i] != 0x0A) && (array1[i] != 0x0D))
268                  ko = test;                                  {
269                  m_Textwindow.SetWindowText(ko);                                          tekst.AppendChar(array1[i]);
270          }                                  }
271                            }
272                            m_Textwindow.SetWindowText(tekst);
273          }          }
274          */  ///////////////Send sms stuff/////////////////
275          SetPin();  */
276  }  }
277  void CFlisServerDlg::writeFrame(std::vector<unsigned char> data)  void CFlisServerDlg::writeFrame(std::vector<unsigned char> data)
278  {  {
# Line 245  void CFlisServerDlg::writeFrame(std::vec Line 287  void CFlisServerDlg::writeFrame(std::vec
287  }  }
288  int CFlisServerDlg::SetPin(void)  int CFlisServerDlg::SetPin(void)
289  {  {
290          CString tekst, oldtekst;          CString tekst;
291          std::vector<unsigned char> data;          std::vector<unsigned char> data;
292          data.push_back('a');          data.push_back('a');
293          data.push_back('t');          data.push_back('t');
# Line 280  int CFlisServerDlg::SetPin(void) Line 322  int CFlisServerDlg::SetPin(void)
322                                          tekst.AppendChar(array1[i]);                                          tekst.AppendChar(array1[i]);
323                                  }                                  }
324                          }                          }
325                            m_Textwindow.SetWindowText(tekst);
                         m_Textwindow.GetWindowText(oldtekst);  
                         oldtekst.Append("\r\n");  
                         oldtekst.Append(tekst);  
                         m_Textwindow.SetWindowText(oldtekst);  
326          }          }
327  return 0;  return 0;
328  }  }
329  void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data)  void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data)
330  {  {      
331            
332          for (int i=0; i<data.size(); i++)          for (int i=0; i<data.size(); i++)
333          {          {
334                  Serial.writeByte( data[i] );                  Serial.writeByte( data[i] );
335                  Sleep(5);                  Sleep(5);
336          }          }
337          Serial.writeByte(0x1A);          Serial.writeByte(0x1A);
338          Sleep(100);          Sleep(500);
339    
340  }  }
341  void CFlisServerDlg::SendSmsHead(std::vector<unsigned char> data)  void CFlisServerDlg::SendSmsHead(std::vector<unsigned char> data)
342  {  {
343            vector<unsigned char> atcommand;
344            atcommand.push_back('a');
345            atcommand.push_back('t');
346            atcommand.push_back('+');
347            atcommand.push_back('c');
348            atcommand.push_back('m');
349            atcommand.push_back('g');
350            atcommand.push_back('s');
351            atcommand.push_back('=');
352            atcommand.push_back('"');
353            int s = (atcommand.size() -1 );
354            
355            for (int i=0; i<(atcommand.size()); i++)
356            {
357                    Serial.writeByte( atcommand[i] );
358                    Sleep(5);
359            }
360            
361          for (int i=0; i<data.size(); i++)          for (int i=0; i<data.size(); i++)
362          {          {
363                  Serial.writeByte( data[i] );                  Serial.writeByte( data[i] );
364                  Sleep(5);                  Sleep(5);
365          }          }
366            Serial.writeByte(atcommand[s]);
367          Serial.writeByte(0x0D);          Serial.writeByte(0x0D);
368          Sleep(100);          Sleep(250);
   
369  }  }
370  void CFlisServerDlg::DBconnect()  void CFlisServerDlg::DBConnect()
371  {  {
372          CString dsn;          CString dsn;
373          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");
374          db.OpenEx(dsn, CDatabase::noOdbcDialog);          db.OpenEx(dsn, CDatabase::noOdbcDialog);
 }  
375    }
376    vector<Commands> CFlisServerDlg::DBRead(void)
377    {
378            vector<Commands> buffer;
379    
380            CString SQL, IDnr, CommandID, InstallationsID;
381            SQL = "select id,date_trunc('second', created) as created,executed,commandid,installationid from command WHERE executed IS NULL;";
382            CRecordset rs(&db);
383            rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL);
384            if (rs.GetRecordCount()>0)
385            {
386                    rs.MoveFirst();
387                    while(!rs.IsEOF())
388                    {
389                    Commands Mycom;
390                    rs.GetFieldValue((short)0, IDnr);
391                    rs.GetFieldValue(3, CommandID);
392                    rs.GetFieldValue(4, InstallationsID);
393                    
394                    Mycom.IDnr = IDnr;
395                    Mycom.CommandID = CommandID;
396                    Mycom.InstallationsID = InstallationsID;
397    
398                    buffer.push_back(Mycom);
399                    rs.MoveNext();
400                    }
401            }
402            rs.Close();
403            return buffer;
404    }
405    void CFlisServerDlg::ReadSms()
406    {
407            CString tekst, oldtekst;
408            Sleep(950);
409            if(Serial.getComstat().cbInQue > 0)
410            {
411                    std::vector<unsigned char> answer = readFrame();
412                    Sleep(50);
413                            char array1[250];
414                            int i;
415                            for (int i=0; i<answer.size(); i++)
416                            {
417                                    array1[i] = answer[i];
418                            }
419                    
420                            for (int i=0; i<answer.size(); i++)
421                            {
422                                    if ((array1[i] != 0x0A) && (array1[i] != 0x0D))
423                                    {
424                                            tekst.AppendChar(array1[i]);
425                                    }
426                            }
427    
428                            m_Textwindow.GetWindowText(oldtekst);
429                            oldtekst.Append("\r\n");
430                            oldtekst.Append(tekst);
431                            m_Textwindow.SetWindowText(oldtekst);
432                            SmsSplit(tekst);
433            }
434    }
435    void CFlisServerDlg::SmsSplit(CString data)
436    {
437            CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail, oldtekst;
438            char CharData[150];
439            strcpy(CharData,data);
440    
441            int s=22;
442            for (int i=0; i<=7; i++)
443            {
444                    TlfNr.AppendChar(CharData[s]);
445                    s++;
446            }
447    
448            for (int s=55; s<=(data.GetLength()-3); s++)
449            {
450                    FyrData.AppendChar(CharData[s]);
451            }
452            FyrData.Append(":");
453            
454            SmsCount = Splitter(FyrData);
455            Temper = Splitter(FyrData);
456            Flamme = Splitter(FyrData);
457            Flis = Splitter(FyrData);
458            FremFejl = Splitter(FyrData);
459            PowerFail = Splitter(FyrData);
460    ///////////////////////////////////////////////////////////////////////////////////////////////////////
461    ///////////////////// Her skal sendes data til databasen //////////////////////////////////////////////
462                    m_Textwindow.GetWindowText(oldtekst);
463                    oldtekst.Append("\r\n");
464                    oldtekst.Append("På næste linie kommer SmsCount. \r\n");
465                    oldtekst.Append(SmsCount);
466                    oldtekst.Append("\r\n");
467                    oldtekst.Append("På næste linie kommer Temper. \r\n");
468                    oldtekst.Append(Temper);
469                    oldtekst.Append("\r\n");
470                    oldtekst.Append("På næste linie kommer Flamme. \r\n");
471                    oldtekst.Append(Flamme);
472                    oldtekst.Append("\r\n");
473                    oldtekst.Append("På næste linie kommer Flis. \r\n");
474                    oldtekst.Append(Flis);
475                    oldtekst.Append("\r\n");
476                    oldtekst.Append("På næste linie kommer FremFejl. \r\n");
477                    oldtekst.Append(FremFejl);
478                    oldtekst.Append("\r\n");
479                    oldtekst.Append("På næste linie kommer PowerFail. \r\n");
480                    oldtekst.Append(PowerFail);
481                    m_Textwindow.SetWindowText(oldtekst);
482    ///////////////////////////////////////////////////////////////////////////////////////////////////////
483    ///////////////////// Her skal sendes data til databasen //////////////////////////////////////////////
484    }
485    CString CFlisServerDlg::Splitter(CString& fyrdata)
486    {
487            CString Output;
488    
489            int pos = fyrdata.Find(':',0);
490            if (pos != -1)
491                    {
492                            Output = fyrdata.Left(pos);
493                            fyrdata = fyrdata.Right( fyrdata.GetLength() - pos -1);
494                    }
495            return Output;
496    }
497    void CFlisServerDlg::OnBnClickedClose()
498    {
499            // TODO: Add your control notification handler code here
500            
501            if( Serial.isOpen() )
502            {
503                    Serial.close();
504            }
505            
506            if(db.IsOpen())
507            {
508            db.Close();
509            }
510            OnOK();
511    }

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

  ViewVC Help
Powered by ViewVC 1.1.20