[go: up one dir, main page]

Menu

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

Download this file

182 lines (140 with data), 3.7 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
// SendWhoIs.cpp : implementation file
//
#include "stdafx.h"
#include "VTS.h"
#include "Send.h"
#include "SendWhoIs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BACnetAPDUEncoder CSendWhoIs::pageContents;
/////////////////////////////////////////////////////////////////////////////
// CSendWhoIs dialog
IMPLEMENT_DYNCREATE( CSendWhoIs, CPropertyPage )
#pragma warning( disable : 4355 )
CSendWhoIs::CSendWhoIs( void )
: CSendPage( CSendWhoIs::IDD )
, m_LowLimit( this, IDC_LOWLIMIT )
, m_HighLimit( this, IDC_HIGHLIMIT )
{
//{{AFX_DATA_INIT(CSendWhoIs)
//}}AFX_DATA_INIT
}
#pragma warning( default : 4355 )
void CSendWhoIs::DoDataExchange(CDataExchange* pDX)
{
TRACE1( "CSendWhoIs::DoDataExchange(%d)\n", pDX->m_bSaveAndValidate );
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendWhoIs)
//}}AFX_DATA_MAP
m_LowLimit.UpdateData( pDX->m_bSaveAndValidate );
m_HighLimit.UpdateData( pDX->m_bSaveAndValidate );
}
BEGIN_MESSAGE_MAP(CSendWhoIs, CPropertyPage)
//{{AFX_MSG_MAP(CSendWhoIs)
ON_EN_CHANGE(IDC_LOWLIMIT, OnChangeLowLimit)
ON_EN_CHANGE(IDC_HIGHLIMIT, OnChangeHighLimit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//
// CSendWhoIs::OnInitDialog
//
BOOL CSendWhoIs::OnInitDialog()
{
TRACE0( "CSendWhoIs::OnInitDialog()\n" );
CPropertyPage::OnInitDialog();
return TRUE;
}
//
// CSendWhoIs::InitPage
//
void CSendWhoIs::InitPage( void )
{
TRACE0( "CSendWhoIs::InitPage()\n" );
// flush the data
m_LowLimit.ctrlNull = true;
m_HighLimit.ctrlNull = true;
// tell the NPCI this is a global broadcast
pageParent->NPCIPage.m_DestPresent = true;
pageParent->NPCIPage.m_DNET.ctrlNull = false;
pageParent->NPCIPage.m_DNET.intValue = 65535;
pageParent->NPCIPage.m_HopCount.ctrlNull = false;
pageParent->NPCIPage.m_HopCount.intValue = 255;
}
//
// CSendWhoIs::EncodePage
//
void CSendWhoIs::EncodePage( CByteArray* contents )
{
CByteArray header
;
BACnetAPDUEncoder enc
;
TRACE0( "CSendWhoIs::EncodePage()\n" );
// encode the pdu type and service choice
header.Add( 0x10 );
header.Add( 0x08 );
// encode the device ID
if (!m_LowLimit.ctrlNull || !m_HighLimit.ctrlNull) {
if (m_LowLimit.ctrlNull)
throw "Low limit required";
if ((m_LowLimit.uintValue < 0) || (m_LowLimit.uintValue > 4194303))
throw "Low limit out of range 0..4194303";
if (m_HighLimit.ctrlNull)
throw "High limit required";
if ((m_HighLimit.uintValue < 0) || (m_HighLimit.uintValue > 4194303))
throw "High limit out of range 0..4194303";
m_LowLimit.Encode( enc, 0 );
m_HighLimit.Encode( enc, 1 );
}
// 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 );
}
//
// CSendWhoIs::SavePage
//
void CSendWhoIs::SavePage( void )
{
TRACE0( "CSendWhoIs::SavePage\n" );
pageContents.Flush();
m_LowLimit.SaveCtrl( pageContents );
m_HighLimit.SaveCtrl( pageContents );
}
//
// CSendWhoIs::RestorePage
//
void CSendWhoIs::RestorePage( int index )
{
BACnetAPDUDecoder dec( pageContents )
;
TRACE0( "CSendWhoIs::RestorePage\n" );
if (dec.pktLength == 0)
return;
m_LowLimit.RestoreCtrl( dec );
m_HighLimit.RestoreCtrl( dec );
}
//
// CSendWhoIs::OnChangeX
//
// The following set of functions are called when one of the interface elements
// has changed.
//
void CSendWhoIs::OnChangeLowLimit()
{
TRACE0( "CSendWhoIs::OnChangeLowLimit()\n" );
m_LowLimit.UpdateData();
SavePage();
UpdateEncoded();
}
void CSendWhoIs::OnChangeHighLimit()
{
TRACE0( "CSendWhoIs::OnChangeHighLimit()\n" );
m_HighLimit.UpdateData();
SavePage();
UpdateEncoded();
}