[go: up one dir, main page]

Menu

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

Download this file

259 lines (204 with data), 5.6 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// SendDevice.cpp : implementation file
//
#include "stdafx.h"
#include "VTS.h"
#include "Send.h"
#include "SendDevice.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BACnetAPDUEncoder CSendDevice::pageContents;
/////////////////////////////////////////////////////////////////////////////
// CSendDevice dialog
IMPLEMENT_DYNCREATE( CSendDevice, CPropertyPage )
#pragma warning( disable : 4355 )
CSendDevice::CSendDevice( void )
: CSendPage( CSendDevice::IDD )
, m_DADR( this, IDC_DADRCOMBO, IDC_DADR )
, m_Network( this, IDC_NETWORK )
, m_Address( this, IDC_ADDRESS )
{
//{{AFX_DATA_INIT(CSendDevice)
#if DEVICE_LOOPBACK
m_AddrType = 0;
#else
m_AddrType = 1;
#endif
//}}AFX_DATA_INIT
}
#pragma warning( default : 4355 )
void CSendDevice::DoDataExchange(CDataExchange* pDX)
{
TRACE1( "CSendDevice::DoDataExchange(%d)\n", pDX->m_bSaveAndValidate );
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendDevice)
DDX_Radio(pDX, IDC_NULLADDR, m_AddrType);
//}}AFX_DATA_MAP
// m_DADR.UpdateData( pDX->m_bSaveAndValidate );
m_Network.UpdateData( pDX->m_bSaveAndValidate );
m_Address.UpdateData( pDX->m_bSaveAndValidate );
}
BEGIN_MESSAGE_MAP(CSendDevice, CPropertyPage)
//{{AFX_MSG_MAP(CSendDevice)
ON_CBN_SELCHANGE(IDC_DADRCOMBO, OnSelchangeDADRCombo)
ON_BN_CLICKED(IDC_NULLADDR, OnAddrTypeChange)
ON_BN_CLICKED(IDC_LOCALBROADCAST, OnAddrTypeChange)
ON_BN_CLICKED(IDC_LOCALSTATION, OnAddrTypeChange)
ON_BN_CLICKED(IDC_REMOTEBROADCAST, OnAddrTypeChange)
ON_BN_CLICKED(IDC_REMOTESTATION, OnAddrTypeChange)
ON_BN_CLICKED(IDC_GLOBALBROADCAST, OnAddrTypeChange)
ON_EN_CHANGE(IDC_NETWORK, OnChangeNetwork)
ON_EN_CHANGE(IDC_ADDRESS, OnChangeAddress)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//
// CSendDevice::OnInitDialog
//
BOOL CSendDevice::OnInitDialog()
{
TRACE0( "CSendDevice::OnInitDialog\n" );
CPropertyPage::OnInitDialog();
// load the address combo
// m_DADR.LoadCombo( &pageParent->m_pPort->portDoc->m_Names, pageParent->m_pPort->portDescID );
// m_DADR.FindName( "IUT" );
return TRUE;
}
//
// CSendDevice::InitPage
//
void CSendDevice::InitPage( void )
{
TRACE0( "CSendDevice::InitPage()\n" );
#if DEVICE_LOOPBACK
GetDlgItem( IDC_NULLADDR )->EnableWindow( true );
#endif
}
//
// CSendDevice::EncodePage
//
void CSendDevice::EncodePage( CByteArray* contents )
{
CByteArray header
;
TRACE0( "CSendDevice::EncodePage()\n" );
switch (m_AddrType) {
case -1: // no selection
throw "Select an address type";
break;
case 0: // null address
#if !DEVICE_LOOPBACK
throw "Invalid null address";
#endif
break;
case 1: // local broadcast
case 5: // global broadcast
break;
case 2: // local station
if (m_Address.ctrlNull)
throw "Address required";
break;
case 3: // remote broadcast
if (m_Network.ctrlNull)
throw "Network required";
if (m_Network.uintValue > 65534)
throw "Network out of range 0..65534";
break;
case 4: // remote station
if (m_Network.ctrlNull)
throw "Network required";
if (m_Network.uintValue > 65534)
throw "Network out of range 0..65534";
if (m_Address.ctrlNull)
throw "Address required";
break;
}
// save the type
header.Add( m_AddrType );
// save the network number
header.Add( (unsigned char)(m_Network.uintValue >> 8) );
header.Add( (unsigned char)(m_Network.uintValue & 0xFF) );
// save the address
header.Add( m_Address.strLen );
for (int i = 0; i < m_Address.strLen; i++)
header.Add( m_Address.strBuff[i] );
// stuff header on the front
contents->InsertAt( 0, &header );
}
//
// CSendDevice::SavePage
//
void CSendDevice::SavePage( void )
{
TRACE0( "CSendDevice::SavePage\n" );
pageContents.Flush();
// m_DADR.SaveCtrl( pageContents );
m_Network.SaveCtrl( pageContents );
m_Address.SaveCtrl( pageContents );
}
//
// CSendDevice::RestorePage
//
void CSendDevice::RestorePage( int index )
{
BACnetAPDUDecoder dec( pageContents )
;
TRACE0( "CSendDevice::RestorePage\n" );
if (dec.pktLength == 0)
return;
// m_DADR.RestoreCtrl( dec );
m_Network.RestoreCtrl( dec );
m_Address.RestoreCtrl( dec );
}
/////////////////////////////////////////////////////////////////////////////
// CSendDevice message handlers
void CSendDevice::OnSelchangeDADRCombo()
{
TRACE0( "CSendDevice::OnSelchangeDADRCombo()\n" );
SavePage();
UpdateEncoded();
}
void CSendDevice::OnAddrTypeChange()
{
TRACE0( "CSendDevice::OnAddrTypeChange()\n" );
// sync the member variables with the dialog controls
UpdateData( true );
switch (m_AddrType) {
case -1: // no selection
case 0: // null address
case 1: // local broadcast
case 5: // global broadcast
GetDlgItem( IDC_NETWORK )->EnableWindow( false );
GetDlgItem( IDC_ADDRESS )->EnableWindow( false );
break;
case 2: // local station
GetDlgItem( IDC_NETWORK )->EnableWindow( false );
GetDlgItem( IDC_ADDRESS )->EnableWindow( true );
break;
case 3: // remote broadcast
GetDlgItem( IDC_NETWORK )->EnableWindow( true );
GetDlgItem( IDC_ADDRESS )->EnableWindow( false );
break;
case 4: // remote station
GetDlgItem( IDC_NETWORK )->EnableWindow( true );
GetDlgItem( IDC_ADDRESS )->EnableWindow( true );
break;
}
SavePage();
UpdateEncoded();
}
void CSendDevice::OnChangeNetwork()
{
TRACE0( "CSendDevice::OnChangeNetwork()\n" );
m_Network.UpdateData();
SavePage();
UpdateEncoded();
}
void CSendDevice::OnChangeAddress()
{
TRACE0( "CSendDevice::OnChangeAddress()\n" );
m_Address.UpdateData();
SavePage();
UpdateEncoded();
}