public static HandleMethodRequest ( |
||
settings | ||
server | ||
data | ||
connectionInfo | ||
replyData | ||
xml | ||
Результат | void |
public static void HandleMethodRequest(GXDLMSSettings settings, GXDLMSServer server, GXByteBuffer data, GXDLMSConnectionEventArgs connectionInfo, GXByteBuffer replyData, GXDLMSTranslatorStructure xml)
{
ErrorCode error = ErrorCode.Ok;
GXByteBuffer bb = new GXByteBuffer();
// Get type.
ActionRequestType type = (ActionRequestType)data.GetUInt8();
// Get invoke ID and priority.
byte invokeId = data.GetUInt8();
// CI
ObjectType ci = (ObjectType)data.GetUInt16();
byte[] ln = new byte[6];
data.Get(ln);
// Attribute Id
byte id = data.GetUInt8();
// Get parameters.
object parameters = null;
byte selection = data.GetUInt8();
if (xml != null)
{
xml.AppendStartTag(Command.MethodRequest);
if (type == ActionRequestType.Normal)
{
xml.AppendStartTag(Command.MethodRequest, ActionRequestType.Normal);
xml.AppendLine(TranslatorTags.InvokeId, "Value", xml.IntegerToHex(invokeId, 2));
AppendMethodDescriptor(xml, (int)ci, ln, id);
if (selection != 0)
{
//MethodInvocationParameters
xml.AppendStartTag(TranslatorTags.MethodInvocationParameters);
GXDataInfo di = new GXDataInfo();
di.xml = xml;
GXCommon.GetData(settings, data, di);
xml.AppendEndTag(TranslatorTags.MethodInvocationParameters);
}
xml.AppendEndTag(Command.MethodRequest, ActionRequestType.Normal);
}
xml.AppendEndTag(Command.MethodRequest);
return;
}
if (selection != 0)
{
GXDataInfo info = new GXDataInfo();
parameters = GXCommon.GetData(settings, data, info);
}
GXDLMSObject obj = settings.Objects.FindByLN(ci, GXDLMSObject.ToLogicalName(ln));
if (!settings.Connected && (ci != ObjectType.AssociationLogicalName || id != 1))
{
replyData.Set(GXDLMSServer.GenerateConfirmedServiceError(ConfirmedServiceError.InitiateError,
ServiceError.Service, (byte)Service.Unsupported));
return;
}
if (obj == null)
{
obj = server.NotifyFindObject(ci, 0, GXDLMSObject.ToLogicalName(ln));
}
if (obj == null)
{
// Device reports a undefined object.
error = ErrorCode.UndefinedObject;
}
else
{
if (obj.GetMethodAccess(id) == MethodAccessMode.NoAccess)
{
error = ErrorCode.ReadWriteDenied;
}
else
{
ValueEventArgs e = new ValueEventArgs(settings, obj, id, 0, parameters);
server.NotifyAction(new ValueEventArgs[] { e });
byte[] actionReply;
if (e.Handled)
{
actionReply = (byte[])e.Value;
}
else
{
actionReply = (obj as IGXDLMSBase).Invoke(settings, e);
}
//Set default action reply if not given.
if (actionReply != null && e.Error == 0)
{
//Add return parameters
bb.SetUInt8(1);
//Add parameters error code.
bb.SetUInt8(0);
GXCommon.SetData(settings, bb, GXCommon.GetValueType(actionReply), actionReply);
}
else
{
error = e.Error;
//Add return parameters
bb.SetUInt8(0);
}
}
}
GXDLMSLNParameters p = new GXDLMSLNParameters(settings, Command.MethodResponse, 1, null, bb, (byte)error);
GXDLMS.GetLNPdu(p, replyData);
//If High level authentication fails.
if (!settings.Connected && obj is GXDLMSAssociationLogicalName && id == 1)
{
server.NotifyInvalidConnection(connectionInfo);
}
}
///<summary> /// Handle received command. ///</summary> private byte[] HandleCommand(Command cmd, GXByteBuffer data, GXDLMSConnectionEventArgs connectionInfo) { byte frame = 0; switch (cmd) { case Command.AccessRequest: GXDLMSLNCommandHandler.HandleAccessRequest(Settings, this, data, replyData, null); break; case Command.SetRequest: GXDLMSLNCommandHandler.HandleSetRequest(Settings, this, data, replyData, null); break; case Command.WriteRequest: GXDLMSSNCommandHandler.HandleWriteRequest(Settings, this, data, replyData, null); break; case Command.GetRequest: if (data.Size != 0) { GXDLMSLNCommandHandler.HandleGetRequest(Settings, this, data, replyData, null); } break; case Command.ReadRequest: GXDLMSSNCommandHandler.HandleReadRequest(Settings, this, data, replyData, null); break; case Command.MethodRequest: GXDLMSLNCommandHandler.HandleMethodRequest(Settings, this, data, connectionInfo, replyData, null); break; case Command.Snrm: HandleSnrmRequest(); frame = (byte)Command.Ua; break; case Command.Aarq: HandleAarqRequest(data, connectionInfo); break; case Command.ReleaseRequest: case Command.DisconnectRequest: GenerateDisconnectRequest(); Settings.Connected = false; Disconnected(connectionInfo); frame = (byte)Command.Ua; break; case Command.None: //Get next frame. break; default: Debug.WriteLine("Invalid command: " + (int)cmd); break; } byte[] reply; if (this.InterfaceType == Enums.InterfaceType.WRAPPER) { reply = GXDLMS.GetWrapperFrame(Settings, replyData); } else { reply = GXDLMS.GetHdlcFrame(Settings, frame, replyData); } return(reply); }