367 |
TlfNr = data.Mid(24,8); |
TlfNr = data.Mid(24,8); |
368 |
FyrData = data.Mid(57,data.GetLength()-59); |
FyrData = data.Mid(57,data.GetLength()-59); |
369 |
FyrData.Append(":"); |
FyrData.Append(":"); |
370 |
|
|
371 |
|
if (FyrData.MakeLower() == "conf ok:") |
372 |
|
{ |
373 |
|
HandleAcknowledge(TlfNr); |
374 |
|
return; |
375 |
|
} |
376 |
|
|
377 |
SmsCount = Splitter(FyrData); |
SmsCount = Splitter(FyrData); |
378 |
Temper = Splitter(FyrData); |
Temper = Splitter(FyrData); |
441 |
void CFlisServerDlg::OnBnClickedGsmpin() |
void CFlisServerDlg::OnBnClickedGsmpin() |
442 |
{ |
{ |
443 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
444 |
m_Textwindow.SetWindowText("Indsætter Pinkode, efterfuldt af 60sec pause"); |
bool ready = true; |
445 |
|
m_Textwindow.SetWindowText("Indsætter Pinkode, og venter på modem bliver klar"); |
446 |
UpdateWindow(); |
UpdateWindow(); |
447 |
SetPin(); |
SetPin(); |
448 |
Sleep(50000); |
Sleep(500); |
449 |
|
|
450 |
while (Serial.getComstat().cbInQue > 0) |
while (ready == true) |
451 |
|
{ |
452 |
|
if (Serial.getComstat().cbInQue > 120) |
453 |
|
{ |
454 |
|
std::vector<unsigned char> answer = readFrame(); |
455 |
|
CString tekst; |
456 |
|
|
457 |
|
for (int i=0; i<answer.size(); i++) |
458 |
|
{ |
459 |
|
if ((answer[i] != 0x0A) && (answer[i] != 0x0D)) |
460 |
|
{ |
461 |
|
tekst.AppendChar(answer[i]); |
462 |
|
} |
463 |
|
} |
464 |
|
int n = tekst.Find("WIND: 11",0); |
465 |
|
if (n > -1) |
466 |
|
{ |
467 |
|
ready = false; |
468 |
|
} |
469 |
|
else |
470 |
|
{ |
471 |
|
AppendText(tekst); |
472 |
|
} |
473 |
|
} |
474 |
|
} |
475 |
|
Sleep(100); //Give the modem a chance to send the last data |
476 |
|
while(Serial.getComstat().cbInQue > 0) |
477 |
{ |
{ |
478 |
Serial.readByte(); //Flush the incoming queue |
Serial.readByte(); //Flush the incoming queue |
479 |
|
Sleep(1); |
480 |
} |
} |
|
|
|
481 |
OnBnClickedStart(); |
OnBnClickedStart(); |
482 |
} |
} |
483 |
void CFlisServerDlg::DeleteSms() |
void CFlisServerDlg::DeleteSms() |
537 |
tekst.Append(":"); |
tekst.Append(":"); |
538 |
|
|
539 |
CString command; |
CString command; |
540 |
bool plus; |
bool plus = false; |
541 |
int pos = tekst.Find('+',0); |
int pos = tekst.Find('+',0); |
542 |
if (pos != -1) |
if (pos != -1) |
543 |
{ |
{ |
613 |
} |
} |
614 |
else |
else |
615 |
{ |
{ |
616 |
CString send; |
AppendText(tekst); |
|
send.Append("Anden tekst end forventet"); |
|
|
send.Append("\r\n"); |
|
|
send.Append(tekst); |
|
|
AppendText(send); |
|
617 |
} |
} |
618 |
if(ResetSms == 20) |
if(ResetSms == 20) |
619 |
{ |
{ |
653 |
SendConfig(sIDnr,sCommandID,sInstallationsID); |
SendConfig(sIDnr,sCommandID,sInstallationsID); |
654 |
} |
} |
655 |
Sleep(500); |
Sleep(500); |
656 |
|
|
657 |
|
CheckAcknowledges(); |
658 |
|
Sleep(500); |
659 |
|
} |
660 |
|
CTime now = CTime::GetCurrentTime(); |
661 |
|
|
662 |
|
CTimeSpan elapsed = now-Alive.tid; |
663 |
|
|
664 |
|
if (elapsed.GetTotalSeconds() >= 900) |
665 |
|
{ |
666 |
|
keepaliveandread(); |
667 |
} |
} |
668 |
} |
} |
669 |
void CFlisServerDlg::SendConfig(CString IDnr,CString CommandID,CString InstallationsID) |
void CFlisServerDlg::SendConfig(CString IDnr,CString CommandID,CString InstallationsID) |
670 |
{ |
{ |
|
CString ServerTlfNr; |
|
|
int i = 0; |
|
|
ServerTlfNr = "29860132"; |
|
|
|
|
671 |
|
|
672 |
std::vector<Installation> inst; |
std::vector<Installation> inst; |
673 |
inst = DBReadPhone(InstallationsID); |
|
674 |
while (i < inst.size()) |
if (CommandID == "1") |
675 |
|
inst = DBReadPhone("0"); |
676 |
|
else |
677 |
|
inst = DBReadPhone(InstallationsID); |
678 |
|
|
679 |
|
for ( int j=0; j < inst.size(); j++) |
680 |
{ |
{ |
681 |
CString TlfNr, Imei, updaterate; |
CString TlfNr, Imei, updaterate; |
682 |
TlfNr.Empty(); |
TlfNr.Empty(); |
683 |
Imei.Empty(); |
Imei.Empty(); |
684 |
updaterate.Empty(); |
updaterate.Empty(); |
685 |
|
|
686 |
CString dataen = inst[i].InstPhoneNr; |
CString dataen = inst[j].InstPhoneNr; |
687 |
TlfNr.Append(dataen); |
TlfNr.Append(dataen); |
688 |
CString Imeidata = inst[i].Imei; |
CString Imeidata = inst[j].Imei; |
689 |
Imei.Append(Imeidata); |
Imei.Append(Imeidata); |
690 |
CString updaterat = inst[i].Updaterate; |
CString updaterat = inst[j].Updaterate; |
691 |
updaterate.Append(updaterat); |
updaterate.Append(updaterat); |
|
i++; |
|
|
|
|
|
vector<unsigned char> tlfnr; |
|
|
for (int i=0; i<TlfNr.GetLength(); i++) |
|
|
{ |
|
|
tlfnr.push_back(TlfNr[i]); |
|
|
} |
|
692 |
|
|
693 |
int calcimei; |
vector<unsigned char> tlfnr; |
694 |
__int64 buf; |
for (int i=0; i<TlfNr.GetLength(); i++) |
695 |
|
{ |
696 |
|
tlfnr.push_back(TlfNr[i]); |
697 |
|
} |
698 |
|
|
699 |
|
int calcimei; |
700 |
|
__int64 buf; |
701 |
|
|
702 |
buf = atof(Imei); |
buf = atof(Imei); |
703 |
|
|
704 |
calcimei = tversum(buf); |
calcimei = tversum(buf); |
705 |
|
|
706 |
Imei.Format("%d",calcimei); |
Imei.Format("%d",calcimei); |
707 |
|
|
708 |
SendSmsHead(tlfnr); |
SendSmsHead(tlfnr); |
709 |
Sleep(250); |
Sleep(250); |
710 |
|
|
711 |
vector<unsigned char> smsdata; |
vector<unsigned char> smsdata; |
712 |
|
|
713 |
for (int i=0; i<Imei.GetLength(); i++) |
for (int i=0; i<Imei.GetLength(); i++) |
714 |
{ |
{ |
715 |
smsdata.push_back(Imei[i]); |
smsdata.push_back(Imei[i]); |
716 |
} |
} |
717 |
smsdata.push_back(':'); |
smsdata.push_back(':'); |
718 |
for (int i=0; i<ServerTlfNr.GetLength(); i++) |
for (int i=0; i<Alive.Phonenr.GetLength(); i++) |
719 |
{ |
{ |
720 |
smsdata.push_back(ServerTlfNr[i]); |
smsdata.push_back(Alive.Phonenr[i]); |
721 |
} |
} |
722 |
smsdata.push_back(':'); |
smsdata.push_back(':'); |
723 |
for (int i=0; i<updaterate.GetLength(); i++) |
for (int i=0; i<updaterate.GetLength(); i++) |
724 |
{ |
{ |
725 |
smsdata.push_back(updaterate[i]); |
smsdata.push_back(updaterate[i]); |
726 |
} |
} |
727 |
|
|
728 |
|
SendSmsData(smsdata); |
729 |
|
Sleep(500); |
730 |
|
|
731 |
|
if (IDnr != "0") |
732 |
|
{ |
733 |
|
Acks.push_back( Acknowledge(inst[j].instID,TlfNr) ); |
734 |
|
} |
735 |
|
|
|
SendSmsData(smsdata); |
|
|
Sleep(500); |
|
|
|
|
736 |
} |
} |
737 |
|
|
738 |
|
if (IDnr != "0") |
739 |
|
{ |
740 |
CString SQL, Textwindow; |
CString SQL, Textwindow; |
741 |
SQL.Format("update command set executed=now() where id=%s",IDnr); |
SQL.Format("update command set executed=now() where id=%s",IDnr); |
742 |
db.ExecuteSQL(SQL); |
db.ExecuteSQL(SQL); |
743 |
AppendText("Command executed"); |
AppendText("Command executed"); |
744 |
Sleep(150); |
} |
745 |
|
Sleep(150); |
746 |
|
|
747 |
|
|
748 |
|
|
749 |
|
|
750 |
} |
} |
751 |
vector<Installation> CFlisServerDlg::DBReadPhone(CString sInstallationsID) |
vector<Installation> CFlisServerDlg::DBReadPhone(CString sInstallationsID) |
752 |
{ |
{ |
753 |
vector<Installation> buffer; |
vector<Installation> buffer; |
754 |
|
|
755 |
CString SQL, phonenr, imei, updaterate; |
CString SQL, phonenr, imei, updaterate, id; |
|
int installernull; |
|
756 |
Installation Myinst; |
Installation Myinst; |
757 |
installernull = atoi(sInstallationsID); |
|
758 |
if (installernull > 1) |
if (sInstallationsID != "0") |
759 |
{ |
{ |
760 |
SQL.Format("select installationphonenr, imei, updaterate from installation WHERE id = %s", sInstallationsID); |
SQL.Format("select installationphonenr, imei, updaterate, id from installation WHERE id = %s", sInstallationsID); |
761 |
} |
} |
762 |
else if(installernull < 2) |
else |
763 |
{ |
{ |
764 |
SQL.Format("select installationphonenr, imei, updaterate from installation"); |
SQL.Format("select installationphonenr, imei, updaterate, id from installation"); |
765 |
} |
} |
766 |
|
|
767 |
CRecordset rs(&db); |
CRecordset rs(&db); |
768 |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
769 |
if (rs.GetRecordCount()>0) |
if (rs.GetRecordCount()>0) |
775 |
rs.GetFieldValue((short)0,phonenr); |
rs.GetFieldValue((short)0,phonenr); |
776 |
rs.GetFieldValue(1,imei); |
rs.GetFieldValue(1,imei); |
777 |
rs.GetFieldValue(2,updaterate); |
rs.GetFieldValue(2,updaterate); |
778 |
|
rs.GetFieldValue(3,id); |
779 |
|
|
780 |
Myinst.InstPhoneNr = phonenr; |
Myinst.InstPhoneNr = phonenr; |
781 |
Myinst.Imei = imei; |
Myinst.Imei = imei; |
782 |
Myinst.Updaterate = updaterate; |
Myinst.Updaterate = updaterate; |
783 |
|
Myinst.instID = id; |
784 |
|
|
785 |
buffer.push_back(Myinst); |
buffer.push_back(Myinst); |
786 |
rs.MoveNext(); |
rs.MoveNext(); |
802 |
void CFlisServerDlg::OnBnClickedStart() |
void CFlisServerDlg::OnBnClickedStart() |
803 |
{ |
{ |
804 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
805 |
|
|
806 |
continueThread = 1; |
continueThread = 1; |
807 |
m_Textwindow.SetWindowText("Started"); |
keepaliveandread(); |
808 |
|
Sleep(150); |
809 |
|
m_Textwindow.SetWindowText(CString("Server phonenr read from db: ") + Alive.Phonenr ); |
810 |
|
AppendText("Started"); |
811 |
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
812 |
} |
} |
813 |
void CFlisServerDlg::AppendText(CString s) |
void CFlisServerDlg::AppendText(CString s) |
853 |
} |
} |
854 |
|
|
855 |
file.close(); |
file.close(); |
856 |
|
} |
857 |
|
void CFlisServerDlg::HandleAcknowledge(CString tlfnr) |
858 |
|
{ |
859 |
|
for (std::list<Acknowledge>::iterator it = Acks.begin(); it != Acks.end(); ++it) |
860 |
|
{ |
861 |
|
Acknowledge& current = (*it); |
862 |
|
if (current.sTlfNr == tlfnr) |
863 |
|
{ |
864 |
|
CString SQL; |
865 |
|
SQL.Format("UPDATE installation SET commerror = false WHERE id = %s", current.sInstallationID); |
866 |
|
db.ExecuteSQL(SQL); |
867 |
|
|
868 |
|
Acks.erase(it); |
869 |
|
|
870 |
|
return; |
871 |
|
} |
872 |
|
} |
873 |
|
} |
874 |
|
|
875 |
|
void CFlisServerDlg::CheckAcknowledges() |
876 |
|
{ |
877 |
|
CTime now = CTime::GetCurrentTime(); |
878 |
|
for (std::list<Acknowledge>::iterator it = Acks.begin(); it != Acks.end(); ++it) |
879 |
|
{ |
880 |
|
Acknowledge& current = (*it); |
881 |
|
|
882 |
|
CTimeSpan elapsed = now-current.cTime; |
883 |
|
|
884 |
|
if (elapsed.GetTotalSeconds() >= 300) |
885 |
|
{ |
886 |
|
DumpAckList(); |
887 |
|
if (current.iRetry >= 1) |
888 |
|
{ |
889 |
|
CString SQL; |
890 |
|
SQL.Format("UPDATE installation SET commerror = true WHERE id = %s", current.sInstallationID); |
891 |
|
db.ExecuteSQL(SQL); |
892 |
|
Acks.erase(it); |
893 |
|
return; // the iterator is now invalidated, but the thread loop will make sure we are here soon again |
894 |
|
} |
895 |
|
else |
896 |
|
{ |
897 |
|
SendConfig("0","2",current.sInstallationID); |
898 |
|
current.iRetry++; |
899 |
|
current.cTime = CTime::GetCurrentTime(); |
900 |
|
AppendText( CString("Retry send config to ") + current.sTlfNr ); |
901 |
|
} |
902 |
|
} |
903 |
|
} |
904 |
|
} |
905 |
|
|
906 |
|
void CFlisServerDlg::DumpAckList() |
907 |
|
{ |
908 |
|
CTime now = CTime::GetCurrentTime(); |
909 |
|
OutputDebugString("-------------------------------\n"); |
910 |
|
int count = 0; |
911 |
|
for (std::list<Acknowledge>::iterator it = Acks.begin(); it != Acks.end(); ++it) |
912 |
|
{ |
913 |
|
CString msg; |
914 |
|
msg.Format("%d:%d:%d> %4d : %s\n", now.GetHour(), now.GetMinute(), now.GetSecond(), count, (*it).sTlfNr); |
915 |
|
OutputDebugString(msg); |
916 |
|
count++; |
917 |
|
} |
918 |
|
} |
919 |
|
vector<keepalive> CFlisServerDlg::keepaliveandread(void) |
920 |
|
{ |
921 |
|
vector<keepalive> buffer; |
922 |
|
|
923 |
|
CString SQL, name, value; |
924 |
|
SQL = "select name, value from config;"; |
925 |
|
CRecordset rs(&db); |
926 |
|
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
927 |
|
if (rs.GetRecordCount()>0) |
928 |
|
{ |
929 |
|
rs.MoveFirst(); |
930 |
|
|
931 |
|
rs.GetFieldValue((short)0, name); |
932 |
|
rs.GetFieldValue(1,value); |
933 |
|
|
934 |
|
Alive.name = name; |
935 |
|
Alive.value = value; |
936 |
|
Alive.tid = CTime::GetCurrentTime(); |
937 |
|
if(Alive.name == "phonenr") |
938 |
|
{ |
939 |
|
Alive.Phonenr = value; |
940 |
|
} |
941 |
|
|
942 |
|
buffer.push_back(Alive); |
943 |
|
rs.MoveNext(); |
944 |
|
|
945 |
|
} |
946 |
|
rs.Close(); |
947 |
|
return buffer; |
948 |
|
|
949 |
} |
} |