@@ -118,33 +118,49 @@ public byte[][] SetFunctionStatus(
118
118
}
119
119
120
120
/// <summary>
121
- /// Adjusts the value of the current credit amount attribute.
121
+ /// Adds a new function to the attribute function list.
122
122
/// </summary>
123
123
/// <param name="client">DLMS client.</param>
124
124
/// <param name="functions">Added functions.</param>
125
125
/// <returns>Action bytes.</returns>
126
126
/// <summary>
127
127
public byte [ ] [ ] AddFunction (
128
128
GXDLMSClient client ,
129
- List < KeyValuePair < string , List < GXDLMSObject > > > functions )
129
+ string name ,
130
+ List < GXDLMSObject > functions )
130
131
{
131
- return client . Method ( this , 2 ,
132
- FunctionListToByteArray ( functions ) , DataType . Array ) ;
132
+ GXByteBuffer bb = new GXByteBuffer ( ) ;
133
+ bb . SetUInt8 ( DataType . Structure ) ;
134
+ bb . SetUInt8 ( 2 ) ;
135
+ bb . SetUInt8 ( DataType . OctetString ) ;
136
+ GXCommon . SetObjectCount ( name . Length , bb ) ;
137
+ bb . Set ( ASCIIEncoding . ASCII . GetBytes ( name ) ) ;
138
+ bb . SetUInt8 ( DataType . Array ) ;
139
+ GXCommon . SetObjectCount ( functions . Count , bb ) ;
140
+ foreach ( var it in functions )
141
+ {
142
+ bb . SetUInt8 ( DataType . Structure ) ;
143
+ bb . SetUInt8 ( 2 ) ;
144
+ GXCommon . SetData ( null , bb , DataType . UInt16 , ( int ) it . ObjectType ) ;
145
+ GXCommon . SetData ( null , bb , DataType . OctetString , GXCommon . LogicalNameToBytes ( it . LogicalName ) ) ;
146
+ }
147
+ return client . Method ( this , 2 , bb . Array ( ) , DataType . Array ) ;
133
148
}
134
149
135
150
/// <summary>
136
- /// Adjusts the value of the current credit amount attribute .
151
+ /// Removes a function from the attribute function list .
137
152
/// </summary>
138
153
/// <param name="client">DLMS client.</param>
139
- /// <param name="functions">Added functions .</param>
154
+ /// <param name="functions">Removed function name .</param>
140
155
/// <returns>Action bytes.</returns>
141
156
/// <summary>
142
- public byte [ ] [ ] RemoveFunction (
143
- GXDLMSClient client ,
144
- List < KeyValuePair < string , List < GXDLMSObject > > > functions )
157
+ public byte [ ] [ ] RemoveFunction ( GXDLMSClient client , string name )
145
158
{
146
- return client . Method ( this , 3 ,
147
- FunctionListToByteArray ( functions ) , DataType . Array ) ;
159
+ GXByteBuffer bb = new GXByteBuffer ( ) ;
160
+ bb . SetUInt8 ( DataType . OctetString ) ;
161
+ GXCommon . SetObjectCount ( name . Length , bb ) ;
162
+ bb . Set ( ASCIIEncoding . ASCII . GetBytes ( name ) ) ;
163
+ return client . Method ( this , 3 , bb . Array ( ) , DataType . Array ) ;
148
164
}
149
165
150
166
/// <summary>
@@ -266,16 +282,26 @@ byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
266
282
}
267
283
else if ( e . Index == 2 )
268
284
{
269
- var functions = FunctionListFromByteArray ( ( List < object > ) e . Parameters ) ;
270
- FunctionList . AddRange ( functions ) ;
285
+ GXStructure it = ( GXStructure ) e . Parameters ;
286
+ string fn = ASCIIEncoding . ASCII . GetString ( ( byte [ ] ) it [ 0 ] ) ;
287
+ List < GXDLMSObject > objects = new List < GXDLMSObject > ( ) ;
288
+ foreach ( GXStructure it2 in ( GXArray ) it [ 1 ] )
289
+ {
290
+ ObjectType ot = ( ObjectType ) Convert . ToInt32 ( it2 [ 0 ] ) ;
291
+ byte [ ] ln = ( byte [ ] ) it2 [ 1 ] ;
292
+ var obj = GXDLMSClient . CreateObject ( ot ) ;
293
+ obj . LogicalName = GXCommon . ToLogicalName ( ln ) ;
294
+ objects . Add ( obj ) ;
295
+ }
296
+ FunctionList . RemoveAll ( w => w . Key == fn ) ;
297
+ FunctionList . Add ( new KeyValuePair < string , List < GXDLMSObject > > ( fn , objects ) ) ;
298
+ ActivationStatus . Add ( new GXKeyValuePair < string , bool > ( fn , true ) ) ;
271
299
}
272
300
else if ( e . Index == 3 )
273
301
{
274
- var functions = FunctionListFromByteArray ( ( List < object > ) e . Parameters ) ;
275
- foreach ( var f in functions )
276
- {
277
- FunctionList . RemoveAll ( w => f . Key == w . Key ) ;
278
- }
302
+ string fn = ASCIIEncoding . ASCII . GetString ( ( byte [ ] ) e . Parameters ) ;
303
+ FunctionList . RemoveAll ( w => w . Key == fn ) ;
304
+ ActivationStatus . RemoveAll ( w => w . Key == fn ) ;
279
305
}
280
306
else
281
307
{
0 commit comments