[go: up one dir, main page]

Menu

[r921]: / trunk / VTS3 / SendVTClose.cpp  Maximize  Restore  History

Download this file

184 lines (139 with data), 3.5 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
// SendVTClose.cpp : implementation file
//
#include "stdafx.h"
#include "VTS.h"
#include "SendVTClose.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BACnetAPDUEncoder CSendVTClose::pageContents;
/////////////////////////////////////////////////////////////////////////////
// CSendVTClose dialog
IMPLEMENT_DYNCREATE( CSendVTClose, CPropertyPage )
CSendVTClose::CSendVTClose( void )
: CSendPage( CSendVTClose::IDD )
{
//{{AFX_DATA_INIT(CSendVTClose)
//}}AFX_DATA_INIT
}
void CSendVTClose::DoDataExchange(CDataExchange* pDX)
{
TRACE1( "CSendVTClose::DoDataExchange(%d)\n", pDX->m_bSaveAndValidate );
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendVTClose)
DDX_Control(pDX, IDC_IDLIST, m_IDList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSendVTClose, CPropertyPage)
//{{AFX_MSG_MAP(CSendVTClose)
ON_BN_CLICKED(IDC_ADDID, OnAddID)
ON_BN_CLICKED(IDC_REMOVEID, OnRemoveID)
ON_EN_CHANGE(IDC_ID, OnChangeID)
ON_NOTIFY(LVN_ITEMCHANGING, IDC_IDLIST, OnItemchangingIDList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//
// CSendVTClose::OnInitDialog
//
BOOL CSendVTClose::OnInitDialog()
{
static VTSListColDesc colDesc[] =
{ { "ID", LVCFMT_RIGHT, 96, IDC_ID }
, { 0, 0, 0, 0 }
};
TRACE0( "CSendVTClose::OnInitDialog()\n" );
CDialog::OnInitDialog();
// only allow one selection at a time, no sorting
m_IDList.m_nFlags |= LVS_SINGLESEL;
m_IDList.m_nFlags &= ~LBS_SORT;
// initialize the list
m_IDCtrl.Init( this, &m_IDList, colDesc );
return TRUE;
}
//
// CSendVTClose::InitPage
//
void CSendVTClose::InitPage( void )
{
TRACE0( "CSendVTClose::InitPage()\n" );
// flush the data
}
//
// CSendVTClose::EncodePage
//
void CSendVTClose::EncodePage( CByteArray* contents )
{
CByteArray header
;
BACnetAPDUEncoder enc
;
TRACE0( "CSendVTClose::EncodePage()\n" );
// encode the pdu type
header.Add( 22 );
// validate and encode the session ID's
int len = m_IDCtrl.GetItemCount();
for (int i = 0; i < len; i++) {
const char *txt = m_IDCtrl.GetItemText( i, 0 );
// make sure something was provided
if (!txt || !*txt)
throw "Invalid session ID";
// convert to an integer and check the range
int id = atoi( txt );
if ((id < 0) || (id > 255))
throw "Session ID out of range 0..255";
// encode it
BACnetUnsigned( id ).Encode( enc );
}
// copy the encoding into the byte array
for (int j = 0; j < enc.pktLength; j++)
header.Add( enc.pktBuffer[j] );
// stuff the header on the front
contents->InsertAt( 0, &header );
}
//
// CSendVTClose::SavePage
//
void CSendVTClose::SavePage( void )
{
TRACE0( "CSendVTClose::SavePage\n" );
pageContents.Flush();
// m_IDCtrl.SaveList( pageContents );
}
//
// CSendVTClose::RestorePage
//
void CSendVTClose::RestorePage( int index )
{
BACnetAPDUDecoder dec( pageContents )
;
TRACE0( "CSendVTClose::RestorePage\n" );
if (dec.pktLength == 0)
return;
// m_IDCtrl.RestoreList( dec );
}
//
// CSendVTClose::OnChangeX
//
// The following set of functions are called when one of the interface elements
// has changed.
//
void CSendVTClose::OnAddID()
{
m_IDCtrl.AddButtonClick();
// madanner 9/3/02, added default ID of 1
m_IDCtrl.SetCtrlText(IDC_ID, "1");
}
void CSendVTClose::OnRemoveID()
{
m_IDCtrl.RemoveButtonClick();
}
void CSendVTClose::OnChangeID()
{
m_IDCtrl.OnChangeItem( IDC_ID );
}
void CSendVTClose::OnItemchangingIDList(NMHDR* pNMHDR, LRESULT* pResult)
{
m_IDCtrl.OnItemChanging( pNMHDR, pResult );
}