forked from cautonwong/GuruxDLMSLibServerExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGXDLMSBase.h
More file actions
153 lines (134 loc) · 4.54 KB
/
GXDLMSBase.h
File metadata and controls
153 lines (134 loc) · 4.54 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
//
// --------------------------------------------------------------------------
// Gurux Ltd
//
//
//
// Filename: $HeadURL$
//
// Version: $Revision$,
// $Date$
// $Author$
//
// Copyright (c) Gurux Ltd
//
//---------------------------------------------------------------------------
//
// DESCRIPTION
//
// This file is a part of Gurux Device Framework.
//
// Gurux Device Framework is Open Source software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2 of the License.
// Gurux Device Framework is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// More information of Gurux products: http://www.gurux.org
//
// This code is licensed under the GNU General Public License v2.
// Full text may be retrieved at http://www.gnu.org/licenses/gpl-2.0.txt
//---------------------------------------------------------------------------
#pragma once
#include "GXNet.h"
#include "GuruxCommon/GXMediaListener.h"
#include "GuruxDLMS/GXDLMSServerBase.h"
class CGXDLMSBase : public CGXDLMSServerBase,
IGXMediaListener, IGXNetListener
{
CGXNet m_Media;
std::string serialNo;
public:
/////////////////////////////////////////////////////////////////////////
//Constructor.
/////////////////////////////////////////////////////////////////////////
CGXDLMSBase(bool UseLogicalNameReferencing = true,
GXDLMS_INTERFACETYPE IntefaceType = GXDLMS_INTERFACETYPE_GENERAL,
unsigned short MaxReceivePDUSize = 0xFFFF) :
CGXDLMSServerBase(UseLogicalNameReferencing,
IntefaceType, 0xFFFF)
{
}
/////////////////////////////////////////////////////////////////////////
//Destructor.
/////////////////////////////////////////////////////////////////////////
~CGXDLMSBase(void)
{
m_Media.Close();
}
int Init(int port);
int OnRead(CGXDLMSObject* pItem, int index, CGXDLMSVariant& value, DLMS_DATA_TYPE& type);
int OnWrite(CGXDLMSObject* pItem, int index, int selector, CGXDLMSVariant& value);
int OnAction(CGXDLMSObject* pItem, int index, CGXDLMSVariant& data);
int OnInvalidConnection();
void OnClientConnected(IGXMedia* pSender, CConnectionEventArgs& e)
{
printf("Client Connected : %s\r\n", e.GetInfo().c_str());
}
/**
Called when the client has been disconnected from the GXNet server.
@param sender The source of the event.
@param e Event arguments.
*/
void OnClientDisconnected(IGXMedia* pSender, CConnectionEventArgs& e)
{
printf("Client Disonnected : %s\r\n", e.GetInfo().c_str());
}
void OnError(IGXMedia* pSender, basic_string<char>& ex)
{
printf("Error has occurred : %s\r\n", ex.c_str());
}
/**
Media component sends received data through this method.
@param sender The source of the event.
@param e Event arguments.
*/
void OnReceived(IGXMedia* pSender, CReceiveEventArgs& e)
{
unsigned char* pReply = NULL;
int size = 0;
printf("<- %s\r\n", GXHelpers::bytesToHex(&e.getData()[0], e.getData().size()).c_str());
HandleRequest(e.getData(), pReply, size);
//Reply is null if we do not want to send any data to the client.
//This is done if client try to make connection with wrong server or client address.
if (size != 0)
{
printf("-> %s\r\n", GXHelpers::bytesToHex(pReply, size).c_str());
m_Media.Send(pReply, size, e.getSenderInfo());
}
}
/**
Media component sends notification, when its state changes.
@param sender The source of the event.
@param e Event arguments.
*/
void OnMediaStateChange(IGXMedia* pSender, CMediaStateEventArgs& e)
{
}
/**
Called when the Media is sending or receiving data.
@param sender
@param e
@see IGXMedia.Trace Traceseealso>
*/
void OnTrace(IGXMedia* pSender, CTraceEventArgs& e)
{
printf("%s\r\n", e.ToString().c_str());
}
// Summary:
// Represents the method that will handle the System.ComponentModel.INotifyPropertyChanged.PropertyChanged
// event raised when a property is changed on a component.
//
// Parameters:
// sender:
// The source of the event.
//
// e:
// A System.ComponentModel.PropertyChangedEventArgs that contains the event
// data.
void OnPropertyChanged(IGXMedia* pSender, CPropertyChangedEventArgs& e)
{
}
};