51 |
: CDialog(CFlisServerDlg::IDD, pParent) |
: CDialog(CFlisServerDlg::IDD, pParent) |
52 |
{ |
{ |
53 |
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); |
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); |
54 |
|
db = 0; |
55 |
} |
} |
56 |
|
|
57 |
void CFlisServerDlg::DoDataExchange(CDataExchange* pDX) |
void CFlisServerDlg::DoDataExchange(CDataExchange* pDX) |
102 |
|
|
103 |
// TODO: Add extra initialization here |
// TODO: Add extra initialization here |
104 |
StartSerial(); |
StartSerial(); |
105 |
SetPin(); |
//SetPin(); |
106 |
|
DBConnect(); |
107 |
|
|
108 |
return TRUE; // return TRUE unless you set the focus to a control |
return TRUE; // return TRUE unless you set the focus to a control |
109 |
} |
} |
191 |
if( Serial.isOpen() ){ |
if( Serial.isOpen() ){ |
192 |
Serial.close(); |
Serial.close(); |
193 |
} |
} |
194 |
|
|
195 |
|
if (db != 0) |
196 |
|
{ |
197 |
|
//db->Close(); |
198 |
|
delete db; |
199 |
|
db=0; |
200 |
|
} |
201 |
} |
} |
202 |
|
|
203 |
void CFlisServerDlg::OnBnClickedCancel() |
void CFlisServerDlg::OnBnClickedCancel() |
207 |
if( Serial.isOpen() ){ |
if( Serial.isOpen() ){ |
208 |
Serial.close(); |
Serial.close(); |
209 |
} |
} |
210 |
|
|
211 |
|
if (db != 0) |
212 |
|
{ |
213 |
|
db->Close(); |
214 |
|
delete db; |
215 |
|
db = 0; |
216 |
|
} |
217 |
} |
} |
218 |
|
|
219 |
void CFlisServerDlg::OnBnClickedtest() |
void CFlisServerDlg::OnBnClickedtest() |
220 |
{ |
{ |
221 |
// TODO: Add your control notification handler code here |
// TODO: Add your control notification handler code here |
222 |
/* |
CString tekst; |
223 |
std::vector<unsigned char> data; |
std::vector<unsigned char> data; |
224 |
data.push_back('a'); |
data.push_back('a'); |
225 |
data.push_back('t'); |
data.push_back('t'); |
226 |
|
data.push_back('+'); |
227 |
|
data.push_back('c'); |
228 |
|
data.push_back('m'); |
229 |
|
data.push_back('g'); |
230 |
|
data.push_back('r'); |
231 |
|
data.push_back('='); |
232 |
|
data.push_back('1'); |
233 |
|
|
234 |
writeFrame(data); |
writeFrame(data); |
235 |
|
ReadSms(); |
|
if(Serial.getComstat().cbInQue > 0) |
|
|
{ |
|
|
std::vector<unsigned char> answer = readFrame(); |
|
|
Sleep(50); |
|
|
if (answer.size() == 0){ |
|
|
m_Textwindow.SetWindowText("ØV"); |
|
|
} |
|
|
else{ |
|
|
CString ko; |
|
|
char test[150]; |
|
|
int i; |
|
|
for (int i=0; i<answer.size(); i++) |
|
|
{ |
|
|
test[i] = answer[i]; |
|
|
} |
|
|
ko = test; |
|
|
m_Textwindow.SetWindowText(ko); |
|
|
} |
|
|
} |
|
|
*/ |
|
|
SetPin(); |
|
236 |
} |
} |
237 |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
void CFlisServerDlg::writeFrame(std::vector<unsigned char> data) |
238 |
{ |
{ |
247 |
} |
} |
248 |
int CFlisServerDlg::SetPin(void) |
int CFlisServerDlg::SetPin(void) |
249 |
{ |
{ |
250 |
CString tekst, oldtekst; |
CString tekst; |
251 |
std::vector<unsigned char> data; |
std::vector<unsigned char> data; |
252 |
data.push_back('a'); |
data.push_back('a'); |
253 |
data.push_back('t'); |
data.push_back('t'); |
282 |
tekst.AppendChar(array1[i]); |
tekst.AppendChar(array1[i]); |
283 |
} |
} |
284 |
} |
} |
285 |
|
m_Textwindow.SetWindowText(tekst); |
|
m_Textwindow.GetWindowText(oldtekst); |
|
|
oldtekst.Append("\r\n"); |
|
|
oldtekst.Append(tekst); |
|
|
m_Textwindow.SetWindowText(oldtekst); |
|
286 |
} |
} |
287 |
return 0; |
return 0; |
288 |
} |
} |
308 |
Sleep(100); |
Sleep(100); |
309 |
|
|
310 |
} |
} |
311 |
void CFlisServerDlg::DBconnect() |
void CFlisServerDlg::DBConnect() |
312 |
{ |
{ |
313 |
|
db = new CDatabase(); |
314 |
|
|
315 |
CString dsn; |
CString dsn; |
316 |
dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=%s; uid=%s;password=%s;database=%s",config.host, config.username, config.password, config.database); |
dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=192.168.134.132; uid=serrenab;password=furnacemonitor;database=flisfyr"); |
317 |
db.OpenEx(dsn, CDatabase::noOdbcDialog); |
//db->OpenEx(dsn, CDatabase::noOdbcDialog); |
318 |
|
|
319 |
|
} |
320 |
|
void CFlisServerDlg::DBRead() |
321 |
|
{ |
322 |
|
|
323 |
|
} |
324 |
|
void CFlisServerDlg::ReadSms() |
325 |
|
{ |
326 |
|
CString tekst, oldtekst; |
327 |
|
Sleep(950); |
328 |
|
if(Serial.getComstat().cbInQue > 0) |
329 |
|
{ |
330 |
|
std::vector<unsigned char> answer = readFrame(); |
331 |
|
Sleep(50); |
332 |
|
char array1[250]; |
333 |
|
int i; |
334 |
|
for (int i=0; i<answer.size(); i++) |
335 |
|
{ |
336 |
|
array1[i] = answer[i]; |
337 |
|
} |
338 |
|
|
339 |
|
for (int i=0; i<answer.size(); i++) |
340 |
|
{ |
341 |
|
if ((array1[i] != 0x0A) && (array1[i] != 0x0D)) |
342 |
|
{ |
343 |
|
tekst.AppendChar(array1[i]); |
344 |
|
} |
345 |
|
} |
346 |
|
|
347 |
|
m_Textwindow.GetWindowText(oldtekst); |
348 |
|
oldtekst.Append("\r\n"); |
349 |
|
oldtekst.Append(tekst); |
350 |
|
m_Textwindow.SetWindowText(oldtekst); |
351 |
|
SmsSplit(tekst); |
352 |
|
} |
353 |
|
} |
354 |
|
void CFlisServerDlg::SmsSplit(CString data) |
355 |
|
{ |
356 |
|
CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail, oldtekst; |
357 |
|
char CharData[150]; |
358 |
|
strcpy(CharData,data); |
359 |
|
|
360 |
|
int s=22; |
361 |
|
for (int i=0; i<=7; i++) |
362 |
|
{ |
363 |
|
TlfNr.AppendChar(CharData[s]); |
364 |
|
s++; |
365 |
|
} |
366 |
|
|
367 |
|
for (int s=55; s<=(data.GetLength()-3); s++) |
368 |
|
{ |
369 |
|
FyrData.AppendChar(CharData[s]); |
370 |
|
} |
371 |
|
FyrData.Append(":"); |
372 |
|
|
373 |
|
SmsCount = Splitter(FyrData); |
374 |
|
Temper = Splitter(FyrData); |
375 |
|
Flamme = Splitter(FyrData); |
376 |
|
Flis = Splitter(FyrData); |
377 |
|
FremFejl = Splitter(FyrData); |
378 |
|
PowerFail = Splitter(FyrData); |
379 |
|
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
380 |
|
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
381 |
|
m_Textwindow.GetWindowText(oldtekst); |
382 |
|
oldtekst.Append("\r\n"); |
383 |
|
oldtekst.Append("På næste linie kommer SmsCount. \r\n"); |
384 |
|
oldtekst.Append(SmsCount); |
385 |
|
oldtekst.Append("\r\n"); |
386 |
|
oldtekst.Append("På næste linie kommer Temper. \r\n"); |
387 |
|
oldtekst.Append(Temper); |
388 |
|
oldtekst.Append("\r\n"); |
389 |
|
oldtekst.Append("På næste linie kommer Flamme. \r\n"); |
390 |
|
oldtekst.Append(Flamme); |
391 |
|
oldtekst.Append("\r\n"); |
392 |
|
oldtekst.Append("På næste linie kommer Flis. \r\n"); |
393 |
|
oldtekst.Append(Flis); |
394 |
|
oldtekst.Append("\r\n"); |
395 |
|
oldtekst.Append("På næste linie kommer FremFejl. \r\n"); |
396 |
|
oldtekst.Append(FremFejl); |
397 |
|
oldtekst.Append("\r\n"); |
398 |
|
oldtekst.Append("På næste linie kommer PowerFail. \r\n"); |
399 |
|
oldtekst.Append(PowerFail); |
400 |
|
m_Textwindow.SetWindowText(oldtekst); |
401 |
|
/////////////////////////////////////////////////////////////////////////////////////////////////////// |
402 |
|
///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// |
403 |
|
} |
404 |
|
CString CFlisServerDlg::Splitter(CString& fyrdata) |
405 |
|
{ |
406 |
|
CString Output; |
407 |
|
|
408 |
|
int pos = fyrdata.Find(':',0); |
409 |
|
if (pos != -1) |
410 |
|
{ |
411 |
|
Output = fyrdata.Left(pos); |
412 |
|
fyrdata = fyrdata.Right( fyrdata.GetLength() - pos -1); |
413 |
|
} |
414 |
|
return Output; |
415 |
} |
} |