4 |
#include "stdafx.h" |
#include "stdafx.h" |
5 |
#include "FlisServer.h" |
#include "FlisServer.h" |
6 |
#include "FlisServerDlg.h" |
#include "FlisServerDlg.h" |
|
#include ".\flisserverdlg.h" |
|
7 |
#include <vector> |
#include <vector> |
8 |
|
|
9 |
#ifdef _DEBUG |
#ifdef _DEBUG |
62 |
ON_WM_SYSCOMMAND() |
ON_WM_SYSCOMMAND() |
63 |
ON_WM_PAINT() |
ON_WM_PAINT() |
64 |
ON_WM_QUERYDRAGICON() |
ON_WM_QUERYDRAGICON() |
65 |
|
ON_MESSAGE(UWM_MYMESSAGE, OnShowString) |
66 |
//}}AFX_MSG_MAP |
//}}AFX_MSG_MAP |
67 |
ON_BN_CLICKED(IDC_test, OnBnClickedtest) |
ON_BN_CLICKED(IDC_test, OnBnClickedtest) |
68 |
ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) |
ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) |
102 |
// TODO: Add extra initialization here |
// TODO: Add extra initialization here |
103 |
StartSerial(); |
StartSerial(); |
104 |
DBConnect(); |
DBConnect(); |
105 |
|
continueThread = true; |
106 |
|
//AfxBeginThread(MyMainThread,0,THREAD_PRIORITY_NORMAL,0,0,NULL); |
107 |
|
|
108 |
return TRUE; // return TRUE unless you set the focus to a control |
return TRUE; // return TRUE unless you set the focus to a control |
109 |
} |
} |
187 |
void CFlisServerDlg::OnBnClickedtest() |
void CFlisServerDlg::OnBnClickedtest() |
188 |
{ |
{ |
189 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
|
/* |
|
|
////////////////Read sms ting////////////////// |
|
|
CString tekst; |
|
|
std::vector<unsigned char> 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('='); |
|
|
data.push_back('1'); |
|
190 |
|
|
|
writeFrame(data); |
|
|
ReadSms(); |
|
|
////////////////Read sms ting////////////////// |
|
|
*/ |
|
191 |
/* |
/* |
192 |
////////////////DBRead stuff////////////////// |
////////////////DBRead stuff////////////////// |
193 |
CString testdata; |
CString testdata; |
236 |
SendSmsData(smsdata); |
SendSmsData(smsdata); |
237 |
///////////////Send sms stuff///////////////// |
///////////////Send sms stuff///////////////// |
238 |
*/ |
*/ |
239 |
|
/* |
240 |
|
////////////Start Tråd//////////////////////// |
241 |
|
MyThread *t = new MyThread(AfxGetMainWnd()); |
242 |
|
t->start(); |
243 |
|
////////////Start Tråd//////////////////////// |
244 |
|
*/ |
245 |
|
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
246 |
|
|
247 |
} |
} |
248 |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
249 |
{ |
{ |
256 |
Sleep(100); |
Sleep(100); |
257 |
|
|
258 |
} |
} |
259 |
int CFlisServerDlg::SetPin(void) |
void CFlisServerDlg::SetPin() |
260 |
{ |
{ |
261 |
CString tekst; |
CString tekst; |
262 |
std::vector<unsigned char> data; |
std::vector<unsigned char> data; |
295 |
} |
} |
296 |
m_Textwindow.SetWindowText(tekst); |
m_Textwindow.SetWindowText(tekst); |
297 |
} |
} |
|
return 0; |
|
298 |
} |
} |
299 |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
300 |
{ |
{ |
361 |
void CFlisServerDlg::DBConnect() |
void CFlisServerDlg::DBConnect() |
362 |
{ |
{ |
363 |
CString dsn; |
CString dsn; |
364 |
dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=192.168.134.132; uid=serrenab;password=furnacemonitor;database=flisfyr;sslmode=prefer"); |
dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=t-hoerup.dk; uid=serrenab;password=furnacemonitor;database=flisfyr;sslmode=prefer"); |
365 |
|
//dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=192.168.134.132; uid=serrenab;password=furnacemonitor;database=flisfyr;sslmode=prefer"); //skole server |
366 |
db.OpenEx(dsn, CDatabase::noOdbcDialog); |
db.OpenEx(dsn, CDatabase::noOdbcDialog); |
367 |
} |
} |
368 |
vector<Commands> CFlisServerDlg::DBRead(void) |
vector<Commands> CFlisServerDlg::DBRead(void) |
470 |
oldtekst.Append("\r\n"); |
oldtekst.Append("\r\n"); |
471 |
oldtekst.Append("På næste linie kommer PowerFail. \r\n"); |
oldtekst.Append("På næste linie kommer PowerFail. \r\n"); |
472 |
oldtekst.Append(PowerFail); |
oldtekst.Append(PowerFail); |
473 |
|
oldtekst.Append("\r\n"); |
474 |
|
oldtekst.Append("På næste linie kommer TlfNR. \r\n"); |
475 |
|
oldtekst.Append(TlfNr); |
476 |
m_Textwindow.SetWindowText(oldtekst); |
m_Textwindow.SetWindowText(oldtekst); |
477 |
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
478 |
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
492 |
void CFlisServerDlg::OnBnClickedClose() |
void CFlisServerDlg::OnBnClickedClose() |
493 |
{ |
{ |
494 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
495 |
|
continueThread = false; |
496 |
if( Serial.isOpen() ) |
if( Serial.isOpen() ) |
497 |
{ |
{ |
498 |
Serial.close(); |
Serial.close(); |
502 |
{ |
{ |
503 |
db.Close(); |
db.Close(); |
504 |
} |
} |
505 |
|
DeleteSms(); |
506 |
OnOK(); |
OnOK(); |
507 |
} |
} |
508 |
|
|
510 |
{ |
{ |
511 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
512 |
SetPin(); |
SetPin(); |
513 |
|
Sleep(5000); |
514 |
} |
} |
515 |
|
void CFlisServerDlg::DeleteSms() |
516 |
|
{ |
517 |
|
vector<unsigned char> atcommand; |
518 |
|
atcommand.push_back('a'); |
519 |
|
atcommand.push_back('t'); |
520 |
|
atcommand.push_back('+'); |
521 |
|
atcommand.push_back('c'); |
522 |
|
atcommand.push_back('m'); |
523 |
|
atcommand.push_back('g'); |
524 |
|
atcommand.push_back('d'); |
525 |
|
atcommand.push_back('='); |
526 |
|
atcommand.push_back('1'); |
527 |
|
atcommand.push_back(','); |
528 |
|
atcommand.push_back('3'); |
529 |
|
|
530 |
|
writeFrame(atcommand); |
531 |
|
Sleep(500); |
532 |
|
if(Serial.getComstat().cbInQue > 0) |
533 |
|
{ |
534 |
|
std::vector<unsigned char> answer = readFrame(); |
535 |
|
Sleep(50); |
536 |
|
CString tekst, oldtekst; |
537 |
|
char array1[250]; |
538 |
|
int i; |
539 |
|
for (int i=0; i<answer.size(); i++) |
540 |
|
{ |
541 |
|
array1[i] = answer[i]; |
542 |
|
} |
543 |
|
|
544 |
|
for (int i=0; i<answer.size(); i++) |
545 |
|
{ |
546 |
|
if ((array1[i] != 0x0A) && (array1[i] != 0x0D)) |
547 |
|
{ |
548 |
|
tekst.AppendChar(array1[i]); |
549 |
|
} |
550 |
|
} |
551 |
|
if(tekst == "OK") |
552 |
|
{ |
553 |
|
m_Textwindow.GetWindowText(oldtekst); |
554 |
|
oldtekst.Append("\r\n"); |
555 |
|
oldtekst.Append("Old Sms messages deleted"); |
556 |
|
m_Textwindow.SetWindowText(oldtekst); |
557 |
|
} |
558 |
|
else |
559 |
|
{ |
560 |
|
m_Textwindow.GetWindowText(oldtekst); |
561 |
|
oldtekst.Append("\r\n"); |
562 |
|
oldtekst.Append(tekst); |
563 |
|
m_Textwindow.SetWindowText(oldtekst); |
564 |
|
} |
565 |
|
} |
566 |
|
} |
567 |
|
LRESULT CFlisServerDlg::OnShowString(WPARAM wParam, LPARAM lParam) |
568 |
|
{ |
569 |
|
CString *s = (CString*) lParam; |
570 |
|
GetDlgItem(IDC_Textwindow)->SetWindowText(*s); |
571 |
|
|
572 |
|
delete s; |
573 |
|
return 0; |
574 |
|
|
575 |
|
}UINT threadWrapper(LPVOID thread) |
576 |
|
{ |
577 |
|
CFlisServerDlg *t = (CFlisServerDlg*) thread; |
578 |
|
t->runthread(); |
579 |
|
return 0; |
580 |
|
} |
581 |
|
|
582 |
|
void CFlisServerDlg::startthread() |
583 |
|
{ |
584 |
|
AfxBeginThread(threadWrapper, (LPVOID) this); |
585 |
|
} |
586 |
|
|
587 |
|
void CFlisServerDlg::runthread() |
588 |
|
{ |
589 |
|
int count = 0; |
590 |
|
while (continueThread = true) |
591 |
|
{ |
592 |
|
Reader(); |
593 |
|
} |
594 |
|
} |
595 |
|
void CFlisServerDlg::Reader() |
596 |
|
{ |
597 |
|
int ResetSms = 0; |
598 |
|
while(1) |
599 |
|
{ |
600 |
|
if(Serial.getComstat().cbInQue > 0) |
601 |
|
{ |
602 |
|
std::vector<unsigned char> answer = readFrame(); |
603 |
|
Sleep(500); |
604 |
|
CString tekst, oldtekst; |
605 |
|
int lol; |
606 |
|
char array1[250]; |
607 |
|
int i; |
608 |
|
for (int i=0; i<answer.size(); i++) |
609 |
|
{ |
610 |
|
array1[i] = answer[i]; |
611 |
|
} |
612 |
|
|
613 |
|
for (int i=0; i<answer.size(); i++) |
614 |
|
{ |
615 |
|
if ((array1[i] != 0x0A) && (array1[i] != 0x0D)) |
616 |
|
{ |
617 |
|
tekst.AppendChar(array1[i]); |
618 |
|
} |
619 |
|
} |
620 |
|
tekst.Append(":"); |
621 |
|
|
622 |
|
CString command; |
623 |
|
bool plus; |
624 |
|
int pos = tekst.Find('+',0); |
625 |
|
if (pos != -1) |
626 |
|
{ |
627 |
|
plus = true; |
628 |
|
tekst = tekst.Right( tekst.GetLength() - pos -1); |
629 |
|
pos = tekst.Find(':'); |
630 |
|
command = tekst.Left(pos); |
631 |
|
tekst = tekst.Right( tekst.GetLength() - pos -1); |
632 |
|
} |
633 |
|
|
634 |
|
|
635 |
|
if(tekst == "OK") |
636 |
|
{ |
637 |
|
m_Textwindow.GetWindowText(oldtekst); |
638 |
|
oldtekst.Append("\r\n"); |
639 |
|
oldtekst.Append("OK tekst modtaget"); |
640 |
|
m_Textwindow.SetWindowText(oldtekst); |
641 |
|
} |
642 |
|
else if (tekst == "error") |
643 |
|
{ |
644 |
|
m_Textwindow.GetWindowText(oldtekst); |
645 |
|
oldtekst.Append("\r\n"); |
646 |
|
oldtekst.Append("error tekst"); |
647 |
|
oldtekst.Append(tekst); |
648 |
|
m_Textwindow.SetWindowText(oldtekst); |
649 |
|
} |
650 |
|
else if (plus = true) |
651 |
|
{ |
652 |
|
if (command = "cmti") |
653 |
|
{ |
654 |
|
CString smscount; |
655 |
|
int pos = tekst.Find(',',0); |
656 |
|
if (pos != -1) |
657 |
|
{ |
658 |
|
smscount = tekst.Right( tekst.GetLength() - pos -1); |
659 |
|
smscount.Remove(':'); |
660 |
|
ResetSms++; |
661 |
|
} |
662 |
|
////////////////Read sms ting////////////////// |
663 |
|
std::vector<unsigned char> data; |
664 |
|
data.push_back('a'); |
665 |
|
data.push_back('t'); |
666 |
|
data.push_back('+'); |
667 |
|
data.push_back('c'); |
668 |
|
data.push_back('m'); |
669 |
|
data.push_back('g'); |
670 |
|
data.push_back('r'); |
671 |
|
data.push_back('='); |
672 |
|
|
673 |
|
for (int i=0; i< smscount.GetLength(); i++) |
674 |
|
{ |
675 |
|
data.push_back(smscount[i]); |
676 |
|
} |
677 |
|
|
678 |
|
writeFrame(data); |
679 |
|
ReadSms(); |
680 |
|
|
681 |
|
} |
682 |
|
} |
683 |
|
if(ResetSms >= 50) |
684 |
|
{ |
685 |
|
DeleteSms(); |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
|
} |
690 |
|
} |
691 |
|
} |