[go: up one dir, main page]

Menu

[r527]: / trunk / VTS3 / SendWriteFile.cpp  Maximize  Restore  History

Download this file

318 lines (256 with data), 7.0 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// SendWriteFile.cpp : implementation file
//
#include "stdafx.h"
#include "VTS.h"
#include "Send.h"
#include "SendWriteFile.h"
#include "VTSObjectIdentifierDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BACnetAPDUEncoder CSendWriteFile::pageContents;
/////////////////////////////////////////////////////////////////////////////
// CSendWriteFile dialog
IMPLEMENT_DYNCREATE( CSendWriteFile, CPropertyPage )
#pragma warning( disable : 4355 )
CSendWriteFile::CSendWriteFile( void )
: CSendPage( CSendWriteFile::IDD )
, m_FileID( this, IDC_FILEID )
, m_StartPosition( this, IDC_STARTPOSITION )
, m_Data( this, IDC_DATA )
, m_StartRecord( this, IDC_STARTRECORD )
{
//{{AFX_DATA_INIT(CSendWriteFile)
//}}AFX_DATA_INIT
}
#pragma warning( default : 4355 )
void CSendWriteFile::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendWriteFile)
DDX_Control(pDX, IDC_RECORDLIST, m_RecordList);
//}}AFX_DATA_MAP
m_FileID.UpdateData( pDX->m_bSaveAndValidate );
m_StartPosition.UpdateData( pDX->m_bSaveAndValidate );
m_Data.UpdateData( pDX->m_bSaveAndValidate );
m_StartRecord.UpdateData( pDX->m_bSaveAndValidate );
}
BEGIN_MESSAGE_MAP(CSendWriteFile, CPropertyPage)
//{{AFX_MSG_MAP(CSendWriteFile)
ON_EN_CHANGE(IDC_FILEID, OnChangeFileID)
ON_EN_CHANGE(IDC_STARTPOSITION, OnChangeStartPosition)
ON_EN_CHANGE(IDC_DATA, OnChangeData)
ON_EN_CHANGE(IDC_STARTRECORD, OnChangeStartRecord)
ON_BN_CLICKED(IDC_ADDRECORD, OnAddRecord)
ON_BN_CLICKED(IDC_REMOVERECORD, OnRemoveRecord)
ON_EN_CHANGE(IDC_RECORDDATA, OnChangeRecordData)
ON_NOTIFY(LVN_ITEMCHANGING, IDC_RECORDLIST, OnItemchangingRecordList)
ON_BN_CLICKED(IDC_FILEIDBTN, OnFileIDButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//
// CSendWriteFile::InitPage
//
void CSendWriteFile::InitPage( void )
{
TRACE0( "CSendWriteFile::InitPage()\n" );
}
//
// CSendWriteFile::EncodePage
//
void CSendWriteFile::EncodePage( CByteArray* contents )
{
int len = m_RecordCtrl.GetItemCount()
;
CByteArray header
;
BACnetAPDUEncoder enc
;
// encode the service choice
header.Add( 7 );
// encode the object ID
if (m_FileID.ctrlNull)
throw "File ID required";
m_FileID.Encode( enc );
// check for access type
if (!m_StartPosition.ctrlNull || !m_Data.ctrlNull) {
if (m_StartPosition.ctrlNull)
throw "Start position required";
if (m_Data.ctrlNull)
throw "Octet string required";
if (!m_StartRecord.ctrlNull)
throw "Omit start record for stream access";
if (len != 0)
throw "Omit record data for stream access";
BACnetOpeningTag().Encode( enc, 0 );
m_StartPosition.Encode( enc );
m_Data.Encode( enc );
BACnetClosingTag().Encode( enc, 0 );
} else
if (!m_StartRecord.ctrlNull || (len != 0)) {
if (m_StartRecord.ctrlNull)
throw "Start record required";
if (!m_StartPosition.ctrlNull)
throw "Omit start position for record access";
if (!m_Data.ctrlNull)
throw "Omit octet string for record access";
BACnetOpeningTag().Encode( enc, 1 );
m_StartRecord.Encode( enc );
// encode the record count
BACnetUnsigned( len ).Encode( enc );
// validate and encode the record data
for (int i = 0; i < len; i++) {
BACnetOctetString ostr
;
const char *txt = m_RecordCtrl.GetItemText( i, 0 )
;
// make sure something was provided
if (!txt || !*txt)
throw "Invalid record data";
// encode it
int upperNibble, lowerNibble
;
char c
;
// translate the text into octets
for (;;) {
// look for a hex digit
while ((c = toupper(*txt++)) && !isxdigit(c))
;
if (!c) break;
upperNibble = (isdigit(c) ? (c - '0') : (c - 'A' + 10));
// look for another hex digit
while ((c = toupper(*txt++)) && !isxdigit(c))
;
if (!c) break;
lowerNibble = (isdigit(c) ? (c - '0') : (c - 'A' + 10));
// add the byte
ostr.Append( (upperNibble << 4) + lowerNibble );
}
// encode the object
ostr.Encode( enc );
}
BACnetClosingTag().Encode( enc, 1 );
} else
throw "Stream or record access required";
// copy the encoding into the byte array
for (int i = 0; i < enc.pktLength; i++)
header.Add( enc.pktBuffer[i] );
// stuff the header on the front
contents->InsertAt( 0, &header );
}
//
// CSendWriteFile::SavePage
//
void CSendWriteFile::SavePage( void )
{
TRACE0( "CSendWriteFile::SavePage\n" );
pageContents.Flush();
m_FileID.SaveCtrl( pageContents );
m_StartPosition.SaveCtrl( pageContents );
m_Data.SaveCtrl( pageContents );
m_StartRecord.SaveCtrl( pageContents );
// m_RecordCtrl.SaveCtrl( pageContents );
}
//
// CSendWriteFile::RestorePage
//
void CSendWriteFile::RestorePage( int index )
{
BACnetAPDUDecoder dec( pageContents )
;
TRACE0( "CSendWriteFile::RestorePage\n" );
if (dec.pktLength == 0)
return;
m_FileID.RestoreCtrl( dec );
m_StartPosition.RestoreCtrl( dec );
m_Data.RestoreCtrl( dec );
m_StartRecord.RestoreCtrl( dec );
// m_RecordCtrl.RestoreCtrl( dec );
}
//
// CSendWriteFile::OnInitDialog
//
BOOL CSendWriteFile::OnInitDialog()
{
static VTSListColDesc colDesc[] =
{ { "Record Data", LVCFMT_RIGHT, 256, IDC_RECORDDATA }
, { 0, 0, 0, 0 }
};
TRACE0( "CSendWriteFile::OnInitDialog()\n" );
CDialog::OnInitDialog();
// init the usual fields
m_FileID.ctrlNull = true;
m_StartPosition.ctrlNull = true;
m_Data.ctrlNull = true;
m_StartRecord.ctrlNull = true;
// only allow one selection at a time, no sorting
m_RecordList.m_nFlags |= LVS_SINGLESEL;
m_RecordList.m_nFlags &= ~LBS_SORT;
// initialize the list
m_RecordCtrl.Init( this, &m_RecordList, colDesc );
return TRUE;
}
//
// CSendWriteFile::OnChangeX
//
// The following set of functions are called when one of the interface elements
// has changed.
//
void CSendWriteFile::OnChangeFileID()
{
m_FileID.UpdateData();
SavePage();
UpdateEncoded();
}
void CSendWriteFile::OnFileIDButton()
{
VTSObjectIdentifierDialog dlg(this) // for proper parent control
;
dlg.objID = m_FileID.objID;
if (dlg.DoModal() && dlg.validObjID) {
m_FileID.ctrlNull = false;
m_FileID.objID = dlg.objID;
m_FileID.ObjToCtrl();
SavePage();
UpdateEncoded();
}
}
void CSendWriteFile::OnChangeStartPosition()
{
m_StartPosition.UpdateData();
SavePage();
UpdateEncoded();
}
void CSendWriteFile::OnChangeData()
{
m_Data.UpdateData();
SavePage();
UpdateEncoded();
}
void CSendWriteFile::OnChangeStartRecord()
{
m_StartRecord.UpdateData();
SavePage();
UpdateEncoded();
}
void CSendWriteFile::OnAddRecord()
{
m_RecordCtrl.AddButtonClick();
// madanner 9/3/02, added default record data
m_RecordCtrl.SetCtrlText(IDC_RECORDDATA, "(record data)");
}
void CSendWriteFile::OnRemoveRecord()
{
m_RecordCtrl.RemoveButtonClick();
}
void CSendWriteFile::OnChangeRecordData()
{
m_RecordCtrl.OnChangeItem( IDC_RECORDDATA );
}
void CSendWriteFile::OnItemchangingRecordList(NMHDR* pNMHDR, LRESULT* pResult)
{
m_RecordCtrl.OnItemChanging( pNMHDR, pResult );
}