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 |
|
#include ".\flisserverdlg.h" |
9 |
|
|
10 |
#ifdef _DEBUG |
#ifdef _DEBUG |
11 |
#define new DEBUG_NEW |
#define new DEBUG_NEW |
64 |
ON_WM_PAINT() |
ON_WM_PAINT() |
65 |
ON_WM_QUERYDRAGICON() |
ON_WM_QUERYDRAGICON() |
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 |
|
ResetSms = 0; |
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 |
|
|
/* |
|
|
////////////////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'); |
|
213 |
|
|
|
writeFrame(data); |
|
|
ReadSms(); |
|
|
////////////////Read sms ting////////////////// |
|
|
*/ |
|
|
/* |
|
|
////////////////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); |
|
|
|
|
|
//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///////////////// |
|
|
*/ |
|
|
} |
|
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++) |
222 |
Sleep(100); |
Sleep(100); |
223 |
|
|
224 |
} |
} |
225 |
int CFlisServerDlg::SetPin(void) |
void CFlisServerDlg::SetPin() |
226 |
{ |
{ |
227 |
CString tekst; |
CString tekst; |
228 |
std::vector<unsigned char> data; |
std::vector<unsigned char> data; |
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); |
|
|
} |
|
|
return 0; |
|
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=192.168.134.132; uid=serrenab;password=furnacemonitor;database=flisfyr;sslmode=prefer"); |
ConfigFile config; |
304 |
|
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()-59); |
|
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); |
try |
392 |
oldtekst.Append("\r\n"); |
{ |
393 |
oldtekst.Append("På næste linie kommer FremFejl. \r\n"); |
db.ExecuteSQL(SQL); |
394 |
oldtekst.Append(FremFejl); |
} |
395 |
oldtekst.Append("\r\n"); |
catch(CDBException* e) |
396 |
oldtekst.Append("På næste linie kommer PowerFail. \r\n"); |
{ |
397 |
oldtekst.Append(PowerFail); |
MessageBox(e->m_strError); |
398 |
m_Textwindow.SetWindowText(oldtekst); |
} |
399 |
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
AppendText("Sms added to Log"); |
400 |
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
Sleep(150); |
401 |
} |
} |
402 |
CString CFlisServerDlg::Splitter(CString& fyrdata) |
CString CFlisServerDlg::Splitter(CString& fyrdata) |
403 |
{ |
{ |
414 |
void CFlisServerDlg::OnBnClickedClose() |
void CFlisServerDlg::OnBnClickedClose() |
415 |
{ |
{ |
416 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
417 |
|
continueThread = 0; |
418 |
|
DeleteSms(); |
419 |
|
|
420 |
|
Sleep(500); |
421 |
if( Serial.isOpen() ) |
if( Serial.isOpen() ) |
422 |
{ |
{ |
423 |
Serial.close(); |
Serial.close(); |
425 |
|
|
426 |
if(db.IsOpen()) |
if(db.IsOpen()) |
427 |
{ |
{ |
428 |
db.Close(); |
db.Close(); |
429 |
} |
} |
430 |
|
|
431 |
OnOK(); |
OnOK(); |
432 |
|
|
433 |
} |
} |
434 |
|
|
435 |
void CFlisServerDlg::OnBnClickedGsmpin() |
void CFlisServerDlg::OnBnClickedGsmpin() |
436 |
{ |
{ |
437 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
438 |
|
m_Textwindow.SetWindowText("Indsætter Pinkode, efterfuldt af 60sec pause"); |
439 |
|
UpdateWindow(); |
440 |
SetPin(); |
SetPin(); |
441 |
|
Sleep(50000); |
442 |
|
|
443 |
|
while (Serial.getComstat().cbInQue > 0) |
444 |
|
{ |
445 |
|
Serial.readByte(); //Flush the incoming queue |
446 |
|
} |
447 |
|
|
448 |
|
OnBnClickedStart(); |
449 |
|
} |
450 |
|
void CFlisServerDlg::DeleteSms() |
451 |
|
{ |
452 |
|
vector<unsigned char> atcommand; |
453 |
|
atcommand.push_back('a'); |
454 |
|
atcommand.push_back('t'); |
455 |
|
atcommand.push_back('+'); |
456 |
|
atcommand.push_back('c'); |
457 |
|
atcommand.push_back('m'); |
458 |
|
atcommand.push_back('g'); |
459 |
|
atcommand.push_back('d'); |
460 |
|
atcommand.push_back('='); |
461 |
|
atcommand.push_back('1'); |
462 |
|
atcommand.push_back(','); |
463 |
|
atcommand.push_back('3'); |
464 |
|
|
465 |
|
writeFrame(atcommand); |
466 |
|
Sleep(500); |
467 |
|
} |
468 |
|
UINT threadWrapper(LPVOID thread) |
469 |
|
{ |
470 |
|
CFlisServerDlg *t = (CFlisServerDlg*) thread; |
471 |
|
t->runthread(); |
472 |
|
return 0; |
473 |
|
} |
474 |
|
|
475 |
|
void CFlisServerDlg::startthread() |
476 |
|
{ |
477 |
|
AfxBeginThread(threadWrapper, (LPVOID) this); |
478 |
|
} |
479 |
|
|
480 |
|
void CFlisServerDlg::runthread() |
481 |
|
{ |
482 |
|
while (continueThread != 0) |
483 |
|
{ |
484 |
|
Reader(); |
485 |
|
} |
486 |
|
} |
487 |
|
void CFlisServerDlg::Reader() |
488 |
|
{ |
489 |
|
if(Serial.getComstat().cbInQue > 0) |
490 |
|
{ |
491 |
|
Sleep(250); |
492 |
|
std::vector<unsigned char> answer = readFrame(); |
493 |
|
Sleep(500); |
494 |
|
CString tekst, oldtekst; |
495 |
|
int lol; |
496 |
|
|
497 |
|
for (int i=0; i<answer.size(); i++) |
498 |
|
{ |
499 |
|
if ((answer[i] != 0x0A) && (answer[i] != 0x0D)) |
500 |
|
{ |
501 |
|
tekst.AppendChar(answer[i]); |
502 |
|
} |
503 |
|
} |
504 |
|
tekst.Append(":"); |
505 |
|
|
506 |
|
CString command; |
507 |
|
bool plus; |
508 |
|
int pos = tekst.Find('+',0); |
509 |
|
if (pos != -1) |
510 |
|
{ |
511 |
|
plus = true; |
512 |
|
tekst = tekst.Right( tekst.GetLength() - pos -1); |
513 |
|
pos = tekst.Find(':'); |
514 |
|
command = tekst.Left(pos); |
515 |
|
tekst = tekst.Right( tekst.GetLength() - pos -1); |
516 |
|
} |
517 |
|
|
518 |
|
|
519 |
|
if(tekst.MakeLower() == "ok") |
520 |
|
{ |
521 |
|
AppendText("OK tekst modtaget"); |
522 |
|
} |
523 |
|
else if (tekst.MakeLower() == "error") |
524 |
|
{ |
525 |
|
CString send; |
526 |
|
send.Append("error tekst"); |
527 |
|
send.Append("\r\n"); |
528 |
|
send.Append(tekst); |
529 |
|
AppendText(send); |
530 |
|
} |
531 |
|
else if (plus == true) |
532 |
|
{ |
533 |
|
if (command.MakeLower() == "cmti") |
534 |
|
{ |
535 |
|
CString smscount, oldteskst; |
536 |
|
int pos = tekst.Find(',',0); |
537 |
|
if (pos != -1) |
538 |
|
{ |
539 |
|
smscount = tekst.Right( tekst.GetLength() - pos -1); |
540 |
|
smscount.Remove(':'); |
541 |
|
ResetSms++; |
542 |
|
} |
543 |
|
////////////////Read sms ting////////////////// |
544 |
|
std::vector<unsigned char> data; |
545 |
|
data.push_back('a'); |
546 |
|
data.push_back('t'); |
547 |
|
data.push_back('+'); |
548 |
|
data.push_back('c'); |
549 |
|
data.push_back('m'); |
550 |
|
data.push_back('g'); |
551 |
|
data.push_back('r'); |
552 |
|
data.push_back('='); |
553 |
|
|
554 |
|
for (int i=0; i< smscount.GetLength(); i++) |
555 |
|
{ |
556 |
|
data.push_back(smscount[i]); |
557 |
|
} |
558 |
|
m_Textwindow.GetWindowText(oldteskst); |
559 |
|
oldteskst.Append("\r\n"); |
560 |
|
for (int i=0; i<data.size();i++) |
561 |
|
{ |
562 |
|
oldteskst.AppendChar(data[i]); |
563 |
|
} |
564 |
|
m_Textwindow.SetWindowText(oldteskst); |
565 |
|
writeFrame(data); |
566 |
|
Sleep(200); |
567 |
|
ReadSms(); |
568 |
|
ResetSms++; |
569 |
|
|
570 |
|
} |
571 |
|
else if(command.MakeLower() == "wind") |
572 |
|
{ |
573 |
|
|
574 |
|
CString send; |
575 |
|
send.Append("Wind modtaget"); |
576 |
|
send.Append("\r\n"); |
577 |
|
send.Append(tekst); |
578 |
|
AppendText(send); |
579 |
|
} |
580 |
|
} |
581 |
|
else |
582 |
|
{ |
583 |
|
CString send; |
584 |
|
send.Append("Anden tekst end forventet"); |
585 |
|
send.Append("\r\n"); |
586 |
|
send.Append(tekst); |
587 |
|
AppendText(send); |
588 |
|
} |
589 |
|
if(ResetSms == 20) |
590 |
|
{ |
591 |
|
DeleteSms(); |
592 |
|
AppendText("Sms'er slettet da vi nåede grænsen"); |
593 |
|
} |
594 |
|
|
595 |
|
} |
596 |
|
if (continueThread == 1) |
597 |
|
{ |
598 |
|
|
599 |
|
CString testdata, dataframe,testprint, sIDnr, sCommandID, sInstallationsID, sImei; |
600 |
|
int commandtest = 0; |
601 |
|
int iAll = 1; |
602 |
|
std::vector<Commands> data; |
603 |
|
data = DBReadCommands(); |
604 |
|
for (int i=0; i<data.size(); i++) |
605 |
|
{ |
606 |
|
sIDnr = data[i].IDnr; |
607 |
|
sCommandID = data[i].CommandID; |
608 |
|
commandtest = atoi(data[i].CommandID); |
609 |
|
sInstallationsID = "0"; |
610 |
|
|
611 |
|
if(commandtest > 1) |
612 |
|
{ |
613 |
|
sInstallationsID = data[i].InstallationsID; |
614 |
|
} |
615 |
|
} |
616 |
|
|
617 |
|
if (commandtest > 1) |
618 |
|
{ |
619 |
|
iAll = 0; |
620 |
|
} |
621 |
|
|
622 |
|
if (sIDnr.GetLength() > 0) |
623 |
|
{ |
624 |
|
SendConfig(sIDnr,sCommandID,sInstallationsID); |
625 |
|
} |
626 |
|
Sleep(500); |
627 |
|
} |
628 |
|
} |
629 |
|
void CFlisServerDlg::SendConfig(CString IDnr,CString CommandID,CString InstallationsID) |
630 |
|
{ |
631 |
|
CString ServerTlfNr; |
632 |
|
int i = 0; |
633 |
|
ServerTlfNr = "29860132"; |
634 |
|
|
635 |
|
|
636 |
|
std::vector<Installation> inst; |
637 |
|
inst = DBReadPhone(InstallationsID); |
638 |
|
while (i < inst.size()) |
639 |
|
{ |
640 |
|
CString TlfNr, Imei, updaterate; |
641 |
|
TlfNr.Empty(); |
642 |
|
Imei.Empty(); |
643 |
|
updaterate.Empty(); |
644 |
|
|
645 |
|
CString dataen = inst[i].InstPhoneNr; |
646 |
|
TlfNr.Append(dataen); |
647 |
|
CString Imeidata = inst[i].Imei; |
648 |
|
Imei.Append(Imeidata); |
649 |
|
CString updaterat = inst[i].Updaterate; |
650 |
|
updaterate.Append(updaterat); |
651 |
|
i++; |
652 |
|
|
653 |
|
vector<unsigned char> tlfnr; |
654 |
|
for (int i=0; i<TlfNr.GetLength(); i++) |
655 |
|
{ |
656 |
|
tlfnr.push_back(TlfNr[i]); |
657 |
|
} |
658 |
|
|
659 |
|
int calcimei; |
660 |
|
__int64 buf; |
661 |
|
|
662 |
|
buf = atof(Imei); |
663 |
|
|
664 |
|
calcimei = tversum(buf); |
665 |
|
|
666 |
|
Imei.Format("%d",calcimei); |
667 |
|
|
668 |
|
SendSmsHead(tlfnr); |
669 |
|
Sleep(250); |
670 |
|
|
671 |
|
vector<unsigned char> smsdata; |
672 |
|
|
673 |
|
for (int i=0; i<Imei.GetLength(); i++) |
674 |
|
{ |
675 |
|
smsdata.push_back(Imei[i]); |
676 |
|
} |
677 |
|
smsdata.push_back(':'); |
678 |
|
for (int i=0; i<ServerTlfNr.GetLength(); i++) |
679 |
|
{ |
680 |
|
smsdata.push_back(ServerTlfNr[i]); |
681 |
|
} |
682 |
|
smsdata.push_back(':'); |
683 |
|
for (int i=0; i<updaterate.GetLength(); i++) |
684 |
|
{ |
685 |
|
smsdata.push_back(updaterate[i]); |
686 |
|
} |
687 |
|
|
688 |
|
SendSmsData(smsdata); |
689 |
|
Sleep(500); |
690 |
|
|
691 |
|
} |
692 |
|
CString SQL, Textwindow; |
693 |
|
SQL.Format("update command set executed=now() where id=%s",IDnr); |
694 |
|
db.ExecuteSQL(SQL); |
695 |
|
AppendText("Command executed"); |
696 |
|
Sleep(150); |
697 |
|
|
698 |
|
} |
699 |
|
vector<Installation> CFlisServerDlg::DBReadPhone(CString sInstallationsID) |
700 |
|
{ |
701 |
|
vector<Installation> buffer; |
702 |
|
|
703 |
|
CString SQL, phonenr, imei, updaterate; |
704 |
|
int installernull; |
705 |
|
Installation Myinst; |
706 |
|
installernull = atoi(sInstallationsID); |
707 |
|
if (installernull > 1) |
708 |
|
{ |
709 |
|
SQL.Format("select installationphonenr, imei, updaterate from installation WHERE id = %s", sInstallationsID); |
710 |
|
} |
711 |
|
else if(installernull < 2) |
712 |
|
{ |
713 |
|
SQL.Format("select installationphonenr, imei, updaterate from installation"); |
714 |
|
} |
715 |
|
CRecordset rs(&db); |
716 |
|
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); |
717 |
|
if (rs.GetRecordCount()>0) |
718 |
|
{ |
719 |
|
rs.MoveFirst(); |
720 |
|
while(!rs.IsEOF()) |
721 |
|
{ |
722 |
|
|
723 |
|
rs.GetFieldValue((short)0,phonenr); |
724 |
|
rs.GetFieldValue(1,imei); |
725 |
|
rs.GetFieldValue(2,updaterate); |
726 |
|
|
727 |
|
Myinst.InstPhoneNr = phonenr; |
728 |
|
Myinst.Imei = imei; |
729 |
|
Myinst.Updaterate = updaterate; |
730 |
|
|
731 |
|
buffer.push_back(Myinst); |
732 |
|
rs.MoveNext(); |
733 |
|
} |
734 |
|
} |
735 |
|
rs.Close(); |
736 |
|
return buffer; |
737 |
} |
} |
738 |
|
int CFlisServerDlg::tversum(__int64 input) |
739 |
|
{ |
740 |
|
int sum = 0; |
741 |
|
while (input > 0) |
742 |
|
{ |
743 |
|
sum += (input %10); |
744 |
|
input /= 10; |
745 |
|
} |
746 |
|
return sum; |
747 |
|
} |
748 |
|
void CFlisServerDlg::OnBnClickedStart() |
749 |
|
{ |
750 |
|
// TODO: Add your control notification handler code here |
751 |
|
|
752 |
|
continueThread = 1; |
753 |
|
m_Textwindow.SetWindowText("Started"); |
754 |
|
AfxBeginThread(threadWrapper,AfxGetMainWnd()); |
755 |
|
} |
756 |
|
void CFlisServerDlg::AppendText(CString s) |
757 |
|
{ |
758 |
|
CString Tekst; |
759 |
|
m_Textwindow.GetWindowText(Tekst); |
760 |
|
Tekst.Append("\r\n"); |
761 |
|
Tekst.Append(s); |
762 |
|
m_Textwindow.SetWindowText(Tekst); |
763 |
|
|
764 |
|
} |
765 |
|
void ConfigFile::ReadSettings() |
766 |
|
{ |
767 |
|
ifstream file("Server-Settings.ini"); |
768 |
|
if (!file.is_open()) |
769 |
|
throw("Could not open file"); |
770 |
|
|
771 |
|
char buf[200]; |
772 |
|
while (!file.eof() ) { |
773 |
|
file.getline(buf,200); |
774 |
|
CString tmp(buf); |
775 |
|
|
776 |
|
if (tmp.GetAt(0) == '#') |
777 |
|
continue; |
778 |
|
|
779 |
|
int pos = tmp.Find('='); |
780 |
|
if (pos>0) { |
781 |
|
CString key = tmp.Left(pos).Trim().MakeLower();; |
782 |
|
CString value = tmp.Right(tmp.GetLength()-pos-1).Trim(); |
783 |
|
|
784 |
|
if (key == "host") |
785 |
|
host = value; |
786 |
|
else if (key == "username") |
787 |
|
username = value; |
788 |
|
else if (key == "password") |
789 |
|
password = value; |
790 |
|
else if (key == "database") |
791 |
|
database = value; |
792 |
|
else if (key == "comport") |
793 |
|
comport = value; |
794 |
|
} |
795 |
|
|
796 |
|
} |
797 |
|
|
798 |
|
file.close(); |
799 |
|
} |