/[H9]/trunk/FlisServer/FlisServerDlg.cpp
ViewVC logotype

Annotation of /trunk/FlisServer/FlisServerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 70 - (hide annotations) (download)
Tue Nov 27 15:26:42 2007 UTC (16 years, 5 months ago) by kevin
File size: 6716 byte(s)
added FlisServer to the project - containing the server software
1 kevin 70 // FlisServerDlg.cpp : implementation file
2     //
3    
4     #include "stdafx.h"
5     #include "FlisServer.h"
6     #include "FlisServerDlg.h"
7     #include ".\flisserverdlg.h"
8     #include <vector>
9    
10     #ifdef _DEBUG
11     #define new DEBUG_NEW
12     #endif
13    
14    
15     // CAboutDlg dialog used for App About
16    
17     class CAboutDlg : public CDialog
18     {
19     public:
20     CAboutDlg();
21    
22     // Dialog Data
23     enum { IDD = IDD_ABOUTBOX };
24    
25     protected:
26     virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
27    
28     // Implementation
29     protected:
30     DECLARE_MESSAGE_MAP()
31     };
32    
33     CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
34     {
35     }
36    
37     void CAboutDlg::DoDataExchange(CDataExchange* pDX)
38     {
39     CDialog::DoDataExchange(pDX);
40     }
41    
42     BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
43     END_MESSAGE_MAP()
44    
45    
46     // CFlisServerDlg dialog
47    
48    
49    
50     CFlisServerDlg::CFlisServerDlg(CWnd* pParent /*=NULL*/)
51     : CDialog(CFlisServerDlg::IDD, pParent)
52     {
53     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
54     }
55    
56     void CFlisServerDlg::DoDataExchange(CDataExchange* pDX)
57     {
58     CDialog::DoDataExchange(pDX);
59     DDX_Control(pDX, IDC_Textwindow, m_Textwindow);
60     }
61    
62     BEGIN_MESSAGE_MAP(CFlisServerDlg, CDialog)
63     ON_WM_SYSCOMMAND()
64     ON_WM_PAINT()
65     ON_WM_QUERYDRAGICON()
66     //}}AFX_MSG_MAP
67     ON_BN_CLICKED(IDOK, OnBnClickedOk)
68     ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
69     ON_BN_CLICKED(IDC_test, OnBnClickedtest)
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     SetPin();
105    
106     return TRUE; // return TRUE unless you set the focus to a control
107     }
108    
109     void CFlisServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
110     {
111     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
112     {
113     CAboutDlg dlgAbout;
114     dlgAbout.DoModal();
115     }
116     else
117     {
118     CDialog::OnSysCommand(nID, lParam);
119     }
120     }
121    
122     // If you add a minimize button to your dialog, you will need the code below
123     // to draw the icon. For MFC applications using the document/view model,
124     // this is automatically done for you by the framework.
125    
126     void CFlisServerDlg::OnPaint()
127     {
128     if (IsIconic())
129     {
130     CPaintDC dc(this); // device context for painting
131    
132     SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
133    
134     // Center icon in client rectangle
135     int cxIcon = GetSystemMetrics(SM_CXICON);
136     int cyIcon = GetSystemMetrics(SM_CYICON);
137     CRect rect;
138     GetClientRect(&rect);
139     int x = (rect.Width() - cxIcon + 1) / 2;
140     int y = (rect.Height() - cyIcon + 1) / 2;
141    
142     // Draw the icon
143     dc.DrawIcon(x, y, m_hIcon);
144     }
145     else
146     {
147     CDialog::OnPaint();
148     }
149     }
150    
151     // The system calls this function to obtain the cursor to display while the user drags
152     // the minimized window.
153     HCURSOR CFlisServerDlg::OnQueryDragIcon()
154     {
155     return static_cast<HCURSOR>(m_hIcon);
156     }
157     int CFlisServerDlg::StartSerial(void)
158     {
159     int Baud;
160     CString SerialPort = "COM3";
161    
162     Baud = 1200;
163     if( Serial.isOpen() ){
164     Serial.close();
165     Serial.open( SerialPort, Baud );
166     }
167     else {
168     Serial.open( SerialPort, Baud );
169     }
170    
171    
172     return 0;
173     }
174     std::vector<unsigned char> CFlisServerDlg::readFrame()
175     {
176     std::vector<unsigned char> buf;
177     while(Serial.getComstat().cbInQue > 0)
178     {
179     unsigned char data = Serial.readByte();
180    
181     buf.push_back(data);
182     }
183     return buf;
184     }
185     void CFlisServerDlg::OnBnClickedOk()
186     {
187     // TODO: Add your control notification handler code here
188     OnOK();
189     if( Serial.isOpen() ){
190     Serial.close();
191     }
192     }
193    
194     void CFlisServerDlg::OnBnClickedCancel()
195     {
196     // TODO: Add your control notification handler code here
197     OnCancel();
198     if( Serial.isOpen() ){
199     Serial.close();
200     }
201     }
202    
203     void CFlisServerDlg::OnBnClickedtest()
204     {
205     // TODO: Add your control notification handler code here
206     /*
207     std::vector<unsigned char> data;
208     data.push_back('a');
209     data.push_back('t');
210    
211     writeFrame(data);
212    
213     if(Serial.getComstat().cbInQue > 0)
214     {
215     std::vector<unsigned char> answer = readFrame();
216     Sleep(50);
217     if (answer.size() == 0){
218     m_Textwindow.SetWindowText("ØV");
219     }
220     else{
221     CString ko;
222     char test[150];
223     int i;
224     for (int i=0; i<answer.size(); i++)
225     {
226     test[i] = answer[i];
227     }
228     ko = test;
229     m_Textwindow.SetWindowText(ko);
230     }
231     }
232     */
233     SetPin();
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     int CFlisServerDlg::SetPin(void)
247     {
248     CString tekst, oldtekst;
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    
284     m_Textwindow.GetWindowText(oldtekst);
285     oldtekst.Append("\r\n");
286     oldtekst.Append(tekst);
287     m_Textwindow.SetWindowText(oldtekst);
288     }
289     return 0;
290     }
291     void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data)
292     {
293     for (int i=0; i<data.size(); i++)
294     {
295     Serial.writeByte( data[i] );
296     Sleep(5);
297     }
298     Serial.writeByte(0x1A);
299     Sleep(100);
300    
301     }
302     void CFlisServerDlg::SendSmsHead(std::vector<unsigned char> data)
303     {
304     for (int i=0; i<data.size(); i++)
305     {
306     Serial.writeByte( data[i] );
307     Sleep(5);
308     }
309     Serial.writeByte(0x0D);
310     Sleep(100);
311    
312     }
313     void CFlisServerDlg::DBconnect()
314     {
315     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);
317     db.OpenEx(dsn, CDatabase::noOdbcDialog);
318     }

  ViewVC Help
Powered by ViewVC 1.1.20