[go: up one dir, main page]

Menu

[r999]: / trunk / VTS3 / SendWriteBDT.cpp  Maximize  Restore  History

Download this file

226 lines (177 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// SendWriteBDT.cpp : implementation file
//
#include "stdafx.h"
#include "VTS.h"
#include "SendWriteBDT.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BACnetAPDUEncoder CSendWriteBDT::pageContents;
/////////////////////////////////////////////////////////////////////////////
// CSendWriteBDT property page
IMPLEMENT_DYNCREATE(CSendWriteBDT, CPropertyPage)
CSendWriteBDT::CSendWriteBDT( void )
: CSendPage( CSendWriteBDT::IDD )
{
//{{AFX_DATA_INIT(CSendWriteBDT)
// NOTE: the ClassWizard will add member initialization here
m_portInt = 0;
m_maskInt = 0;
//}}AFX_DATA_INIT
}
void CSendWriteBDT::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendWriteBDT)
DDX_Control(pDX, IDC_MASK, m_mask);
DDX_Control(pDX, IDC_BDTPORT, m_port);
DDX_Control(pDX, IDC_IP, m_IP);
DDX_Control(pDX, IDC_BDTLIST, m_BDTList);
DDX_Text(pDX, IDC_BDTPORT, m_portInt);
DDX_Text(pDX, IDC_MASK, m_maskInt);
//}}AFX_DATA_MAP
if(m_port.IsWindowEnabled())
DDV_MinMaxInt(pDX, m_portInt, 0, 0xFFFF);
if(m_mask.IsWindowEnabled())
DDV_MinMaxInt(pDX, m_maskInt, 1, 32);
}
BEGIN_MESSAGE_MAP(CSendWriteBDT, CPropertyPage)
//{{AFX_MSG_MAP(CSendWriteBDT)
ON_BN_CLICKED(IDC_ADDBDT, OnAddBDT)
ON_BN_CLICKED(IDC_REMOVEBDT, OnRemoveBDT)
ON_EN_CHANGE(IDC_IP, OnChangeIP)
ON_NOTIFY(LVN_ITEMCHANGING, IDC_BDTLIST, OnItemchangingBDTList)
ON_EN_CHANGE(IDC_MASK, OnChangeMask)
ON_EN_CHANGE(IDC_BDTPORT, OnChangePort)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//
// CSendWriteBDT::InitPage
//
void CSendWriteBDT::InitPage( void )
{
TRACE0( "CSendWriteBDT::InitPage()\n" );
}
//
// CSendWriteBDT::EncodePage
//
void CSendWriteBDT::EncodePage( CByteArray* contents )
{
int len = m_BDTCtrl.GetItemCount()
, msgLen = len * 10 + 4
;
unsigned long host, mask
;
unsigned short port
;
CByteArray header
;
TRACE0( "CSendWriteBDT::EncodePage()\n" );
// encode the message type and function
header.Add( 0x81 );
header.Add( 0x01 );
// encode the length
header.Add( msgLen >> 8 );
header.Add( msgLen & 0xFF );
// validate and encode the BDT entries
for (int i = 0; i < len; i++) {
//Xiao Shiyuan 2002-6-18
//format:192.168.1.88/24:47808
CString str = m_BDTCtrl.GetItemText( i, 0 );
str = str + "/" + m_BDTCtrl.GetItemText(i, 2);
str = str + ":" + m_BDTCtrl.GetItemText(i, 1);
const char *txt = (LPCTSTR)str;
// make sure something was provided
if (!txt || !*txt)
throw "Invalid BDT entry";
// convert to host, port and network mask
BACnetIPAddr::StringToHostPort( txt, &host, &mask, &port );
// encode the host
for (int i = 3; i >= 0; i--)
header.Add( (unsigned char)((host >> (i * 8)) & 0xFF) );
// encode the port
header.Add( port >> 8 );
header.Add( port & 0xFF );
// encode the mask
for (int j = 3; j >= 0; j--)
header.Add( (unsigned char)((mask >> (j * 8)) & 0xFF) );
}
// stuff the header on the front
contents->InsertAt( 0, &header );
}
//
// CSendWriteBDT::SavePage
//
void CSendWriteBDT::SavePage( void )
{
TRACE0( "CSendWriteBDT::SavePage\n" );
pageContents.Flush();
// m_BDTCtrl.SaveList( pageContents );
}
//
// CSendWriteBDT::RestorePage
//
void CSendWriteBDT::RestorePage( int index )
{
BACnetAPDUDecoder dec( pageContents )
;
TRACE0( "CSendWriteBDT::RestorePage\n" );
if (dec.pktLength == 0)
return;
// m_BDTCtrl.RestoreCtrl( dec );
}
//
// CSendWriteBDT::OnInitDialog
//
BOOL CSendWriteBDT::OnInitDialog()
{
//Xiao Shiyuan 2002-6-18
static VTSListColDesc colDesc[] =
{ { "IP Address", LVCFMT_RIGHT, 128, IDC_IP }
, { "UDP Port", LVCFMT_RIGHT, 84, IDC_BDTPORT }
, { "Mask", LVCFMT_RIGHT, 60, IDC_MASK }
, { 0, 0, 0, 0 }
};
TRACE0( "CSendWriteBDT::OnInitDialog()\n" );
CDialog::OnInitDialog();
// only allow one selection at a time, no sorting
m_BDTList.m_nFlags |= LVS_SINGLESEL;
m_BDTList.m_nFlags &= ~LBS_SORT;
// initialize the list
m_BDTCtrl.Init( this, &m_BDTList, colDesc );
//Xiao Shiyuan 2002-6-18 default UDP port
m_port.SetWindowText("47808");
m_mask.SetWindowText("0");
return TRUE;
}
void CSendWriteBDT::OnAddBDT()
{
m_BDTCtrl.AddButtonClick();
//Xiao Shiyuan 2002-6-18 default UDP port
m_port.SetWindowText("47808");
m_mask.SetWindowText("0");
}
void CSendWriteBDT::OnRemoveBDT()
{
m_BDTCtrl.RemoveButtonClick();
}
void CSendWriteBDT::OnChangeIP()
{
m_BDTCtrl.OnChangeItem( IDC_IP );
}
void CSendWriteBDT::OnItemchangingBDTList(NMHDR* pNMHDR, LRESULT* pResult)
{
m_BDTCtrl.OnItemChanging( pNMHDR, pResult );
}
//Xiao Shiyuan 2002-6-18
void CSendWriteBDT::OnChangeMask()
{
m_BDTCtrl.OnChangeItem( IDC_MASK );
}
//Xiao Shiyuan 2002-6-18
void CSendWriteBDT::OnChangePort()
{
m_BDTCtrl.OnChangeItem( IDC_BDTPORT );
}