Skip to content

Commit a18f1a5

Browse files
committed
1 parent fd66dfe commit a18f1a5

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

Development/Objects/GXDLMSFunctionControl.cs

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,49 @@ public byte[][] SetFunctionStatus(
118118
}
119119

120120
/// <summary>
121-
/// Adjusts the value of the current credit amount attribute.
121+
/// Adds a new function to the attribute function list.
122122
/// </summary>
123123
/// <param name="client">DLMS client.</param>
124124
/// <param name="functions">Added functions.</param>
125125
/// <returns>Action bytes.</returns>
126126
/// <summary>
127127
public byte[][] AddFunction(
128128
GXDLMSClient client,
129-
List<KeyValuePair<string, List<GXDLMSObject>>> functions)
129+
string name,
130+
List<GXDLMSObject> functions)
130131
{
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);
133148
}
134149

135150
/// <summary>
136-
/// Adjusts the value of the current credit amount attribute.
151+
/// Removes a function from the attribute function list.
137152
/// </summary>
138153
/// <param name="client">DLMS client.</param>
139-
/// <param name="functions">Added functions.</param>
154+
/// <param name="functions">Removed function name.</param>
140155
/// <returns>Action bytes.</returns>
141156
/// <summary>
142-
public byte[][] RemoveFunction(
143-
GXDLMSClient client,
144-
List<KeyValuePair<string, List<GXDLMSObject>>> functions)
157+
public byte[][] RemoveFunction(GXDLMSClient client, string name)
145158
{
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);
148164
}
149165

150166
/// <summary>
@@ -266,16 +282,26 @@ byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
266282
}
267283
else if (e.Index == 2)
268284
{
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));
271299
}
272300
else if (e.Index == 3)
273301
{
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);
279305
}
280306
else
281307
{

0 commit comments

Comments
 (0)