/// <summary> /// The handle message. /// </summary> /// <param name="CommandId"> /// The command id. /// </param> /// <param name="DataType"> /// The data type. /// </param> /// <param name="PayloadSize"> /// The payload size. /// </param> /// <param name="DataCount"> /// The data count. /// </param> /// <param name="Parameter1"> /// The parameter 1. /// </param> /// <param name="Parameter2"> /// The parameter 2. /// </param> /// <param name="header"> /// The header. /// </param> /// <param name="payload"> /// The payload. /// </param> /// <param name="iep"> /// The iep. /// </param> protected override void HandleMessage( ushort CommandId, ushort DataType, ref uint PayloadSize, ref uint DataCount, ref uint Parameter1, ref uint Parameter2, ref byte[] header, ref byte[] payload, ref EndPoint iep) { switch (CommandId) { case CommandID.CA_PROTO_VERSION: break; case CommandID.CA_PROTO_SEARCH: { var channelName = NetworkByteConverter.ToString(payload); if (channelName.Contains(".")) { channelName = channelName.Split('.')[0]; } if (this.Server.recordList.ContainsKey(channelName)) { this.Server.udpConnection.Send(this.channelFoundMessage(Parameter1), (IPEndPoint)iep); } } break; case CommandID.CA_PROTO_CLIENT_NAME: this.Server.openConnection[iep.ToString()].Username = NetworkByteConverter.ToString(payload); break; case CommandID.CA_PROTO_HOST_NAME: this.Server.openConnection[iep.ToString()].Hostname = NetworkByteConverter.ToString(payload); break; case CommandID.CA_PROTO_CREATE_CHAN: this.Server.CreateEpicsChannel((int)Parameter1, iep, NetworkByteConverter.ToString(payload)); break; case CommandID.CA_PROTO_CLEAR_CHANNEL: this.Server.channelList[(int)Parameter1].Dispose(true); break; case CommandID.CA_PROTO_EVENT_ADD: int mask = NetworkByteConverter.ToUInt16(payload, 12); this.Server.channelList[(int)Parameter1].addMonitor( (EpicsType)DataType, (int)DataCount, (int)Parameter2, (MonitorMask)mask); break; case CommandID.CA_PROTO_EVENT_CANCEL: this.Server.channelList[(int)Parameter1].removeMonitor((int)Parameter2); break; case CommandID.CA_PROTO_EVENTS_OFF: break; case CommandID.CA_PROTO_EVENTS_ON: break; case CommandID.CA_PROTO_READ: case CommandID.CA_PROTO_READ_NOTIFY: this.Server.channelList[(int)Parameter1].readValue((int)Parameter2, (EpicsType)DataType, (int)DataCount); break; case CommandID.CA_PROTO_WRITE: case CommandID.CA_PROTO_WRITE_NOTIFY: this.Server.channelList[(int)Parameter1].putValue((int)Parameter2, (EpicsType)DataType, (int)DataCount, payload); break; case CommandID.CA_PROTO_ECHO: this.Server.openConnection[iep.ToString()].Send(CEchoMessage); break; } }
/// <summary> /// The handle message. /// </summary> /// <param name="CommandId"> /// The command id. /// </param> /// <param name="DataType"> /// The data type. /// </param> /// <param name="PayloadSize"> /// The payload size. /// </param> /// <param name="DataCount"> /// The data count. /// </param> /// <param name="Parameter1"> /// The parameter 1. /// </param> /// <param name="Parameter2"> /// The parameter 2. /// </param> /// <param name="header"> /// The header. /// </param> /// <param name="payload"> /// The payload. /// </param> /// <param name="iep"> /// The iep. /// </param> protected override void HandleMessage( ushort CommandId, ushort DataType, ref uint PayloadSize, ref uint DataCount, ref uint Parameter1, ref uint Parameter2, ref byte[] header, ref byte[] payload, ref EndPoint iep) { this.GateWay.Statistic.BytesReceived += header.Length + payload.Length; switch (CommandId) { case CommandID.CA_PROTO_SEARCH: this.GateWay.SearchForChannel(Parameter1, NetworkByteConverter.ToString(payload), iep); this.GateWay.Statistic.Searches++; break; case CommandID.CA_PROTO_CLIENT_NAME: this.GateWay.TCPConnections[iep.ToString()].Username = NetworkByteConverter.ToString(payload); break; case CommandID.CA_PROTO_HOST_NAME: this.GateWay.TCPConnections[iep.ToString()].Hostname = NetworkByteConverter.ToString(payload); break; case CommandID.CA_PROTO_CREATE_CHAN: this.GateWay.CreateClientChannel(Parameter1, NetworkByteConverter.ToString(payload), iep); break; case CommandID.CA_PROTO_CLEAR_CHANNEL: this.GateWay.ChannelListClientId[Parameter1].Dispose(); break; case CommandID.CA_PROTO_WRITE_NOTIFY: case CommandID.CA_PROTO_WRITE: this.GateWay.ChannelListClientId[Parameter1].PutAsync(Parameter2, header, payload); this.GateWay.Statistic.Puts++; break; case CommandID.CA_PROTO_READ: case CommandID.CA_PROTO_READ_NOTIFY: this.GateWay.ChannelListClientId[Parameter1].GetAsync(Parameter2, header); this.GateWay.Statistic.Gets++; break; case CommandID.CA_PROTO_EVENTS_ON: break; case CommandID.CA_PROTO_EVENTS_OFF: break; case CommandID.CA_PROTO_EVENT_ADD: this.GateWay.ChannelListClientId[Parameter1].StartMonitor(Parameter2, header, payload); break; case CommandID.CA_PROTO_EVENT_CANCEL: this.GateWay.ChannelListClientId[Parameter1].RemoveMonitor(Parameter2); break; case CommandID.CA_PROTO_ECHO: this.GateWay.TCPConnections[iep.ToString()].Send(CEchoMessage); break; } }
/// <summary> /// The handle message. /// </summary> /// <param name="CommandId"> /// The command id. /// </param> /// <param name="DataType"> /// The data type. /// </param> /// <param name="PayloadSize"> /// The payload size. /// </param> /// <param name="DataCount"> /// The data count. /// </param> /// <param name="Parameter1"> /// The parameter 1. /// </param> /// <param name="Parameter2"> /// The parameter 2. /// </param> /// <param name="header"> /// The header. /// </param> /// <param name="payload"> /// The payload. /// </param> /// <param name="iep"> /// The iep. /// </param> protected override void HandleMessage( ushort CommandId, ushort DataType, ref uint PayloadSize, ref uint DataCount, ref uint Parameter1, ref uint Parameter2, ref byte[] header, ref byte[] payload, ref EndPoint iep) { switch (CommandId) { // Got Back Value for Get case CommandID.CA_PROTO_READ_NOTIFY: if (DataCount == 0) { this.client.cidChannels[(int)Parameter2].LastValue = null; } else if (DataCount == 1) { this.client.cidChannels[(int)Parameter2].LastValue = NetworkByteConverter.byteToObject( payload, (EpicsType)DataType); } else { this.client.cidChannels[(int)Parameter2].LastValue = NetworkByteConverter.byteToObject( payload, (EpicsType)DataType, (int)DataCount); } break; // Got Status Back for Put case CommandID.CA_PROTO_WRITE_NOTIFY: if (this.client.cidChannels.ContainsKey((int)Parameter2)) { this.client.cidChannels[(int)Parameter2].writeSucceeded(); } break; // Did receive a Monitor Signal case CommandID.CA_PROTO_EVENT_ADD: if (DataCount == 0) { this.client.cidChannels[(int)Parameter2].receiveValueUpdate(null); } else if (DataCount == 1) { this.client.cidChannels[(int)Parameter2].receiveValueUpdate( NetworkByteConverter.byteToObject(payload, (EpicsType)DataType)); } else { this.client.cidChannels[(int)Parameter2].receiveValueUpdate( NetworkByteConverter.byteToObject(payload, (EpicsType)DataType, (int)DataCount)); } break; // Got information about Access Rights case CommandID.CA_PROTO_ACCESS_RIGHTS: this.client.cidChannels[(int)Parameter1].AccessRight = (AccessRights)Parameter2; break; // Could register a Channel on the IOC case CommandID.CA_PROTO_CREATE_CHAN: try { this.tmpChan = this.client.cidChannels[(int)Parameter1]; this.tmpChan.ChannelEpicsType = (EpicsType)DataType; this.tmpChan.ChannelDefinedType = CETypeTranslator[(EpicsType)DataType]; this.tmpChan.ChannelDataCount = DataCount; if (this.tmpChan.MonitorDataCount == 0) { this.tmpChan.MonitorDataCount = DataCount; } this.tmpChan.SID = Parameter2; } catch (Exception e) { } break; // failed to created a Channel. case CommandID.CA_PROTO_CREATE_CH_FAIL: this.tmpChan = this.client.cidChannels[(int)Parameter1]; this.tmpChan.Conn = null; break; case CommandID.CA_PROTO_SERVER_DISCONN: this.client.cidChannels[(int)Parameter1].conn_ConnectionStateChanged(false); break; case CommandID.CA_PROTO_SEARCH: // if a channel is disposed it will fail here. try { var riep = new IPEndPoint(((IPEndPoint)iep).Address, DataType); this.client.cidChannels[(int)Parameter2].Conn = this.client.GetServerConnection(riep); } catch (Exception e) { this.client.ExceptionContainer.Add(new Exception("MINOR: FOUND CHANNEL WHICH ALREADY IS DISPOSED")); } break; case CommandID.CA_PROTO_RSRV_IS_UP: if (this.client.beaconCollection.ContainsKey(iep.ToString())) { lock (this.client.beaconCollection) { this.client.beaconCollection[iep.ToString()] = DateTime.Now; } } else { this.client.addIocBeaconed(iep); } break; case CommandID.CA_PROTO_VERSION: case CommandID.CA_PROTO_ECHO: case CommandID.CA_PROTO_CLEAR_CHANNEL: if (PayloadSize > 0) { this.client.ExceptionContainer.Add( new Exception("MESSAGE WITHOUT PAYLOAD, REQUESTED PAYLOAD. POSSIBLE MISSREADING!")); } break; case CommandID.CA_PROTO_ERROR: this.client.ExceptionContainer.Add( new Exception("EPICS-ERROR: " + Parameter2 + " - " + NetworkByteConverter.ToString(payload, 16))); break; default: this.client.ExceptionContainer.Add(new Exception("NETWORK MISS READING - DROP WHOLE PACKAGE!")); return; } }