1 |
// FlisServerDlg.cpp : implementation file
|
2 |
//
|
3 |
|
4 |
#include "stdafx.h"
|
5 |
#include "FlisServer.h"
|
6 |
#include "FlisServerDlg.h"
|
7 |
#include <vector>
|
8 |
|
9 |
#ifdef _DEBUG
|
10 |
#define new DEBUG_NEW
|
11 |
#endif
|
12 |
|
13 |
|
14 |
// CAboutDlg dialog used for App About
|
15 |
|
16 |
class CAboutDlg : public CDialog
|
17 |
{
|
18 |
public:
|
19 |
CAboutDlg();
|
20 |
|
21 |
// Dialog Data
|
22 |
enum { IDD = IDD_ABOUTBOX };
|
23 |
|
24 |
protected:
|
25 |
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
26 |
|
27 |
// Implementation
|
28 |
protected:
|
29 |
DECLARE_MESSAGE_MAP()
|
30 |
};
|
31 |
|
32 |
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
|
33 |
{
|
34 |
}
|
35 |
|
36 |
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
|
37 |
{
|
38 |
CDialog::DoDataExchange(pDX);
|
39 |
}
|
40 |
|
41 |
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
|
42 |
END_MESSAGE_MAP()
|
43 |
|
44 |
|
45 |
// CFlisServerDlg dialog
|
46 |
|
47 |
|
48 |
|
49 |
CFlisServerDlg::CFlisServerDlg(CWnd* pParent /*=NULL*/)
|
50 |
: CDialog(CFlisServerDlg::IDD, pParent)
|
51 |
{
|
52 |
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
53 |
}
|
54 |
|
55 |
void CFlisServerDlg::DoDataExchange(CDataExchange* pDX)
|
56 |
{
|
57 |
CDialog::DoDataExchange(pDX);
|
58 |
DDX_Control(pDX, IDC_Textwindow, m_Textwindow);
|
59 |
}
|
60 |
|
61 |
BEGIN_MESSAGE_MAP(CFlisServerDlg, CDialog)
|
62 |
ON_WM_SYSCOMMAND()
|
63 |
ON_WM_PAINT()
|
64 |
ON_WM_QUERYDRAGICON()
|
65 |
ON_MESSAGE(UWM_MYMESSAGE, OnShowString)
|
66 |
//}}AFX_MSG_MAP
|
67 |
ON_BN_CLICKED(IDC_test, OnBnClickedtest)
|
68 |
ON_BN_CLICKED(IDCLOSE, OnBnClickedClose)
|
69 |
ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin)
|
70 |
END_MESSAGE_MAP()
|
71 |
|
72 |
|
73 |
// CFlisServerDlg message handlers
|
74 |
|
75 |
BOOL CFlisServerDlg::OnInitDialog()
|
76 |
{
|
77 |
CDialog::OnInitDialog();
|
78 |
|
79 |
// Add "About..." menu item to system menu.
|
80 |
|
81 |
// IDM_ABOUTBOX must be in the system command range.
|
82 |
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
|
83 |
ASSERT(IDM_ABOUTBOX < 0xF000);
|
84 |
|
85 |
CMenu* pSysMenu = GetSystemMenu(FALSE);
|
86 |
if (pSysMenu != NULL)
|
87 |
{
|
88 |
CString strAboutMenu;
|
89 |
strAboutMenu.LoadString(IDS_ABOUTBOX);
|
90 |
if (!strAboutMenu.IsEmpty())
|
91 |
{
|
92 |
pSysMenu->AppendMenu(MF_SEPARATOR);
|
93 |
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
|
94 |
}
|
95 |
}
|
96 |
|
97 |
// Set the icon for this dialog. The framework does this automatically
|
98 |
// when the application's main window is not a dialog
|
99 |
SetIcon(m_hIcon, TRUE); // Set big icon
|
100 |
SetIcon(m_hIcon, FALSE); // Set small icon
|
101 |
|
102 |
// TODO: Add extra initialization here
|
103 |
StartSerial();
|
104 |
DBConnect();
|
105 |
continueThread = 1;
|
106 |
ResetSms = 0;
|
107 |
/*
|
108 |
////////////Start Tråd////////////////////////
|
109 |
MyThread *t = new MyThread(AfxGetMainWnd());
|
110 |
t->start();
|
111 |
////////////Start Tråd////////////////////////
|
112 |
*/
|
113 |
AfxBeginThread(threadWrapper,AfxGetMainWnd());
|
114 |
|
115 |
return TRUE; // return TRUE unless you set the focus to a control
|
116 |
}
|
117 |
|
118 |
void CFlisServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
119 |
{
|
120 |
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
|
121 |
{
|
122 |
CAboutDlg dlgAbout;
|
123 |
dlgAbout.DoModal();
|
124 |
}
|
125 |
else
|
126 |
{
|
127 |
CDialog::OnSysCommand(nID, lParam);
|
128 |
}
|
129 |
}
|
130 |
|
131 |
// If you add a minimize button to your dialog, you will need the code below
|
132 |
// to draw the icon. For MFC applications using the document/view model,
|
133 |
// this is automatically done for you by the framework.
|
134 |
|
135 |
void CFlisServerDlg::OnPaint()
|
136 |
{
|
137 |
if (IsIconic())
|
138 |
{
|
139 |
CPaintDC dc(this); // device context for painting
|
140 |
|
141 |
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
142 |
|
143 |
// Center icon in client rectangle
|
144 |
int cxIcon = GetSystemMetrics(SM_CXICON);
|
145 |
int cyIcon = GetSystemMetrics(SM_CYICON);
|
146 |
CRect rect;
|
147 |
GetClientRect(&rect);
|
148 |
int x = (rect.Width() - cxIcon + 1) / 2;
|
149 |
int y = (rect.Height() - cyIcon + 1) / 2;
|
150 |
|
151 |
// Draw the icon
|
152 |
dc.DrawIcon(x, y, m_hIcon);
|
153 |
}
|
154 |
else
|
155 |
{
|
156 |
CDialog::OnPaint();
|
157 |
}
|
158 |
}
|
159 |
|
160 |
// The system calls this function to obtain the cursor to display while the user drags
|
161 |
// the minimized window.
|
162 |
HCURSOR CFlisServerDlg::OnQueryDragIcon()
|
163 |
{
|
164 |
return static_cast<HCURSOR>(m_hIcon);
|
165 |
}
|
166 |
int CFlisServerDlg::StartSerial(void)
|
167 |
{
|
168 |
int Baud;
|
169 |
CString SerialPort = "COM3";
|
170 |
|
171 |
Baud = 1200;
|
172 |
if( Serial.isOpen() ){
|
173 |
Serial.close();
|
174 |
Serial.open( SerialPort, Baud );
|
175 |
}
|
176 |
else {
|
177 |
Serial.open( SerialPort, Baud );
|
178 |
}
|
179 |
|
180 |
|
181 |
return 0;
|
182 |
}
|
183 |
std::vector<unsigned char> CFlisServerDlg::readFrame()
|
184 |
{
|
185 |
std::vector<unsigned char> buf;
|
186 |
while(Serial.getComstat().cbInQue > 0)
|
187 |
{
|
188 |
unsigned char data = Serial.readByte();
|
189 |
|
190 |
buf.push_back(data);
|
191 |
}
|
192 |
return buf;
|
193 |
}
|
194 |
void CFlisServerDlg::OnBnClickedtest()
|
195 |
{
|
196 |
// TODO: Add your control notification handler code here
|
197 |
|
198 |
/*
|
199 |
///////////////Send sms stuff/////////////////
|
200 |
vector<unsigned char> tlfnr;
|
201 |
vector<unsigned char> smsdata;
|
202 |
tlfnr.push_back('2');
|
203 |
tlfnr.push_back('9');
|
204 |
tlfnr.push_back('7');
|
205 |
tlfnr.push_back('2');
|
206 |
tlfnr.push_back('2');
|
207 |
tlfnr.push_back('6');
|
208 |
tlfnr.push_back('0');
|
209 |
tlfnr.push_back('3');
|
210 |
|
211 |
SendSmsHead(tlfnr);
|
212 |
|
213 |
//35:29860132:75 <--- demo pakke;
|
214 |
vector<unsigned char> smsdata;
|
215 |
smsdata.push_back('3');
|
216 |
smsdata.push_back('5');
|
217 |
smsdata.push_back(':');
|
218 |
smsdata.push_back('2');
|
219 |
smsdata.push_back('9');
|
220 |
smsdata.push_back('8');
|
221 |
smsdata.push_back('6');
|
222 |
smsdata.push_back('0');
|
223 |
smsdata.push_back('1');
|
224 |
smsdata.push_back('3');
|
225 |
smsdata.push_back('2');
|
226 |
smsdata.push_back(':');
|
227 |
smsdata.push_back('7');
|
228 |
smsdata.push_back('5');
|
229 |
|
230 |
SendSmsData(smsdata);
|
231 |
///////////////Send sms stuff/////////////////
|
232 |
*/
|
233 |
|
234 |
}
|
235 |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data)
|
236 |
{
|
237 |
for (int i=0; i<data.size(); i++)
|
238 |
{
|
239 |
Serial.writeByte( data[i] );
|
240 |
Sleep(5);
|
241 |
}
|
242 |
Serial.writeByte(0x0D);
|
243 |
Sleep(100);
|
244 |
|
245 |
}
|
246 |
void CFlisServerDlg::SetPin()
|
247 |
{
|
248 |
CString tekst;
|
249 |
std::vector<unsigned char> data;
|
250 |
data.push_back('a');
|
251 |
data.push_back('t');
|
252 |
data.push_back('+');
|
253 |
data.push_back('c');
|
254 |
data.push_back('p');
|
255 |
data.push_back('i');
|
256 |
data.push_back('n');
|
257 |
data.push_back('=');
|
258 |
data.push_back('2');
|
259 |
data.push_back('5');
|
260 |
data.push_back('9');
|
261 |
data.push_back('5');
|
262 |
|
263 |
writeFrame(data);
|
264 |
/* Sleep(750);
|
265 |
if(Serial.getComstat().cbInQue > 0)
|
266 |
{
|
267 |
std::vector<unsigned char> answer = readFrame();
|
268 |
Sleep(50);
|
269 |
char array1[25];
|
270 |
int i;
|
271 |
for (int i=0; i<answer.size(); i++)
|
272 |
{
|
273 |
array1[i] = answer[i];
|
274 |
}
|
275 |
|
276 |
for (int i=0; i<answer.size(); i++)
|
277 |
{
|
278 |
if ((array1[i] != 0x0A) && (array1[i] != 0x0D))
|
279 |
{
|
280 |
tekst.AppendChar(array1[i]);
|
281 |
}
|
282 |
}
|
283 |
m_Textwindow.SetWindowText(tekst);
|
284 |
}
|
285 |
*/
|
286 |
}
|
287 |
void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data)
|
288 |
{
|
289 |
|
290 |
for (int i=0; i<data.size(); i++)
|
291 |
{
|
292 |
Serial.writeByte( data[i] );
|
293 |
Sleep(5);
|
294 |
}
|
295 |
Serial.writeByte(0x1A);
|
296 |
Sleep(3000);
|
297 |
if(Serial.getComstat().cbInQue > 0)
|
298 |
{
|
299 |
CString tekst;
|
300 |
std::vector<unsigned char> answer = readFrame();
|
301 |
Sleep(50);
|
302 |
char array1[25];
|
303 |
int i;
|
304 |
for (int i=0; i<answer.size(); i++)
|
305 |
{
|
306 |
array1[i] = answer[i];
|
307 |
}
|
308 |
|
309 |
for (int i=0; i<answer.size(); i++)
|
310 |
{
|
311 |
if ((array1[i] != 0x0A) && (array1[i] != 0x0D))
|
312 |
{
|
313 |
tekst.AppendChar(array1[i]);
|
314 |
}
|
315 |
}
|
316 |
m_Textwindow.SetWindowText(tekst);
|
317 |
}
|
318 |
|
319 |
}
|
320 |
void CFlisServerDlg::SendSmsHead(std::vector<unsigned char> data)
|
321 |
{
|
322 |
vector<unsigned char> atcommand;
|
323 |
atcommand.push_back('a');
|
324 |
atcommand.push_back('t');
|
325 |
atcommand.push_back('+');
|
326 |
atcommand.push_back('c');
|
327 |
atcommand.push_back('m');
|
328 |
atcommand.push_back('g');
|
329 |
atcommand.push_back('s');
|
330 |
atcommand.push_back('=');
|
331 |
atcommand.push_back('"');
|
332 |
int s = (atcommand.size() -1 );
|
333 |
|
334 |
for (int i=0; i<(atcommand.size()); i++)
|
335 |
{
|
336 |
Serial.writeByte( atcommand[i] );
|
337 |
Sleep(5);
|
338 |
}
|
339 |
|
340 |
for (int i=0; i<data.size(); i++)
|
341 |
{
|
342 |
Serial.writeByte( data[i] );
|
343 |
Sleep(5);
|
344 |
}
|
345 |
Serial.writeByte(atcommand[s]);
|
346 |
Serial.writeByte(0x0D);
|
347 |
Sleep(250);
|
348 |
}
|
349 |
void CFlisServerDlg::DBConnect()
|
350 |
{
|
351 |
CString dsn;
|
352 |
dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=t-hoerup.dk; uid=serrenab;password=furnacemonitor;database=flisfyr;sslmode=prefer");
|
353 |
//dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=192.168.134.132; uid=serrenab;password=furnacemonitor;database=flisfyr;sslmode=prefer"); //skole server
|
354 |
db.OpenEx(dsn, CDatabase::noOdbcDialog);
|
355 |
}
|
356 |
vector<Commands> CFlisServerDlg::DBRead(void)
|
357 |
{
|
358 |
vector<Commands> buffer;
|
359 |
|
360 |
CString SQL, IDnr, CommandID, InstallationsID;
|
361 |
SQL = "select id,date_trunc('second', created) as created,executed,commandid,installationid from command WHERE executed IS NULL;";
|
362 |
CRecordset rs(&db);
|
363 |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL);
|
364 |
if (rs.GetRecordCount()>0)
|
365 |
{
|
366 |
rs.MoveFirst();
|
367 |
while(!rs.IsEOF())
|
368 |
{
|
369 |
Commands Mycom;
|
370 |
rs.GetFieldValue((short)0, IDnr);
|
371 |
rs.GetFieldValue(3, CommandID);
|
372 |
rs.GetFieldValue(4, InstallationsID);
|
373 |
|
374 |
Mycom.IDnr = IDnr;
|
375 |
Mycom.CommandID = CommandID;
|
376 |
Mycom.InstallationsID = InstallationsID;
|
377 |
|
378 |
buffer.push_back(Mycom);
|
379 |
rs.MoveNext();
|
380 |
}
|
381 |
}
|
382 |
rs.Close();
|
383 |
return buffer;
|
384 |
}
|
385 |
void CFlisServerDlg::ReadSms()
|
386 |
{
|
387 |
CString tekst, oldtekst;
|
388 |
Sleep(950);
|
389 |
if(Serial.getComstat().cbInQue > 0)
|
390 |
{
|
391 |
std::vector<unsigned char> answer = readFrame();
|
392 |
Sleep(50);
|
393 |
char array1[250];
|
394 |
int i;
|
395 |
for (int i=0; i<answer.size(); i++)
|
396 |
{
|
397 |
array1[i] = answer[i];
|
398 |
}
|
399 |
|
400 |
for (int i=0; i<answer.size(); i++)
|
401 |
{
|
402 |
if ((array1[i] != 0x0A) && (array1[i] != 0x0D))
|
403 |
{
|
404 |
tekst.AppendChar(array1[i]);
|
405 |
}
|
406 |
}
|
407 |
|
408 |
m_Textwindow.GetWindowText(oldtekst);
|
409 |
oldtekst.Append("\r\n");
|
410 |
oldtekst.Append(tekst);
|
411 |
m_Textwindow.SetWindowText(oldtekst);
|
412 |
SmsSplit(tekst);
|
413 |
}
|
414 |
}
|
415 |
void CFlisServerDlg::SmsSplit(CString data)
|
416 |
{
|
417 |
CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail, oldtekst;
|
418 |
char CharData[150];
|
419 |
strcpy(CharData,data);
|
420 |
|
421 |
int s=24;
|
422 |
for (int i=0; i<=7; i++)
|
423 |
{
|
424 |
TlfNr.AppendChar(CharData[s]);
|
425 |
s++;
|
426 |
}
|
427 |
|
428 |
for (int s=57; s<=(data.GetLength()-3); s++)
|
429 |
{
|
430 |
FyrData.AppendChar(CharData[s]);
|
431 |
}
|
432 |
FyrData.Append(":");
|
433 |
|
434 |
SmsCount = Splitter(FyrData);
|
435 |
Temper = Splitter(FyrData);
|
436 |
Flamme = Splitter(FyrData);
|
437 |
Flis = Splitter(FyrData);
|
438 |
FremFejl = Splitter(FyrData);
|
439 |
PowerFail = Splitter(FyrData);
|
440 |
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
441 |
///////////////////// Her skal sendes data til databasen //////////////////////////////////////////////
|
442 |
m_Textwindow.GetWindowText(oldtekst);
|
443 |
oldtekst.Append("\r\n");
|
444 |
oldtekst.Append("På næste linie kommer SmsCount. \r\n");
|
445 |
oldtekst.Append(SmsCount);
|
446 |
oldtekst.Append("\r\n");
|
447 |
oldtekst.Append("På næste linie kommer Temper. \r\n");
|
448 |
oldtekst.Append(Temper);
|
449 |
oldtekst.Append("\r\n");
|
450 |
oldtekst.Append("På næste linie kommer Flamme. \r\n");
|
451 |
oldtekst.Append(Flamme);
|
452 |
oldtekst.Append("\r\n");
|
453 |
oldtekst.Append("På næste linie kommer Flis. \r\n");
|
454 |
oldtekst.Append(Flis);
|
455 |
oldtekst.Append("\r\n");
|
456 |
oldtekst.Append("På næste linie kommer FremFejl. \r\n");
|
457 |
oldtekst.Append(FremFejl);
|
458 |
oldtekst.Append("\r\n");
|
459 |
oldtekst.Append("På næste linie kommer PowerFail. \r\n");
|
460 |
oldtekst.Append(PowerFail);
|
461 |
oldtekst.Append("\r\n");
|
462 |
oldtekst.Append("På næste linie kommer TlfNR. \r\n");
|
463 |
oldtekst.Append(TlfNr);
|
464 |
m_Textwindow.SetWindowText(oldtekst);
|
465 |
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
466 |
///////////////////// Her skal sendes data til databasen //////////////////////////////////////////////
|
467 |
}
|
468 |
CString CFlisServerDlg::Splitter(CString& fyrdata)
|
469 |
{
|
470 |
CString Output;
|
471 |
|
472 |
int pos = fyrdata.Find(':',0);
|
473 |
if (pos != -1)
|
474 |
{
|
475 |
Output = fyrdata.Left(pos);
|
476 |
fyrdata = fyrdata.Right( fyrdata.GetLength() - pos -1);
|
477 |
}
|
478 |
return Output;
|
479 |
}
|
480 |
void CFlisServerDlg::OnBnClickedClose()
|
481 |
{
|
482 |
// TODO: Add your control notification handler code here
|
483 |
continueThread = 0;
|
484 |
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
|
485 |
|
486 |
Sleep(500);
|
487 |
if( Serial.isOpen() )
|
488 |
{
|
489 |
Serial.close();
|
490 |
}
|
491 |
|
492 |
if(db.IsOpen())
|
493 |
{
|
494 |
db.Close();
|
495 |
}
|
496 |
|
497 |
OnOK();
|
498 |
|
499 |
}
|
500 |
|
501 |
void CFlisServerDlg::OnBnClickedGsmpin()
|
502 |
{
|
503 |
// TODO: Add your control notification handler code here
|
504 |
SetPin();
|
505 |
//Sleep(5000);
|
506 |
}
|
507 |
void CFlisServerDlg::DeleteSms()
|
508 |
{
|
509 |
vector<unsigned char> atcommand;
|
510 |
atcommand.push_back('a');
|
511 |
atcommand.push_back('t');
|
512 |
atcommand.push_back('+');
|
513 |
atcommand.push_back('c');
|
514 |
atcommand.push_back('m');
|
515 |
atcommand.push_back('g');
|
516 |
atcommand.push_back('d');
|
517 |
atcommand.push_back('=');
|
518 |
atcommand.push_back('1');
|
519 |
atcommand.push_back(',');
|
520 |
atcommand.push_back('3');
|
521 |
|
522 |
writeFrame(atcommand);
|
523 |
Sleep(500);
|
524 |
}
|
525 |
LRESULT CFlisServerDlg::OnShowString(WPARAM wParam, LPARAM lParam)
|
526 |
{
|
527 |
CString *s = (CString*) lParam;
|
528 |
GetDlgItem(IDC_Textwindow)->SetWindowText(*s);
|
529 |
|
530 |
delete s;
|
531 |
return 0;
|
532 |
|
533 |
}UINT threadWrapper(LPVOID thread)
|
534 |
{
|
535 |
CFlisServerDlg *t = (CFlisServerDlg*) thread;
|
536 |
t->runthread();
|
537 |
return 0;
|
538 |
}
|
539 |
|
540 |
void CFlisServerDlg::startthread()
|
541 |
{
|
542 |
AfxBeginThread(threadWrapper, (LPVOID) this);
|
543 |
}
|
544 |
|
545 |
void CFlisServerDlg::runthread()
|
546 |
{
|
547 |
while (continueThread != 0)
|
548 |
{
|
549 |
Reader();
|
550 |
}
|
551 |
}
|
552 |
void CFlisServerDlg::Reader()
|
553 |
{
|
554 |
if(Serial.getComstat().cbInQue > 0)
|
555 |
{
|
556 |
Sleep(250);
|
557 |
std::vector<unsigned char> answer = readFrame();
|
558 |
Sleep(500);
|
559 |
CString tekst, oldtekst;
|
560 |
int lol;
|
561 |
char array1[250];
|
562 |
int i;
|
563 |
for (int i=0; i<answer.size(); i++)
|
564 |
{
|
565 |
array1[i] = answer[i];
|
566 |
}
|
567 |
|
568 |
for (int i=0; i<answer.size(); i++)
|
569 |
{
|
570 |
if ((array1[i] != 0x0A) && (array1[i] != 0x0D))
|
571 |
{
|
572 |
tekst.AppendChar(array1[i]);
|
573 |
}
|
574 |
}
|
575 |
tekst.Append(":");
|
576 |
|
577 |
CString command;
|
578 |
bool plus;
|
579 |
int pos = tekst.Find('+',0);
|
580 |
if (pos != -1)
|
581 |
{
|
582 |
plus = true;
|
583 |
tekst = tekst.Right( tekst.GetLength() - pos -1);
|
584 |
pos = tekst.Find(':');
|
585 |
command = tekst.Left(pos);
|
586 |
tekst = tekst.Right( tekst.GetLength() - pos -1);
|
587 |
}
|
588 |
|
589 |
|
590 |
if(tekst == "OK")
|
591 |
{
|
592 |
m_Textwindow.GetWindowText(oldtekst);
|
593 |
oldtekst.Append("\r\n");
|
594 |
oldtekst.Append("OK tekst modtaget");
|
595 |
m_Textwindow.SetWindowText(oldtekst);
|
596 |
}
|
597 |
else if (tekst == "error")
|
598 |
{
|
599 |
m_Textwindow.GetWindowText(oldtekst);
|
600 |
oldtekst.Append("\r\n");
|
601 |
oldtekst.Append("error tekst");
|
602 |
oldtekst.Append(tekst);
|
603 |
m_Textwindow.SetWindowText(oldtekst);
|
604 |
}
|
605 |
else if (plus = true)
|
606 |
{
|
607 |
if (command = "cmti")
|
608 |
{
|
609 |
CString smscount, oldteskst;
|
610 |
int pos = tekst.Find(',',0);
|
611 |
if (pos != -1)
|
612 |
{
|
613 |
smscount = tekst.Right( tekst.GetLength() - pos -1);
|
614 |
smscount.Remove(':');
|
615 |
ResetSms++;
|
616 |
}
|
617 |
////////////////Read sms ting//////////////////
|
618 |
std::vector<unsigned char> data;
|
619 |
data.push_back('a');
|
620 |
data.push_back('t');
|
621 |
data.push_back('+');
|
622 |
data.push_back('c');
|
623 |
data.push_back('m');
|
624 |
data.push_back('g');
|
625 |
data.push_back('r');
|
626 |
data.push_back('=');
|
627 |
|
628 |
for (int i=0; i< smscount.GetLength(); i++)
|
629 |
{
|
630 |
data.push_back(smscount[i]);
|
631 |
}
|
632 |
for (int i=0; i<data.size();i++)
|
633 |
{
|
634 |
oldteskst.AppendChar(data[i]);
|
635 |
}
|
636 |
m_Textwindow.SetWindowText(oldteskst);
|
637 |
writeFrame(data);
|
638 |
Sleep(200);
|
639 |
ReadSms();
|
640 |
|
641 |
}
|
642 |
else if(command = "wind")
|
643 |
{
|
644 |
m_Textwindow.GetWindowText(oldtekst);
|
645 |
oldtekst.Append("\r\n");
|
646 |
oldtekst.Append("Først lidt tekst på næste linie\r\n");
|
647 |
oldtekst.Append(tekst);
|
648 |
m_Textwindow.SetWindowText(oldtekst);
|
649 |
}
|
650 |
}
|
651 |
if(ResetSms == 50)
|
652 |
{
|
653 |
DeleteSms();
|
654 |
}
|
655 |
|
656 |
}
|
657 |
if (continueThread = 1)
|
658 |
{
|
659 |
|
660 |
////////////////DBRead stuff//////////////////
|
661 |
CString testdata, dataframe,testprint, sIDnr, sCommandID, sInstallationsID;
|
662 |
std::vector<Commands> data;
|
663 |
data = DBRead();
|
664 |
for (int i=0; i<data.size(); i++)
|
665 |
{
|
666 |
testdata.Append(data[i].IDnr);
|
667 |
testdata.Append(":");
|
668 |
testdata.Append(data[i].CommandID);
|
669 |
testdata.Append(":");
|
670 |
testdata.Append(data[i].InstallationsID);
|
671 |
testdata.Append(":");
|
672 |
}
|
673 |
sIDnr = Splitter(testdata);
|
674 |
sCommandID = Splitter(testdata);
|
675 |
sInstallationsID = Splitter(testdata);
|
676 |
|
677 |
testprint.Append("sIDnr på næste linie\r\n");
|
678 |
testprint.Append(sIDnr);
|
679 |
testprint.Append("\r\n");
|
680 |
testprint.Append("sCommandID på næste linie\r\n");
|
681 |
testprint.Append(sCommandID);
|
682 |
testprint.Append("\r\n");
|
683 |
testprint.Append("sInstallationsID på næste linie\r\n");
|
684 |
testprint.Append(sInstallationsID);
|
685 |
m_Textwindow.SetWindowText(testprint);
|
686 |
|
687 |
|
688 |
if (sIDnr.GetLength() > 0)
|
689 |
{
|
690 |
DBReadData(sIDnr,sCommandID,sInstallationsID);
|
691 |
}
|
692 |
Sleep(500);
|
693 |
////////////////DBRead stuff//////////////////
|
694 |
}
|
695 |
}
|
696 |
void CFlisServerDlg::DBReadData(CString IDnr,CString CommandID,CString InstallationsID)
|
697 |
{
|
698 |
CString TlfNr;
|
699 |
|
700 |
//kald dbreadphone som du kalder dbread
|
701 |
std::vector<Installation> inst;
|
702 |
inst = DBReadPhone(InstallationsID);
|
703 |
for (int i=0; i<inst.size(); i++)
|
704 |
{
|
705 |
CString dataen = inst[i].InstPhoneNr;
|
706 |
TlfNr.Append(dataen);
|
707 |
}
|
708 |
vector<unsigned char> tlfnr;
|
709 |
for (int i=0; i<TlfNr.GetLength(); i++)
|
710 |
{
|
711 |
tlfnr.push_back(TlfNr[i]);
|
712 |
}
|
713 |
|
714 |
SendSmsHead(tlfnr);
|
715 |
Sleep(500);
|
716 |
//35:29860132:75 <--- demo pakke;
|
717 |
vector<unsigned char> smsdata;
|
718 |
smsdata.push_back('3');
|
719 |
smsdata.push_back('5');
|
720 |
smsdata.push_back(':');
|
721 |
smsdata.push_back('2');
|
722 |
smsdata.push_back('9');
|
723 |
smsdata.push_back('8');
|
724 |
smsdata.push_back('6');
|
725 |
smsdata.push_back('0');
|
726 |
smsdata.push_back('1');
|
727 |
smsdata.push_back('3');
|
728 |
smsdata.push_back('2');
|
729 |
smsdata.push_back(':');
|
730 |
smsdata.push_back('7');
|
731 |
smsdata.push_back('5');
|
732 |
|
733 |
SendSmsData(smsdata);
|
734 |
Sleep(250);
|
735 |
|
736 |
CString SQL;
|
737 |
|
738 |
SQL.Format("update command set executed=now() where id=%s",IDnr);
|
739 |
db.ExecuteSQL(SQL);
|
740 |
Sleep(150);
|
741 |
}
|
742 |
vector<Installation> CFlisServerDlg::DBReadPhone(CString sInstallationsID)
|
743 |
{
|
744 |
vector<Installation> buffer;
|
745 |
|
746 |
CString SQL, phonenr;
|
747 |
SQL.Format("select installationphonenr from installation WHERE id = %s",sInstallationsID);
|
748 |
CRecordset rs(&db);
|
749 |
rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL);
|
750 |
if (rs.GetRecordCount()>0)
|
751 |
{
|
752 |
rs.MoveFirst();
|
753 |
while(!rs.IsEOF())
|
754 |
{
|
755 |
Installation Myinst;
|
756 |
rs.GetFieldValue((short)0,phonenr);
|
757 |
|
758 |
Myinst.InstPhoneNr.Append(phonenr);
|
759 |
|
760 |
buffer.push_back(Myinst);
|
761 |
rs.MoveNext();
|
762 |
}
|
763 |
}
|
764 |
rs.Close();
|
765 |
return buffer;
|
766 |
} |