5 |
#include "FlisServer.h" |
#include "FlisServer.h" |
6 |
#include "FlisServerDlg.h" |
#include "FlisServerDlg.h" |
7 |
#include <vector> |
#include <vector> |
8 |
|
#include ".\flisserverdlg.h" |
9 |
|
|
10 |
#ifdef _DEBUG |
#ifdef _DEBUG |
11 |
#define new DEBUG_NEW |
#define new DEBUG_NEW |
63 |
ON_WM_SYSCOMMAND() |
ON_WM_SYSCOMMAND() |
64 |
ON_WM_PAINT() |
ON_WM_PAINT() |
65 |
ON_WM_QUERYDRAGICON() |
ON_WM_QUERYDRAGICON() |
|
ON_MESSAGE(UWM_MYMESSAGE, OnShowString) |
|
66 |
//}}AFX_MSG_MAP |
//}}AFX_MSG_MAP |
|
ON_BN_CLICKED(IDC_test, OnBnClickedtest) |
|
67 |
ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) |
ON_BN_CLICKED(IDCLOSE, OnBnClickedClose) |
68 |
ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin) |
ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin) |
69 |
|
ON_BN_CLICKED(IDC_Start, OnBnClickedStart) |
70 |
END_MESSAGE_MAP() |
END_MESSAGE_MAP() |
71 |
|
|
72 |
|
|
102 |
// TODO: Add extra initialization here |
// TODO: Add extra initialization here |
103 |
StartSerial(); |
StartSerial(); |
104 |
DBConnect(); |
DBConnect(); |
105 |
continueThread = true; |
ResetSms = 0; |
|
//AfxBeginThread(MyMainThread,0,THREAD_PRIORITY_NORMAL,0,0,NULL); |
|
106 |
|
|
107 |
return TRUE; // return TRUE unless you set the focus to a control |
return TRUE; // return TRUE unless you set the focus to a control |
108 |
} |
} |
157 |
} |
} |
158 |
int CFlisServerDlg::StartSerial(void) |
int CFlisServerDlg::StartSerial(void) |
159 |
{ |
{ |
160 |
|
|
161 |
int Baud; |
int Baud; |
|
CString SerialPort = "COM3"; |
|
162 |
|
|
163 |
|
ConfigFile config; |
164 |
|
try { |
165 |
|
config.ReadSettings(); |
166 |
|
} catch(...) { |
167 |
|
MessageBox("Could not open config file"); |
168 |
|
OnOK(); |
169 |
|
return true; |
170 |
|
} |
171 |
|
|
172 |
Baud = 1200; |
Baud = 1200; |
173 |
if( Serial.isOpen() ){ |
if( Serial.isOpen() ) |
174 |
Serial.close(); |
{ |
175 |
Serial.open( SerialPort, Baud ); |
try |
176 |
|
{ |
177 |
|
Serial.close(); |
178 |
|
Serial.open( config.comport, Baud ); |
179 |
|
} |
180 |
|
catch (exception* e) |
181 |
|
{ |
182 |
|
MessageBox( "Serial.open() exception" ); |
183 |
|
return 0; |
184 |
|
} |
185 |
} |
} |
186 |
else { |
else |
187 |
Serial.open( SerialPort, Baud ); |
{ |
188 |
|
try |
189 |
|
{ |
190 |
|
Serial.open( config.comport, Baud ); |
191 |
|
} |
192 |
|
catch (exception* e) |
193 |
|
{ |
194 |
|
MessageBox( "Serial.open() exception 2" ); |
195 |
|
return 0; |
196 |
|
} |
197 |
} |
} |
198 |
|
|
199 |
|
|
200 |
return 0; |
return 0; |
201 |
} |
} |
204 |
std::vector<unsigned char> buf; |
std::vector<unsigned char> buf; |
205 |
while(Serial.getComstat().cbInQue > 0) |
while(Serial.getComstat().cbInQue > 0) |
206 |
{ |
{ |
207 |
unsigned char data = Serial.readByte(); |
unsigned char data = Serial.readByte(); |
208 |
|
|
209 |
buf.push_back(data); |
buf.push_back(data); |
210 |
} |
} |
211 |
return buf; |
return buf; |
212 |
} |
} |
|
void CFlisServerDlg::OnBnClickedtest() |
|
|
{ |
|
|
// TODO: Add your control notification handler code here |
|
|
|
|
|
/* |
|
|
////////////////DBRead stuff////////////////// |
|
|
CString testdata; |
|
|
std::vector<Commands> data; |
|
|
data = DBRead(); |
|
|
for (int i=0; i<data.size(); i++) |
|
|
{ |
|
|
testdata.Append(data[i].IDnr); |
|
|
testdata.Append(data[i].CommandID); |
|
|
testdata.Append(data[i].InstallationsID); |
|
|
} |
|
|
m_Textwindow.SetWindowText(testdata); |
|
|
////////////////DBRead stuff////////////////// |
|
|
*/ |
|
|
/* |
|
|
///////////////Send sms stuff///////////////// |
|
|
vector<unsigned char> tlfnr; |
|
|
vector<unsigned char> smsdata; |
|
|
tlfnr.push_back('2'); |
|
|
tlfnr.push_back('9'); |
|
|
tlfnr.push_back('7'); |
|
|
tlfnr.push_back('2'); |
|
|
tlfnr.push_back('2'); |
|
|
tlfnr.push_back('6'); |
|
|
tlfnr.push_back('0'); |
|
|
tlfnr.push_back('3'); |
|
|
|
|
|
SendSmsHead(tlfnr); |
|
213 |
|
|
|
//35:29860132:75 <--- demo pakke; |
|
|
smsdata.push_back('3'); |
|
|
smsdata.push_back('5'); |
|
|
smsdata.push_back(':'); |
|
|
smsdata.push_back('2'); |
|
|
smsdata.push_back('9'); |
|
|
smsdata.push_back('8'); |
|
|
smsdata.push_back('6'); |
|
|
smsdata.push_back('0'); |
|
|
smsdata.push_back('1'); |
|
|
smsdata.push_back('3'); |
|
|
smsdata.push_back('2'); |
|
|
smsdata.push_back(':'); |
|
|
smsdata.push_back('7'); |
|
|
smsdata.push_back('5'); |
|
|
|
|
|
SendSmsData(smsdata); |
|
|
///////////////Send sms stuff///////////////// |
|
|
*/ |
|
|
/* |
|
|
////////////Start Tråd//////////////////////// |
|
|
MyThread *t = new MyThread(AfxGetMainWnd()); |
|
|
t->start(); |
|
|
////////////Start Tråd//////////////////////// |
|
|
*/ |
|
|
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
|
|
|
|
|
} |
|
214 |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
215 |
{ |
{ |
216 |
for (int i=0; i<data.size(); i++) |
for (int i=0; i<data.size(); i++) |
240 |
data.push_back('5'); |
data.push_back('5'); |
241 |
|
|
242 |
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); |
|
|
} |
|
243 |
} |
} |
244 |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data) |
245 |
{ |
{ |
256 |
CString tekst; |
CString tekst; |
257 |
std::vector<unsigned char> answer = readFrame(); |
std::vector<unsigned char> answer = readFrame(); |
258 |
Sleep(50); |
Sleep(50); |
259 |
char array1[25]; |
|
260 |
int i; |
for (int i=0; i<answer.size(); i++) |
|
for (int i=0; i<answer.size(); i++) |
|
|
{ |
|
|
array1[i] = answer[i]; |
|
|
} |
|
|
|
|
|
for (int i=0; i<answer.size(); i++) |
|
261 |
{ |
{ |
262 |
if ((array1[i] != 0x0A) && (array1[i] != 0x0D)) |
if ((answer[i] != 0x0A) && (answer[i] != 0x0D)) |
263 |
{ |
{ |
264 |
tekst.AppendChar(array1[i]); |
tekst.AppendChar(answer[i]); |
265 |
} |
} |
266 |
} |
} |
267 |
m_Textwindow.SetWindowText(tekst); |
AppendText(tekst); |
268 |
} |
} |
269 |
|
|
270 |
} |
} |
271 |
void CFlisServerDlg::SendSmsHead(std::vector<unsigned char> data) |
void CFlisServerDlg::SendSmsHead(std::vector<unsigned char> tlfnr) |
272 |
{ |
{ |
273 |
vector<unsigned char> atcommand; |
vector<unsigned char> atcommand; |
274 |
atcommand.push_back('a'); |
atcommand.push_back('a'); |
288 |
Sleep(5); |
Sleep(5); |
289 |
} |
} |
290 |
|
|
291 |
for (int i=0; i<data.size(); i++) |
for (int i=0; i<tlfnr.size(); i++) |
292 |
{ |
{ |
293 |
Serial.writeByte( data[i] ); |
Serial.writeByte( tlfnr[i] ); |
294 |
Sleep(5); |
Sleep(5); |
295 |
} |
} |
296 |
Serial.writeByte(atcommand[s]); |
Serial.writeByte(atcommand[s]); |
300 |
void CFlisServerDlg::DBConnect() |
void CFlisServerDlg::DBConnect() |
301 |
{ |
{ |
302 |
CString dsn; |
CString dsn; |
303 |
dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=t-hoerup.dk; uid=serrenab;password=furnacemonitor;database=flisfyr;sslmode=prefer"); |
ConfigFile config; |
304 |
//dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=192.168.134.132; uid=serrenab;password=furnacemonitor;database=flisfyr;sslmode=prefer"); //skole server |
try { |
305 |
|
config.ReadSettings(); |
306 |
|
} catch(...) { |
307 |
|
MessageBox("Could not open config file"); |
308 |
|
} |
309 |
|
|
310 |
|
dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=%s; uid=%s;password=%s;database=%s;sslmode=prefer",config.host,config.username, config.password, config.database); |
311 |
db.OpenEx(dsn, CDatabase::noOdbcDialog); |
db.OpenEx(dsn, CDatabase::noOdbcDialog); |
312 |
} |
} |
313 |
vector<Commands> CFlisServerDlg::DBRead(void) |
vector<Commands> CFlisServerDlg::DBReadCommands(void) |
314 |
{ |
{ |
315 |
vector<Commands> buffer; |
vector<Commands> buffer; |
316 |
|
|
317 |
CString SQL, IDnr, CommandID, InstallationsID; |
CString SQL, IDnr, CommandID, InstallationsID; |
318 |
SQL = "select id,date_trunc('second', created) as created,executed,commandid,installationid from command WHERE executed IS NULL;"; |
SQL = "select id,date_trunc('second', created) as created,executed,commandid,installationid from command WHERE executed IS NULL ORDER BY created ASC LIMIT 1;"; |
319 |
CRecordset rs(&db); |
CRecordset rs(&db); |
320 |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
321 |
if (rs.GetRecordCount()>0) |
if (rs.GetRecordCount()>0) |
322 |
{ |
{ |
323 |
rs.MoveFirst(); |
rs.MoveFirst(); |
324 |
while(!rs.IsEOF()) |
|
|
{ |
|
325 |
Commands Mycom; |
Commands Mycom; |
326 |
rs.GetFieldValue((short)0, IDnr); |
rs.GetFieldValue((short)0, IDnr); |
327 |
rs.GetFieldValue(3, CommandID); |
rs.GetFieldValue(3, CommandID); |
333 |
|
|
334 |
buffer.push_back(Mycom); |
buffer.push_back(Mycom); |
335 |
rs.MoveNext(); |
rs.MoveNext(); |
336 |
} |
|
337 |
} |
} |
338 |
rs.Close(); |
rs.Close(); |
339 |
return buffer; |
return buffer; |
341 |
void CFlisServerDlg::ReadSms() |
void CFlisServerDlg::ReadSms() |
342 |
{ |
{ |
343 |
CString tekst, oldtekst; |
CString tekst, oldtekst; |
344 |
Sleep(950); |
Sleep(950); //Holder en pause for at lade hele sms'en komme ind i serial køen. |
345 |
if(Serial.getComstat().cbInQue > 0) |
if(Serial.getComstat().cbInQue > 0) |
346 |
{ |
{ |
347 |
std::vector<unsigned char> answer = readFrame(); |
std::vector<unsigned char> answer = readFrame(); |
348 |
Sleep(50); |
//Sleep(50); |
349 |
char array1[250]; |
|
|
int i; |
|
|
for (int i=0; i<answer.size(); i++) |
|
|
{ |
|
|
array1[i] = answer[i]; |
|
|
} |
|
|
|
|
350 |
for (int i=0; i<answer.size(); i++) |
for (int i=0; i<answer.size(); i++) |
351 |
{ |
{ |
352 |
if ((array1[i] != 0x0A) && (array1[i] != 0x0D)) |
if ((answer[i] != 0x0A) && (answer[i] != 0x0D)) |
353 |
{ |
{ |
354 |
tekst.AppendChar(array1[i]); |
tekst.AppendChar(answer[i]); |
355 |
} |
} |
356 |
} |
} |
357 |
|
|
358 |
m_Textwindow.GetWindowText(oldtekst); |
AppendText(tekst); |
|
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append(tekst); |
|
|
m_Textwindow.SetWindowText(oldtekst); |
|
359 |
SmsSplit(tekst); |
SmsSplit(tekst); |
360 |
} |
} |
361 |
} |
} |
364 |
CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail, oldtekst; |
CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail, oldtekst; |
365 |
char CharData[150]; |
char CharData[150]; |
366 |
strcpy(CharData,data); |
strcpy(CharData,data); |
367 |
|
TlfNr = data.Mid(24,8); |
368 |
int s=22; |
FyrData = data.Mid(57,data.GetLength()-3); |
|
for (int i=0; i<=7; i++) |
|
|
{ |
|
|
TlfNr.AppendChar(CharData[s]); |
|
|
s++; |
|
|
} |
|
|
|
|
|
for (int s=55; s<=(data.GetLength()-3); s++) |
|
|
{ |
|
|
FyrData.AppendChar(CharData[s]); |
|
|
} |
|
369 |
FyrData.Append(":"); |
FyrData.Append(":"); |
370 |
|
|
371 |
SmsCount = Splitter(FyrData); |
SmsCount = Splitter(FyrData); |
374 |
Flis = Splitter(FyrData); |
Flis = Splitter(FyrData); |
375 |
FremFejl = Splitter(FyrData); |
FremFejl = Splitter(FyrData); |
376 |
PowerFail = Splitter(FyrData); |
PowerFail = Splitter(FyrData); |
377 |
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
378 |
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
CString SQL, Textwindow, InstallNR; |
379 |
m_Textwindow.GetWindowText(oldtekst); |
SQL.Format("select ID from installation where installationphonenr=%s",TlfNr); |
380 |
oldtekst.Append("\r\n"); |
|
381 |
oldtekst.Append("På næste linie kommer SmsCount. \r\n"); |
CRecordset rs(&db); |
382 |
oldtekst.Append(SmsCount); |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
383 |
oldtekst.Append("\r\n"); |
if (rs.GetRecordCount()>0) |
384 |
oldtekst.Append("På næste linie kommer Temper. \r\n"); |
{ |
385 |
oldtekst.Append(Temper); |
rs.MoveFirst(); |
386 |
oldtekst.Append("\r\n"); |
rs.GetFieldValue((short)0,InstallNR); |
387 |
oldtekst.Append("På næste linie kommer Flamme. \r\n"); |
} |
388 |
oldtekst.Append(Flamme); |
rs.Close(); |
389 |
oldtekst.Append("\r\n"); |
|
390 |
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); |
391 |
oldtekst.Append(Flis); |
db.ExecuteSQL(SQL); |
392 |
oldtekst.Append("\r\n"); |
|
393 |
oldtekst.Append("På næste linie kommer FremFejl. \r\n"); |
AppendText("Sms added to Log"); |
394 |
oldtekst.Append(FremFejl); |
Sleep(150); |
|
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append("På næste linie kommer PowerFail. \r\n"); |
|
|
oldtekst.Append(PowerFail); |
|
|
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append("På næste linie kommer TlfNR. \r\n"); |
|
|
oldtekst.Append(TlfNr); |
|
|
m_Textwindow.SetWindowText(oldtekst); |
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
|
395 |
} |
} |
396 |
CString CFlisServerDlg::Splitter(CString& fyrdata) |
CString CFlisServerDlg::Splitter(CString& fyrdata) |
397 |
{ |
{ |
408 |
void CFlisServerDlg::OnBnClickedClose() |
void CFlisServerDlg::OnBnClickedClose() |
409 |
{ |
{ |
410 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
411 |
continueThread = false; |
continueThread = 0; |
412 |
|
DeleteSms(); |
413 |
|
|
414 |
|
Sleep(500); |
415 |
if( Serial.isOpen() ) |
if( Serial.isOpen() ) |
416 |
{ |
{ |
417 |
Serial.close(); |
Serial.close(); |
419 |
|
|
420 |
if(db.IsOpen()) |
if(db.IsOpen()) |
421 |
{ |
{ |
422 |
db.Close(); |
db.Close(); |
423 |
} |
} |
424 |
DeleteSms(); |
|
425 |
OnOK(); |
OnOK(); |
426 |
|
|
427 |
} |
} |
428 |
|
|
429 |
void CFlisServerDlg::OnBnClickedGsmpin() |
void CFlisServerDlg::OnBnClickedGsmpin() |
430 |
{ |
{ |
431 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
432 |
|
m_Textwindow.SetWindowText("Indsætter Pinkode, efterfuldt af 60sec pause"); |
433 |
|
UpdateWindow(); |
434 |
SetPin(); |
SetPin(); |
435 |
Sleep(5000); |
Sleep(50000); |
436 |
|
|
437 |
|
while (Serial.getComstat().cbInQue > 0) |
438 |
|
{ |
439 |
|
Serial.readByte(); //Flush the incoming queue |
440 |
|
} |
441 |
|
|
442 |
|
OnBnClickedStart(); |
443 |
} |
} |
444 |
void CFlisServerDlg::DeleteSms() |
void CFlisServerDlg::DeleteSms() |
445 |
{ |
{ |
458 |
|
|
459 |
writeFrame(atcommand); |
writeFrame(atcommand); |
460 |
Sleep(500); |
Sleep(500); |
|
if(Serial.getComstat().cbInQue > 0) |
|
|
{ |
|
|
std::vector<unsigned char> answer = readFrame(); |
|
|
Sleep(50); |
|
|
CString tekst, oldtekst; |
|
|
char array1[250]; |
|
|
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]); |
|
|
} |
|
|
} |
|
|
if(tekst == "OK") |
|
|
{ |
|
|
m_Textwindow.GetWindowText(oldtekst); |
|
|
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append("Old Sms messages deleted"); |
|
|
m_Textwindow.SetWindowText(oldtekst); |
|
|
} |
|
|
else |
|
|
{ |
|
|
m_Textwindow.GetWindowText(oldtekst); |
|
|
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append(tekst); |
|
|
m_Textwindow.SetWindowText(oldtekst); |
|
|
} |
|
|
} |
|
461 |
} |
} |
462 |
LRESULT CFlisServerDlg::OnShowString(WPARAM wParam, LPARAM lParam) |
UINT threadWrapper(LPVOID thread) |
|
{ |
|
|
CString *s = (CString*) lParam; |
|
|
GetDlgItem(IDC_Textwindow)->SetWindowText(*s); |
|
|
|
|
|
delete s; |
|
|
return 0; |
|
|
|
|
|
}UINT threadWrapper(LPVOID thread) |
|
463 |
{ |
{ |
464 |
CFlisServerDlg *t = (CFlisServerDlg*) thread; |
CFlisServerDlg *t = (CFlisServerDlg*) thread; |
465 |
t->runthread(); |
t->runthread(); |
473 |
|
|
474 |
void CFlisServerDlg::runthread() |
void CFlisServerDlg::runthread() |
475 |
{ |
{ |
476 |
int count = 0; |
while (continueThread != 0) |
|
while (continueThread = true) |
|
477 |
{ |
{ |
478 |
Reader(); |
Reader(); |
479 |
} |
} |
480 |
} |
} |
481 |
void CFlisServerDlg::Reader() |
void CFlisServerDlg::Reader() |
482 |
{ |
{ |
483 |
int ResetSms = 0; |
if(Serial.getComstat().cbInQue > 0) |
|
while(1) |
|
|
{ |
|
|
if(Serial.getComstat().cbInQue > 0) |
|
484 |
{ |
{ |
485 |
|
Sleep(250); |
486 |
std::vector<unsigned char> answer = readFrame(); |
std::vector<unsigned char> answer = readFrame(); |
487 |
Sleep(500); |
Sleep(500); |
488 |
CString tekst, oldtekst; |
CString tekst, oldtekst; |
489 |
int lol; |
int lol; |
|
char array1[250]; |
|
|
int i; |
|
|
for (int i=0; i<answer.size(); i++) |
|
|
{ |
|
|
array1[i] = answer[i]; |
|
|
} |
|
490 |
|
|
491 |
for (int i=0; i<answer.size(); i++) |
for (int i=0; i<answer.size(); i++) |
492 |
{ |
{ |
493 |
if ((array1[i] != 0x0A) && (array1[i] != 0x0D)) |
if ((answer[i] != 0x0A) && (answer[i] != 0x0D)) |
494 |
{ |
{ |
495 |
tekst.AppendChar(array1[i]); |
tekst.AppendChar(answer[i]); |
496 |
} |
} |
497 |
} |
} |
498 |
tekst.Append(":"); |
tekst.Append(":"); |
512 |
|
|
513 |
if(tekst == "OK") |
if(tekst == "OK") |
514 |
{ |
{ |
515 |
m_Textwindow.GetWindowText(oldtekst); |
AppendText("OK tekst modtaget"); |
|
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append("OK tekst modtaget"); |
|
|
m_Textwindow.SetWindowText(oldtekst); |
|
516 |
} |
} |
517 |
else if (tekst == "error") |
else if (tekst == "error") |
518 |
{ |
{ |
519 |
m_Textwindow.GetWindowText(oldtekst); |
CString send; |
520 |
oldtekst.Append("\r\n"); |
send.Append("error tekst"); |
521 |
oldtekst.Append("error tekst"); |
send.Append("\r\n"); |
522 |
oldtekst.Append(tekst); |
send.Append(tekst); |
523 |
m_Textwindow.SetWindowText(oldtekst); |
AppendText(send); |
524 |
} |
} |
525 |
else if (plus = true) |
else if (plus == true) |
526 |
{ |
{ |
527 |
if (command = "cmti") |
if (command == "cmti") |
528 |
{ |
{ |
529 |
CString smscount; |
CString smscount, oldteskst; |
530 |
int pos = tekst.Find(',',0); |
int pos = tekst.Find(',',0); |
531 |
if (pos != -1) |
if (pos != -1) |
532 |
{ |
{ |
549 |
{ |
{ |
550 |
data.push_back(smscount[i]); |
data.push_back(smscount[i]); |
551 |
} |
} |
552 |
|
m_Textwindow.GetWindowText(oldteskst); |
553 |
|
oldteskst.Append("\r\n"); |
554 |
|
for (int i=0; i<data.size();i++) |
555 |
|
{ |
556 |
|
oldteskst.AppendChar(data[i]); |
557 |
|
} |
558 |
|
m_Textwindow.SetWindowText(oldteskst); |
559 |
writeFrame(data); |
writeFrame(data); |
560 |
|
Sleep(200); |
561 |
ReadSms(); |
ReadSms(); |
562 |
|
ResetSms++; |
563 |
|
|
564 |
} |
} |
565 |
|
else if(command == "wind") |
566 |
|
{ |
567 |
|
|
568 |
|
CString send; |
569 |
|
send.Append("Wind modtaget"); |
570 |
|
send.Append("\r\n"); |
571 |
|
send.Append(tekst); |
572 |
|
AppendText(send); |
573 |
|
} |
574 |
|
} |
575 |
|
else |
576 |
|
{ |
577 |
|
CString send; |
578 |
|
send.Append("Anden tekst end forventet"); |
579 |
|
send.Append("\r\n"); |
580 |
|
send.Append(tekst); |
581 |
|
AppendText(send); |
582 |
} |
} |
583 |
if(ResetSms >= 50) |
if(ResetSms == 20) |
584 |
{ |
{ |
585 |
DeleteSms(); |
DeleteSms(); |
586 |
|
AppendText("Sms'er slettet da vi nåede grænsen"); |
587 |
} |
} |
588 |
|
|
589 |
|
} |
590 |
|
if (continueThread == 1) |
591 |
|
{ |
592 |
|
|
593 |
|
CString testdata, dataframe,testprint, sIDnr, sCommandID, sInstallationsID, sImei; |
594 |
|
int commandtest = 0; |
595 |
|
int iAll = 1; |
596 |
|
std::vector<Commands> data; |
597 |
|
data = DBReadCommands(); |
598 |
|
for (int i=0; i<data.size(); i++) |
599 |
|
{ |
600 |
|
sIDnr = data[i].IDnr; |
601 |
|
sCommandID = data[i].CommandID; |
602 |
|
commandtest = atoi(data[i].CommandID); |
603 |
|
|
604 |
|
if(commandtest > 1) |
605 |
|
{ |
606 |
|
sInstallationsID = data[i].InstallationsID; |
607 |
|
} |
608 |
|
} |
609 |
|
sIDnr = Splitter(testdata); |
610 |
|
sCommandID = Splitter(testdata); |
611 |
|
sInstallationsID = "0"; |
612 |
|
if (commandtest > 1) |
613 |
|
{ |
614 |
|
sInstallationsID = Splitter(testdata); |
615 |
|
iAll = 0; |
616 |
|
} |
617 |
|
|
618 |
|
if (sIDnr.GetLength() > 0) |
619 |
|
{ |
620 |
|
SendConfig(sIDnr,sCommandID,sInstallationsID); |
621 |
|
} |
622 |
|
Sleep(500); |
623 |
} |
} |
624 |
|
} |
625 |
|
void CFlisServerDlg::SendConfig(CString IDnr,CString CommandID,CString InstallationsID) |
626 |
|
{ |
627 |
|
CString ServerTlfNr; |
628 |
|
int i = 0; |
629 |
|
ServerTlfNr = "29860132"; |
630 |
|
|
631 |
|
|
632 |
|
std::vector<Installation> inst; |
633 |
|
inst = DBReadPhone(InstallationsID); |
634 |
|
while (i < inst.size()) |
635 |
|
{ |
636 |
|
CString TlfNr, Imei, updaterate; |
637 |
|
TlfNr.Empty(); |
638 |
|
Imei.Empty(); |
639 |
|
updaterate.Empty(); |
640 |
|
|
641 |
|
CString dataen = inst[i].InstPhoneNr; |
642 |
|
TlfNr.Append(dataen); |
643 |
|
CString Imeidata = inst[i].Imei; |
644 |
|
Imei.Append(Imeidata); |
645 |
|
CString updaterat = inst[i].Updaterate; |
646 |
|
updaterate.Append(updaterat); |
647 |
|
i++; |
648 |
|
|
649 |
|
vector<unsigned char> tlfnr; |
650 |
|
for (int i=0; i<TlfNr.GetLength(); i++) |
651 |
|
{ |
652 |
|
tlfnr.push_back(TlfNr[i]); |
653 |
} |
} |
654 |
|
|
655 |
|
int calcimei; |
656 |
|
__int64 buf; |
657 |
|
|
658 |
|
buf = atof(Imei); |
659 |
|
|
660 |
|
calcimei = tversum(buf); |
661 |
|
|
662 |
|
Imei.Format("%d",calcimei); |
663 |
|
|
664 |
|
SendSmsHead(tlfnr); |
665 |
|
Sleep(250); |
666 |
|
|
667 |
|
vector<unsigned char> smsdata; |
668 |
|
|
669 |
|
for (int i=0; i<Imei.GetLength(); i++) |
670 |
|
{ |
671 |
|
smsdata.push_back(Imei[i]); |
672 |
|
} |
673 |
|
smsdata.push_back(':'); |
674 |
|
for (int i=0; i<ServerTlfNr.GetLength(); i++) |
675 |
|
{ |
676 |
|
smsdata.push_back(ServerTlfNr[i]); |
677 |
|
} |
678 |
|
smsdata.push_back(':'); |
679 |
|
for (int i=0; i<updaterate.GetLength(); i++) |
680 |
|
{ |
681 |
|
smsdata.push_back(updaterate[i]); |
682 |
|
} |
683 |
|
|
684 |
|
SendSmsData(smsdata); |
685 |
|
Sleep(500); |
686 |
|
|
687 |
|
} |
688 |
|
CString SQL, Textwindow; |
689 |
|
SQL.Format("update command set executed=now() where id=%s",IDnr); |
690 |
|
db.ExecuteSQL(SQL); |
691 |
|
AppendText("Command executed"); |
692 |
|
Sleep(150); |
693 |
|
|
694 |
|
} |
695 |
|
vector<Installation> CFlisServerDlg::DBReadPhone(CString sInstallationsID) |
696 |
|
{ |
697 |
|
vector<Installation> buffer; |
698 |
|
|
699 |
|
CString SQL, phonenr, imei, updaterate; |
700 |
|
int installernull; |
701 |
|
Installation Myinst; |
702 |
|
installernull = atoi(sInstallationsID); |
703 |
|
if (installernull > 1) |
704 |
|
{ |
705 |
|
SQL.Format("select installationphonenr, imei, updaterate from installation WHERE id = %s", sInstallationsID); |
706 |
|
} |
707 |
|
else if(installernull < 2) |
708 |
|
{ |
709 |
|
SQL.Format("select installationphonenr, imei, updaterate from installation"); |
710 |
|
} |
711 |
|
CRecordset rs(&db); |
712 |
|
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
713 |
|
if (rs.GetRecordCount()>0) |
714 |
|
{ |
715 |
|
rs.MoveFirst(); |
716 |
|
while(!rs.IsEOF()) |
717 |
|
{ |
718 |
|
|
719 |
|
rs.GetFieldValue((short)0,phonenr); |
720 |
|
rs.GetFieldValue(1,imei); |
721 |
|
rs.GetFieldValue(2,updaterate); |
722 |
|
|
723 |
|
Myinst.InstPhoneNr = phonenr; |
724 |
|
Myinst.Imei = imei; |
725 |
|
Myinst.Updaterate = updaterate; |
726 |
|
|
727 |
|
buffer.push_back(Myinst); |
728 |
|
rs.MoveNext(); |
729 |
|
} |
730 |
|
} |
731 |
|
rs.Close(); |
732 |
|
return buffer; |
733 |
|
} |
734 |
|
int CFlisServerDlg::tversum(__int64 input) |
735 |
|
{ |
736 |
|
int sum = 0; |
737 |
|
while (input > 0) |
738 |
|
{ |
739 |
|
sum += (input %10); |
740 |
|
input /= 10; |
741 |
|
} |
742 |
|
return sum; |
743 |
|
} |
744 |
|
void CFlisServerDlg::OnBnClickedStart() |
745 |
|
{ |
746 |
|
// TODO: Add your control notification handler code here |
747 |
|
|
748 |
|
continueThread = 1; |
749 |
|
m_Textwindow.SetWindowText("Started"); |
750 |
|
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
751 |
|
} |
752 |
|
void CFlisServerDlg::AppendText(CString s) |
753 |
|
{ |
754 |
|
CString Tekst; |
755 |
|
m_Textwindow.GetWindowText(Tekst); |
756 |
|
Tekst.Append("\r\n"); |
757 |
|
Tekst.Append(s); |
758 |
|
m_Textwindow.SetWindowText(Tekst); |
759 |
|
|
760 |
|
} |
761 |
|
void ConfigFile::ReadSettings() |
762 |
|
{ |
763 |
|
ifstream file("Server-Settings.ini"); |
764 |
|
if (!file.is_open()) |
765 |
|
throw("Could not open file"); |
766 |
|
|
767 |
|
char buf[200]; |
768 |
|
while (!file.eof() ) { |
769 |
|
file.getline(buf,200); |
770 |
|
CString tmp(buf); |
771 |
|
|
772 |
|
if (tmp.GetAt(0) == '#') |
773 |
|
continue; |
774 |
|
|
775 |
|
int pos = tmp.Find('='); |
776 |
|
if (pos>0) { |
777 |
|
CString key = tmp.Left(pos).Trim().MakeLower();; |
778 |
|
CString value = tmp.Right(tmp.GetLength()-pos-1).Trim(); |
779 |
|
|
780 |
|
if (key == "host") |
781 |
|
host = value; |
782 |
|
else if (key == "username") |
783 |
|
username = value; |
784 |
|
else if (key == "password") |
785 |
|
password = value; |
786 |
|
else if (key == "database") |
787 |
|
database = value; |
788 |
|
else if (key == "comport") |
789 |
|
comport = value; |
790 |
|
} |
791 |
|
|
792 |
|
} |
793 |
|
|
794 |
|
file.close(); |
795 |
} |
} |