// DemoView.h : interface of the CDemoView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_DEMOVIEW_H__DB07D0D1_9753_42CE_A372_037C60B85DCB__INCLUDED_)
#define AFX_DEMOVIEW_H__DB07D0D1_9753_42CE_A372_037C60B85DCB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "msg.h"

class CSerialPort;

#define WM_MSG			WM_USER + 100

#define IP				_T("127.0.0.1")
#define PORT			_T("1100")
#define ID				_T("")

struct DEVICE
{
	char id[100];
	int address;
};

UINT DemoThread(LPVOID pParam);

void _stdcall func(LPCTSTR str);

class CDemoView : public CEditView
{
protected: // create from serialization only
	CDemoView();
	DECLARE_DYNCREATE(CDemoView)

// Attributes
public:
	CDemoDoc* GetDocument();

// Operations
public:

	BOOL m_bRestore;

	CString m_Port, m_Ip, m_Id;
	CString m_ComPort;

	CSerialPort *m_pComPort;

	CArray<DEVICE,DEVICE> m_Device;

	void ClearText();
	void DisplayText(LPCTSTR str);

	void DisplayMsg(Msg msg);

	void Init();

	BOOL Connect();
	void Disconnect();

	void Lost(LPCTSTR id);
	void Restore(LPCTSTR id);

	int GetDeviceAddress(LPCTSTR id);
	void AddDevice(DEVICE device);
	void DelDevice(DEVICE device);
	void DeviceOn(DEVICE device);
	void DeviceOff(DEVICE device);

	void Test();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDemoView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	virtual void OnInitialUpdate();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CDemoView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CDemoView)
	afx_msg void OnDestroy();
	afx_msg void OnClear();
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in DemoView.cpp
inline CDemoDoc* CDemoView::GetDocument()
   { return (CDemoDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DEMOVIEW_H__DB07D0D1_9753_42CE_A372_037C60B85DCB__INCLUDED_)
