[go: up one dir, main page]

Menu

[r53]: / trunk / VTS3 / SendICouldBeRTN.cpp  Maximize  Restore  History

Download this file

156 lines (120 with data), 3.2 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
// SendICouldBeRTN.cpp : implementation file
//
#include "stdafx.h"
#include "VTS.h"
#include "Send.h"
#include "SendICouldBeRTN.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BACnetAPDUEncoder CSendICouldBeRTN::pageContents;
/////////////////////////////////////////////////////////////////////////////
// CSendICouldBeRTN dialog
IMPLEMENT_DYNCREATE( CSendICouldBeRTN, CPropertyPage )
CSendICouldBeRTN::CSendICouldBeRTN( void )
: CSendPage( CSendICouldBeRTN::IDD )
, m_DNET( this, IDC_DNET )
, m_PerfIndx( this, IDC_PERFINDX )
{
//{{AFX_DATA_INIT(CSendICouldBeRTN)
//}}AFX_DATA_INIT
}
void CSendICouldBeRTN::DoDataExchange(CDataExchange* pDX)
{
TRACE1( "CSendICouldBeRTN::DoDataExchange(%d)\n", pDX->m_bSaveAndValidate );
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendICouldBeRTN)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
m_DNET.UpdateData( pDX->m_bSaveAndValidate );
m_PerfIndx.UpdateData( pDX->m_bSaveAndValidate );
}
BEGIN_MESSAGE_MAP(CSendICouldBeRTN, CPropertyPage)
//{{AFX_MSG_MAP(CSendICouldBeRTN)
ON_EN_CHANGE(IDC_DNET, OnChangeDNET)
ON_EN_CHANGE(IDC_PERFINDX, OnChangePerfIndx)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//
// CSendICouldBeRTN::InitPage
//
void CSendICouldBeRTN::InitPage( void )
{
TRACE0( "CSendICouldBeRTN::InitPage()\n" );
// flush the data
m_DNET.ctrlNull = true;
m_PerfIndx.ctrlNull = true;
// tell the NPCI this is a network layer message
pageParent->NPCIPage.m_isNetMessage = true;
}
//
// CSendICouldBeRTN::EncodePage
//
void CSendICouldBeRTN::EncodePage( CByteArray* contents )
{
CByteArray header
;
TRACE0( "CSendICouldBeRTN::EncodePage()\n" );
// encode the message type
header.Add( 0x02 );
// encode the DNET
if (m_DNET.ctrlNull)
throw "Destination network required";
if ((m_DNET.intValue < 0) || (m_DNET.intValue > 65534))
throw "Destination network out of range 0..65534";
header.Add( m_DNET.intValue >> 8 );
header.Add( m_DNET.intValue & 0xFF );
// encode the performance index
if (m_PerfIndx.ctrlNull)
throw "Performance index required";
if ((m_PerfIndx.intValue < 0) || (m_PerfIndx.intValue > 255))
throw "Performance index out of range 0..255";
header.Add( m_PerfIndx.intValue );
// stuff the header on the front
contents->InsertAt( 0, &header );
}
//
// CSendICouldBeRTN::SavePage
//
void CSendICouldBeRTN::SavePage( void )
{
TRACE0( "CSendICouldBeRTN::SavePage\n" );
pageContents.Flush();
m_DNET.SaveCtrl( pageContents );
m_PerfIndx.SaveCtrl( pageContents );
}
//
// CSendICouldBeRTN::RestorePage
//
void CSendICouldBeRTN::RestorePage( void )
{
BACnetAPDUDecoder dec( pageContents )
;
TRACE0( "CSendICouldBeRTN::RestorePage\n" );
if (dec.pktLength == 0)
return;
m_DNET.RestoreCtrl( dec );
m_PerfIndx.RestoreCtrl( dec );
}
//
// CSendICouldBeRTN::OnChangeDNET
//
void CSendICouldBeRTN::OnChangeDNET()
{
TRACE0( "CSendICouldBeRTN::OnChangeDNET()\n" );
m_DNET.UpdateData();
SavePage();
UpdateEncoded();
}
//
// CSendICouldBeRTN::OnChangePerfIndx
//
void CSendICouldBeRTN::OnChangePerfIndx()
{
TRACE0( "CSendICouldBeRTN::OnChangePerfIndx()\n" );
m_PerfIndx.UpdateData();
SavePage();
UpdateEncoded();
}