162 |
CString SerialPort = "COM3"; |
CString SerialPort = "COM3"; |
163 |
|
|
164 |
Baud = 1200; |
Baud = 1200; |
165 |
if( Serial.isOpen() ){ |
if( Serial.isOpen() ) |
166 |
|
{ |
167 |
Serial.close(); |
Serial.close(); |
168 |
Serial.open( SerialPort, Baud ); |
Serial.open( SerialPort, Baud ); |
169 |
} |
} |
170 |
else { |
else |
171 |
|
{ |
172 |
Serial.open( SerialPort, Baud ); |
Serial.open( SerialPort, Baud ); |
173 |
} |
} |
174 |
|
|
180 |
std::vector<unsigned char> buf; |
std::vector<unsigned char> buf; |
181 |
while(Serial.getComstat().cbInQue > 0) |
while(Serial.getComstat().cbInQue > 0) |
182 |
{ |
{ |
183 |
unsigned char data = Serial.readByte(); |
unsigned char data = Serial.readByte(); |
184 |
|
|
185 |
buf.push_back(data); |
buf.push_back(data); |
186 |
} |
} |
187 |
return buf; |
return buf; |
188 |
} |
} |
216 |
data.push_back('5'); |
data.push_back('5'); |
217 |
|
|
218 |
writeFrame(data); |
writeFrame(data); |
|
/* Sleep(750); |
|
|
if(Serial.getComstat().cbInQue > 0) |
|
|
{ |
|
|
std::vector<unsigned char> answer = readFrame(); |
|
|
Sleep(50); |
|
|
char array1[25]; |
|
|
int i; |
|
|
for (int i=0; i<answer.size(); i++) |
|
|
{ |
|
|
array1[i] = answer[i]; |
|
|
} |
|
|
|
|
|
for (int i=0; i<answer.size(); i++) |
|
|
{ |
|
|
if ((array1[i] != 0x0A) && (array1[i] != 0x0D)) |
|
|
{ |
|
|
tekst.AppendChar(array1[i]); |
|
|
} |
|
|
} |
|
|
m_Textwindow.SetWindowText(tekst); |
|
|
} |
|
|
*/ |
|
219 |
} |
} |
220 |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
221 |
{ |
{ |
370 |
Flis = Splitter(FyrData); |
Flis = Splitter(FyrData); |
371 |
FremFejl = Splitter(FyrData); |
FremFejl = Splitter(FyrData); |
372 |
PowerFail = Splitter(FyrData); |
PowerFail = Splitter(FyrData); |
373 |
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
374 |
///////////////////// Her skal sendes data til databasen ////NÅR HEDIN KAN SENDE SMS/////////////////// |
CString SQL, Textwindow, InstallNR; |
375 |
m_Textwindow.GetWindowText(oldtekst); |
SQL.Format("select ID from installation where installationphonenr=%s",TlfNr); |
376 |
oldtekst.Append("\r\n"); |
|
377 |
oldtekst.Append("På næste linie kommer SmsCount. \r\n"); |
CRecordset rs(&db); |
378 |
oldtekst.Append(SmsCount); |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
379 |
oldtekst.Append("\r\n"); |
if (rs.GetRecordCount()>0) |
380 |
oldtekst.Append("På næste linie kommer Temper. \r\n"); |
{ |
381 |
oldtekst.Append(Temper); |
rs.MoveFirst(); |
382 |
oldtekst.Append("\r\n"); |
rs.GetFieldValue((short)0,InstallNR); |
383 |
oldtekst.Append("På næste linie kommer Flamme. \r\n"); |
} |
384 |
oldtekst.Append(Flamme); |
rs.Close(); |
385 |
oldtekst.Append("\r\n"); |
|
386 |
oldtekst.Append("På næste linie kommer Flis. \r\n"); |
SQL.Format("insert into logtable (logtime,temperature,flamedetector,solidfuelempty,conveyorerror,powerfailure,messagenr,installationnr) Values (now(),%s,'%s','%s','%s','%s',%s,%s)",Temper, Flamme, Flis, FremFejl, PowerFail, SmsCount,InstallNR); |
387 |
oldtekst.Append(Flis); |
db.ExecuteSQL(SQL); |
388 |
oldtekst.Append("\r\n"); |
|
389 |
oldtekst.Append("På næste linie kommer FremFejl. \r\n"); |
m_Textwindow.GetWindowText(Textwindow); |
390 |
oldtekst.Append(FremFejl); |
Textwindow.Append("\r\n"); |
391 |
oldtekst.Append("\r\n"); |
Textwindow.Append("Sms added to Log"); |
392 |
oldtekst.Append("På næste linie kommer PowerFail. \r\n"); |
m_Textwindow.SetWindowText(Textwindow); |
393 |
oldtekst.Append(PowerFail); |
Sleep(150); |
394 |
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append("På næste linie kommer TlfNR. \r\n"); |
|
|
oldtekst.Append(TlfNr); |
|
|
m_Textwindow.SetWindowText(oldtekst); |
|
395 |
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
396 |
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
397 |
} |
} |
411 |
{ |
{ |
412 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
413 |
continueThread = 0; |
continueThread = 0; |
414 |
DeleteSms(); //<--- crasher, men gider ikke bruge flere af mine penge på at teste det med sms'er, hele close laver crash, bare ikke når jeg stepper. :S |
DeleteSms(); |
415 |
|
|
416 |
Sleep(500); |
Sleep(500); |
417 |
if( Serial.isOpen() ) |
if( Serial.isOpen() ) |
421 |
|
|
422 |
if(db.IsOpen()) |
if(db.IsOpen()) |
423 |
{ |
{ |
424 |
db.Close(); |
db.Close(); |
425 |
} |
} |
426 |
|
|
427 |
OnOK(); |
OnOK(); |
431 |
void CFlisServerDlg::OnBnClickedGsmpin() |
void CFlisServerDlg::OnBnClickedGsmpin() |
432 |
{ |
{ |
433 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
434 |
|
m_Textwindow.SetWindowText("Indsætter Pinkode, efterfuldt af 60sec pause"); |
435 |
|
UpdateWindow(); |
436 |
SetPin(); |
SetPin(); |
437 |
Sleep(35000); |
Sleep(50000); |
438 |
|
|
439 |
|
while (Serial.getComstat().cbInQue > 0) |
440 |
|
{ |
441 |
|
Serial.readByte(); //Flush the incoming queue |
442 |
|
} |
443 |
|
|
444 |
OnBnClickedStart(); |
OnBnClickedStart(); |
445 |
} |
} |
446 |
void CFlisServerDlg::DeleteSms() |
void CFlisServerDlg::DeleteSms() |
568 |
{ |
{ |
569 |
data.push_back(smscount[i]); |
data.push_back(smscount[i]); |
570 |
} |
} |
571 |
|
m_Textwindow.GetWindowText(oldteskst); |
572 |
|
oldteskst.Append("\r\n"); |
573 |
for (int i=0; i<data.size();i++) |
for (int i=0; i<data.size();i++) |
574 |
{ |
{ |
575 |
oldteskst.AppendChar(data[i]); |
oldteskst.AppendChar(data[i]); |
576 |
} |
} |
577 |
m_Textwindow.SetWindowText(oldteskst); |
m_Textwindow.SetWindowText(oldteskst); |
578 |
writeFrame(data); |
writeFrame(data); |
590 |
m_Textwindow.SetWindowText(oldtekst); |
m_Textwindow.SetWindowText(oldtekst); |
591 |
} |
} |
592 |
} |
} |
593 |
if(ResetSms == 50) |
else |
594 |
|
{ |
595 |
|
m_Textwindow.GetWindowText(oldtekst); |
596 |
|
oldtekst.Append("\r\n"); |
597 |
|
oldtekst.Append("Anden tekst end forventet"); |
598 |
|
oldtekst.Append("\r\n"); |
599 |
|
oldtekst.Append(tekst); |
600 |
|
m_Textwindow.SetWindowText(oldtekst); |
601 |
|
} |
602 |
|
if(ResetSms == 20) |
603 |
{ |
{ |
604 |
DeleteSms(); |
DeleteSms(); |
605 |
|
m_Textwindow.GetWindowText(oldtekst); |
606 |
|
oldtekst.Append("\r\n"); |
607 |
|
oldtekst.Append("Slettet Sendte og læste beskeder da vi nåede grænsen."); |
608 |
|
m_Textwindow.SetWindowText(oldtekst); |
609 |
} |
} |
610 |
|
|
611 |
} |
} |
627 |
|
|
628 |
if(commandtest > 1) |
if(commandtest > 1) |
629 |
{ |
{ |
630 |
testdata.Append(data[i].InstallationsID); |
testdata.Append(data[i].InstallationsID); |
631 |
testdata.Append(":"); |
testdata.Append(":"); |
632 |
} |
} |
633 |
} |
} |
634 |
sIDnr = Splitter(testdata); |
sIDnr = Splitter(testdata); |
636 |
sInstallationsID = "0"; |
sInstallationsID = "0"; |
637 |
if (commandtest > 1) |
if (commandtest > 1) |
638 |
{ |
{ |
639 |
sInstallationsID = Splitter(testdata); |
sInstallationsID = Splitter(testdata); |
640 |
iAll = 0; |
iAll = 0; |
641 |
} |
} |
642 |
|
|
643 |
if (sIDnr.GetLength() > 0) |
if (sIDnr.GetLength() > 0) |
774 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
775 |
|
|
776 |
continueThread = 1; |
continueThread = 1; |
777 |
|
m_Textwindow.SetWindowText("Started"); |
778 |
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
779 |
} |
} |